Correct some questionable uses of printf-like functions in uuid.c
[siplcs.git] / src / sipe.h
blob73f797039502b5d5c50368d3bcc94737ed211285
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 "sip-sec.h"
42 #include "uuid.h"
44 #define SIMPLE_BUF_INC 4096
46 #define SIPE_TYPING_RECV_TIMEOUT 6
47 #define SIPE_TYPING_SEND_TIMEOUT 4
48 #ifndef _WIN32
49 #define PURPLE_WEBSITE "http://pidgin.sf.im/"
50 #endif
52 struct sip_im_session {
53 gchar * with;
54 struct sip_dialog * dialog;
55 struct transaction * outgoing_invite;
57 GSList *outgoing_message_queue;
58 /** Key is <Call-ID><CSeq><METHOD> */
59 GHashTable *unconfirmed_messages;
62 // dialog is the new term for call-leg
63 struct sip_dialog {
64 gchar *ourtag;
65 gchar *theirtag;
66 gchar *theirepid;
67 gchar *callid;
68 GSList *routes;
69 gchar *request;
70 GSList *supported; // counterparty capabilities
71 int cseq;
74 struct sipe_buddy {
75 gchar *name;
76 gchar *annotation;
77 gchar *device_name;
78 GSList *groups;
79 gboolean resubscribed;
82 struct sip_auth {
83 SipSecAuthType type;
84 SipSecContext gssapi_context;
85 gchar *gssapi_data;
86 gchar *opaque;
87 gchar *realm;
88 gchar *target;
89 guint32 flags;
90 int nc;
91 int retries;
92 int ntlm_num;
93 time_t expires;
96 typedef enum {
97 SIPE_TRANSPORT_TLS,
98 SIPE_TRANSPORT_TCP,
99 SIPE_TRANSPORT_UDP,
100 } sipe_transport_type;
102 struct sipe_service_data {
103 const char *service;
104 const char *transport;
105 sipe_transport_type type;
108 struct sipe_account_data {
109 PurpleConnection *gc;
110 gchar *sipdomain;
111 gchar *username;
112 gchar *authdomain;
113 gchar *authuser;
114 gchar *password;
115 gchar *epid;
116 /** Allowed server events to subscribe. From register OK response. */
117 GSList *allow_events;
118 PurpleDnsQueryData *query_data;
119 PurpleSrvQueryData *srv_query_data;
120 const struct sipe_service_data *service_data;
121 PurpleNetworkListenData *listen_data;
122 int fd;
123 int cseq;
124 time_t last_keepalive;
125 int registerstatus; /* 0 nothing, 1 first registration send, 2 auth received, 3 registered */
126 struct sip_auth registrar;
127 struct sip_auth proxy;
128 gboolean reregister_set; /* whether reregister timer set */
129 gboolean reauthenticate_set; /* whether reauthenticate timer set */
130 gboolean subscribed; /* whether subscribed to events, except buddies presence */
131 gboolean subscribed_buddies; /* whether subscribed to buddies presence */
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 gboolean msrtc_event_categories; /*if there is support for batched category subscription [SIP-PRES]*/
142 gboolean batched_support; /*if there is support for batched subscription*/
143 GHashTable *buddies;
144 guint resendtimeout;
145 guint keepalive_timeout;
146 GSList *timeouts;
147 gboolean connecting;
148 PurpleAccount *account;
149 PurpleCircBuffer *txbuf;
150 guint tx_handler;
151 gchar *regcallid;
152 GSList *transactions;
153 GSList *im_sessions;
154 GSList *openconns;
155 GSList *groups;
156 sipe_transport_type transport;
157 gboolean auto_transport;
158 PurpleSslConnection *gsc;
159 struct sockaddr_in serveraddr;
160 gchar *realhostname;
161 int realport; /* port and hostname from SRV record */
162 gboolean processing_input;
165 struct sip_connection {
166 int fd;
167 gchar *inbuf;
168 int inbuflen;
169 int inbufused;
170 int inputhandler;
173 struct sipe_auth_job {
174 gchar * who;
175 struct sipe_account_data * sip;
178 struct transaction;
180 typedef gboolean (*TransCallback) (struct sipe_account_data *, struct sipmsg *, struct transaction *);
182 struct transaction {
183 time_t time;
184 int retries;
185 int transport; /* 0 = tcp, 1 = udp */
186 int fd;
187 gchar *cseq;
188 struct sipmsg *msg;
189 TransCallback callback;
190 void * payload;
193 struct sipe_group {
194 gchar *name;
195 int id;
196 PurpleGroup *purple_group;
199 struct group_user_context {
200 gchar * group_name;
201 gchar * user_name;
204 GSList * slist_insert_unique_sorted(GSList *list, gpointer data, GCompareFunc func);
206 GList *sipe_actions(PurplePlugin *plugin, gpointer context);
208 gboolean purple_init_plugin(PurplePlugin *plugin);
210 #define SIPE_INVITE_TEXT "ms-text-format: text/plain; charset=UTF-8%s;ms-body=%s\r\n"
212 #define SIPE_SEND_TYPING \
213 "<?xml version=\"1.0\"?>"\
214 "<KeyboardActivity>"\
215 "<status status=\"type\" />"\
216 "</KeyboardActivity>"
218 #define SIPE_SEND_PRESENCE \
219 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
220 "<publications uri=\"%s\">"\
221 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"%d\" expireType=\"endpoint\">"\
222 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"machineState\">"\
223 "<availability>%d</availability>"\
224 "<endpointLocation></endpointLocation>"\
225 "</state>"\
226 "</publication>"\
227 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"%d\" expireType=\"endpoint\">"\
228 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"userState\">"\
229 "<availability>%d</availability>"\
230 "<endpointLocation></endpointLocation>"\
231 "</state>"\
232 "</publication>"\
233 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"%d\" expireType=\"static\">"\
234 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
235 "<body type=\"personal\" uri=\"\">%s</body>"\
236 "</note>"\
237 "</publication>"\
238 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"%d\" expireType=\"static\">"\
239 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
240 "<body type=\"personal\" uri=\"\">%s</body>"\
241 "</note>"\
242 "</publication>"\
243 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" 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 "</publications>"\
249 "</publish>"
252 #define SIPE_SEND_CLEAR_PRESENCE \
253 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
254 "<publications uri=\"%s\">"\
255 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
256 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
257 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
258 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
259 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
260 "</publications>"\
261 "</publish>"
264 #define sipe_soap(method, body) \
265 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
266 "<SOAP-ENV:Body>" \
267 "<m:" method " xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
268 body \
269 "</m:" method ">" \
270 "</SOAP-ENV:Body>" \
271 "</SOAP-ENV:Envelope>"
273 #define SIPE_SOAP_SET_CONTACT sipe_soap("setContact", \
274 "<m:displayName>%s</m:displayName>"\
275 "<m:groups>%s</m:groups>"\
276 "<m:subscribed>%s</m:subscribed>"\
277 "<m:URI>%s</m:URI>"\
278 "<m:externalURI />"\
279 "<m:deltaNum>%d</m:deltaNum>")
281 #define SIPE_SOAP_DEL_CONTACT sipe_soap("deleteContact", \
282 "<m:URI>%s</m:URI>"\
283 "<m:deltaNum>%d</m:deltaNum>")
285 #define SIPE_SOAP_ADD_GROUP sipe_soap("addGroup", \
286 "<m:name>%s</m:name>"\
287 "<m:externalURI />"\
288 "<m:deltaNum>%d</m:deltaNum>")
290 #define SIPE_SOAP_MOD_GROUP sipe_soap("modifyGroup", \
291 "<m:groupID>%d</m:groupID>"\
292 "<m:name>%s</m:name>"\
293 "<m:externalURI />"\
294 "<m:deltaNum>%d</m:deltaNum>")
296 #define SIPE_SOAP_DEL_GROUP sipe_soap("deleteGroup", \
297 "<m:groupID>%d</m:groupID>"\
298 "<m:deltaNum>%d</m:deltaNum>")
300 // first/mask arg is sip:user@domain.com
301 // second/rights arg is AA for allow, BD for deny
302 #define SIPE_SOAP_ALLOW_DENY sipe_soap("setACE", \
303 "<m:type>USER</m:type>"\
304 "<m:mask>%s</m:mask>"\
305 "<m:rights>%s</m:rights>"\
306 "<m:deltaNum>%d</m:deltaNum>")
308 #define SIPE_SOAP_SET_PRESENCE sipe_soap("setPresence", \
309 "<m:presentity m:uri=\"%s\">"\
310 "<m:availability m:aggregate=\"%d\"/>"\
311 "<m:activity m:aggregate=\"%d\" m:note=\"%s\"/>"\
312 "<deviceName xmlns=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" name=\"USER-DESKTOP\"/>"\
313 "<rtc:devicedata xmlns:rtc=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" namespace=\"rtcService\">"\
314 "&lt;![CDATA[<caps><renders_gif/><renders_isf/></caps>]]&gt;</rtc:devicedata>"\
315 "</m:presentity>")
317 #define SIPE_SOAP_SEARCH_CONTACT \
318 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
319 "<SOAP-ENV:Body>" \
320 "<m:directorySearch xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
321 "<m:filter m:href=\"#searchArray\"/>"\
322 "<m:maxResults>%d</m:maxResults>"\
323 "</m:directorySearch>"\
324 "<m:Array xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\" m:id=\"searchArray\">"\
325 "%s"\
326 "</m:Array>"\
327 "</SOAP-ENV:Body>"\
328 "</SOAP-ENV:Envelope>"
330 #define SIPE_SOAP_SEARCH_ROW "<m:row m:attrib=\"%s\" m:value=\"%s\"/>"
332 #endif /* _PIDGIN_SIPE_H */