conference: incoming invite (part I)
[siplcs.git] / src / sipe.h
blobd52e83a71f39b72b6c1dfabc68b0408680814d0b
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 /** Correspond to multy-party conversation */
53 struct sip_im_session {
54 gchar *with; /* For IM sessions only (not multi-party) . A URI.*/
55 int chat_id;
56 /** Human readable chat name */
57 gchar *chat_name;
58 /** Call-Id identifying the conversation */
59 gchar *callid; /* For multiparty conversations */
60 /** Roster Manager URI */
61 gchar *roster_manager;
62 int bid;
63 gboolean is_voting_in_progress;
64 gboolean is_multiparty;
65 gchar *focus_uri;
66 guint request_id;
67 struct sip_dialog *focus_dialog;
68 /** key is user (URI) */
69 GSList *dialogs;
70 //struct sip_dialog * dialog;
71 /** Link to purple chat or IM */
72 PurpleConversation *conv;
74 GSList *outgoing_message_queue;
75 /** Key is <Call-ID><CSeq><METHOD> */
76 GHashTable *unconfirmed_messages;
78 GSList *pending_invite_queue;
81 // dialog is the new term for call-leg
82 struct sip_dialog {
83 gchar *with; /* URI */
84 gchar *endpoint_GUID;
85 /**
86 * >0 - pro
87 * <0 - contra
88 * 0 - didn't participate
89 */
90 int election_vote;
91 gchar *ourtag;
92 gchar *theirtag;
93 gchar *theirepid;
94 gchar *callid;
95 GSList *routes;
96 gchar *request;
97 GSList *supported; // counterparty capabilities
98 int cseq;
99 gboolean is_established;
100 struct transaction *outgoing_invite;
103 struct sipe_buddy {
104 gchar *name;
105 gchar *annotation;
106 gchar *device_name;
107 GSList *groups;
108 gboolean resubscribed;
111 struct sip_auth {
112 SipSecAuthType type;
113 SipSecContext gssapi_context;
114 gchar *gssapi_data;
115 gchar *opaque;
116 gchar *realm;
117 gchar *target;
118 int nc;
119 int retries;
120 int ntlm_num;
121 int expires;
124 typedef enum {
125 SIPE_TRANSPORT_TLS,
126 SIPE_TRANSPORT_TCP,
127 SIPE_TRANSPORT_UDP,
128 } sipe_transport_type;
130 struct sipe_service_data {
131 const char *service;
132 const char *transport;
133 sipe_transport_type type;
136 /** MS-PRES container */
137 struct sipe_container {
138 guint id;
139 guint version;
140 GSList *members;
142 /** MS-PRES container member */
143 struct sipe_container_member {
144 /** user, domain, sameEnterprise, federated, publicCloud; everyone */
145 const gchar *type;
146 const gchar *value;
149 struct sipe_account_data {
150 PurpleConnection *gc;
151 gchar *sipdomain;
152 gchar *username;
153 gchar *authdomain;
154 gchar *authuser;
155 gchar *password;
156 gchar *epid;
157 /** Allowed server events to subscribe. From register OK response. */
158 GSList *allow_events;
159 PurpleDnsQueryData *query_data;
160 PurpleSrvQueryData *srv_query_data;
161 const struct sipe_service_data *service_data;
162 PurpleNetworkListenData *listen_data;
163 int fd;
164 int cseq;
165 int chat_seq;
166 time_t last_keepalive;
167 int registerstatus; /* 0 nothing, 1 first registration send, 2 auth received, 3 registered */
168 struct sip_auth registrar;
169 struct sip_auth proxy;
170 gboolean reregister_set; /* whether reregister timer set */
171 gboolean reauthenticate_set; /* whether reauthenticate timer set */
172 gboolean subscribed; /* whether subscribed to events, except buddies presence */
173 gboolean subscribed_buddies; /* whether subscribed to buddies presence */
174 gboolean access_level_set; /* whether basic access level set */
175 int listenfd;
176 int listenport;
177 int listenpa;
178 int contacts_delta;
179 int acl_delta;
180 int presence_method_version;
181 gchar *status;
182 int status_version;
183 gchar *contact;
184 gboolean msrtc_event_categories; /*if there is support for batched category subscription [SIP-PRES]*/
185 gboolean batched_support; /*if there is support for batched subscription*/
186 GSList *containers; /* MS-PRES containers */
187 GHashTable *buddies;
188 guint resendtimeout;
189 guint keepalive_timeout;
190 GSList *timeouts;
191 gboolean connecting;
192 PurpleAccount *account;
193 PurpleCircBuffer *txbuf;
194 guint tx_handler;
195 gchar *regcallid;
196 GSList *transactions;
197 GSList *im_sessions;
198 GSList *openconns;
199 GSList *groups;
200 sipe_transport_type transport;
201 gboolean auto_transport;
202 PurpleSslConnection *gsc;
203 struct sockaddr_in serveraddr;
204 gchar *realhostname;
205 int realport; /* port and hostname from SRV record */
206 gboolean processing_input;
209 struct sip_connection {
210 int fd;
211 gchar *inbuf;
212 int inbuflen;
213 int inbufused;
214 int inputhandler;
217 struct sipe_auth_job {
218 gchar * who;
219 struct sipe_account_data * sip;
222 struct transaction;
224 typedef gboolean (*TransCallback) (struct sipe_account_data *, struct sipmsg *, struct transaction *);
226 struct transaction {
227 time_t time;
228 int retries;
229 int transport; /* 0 = tcp, 1 = udp */
230 int fd;
231 gchar *cseq;
232 struct sipmsg *msg;
233 TransCallback callback;
234 void * payload;
237 struct sipe_group {
238 gchar *name;
239 int id;
240 PurpleGroup *purple_group;
243 struct group_user_context {
244 gchar * group_name;
245 gchar * user_name;
248 GSList * slist_insert_unique_sorted(GSList *list, gpointer data, GCompareFunc func);
250 GList *sipe_actions(PurplePlugin *plugin, gpointer context);
252 gboolean purple_init_plugin(PurplePlugin *plugin);
254 #define SIPE_INVITE_TEXT "ms-text-format: text/plain; charset=UTF-8%s;ms-body=%s\r\n"
256 #define SIPE_SEND_TYPING \
257 "<?xml version=\"1.0\"?>"\
258 "<KeyboardActivity>"\
259 "<status status=\"type\" />"\
260 "</KeyboardActivity>"
262 #define SIPE_SEND_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=\"%d\" expireType=\"endpoint\">"\
266 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"machineState\">"\
267 "<availability>%d</availability>"\
268 "<endpointLocation></endpointLocation>"\
269 "</state>"\
270 "</publication>"\
271 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"%d\" expireType=\"endpoint\">"\
272 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"userState\">"\
273 "<availability>%d</availability>"\
274 "<endpointLocation></endpointLocation>"\
275 "</state>"\
276 "</publication>"\
277 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"%d\" expireType=\"static\">"\
278 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
279 "<body type=\"personal\" uri=\"\">%s</body>"\
280 "</note>"\
281 "</publication>"\
282 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"%d\" expireType=\"static\">"\
283 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
284 "<body type=\"personal\" uri=\"\">%s</body>"\
285 "</note>"\
286 "</publication>"\
287 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"%d\" expireType=\"static\">"\
288 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
289 "<body type=\"personal\" uri=\"\">%s</body>"\
290 "</note>"\
291 "</publication>"\
292 "</publications>"\
293 "</publish>"
296 #define SIPE_SEND_CLEAR_PRESENCE \
297 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
298 "<publications uri=\"%s\">"\
299 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
300 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
301 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
302 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
303 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
304 "</publications>"\
305 "</publish>"
308 #define sipe_soap(method, body) \
309 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
310 "<SOAP-ENV:Body>" \
311 "<m:" method " xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
312 body \
313 "</m:" method ">" \
314 "</SOAP-ENV:Body>" \
315 "</SOAP-ENV:Envelope>"
317 #define SIPE_SOAP_SET_CONTACT sipe_soap("setContact", \
318 "<m:displayName>%s</m:displayName>"\
319 "<m:groups>%s</m:groups>"\
320 "<m:subscribed>%s</m:subscribed>"\
321 "<m:URI>%s</m:URI>"\
322 "<m:externalURI />"\
323 "<m:deltaNum>%d</m:deltaNum>")
325 #define SIPE_SOAP_DEL_CONTACT sipe_soap("deleteContact", \
326 "<m:URI>%s</m:URI>"\
327 "<m:deltaNum>%d</m:deltaNum>")
329 #define SIPE_SOAP_ADD_GROUP sipe_soap("addGroup", \
330 "<m:name>%s</m:name>"\
331 "<m:externalURI />"\
332 "<m:deltaNum>%d</m:deltaNum>")
334 #define SIPE_SOAP_MOD_GROUP sipe_soap("modifyGroup", \
335 "<m:groupID>%d</m:groupID>"\
336 "<m:name>%s</m:name>"\
337 "<m:externalURI />"\
338 "<m:deltaNum>%d</m:deltaNum>")
340 #define SIPE_SOAP_DEL_GROUP sipe_soap("deleteGroup", \
341 "<m:groupID>%d</m:groupID>"\
342 "<m:deltaNum>%d</m:deltaNum>")
344 // first/mask arg is sip:user@domain.com
345 // second/rights arg is AA for allow, BD for deny
346 #define SIPE_SOAP_ALLOW_DENY sipe_soap("setACE", \
347 "<m:type>USER</m:type>"\
348 "<m:mask>%s</m:mask>"\
349 "<m:rights>%s</m:rights>"\
350 "<m:deltaNum>%d</m:deltaNum>")
352 #define SIPE_SOAP_SET_PRESENCE sipe_soap("setPresence", \
353 "<m:presentity m:uri=\"%s\">"\
354 "<m:availability m:aggregate=\"%d\"/>"\
355 "<m:activity m:aggregate=\"%d\" m:note=\"%s\"/>"\
356 "<deviceName xmlns=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" name=\"USER-DESKTOP\"/>"\
357 "<rtc:devicedata xmlns:rtc=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" namespace=\"rtcService\">"\
358 "&lt;![CDATA[<caps><renders_gif/><renders_isf/></caps>]]&gt;</rtc:devicedata>"\
359 "</m:presentity>")
361 #define SIPE_SOAP_SEARCH_CONTACT \
362 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
363 "<SOAP-ENV:Body>" \
364 "<m:directorySearch xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
365 "<m:filter m:href=\"#searchArray\"/>"\
366 "<m:maxResults>%d</m:maxResults>"\
367 "</m:directorySearch>"\
368 "<m:Array xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\" m:id=\"searchArray\">"\
369 "%s"\
370 "</m:Array>"\
371 "</SOAP-ENV:Body>"\
372 "</SOAP-ENV:Envelope>"
374 #define SIPE_SOAP_SEARCH_ROW "<m:row m:attrib=\"%s\" m:value=\"%s\"/>"
376 #endif /* _PIDGIN_SIPE_H */