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
36 #include "circbuffer.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
58 gchar
*meeting_subject
;
59 gchar
*meeting_location
;
63 /** flag to control sending 'context' element in 2007 subscriptions */
69 SipSecContext gssapi_context
;
84 } sipe_transport_type
;
86 struct sipe_service_data
{
88 const char *transport
;
89 sipe_transport_type type
;
92 /** MS-PRES publication */
93 struct sipe_publication
{
98 /** for 'state' category */
100 /** for 'note' category */
104 /** MS-PRES container */
105 struct sipe_container
{
110 /** MS-PRES container member */
111 struct sipe_container_member
{
112 /** user, domain, sameEnterprise, federated, publicCloud; everyone */
117 struct sipe_account_data
{
118 PurpleConnection
*gc
;
125 gchar
*focus_factory_uri
;
126 /** Allowed server events to subscribe. From register OK response. */
127 GSList
*allow_events
;
128 PurpleDnsQueryData
*query_data
;
129 PurpleSrvQueryData
*srv_query_data
;
130 const struct sipe_service_data
*service_data
;
131 PurpleNetworkListenData
*listen_data
;
134 time_t last_keepalive
;
135 int registerstatus
; /* 0 nothing, 1 first registration send, 2 auth received, 3 registered */
136 struct sip_auth registrar
;
137 struct sip_auth proxy
;
138 struct sip_csta
*csta
; /* For RCC - Remote Call Control */
139 gboolean reregister_set
; /* whether reregister timer set */
140 gboolean reauthenticate_set
; /* whether reauthenticate timer set */
141 gboolean subscribed
; /* whether subscribed to events, except buddies presence */
142 gboolean subscribed_buddies
; /* whether subscribed to buddies presence */
143 gboolean access_level_set
; /* whether basic access level set */
144 gboolean initial_state_published
; /* whether we published our initial state */
145 GSList
*our_publication_keys
; /* [MS-PRES] */
146 GHashTable
*our_publications
; /* [MS-PRES] */
147 GHashTable
*subscriptions
;
153 int presence_method_version
;
158 gchar
*server_version
;
159 gboolean ocs2007
; /*if there is support for batched category subscription [SIP-PRES]*/
160 gboolean batched_support
; /*if there is support for batched subscription*/
161 GSList
*containers
; /* MS-PRES containers */
164 guint keepalive_timeout
;
167 PurpleAccount
*account
;
168 PurpleCircBuffer
*txbuf
;
171 GSList
*transactions
;
175 sipe_transport_type transport
;
176 gboolean auto_transport
;
177 PurpleSslConnection
*gsc
;
178 struct sockaddr
*serveraddr
;
180 int realport
; /* port and hostname from SRV record */
181 gboolean processing_input
;
184 struct sip_connection
{
192 struct sipe_auth_job
{
194 struct sipe_account_data
* sip
;
199 typedef gboolean (*TransCallback
) (struct sipe_account_data
*, struct sipmsg
*, struct transaction
*);
201 struct transaction_payload
{
202 GDestroyNotify destroy
;
209 int transport
; /* 0 = tcp, 1 = udp */
211 /** Not yet perfect, but surely better then plain CSeq
212 * Format is: <Call-ID><CSeq>
213 * (RFC3261 17.2.3 for matching server transactions: Request-URI, To tag, From tag, Call-ID, CSeq, and top Via)
217 TransCallback callback
;
218 struct transaction_payload
*payload
;
221 typedef void (*Action
) (struct sipe_account_data
*, void *);
224 * Do schedule action for execution in the future.
225 * Non repetitive execution.
227 * @param name of action (will be copied)
228 * @param timeout in seconds
229 * @param action callback function
230 * @param destroy payload destroy function
232 * @param payload callback data (can be NULL, otherwise caller must allocate memory)
235 sipe_schedule_action(const gchar
*name
,
238 GDestroyNotify destroy
,
239 struct sipe_account_data
*sip
,
245 PurpleGroup
*purple_group
;
248 struct group_user_context
{
253 GSList
* slist_insert_unique_sorted(GSList
*list
, gpointer data
, GCompareFunc func
);
255 GList
*sipe_actions(PurplePlugin
*plugin
, gpointer context
);
257 gboolean
purple_init_plugin(PurplePlugin
*plugin
);
260 * THE BIG SPLIT - temporary interfaces
262 * Previously private functions in sipe.c that are
263 * - waiting to be factored out to an appropriate module
264 * - are needed by the already created new modules
269 * Since SIP (RFC3261) is extensible by its design,
270 * and MS specs prove just that (they all are defined as SIP extensions),
271 * it make sense to split functionality by extension (or close extension group).
272 * For example: conference, presence (MS-PRES), etc.
274 * This way our code will not be monolithic, but potentially _reusable_. May be
275 * a top of other SIP core, and/or other front-end (Telepathy framework?).
277 /* Forward declarations */
281 /* SIP send module? */
283 send_sip_request(PurpleConnection
*gc
, const gchar
*method
,
284 const gchar
*url
, const gchar
*to
, const gchar
*addheaders
,
285 const gchar
*body
, struct sip_dialog
*dialog
, TransCallback tc
);
287 send_sip_response(PurpleConnection
*gc
, struct sipmsg
*msg
, int code
,
288 const char *text
, const char *body
);
290 sipe_invite(struct sipe_account_data
*sip
, struct sip_session
*session
,
291 const gchar
*who
, const gchar
*msg_body
,
292 const gchar
*referred_by
, const gboolean is_triggered
);
294 gboolean
process_subscribe_response(struct sipe_account_data
*sip
,
296 struct transaction
*tc
);
299 sipe_invite_to_chat(struct sipe_account_data
*sip
,
300 struct sip_session
*session
,
302 /* Session module? */
304 sipe_present_message_undelivered_err(struct sipe_account_data
*sip
,
305 struct sip_session
*session
,
308 const gchar
*message
);
311 sipe_present_info(struct sipe_account_data
*sip
,
312 struct sip_session
*session
,
313 const gchar
*message
);
317 sipe_process_pending_invite_queue(struct sipe_account_data
*sip
,
318 struct sip_session
*session
);
320 /*** THE BIG SPLIT END ***/
322 #define SIPE_INVITE_TEXT "ms-text-format: text/plain; charset=UTF-8%s;ms-body=%s\r\n"
324 #define SIPE_SEND_TYPING \
325 "<?xml version=\"1.0\"?>"\
326 "<KeyboardActivity>"\
327 "<status status=\"type\" />"\
328 "</KeyboardActivity>"
331 * Publishes categories.
332 * @param uri (%s) Self URI. Ex.: sip:alice7@boston.local
333 * @param publications (%s) XML publications
335 #define SIPE_SEND_PRESENCE \
336 "<publish xmlns=\"http://schemas.microsoft.com/2006/09/sip/rich-presence\">"\
337 "<publications uri=\"%s\">"\
343 * Publishes 'device' category.
344 * @param instance (%u) Ex.: 1938468728
345 * @param version (%u) Ex.: 1
346 * @param endpointId (%s) Ex.: C707E38E-1E10-5413-94D9-ECAC260A0269
347 * @param uri (%s) Self URI. Ex.: sip:alice7@boston.local
348 * @param timezone (%s) Ex.: 00:00:00+01:00
349 * @param machineName (%s) Ex.: BOSTON-OCS07
351 #define SIPE_PUB_XML_DEVICE \
352 "<publication categoryName=\"device\" instance=\"%u\" container=\"2\" version=\"%u\" expireType=\"endpoint\">"\
353 "<device xmlns=\"http://schemas.microsoft.com/2006/09/sip/device\" endpointId=\"%s\">"\
354 "<capabilities preferred=\"false\" uri=\"%s\">"\
355 "<text capture=\"true\" render=\"true\" publish=\"false\"/>"\
356 "<gifInk capture=\"false\" render=\"true\" publish=\"false\"/>"\
357 "<isfInk capture=\"false\" render=\"true\" publish=\"false\"/>"\
359 "<timezone>%s</timezone>"\
360 "<machineName>%s</machineName>"\
365 * Publishes 'machineState' category.
366 * @param instance (%u) Ex.: 926460663
367 * @param version (%u) Ex.: 22
368 * @param availability (%d) Ex.: 3500
369 * @param instance (%u) Ex.: 926460663
370 * @param version (%u) Ex.: 22
371 * @param availability (%d) Ex.: 3500
373 #define SIPE_PUB_XML_STATE_MACHINE \
374 "<publication categoryName=\"state\" instance=\"%u\" container=\"2\" version=\"%u\" expireType=\"endpoint\">"\
375 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"machineState\">"\
376 "<availability>%d</availability>"\
377 "<endpointLocation/>"\
380 "<publication categoryName=\"state\" instance=\"%u\" container=\"3\" version=\"%u\" expireType=\"endpoint\">"\
381 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"machineState\">"\
382 "<availability>%d</availability>"\
383 "<endpointLocation/>"\
388 * Publishes 'userState' category.
389 * @param instance (%u) User. Ex.: 536870912
390 * @param version (%u) User Container 2. Ex.: 22
391 * @param availability (%d) User Container 2. Ex.: 15500
392 * @param instance (%u) User. Ex.: 536870912
393 * @param version (%u) User Container 3.Ex.: 22
394 * @param availability (%d) User Container 3. Ex.: 15500
396 #define SIPE_PUB_XML_STATE_USER \
397 "<publication categoryName=\"state\" instance=\"%u\" container=\"2\" version=\"%u\" expireType=\"static\">"\
398 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"userState\">"\
399 "<availability>%d</availability>"\
400 "<endpointLocation/>"\
403 "<publication categoryName=\"state\" instance=\"%u\" container=\"3\" version=\"%u\" expireType=\"static\">"\
404 "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" manual=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"userState\">"\
405 "<availability>%d</availability>"\
406 "<endpointLocation/>"\
411 * Publishes 'note' category.
412 * @param version (%u) Ex.: 2
413 * @param body (%s) Ex.: In the office
414 * @param version (%u) Ex.: 2
415 * @param body (%s) Ex.: In the office
416 * @param version (%u) Ex.: 2
417 * @param body (%s) Ex.: In the office
419 #define SIPE_PUB_XML_NOTE \
420 "<publication categoryName=\"note\" instance=\"0\" container=\"200\" version=\"%d\" expireType=\"static\">"\
421 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
422 "<body type=\"personal\" uri=\"\">%s</body>"\
425 "<publication categoryName=\"note\" instance=\"0\" container=\"300\" version=\"%d\" expireType=\"static\">"\
426 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
427 "<body type=\"personal\" uri=\"\">%s</body>"\
430 "<publication categoryName=\"note\" instance=\"0\" container=\"400\" version=\"%d\" expireType=\"static\">"\
431 "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\">"\
432 "<body type=\"personal\" uri=\"\">%s</body>"\
437 #define sipe_soap(method, body) \
438 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
440 "<m:" method " xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
444 "</SOAP-ENV:Envelope>"
446 #define SIPE_SOAP_SET_CONTACT sipe_soap("setContact", \
447 "<m:displayName>%s</m:displayName>"\
448 "<m:groups>%s</m:groups>"\
449 "<m:subscribed>%s</m:subscribed>"\
452 "<m:deltaNum>%d</m:deltaNum>")
454 #define SIPE_SOAP_DEL_CONTACT sipe_soap("deleteContact", \
456 "<m:deltaNum>%d</m:deltaNum>")
458 #define SIPE_SOAP_ADD_GROUP sipe_soap("addGroup", \
459 "<m:name>%s</m:name>"\
461 "<m:deltaNum>%d</m:deltaNum>")
463 #define SIPE_SOAP_MOD_GROUP sipe_soap("modifyGroup", \
464 "<m:groupID>%d</m:groupID>"\
465 "<m:name>%s</m:name>"\
467 "<m:deltaNum>%d</m:deltaNum>")
469 #define SIPE_SOAP_DEL_GROUP sipe_soap("deleteGroup", \
470 "<m:groupID>%d</m:groupID>"\
471 "<m:deltaNum>%d</m:deltaNum>")
473 // first/mask arg is sip:user@domain.com
474 // second/rights arg is AA for allow, BD for deny
475 #define SIPE_SOAP_ALLOW_DENY sipe_soap("setACE", \
476 "<m:type>USER</m:type>"\
477 "<m:mask>%s</m:mask>"\
478 "<m:rights>%s</m:rights>"\
479 "<m:deltaNum>%d</m:deltaNum>")
481 #define SIPE_SOAP_SET_PRESENCE_NOTE_XML "<note>%s</note>"
482 #define SIPE_SOAP_SET_PRESENCE_NOTE_XML_EMPTY "%s"
483 #define SIPE_SOAP_SET_PRESENCE(note_xml) sipe_soap("setPresence", \
484 "<m:presentity m:uri=\"sip:%s\">"\
485 "<m:availability m:aggregate=\"%d\"/>"\
486 "<m:activity m:aggregate=\"%d\" m:note=\"%s\"/>"\
487 "<deviceName xmlns=\"http://schemas.microsoft.com/2002/09/sip/presence\" name=\"USER-DESKTOP\"/>"\
488 "<rtc:devicedata xmlns:rtc=\"http://schemas.microsoft.com/winrtc/2002/11/sip\" namespace=\"rtcService\">"\
489 "<![CDATA[<caps><renders_gif/><renders_isf/></caps>]]></rtc:devicedata>"\
490 "<userInfo xmlns=\"http://schemas.microsoft.com/2002/09/sip/presence\">"\
495 #define SIPE_SOAP_SEARCH_CONTACT \
496 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
498 "<m:directorySearch xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\">" \
499 "<m:filter m:href=\"#searchArray\"/>"\
500 "<m:maxResults>%d</m:maxResults>"\
501 "</m:directorySearch>"\
502 "<m:Array xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\" m:id=\"searchArray\">"\
506 "</SOAP-ENV:Envelope>"
508 #define SIPE_SOAP_SEARCH_ROW "<m:row m:attrib=\"%s\" m:value=\"%s\"/>"
510 #endif /* _PIDGIN_SIPE_H */