Merge branch 'mob' of git+ssh://mob@repo.or.cz/srv/git/siplcs into mob
[siplcs.git] / src / sipe.h
blobefd4ead99bc17152eac9ad6181ae70414191f588
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 #define PURPLE_WEBSITE "http://pidgin.sf.im/"
49 struct sip_im_session {
50 gchar * with;
51 struct sip_dialog * dialog;
52 struct transaction * outgoing_invite;
54 GSList *outgoing_message_queue;
57 // dialog is the new term for call-leg
58 struct sip_dialog {
59 gchar *ourtag;
60 gchar *theirtag;
61 gchar *theirepid;
62 gchar *callid;
63 GSList *routes;
64 gchar *request;
65 int cseq;
68 struct sipe_watcher {
69 gchar *name;
70 time_t expire;
71 struct sip_dialog dialog;
72 gboolean needsxpidf;
75 struct sipe_buddy {
76 gchar *name;
77 time_t resubscribe;
78 int group_id;
81 struct sip_auth {
82 int type; /* 1 = Digest / 2 = NTLM / 3 = Kerberos */
83 gchar *nonce;
84 gchar *opaque;
85 gchar *realm;
86 gchar *target;
87 gchar *rspauth;
88 gchar *srand;
89 guint32 flags;
90 int nc;
91 gchar *digest_session_key;
92 int retries;
93 gchar *ntlm_key;
94 int ntlm_num;
97 typedef enum {
98 SIPE_TRANSPORT_TLS,
99 SIPE_TRANSPORT_TCP,
100 SIPE_TRANSPORT_UDP,
101 } sipe_transport_type;
103 struct sipe_service_data {
104 const char *service;
105 const char *transport;
106 sipe_transport_type type;
109 struct sipe_account_data {
110 PurpleConnection *gc;
111 gchar *sipdomain;
112 gchar *username;
113 gchar *password;
114 PurpleDnsQueryData *query_data;
115 PurpleSrvQueryData *srv_query_data;
116 const struct sipe_service_data *service_data;
117 PurpleNetworkListenData *listen_data;
118 int fd;
119 int cseq;
120 time_t reregister;
121 time_t republish;
122 time_t last_keepalive;
123 int registerstatus; /* 0 nothing, 1 first registration send, 2 auth received, 3 registered */
124 struct sip_auth registrar;
125 struct sip_auth proxy;
126 int listenfd;
127 int listenport;
128 int listenpa;
129 int delta_num;
130 int presence_method_version;
131 gchar *status;
132 int status_version;
133 gchar *contact;
134 GHashTable *buddies;
135 guint registertimeout;
136 guint resendtimeout;
137 guint keepalive_timeout;
138 gboolean connecting;
139 PurpleAccount *account;
140 PurpleCircBuffer *txbuf;
141 guint tx_handler;
142 gchar *regcallid;
143 GSList *transactions;
144 GSList *watcher;
145 GSList *im_sessions;
146 GSList *openconns;
147 GSList *groups;
148 sipe_transport_type transport;
149 PurpleSslConnection *gsc;
150 struct sockaddr_in serveraddr;
151 int registerexpire;
152 gchar *realhostname;
153 int realport; /* port and hostname from SRV record */
156 struct sip_connection {
157 int fd;
158 gchar *inbuf;
159 int inbuflen;
160 int inbufused;
161 int inputhandler;
164 struct transaction;
166 typedef gboolean (*TransCallback) (struct sipe_account_data *, struct sipmsg *, struct transaction *);
168 struct transaction {
169 time_t time;
170 int retries;
171 int transport; /* 0 = tcp, 1 = udp */
172 int fd;
173 gchar *cseq;
174 struct sipmsg *msg;
175 TransCallback callback;
176 void * payload;
179 struct sipe_group {
180 gchar *name;
181 int id;
182 PurpleGroup *purple_group;
185 struct group_user_context {
186 gchar * group_name;
187 gchar * user_name;
190 #define SIPE_INVITE_TEXT "ms-text-format: text/plain; charset=UTF-8;msgr=WAAtAE0ATQBTAC0ASQBNAC0ARgBvAHIAbQBhAHQAOgAgAEYATgA9AE0AUwAlADIAMABTAGgAZQBsAGwAJQAyADAARABsAGcAJQAyADAAMgA7ACAARQBGAD0AOwAgAEMATwA9ADAAOwAgAEMAUwA9ADAAOwAgAFAARgA9ADAACgANAAoADQA;ms-body=%s\r\n"
192 #define SIPE_SEND_TYPING \
193 "<?xml version=\"1.0\"?>"\
194 "<KeyboardActivity>"\
195 "<status status=\"type\" />"\
196 "</KeyboardActivity>"
198 #define SIPE_SEND_PRESENCE \
199 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
200 "<publications uri=\"%s\">"\
201 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"%d\" expireType=\"endpoint\">"\
202 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"machineState\">"\
203 "<availability>%d</availability>"\
204 "<endpointLocation></endpointLocation>"\
205 "</state>"\
206 "</publication>"\
207 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"%d\" expireType=\"endpoint\">"\
208 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"userState\">"\
209 "<availability>%d</availability>"\
210 "<endpointLocation></endpointLocation>"\
211 "</state>"\
212 "</publication>"\
213 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"%d\" expireType=\"static\">"\
214 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
215 "<body type=\"personal\" uri=\"\">%s</body>"\
216 "</note>"\
217 "</publication>"\
218 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"%d\" expireType=\"static\">"\
219 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
220 "<body type=\"personal\" uri=\"\">%s</body>"\
221 "</note>"\
222 "</publication>"\
223 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"%d\" expireType=\"static\">"\
224 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
225 "<body type=\"personal\" uri=\"\">%s</body>"\
226 "</note>"\
227 "</publication>"\
228 "</publications>"\
229 "</publish>"
232 #define SIPE_SEND_CLEAR_PRESENCE \
233 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
234 "<publications uri=\"%s\">"\
235 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
236 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
237 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
238 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
239 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
240 "</publications>"\
241 "</publish>"
244 #define sipe_soap(method, body) \
245 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
246 "<SOAP-ENV:Body>" \
247 "<m:" method " xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
248 body \
249 "</m:" method ">" \
250 "</SOAP-ENV:Body>" \
251 "</SOAP-ENV:Envelope>"
253 #define SIPE_SOAP_SET_CONTACT sipe_soap("setContact", \
254 "<m:displayName>%s</m:displayName>"\
255 "<m:groups>%d</m:groups>"\
256 "<m:subscribed>%s</m:subscribed>"\
257 "<m:URI>%s</m:URI>"\
258 "<m:externalURI />"\
259 "<m:deltaNum>%d</m:deltaNum>")
261 #define SIPE_SOAP_DEL_CONTACT sipe_soap("deleteContact", \
262 "<m:URI>%s</m:URI>"\
263 "<m:deltaNum>%d</m:deltaNum>")
265 #define SIPE_SOAP_ADD_GROUP sipe_soap("addGroup", \
266 "<m:name>%s</m:name>"\
267 "<m:externalURI />"\
268 "<m:deltaNum>%d</m:deltaNum>")
270 #define SIPE_SOAP_MOD_GROUP sipe_soap("modifyGroup", \
271 "<m:groupID>%d</m:groupID>"\
272 "<m:name>%s</m:name>"\
273 "<m:externalURI />"\
274 "<m:deltaNum>%d</m:deltaNum>")
276 #define SIPE_SOAP_DEL_GROUP sipe_soap("deleteGroup", \
277 "<m:groupID>%d</m:groupID>"\
278 "<m:deltaNum>%d</m:deltaNum>")
280 #define SIPE_SOAP_SET_PRESENCE sipe_soap("setPresence", \
281 "<m:presentity m:uri=\"%s\">"\
282 "<m:availability m:aggregate=\"%d\"/>"\
283 "<m:activity m:aggregate=\"%d\" m:note=\"%s\"/>"\
284 "<deviceName xmlns=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" name=\"USER-DESKTOP\"/>"\
285 "<rtc:devicedata xmlns:rtc=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" namespace=\"rtcService\">"\
286 "&lt;![CDATA[<caps><renders_gif/><renders_isf/></caps>]]&gt;</rtc:devicedata>"\
287 "</m:presentity>")
289 #define SIPE_SOAP_SEARCH_CONTACT \
290 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
291 "<SOAP-ENV:Body>" \
292 "<m:directorySearch xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
293 "<m:filter m:href=\"#searchArray\"/>"\
294 "<m:maxResults>%d</m:maxResults>"\
295 "</m:directorySearch>"\
296 "<m:Array xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\" m:id=\"searchArray\">"\
297 "%s"\
298 "</m:Array>"\
299 "</SOAP-ENV:Body>"\
300 "</SOAP-ENV:Envelope>"
302 #define SIPE_SOAP_SEARCH_ROW "<m:row m:attrib=\"%s\" m:value=\"%s\"/>"
304 #endif /* _PIDGIN_SIPE_H */