Merge with git+ssh://mob@repo.or.cz/srv/git/siplcs.git#mob
[siplcs.git] / src / sipe.h
blobfcfb723317fce16d5610698c784b028b701c2874
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
48 struct sip_im_session {
49 gchar * with;
50 struct sip_dialog * dialog;
51 struct transaction * outgoing_invite;
53 GSList *outgoing_message_queue;
56 // dialog is the new term for call-leg
57 struct sip_dialog {
58 gchar *ourtag;
59 gchar *theirtag;
60 gchar *theirepid;
61 gchar *callid;
62 gchar *route;
63 gchar *request;
64 int cseq;
67 struct sipe_watcher {
68 gchar *name;
69 time_t expire;
70 struct sip_dialog dialog;
71 gboolean needsxpidf;
74 struct sipe_buddy {
75 gchar *name;
76 time_t resubscribe;
77 int group_id;
80 struct sip_auth {
81 int type; /* 1 = Digest / 2 = NTLM / 3 = Kerberos */
82 gchar *nonce;
83 gchar *opaque;
84 gchar *realm;
85 gchar *target;
86 gchar *rspauth;
87 gchar *srand;
88 guint32 flags;
89 int nc;
90 gchar *digest_session_key;
91 int retries;
92 gchar *ntlm_key;
93 int ntlm_num;
96 struct sipe_service_data {
97 const char *service;
98 const char *transport;
99 gboolean use_ssl;
102 struct sipe_account_data {
103 PurpleConnection *gc;
104 gchar *sipdomain;
105 gchar *username;
106 gchar *password;
107 PurpleDnsQueryData *query_data;
108 PurpleSrvQueryData *srv_query_data;
109 const struct sipe_service_data *service_data;
110 PurpleNetworkListenData *listen_data;
111 int fd;
112 int cseq;
113 time_t reregister;
114 time_t republish;
115 int registerstatus; /* 0 nothing, 1 first registration send, 2 auth received, 3 registered */
116 struct sip_auth registrar;
117 struct sip_auth proxy;
118 int listenfd;
119 int listenport;
120 int listenpa;
121 int delta_num;
122 int presence_method_version;
123 gchar *status;
124 int status_version;
125 gchar *contact;
126 GHashTable *buddies;
127 guint registertimeout;
128 guint resendtimeout;
129 gboolean connecting;
130 PurpleAccount *account;
131 PurpleCircBuffer *txbuf;
132 guint tx_handler;
133 gchar *regcallid;
134 GSList *transactions;
135 GSList *watcher;
136 GSList *im_sessions;
137 GSList *openconns;
138 GSList *groups;
139 gboolean udp;
140 gboolean use_ssl;
141 PurpleSslConnection *gsc;
142 struct sockaddr_in serveraddr;
143 int registerexpire;
144 gchar *realhostname;
145 int realport; /* port and hostname from SRV record */
148 struct sip_connection {
149 int fd;
150 gchar *inbuf;
151 int inbuflen;
152 int inbufused;
153 int inputhandler;
156 struct transaction;
158 typedef gboolean (*TransCallback) (struct sipe_account_data *, struct sipmsg *, struct transaction *);
160 struct transaction {
161 time_t time;
162 int retries;
163 int transport; /* 0 = tcp, 1 = udp */
164 int fd;
165 gchar *cseq;
166 struct sipmsg *msg;
167 TransCallback callback;
168 void * payload;
171 struct sipe_group {
172 gchar *name;
173 int id;
174 PurpleGroup *purple_group;
177 struct group_user_context {
178 gchar * group_name;
179 gchar * user_name;
182 #define SIPE_SEND_TYPING \
183 "<?xml version=\"1.0\"?>"\
184 "<KeyboardActivity>"\
185 "<status status=\"type\" />"\
186 "</KeyboardActivity>"
188 #define SIPE_SEND_PRESENCE \
189 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
190 "<publications uri=\"%s\">"\
191 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"%d\" expireType=\"endpoint\">"\
192 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"machineState\">"\
193 "<availability>%d</availability>"\
194 "<endpointLocation></endpointLocation>"\
195 "</state>"\
196 "</publication>"\
197 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"%d\" expireType=\"endpoint\">"\
198 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"userState\">"\
199 "<availability>%d</availability>"\
200 "<endpointLocation></endpointLocation>"\
201 "</state>"\
202 "</publication>"\
203 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"%d\" expireType=\"static\">"\
204 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
205 "<body type=\"personal\" uri=\"\">%s</body>"\
206 "</note>"\
207 "</publication>"\
208 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"%d\" expireType=\"static\">"\
209 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
210 "<body type=\"personal\" uri=\"\">%s</body>"\
211 "</note>"\
212 "</publication>"\
213 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" 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 "</publications>"\
219 "</publish>"
222 #define SIPE_SEND_CLEAR_PRESENCE \
223 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
224 "<publications uri=\"%s\">"\
225 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
226 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
227 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
228 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
229 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
230 "</publications>"\
231 "</publish>"
234 #define sipe_soap(method, body) \
235 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
236 "<SOAP-ENV:Body>" \
237 "<m:" method " xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
238 body \
239 "</m:" method ">" \
240 "</SOAP-ENV:Body>" \
241 "</SOAP-ENV:Envelope>"
243 #define SIPE_SOAP_SET_CONTACT sipe_soap("setContact", \
244 "<m:displayName>%s</m:displayName>"\
245 "<m:groups>%d</m:groups>"\
246 "<m:subscribed>%s</m:subscribed>"\
247 "<m:URI>%s</m:URI>"\
248 "<m:externalURI />"\
249 "<m:deltaNum>%d</m:deltaNum>")
251 #define SIPE_SOAP_DEL_CONTACT sipe_soap("deleteContact", \
252 "<m:URI>%s</m:URI>"\
253 "<m:deltaNum>%d</m:deltaNum>")
255 #define SIPE_SOAP_ADD_GROUP sipe_soap("addGroup", \
256 "<m:name>%s</m:name>"\
257 "<m:externalURI />"\
258 "<m:deltaNum>%d</m:deltaNum>")
260 #define SIPE_SOAP_MOD_GROUP sipe_soap("modifyGroup", \
261 "<m:groupID>%d</m:groupID>"\
262 "<m:name>%s</m:name>"\
263 "<m:externalURI />"\
264 "<m:deltaNum>%d</m:deltaNum>")
266 #define SIPE_SOAP_DEL_GROUP sipe_soap("deleteGroup", \
267 "<m:groupID>%d</m:groupID>"\
268 "<m:deltaNum>%d</m:deltaNum>")
270 #define SIPE_SOAP_SET_PRESENCE sipe_soap("setPresence", \
271 "<m:presentity m:uri=\"%s\">"\
272 "<m:availability m:aggregate=\"%d\"/>"\
273 "<m:activity m:aggregate=\"%d\" m:note=\"%s\"/>"\
274 "<deviceName xmlns=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" name=\"USER-DESKTOP\"/>"\
275 "<rtc:devicedata xmlns:rtc=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" namespace=\"rtcService\">"\
276 "&lt;![CDATA[<caps><renders_gif/><renders_isf/></caps>]]&gt;</rtc:devicedata>"\
277 "</m:presentity>")
279 #endif /* _PIDGIN_SIPE_H */