Cleaned some warnings in the code
[siplcs.git] / src / sipe.h
blob0dcd20ef668dc0a8f8eb9477100e97943e74c3a5
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;
57 /** Key is <Call-ID><CSeq><METHOD> */
58 GHashTable *unconfirmed_messages;
61 // dialog is the new term for call-leg
62 struct sip_dialog {
63 gchar *ourtag;
64 gchar *theirtag;
65 gchar *theirepid;
66 gchar *callid;
67 GSList *routes;
68 gchar *request;
69 GSList *supported; // counterparty capabilities
70 int cseq;
73 struct sipe_buddy {
74 gchar *name;
75 gchar *annotation;
76 gchar *device_name;
77 GSList *groups;
78 gboolean resubscribed;
81 typedef enum sipe_auth_type
83 AUTH_TYPE_UNSET = 0,
84 AUTH_TYPE_DIGEST,
85 AUTH_TYPE_NTLM,
86 AUTH_TYPE_KERBEROS
87 } sipe_auth_type;
89 struct sip_auth {
90 sipe_auth_type type;
91 gchar *nonce;
92 gchar *opaque;
93 gchar *realm;
94 gchar *target;
95 gchar *rspauth;
96 gchar *srand;
97 guint32 flags;
98 int nc;
99 gchar *digest_session_key;
100 int retries;
101 gchar *ntlm_key;
102 int ntlm_num;
103 time_t expires;
106 typedef enum {
107 SIPE_TRANSPORT_TLS,
108 SIPE_TRANSPORT_TCP,
109 SIPE_TRANSPORT_UDP,
110 } sipe_transport_type;
112 struct sipe_service_data {
113 const char *service;
114 const char *transport;
115 sipe_transport_type type;
118 struct sipe_account_data {
119 PurpleConnection *gc;
120 gchar *sipdomain;
121 gchar *username;
122 gchar *authdomain;
123 gchar *authuser;
124 gchar *password;
125 gchar *epid;
126 /** Allowed server events to subscribe. From register OK response. */
127 GSList *allow_events;
128 PurpleDnsQueryData *query_data;
129 PurpleSrvQueryData *srv_query_data;
130 const struct sipe_service_data *service_data;
131 PurpleNetworkListenData *listen_data;
132 int fd;
133 int cseq;
134 time_t last_keepalive;
135 int registerstatus; /* 0 nothing, 1 first registration send, 2 auth received, 3 registered */
136 struct sip_auth registrar;
137 struct sip_auth proxy;
138 gboolean reregister_set; /* whether reregister timer set */
139 gboolean reauthenticate_set; /* whether reauthenticate timer set */
140 gboolean subscribed; /* whether subscribed to events, except buddies presence */
141 gboolean subscribed_buddies; /* whether subscribed to buddies presence */
142 int listenfd;
143 int listenport;
144 int listenpa;
145 int contacts_delta;
146 int acl_delta;
147 int presence_method_version;
148 gchar *status;
149 int status_version;
150 gchar *contact;
151 gboolean msrtc_event_categories; /*if there is support for batched category subscription [SIP-PRES]*/
152 gboolean batched_support; /*if there is support for batched subscription*/
153 GHashTable *buddies;
154 guint resendtimeout;
155 guint keepalive_timeout;
156 GSList *timeouts;
157 gboolean connecting;
158 PurpleAccount *account;
159 PurpleCircBuffer *txbuf;
160 guint tx_handler;
161 gchar *regcallid;
162 GSList *transactions;
163 GSList *im_sessions;
164 GSList *openconns;
165 GSList *groups;
166 sipe_transport_type transport;
167 gboolean auto_transport;
168 PurpleSslConnection *gsc;
169 struct sockaddr_in serveraddr;
170 gchar *realhostname;
171 int realport; /* port and hostname from SRV record */
172 gboolean processing_input;
175 struct sip_connection {
176 int fd;
177 gchar *inbuf;
178 int inbuflen;
179 int inbufused;
180 int inputhandler;
183 struct sipe_auth_job {
184 gchar * who;
185 struct sipe_account_data * sip;
188 struct transaction;
190 typedef gboolean (*TransCallback) (struct sipe_account_data *, struct sipmsg *, struct transaction *);
192 struct transaction {
193 time_t time;
194 int retries;
195 int transport; /* 0 = tcp, 1 = udp */
196 int fd;
197 gchar *cseq;
198 struct sipmsg *msg;
199 TransCallback callback;
200 void * payload;
203 struct sipe_group {
204 gchar *name;
205 int id;
206 PurpleGroup *purple_group;
209 struct group_user_context {
210 gchar * group_name;
211 gchar * user_name;
214 GSList * slist_insert_unique_sorted(GSList *list, gpointer data, GCompareFunc func);
216 GList *sipe_actions(PurplePlugin *plugin, gpointer context);
218 gboolean purple_init_plugin(PurplePlugin *plugin);
220 #define SIPE_INVITE_TEXT "ms-text-format: text/plain; charset=UTF-8%s;ms-body=%s\r\n"
222 #define SIPE_SEND_TYPING \
223 "<?xml version=\"1.0\"?>"\
224 "<KeyboardActivity>"\
225 "<status status=\"type\" />"\
226 "</KeyboardActivity>"
228 #define SIPE_SEND_PRESENCE \
229 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
230 "<publications uri=\"%s\">"\
231 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"%d\" expireType=\"endpoint\">"\
232 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"machineState\">"\
233 "<availability>%d</availability>"\
234 "<endpointLocation></endpointLocation>"\
235 "</state>"\
236 "</publication>"\
237 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"%d\" expireType=\"endpoint\">"\
238 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"userState\">"\
239 "<availability>%d</availability>"\
240 "<endpointLocation></endpointLocation>"\
241 "</state>"\
242 "</publication>"\
243 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"%d\" expireType=\"static\">"\
244 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
245 "<body type=\"personal\" uri=\"\">%s</body>"\
246 "</note>"\
247 "</publication>"\
248 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"%d\" expireType=\"static\">"\
249 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
250 "<body type=\"personal\" uri=\"\">%s</body>"\
251 "</note>"\
252 "</publication>"\
253 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"%d\" expireType=\"static\">"\
254 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
255 "<body type=\"personal\" uri=\"\">%s</body>"\
256 "</note>"\
257 "</publication>"\
258 "</publications>"\
259 "</publish>"
262 #define SIPE_SEND_CLEAR_PRESENCE \
263 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
264 "<publications uri=\"%s\">"\
265 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
266 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
267 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
268 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
269 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
270 "</publications>"\
271 "</publish>"
274 #define sipe_soap(method, body) \
275 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
276 "<SOAP-ENV:Body>" \
277 "<m:" method " xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
278 body \
279 "</m:" method ">" \
280 "</SOAP-ENV:Body>" \
281 "</SOAP-ENV:Envelope>"
283 #define SIPE_SOAP_SET_CONTACT sipe_soap("setContact", \
284 "<m:displayName>%s</m:displayName>"\
285 "<m:groups>%s</m:groups>"\
286 "<m:subscribed>%s</m:subscribed>"\
287 "<m:URI>%s</m:URI>"\
288 "<m:externalURI />"\
289 "<m:deltaNum>%d</m:deltaNum>")
291 #define SIPE_SOAP_DEL_CONTACT sipe_soap("deleteContact", \
292 "<m:URI>%s</m:URI>"\
293 "<m:deltaNum>%d</m:deltaNum>")
295 #define SIPE_SOAP_ADD_GROUP sipe_soap("addGroup", \
296 "<m:name>%s</m:name>"\
297 "<m:externalURI />"\
298 "<m:deltaNum>%d</m:deltaNum>")
300 #define SIPE_SOAP_MOD_GROUP sipe_soap("modifyGroup", \
301 "<m:groupID>%d</m:groupID>"\
302 "<m:name>%s</m:name>"\
303 "<m:externalURI />"\
304 "<m:deltaNum>%d</m:deltaNum>")
306 #define SIPE_SOAP_DEL_GROUP sipe_soap("deleteGroup", \
307 "<m:groupID>%d</m:groupID>"\
308 "<m:deltaNum>%d</m:deltaNum>")
310 // first/mask arg is sip:user@domain.com
311 // second/rights arg is AA for allow, BD for deny
312 #define SIPE_SOAP_ALLOW_DENY sipe_soap("setACE", \
313 "<m:type>USER</m:type>"\
314 "<m:mask>%s</m:mask>"\
315 "<m:rights>%s</m:rights>"\
316 "<m:deltaNum>%d</m:deltaNum>")
318 #define SIPE_SOAP_SET_PRESENCE sipe_soap("setPresence", \
319 "<m:presentity m:uri=\"%s\">"\
320 "<m:availability m:aggregate=\"%d\"/>"\
321 "<m:activity m:aggregate=\"%d\" m:note=\"%s\"/>"\
322 "<deviceName xmlns=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" name=\"USER-DESKTOP\"/>"\
323 "<rtc:devicedata xmlns:rtc=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" namespace=\"rtcService\">"\
324 "&lt;![CDATA[<caps><renders_gif/><renders_isf/></caps>]]&gt;</rtc:devicedata>"\
325 "</m:presentity>")
327 #define SIPE_SOAP_SEARCH_CONTACT \
328 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
329 "<SOAP-ENV:Body>" \
330 "<m:directorySearch xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
331 "<m:filter m:href=\"#searchArray\"/>"\
332 "<m:maxResults>%d</m:maxResults>"\
333 "</m:directorySearch>"\
334 "<m:Array xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\" m:id=\"searchArray\">"\
335 "%s"\
336 "</m:Array>"\
337 "</SOAP-ENV:Body>"\
338 "</SOAP-ENV:Envelope>"
340 #define SIPE_SOAP_SEARCH_ROW "<m:row m:attrib=\"%s\" m:value=\"%s\"/>"
342 #endif /* _PIDGIN_SIPE_H */