2 * @file sipe-subscriptions.c
6 * Copyright (C) 2010-2013 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "sipe-common.h"
30 #include "sip-transport.h"
31 #include "sipe-backend.h"
32 #include "sipe-buddy.h"
33 #include "sipe-core.h"
34 #include "sipe-core-private.h"
35 #include "sipe-dialog.h"
36 #include "sipe-mime.h"
37 #include "sipe-notify.h"
38 #include "sipe-schedule.h"
39 #include "sipe-subscriptions.h"
40 #include "sipe-utils.h"
43 /* RFC3265 subscription */
44 struct sip_subscription
{
45 struct sip_dialog dialog
;
47 GSList
*buddies
; /* batched subscriptions */
50 static void sipe_subscription_free(struct sip_subscription
*subscription
)
53 if (!subscription
) return;
55 g_free(subscription
->event
);
56 sipe_utils_slist_free_full(subscription
->buddies
, g_free
);
58 /* NOTE: use cast to prevent BAD_FREE warning from Coverity */
59 sipe_dialog_free((struct sip_dialog
*) subscription
);
62 void sipe_subscriptions_init(struct sipe_core_private
*sipe_private
)
64 sipe_private
->subscriptions
= g_hash_table_new_full(g_str_hash
,
67 (GDestroyNotify
)sipe_subscription_free
);
70 static void sipe_unsubscribe_cb(SIPE_UNUSED_PARAMETER gpointer key
,
71 gpointer value
, gpointer user_data
)
73 struct sip_subscription
*subscription
= value
;
74 struct sip_dialog
*dialog
= &subscription
->dialog
;
75 struct sipe_core_private
*sipe_private
= user_data
;
76 gchar
*contact
= get_contact(sipe_private
);
77 gchar
*hdr
= g_strdup_printf(
80 "Contact: %s\r\n", subscription
->event
, contact
);
83 /* Rate limit to max. 25 requests per seconds */
84 g_usleep(1000000 / 25);
86 sip_transport_subscribe(sipe_private
,
96 void sipe_subscriptions_unsubscribe(struct sipe_core_private
*sipe_private
)
99 g_hash_table_foreach(sipe_private
->subscriptions
,
105 void sipe_subscriptions_destroy(struct sipe_core_private
*sipe_private
)
107 g_hash_table_destroy(sipe_private
->subscriptions
);
110 static void sipe_subscription_remove(struct sipe_core_private
*sipe_private
,
113 if (g_hash_table_lookup(sipe_private
->subscriptions
, key
)) {
114 g_hash_table_remove(sipe_private
->subscriptions
, key
);
115 SIPE_DEBUG_INFO("sipe_subscription_remove: %s", key
);
120 * Generate subscription key
122 * @param event event name (must not by @c NULL)
123 * @param uri presence URI (ignored if @c event != "presence")
125 * @return key string. Must be g_free()'d after use.
127 static gchar
*sipe_subscription_key(const gchar
*event
,
130 if (!g_ascii_strcasecmp(event
, "presence"))
131 /* Subscription is identified by <presence><uri> key */
132 return(sipe_utils_presence_key(uri
));
134 /* Subscription is identified by <event> key */
135 return(g_strdup_printf("<%s>", event
));
138 static struct sip_dialog
*sipe_subscribe_dialog(struct sipe_core_private
*sipe_private
,
141 struct sip_dialog
*dialog
= g_hash_table_lookup(sipe_private
->subscriptions
,
143 SIPE_DEBUG_INFO("sipe_subscribe_dialog: dialog for '%s' is %s", key
, dialog
? "not NULL" : "NULL");
147 static void sipe_subscription_expiration(struct sipe_core_private
*sipe_private
,
150 static gboolean
process_subscribe_response(struct sipe_core_private
*sipe_private
,
152 struct transaction
*trans
)
154 gchar
*with
= parse_from(sipmsg_find_header(msg
, "To"));
155 const gchar
*event
= sipmsg_find_header(msg
, "Event");
157 /* The case with 2005 Public IM Connectivity (PIC) - no Event header */
159 struct sipmsg
*request_msg
= trans
->msg
;
160 event
= sipmsg_find_header(request_msg
, "Event");
164 const gchar
*subscription_state
= sipmsg_find_header(msg
, "subscription-state");
165 gboolean terminated
= subscription_state
&& strstr(subscription_state
, "terminated");
166 gchar
*key
= sipe_subscription_key(event
, with
);
169 * @TODO: does the server send this only for one-off
170 * subscriptions, i.e. the ones which anyway
174 SIPE_DEBUG_INFO("process_subscribe_response: subscription '%s' to '%s' was terminated",
177 /* 481 Call Leg Does Not Exist */
178 if ((msg
->response
== 481) || terminated
) {
179 sipe_subscription_remove(sipe_private
, key
);
181 /* create/store subscription dialog if not yet */
182 } else if (msg
->response
== 200) {
183 struct sip_dialog
*dialog
= sipe_subscribe_dialog(sipe_private
, key
);
186 struct sip_subscription
*subscription
= g_new0(struct sip_subscription
, 1);
188 SIPE_DEBUG_INFO("process_subscribe_response: subscription dialog added for event '%s'",
191 g_hash_table_insert(sipe_private
->subscriptions
,
194 key
= NULL
; /* table takes ownership of key */
196 subscription
->dialog
.callid
= g_strdup(sipmsg_find_header(msg
, "Call-ID"));
197 subscription
->dialog
.cseq
= sipmsg_parse_cseq(msg
);
198 subscription
->dialog
.with
= g_strdup(with
);
199 subscription
->event
= g_strdup(event
);
201 dialog
= &subscription
->dialog
;
204 sipe_dialog_parse(dialog
, msg
, TRUE
);
206 sipe_subscription_expiration(sipe_private
, msg
, event
);
212 if (sipmsg_find_header(msg
, "ms-piggyback-cseq"))
213 process_incoming_notify(sipe_private
, msg
);
219 * common subscription code
221 static void sipe_subscribe(struct sipe_core_private
*sipe_private
,
225 const gchar
*addheaders
,
227 struct sip_dialog
*dialog
)
229 gchar
*contact
= get_contact(sipe_private
);
230 gchar
*hdr
= g_strdup_printf(
233 "Supported: com.microsoft.autoextend\r\n"
234 "Supported: ms-benotify\r\n"
235 "Proxy-Require: ms-benotify\r\n"
236 "Supported: ms-piggyback-first-notify\r\n"
241 addheaders
? addheaders
: "",
245 sip_transport_subscribe(sipe_private
,
250 process_subscribe_response
);
255 * common subscription code for self-subscriptions
257 static void sipe_subscribe_self(struct sipe_core_private
*sipe_private
,
260 const gchar
*addheaders
,
263 gchar
*self
= sip_uri_self(sipe_private
);
264 gchar
*key
= sipe_subscription_key(event
, self
);
265 struct sip_dialog
*dialog
= sipe_subscribe_dialog(sipe_private
, key
);
267 sipe_subscribe(sipe_private
,
278 static void sipe_subscribe_presence_wpending(struct sipe_core_private
*sipe_private
,
279 SIPE_UNUSED_PARAMETER
void *unused
)
281 sipe_subscribe_self(sipe_private
,
283 "text/xml+msrtc.wpending",
289 * Subscribe roaming ACL
291 static void sipe_subscribe_roaming_acl(struct sipe_core_private
*sipe_private
,
292 SIPE_UNUSED_PARAMETER
void *unused
)
294 sipe_subscribe_self(sipe_private
,
295 "vnd-microsoft-roaming-ACL",
296 "application/vnd-microsoft-roaming-acls+xml",
302 * Subscribe roaming contacts
304 static void sipe_subscribe_roaming_contacts(struct sipe_core_private
*sipe_private
,
305 SIPE_UNUSED_PARAMETER
void *unused
)
307 sipe_subscribe_self(sipe_private
,
308 "vnd-microsoft-roaming-contacts",
309 "application/vnd-microsoft-roaming-contacts+xml",
317 static void sipe_subscribe_roaming_provisioning(struct sipe_core_private
*sipe_private
,
318 SIPE_UNUSED_PARAMETER
void *unused
)
320 sipe_subscribe_self(sipe_private
,
321 "vnd-microsoft-provisioning",
322 "application/vnd-microsoft-roaming-provisioning+xml",
328 * Subscription for provisioning information to help with initial
329 * configuration. This subscription is a one-time query (denoted by the
330 * Expires header, which asks for 0 seconds for the subscription lifetime).
331 * This subscription asks for server configuration, meeting policies, and
332 * policy settings that Communicator must enforce.
334 static void sipe_subscribe_roaming_provisioning_v2(struct sipe_core_private
*sipe_private
,
335 SIPE_UNUSED_PARAMETER
void *unused
)
337 sipe_subscribe_self(sipe_private
,
338 "vnd-microsoft-provisioning-v2",
339 "application/vnd-microsoft-roaming-provisioning-v2+xml",
341 "Content-Type: application/vnd-microsoft-roaming-provisioning-v2+xml\r\n",
342 "<provisioningGroupList xmlns=\"http://schemas.microsoft.com/2006/09/sip/provisioninggrouplist\">"
343 "<provisioningGroup name=\"ServerConfiguration\"/><provisioningGroup name=\"meetingPolicy\"/>"
344 "<provisioningGroup name=\"ucPolicy\"/>"
345 "</provisioningGroupList>");
349 * To request for presence information about the user, access level settings
350 * that have already been configured by the user to control who has access to
351 * what information, and the list of contacts who currently have outstanding
354 * We wait for (BE)NOTIFY messages with some info change (categories,
355 * containers, subscribers)
357 static void sipe_subscribe_roaming_self(struct sipe_core_private
*sipe_private
,
358 SIPE_UNUSED_PARAMETER
void *unused
)
360 sipe_subscribe_self(sipe_private
,
361 "vnd-microsoft-roaming-self",
362 "application/vnd-microsoft-roaming-self+xml",
363 "Content-Type: application/vnd-microsoft-roaming-self+xml\r\n",
364 "<roamingList xmlns=\"http://schemas.microsoft.com/2006/09/sip/roaming-self\">"
365 "<roaming type=\"categories\"/>"
366 "<roaming type=\"containers\"/>"
367 "<roaming type=\"subscribers\"/></roamingList>");
370 static void sipe_presence_timeout_mime_cb(gpointer user_data
,
371 SIPE_UNUSED_PARAMETER
const GSList
*fields
,
375 GSList
**buddies
= user_data
;
376 sipe_xml
*xml
= sipe_xml_parse(body
, length
);
378 if (xml
&& !sipe_strequal(sipe_xml_name(xml
), "list")) {
379 const gchar
*uri
= sipe_xml_attribute(xml
, "uri");
380 const sipe_xml
*xn_category
;
383 * automaton: presence is never expected to change
385 * see: http://msdn.microsoft.com/en-us/library/ee354295(office.13).aspx
387 for (xn_category
= sipe_xml_child(xml
, "category");
389 xn_category
= sipe_xml_twin(xn_category
)) {
390 if (sipe_strequal(sipe_xml_attribute(xn_category
, "name"),
392 const sipe_xml
*node
= sipe_xml_child(xn_category
, "contactCard/automaton");
394 char *boolean
= sipe_xml_data(node
);
395 if (sipe_strequal(boolean
, "true")) {
396 SIPE_DEBUG_INFO("sipe_process_presence_timeout: %s is an automaton: - not subscribing to presence updates",
407 *buddies
= g_slist_append(*buddies
, sip_uri(uri
));
414 static void sipe_subscribe_presence_batched_schedule(struct sipe_core_private
*sipe_private
,
415 const gchar
*action_name
,
419 static void sipe_process_presence_timeout(struct sipe_core_private
*sipe_private
,
424 const char *ctype
= sipmsg_find_header(msg
, "Content-Type");
425 gchar
*action_name
= sipe_utils_presence_key(who
);
427 SIPE_DEBUG_INFO("sipe_process_presence_timeout: Content-Type: %s", ctype
? ctype
: "");
430 strstr(ctype
, "multipart") &&
431 (strstr(ctype
, "application/rlmi+xml") ||
432 strstr(ctype
, "application/msrtc-event-categories+xml"))) {
433 GSList
*buddies
= NULL
;
435 sipe_mime_parts_foreach(ctype
, msg
->body
, sipe_presence_timeout_mime_cb
, &buddies
);
438 sipe_subscribe_presence_batched_schedule(sipe_private
,
445 sipe_schedule_seconds(sipe_private
,
449 sipe_subscribe_presence_single_cb
,
451 SIPE_DEBUG_INFO("Resubscription single contact with batched support(%s) in %d seconds", who
, timeout
);
457 * @param expires not respected if set to negative value (E.g. -1)
459 void sipe_subscribe_conference(struct sipe_core_private
*sipe_private
,
463 sipe_subscribe(sipe_private
,
466 "application/conference-info+xml",
467 expires
? "Expires: 0\r\n" : NULL
,
473 * code for presence subscription
475 static void sipe_subscribe_presence_buddy(struct sipe_core_private
*sipe_private
,
477 const gchar
*request
,
480 gchar
*key
= sipe_utils_presence_key(uri
);
482 sip_transport_subscribe(sipe_private
,
486 sipe_subscribe_dialog(sipe_private
, key
),
487 process_subscribe_response
);
493 * if to == NULL: initial single subscription
494 * OCS2005: send to URI
495 * OCS2007: send to self URI
498 * Single Category SUBSCRIBE [MS-PRES] ; To send when the server returns a 200 OK message with state="resubscribe" in response.
499 * The user sends a single SUBSCRIBE request to the subscribed contact.
500 * The To-URI and the URI listed in the resource list MUST be the same for a single category SUBSCRIBE request.
503 void sipe_subscribe_presence_single(struct sipe_core_private
*sipe_private
,
508 gchar
*contact
= get_contact(sipe_private
);
510 gchar
*content
= NULL
;
511 const gchar
*additional
= "";
512 const gchar
*content_type
= "";
513 struct sipe_buddy
*sbuddy
= g_hash_table_lookup(sipe_private
->buddies
, uri
);
515 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
516 content_type
= "Content-Type: application/msrtc-adrl-categorylist+xml\r\n";
517 content
= g_strdup_printf("<batchSub xmlns=\"http://schemas.microsoft.com/2006/01/sip/batch-subscribe\" uri=\"sip:%s\" name=\"\">\n"
518 "<action name=\"subscribe\" id=\"63792024\"><adhocList>\n"
519 "<resource uri=\"%s\"%s\n"
521 "<categoryList xmlns=\"http://schemas.microsoft.com/2006/09/sip/categorylist\">\n"
522 "<category name=\"calendarData\"/>\n"
523 "<category name=\"contactCard\"/>\n"
524 "<category name=\"note\"/>\n"
525 "<category name=\"state\"/>\n"
529 sipe_private
->username
,
531 sbuddy
&& sbuddy
->just_added
? "><context/></resource>" : "/>");
533 additional
= "Require: adhoclist, categoryList\r\n" \
534 "Supported: eventlist\r\n";
535 to
= self
= sip_uri_self(sipe_private
);
539 additional
= "Supported: com.microsoft.autoextend\r\n";
545 sbuddy
->just_added
= FALSE
;
547 request
= g_strdup_printf("Accept: application/msrtc-event-categories+xml, text/xml+msrtc.pidf, application/xpidf+xml, application/pidf+xml, application/rlmi+xml, multipart/related\r\n"
548 "Supported: ms-piggyback-first-notify\r\n"
549 "%s%sSupported: ms-benotify\r\n"
550 "Proxy-Require: ms-benotify\r\n"
551 "Event: presence\r\n"
558 sipe_subscribe_presence_buddy(sipe_private
, to
, request
, content
);
565 void sipe_subscribe_presence_single_cb(struct sipe_core_private
*sipe_private
,
568 sipe_subscribe_presence_single(sipe_private
, uri
, NULL
);
573 * Support for Batch Category SUBSCRIBE [MS-PRES] - msrtc-event-categories+xml OCS 2007
574 * Support for Batch Category SUBSCRIBE [MS-SIP] - adrl+xml LCS 2005
575 * The user sends an initial batched category SUBSCRIBE request against all contacts on his roaming list in only a request
576 * A batch category SUBSCRIBE request MUST have the same To-URI and From-URI.
577 * This header will be send only if adhoclist there is a "Supported: adhoclist" in REGISTER answer else will be send a Single Category SUBSCRIBE
579 static void sipe_subscribe_presence_batched_to(struct sipe_core_private
*sipe_private
,
580 gchar
*resources_uri
,
583 gchar
*contact
= get_contact(sipe_private
);
586 const gchar
*require
= "";
587 const gchar
*accept
= "";
588 const gchar
*autoextend
= "";
589 const gchar
*content_type
;
591 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
592 require
= ", categoryList";
593 accept
= ", application/msrtc-event-categories+xml, application/xpidf+xml, application/pidf+xml";
594 content_type
= "application/msrtc-adrl-categorylist+xml";
595 content
= g_strdup_printf("<batchSub xmlns=\"http://schemas.microsoft.com/2006/01/sip/batch-subscribe\" uri=\"sip:%s\" name=\"\">\n"
596 "<action name=\"subscribe\" id=\"63792024\">\n"
597 "<adhocList>\n%s</adhocList>\n"
598 "<categoryList xmlns=\"http://schemas.microsoft.com/2006/09/sip/categorylist\">\n"
599 "<category name=\"calendarData\"/>\n"
600 "<category name=\"contactCard\"/>\n"
601 "<category name=\"note\"/>\n"
602 "<category name=\"state\"/>\n"
606 sipe_private
->username
,
609 autoextend
= "Supported: com.microsoft.autoextend\r\n";
610 content_type
= "application/adrl+xml";
611 content
= g_strdup_printf("<adhoclist xmlns=\"urn:ietf:params:xml:ns:adrl\" uri=\"sip:%s\" name=\"sip:%s\">\n"
612 "<create xmlns=\"\">\n%s</create>\n"
614 sipe_private
->username
,
615 sipe_private
->username
,
618 g_free(resources_uri
);
620 request
= g_strdup_printf("Require: adhoclist%s\r\n"
621 "Supported: eventlist\r\n"
622 "Accept: application/rlmi+xml, multipart/related, text/xml+msrtc.pidf%s\r\n"
623 "Supported: ms-piggyback-first-notify\r\n"
624 "%sSupported: ms-benotify\r\n"
625 "Proxy-Require: ms-benotify\r\n"
626 "Event: presence\r\n"
627 "Content-Type: %s\r\n"
636 sipe_subscribe_presence_buddy(sipe_private
, to
, request
, content
);
643 struct presence_batched_routed
{
645 const GSList
*buddies
; /* points to subscription->buddies */
648 static void sipe_subscribe_presence_batched_routed_free(gpointer payload
)
650 struct presence_batched_routed
*data
= payload
;
655 static void sipe_subscribe_presence_batched_routed(struct sipe_core_private
*sipe_private
,
658 struct presence_batched_routed
*data
= payload
;
659 const GSList
*buddies
= data
->buddies
;
660 gchar
*resources_uri
= g_strdup("");
662 gchar
*tmp
= resources_uri
;
663 resources_uri
= g_strdup_printf("%s<resource uri=\"%s\"/>\n", tmp
, (char *) buddies
->data
);
665 buddies
= buddies
->next
;
667 sipe_subscribe_presence_batched_to(sipe_private
, resources_uri
,
668 g_strdup(data
->host
));
671 static void sipe_subscribe_presence_batched_schedule(struct sipe_core_private
*sipe_private
,
672 const gchar
*action_name
,
677 struct sip_subscription
*subscription
= g_hash_table_lookup(sipe_private
->subscriptions
,
679 struct presence_batched_routed
*payload
= g_malloc(sizeof(struct presence_batched_routed
));
681 if (subscription
->buddies
) {
682 /* merge old and new list */
683 GSList
*entry
= buddies
;
685 subscription
->buddies
= sipe_utils_slist_insert_unique_sorted(subscription
->buddies
,
686 g_strdup(entry
->data
),
687 (GCompareFunc
) g_ascii_strcasecmp
,
691 sipe_utils_slist_free_full(buddies
, g_free
);
693 /* no list yet, simply take ownership of whole list */
694 subscription
->buddies
= buddies
;
697 payload
->host
= g_strdup(who
);
698 payload
->buddies
= subscription
->buddies
;
699 sipe_schedule_seconds(sipe_private
,
703 sipe_subscribe_presence_batched_routed
,
704 sipe_subscribe_presence_batched_routed_free
);
705 SIPE_DEBUG_INFO("Resubscription multiple contacts with batched support & route(%s) in %d", who
, timeout
);
708 static void sipe_subscribe_resource_uri_with_context(const gchar
*name
,
710 gchar
**resources_uri
)
712 struct sipe_buddy
*sbuddy
= (struct sipe_buddy
*)value
;
713 gchar
*context
= sbuddy
&& sbuddy
->just_added
? "><context/></resource>" : "/>";
714 gchar
*tmp
= *resources_uri
;
716 /* should be enough to include context one time */
718 sbuddy
->just_added
= FALSE
;
720 *resources_uri
= g_strdup_printf("%s<resource uri=\"%s\"%s\n", tmp
, name
, context
);
724 static void sipe_subscribe_resource_uri(const char *name
,
725 SIPE_UNUSED_PARAMETER gpointer value
,
726 gchar
**resources_uri
)
728 gchar
*tmp
= *resources_uri
;
729 *resources_uri
= g_strdup_printf("%s<resource uri=\"%s\"/>\n", tmp
, name
);
733 void sipe_subscribe_presence_batched(struct sipe_core_private
*sipe_private
)
735 gchar
*to
= sip_uri_self(sipe_private
);
736 gchar
*resources_uri
= g_strdup("");
737 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
738 g_hash_table_foreach(sipe_private
->buddies
,
739 (GHFunc
) sipe_subscribe_resource_uri_with_context
,
742 g_hash_table_foreach(sipe_private
->buddies
,
743 (GHFunc
) sipe_subscribe_resource_uri
,
746 sipe_subscribe_presence_batched_to(sipe_private
, resources_uri
, to
);
749 void sipe_subscribe_poolfqdn_resource_uri(const char *host
,
751 struct sipe_core_private
*sipe_private
)
753 struct presence_batched_routed
*payload
= g_malloc(sizeof(struct presence_batched_routed
));
754 SIPE_DEBUG_INFO("process_incoming_notify_rlmi_resub: pool(%s)", host
);
755 payload
->host
= g_strdup(host
);
756 payload
->buddies
= server
;
757 sipe_subscribe_presence_batched_routed(sipe_private
,
759 sipe_subscribe_presence_batched_routed_free(payload
);
760 sipe_utils_slist_free_full(server
, g_free
);
765 * subscription expiration handling
767 struct event_subscription_data
{
769 sipe_schedule_action callback
;
773 #define EVENT_OCS2005 0x00000001
774 #define EVENT_OCS2007 0x00000002
776 static const struct event_subscription_data events_table
[] =
779 * For 2007+ it does not make sence to subscribe to:
782 * vnd-microsoft-roaming-ACL
783 * vnd-microsoft-provisioning (not v2)
785 * These are only needed as backward compatibility for older clients
787 * For 2005- we publish our initial statuses only after we received
788 * our existing UserInfo data in response to self subscription.
789 * Only in this case we won't override existing UserInfo data
790 * set earlier or by other client on our behalf.
792 * For 2007+ we publish our initial statuses and calendar data only
793 * after we received our existing publications in roaming_self.
794 * Only in this case we know versions of current publications made
797 { "presence.wpending", sipe_subscribe_presence_wpending
,
799 { "vnd-microsoft-roaming-ACL", sipe_subscribe_roaming_acl
,
801 { "vnd-microsoft-roaming-contacts", sipe_subscribe_roaming_contacts
,
802 EVENT_OCS2005
| EVENT_OCS2007
},
803 { "vnd-microsoft-provisioning", sipe_subscribe_roaming_provisioning
,
805 { "vnd-microsoft-provisioning-v2", sipe_subscribe_roaming_provisioning_v2
,
807 { "vnd-microsoft-roaming-self", sipe_subscribe_roaming_self
,
812 static void sipe_subscription_expiration(struct sipe_core_private
*sipe_private
,
816 const gchar
*expires_header
= sipmsg_find_header(msg
, "Expires");
817 guint timeout
= expires_header
? strtol(expires_header
, NULL
, 10) : 0;
820 /* 2 min ahead of expiration */
821 if (timeout
> 240) timeout
-= 120;
823 if (sipe_strcase_equal(event
, "presence")) {
824 gchar
*who
= parse_from(sipmsg_find_header(msg
, "To"));
826 if (SIPE_CORE_PRIVATE_FLAG_IS(BATCHED_SUPPORT
)) {
827 sipe_process_presence_timeout(sipe_private
, msg
, who
, timeout
);
829 gchar
*action_name
= sipe_utils_presence_key(who
);
830 sipe_schedule_seconds(sipe_private
,
834 sipe_subscribe_presence_single_cb
,
837 SIPE_DEBUG_INFO("Resubscription single contact '%s' in %d seconds", who
, timeout
);
842 const struct event_subscription_data
*esd
;
844 for (esd
= events_table
; esd
->event
; esd
++) {
845 if (sipe_strcase_equal(event
, esd
->event
)) {
846 gchar
*action_name
= g_strdup_printf("<%s>", event
);
847 sipe_schedule_seconds(sipe_private
,
854 SIPE_DEBUG_INFO("Resubscription to event '%s' in %d seconds", event
, timeout
);
863 * Initial event subscription
865 void sipe_subscription_self_events(struct sipe_core_private
*sipe_private
)
867 const guint mask
= SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
) ? EVENT_OCS2007
: EVENT_OCS2005
;
868 const struct event_subscription_data
*esd
;
870 /* subscribe to those events which are selected for
871 * this version and are allowed by the server */
872 for (esd
= events_table
; esd
->event
; esd
++)
873 if ((esd
->flags
& mask
) &&
874 (g_slist_find_custom(sipe_private
->allowed_events
,
876 (GCompareFunc
) g_ascii_strcasecmp
) != NULL
))
877 (*esd
->callback
)(sipe_private
, NULL
);