Added to find contacts support with the name 'Search for Contact by Name'
[siplcs.git] / src / sipe.h
blob653682601e3ea53d86002a38393507959d1205eb
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 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 *password;
113 PurpleDnsQueryData *query_data;
114 PurpleSrvQueryData *srv_query_data;
115 const struct sipe_service_data *service_data;
116 PurpleNetworkListenData *listen_data;
117 int fd;
118 int cseq;
119 time_t reregister;
120 time_t republish;
121 int registerstatus; /* 0 nothing, 1 first registration send, 2 auth received, 3 registered */
122 struct sip_auth registrar;
123 struct sip_auth proxy;
124 int listenfd;
125 int listenport;
126 int listenpa;
127 int delta_num;
128 int presence_method_version;
129 gchar *status;
130 int status_version;
131 gchar *contact;
132 GHashTable *buddies;
133 guint registertimeout;
134 guint resendtimeout;
135 gboolean connecting;
136 PurpleAccount *account;
137 PurpleCircBuffer *txbuf;
138 guint tx_handler;
139 gchar *regcallid;
140 GSList *transactions;
141 GSList *watcher;
142 GSList *im_sessions;
143 GSList *openconns;
144 GSList *groups;
145 sipe_transport_type transport;
146 PurpleSslConnection *gsc;
147 struct sockaddr_in serveraddr;
148 int registerexpire;
149 gchar *realhostname;
150 int realport; /* port and hostname from SRV record */
153 struct sipe_find{
154 gchar *name;
157 struct sip_connection {
158 int fd;
159 gchar *inbuf;
160 int inbuflen;
161 int inbufused;
162 int inputhandler;
165 struct transaction;
167 typedef gboolean (*TransCallback) (struct sipe_account_data *, struct sipmsg *, struct transaction *);
169 struct transaction {
170 time_t time;
171 int retries;
172 int transport; /* 0 = tcp, 1 = udp */
173 int fd;
174 gchar *cseq;
175 struct sipmsg *msg;
176 TransCallback callback;
177 void * payload;
180 struct sipe_group {
181 gchar *name;
182 int id;
183 PurpleGroup *purple_group;
186 struct group_user_context {
187 gchar * group_name;
188 gchar * user_name;
191 #define SIPE_INVITE_TEXT "ms-text-format: text/plain; charset=UTF-8;msgr=WAAtAE0ATQBTAC0ASQBNAC0ARgBvAHIAbQBhAHQAOgAgAEYATgA9AE0AUwAlADIAMABTAGgAZQBsAGwAJQAyADAARABsAGcAJQAyADAAMgA7ACAARQBGAD0AOwAgAEMATwA9ADAAOwAgAEMAUwA9ADAAOwAgAFAARgA9ADAACgANAAoADQA;ms-body=%s\r\n"
193 #define SIPE_SEND_TYPING \
194 "<?xml version=\"1.0\"?>"\
195 "<KeyboardActivity>"\
196 "<status status=\"type\" />"\
197 "</KeyboardActivity>"
199 #define SIPE_SEND_PRESENCE \
200 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
201 "<publications uri=\"%s\">"\
202 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"%d\" expireType=\"endpoint\">"\
203 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"machineState\">"\
204 "<availability>%d</availability>"\
205 "<endpointLocation></endpointLocation>"\
206 "</state>"\
207 "</publication>"\
208 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"%d\" expireType=\"endpoint\">"\
209 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"userState\">"\
210 "<availability>%d</availability>"\
211 "<endpointLocation></endpointLocation>"\
212 "</state>"\
213 "</publication>"\
214 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"%d\" expireType=\"static\">"\
215 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
216 "<body type=\"personal\" uri=\"\">%s</body>"\
217 "</note>"\
218 "</publication>"\
219 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"%d\" expireType=\"static\">"\
220 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
221 "<body type=\"personal\" uri=\"\">%s</body>"\
222 "</note>"\
223 "</publication>"\
224 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"%d\" expireType=\"static\">"\
225 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
226 "<body type=\"personal\" uri=\"\">%s</body>"\
227 "</note>"\
228 "</publication>"\
229 "</publications>"\
230 "</publish>"
233 #define SIPE_SEND_CLEAR_PRESENCE \
234 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
235 "<publications uri=\"%s\">"\
236 "<publication categoryName=\"state\" instance=\"906391354\" container=\"2\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
237 "<publication categoryName=\"state\" instance=\"906391356\" container=\"0\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
238 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
239 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
240 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"1\" expireType=\"static\" expires=\"0\" />"\
241 "</publications>"\
242 "</publish>"
245 #define sipe_soap(method, body) \
246 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
247 "<SOAP-ENV:Body>" \
248 "<m:" method " xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
249 body \
250 "</m:" method ">" \
251 "</SOAP-ENV:Body>" \
252 "</SOAP-ENV:Envelope>"
254 #define SIPE_SOAP_SET_CONTACT sipe_soap("setContact", \
255 "<m:displayName>%s</m:displayName>"\
256 "<m:groups>%d</m:groups>"\
257 "<m:subscribed>%s</m:subscribed>"\
258 "<m:URI>%s</m:URI>"\
259 "<m:externalURI />"\
260 "<m:deltaNum>%d</m:deltaNum>")
262 #define SIPE_SOAP_DEL_CONTACT sipe_soap("deleteContact", \
263 "<m:URI>%s</m:URI>"\
264 "<m:deltaNum>%d</m:deltaNum>")
266 #define SIPE_SOAP_ADD_GROUP sipe_soap("addGroup", \
267 "<m:name>%s</m:name>"\
268 "<m:externalURI />"\
269 "<m:deltaNum>%d</m:deltaNum>")
271 #define SIPE_SOAP_MOD_GROUP sipe_soap("modifyGroup", \
272 "<m:groupID>%d</m:groupID>"\
273 "<m:name>%s</m:name>"\
274 "<m:externalURI />"\
275 "<m:deltaNum>%d</m:deltaNum>")
277 #define SIPE_SOAP_DEL_GROUP sipe_soap("deleteGroup", \
278 "<m:groupID>%d</m:groupID>"\
279 "<m:deltaNum>%d</m:deltaNum>")
281 #define SIPE_SOAP_SET_PRESENCE sipe_soap("setPresence", \
282 "<m:presentity m:uri=\"%s\">"\
283 "<m:availability m:aggregate=\"%d\"/>"\
284 "<m:activity m:aggregate=\"%d\" m:note=\"%s\"/>"\
285 "<deviceName xmlns=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" name=\"USER-DESKTOP\"/>"\
286 "<rtc:devicedata xmlns:rtc=\"http://schemas.microsoft.com/2002/09/sip/client/presence\" namespace=\"rtcService\">"\
287 "&lt;![CDATA[<caps><renders_gif/><renders_isf/></caps>]]&gt;</rtc:devicedata>"\
288 "</m:presentity>")
290 #define SIPE_SOAP_SEARCH_CONTACT \
291 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
292 "<SOAP-ENV:Body>" \
293 "<m:directorySearch xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
294 "<m:filter m:href=\"#searchArray\"/>"\
295 "<m:maxResults>%d</m:maxResults>"\
296 "</m:directorySearch>"\
297 "<m:Array xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\" m:id=\"searchArray\">"\
298 "<m:row m:attrib=\"givenName\" m:value=\"%s\"/>"\
299 "</m:Array>"\
300 "</SOAP-ENV:Body>"\
301 "</SOAP-ENV:Envelope>"
305 #endif /* _PIDGIN_SIPE_H */