Update 'es' translation
[siplcs.git] / src / sipe.h
blobdeec9fe9f68c9c520ffeb4b30af4046854d9184f
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 #ifdef _WIN32
32 #include "internal.h"
33 #endif
35 #include "cipher.h"
36 #include "circbuffer.h"
37 #include "dnsquery.h"
38 #include "dnssrv.h"
39 #include "network.h"
40 #include "proxy.h"
41 #include "prpl.h"
42 #include "sslconn.h"
44 #include "sipmsg.h"
45 #include "sip-sec.h"
46 #include "uuid.h"
48 #define SIPE_UNUSED_PARAMETER __attribute__((unused))
50 #define SIMPLE_BUF_INC 4096
52 #define SIPE_TYPING_RECV_TIMEOUT 6
53 #define SIPE_TYPING_SEND_TIMEOUT 4
54 #ifndef _WIN32
55 #define PURPLE_WEBSITE "http://pidgin.sf.im/"
56 #endif
58 struct sipe_buddy {
59 gchar *name;
60 gchar *annotation;
61 gchar *device_name;
62 GSList *groups;
63 gboolean resubscribed;
66 struct sip_auth {
67 SipSecAuthType type;
68 SipSecContext gssapi_context;
69 gchar *gssapi_data;
70 gchar *opaque;
71 gchar *realm;
72 gchar *target;
73 int nc;
74 int retries;
75 int ntlm_num;
76 int expires;
79 typedef enum {
80 SIPE_TRANSPORT_TLS,
81 SIPE_TRANSPORT_TCP,
82 SIPE_TRANSPORT_UDP,
83 } sipe_transport_type;
85 struct sipe_service_data {
86 const char *service;
87 const char *transport;
88 sipe_transport_type type;
91 /** MS-PRES container */
92 struct sipe_publication {
93 gchar *category;
94 guint instance;
95 guint container;
96 guint version;
99 /** MS-PRES container */
100 struct sipe_container {
101 guint id;
102 guint version;
103 GSList *members;
105 /** MS-PRES container member */
106 struct sipe_container_member {
107 /** user, domain, sameEnterprise, federated, publicCloud; everyone */
108 const gchar *type;
109 const gchar *value;
112 struct sipe_account_data {
113 PurpleConnection *gc;
114 gchar *sipdomain;
115 gchar *username;
116 gchar *authdomain;
117 gchar *authuser;
118 gchar *password;
119 gchar *epid;
120 gchar *focus_factory_uri;
121 /** Allowed server events to subscribe. From register OK response. */
122 GSList *allow_events;
123 PurpleDnsQueryData *query_data;
124 PurpleSrvQueryData *srv_query_data;
125 const struct sipe_service_data *service_data;
126 PurpleNetworkListenData *listen_data;
127 int fd;
128 int cseq;
129 int chat_seq;
130 time_t last_keepalive;
131 int registerstatus; /* 0 nothing, 1 first registration send, 2 auth received, 3 registered */
132 struct sip_auth registrar;
133 struct sip_auth proxy;
134 gboolean reregister_set; /* whether reregister timer set */
135 gboolean reauthenticate_set; /* whether reauthenticate timer set */
136 gboolean subscribed; /* whether subscribed to events, except buddies presence */
137 gboolean subscribed_buddies; /* whether subscribed to buddies presence */
138 gboolean access_level_set; /* whether basic access level set */
139 GSList *our_publication_keys; /* [MS-PRES] */
140 GHashTable *our_publications; /* [MS-PRES] */
141 int listenfd;
142 int listenport;
143 int listenpa;
144 int contacts_delta;
145 int acl_delta;
146 int presence_method_version;
147 gchar *status;
148 int status_version;
149 gchar *contact;
150 gboolean msrtc_event_categories; /*if there is support for batched category subscription [SIP-PRES]*/
151 gboolean batched_support; /*if there is support for batched subscription*/
152 GSList *containers; /* MS-PRES containers */
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 *sessions;
164 GSList *openconns;
165 GSList *groups;
166 sipe_transport_type transport;
167 gboolean auto_transport;
168 PurpleSslConnection *gsc;
169 struct sockaddr *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 /** Not yet perfect, but surely better then plain CSeq
198 * Format is: <Call-ID><CSeq>
199 * (RFC3261 17.2.3 for matching server transactions: Request-URI, To tag, From tag, Call-ID, CSeq, and top Via)
201 gchar *key;
202 struct sipmsg *msg;
203 TransCallback callback;
204 void * payload;
207 struct sipe_group {
208 gchar *name;
209 int id;
210 PurpleGroup *purple_group;
213 struct group_user_context {
214 gchar * group_name;
215 gchar * user_name;
218 GSList * slist_insert_unique_sorted(GSList *list, gpointer data, GCompareFunc func);
220 GList *sipe_actions(PurplePlugin *plugin, gpointer context);
222 gboolean purple_init_plugin(PurplePlugin *plugin);
225 * THE BIG SPLIT - temporary interfaces
227 * Previously private functions in sipe.c that are
228 * - waiting to be factored out to an appropriate module
229 * - are needed by the already created new modules
232 /* pier11:
234 * Since SIP (RFC3261) is extensible by its design,
235 * and MS specs prove just that (they all are defined as SIP extensions),
236 * it make sense to split functionality by extension (or close extension group).
237 * For example: conference, presence (MS-PRES), etc.
239 * This way our code will not be monolithic, but potentially _reusable_. May be
240 * a top of other SIP core, and/or other front-end (Telepathy framework?).
242 /* Forward declarations */
243 struct sip_session;
244 struct sip_dialog;
246 /* SIP send module? */
247 struct transaction *
248 send_sip_request(PurpleConnection *gc, const gchar *method,
249 const gchar *url, const gchar *to, const gchar *addheaders,
250 const gchar *body, struct sip_dialog *dialog, TransCallback tc);
251 void
252 send_sip_response(PurpleConnection *gc, struct sipmsg *msg, int code,
253 const char *text, const char *body);
254 void
255 sipe_invite(struct sipe_account_data *sip, struct sip_session *session,
256 const gchar *who, const gchar *msg_body,
257 const gchar *referred_by, const gboolean is_triggered);
258 /* ??? module */
259 gboolean process_subscribe_response(struct sipe_account_data *sip,
260 struct sipmsg *msg,
261 struct transaction *tc);
262 /* Chat module */
263 void
264 sipe_invite_to_chat(struct sipe_account_data *sip,
265 struct sip_session *session,
266 const gchar *who);
267 /* Session module? */
268 void
269 sipe_present_message_undelivered_err(struct sipe_account_data *sip,
270 struct sip_session *session,
271 const gchar *who,
272 const gchar *message);
274 void
275 sipe_present_info(struct sipe_account_data *sip,
276 struct sip_session *session,
277 const gchar *message);
280 void
281 sipe_process_pending_invite_queue(struct sipe_account_data *sip,
282 struct sip_session *session);
284 /*** THE BIG SPLIT END ***/
286 #define SIPE_INVITE_TEXT "ms-text-format: text/plain; charset=UTF-8%s;ms-body=%s\r\n"
288 #define SIPE_SEND_TYPING \
289 "<?xml version=\"1.0\"?>"\
290 "<KeyboardActivity>"\
291 "<status status=\"type\" />"\
292 "</KeyboardActivity>"
294 #define SIPE_SEND_PRESENCE \
295 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
296 "<publications uri=\"%s\">"\
297 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"%d\" expireType=\"endpoint\">"\
298 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"machineState\">"\
299 "<availability>%d</availability>"\
300 "<endpointLocation></endpointLocation>"\
301 "</state>"\
302 "</publication>"\
303 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"%d\" expireType=\"endpoint\">"\
304 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"userState\">"\
305 "<availability>%d</availability>"\
306 "<endpointLocation></endpointLocation>"\
307 "</state>"\
308 "</publication>"\
309 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"%d\" expireType=\"static\">"\
310 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
311 "<body type=\"personal\" uri=\"\">%s</body>"\
312 "</note>"\
313 "</publication>"\
314 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"%d\" expireType=\"static\">"\
315 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
316 "<body type=\"personal\" uri=\"\">%s</body>"\
317 "</note>"\
318 "</publication>"\
319 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"%d\" expireType=\"static\">"\
320 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
321 "<body type=\"personal\" uri=\"\">%s</body>"\
322 "</note>"\
323 "</publication>"\
324 "</publications>"\
325 "</publish>"
328 #define SIPE_SEND_CLEAR_PRESENCE \
329 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
330 "<publications uri=\"%s\">"\
331 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
332 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
333 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
334 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
335 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
336 "</publications>"\
337 "</publish>"
340 #define sipe_soap(method, body) \
341 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
342 "<SOAP-ENV:Body>" \
343 "<m:" method " xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
344 body \
345 "</m:" method ">" \
346 "</SOAP-ENV:Body>" \
347 "</SOAP-ENV:Envelope>"
349 #define SIPE_SOAP_SET_CONTACT sipe_soap("setContact", \
350 "<m:displayName>%s</m:displayName>"\
351 "<m:groups>%s</m:groups>"\
352 "<m:subscribed>%s</m:subscribed>"\
353 "<m:URI>%s</m:URI>"\
354 "<m:externalURI />"\
355 "<m:deltaNum>%d</m:deltaNum>")
357 #define SIPE_SOAP_DEL_CONTACT sipe_soap("deleteContact", \
358 "<m:URI>%s</m:URI>"\
359 "<m:deltaNum>%d</m:deltaNum>")
361 #define SIPE_SOAP_ADD_GROUP sipe_soap("addGroup", \
362 "<m:name>%s</m:name>"\
363 "<m:externalURI />"\
364 "<m:deltaNum>%d</m:deltaNum>")
366 #define SIPE_SOAP_MOD_GROUP sipe_soap("modifyGroup", \
367 "<m:groupID>%d</m:groupID>"\
368 "<m:name>%s</m:name>"\
369 "<m:externalURI />"\
370 "<m:deltaNum>%d</m:deltaNum>")
372 #define SIPE_SOAP_DEL_GROUP sipe_soap("deleteGroup", \
373 "<m:groupID>%d</m:groupID>"\
374 "<m:deltaNum>%d</m:deltaNum>")
376 // first/mask arg is sip:user@domain.com
377 // second/rights arg is AA for allow, BD for deny
378 #define SIPE_SOAP_ALLOW_DENY sipe_soap("setACE", \
379 "<m:type>USER</m:type>"\
380 "<m:mask>%s</m:mask>"\
381 "<m:rights>%s</m:rights>"\
382 "<m:deltaNum>%d</m:deltaNum>")
384 #define SIPE_SOAP_SET_PRESENCE sipe_soap("setPresence", \
385 "<m:presentity m:uri=\"%s\">"\
386 "<m:availability m:aggregate=\"%d\"/>"\
387 "<m:activity m:aggregate=\"%d\" m:note=\"%s\"/>"\
388 "<deviceName xmlns=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" name=\"USER-DESKTOP\"/>"\
389 "<rtc:devicedata xmlns:rtc=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" namespace=\"rtcService\">"\
390 "&lt;![CDATA[<caps><renders_gif/><renders_isf/></caps>]]&gt;</rtc:devicedata>"\
391 "</m:presentity>")
393 #define SIPE_SOAP_SEARCH_CONTACT \
394 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
395 "<SOAP-ENV:Body>" \
396 "<m:directorySearch xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
397 "<m:filter m:href=\"#searchArray\"/>"\
398 "<m:maxResults>%d</m:maxResults>"\
399 "</m:directorySearch>"\
400 "<m:Array xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\" m:id=\"searchArray\">"\
401 "%s"\
402 "</m:Array>"\
403 "</SOAP-ENV:Body>"\
404 "</SOAP-ENV:Envelope>"
406 #define SIPE_SOAP_SEARCH_ROW "<m:row m:attrib=\"%s\" m:value=\"%s\"/>"
408 #endif /* _PIDGIN_SIPE_H */