6 * Copyright (C) 2011-2013 SIPE Project <http://sipe.sourceforge.net/>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Process incoming SIP NOTIFY/BENOTIFY messages
40 #include "sipe-backend.h"
41 #include "sipe-buddy.h"
43 #include "sipe-conf.h"
44 #include "sipe-core.h"
45 #include "sipe-core-private.h"
46 #include "sipe-group.h"
47 #include "sipe-groupchat.h"
48 #include "sipe-media.h"
49 #include "sipe-mime.h"
51 #include "sipe-notify.h"
52 #include "sipe-ocs2005.h"
53 #include "sipe-ocs2007.h"
54 #include "sipe-status.h"
55 #include "sipe-subscriptions.h"
57 #include "sipe-utils.h"
61 static void sipe_process_provisioning(struct sipe_core_private
*sipe_private
,
64 sipe_xml
*xn_provision
;
67 xn_provision
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
68 if ((node
= sipe_xml_child(xn_provision
, "user"))) {
69 SIPE_DEBUG_INFO("sipe_process_provisioning: uri=%s", sipe_xml_attribute(node
, "uri"));
70 if ((node
= sipe_xml_child(node
, "line"))) {
71 const gchar
*line_uri
= sipe_xml_attribute(node
, "uri");
72 const gchar
*server
= sipe_xml_attribute(node
, "server");
73 SIPE_DEBUG_INFO("sipe_process_provisioning: line_uri=%s server=%s", line_uri
, server
);
74 sip_csta_open(sipe_private
, line_uri
, server
);
77 sipe_xml_free(xn_provision
);
81 static void sipe_process_provisioning_v2(struct sipe_core_private
*sipe_private
,
84 sipe_xml
*xn_provision_group_list
;
87 xn_provision_group_list
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
90 for (node
= sipe_xml_child(xn_provision_group_list
, "provisionGroup");
92 node
= sipe_xml_twin(node
)) {
93 const gchar
*node_name
= sipe_xml_attribute(node
, "name");
95 /* ServerConfiguration */
96 if (sipe_strequal("ServerConfiguration", node_name
)) {
97 const gchar
*dlx_uri_str
= SIPE_CORE_PRIVATE_FLAG_IS(REMOTE_USER
) ?
98 "dlxExternalUrl" : "dlxInternalUrl";
99 const gchar
*addressbook_uri_str
= SIPE_CORE_PRIVATE_FLAG_IS(REMOTE_USER
) ?
100 "absExternalServerUrl" : "absInternalServerUrl";
102 g_free(sipe_private
->focus_factory_uri
);
103 sipe_private
->focus_factory_uri
= sipe_xml_data(sipe_xml_child(node
, "focusFactoryUri"));
104 SIPE_DEBUG_INFO("sipe_process_provisioning_v2: sipe_private->focus_factory_uri=%s",
105 sipe_private
->focus_factory_uri
? sipe_private
->focus_factory_uri
: "");
107 g_free(sipe_private
->dlx_uri
);
108 sipe_private
->dlx_uri
= sipe_xml_data(sipe_xml_child(node
, dlx_uri_str
));
109 SIPE_DEBUG_INFO("sipe_process_provisioning_v2: sipe_private->dlx_uri=%s",
110 sipe_private
->dlx_uri
? sipe_private
->dlx_uri
: "");
112 g_free(sipe_private
->addressbook_uri
);
113 sipe_private
->addressbook_uri
= sipe_xml_data(sipe_xml_child(node
, addressbook_uri_str
));
114 SIPE_DEBUG_INFO("sipe_process_provisioning_v2: sipe_private->addressbook_uri=%s",
115 sipe_private
->addressbook_uri
? sipe_private
->addressbook_uri
: "");
118 g_free(sipe_private
->test_call_bot_uri
);
119 sipe_private
->test_call_bot_uri
= sipe_xml_data(sipe_xml_child(node
, "botSipUriForTestCall"));
120 SIPE_DEBUG_INFO("sipe_process_provisioning_v2: sipe_private->test_call_bot_uri=%s",
121 sipe_private
->test_call_bot_uri
? sipe_private
->test_call_bot_uri
: "");
123 g_free(sipe_private
->mras_uri
);
124 sipe_private
->mras_uri
= g_strstrip(sipe_xml_data(sipe_xml_child(node
, "mrasUri")));
125 SIPE_DEBUG_INFO("sipe_process_provisioning_v2: sipe_private->mras_uri=%s",
126 sipe_private
->mras_uri
? sipe_private
->mras_uri
: "");
128 if (sipe_private
->mras_uri
)
129 sipe_media_get_av_edge_credentials(sipe_private
);
132 /* persistentChatConfiguration */
133 } else if (sipe_strequal("persistentChatConfiguration", node_name
)) {
134 const sipe_xml
*property
;
135 gboolean enabled
= FALSE
;
138 for (property
= sipe_xml_child(node
, "propertyEntryList/property");
140 property
= sipe_xml_twin(property
)) {
141 const gchar
*name
= sipe_xml_attribute(property
, "name");
142 gchar
*value
= sipe_xml_data(property
);
144 if (sipe_strequal(name
, "EnablePersistentChat")) {
145 enabled
= sipe_strequal(value
, "true");
147 } else if (sipe_strequal(name
, "DefaultPersistentChatPoolUri")) {
156 g_free(sipe_private
->persistentChatPool_uri
);
157 sipe_private
->persistentChatPool_uri
= g_strdup(sipe_get_no_sip_uri(uri
));
158 SIPE_DEBUG_INFO("sipe_process_provisioning_v2: sipe_private->persistentChatPool_uri=%s",
159 sipe_private
->persistentChatPool_uri
? sipe_private
->persistentChatPool_uri
: "");
165 sipe_xml_free(xn_provision_group_list
);
167 if (sipe_private
->dlx_uri
&& sipe_private
->addressbook_uri
) {
168 /* Some buddies might have been added before we received this
169 * provisioning notify with DLX and addressbook URIs. Now we can
170 * trigger an update of their photos. */
171 sipe_buddy_refresh_photos(sipe_private
);
174 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
))
175 /* persistentChatPool_uri has been set at this point */
176 sipe_groupchat_init(sipe_private
);
179 static void process_incoming_notify_rlmi_resub(struct sipe_core_private
*sipe_private
,
180 const gchar
*data
, unsigned len
)
183 const sipe_xml
*xn_resource
;
184 GHashTable
*servers
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
187 xn_list
= sipe_xml_parse(data
, len
);
189 for (xn_resource
= sipe_xml_child(xn_list
, "resource");
191 xn_resource
= sipe_xml_twin(xn_resource
) )
193 const char *uri
, *state
;
194 const sipe_xml
*xn_instance
;
196 xn_instance
= sipe_xml_child(xn_resource
, "instance");
197 if (!xn_instance
) continue;
199 uri
= sipe_xml_attribute(xn_resource
, "uri");
200 state
= sipe_xml_attribute(xn_instance
, "state");
201 SIPE_DEBUG_INFO("process_incoming_notify_rlmi_resub: uri(%s),state(%s)", uri
, state
);
203 if (strstr(state
, "resubscribe")) {
204 const char *poolFqdn
= sipe_xml_attribute(xn_instance
, "poolFqdn");
206 if (poolFqdn
) { //[MS-PRES] Section 3.4.5.1.3 Processing Details
207 gchar
*user
= g_strdup(uri
);
208 gchar
*host
= g_strdup(poolFqdn
);
209 GSList
*server
= g_hash_table_lookup(servers
,
211 server
= g_slist_append(server
, user
);
212 g_hash_table_insert(servers
, host
, server
);
214 sipe_subscribe_presence_single(sipe_private
,
221 /* Send out any deferred poolFqdn subscriptions */
222 g_hash_table_foreach(servers
, (GHFunc
) sipe_subscribe_poolfqdn_resource_uri
, sipe_private
);
223 g_hash_table_destroy(servers
);
225 sipe_xml_free(xn_list
);
230 * Suitable for both 2005 and 2007 systems.
232 * @param uri buddy SIP URI with 'sip:' prefix whose info we want to change.
234 * @param phone may be modified to strip white space
235 * @param phone_display_string may be modified to strip white space
238 sipe_update_user_phone(struct sipe_core_private
*sipe_private
,
240 const gchar
*phone_type
,
242 gchar
*phone_display_string
)
244 sipe_buddy_info_fields phone_node
= SIPE_BUDDY_INFO_WORK_PHONE
; /* work phone by default */
245 sipe_buddy_info_fields phone_display_node
= SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY
; /* work phone by default */
247 if(!phone
|| strlen(phone
) == 0) return;
249 if ((sipe_strequal(phone_type
, "mobile") || sipe_strequal(phone_type
, "cell"))) {
250 phone_node
= SIPE_BUDDY_INFO_MOBILE_PHONE
;
251 phone_display_node
= SIPE_BUDDY_INFO_MOBILE_PHONE_DISPLAY
;
252 } else if (sipe_strequal(phone_type
, "home")) {
253 phone_node
= SIPE_BUDDY_INFO_HOME_PHONE
;
254 phone_display_node
= SIPE_BUDDY_INFO_HOME_PHONE_DISPLAY
;
255 } else if (sipe_strequal(phone_type
, "other")) {
256 phone_node
= SIPE_BUDDY_INFO_OTHER_PHONE
;
257 phone_display_node
= SIPE_BUDDY_INFO_OTHER_PHONE_DISPLAY
;
258 } else if (sipe_strequal(phone_type
, "custom1")) {
259 phone_node
= SIPE_BUDDY_INFO_CUSTOM1_PHONE
;
260 phone_display_node
= SIPE_BUDDY_INFO_CUSTOM1_PHONE_DISPLAY
;
263 sipe_buddy_update_property(sipe_private
, uri
, phone_node
, phone
);
264 if (phone_display_string
) {
265 sipe_buddy_update_property(sipe_private
, uri
, phone_display_node
, phone_display_string
);
269 static void process_incoming_notify_msrtc(struct sipe_core_private
*sipe_private
,
273 char *activity
= NULL
;
275 const char *status_id
= NULL
;
278 char *self_uri
= sip_uri_self(sipe_private
);
281 const char *device_name
= NULL
;
282 const char *cal_start_time
= NULL
;
283 const char *cal_granularity
= NULL
;
284 char *cal_free_busy_base64
= NULL
;
285 struct sipe_buddy
*sbuddy
;
286 const sipe_xml
*node
;
287 sipe_xml
*xn_presentity
;
288 const sipe_xml
*xn_availability
;
289 const sipe_xml
*xn_activity
;
290 const sipe_xml
*xn_display_name
;
291 const sipe_xml
*xn_email
;
292 const sipe_xml
*xn_phone_number
;
293 const sipe_xml
*xn_userinfo
;
294 const sipe_xml
*xn_note
;
295 const sipe_xml
*xn_oof
;
296 const sipe_xml
*xn_state
;
297 const sipe_xml
*xn_contact
;
300 const char *user_avail_nil
;
302 time_t user_avail_since
= 0;
303 time_t activity_since
= 0;
305 /* fix for Reuters environment on Linux */
306 if (data
&& strstr(data
, "encoding=\"utf-16\"")) {
308 tmp_data
= replace(data
, "encoding=\"utf-16\"", "encoding=\"utf-8\"");
309 xn_presentity
= sipe_xml_parse(tmp_data
, strlen(tmp_data
));
312 xn_presentity
= sipe_xml_parse(data
, len
);
315 xn_availability
= sipe_xml_child(xn_presentity
, "availability");
316 xn_activity
= sipe_xml_child(xn_presentity
, "activity");
317 xn_display_name
= sipe_xml_child(xn_presentity
, "displayName");
318 xn_email
= sipe_xml_child(xn_presentity
, "email");
319 xn_phone_number
= sipe_xml_child(xn_presentity
, "phoneNumber");
320 xn_userinfo
= sipe_xml_child(xn_presentity
, "userInfo");
321 xn_oof
= xn_userinfo
? sipe_xml_child(xn_userinfo
, "oof") : NULL
;
322 xn_state
= xn_userinfo
? sipe_xml_child(xn_userinfo
, "states/state"): NULL
;
323 user_avail
= xn_state
? sipe_xml_int_attribute(xn_state
, "avail", 0) : 0;
324 user_avail_since
= xn_state
? sipe_utils_str_to_time(sipe_xml_attribute(xn_state
, "since")) : 0;
325 user_avail_nil
= xn_state
? sipe_xml_attribute(xn_state
, "nil") : NULL
;
326 xn_contact
= xn_userinfo
? sipe_xml_child(xn_userinfo
, "contact") : NULL
;
327 xn_note
= xn_userinfo
? sipe_xml_child(xn_userinfo
, "note") : NULL
;
328 note
= xn_note
? sipe_xml_data(xn_note
) : NULL
;
330 if (sipe_strequal(user_avail_nil
, "true")) { /* null-ed */
332 user_avail_since
= 0;
335 name
= sipe_xml_attribute(xn_presentity
, "uri"); /* without 'sip:' prefix */
336 uri
= sip_uri_from_name(name
);
337 avl
= sipe_xml_int_attribute(xn_availability
, "aggregate", 0);
338 epid
= sipe_xml_attribute(xn_availability
, "epid");
339 act
= sipe_xml_int_attribute(xn_activity
, "aggregate", 0);
341 status_id
= sipe_ocs2005_status_from_activity_availability(act
, avl
);
342 activity
= g_strdup(sipe_ocs2005_activity_description(act
));
343 res_avail
= sipe_ocs2007_availability_from_status(status_id
, NULL
);
344 if (user_avail
> res_avail
) {
345 res_avail
= user_avail
;
346 status_id
= sipe_ocs2007_status_from_legacy_availability(user_avail
, NULL
);
349 if (xn_display_name
) {
350 char *display_name
= g_strdup(sipe_xml_attribute(xn_display_name
, "displayName"));
351 char *email
= xn_email
? g_strdup(sipe_xml_attribute(xn_email
, "email")) : NULL
;
352 char *phone_label
= xn_phone_number
? g_strdup(sipe_xml_attribute(xn_phone_number
, "label")) : NULL
;
353 char *phone_number
= xn_phone_number
? g_strdup(sipe_xml_attribute(xn_phone_number
, "number")) : NULL
;
354 char *tel_uri
= sip_to_tel_uri(phone_number
);
356 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_DISPLAY_NAME
, display_name
);
357 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_EMAIL
, email
);
358 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_WORK_PHONE
, tel_uri
);
359 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY
, !is_empty(phone_label
) ? phone_label
: phone_number
);
363 g_free(phone_number
);
365 g_free(display_name
);
370 for (node
= sipe_xml_child(xn_contact
, "tel"); node
; node
= sipe_xml_twin(node
))
372 /* Ex.: <tel type="work">tel:+3222220000</tel> */
373 const char *phone_type
= sipe_xml_attribute(node
, "type");
374 char* phone
= sipe_xml_data(node
);
376 sipe_update_user_phone(sipe_private
, uri
, phone_type
, phone
, NULL
);
382 if (xn_display_name
|| xn_contact
)
383 sipe_backend_buddy_refresh_properties(SIPE_CORE_PUBLIC
, uri
);
386 for (node
= sipe_xml_child(xn_presentity
, "devices/devicePresence"); node
; node
= sipe_xml_twin(node
)) {
387 const sipe_xml
*xn_device_name
;
388 const sipe_xml
*xn_calendar_info
;
389 const sipe_xml
*xn_state
;
393 if (sipe_strequal(sipe_xml_attribute(node
, "epid"), epid
)) {
394 xn_device_name
= sipe_xml_child(node
, "deviceName");
395 device_name
= xn_device_name
? sipe_xml_attribute(xn_device_name
, "name") : NULL
;
399 xn_calendar_info
= sipe_xml_child(node
, "calendarInfo");
400 if (xn_calendar_info
) {
401 const char *cal_start_time_tmp
= sipe_xml_attribute(xn_calendar_info
, "startTime");
403 if (cal_start_time
) {
404 time_t cal_start_time_t
= sipe_utils_str_to_time(cal_start_time
);
405 time_t cal_start_time_t_tmp
= sipe_utils_str_to_time(cal_start_time_tmp
);
407 if (cal_start_time_t_tmp
> cal_start_time_t
) {
408 cal_start_time
= cal_start_time_tmp
;
409 cal_granularity
= sipe_xml_attribute(xn_calendar_info
, "granularity");
410 g_free(cal_free_busy_base64
);
411 cal_free_busy_base64
= sipe_xml_data(xn_calendar_info
);
413 SIPE_DEBUG_INFO("process_incoming_notify_msrtc: startTime=%s granularity=%s cal_free_busy_base64=\n%s", cal_start_time
, cal_granularity
, cal_free_busy_base64
);
416 cal_start_time
= cal_start_time_tmp
;
417 cal_granularity
= sipe_xml_attribute(xn_calendar_info
, "granularity");
418 g_free(cal_free_busy_base64
);
419 cal_free_busy_base64
= sipe_xml_data(xn_calendar_info
);
421 SIPE_DEBUG_INFO("process_incoming_notify_msrtc: startTime=%s granularity=%s cal_free_busy_base64=\n%s", cal_start_time
, cal_granularity
, cal_free_busy_base64
);
426 xn_state
= sipe_xml_child(node
, "states/state");
428 int dev_avail
= sipe_xml_int_attribute(xn_state
, "avail", 0);
429 time_t dev_avail_since
= sipe_utils_str_to_time(sipe_xml_attribute(xn_state
, "since"));
431 state
= sipe_xml_data(xn_state
);
432 if (dev_avail_since
> user_avail_since
&&
433 dev_avail
>= res_avail
)
435 const gchar
*new_desc
;
436 res_avail
= dev_avail
;
437 if (!is_empty(state
)) {
438 if (sipe_strequal(state
, sipe_status_activity_to_token(SIPE_ACTIVITY_ON_PHONE
))) {
440 activity
= g_strdup(sipe_core_activity_description(SIPE_ACTIVITY_ON_PHONE
));
441 } else if (sipe_strequal(state
, "presenting")) {
443 activity
= g_strdup(sipe_core_activity_description(SIPE_ACTIVITY_IN_CONF
));
448 activity_since
= dev_avail_since
;
450 status_id
= sipe_ocs2007_status_from_legacy_availability(res_avail
, NULL
);
451 new_desc
= sipe_ocs2007_legacy_activity_description(res_avail
);
454 activity
= g_strdup(new_desc
);
462 if (xn_oof
&& res_avail
>= 15000) { /* 12000 in 2007 */
464 activity
= g_strdup(sipe_core_activity_description(SIPE_ACTIVITY_OOF
));
468 sbuddy
= sipe_buddy_find_by_uri(sipe_private
, uri
);
471 g_free(sbuddy
->activity
);
472 sbuddy
->activity
= activity
;
475 sbuddy
->activity_since
= activity_since
;
477 sbuddy
->user_avail
= user_avail
;
478 sbuddy
->user_avail_since
= user_avail_since
;
480 g_free(sbuddy
->note
);
482 if (!is_empty(note
)) { sbuddy
->note
= g_markup_escape_text(note
, -1); }
484 sbuddy
->is_oof_note
= (xn_oof
!= NULL
);
486 g_free(sbuddy
->device_name
);
487 sbuddy
->device_name
= NULL
;
488 if (!is_empty(device_name
)) { sbuddy
->device_name
= g_strdup(device_name
); }
490 if (!is_empty(cal_free_busy_base64
)) {
491 g_free(sbuddy
->cal_start_time
);
492 sbuddy
->cal_start_time
= g_strdup(cal_start_time
);
494 sbuddy
->cal_granularity
= sipe_strcase_equal(cal_granularity
, "PT15M") ? 15 : 0;
496 g_free(sbuddy
->cal_free_busy_base64
);
497 sbuddy
->cal_free_busy_base64
= cal_free_busy_base64
;
498 cal_free_busy_base64
= NULL
;
500 g_free(sbuddy
->cal_free_busy
);
501 sbuddy
->cal_free_busy
= NULL
;
504 sbuddy
->last_non_cal_status_id
= status_id
;
505 g_free(sbuddy
->last_non_cal_activity
);
506 sbuddy
->last_non_cal_activity
= g_strdup(sbuddy
->activity
);
508 if (sipe_strcase_equal(sbuddy
->name
, self_uri
)) {
509 if (!sipe_strequal(sbuddy
->note
, sipe_private
->note
)) /* not same */
511 if (sbuddy
->is_oof_note
)
512 SIPE_CORE_PRIVATE_FLAG_SET(OOF_NOTE
);
514 SIPE_CORE_PRIVATE_FLAG_UNSET(OOF_NOTE
);
516 g_free(sipe_private
->note
);
517 sipe_private
->note
= g_strdup(sbuddy
->note
);
519 sipe_private
->note_since
= time(NULL
);
522 sipe_status_set_token(sipe_private
,
523 sbuddy
->last_non_cal_status_id
);
526 g_free(cal_free_busy_base64
);
529 SIPE_DEBUG_INFO("process_incoming_notify_msrtc: status(%s)", status_id
);
530 sipe_core_buddy_got_status(SIPE_CORE_PUBLIC
, uri
,
531 sipe_status_token_to_activity(status_id
));
533 if (!SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
) && sipe_strcase_equal(self_uri
, uri
)) {
534 sipe_ocs2005_user_info_has_updated(sipe_private
, xn_userinfo
);
538 sipe_xml_free(xn_presentity
);
543 static void process_incoming_notify_rlmi(struct sipe_core_private
*sipe_private
,
548 struct sipe_buddy
*sbuddy
= NULL
;
549 sipe_xml
*xn_categories
;
550 const sipe_xml
*xn_category
;
551 const char *status
= NULL
;
552 gboolean do_update_status
= FALSE
;
553 gboolean has_note_cleaned
= FALSE
;
554 gboolean has_free_busy_cleaned
= FALSE
;
556 xn_categories
= sipe_xml_parse(data
, len
);
557 uri
= sipe_xml_attribute(xn_categories
, "uri"); /* with 'sip:' prefix */
559 sbuddy
= sipe_buddy_find_by_uri(sipe_private
, uri
);
563 /* Got presence of a buddy not in our contact list, ignore. */
564 sipe_xml_free(xn_categories
);
568 for (xn_category
= sipe_xml_child(xn_categories
, "category");
570 xn_category
= sipe_xml_twin(xn_category
) )
572 const sipe_xml
*xn_node
;
574 const char *attrVar
= sipe_xml_attribute(xn_category
, "name");
575 time_t publish_time
= (tmp
= sipe_xml_attribute(xn_category
, "publishTime")) ?
576 sipe_utils_str_to_time(tmp
) : 0;
579 if (sipe_strequal(attrVar
, "contactCard"))
581 const sipe_xml
*card
= sipe_xml_child(xn_category
, "contactCard");
584 const sipe_xml
*node
;
585 /* identity - Display Name and email */
586 node
= sipe_xml_child(card
, "identity");
588 char* display_name
= sipe_xml_data(
589 sipe_xml_child(node
, "name/displayName"));
590 char* email
= sipe_xml_data(
591 sipe_xml_child(node
, "email"));
593 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_DISPLAY_NAME
, display_name
);
594 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_EMAIL
, email
);
596 g_free(display_name
);
600 node
= sipe_xml_child(card
, "company");
602 char* company
= sipe_xml_data(node
);
603 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_COMPANY
, company
);
607 node
= sipe_xml_child(card
, "department");
609 char* department
= sipe_xml_data(node
);
610 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_DEPARTMENT
, department
);
614 node
= sipe_xml_child(card
, "title");
616 char* title
= sipe_xml_data(node
);
617 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_JOB_TITLE
, title
);
621 node
= sipe_xml_child(card
, "office");
623 char* office
= sipe_xml_data(node
);
624 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_OFFICE
, office
);
628 node
= sipe_xml_child(card
, "url");
630 char* site
= sipe_xml_data(node
);
631 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_SITE
, site
);
635 for (node
= sipe_xml_child(card
, "phone");
637 node
= sipe_xml_twin(node
))
639 const char *phone_type
= sipe_xml_attribute(node
, "type");
640 char* phone
= sipe_xml_data(sipe_xml_child(node
, "uri"));
641 char* phone_display_string
= sipe_xml_data(sipe_xml_child(node
, "displayString"));
643 sipe_update_user_phone(sipe_private
, uri
, phone_type
, phone
, phone_display_string
);
646 g_free(phone_display_string
);
649 for (node
= sipe_xml_child(card
, "address");
651 node
= sipe_xml_twin(node
))
653 if (sipe_strequal(sipe_xml_attribute(node
, "type"), "work")) {
654 char* street
= sipe_xml_data(sipe_xml_child(node
, "street"));
655 char* city
= sipe_xml_data(sipe_xml_child(node
, "city"));
656 char* state
= sipe_xml_data(sipe_xml_child(node
, "state"));
657 char* zipcode
= sipe_xml_data(sipe_xml_child(node
, "zipcode"));
658 char* country_code
= sipe_xml_data(sipe_xml_child(node
, "countryCode"));
660 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_STREET
, street
);
661 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_CITY
, city
);
662 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_STATE
, state
);
663 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_ZIPCODE
, zipcode
);
664 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_COUNTRY
, country_code
);
670 g_free(country_code
);
678 else if (sipe_strequal(attrVar
, "note"))
680 if (!has_note_cleaned
) {
681 has_note_cleaned
= TRUE
;
683 g_free(sbuddy
->note
);
685 sbuddy
->is_oof_note
= FALSE
;
686 sbuddy
->note_since
= publish_time
;
688 do_update_status
= TRUE
;
690 if (publish_time
>= sbuddy
->note_since
) {
691 /* clean up in case no 'note' element is supplied
692 * which indicate note removal in client
694 g_free(sbuddy
->note
);
696 sbuddy
->is_oof_note
= FALSE
;
697 sbuddy
->note_since
= publish_time
;
699 xn_node
= sipe_xml_child(xn_category
, "note/body");
702 sbuddy
->note
= g_markup_escape_text((tmp
= sipe_xml_data(xn_node
)), -1);
704 sbuddy
->is_oof_note
= sipe_strequal(sipe_xml_attribute(xn_node
, "type"), "OOF");
705 sbuddy
->note_since
= publish_time
;
707 SIPE_DEBUG_INFO("process_incoming_notify_rlmi: uri(%s), note(%s)",
708 uri
, sbuddy
->note
? sbuddy
->note
: "");
710 /* to trigger UI refresh in case no status info is supplied in this update */
711 do_update_status
= TRUE
;
715 else if(sipe_strequal(attrVar
, "state"))
719 const sipe_xml
*xn_availability
;
720 const sipe_xml
*xn_activity
;
721 const sipe_xml
*xn_meeting_subject
;
722 const sipe_xml
*xn_meeting_location
;
723 const gchar
*legacy_activity
;
725 xn_node
= sipe_xml_child(xn_category
, "state");
726 if (!xn_node
) continue;
727 xn_availability
= sipe_xml_child(xn_node
, "availability");
728 if (!xn_availability
) continue;
729 xn_activity
= sipe_xml_child(xn_node
, "activity");
730 xn_meeting_subject
= sipe_xml_child(xn_node
, "meetingSubject");
731 xn_meeting_location
= sipe_xml_child(xn_node
, "meetingLocation");
733 tmp
= sipe_xml_data(xn_availability
);
734 availability
= atoi(tmp
);
738 g_free(sbuddy
->activity
);
739 sbuddy
->activity
= NULL
;
741 const char *token
= sipe_xml_attribute(xn_activity
, "token");
742 const sipe_xml
*xn_custom
= sipe_xml_child(xn_activity
, "custom");
745 if (!is_empty(token
)) {
746 sbuddy
->activity
= g_strdup(sipe_core_activity_description(sipe_status_token_to_activity(token
)));
748 /* from custom element */
750 char *custom
= sipe_xml_data(xn_custom
);
752 if (!is_empty(custom
)) {
753 g_free(sbuddy
->activity
);
754 sbuddy
->activity
= custom
;
760 /* meeting_subject */
761 g_free(sbuddy
->meeting_subject
);
762 sbuddy
->meeting_subject
= NULL
;
763 if (xn_meeting_subject
) {
764 char *meeting_subject
= sipe_xml_data(xn_meeting_subject
);
766 if (!is_empty(meeting_subject
)) {
767 sbuddy
->meeting_subject
= meeting_subject
;
768 meeting_subject
= NULL
;
770 g_free(meeting_subject
);
772 /* meeting_location */
773 g_free(sbuddy
->meeting_location
);
774 sbuddy
->meeting_location
= NULL
;
775 if (xn_meeting_location
) {
776 char *meeting_location
= sipe_xml_data(xn_meeting_location
);
778 if (!is_empty(meeting_location
)) {
779 sbuddy
->meeting_location
= meeting_location
;
780 meeting_location
= NULL
;
782 g_free(meeting_location
);
785 status
= sipe_ocs2007_status_from_legacy_availability(availability
, NULL
);
786 legacy_activity
= sipe_ocs2007_legacy_activity_description(availability
);
787 if (sbuddy
->activity
&& legacy_activity
) {
788 gchar
*tmp2
= sbuddy
->activity
;
790 sbuddy
->activity
= g_strdup_printf("%s, %s", sbuddy
->activity
, legacy_activity
);
792 } else if (legacy_activity
) {
793 sbuddy
->activity
= g_strdup(legacy_activity
);
796 do_update_status
= TRUE
;
799 else if(sipe_strequal(attrVar
, "calendarData"))
801 const sipe_xml
*xn_free_busy
= sipe_xml_child(xn_category
, "calendarData/freeBusy");
802 const sipe_xml
*xn_working_hours
= sipe_xml_child(xn_category
, "calendarData/WorkingHours");
805 if (!has_free_busy_cleaned
) {
806 has_free_busy_cleaned
= TRUE
;
808 g_free(sbuddy
->cal_start_time
);
809 sbuddy
->cal_start_time
= NULL
;
811 g_free(sbuddy
->cal_free_busy_base64
);
812 sbuddy
->cal_free_busy_base64
= NULL
;
814 g_free(sbuddy
->cal_free_busy
);
815 sbuddy
->cal_free_busy
= NULL
;
817 sbuddy
->cal_free_busy_published
= publish_time
;
820 if (publish_time
>= sbuddy
->cal_free_busy_published
) {
821 g_free(sbuddy
->cal_start_time
);
822 sbuddy
->cal_start_time
= g_strdup(sipe_xml_attribute(xn_free_busy
, "startTime"));
824 sbuddy
->cal_granularity
= sipe_strcase_equal(sipe_xml_attribute(xn_free_busy
, "granularity"), "PT15M") ?
827 g_free(sbuddy
->cal_free_busy_base64
);
828 sbuddy
->cal_free_busy_base64
= sipe_xml_data(xn_free_busy
);
830 g_free(sbuddy
->cal_free_busy
);
831 sbuddy
->cal_free_busy
= NULL
;
833 sbuddy
->cal_free_busy_published
= publish_time
;
835 SIPE_DEBUG_INFO("process_incoming_notify_rlmi: startTime=%s granularity=%d cal_free_busy_base64=\n%s", sbuddy
->cal_start_time
, sbuddy
->cal_granularity
, sbuddy
->cal_free_busy_base64
);
839 if (xn_working_hours
) {
840 sipe_cal_parse_working_hours(xn_working_hours
, sbuddy
);
845 if (do_update_status
) {
849 SIPE_DEBUG_INFO("process_incoming_notify_rlmi: %s", status
);
850 activity
= sipe_status_token_to_activity(status
);
852 /* no status category in this update,
853 using contact's current status */
854 activity
= sipe_backend_buddy_get_status(SIPE_CORE_PUBLIC
,
858 sipe_core_buddy_got_status(SIPE_CORE_PUBLIC
, uri
, activity
);
861 sipe_backend_buddy_refresh_properties(SIPE_CORE_PUBLIC
, uri
);
863 sipe_xml_free(xn_categories
);
866 static void sipe_buddy_status_from_activity(struct sipe_core_private
*sipe_private
,
868 const gchar
*activity
,
872 const gchar
*status_id
= NULL
;
874 if (sipe_strequal(activity
,
875 sipe_status_activity_to_token(SIPE_ACTIVITY_BUSY
))) {
876 status_id
= sipe_status_activity_to_token(SIPE_ACTIVITY_BUSY
);
877 } else if (sipe_strequal(activity
,
878 sipe_status_activity_to_token(SIPE_ACTIVITY_AWAY
))) {
879 status_id
= sipe_status_activity_to_token(SIPE_ACTIVITY_AWAY
);
884 status_id
= sipe_status_activity_to_token(SIPE_ACTIVITY_AVAILABLE
);
887 SIPE_DEBUG_INFO("sipe_buddy_status_from_activity: status_id(%s)", status_id
);
888 sipe_core_buddy_got_status(SIPE_CORE_PUBLIC
, uri
,
889 sipe_status_token_to_activity(status_id
));
891 sipe_core_buddy_got_status(SIPE_CORE_PUBLIC
, uri
,
892 SIPE_ACTIVITY_OFFLINE
);
896 static void process_incoming_notify_pidf(struct sipe_core_private
*sipe_private
,
902 gchar
*activity
= NULL
;
904 const sipe_xml
*basicstatus
= NULL
, *tuple
, *status
;
905 gboolean isonline
= FALSE
;
906 const sipe_xml
*display_name_node
;
908 pidf
= sipe_xml_parse(data
, len
);
910 SIPE_DEBUG_INFO("process_incoming_notify_pidf: no parseable pidf:%s", data
);
914 if ((tuple
= sipe_xml_child(pidf
, "tuple")))
916 if ((status
= sipe_xml_child(tuple
, "status"))) {
917 basicstatus
= sipe_xml_child(status
, "basic");
922 SIPE_DEBUG_INFO_NOFORMAT("process_incoming_notify_pidf: no basic found");
927 getbasic
= sipe_xml_data(basicstatus
);
929 SIPE_DEBUG_INFO_NOFORMAT("process_incoming_notify_pidf: no basic data found");
934 SIPE_DEBUG_INFO("process_incoming_notify_pidf: basic-status(%s)", getbasic
);
935 if (strstr(getbasic
, "open")) {
940 uri
= sip_uri(sipe_xml_attribute(pidf
, "entity")); /* with 'sip:' prefix */ /* AOL comes without the prefix */
942 display_name_node
= sipe_xml_child(pidf
, "display-name");
943 if (display_name_node
) {
944 char * display_name
= sipe_xml_data(display_name_node
);
946 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_DISPLAY_NAME
, display_name
);
947 g_free(display_name
);
949 sipe_backend_buddy_refresh_properties(SIPE_CORE_PUBLIC
, uri
);
952 if ((tuple
= sipe_xml_child(pidf
, "tuple"))) {
953 if ((status
= sipe_xml_child(tuple
, "status"))) {
954 if ((basicstatus
= sipe_xml_child(status
, "activities"))) {
955 if ((basicstatus
= sipe_xml_child(basicstatus
, "activity"))) {
956 activity
= sipe_xml_data(basicstatus
);
957 SIPE_DEBUG_INFO("process_incoming_notify_pidf: activity(%s)", activity
);
963 sipe_buddy_status_from_activity(sipe_private
,
973 static void sipe_presence_mime_cb(gpointer user_data
, /* sipe_core_private */
974 const GSList
*fields
,
978 const gchar
*type
= sipe_utils_nameval_find(fields
, "Content-Type");
980 if (strstr(type
,"application/rlmi+xml")) {
981 process_incoming_notify_rlmi_resub(user_data
, body
, length
);
982 } else if (strstr(type
, "text/xml+msrtc.pidf")) {
983 process_incoming_notify_msrtc(user_data
, body
, length
);
985 process_incoming_notify_rlmi(user_data
, body
, length
);
989 static void sipe_process_presence(struct sipe_core_private
*sipe_private
,
992 const char *ctype
= sipmsg_find_header(msg
, "Content-Type");
994 SIPE_DEBUG_INFO("sipe_process_presence: Content-Type: %s", ctype
? ctype
: "");
997 (strstr(ctype
, "application/rlmi+xml") ||
998 strstr(ctype
, "application/msrtc-event-categories+xml")))
1000 if (strstr(ctype
, "multipart"))
1002 sipe_mime_parts_foreach(ctype
, msg
->body
, sipe_presence_mime_cb
, sipe_private
);
1004 else if(strstr(ctype
, "application/msrtc-event-categories+xml") )
1006 process_incoming_notify_rlmi(sipe_private
, msg
->body
, msg
->bodylen
);
1008 else if(strstr(ctype
, "application/rlmi+xml"))
1010 process_incoming_notify_rlmi_resub(sipe_private
, msg
->body
, msg
->bodylen
);
1013 else if(ctype
&& strstr(ctype
, "text/xml+msrtc.pidf"))
1015 process_incoming_notify_msrtc(sipe_private
, msg
->body
, msg
->bodylen
);
1019 process_incoming_notify_pidf(sipe_private
, msg
->body
, msg
->bodylen
);
1024 * Fires on deregistration event initiated by server.
1025 * [MS-SIPREGE] SIP extension.
1029 * Content-Type: text/registration-event
1030 * subscription-state: terminated;expires=0
1031 * ms-diagnostics-public: 4141;reason="User disabled"
1033 * deregistered;event=rejected
1035 static void sipe_process_registration_notify(struct sipe_core_private
*sipe_private
,
1038 const gchar
*contenttype
= sipmsg_find_header(msg
, "Content-Type");
1039 gchar
*event
= NULL
;
1040 gchar
*reason
= NULL
;
1043 SIPE_DEBUG_INFO_NOFORMAT("sipe_process_registration_notify: deregistration received.");
1045 if (!g_ascii_strncasecmp(contenttype
, "text/registration-event", 23)) {
1046 event
= sipmsg_find_part_of_header(msg
->body
, "event=", NULL
, NULL
);
1047 //@TODO have proper parameter extraction _by_name_ func, case insesitive.
1048 event
= event
? event
: sipmsg_find_part_of_header(msg
->body
, "event=", ";", NULL
);
1050 SIPE_DEBUG_INFO_NOFORMAT("sipe_process_registration_notify: unknown content type, exiting.");
1054 reason
= sipmsg_get_ms_diagnostics_reason(msg
);
1055 reason
= reason
? reason
: sipmsg_get_ms_diagnostics_public_reason(msg
);
1056 if (!reason
) { // for LCS2005
1057 if (event
&& sipe_strcase_equal(event
, "unregistered")) {
1058 //reason = g_strdup(_("User logged out")); // [MS-OCER]
1059 reason
= g_strdup(_("you are already signed in at another location"));
1060 } else if (event
&& sipe_strcase_equal(event
, "rejected")) {
1061 reason
= g_strdup(_("user disabled")); // [MS-OCER]
1062 } else if (event
&& sipe_strcase_equal(event
, "deactivated")) {
1063 reason
= g_strdup(_("user moved")); // [MS-OCER]
1067 warning
= g_strdup_printf(_("You have been rejected by the server: %s"), reason
? reason
: _("no reason given"));
1070 sipe_backend_connection_error(SIPE_CORE_PUBLIC
,
1071 SIPE_CONNECTION_ERROR_INVALID_USERNAME
,
1077 /* Replace "~" with localized version of "Other Contacts" */
1078 static const gchar
*get_group_name(const sipe_xml
*node
)
1080 const gchar
*name
= sipe_xml_attribute(node
, "name");
1081 return(g_str_has_prefix(name
, "~") ? _("Other Contacts") : name
);
1084 static void add_new_group(struct sipe_core_private
*sipe_private
,
1085 const sipe_xml
*node
)
1087 sipe_group_add(sipe_private
,
1088 get_group_name(node
),
1091 sipe_xml_int_attribute(node
, "id", 0));
1094 static void add_new_buddy(struct sipe_core_private
*sipe_private
,
1095 const sipe_xml
*node
,
1098 const gchar
*name
= sipe_xml_attribute(node
, "name");
1099 struct sipe_buddy
*buddy
= NULL
;
1101 gchar
**item_groups
;
1104 /* assign to group Other Contacts if nothing else received */
1105 tmp
= g_strdup(sipe_xml_attribute(node
, "groups"));
1106 if (is_empty(tmp
)) {
1107 struct sipe_group
*group
= sipe_group_find_by_name(sipe_private
,
1108 _("Other Contacts"));
1110 tmp
= group
? g_strdup_printf("%d", group
->id
) : g_strdup("1");
1112 item_groups
= g_strsplit(tmp
, " ", 0);
1115 while (item_groups
[i
]) {
1116 struct sipe_group
*group
= sipe_group_find_by_id(sipe_private
,
1117 g_ascii_strtod(item_groups
[i
],
1120 /* If couldn't find the right group for this contact, */
1121 /* then just put it in the first group we have */
1123 group
= sipe_group_first(sipe_private
);
1127 buddy
= sipe_buddy_add(sipe_private
,
1132 sipe_buddy_add_to_group(sipe_private
,
1137 SIPE_DEBUG_INFO("No group found for contact %s! Unable to add to buddy list",
1144 g_strfreev(item_groups
);
1147 static gboolean
sipe_process_roaming_contacts(struct sipe_core_private
*sipe_private
,
1150 int len
= msg
->bodylen
;
1152 const gchar
*tmp
= sipmsg_find_header(msg
, "Event");
1153 const sipe_xml
*item
;
1156 const sipe_xml
*group_node
;
1158 if (!g_str_has_prefix(tmp
, "vnd-microsoft-roaming-contacts")) {
1162 /* Convert the contact from XML to backend Buddies */
1163 isc
= sipe_xml_parse(msg
->body
, len
);
1168 /* [MS-SIP]: deltaNum MUST be non-zero */
1169 delta
= sipe_xml_int_attribute(isc
, "deltaNum", 0);
1171 sipe_private
->deltanum_contacts
= delta
;
1175 * Process whole buddy list
1179 * * Lync 2013 (and later) with buddy list not migrated
1181 * - Lync 2013 with buddy list migrated to Unified Contact Store (UCS)
1182 * * Notify piggy-backed on SUBSCRIBE response with empty list
1183 * * NOTIFY send by server with standard list (ignored by us)
1185 if (sipe_strequal(sipe_xml_name(isc
), "contactList")) {
1186 const gchar
*ucsmode
= sipe_xml_attribute(isc
, "ucsmode");
1188 SIPE_CORE_PRIVATE_FLAG_UNSET(LYNC2013
);
1190 gboolean migrated
= sipe_strcase_equal(ucsmode
,
1192 SIPE_CORE_PRIVATE_FLAG_SET(LYNC2013
);
1193 SIPE_DEBUG_INFO_NOFORMAT("contact list contains 'ucsmode' attribute (indicates Lync 2013+)");
1196 SIPE_DEBUG_INFO_NOFORMAT("contact list has been migrated to Unified Contact Store (UCS)");
1197 sipe_ucs_init(sipe_private
, migrated
);
1200 if (!sipe_ucs_is_migrated(sipe_private
)) {
1201 /* Start processing contact list */
1202 sipe_backend_buddy_list_processing_start(SIPE_CORE_PUBLIC
);
1205 for (group_node
= sipe_xml_child(isc
, "group"); group_node
; group_node
= sipe_xml_twin(group_node
))
1206 add_new_group(sipe_private
, group_node
);
1208 /* Make sure we have at least one group */
1209 if (sipe_group_count(sipe_private
) == 0) {
1210 sipe_group_create(sipe_private
,
1212 _("Other Contacts"),
1216 /* Parse contacts */
1217 for (item
= sipe_xml_child(isc
, "contact"); item
; item
= sipe_xml_twin(item
)) {
1218 const gchar
*name
= sipe_xml_attribute(item
, "uri");
1219 gchar
*uri
= sip_uri_from_name(name
);
1220 add_new_buddy(sipe_private
, item
, uri
);
1224 sipe_buddy_cleanup_local_list(sipe_private
);
1226 /* Add self-contact if not there yet. 2005 systems. */
1227 /* This will resemble subscription to roaming_self in 2007 systems */
1228 if (!SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
1229 gchar
*self_uri
= sip_uri_self(sipe_private
);
1230 sipe_buddy_add(sipe_private
,
1237 /* Finished processing contact list */
1238 sipe_backend_buddy_list_processing_finish(SIPE_CORE_PUBLIC
);
1241 /* Process buddy list updates */
1242 } else if (sipe_strequal(sipe_xml_name(isc
), "contactDelta")) {
1244 /* Process new groups */
1245 for (group_node
= sipe_xml_child(isc
, "addedGroup"); group_node
; group_node
= sipe_xml_twin(group_node
))
1246 add_new_group(sipe_private
, group_node
);
1248 /* Process modified groups */
1249 for (group_node
= sipe_xml_child(isc
, "modifiedGroup"); group_node
; group_node
= sipe_xml_twin(group_node
)) {
1250 struct sipe_group
*group
= sipe_group_find_by_id(sipe_private
,
1251 (int)g_ascii_strtod(sipe_xml_attribute(group_node
, "id"),
1254 const gchar
*name
= get_group_name(group_node
);
1256 if (!(is_empty(name
) ||
1257 sipe_strequal(group
->name
, name
)) &&
1258 sipe_group_rename(sipe_private
,
1261 SIPE_DEBUG_INFO("Replaced group %d name with %s", group
->id
, name
);
1265 /* Process new buddies */
1266 for (item
= sipe_xml_child(isc
, "addedContact"); item
; item
= sipe_xml_twin(item
)) {
1267 add_new_buddy(sipe_private
,
1269 sipe_xml_attribute(item
, "uri"));
1272 /* Process modified buddies */
1273 for (item
= sipe_xml_child(isc
, "modifiedContact"); item
; item
= sipe_xml_twin(item
)) {
1274 const gchar
*uri
= sipe_xml_attribute(item
, "uri");
1275 struct sipe_buddy
*buddy
= sipe_buddy_find_by_uri(sipe_private
,
1279 gchar
**item_groups
= g_strsplit(sipe_xml_attribute(item
,
1283 /* this should be defined. Otherwise we would get "deletedContact" */
1285 const gchar
*name
= sipe_xml_attribute(item
, "name");
1286 gboolean empty_name
= is_empty(name
);
1287 GSList
*found
= NULL
;
1290 while (item_groups
[i
]) {
1291 struct sipe_group
*group
= sipe_group_find_by_id(sipe_private
,
1292 g_ascii_strtod(item_groups
[i
],
1294 /* ignore unkown groups */
1296 sipe_backend_buddy b
= sipe_backend_buddy_find(SIPE_CORE_PUBLIC
,
1300 /* add group to found list */
1301 found
= g_slist_prepend(found
, group
);
1305 gchar
*b_alias
= sipe_backend_buddy_get_alias(SIPE_CORE_PUBLIC
,
1309 sipe_strequal(b_alias
, name
))) {
1310 sipe_backend_buddy_set_alias(SIPE_CORE_PUBLIC
,
1313 SIPE_DEBUG_INFO("Replaced for buddy %s in group '%s' old alias '%s' with '%s'",
1314 uri
, group
->name
, b_alias
, name
);
1319 const gchar
*alias
= empty_name
? uri
: name
;
1320 /* buddy was not in this group */
1321 sipe_backend_buddy_add(SIPE_CORE_PUBLIC
,
1325 sipe_buddy_insert_group(buddy
, group
);
1326 SIPE_DEBUG_INFO("Added buddy %s (alias '%s' to group '%s'",
1327 uri
, alias
, group
->name
);
1334 g_strfreev(item_groups
);
1336 /* removed from groups? */
1337 sipe_buddy_update_groups(sipe_private
,
1340 g_slist_free(found
);
1345 /* Process deleted buddies */
1346 for (item
= sipe_xml_child(isc
, "deletedContact"); item
; item
= sipe_xml_twin(item
)) {
1347 const gchar
*uri
= sipe_xml_attribute(item
, "uri");
1348 struct sipe_buddy
*buddy
= sipe_buddy_find_by_uri(sipe_private
,
1352 SIPE_DEBUG_INFO("Removing buddy %s", uri
);
1353 sipe_buddy_remove(sipe_private
, buddy
);
1357 /* Process deleted groups
1359 * NOTE: all buddies will already have been removed from the
1360 * group prior to this. The log shows that OCS actually
1361 * sends two separate updates when you delete a group:
1363 * - first one with "modifiedContact" removing buddies
1364 * from the group, leaving it empty, and
1366 * - then one with "deletedGroup" removing the group
1368 for (group_node
= sipe_xml_child(isc
, "deletedGroup"); group_node
; group_node
= sipe_xml_twin(group_node
))
1369 sipe_group_remove(sipe_private
,
1370 sipe_group_find_by_id(sipe_private
,
1371 (int)g_ascii_strtod(sipe_xml_attribute(group_node
, "id"),
1377 /* Subscribe to buddies, if contact list not migrated to UCS */
1378 if (!sipe_ucs_is_migrated(sipe_private
))
1379 sipe_subscribe_presence_initial(sipe_private
);
1381 /* for 2005 systems schedule contacts' status update
1382 * based on their calendar information
1384 if (!SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
1385 sipe_ocs2005_schedule_status_update(sipe_private
, time(NULL
));
1391 static void sipe_process_roaming_acl(struct sipe_core_private
*sipe_private
,
1397 xml
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1401 /* [MS-SIP]: deltaNum MUST be non-zero */
1402 delta
= sipe_xml_int_attribute(xml
, "deltaNum", 0);
1404 sipe_private
->deltanum_acl
= delta
;
1410 struct sipe_auth_job
{
1412 struct sipe_core_private
*sipe_private
;
1415 void sipe_core_contact_allow_deny(struct sipe_core_public
*sipe_public
,
1419 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1422 SIPE_DEBUG_INFO("sipe_core_contact_allow_deny: authorizing contact %s", who
);
1424 SIPE_DEBUG_INFO("sipe_core_contact_allow_deny: blocking contact %s", who
);
1427 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
1428 sipe_ocs2007_change_access_level(sipe_private
,
1429 (allow
? -1 : 32000),
1431 sipe_get_no_sip_uri(who
));
1433 sip_soap_ocs2005_setacl(sipe_private
, who
, allow
);
1438 static void sipe_auth_user_cb(gpointer data
)
1440 struct sipe_auth_job
*job
= (struct sipe_auth_job
*) data
;
1443 sipe_core_contact_allow_deny((struct sipe_core_public
*)job
->sipe_private
,
1449 static void sipe_deny_user_cb(gpointer data
)
1451 struct sipe_auth_job
*job
= (struct sipe_auth_job
*) data
;
1454 sipe_core_contact_allow_deny((struct sipe_core_public
*)job
->sipe_private
,
1461 static void sipe_process_presence_wpending (struct sipe_core_private
*sipe_private
,
1462 struct sipmsg
* msg
)
1465 const sipe_xml
*watcher
;
1466 // Ensure it's either not a response (eg it's a BENOTIFY) or that it's a 200 OK response
1467 if (msg
->response
!= 0 && msg
->response
!= 200) return;
1469 if (msg
->bodylen
== 0 || msg
->body
== NULL
|| sipe_strequal(sipmsg_find_header(msg
, "Event"), "msrtc.wpending")) return;
1471 watchers
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1472 if (!watchers
) return;
1474 for (watcher
= sipe_xml_child(watchers
, "watcher"); watcher
; watcher
= sipe_xml_twin(watcher
)) {
1475 gchar
* remote_user
= g_strdup(sipe_xml_attribute(watcher
, "uri"));
1476 gchar
* alias
= g_strdup(sipe_xml_attribute(watcher
, "displayName"));
1477 gboolean on_list
= sipe_buddy_find_by_uri(sipe_private
, remote_user
) != NULL
;
1479 // TODO pull out optional displayName to pass as alias
1481 struct sipe_auth_job
* job
= g_new0(struct sipe_auth_job
, 1);
1482 job
->who
= remote_user
;
1483 job
->sipe_private
= sipe_private
;
1484 sipe_backend_buddy_request_authorization(SIPE_CORE_PUBLIC
,
1495 sipe_xml_free(watchers
);
1500 * Dispatcher for all incoming subscription information
1501 * whether it comes from NOTIFY, BENOTIFY requests or
1502 * piggy-backed to subscription's OK responce.
1504 void process_incoming_notify(struct sipe_core_private
*sipe_private
,
1507 const gchar
*content_type
= sipmsg_find_header(msg
, "Content-Type");
1508 const gchar
*event
= sipmsg_find_header(msg
, "Event");
1509 const gchar
*subscription_state
= sipmsg_find_header(msg
, "subscription-state");
1511 SIPE_DEBUG_INFO("process_incoming_notify: subscription_state: %s", subscription_state
? subscription_state
: "");
1513 /* implicit subscriptions */
1514 if (content_type
&& g_str_has_prefix(content_type
, "application/ms-imdn+xml")) {
1515 sipe_process_imdn(sipe_private
, msg
);
1517 /* event subscriptions */
1520 /* One-off subscriptions - sent with "Expires: 0" */
1521 if (sipe_strcase_equal(event
, "vnd-microsoft-provisioning-v2")) {
1522 sipe_process_provisioning_v2(sipe_private
, msg
);
1523 } else if (sipe_strcase_equal(event
, "vnd-microsoft-provisioning")) {
1524 sipe_process_provisioning(sipe_private
, msg
);
1525 } else if (sipe_strcase_equal(event
, "presence")) {
1526 sipe_process_presence(sipe_private
, msg
);
1527 } else if (sipe_strcase_equal(event
, "registration-notify")) {
1528 sipe_process_registration_notify(sipe_private
, msg
);
1530 /* Subscriptions with timeout */
1531 } else if (!subscription_state
|| strstr(subscription_state
, "active")) {
1532 if (sipe_strcase_equal(event
, "vnd-microsoft-roaming-contacts")) {
1533 sipe_process_roaming_contacts(sipe_private
, msg
);
1534 } else if (sipe_strcase_equal(event
, "vnd-microsoft-roaming-self")) {
1535 sipe_ocs2007_process_roaming_self(sipe_private
, msg
);
1536 } else if (sipe_strcase_equal(event
, "vnd-microsoft-roaming-ACL")) {
1537 sipe_process_roaming_acl(sipe_private
, msg
);
1538 } else if (sipe_strcase_equal(event
, "presence.wpending")) {
1539 sipe_process_presence_wpending(sipe_private
, msg
);
1540 } else if (sipe_strcase_equal(event
, "conference")) {
1541 sipe_process_conference(sipe_private
, msg
);