Fixed offline contacts in OCS2007. Also other minor details.
[siplcs.git] / src / sipe.h
blobb269b6d140f9547412e0eb2e14dfaf956cbf96d9
1 /**
2 * @file sipe.h
4 * pidgin-sipe
6 * Copyright (C) 2008 Novell, Inc.
7 * Copyright (C) 2007 Anibal Avelar <avelar@gmail.com>
8 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef _PIDGIN_SIPE_H
26 #define _PIDGIN_SIPE_H
28 #include <glib.h>
29 #include <time.h>
31 #include "cipher.h"
32 #include "circbuffer.h"
33 #include "dnsquery.h"
34 #include "dnssrv.h"
35 #include "network.h"
36 #include "proxy.h"
37 #include "prpl.h"
38 #include "sslconn.h"
40 #include "sipmsg.h"
41 #include "uuid.h"
43 #define SIMPLE_BUF_INC 4096
45 #define SIPE_TYPING_RECV_TIMEOUT 6
46 #define SIPE_TYPING_SEND_TIMEOUT 4
47 #ifndef _WIN32
48 #define PURPLE_WEBSITE "http://pidgin.sf.im/"
49 #endif
51 struct sip_im_session {
52 gchar * with;
53 struct sip_dialog * dialog;
54 struct transaction * outgoing_invite;
56 GSList *outgoing_message_queue;
59 // dialog is the new term for call-leg
60 struct sip_dialog {
61 gchar *ourtag;
62 gchar *theirtag;
63 gchar *theirepid;
64 gchar *callid;
65 GSList *routes;
66 gchar *request;
67 GSList *supported; // counterparty capabilities
68 int cseq;
71 struct sipe_buddy {
72 gchar *name;
73 gchar *annotation;
74 time_t resubscribe;
75 int group_id;
78 typedef enum sipe_auth_type
80 AUTH_TYPE_UNSET = 0,
81 AUTH_TYPE_DIGEST,
82 AUTH_TYPE_NTLM,
83 AUTH_TYPE_KERBEROS
84 } sipe_auth_type;
86 struct sip_auth {
87 sipe_auth_type type;
88 gchar *nonce;
89 gchar *opaque;
90 gchar *realm;
91 gchar *target;
92 gchar *rspauth;
93 gchar *srand;
94 guint32 flags;
95 int nc;
96 gchar *digest_session_key;
97 int retries;
98 gchar *ntlm_key;
99 int ntlm_num;
100 time_t expires;
103 typedef enum {
104 SIPE_TRANSPORT_TLS,
105 SIPE_TRANSPORT_TCP,
106 SIPE_TRANSPORT_UDP,
107 } sipe_transport_type;
109 struct sipe_service_data {
110 const char *service;
111 const char *transport;
112 sipe_transport_type type;
115 struct sipe_account_data {
116 PurpleConnection *gc;
117 gchar *sipdomain;
118 gchar *username;
119 gchar *password;
120 PurpleDnsQueryData *query_data;
121 PurpleSrvQueryData *srv_query_data;
122 const struct sipe_service_data *service_data;
123 PurpleNetworkListenData *listen_data;
124 int fd;
125 int cseq;
126 time_t reregister;
127 time_t republish;
128 time_t last_keepalive;
129 int registerstatus; /* 0 nothing, 1 first registration send, 2 auth received, 3 registered */
130 struct sip_auth registrar;
131 struct sip_auth proxy;
132 int listenfd;
133 int listenport;
134 int listenpa;
135 int contacts_delta;
136 int acl_delta;
137 int presence_method_version;
138 gchar *status;
139 int status_version;
140 gchar *contact;
141 GHashTable *buddies;
142 guint registertimeout;
143 guint resendtimeout;
144 guint keepalive_timeout;
145 gboolean connecting;
146 PurpleAccount *account;
147 PurpleCircBuffer *txbuf;
148 guint tx_handler;
149 gchar *regcallid;
150 GSList *transactions;
151 GSList *im_sessions;
152 GSList *openconns;
153 GSList *groups;
154 sipe_transport_type transport;
155 gboolean auto_transport;
156 PurpleSslConnection *gsc;
157 struct sockaddr_in serveraddr;
158 int registerexpire;
159 gchar *realhostname;
160 int realport; /* port and hostname from SRV record */
161 gboolean processing_input;
164 struct sip_connection {
165 int fd;
166 gchar *inbuf;
167 int inbuflen;
168 int inbufused;
169 int inputhandler;
172 struct sipe_auth_job {
173 gchar * who;
174 struct sipe_account_data * sip;
177 struct transaction;
179 typedef gboolean (*TransCallback) (struct sipe_account_data *, struct sipmsg *, struct transaction *);
181 struct transaction {
182 time_t time;
183 int retries;
184 int transport; /* 0 = tcp, 1 = udp */
185 int fd;
186 gchar *cseq;
187 struct sipmsg *msg;
188 TransCallback callback;
189 void * payload;
192 struct sipe_group {
193 gchar *name;
194 int id;
195 PurpleGroup *purple_group;
198 struct group_user_context {
199 gchar * group_name;
200 gchar * user_name;
203 #define SIPE_INVITE_TEXT "ms-text-format: text/plain; charset=UTF-8%s;ms-body=%s\r\n"
205 #define SIPE_SEND_TYPING \
206 "<?xml version=\"1.0\"?>"\
207 "<KeyboardActivity>"\
208 "<status status=\"type\" />"\
209 "</KeyboardActivity>"
211 #define SIPE_SEND_PRESENCE \
212 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
213 "<publications uri=\"%s\">"\
214 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"%d\" expireType=\"endpoint\">"\
215 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"machineState\">"\
216 "<availability>%d</availability>"\
217 "<endpointLocation></endpointLocation>"\
218 "</state>"\
219 "</publication>"\
220 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"%d\" expireType=\"endpoint\">"\
221 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"userState\">"\
222 "<availability>%d</availability>"\
223 "<endpointLocation></endpointLocation>"\
224 "</state>"\
225 "</publication>"\
226 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"%d\" expireType=\"static\">"\
227 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
228 "<body type=\"personal\" uri=\"\">%s</body>"\
229 "</note>"\
230 "</publication>"\
231 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"%d\" expireType=\"static\">"\
232 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
233 "<body type=\"personal\" uri=\"\">%s</body>"\
234 "</note>"\
235 "</publication>"\
236 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"%d\" expireType=\"static\">"\
237 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
238 "<body type=\"personal\" uri=\"\">%s</body>"\
239 "</note>"\
240 "</publication>"\
241 "</publications>"\
242 "</publish>"
245 #define SIPE_SEND_CLEAR_PRESENCE \
246 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
247 "<publications uri=\"%s\">"\
248 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
249 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
250 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
251 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
252 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
253 "</publications>"\
254 "</publish>"
257 #define sipe_soap(method, body) \
258 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
259 "<SOAP-ENV:Body>" \
260 "<m:" method " xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
261 body \
262 "</m:" method ">" \
263 "</SOAP-ENV:Body>" \
264 "</SOAP-ENV:Envelope>"
266 #define SIPE_SOAP_SET_CONTACT sipe_soap("setContact", \
267 "<m:displayName>%s</m:displayName>"\
268 "<m:groups>%d</m:groups>"\
269 "<m:subscribed>%s</m:subscribed>"\
270 "<m:URI>%s</m:URI>"\
271 "<m:externalURI />"\
272 "<m:deltaNum>%d</m:deltaNum>")
274 #define SIPE_SOAP_DEL_CONTACT sipe_soap("deleteContact", \
275 "<m:URI>%s</m:URI>"\
276 "<m:deltaNum>%d</m:deltaNum>")
278 #define SIPE_SOAP_ADD_GROUP sipe_soap("addGroup", \
279 "<m:name>%s</m:name>"\
280 "<m:externalURI />"\
281 "<m:deltaNum>%d</m:deltaNum>")
283 #define SIPE_SOAP_MOD_GROUP sipe_soap("modifyGroup", \
284 "<m:groupID>%d</m:groupID>"\
285 "<m:name>%s</m:name>"\
286 "<m:externalURI />"\
287 "<m:deltaNum>%d</m:deltaNum>")
289 #define SIPE_SOAP_DEL_GROUP sipe_soap("deleteGroup", \
290 "<m:groupID>%d</m:groupID>"\
291 "<m:deltaNum>%d</m:deltaNum>")
293 // first/mask arg is sip:user@domain.com
294 // second/rights arg is AA for allow, BD for deny
295 #define SIPE_SOAP_ALLOW_DENY sipe_soap("setACE", \
296 "<m:type>USER</m:type>"\
297 "<m:mask>%s</m:mask>"\
298 "<m:rights>%s</m:rights>"\
299 "<m:deltaNum>%d</m:deltaNum>")
301 #define SIPE_SOAP_SET_PRESENCE sipe_soap("setPresence", \
302 "<m:presentity m:uri=\"%s\">"\
303 "<m:availability m:aggregate=\"%d\"/>"\
304 "<m:activity m:aggregate=\"%d\" m:note=\"%s\"/>"\
305 "<deviceName xmlns=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" name=\"USER-DESKTOP\"/>"\
306 "<rtc:devicedata xmlns:rtc=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" namespace=\"rtcService\">"\
307 "&lt;![CDATA[<caps><renders_gif/><renders_isf/></caps>]]&gt;</rtc:devicedata>"\
308 "</m:presentity>")
310 #define SIPE_SOAP_SEARCH_CONTACT \
311 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
312 "<SOAP-ENV:Body>" \
313 "<m:directorySearch xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
314 "<m:filter m:href=\"#searchArray\"/>"\
315 "<m:maxResults>%d</m:maxResults>"\
316 "</m:directorySearch>"\
317 "<m:Array xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\" m:id=\"searchArray\">"\
318 "%s"\
319 "</m:Array>"\
320 "</SOAP-ENV:Body>"\
321 "</SOAP-ENV:Envelope>"
323 #define SIPE_SOAP_SEARCH_ROW "<m:row m:attrib=\"%s\" m:value=\"%s\"/>"
325 #endif /* _PIDGIN_SIPE_H */