Full support for Batched Category Subscription for OCS2007.
[siplcs.git] / src / sipe.h
blobceda933e8afd618791e3ec7f623e3483d4cbc565
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 gchar *device_name;
75 GSList *groups;
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 *authdomain;
120 gchar *authuser;
121 gchar *password;
122 PurpleDnsQueryData *query_data;
123 PurpleSrvQueryData *srv_query_data;
124 const struct sipe_service_data *service_data;
125 PurpleNetworkListenData *listen_data;
126 int fd;
127 int cseq;
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 gboolean reregister_set; /* whether reregister timer set */
133 gboolean reauthenticate_set; /* whether reauthenticate timer set */
134 gboolean subscribed; /* whether subscribed to events, except buddies presence */
135 gboolean subscribed_buddies; /* whether subscribed to buddies presence */
136 int listenfd;
137 int listenport;
138 int listenpa;
139 int contacts_delta;
140 int acl_delta;
141 int presence_method_version;
142 gchar *status;
143 int status_version;
144 gchar *contact;
145 gboolean msrtc_event_categories; /*if there is support for batched category subscription [SIP-PRES]*/
146 GHashTable *buddies;
147 guint resendtimeout;
148 guint keepalive_timeout;
149 GSList *timeouts;
150 gboolean connecting;
151 PurpleAccount *account;
152 PurpleCircBuffer *txbuf;
153 guint tx_handler;
154 gchar *regcallid;
155 GSList *transactions;
156 GSList *im_sessions;
157 GSList *openconns;
158 GSList *groups;
159 sipe_transport_type transport;
160 gboolean auto_transport;
161 PurpleSslConnection *gsc;
162 struct sockaddr_in serveraddr;
163 int registerexpire;
164 gchar *realhostname;
165 int realport; /* port and hostname from SRV record */
166 gboolean processing_input;
169 struct sip_connection {
170 int fd;
171 gchar *inbuf;
172 int inbuflen;
173 int inbufused;
174 int inputhandler;
177 struct sipe_auth_job {
178 gchar * who;
179 struct sipe_account_data * sip;
182 struct scheduled_action;
184 typedef gboolean (*Action) (struct sipe_account_data *, struct scheduled_action *);
186 struct scheduled_action {
187 /**
188 * Name of action.
189 * Format is <Event>[<Data>...]
190 * Example: <presence><sip:user@domain.com> or <registration>
192 gchar *name;
193 guint timeout_handler;
194 gboolean repetitive;
195 Action action;
196 struct sipe_account_data *sip;
197 void *payload;
200 struct transaction;
202 typedef gboolean (*TransCallback) (struct sipe_account_data *, struct sipmsg *, struct transaction *);
204 struct transaction {
205 time_t time;
206 int retries;
207 int transport; /* 0 = tcp, 1 = udp */
208 int fd;
209 gchar *cseq;
210 struct sipmsg *msg;
211 TransCallback callback;
212 void * payload;
215 struct sipe_group {
216 gchar *name;
217 int id;
218 PurpleGroup *purple_group;
221 struct group_user_context {
222 gchar * group_name;
223 gchar * user_name;
226 #define SIPE_INVITE_TEXT "ms-text-format: text/plain; charset=UTF-8%s;ms-body=%s\r\n"
228 #define SIPE_SEND_TYPING \
229 "<?xml version=\"1.0\"?>"\
230 "<KeyboardActivity>"\
231 "<status status=\"type\" />"\
232 "</KeyboardActivity>"
234 #define SIPE_SEND_PRESENCE \
235 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
236 "<publications uri=\"%s\">"\
237 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"%d\" expireType=\"endpoint\">"\
238 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"machineState\">"\
239 "<availability>%d</availability>"\
240 "<endpointLocation></endpointLocation>"\
241 "</state>"\
242 "</publication>"\
243 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"%d\" expireType=\"endpoint\">"\
244 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"userState\">"\
245 "<availability>%d</availability>"\
246 "<endpointLocation></endpointLocation>"\
247 "</state>"\
248 "</publication>"\
249 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"%d\" expireType=\"static\">"\
250 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
251 "<body type=\"personal\" uri=\"\">%s</body>"\
252 "</note>"\
253 "</publication>"\
254 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"%d\" expireType=\"static\">"\
255 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
256 "<body type=\"personal\" uri=\"\">%s</body>"\
257 "</note>"\
258 "</publication>"\
259 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"%d\" expireType=\"static\">"\
260 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
261 "<body type=\"personal\" uri=\"\">%s</body>"\
262 "</note>"\
263 "</publication>"\
264 "</publications>"\
265 "</publish>"
268 #define SIPE_SEND_CLEAR_PRESENCE \
269 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
270 "<publications uri=\"%s\">"\
271 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
272 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
273 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
274 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
275 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
276 "</publications>"\
277 "</publish>"
280 #define sipe_soap(method, body) \
281 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
282 "<SOAP-ENV:Body>" \
283 "<m:" method " xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
284 body \
285 "</m:" method ">" \
286 "</SOAP-ENV:Body>" \
287 "</SOAP-ENV:Envelope>"
289 #define SIPE_SOAP_SET_CONTACT sipe_soap("setContact", \
290 "<m:displayName>%s</m:displayName>"\
291 "<m:groups>%s</m:groups>"\
292 "<m:subscribed>%s</m:subscribed>"\
293 "<m:URI>%s</m:URI>"\
294 "<m:externalURI />"\
295 "<m:deltaNum>%d</m:deltaNum>")
297 #define SIPE_SOAP_DEL_CONTACT sipe_soap("deleteContact", \
298 "<m:URI>%s</m:URI>"\
299 "<m:deltaNum>%d</m:deltaNum>")
301 #define SIPE_SOAP_ADD_GROUP sipe_soap("addGroup", \
302 "<m:name>%s</m:name>"\
303 "<m:externalURI />"\
304 "<m:deltaNum>%d</m:deltaNum>")
306 #define SIPE_SOAP_MOD_GROUP sipe_soap("modifyGroup", \
307 "<m:groupID>%d</m:groupID>"\
308 "<m:name>%s</m:name>"\
309 "<m:externalURI />"\
310 "<m:deltaNum>%d</m:deltaNum>")
312 #define SIPE_SOAP_DEL_GROUP sipe_soap("deleteGroup", \
313 "<m:groupID>%d</m:groupID>"\
314 "<m:deltaNum>%d</m:deltaNum>")
316 // first/mask arg is sip:user@domain.com
317 // second/rights arg is AA for allow, BD for deny
318 #define SIPE_SOAP_ALLOW_DENY sipe_soap("setACE", \
319 "<m:type>USER</m:type>"\
320 "<m:mask>%s</m:mask>"\
321 "<m:rights>%s</m:rights>"\
322 "<m:deltaNum>%d</m:deltaNum>")
324 #define SIPE_SOAP_SET_PRESENCE sipe_soap("setPresence", \
325 "<m:presentity m:uri=\"%s\">"\
326 "<m:availability m:aggregate=\"%d\"/>"\
327 "<m:activity m:aggregate=\"%d\" m:note=\"%s\"/>"\
328 "<deviceName xmlns=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" name=\"USER-DESKTOP\"/>"\
329 "<rtc:devicedata xmlns:rtc=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" namespace=\"rtcService\">"\
330 "&lt;![CDATA[<caps><renders_gif/><renders_isf/></caps>]]&gt;</rtc:devicedata>"\
331 "</m:presentity>")
333 #define SIPE_SOAP_SEARCH_CONTACT \
334 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
335 "<SOAP-ENV:Body>" \
336 "<m:directorySearch xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
337 "<m:filter m:href=\"#searchArray\"/>"\
338 "<m:maxResults>%d</m:maxResults>"\
339 "</m:directorySearch>"\
340 "<m:Array xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\" m:id=\"searchArray\">"\
341 "%s"\
342 "</m:Array>"\
343 "</SOAP-ENV:Body>"\
344 "</SOAP-ENV:Envelope>"
346 #define SIPE_SOAP_SEARCH_ROW "<m:row m:attrib=\"%s\" m:value=\"%s\"/>"
348 #endif /* _PIDGIN_SIPE_H */