6 * Copyright (C) 2011-2017 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 #define READ_INT_FROM_NODE(node_name, field) { \
85 gchar *s = g_strstrip(sipe_xml_data(sipe_xml_child(node, node_name))); \
86 sipe_private->field = s ? atoi(s) : 0; \
89 sipe_xml
*xn_provision_group_list
;
92 xn_provision_group_list
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
95 for (node
= sipe_xml_child(xn_provision_group_list
, "provisionGroup");
97 node
= sipe_xml_twin(node
)) {
98 const gchar
*node_name
= sipe_xml_attribute(node
, "name");
100 /* ServerConfiguration */
101 if (sipe_strequal("ServerConfiguration", node_name
)) {
102 const gchar
*dlx_uri_str
= SIPE_CORE_PRIVATE_FLAG_IS(REMOTE_USER
) ?
103 "dlxExternalUrl" : "dlxInternalUrl";
104 const gchar
*addressbook_uri_str
= SIPE_CORE_PRIVATE_FLAG_IS(REMOTE_USER
) ?
105 "absExternalServerUrl" : "absInternalServerUrl";
106 gchar
*ucPC2PCAVEncryption
= NULL
;
107 gchar
*ucPortRangeEnabled
= NULL
;
109 g_free(sipe_private
->focus_factory_uri
);
110 sipe_private
->focus_factory_uri
= sipe_xml_data(sipe_xml_child(node
, "focusFactoryUri"));
111 SIPE_DEBUG_INFO("sipe_process_provisioning_v2: sipe_private->focus_factory_uri=%s",
112 sipe_private
->focus_factory_uri
? sipe_private
->focus_factory_uri
: "");
114 g_free(sipe_private
->dlx_uri
);
115 sipe_private
->dlx_uri
= sipe_xml_data(sipe_xml_child(node
, dlx_uri_str
));
116 SIPE_DEBUG_INFO("sipe_process_provisioning_v2: sipe_private->dlx_uri=%s",
117 sipe_private
->dlx_uri
? sipe_private
->dlx_uri
: "");
119 g_free(sipe_private
->addressbook_uri
);
120 sipe_private
->addressbook_uri
= sipe_xml_data(sipe_xml_child(node
, addressbook_uri_str
));
121 SIPE_DEBUG_INFO("sipe_process_provisioning_v2: sipe_private->addressbook_uri=%s",
122 sipe_private
->addressbook_uri
? sipe_private
->addressbook_uri
: "");
125 g_free(sipe_private
->test_call_bot_uri
);
126 sipe_private
->test_call_bot_uri
= sipe_xml_data(sipe_xml_child(node
, "botSipUriForTestCall"));
127 SIPE_DEBUG_INFO("sipe_process_provisioning_v2: sipe_private->test_call_bot_uri=%s",
128 sipe_private
->test_call_bot_uri
? sipe_private
->test_call_bot_uri
: "");
130 g_free(sipe_private
->mras_uri
);
131 sipe_private
->mras_uri
= g_strstrip(sipe_xml_data(sipe_xml_child(node
, "mrasUri")));
132 SIPE_DEBUG_INFO("sipe_process_provisioning_v2: sipe_private->mras_uri=%s",
133 sipe_private
->mras_uri
? sipe_private
->mras_uri
: "");
135 if (sipe_private
->mras_uri
)
136 sipe_media_get_av_edge_credentials(sipe_private
);
139 ucPC2PCAVEncryption
= g_strstrip(sipe_xml_data(sipe_xml_child(node
, "ucPC2PCAVEncryption")));
140 if (sipe_strequal(ucPC2PCAVEncryption
, "SupportEncryption")) {
141 sipe_private
->server_av_encryption_policy
= SIPE_ENCRYPTION_POLICY_OPTIONAL
;
142 } else if (sipe_strequal(ucPC2PCAVEncryption
, "DoNotSupportEncryption")) {
143 sipe_private
->server_av_encryption_policy
= SIPE_ENCRYPTION_POLICY_REJECTED
;
145 // "RequireEncryption" or any unknown value.
146 sipe_private
->server_av_encryption_policy
= SIPE_ENCRYPTION_POLICY_REQUIRED
;
148 g_free(ucPC2PCAVEncryption
);
150 ucPortRangeEnabled
= g_strstrip(sipe_xml_data(sipe_xml_child(node
, "ucPortRangeEnabled")));
151 if (sipe_strequal(ucPortRangeEnabled
, "true")) {
152 READ_INT_FROM_NODE("ucMinMediaPort", min_media_port
)
153 READ_INT_FROM_NODE("ucMaxMediaPort", max_media_port
)
154 READ_INT_FROM_NODE("ucMinAudioPort", min_audio_port
)
155 READ_INT_FROM_NODE("ucMaxAudioPort", max_audio_port
)
156 READ_INT_FROM_NODE("ucMinVideoPort", min_video_port
)
157 READ_INT_FROM_NODE("ucMaxVideoPort", max_video_port
)
158 READ_INT_FROM_NODE("ucMinAppSharingPort", min_appsharing_port
)
159 READ_INT_FROM_NODE("ucMaxAppSharingPort", max_appsharing_port
)
160 READ_INT_FROM_NODE("ucMinFileTransferPort", min_filetransfer_port
)
161 READ_INT_FROM_NODE("ucMaxFileTransferPort", max_filetransfer_port
)
163 sipe_private
->min_media_port
= 0;
164 sipe_private
->max_media_port
= 0;
165 sipe_private
->min_audio_port
= 0;
166 sipe_private
->max_audio_port
= 0;
167 sipe_private
->min_video_port
= 0;
168 sipe_private
->max_video_port
= 0;
169 sipe_private
->min_appsharing_port
= 0;
170 sipe_private
->max_appsharing_port
= 0;
171 sipe_private
->min_filetransfer_port
= 0;
172 sipe_private
->max_filetransfer_port
= 0;
174 g_free(ucPortRangeEnabled
);
176 /* persistentChatConfiguration */
177 } else if (sipe_strequal("persistentChatConfiguration", node_name
)) {
178 const sipe_xml
*property
;
179 gboolean enabled
= FALSE
;
182 for (property
= sipe_xml_child(node
, "propertyEntryList/property");
184 property
= sipe_xml_twin(property
)) {
185 const gchar
*name
= sipe_xml_attribute(property
, "name");
186 gchar
*value
= sipe_xml_data(property
);
188 if (sipe_strequal(name
, "EnablePersistentChat")) {
189 enabled
= sipe_strequal(value
, "true");
191 } else if (sipe_strequal(name
, "DefaultPersistentChatPoolUri")) {
200 g_free(sipe_private
->persistentChatPool_uri
);
201 sipe_private
->persistentChatPool_uri
= g_strdup(sipe_get_no_sip_uri(uri
));
202 SIPE_DEBUG_INFO("sipe_process_provisioning_v2: sipe_private->persistentChatPool_uri=%s",
203 sipe_private
->persistentChatPool_uri
? sipe_private
->persistentChatPool_uri
: "");
209 sipe_xml_free(xn_provision_group_list
);
211 if (sipe_private
->dlx_uri
&& sipe_private
->addressbook_uri
) {
212 /* Some buddies might have been added before we received this
213 * provisioning notify with DLX and addressbook URIs. Now we can
214 * trigger an update of their photos. */
215 sipe_buddy_refresh_photos(sipe_private
);
218 if (sipe_private
->focus_factory_uri
) {
219 /* Fill the list of conferencing capabilities enabled on
221 sipe_conf_get_capabilities(sipe_private
);
224 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
))
225 /* persistentChatPool_uri has been set at this point */
226 sipe_groupchat_init(sipe_private
);
229 static void process_incoming_notify_rlmi_resub(struct sipe_core_private
*sipe_private
,
230 const gchar
*data
, unsigned len
)
233 const sipe_xml
*xn_resource
;
234 GHashTable
*servers
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
237 xn_list
= sipe_xml_parse(data
, len
);
239 for (xn_resource
= sipe_xml_child(xn_list
, "resource");
241 xn_resource
= sipe_xml_twin(xn_resource
) )
243 const char *uri
, *state
;
244 const sipe_xml
*xn_instance
;
246 xn_instance
= sipe_xml_child(xn_resource
, "instance");
247 if (!xn_instance
) continue;
249 uri
= sipe_xml_attribute(xn_resource
, "uri");
250 state
= sipe_xml_attribute(xn_instance
, "state");
251 SIPE_DEBUG_INFO("process_incoming_notify_rlmi_resub: uri(%s),state(%s)", uri
, state
);
253 if (strstr(state
, "resubscribe")) {
254 const char *poolFqdn
= sipe_xml_attribute(xn_instance
, "poolFqdn");
256 if (poolFqdn
) { //[MS-PRES] Section 3.4.5.1.3 Processing Details
257 gchar
*user
= g_strdup(uri
);
258 gchar
*host
= g_strdup(poolFqdn
);
259 GSList
*server
= g_hash_table_lookup(servers
,
261 server
= g_slist_append(server
, user
);
262 g_hash_table_insert(servers
, host
, server
);
264 sipe_subscribe_presence_single(sipe_private
,
271 /* Send out any deferred poolFqdn subscriptions */
272 g_hash_table_foreach(servers
, (GHFunc
) sipe_subscribe_poolfqdn_resource_uri
, sipe_private
);
273 g_hash_table_destroy(servers
);
275 sipe_xml_free(xn_list
);
280 * Suitable for both 2005 and 2007 systems.
282 * @param uri buddy SIP URI with 'sip:' prefix whose info we want to change.
284 * @param phone may be modified to strip white space
285 * @param phone_display_string may be modified to strip white space
288 sipe_update_user_phone(struct sipe_core_private
*sipe_private
,
290 const gchar
*phone_type
,
292 gchar
*phone_display_string
)
294 sipe_buddy_info_fields phone_node
= SIPE_BUDDY_INFO_WORK_PHONE
; /* work phone by default */
295 sipe_buddy_info_fields phone_display_node
= SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY
; /* work phone by default */
297 if(!phone
|| strlen(phone
) == 0) return;
299 if ((sipe_strequal(phone_type
, "mobile") || sipe_strequal(phone_type
, "cell"))) {
300 phone_node
= SIPE_BUDDY_INFO_MOBILE_PHONE
;
301 phone_display_node
= SIPE_BUDDY_INFO_MOBILE_PHONE_DISPLAY
;
302 } else if (sipe_strequal(phone_type
, "home")) {
303 phone_node
= SIPE_BUDDY_INFO_HOME_PHONE
;
304 phone_display_node
= SIPE_BUDDY_INFO_HOME_PHONE_DISPLAY
;
305 } else if (sipe_strequal(phone_type
, "other")) {
306 phone_node
= SIPE_BUDDY_INFO_OTHER_PHONE
;
307 phone_display_node
= SIPE_BUDDY_INFO_OTHER_PHONE_DISPLAY
;
308 } else if (sipe_strequal(phone_type
, "custom1")) {
309 phone_node
= SIPE_BUDDY_INFO_CUSTOM1_PHONE
;
310 phone_display_node
= SIPE_BUDDY_INFO_CUSTOM1_PHONE_DISPLAY
;
313 sipe_buddy_update_property(sipe_private
, uri
, phone_node
, phone
);
314 if (phone_display_string
) {
315 sipe_buddy_update_property(sipe_private
, uri
, phone_display_node
, phone_display_string
);
319 static void process_incoming_notify_msrtc(struct sipe_core_private
*sipe_private
,
323 char *activity
= NULL
;
325 const char *status_id
= NULL
;
328 char *self_uri
= sip_uri_self(sipe_private
);
331 const char *device_name
= NULL
;
332 const char *cal_start_time
= NULL
;
333 const char *cal_granularity
= NULL
;
334 char *cal_free_busy_base64
= NULL
;
335 struct sipe_buddy
*sbuddy
;
336 const sipe_xml
*node
;
337 sipe_xml
*xn_presentity
;
338 const sipe_xml
*xn_availability
;
339 const sipe_xml
*xn_activity
;
340 const sipe_xml
*xn_display_name
;
341 const sipe_xml
*xn_email
;
342 const sipe_xml
*xn_phone_number
;
343 const sipe_xml
*xn_userinfo
;
344 const sipe_xml
*xn_note
;
345 const sipe_xml
*xn_oof
;
346 const sipe_xml
*xn_state
;
347 const sipe_xml
*xn_contact
;
350 const char *user_avail_nil
;
352 time_t user_avail_since
= 0;
353 time_t activity_since
= 0;
355 /* fix for Reuters environment on Linux */
356 if (data
&& strstr(data
, "encoding=\"utf-16\"")) {
358 tmp_data
= sipe_utils_str_replace(data
, "encoding=\"utf-16\"", "encoding=\"utf-8\"");
359 xn_presentity
= sipe_xml_parse(tmp_data
, strlen(tmp_data
));
362 xn_presentity
= sipe_xml_parse(data
, len
);
365 xn_availability
= sipe_xml_child(xn_presentity
, "availability");
366 xn_activity
= sipe_xml_child(xn_presentity
, "activity");
367 xn_display_name
= sipe_xml_child(xn_presentity
, "displayName");
368 xn_email
= sipe_xml_child(xn_presentity
, "email");
369 xn_phone_number
= sipe_xml_child(xn_presentity
, "phoneNumber");
370 xn_userinfo
= sipe_xml_child(xn_presentity
, "userInfo");
371 xn_oof
= xn_userinfo
? sipe_xml_child(xn_userinfo
, "oof") : NULL
;
372 xn_state
= xn_userinfo
? sipe_xml_child(xn_userinfo
, "states/state"): NULL
;
373 user_avail
= xn_state
? sipe_xml_int_attribute(xn_state
, "avail", 0) : 0;
374 user_avail_since
= xn_state
? sipe_utils_str_to_time(sipe_xml_attribute(xn_state
, "since")) : 0;
375 user_avail_nil
= xn_state
? sipe_xml_attribute(xn_state
, "nil") : NULL
;
376 xn_contact
= xn_userinfo
? sipe_xml_child(xn_userinfo
, "contact") : NULL
;
377 xn_note
= xn_userinfo
? sipe_xml_child(xn_userinfo
, "note") : NULL
;
378 note
= xn_note
? sipe_xml_data(xn_note
) : NULL
;
380 if (sipe_strequal(user_avail_nil
, "true")) { /* null-ed */
382 user_avail_since
= 0;
385 name
= sipe_xml_attribute(xn_presentity
, "uri"); /* without 'sip:' prefix */
386 uri
= sip_uri_from_name(name
);
387 avl
= sipe_xml_int_attribute(xn_availability
, "aggregate", 0);
388 epid
= sipe_xml_attribute(xn_availability
, "epid");
389 act
= sipe_xml_int_attribute(xn_activity
, "aggregate", 0);
391 status_id
= sipe_ocs2005_status_from_activity_availability(act
, avl
);
392 activity
= g_strdup(sipe_ocs2005_activity_description(act
));
393 res_avail
= sipe_ocs2007_availability_from_status(status_id
, NULL
);
394 if (user_avail
> res_avail
) {
395 res_avail
= user_avail
;
396 status_id
= sipe_ocs2007_status_from_legacy_availability(user_avail
, NULL
);
399 if (xn_display_name
) {
400 char *display_name
= g_strdup(sipe_xml_attribute(xn_display_name
, "displayName"));
401 char *email
= xn_email
? g_strdup(sipe_xml_attribute(xn_email
, "email")) : NULL
;
402 char *phone_label
= xn_phone_number
? g_strdup(sipe_xml_attribute(xn_phone_number
, "label")) : NULL
;
403 char *phone_number
= xn_phone_number
? g_strdup(sipe_xml_attribute(xn_phone_number
, "number")) : NULL
;
404 char *tel_uri
= sip_to_tel_uri(phone_number
);
406 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_DISPLAY_NAME
, display_name
);
407 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_EMAIL
, email
);
408 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_WORK_PHONE
, tel_uri
);
409 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY
, !is_empty(phone_label
) ? phone_label
: phone_number
);
413 g_free(phone_number
);
415 g_free(display_name
);
420 for (node
= sipe_xml_child(xn_contact
, "tel"); node
; node
= sipe_xml_twin(node
))
422 /* Ex.: <tel type="work">tel:+3222220000</tel> */
423 const char *phone_type
= sipe_xml_attribute(node
, "type");
424 char* phone
= sipe_xml_data(node
);
426 sipe_update_user_phone(sipe_private
, uri
, phone_type
, phone
, NULL
);
432 if (xn_display_name
|| xn_contact
)
433 sipe_backend_buddy_refresh_properties(SIPE_CORE_PUBLIC
, uri
);
436 for (node
= sipe_xml_child(xn_presentity
, "devices/devicePresence"); node
; node
= sipe_xml_twin(node
)) {
437 const sipe_xml
*xn_device_name
;
438 const sipe_xml
*xn_calendar_info
;
439 const sipe_xml
*xn_state
;
443 if (sipe_strequal(sipe_xml_attribute(node
, "epid"), epid
)) {
444 xn_device_name
= sipe_xml_child(node
, "deviceName");
445 device_name
= xn_device_name
? sipe_xml_attribute(xn_device_name
, "name") : NULL
;
449 xn_calendar_info
= sipe_xml_child(node
, "calendarInfo");
450 if (xn_calendar_info
) {
451 const char *cal_start_time_tmp
= sipe_xml_attribute(xn_calendar_info
, "startTime");
453 if (cal_start_time
) {
454 time_t cal_start_time_t
= sipe_utils_str_to_time(cal_start_time
);
455 time_t cal_start_time_t_tmp
= sipe_utils_str_to_time(cal_start_time_tmp
);
457 if (cal_start_time_t_tmp
> cal_start_time_t
) {
458 cal_start_time
= cal_start_time_tmp
;
459 cal_granularity
= sipe_xml_attribute(xn_calendar_info
, "granularity");
460 g_free(cal_free_busy_base64
);
461 cal_free_busy_base64
= sipe_xml_data(xn_calendar_info
);
463 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
);
466 cal_start_time
= cal_start_time_tmp
;
467 cal_granularity
= sipe_xml_attribute(xn_calendar_info
, "granularity");
468 g_free(cal_free_busy_base64
);
469 cal_free_busy_base64
= sipe_xml_data(xn_calendar_info
);
471 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
);
476 xn_state
= sipe_xml_child(node
, "states/state");
478 int dev_avail
= sipe_xml_int_attribute(xn_state
, "avail", 0);
479 time_t dev_avail_since
= sipe_utils_str_to_time(sipe_xml_attribute(xn_state
, "since"));
481 state
= sipe_xml_data(xn_state
);
482 if (dev_avail_since
> user_avail_since
&&
483 dev_avail
>= res_avail
)
485 const gchar
*new_desc
;
486 res_avail
= dev_avail
;
487 if (!is_empty(state
)) {
488 if (sipe_strequal(state
, sipe_status_activity_to_token(SIPE_ACTIVITY_ON_PHONE
))) {
490 activity
= g_strdup(sipe_core_activity_description(SIPE_ACTIVITY_ON_PHONE
));
491 } else if (sipe_strequal(state
, "presenting")) {
493 activity
= g_strdup(sipe_core_activity_description(SIPE_ACTIVITY_IN_CONF
));
498 activity_since
= dev_avail_since
;
500 status_id
= sipe_ocs2007_status_from_legacy_availability(res_avail
, NULL
);
501 new_desc
= sipe_ocs2007_legacy_activity_description(res_avail
);
504 activity
= g_strdup(new_desc
);
512 if (xn_oof
&& res_avail
>= 15000) { /* 12000 in 2007 */
514 activity
= g_strdup(sipe_core_activity_description(SIPE_ACTIVITY_OOF
));
518 sbuddy
= sipe_buddy_find_by_uri(sipe_private
, uri
);
521 g_free(sbuddy
->activity
);
522 sbuddy
->activity
= activity
;
525 sbuddy
->activity_since
= activity_since
;
527 sbuddy
->user_avail
= user_avail
;
528 sbuddy
->user_avail_since
= user_avail_since
;
530 g_free(sbuddy
->note
);
532 if (!is_empty(note
)) { sbuddy
->note
= g_markup_escape_text(note
, -1); }
534 sbuddy
->is_oof_note
= (xn_oof
!= NULL
);
536 g_free(sbuddy
->device_name
);
537 sbuddy
->device_name
= NULL
;
538 if (!is_empty(device_name
)) { sbuddy
->device_name
= g_strdup(device_name
); }
540 if (!is_empty(cal_free_busy_base64
)) {
541 g_free(sbuddy
->cal_start_time
);
542 sbuddy
->cal_start_time
= g_strdup(cal_start_time
);
544 sbuddy
->cal_granularity
= sipe_strcase_equal(cal_granularity
, "PT15M") ? 15 : 0;
546 g_free(sbuddy
->cal_free_busy_base64
);
547 sbuddy
->cal_free_busy_base64
= cal_free_busy_base64
;
548 cal_free_busy_base64
= NULL
;
550 g_free(sbuddy
->cal_free_busy
);
551 sbuddy
->cal_free_busy
= NULL
;
554 sbuddy
->last_non_cal_status_id
= status_id
;
555 g_free(sbuddy
->last_non_cal_activity
);
556 sbuddy
->last_non_cal_activity
= g_strdup(sbuddy
->activity
);
558 if (sipe_strcase_equal(sbuddy
->name
, self_uri
)) {
559 if (!sipe_strequal(sbuddy
->note
, sipe_private
->note
)) /* not same */
561 if (sbuddy
->is_oof_note
)
562 SIPE_CORE_PRIVATE_FLAG_SET(OOF_NOTE
);
564 SIPE_CORE_PRIVATE_FLAG_UNSET(OOF_NOTE
);
566 g_free(sipe_private
->note
);
567 sipe_private
->note
= g_strdup(sbuddy
->note
);
569 sipe_private
->note_since
= time(NULL
);
572 sipe_status_set_token(sipe_private
,
573 sbuddy
->last_non_cal_status_id
);
576 g_free(cal_free_busy_base64
);
579 SIPE_DEBUG_INFO("process_incoming_notify_msrtc: status(%s)", status_id
);
580 sipe_core_buddy_got_status(SIPE_CORE_PUBLIC
, uri
,
581 sipe_status_token_to_activity(status_id
));
583 if (!SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
) && sipe_strcase_equal(self_uri
, uri
)) {
584 sipe_ocs2005_user_info_has_updated(sipe_private
, xn_userinfo
);
588 sipe_xml_free(xn_presentity
);
593 static void process_incoming_notify_rlmi(struct sipe_core_private
*sipe_private
,
598 struct sipe_buddy
*sbuddy
= NULL
;
599 sipe_xml
*xn_categories
;
600 const sipe_xml
*xn_category
;
601 const char *status
= NULL
;
602 gboolean do_update_status
= FALSE
;
603 gboolean has_note_cleaned
= FALSE
;
604 gboolean has_free_busy_cleaned
= FALSE
;
606 xn_categories
= sipe_xml_parse(data
, len
);
607 uri
= sipe_xml_attribute(xn_categories
, "uri"); /* with 'sip:' prefix */
609 sbuddy
= sipe_buddy_find_by_uri(sipe_private
, uri
);
613 /* Got presence of a buddy not in our contact list, ignore. */
614 sipe_xml_free(xn_categories
);
618 for (xn_category
= sipe_xml_child(xn_categories
, "category");
620 xn_category
= sipe_xml_twin(xn_category
) )
622 const sipe_xml
*xn_node
;
624 const char *attrVar
= sipe_xml_attribute(xn_category
, "name");
625 time_t publish_time
= (tmp
= sipe_xml_attribute(xn_category
, "publishTime")) ?
626 sipe_utils_str_to_time(tmp
) : 0;
629 if (sipe_strequal(attrVar
, "contactCard"))
631 const sipe_xml
*card
= sipe_xml_child(xn_category
, "contactCard");
634 const sipe_xml
*node
;
635 /* identity - Display Name and email */
636 node
= sipe_xml_child(card
, "identity");
638 char* display_name
= sipe_xml_data(
639 sipe_xml_child(node
, "name/displayName"));
640 char* email
= sipe_xml_data(
641 sipe_xml_child(node
, "email"));
643 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_DISPLAY_NAME
, display_name
);
644 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_EMAIL
, email
);
646 g_free(display_name
);
650 node
= sipe_xml_child(card
, "company");
652 char* company
= sipe_xml_data(node
);
653 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_COMPANY
, company
);
657 node
= sipe_xml_child(card
, "department");
659 char* department
= sipe_xml_data(node
);
660 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_DEPARTMENT
, department
);
664 node
= sipe_xml_child(card
, "title");
666 char* title
= sipe_xml_data(node
);
667 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_JOB_TITLE
, title
);
671 node
= sipe_xml_child(card
, "office");
673 char* office
= sipe_xml_data(node
);
674 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_OFFICE
, office
);
678 node
= sipe_xml_child(card
, "url");
680 char* site
= sipe_xml_data(node
);
681 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_SITE
, site
);
685 for (node
= sipe_xml_child(card
, "phone");
687 node
= sipe_xml_twin(node
))
689 const char *phone_type
= sipe_xml_attribute(node
, "type");
690 char* phone
= sipe_xml_data(sipe_xml_child(node
, "uri"));
691 char* phone_display_string
= sipe_xml_data(sipe_xml_child(node
, "displayString"));
693 sipe_update_user_phone(sipe_private
, uri
, phone_type
, phone
, phone_display_string
);
696 g_free(phone_display_string
);
699 for (node
= sipe_xml_child(card
, "address");
701 node
= sipe_xml_twin(node
))
703 if (sipe_strequal(sipe_xml_attribute(node
, "type"), "work")) {
704 char* street
= sipe_xml_data(sipe_xml_child(node
, "street"));
705 char* city
= sipe_xml_data(sipe_xml_child(node
, "city"));
706 char* state
= sipe_xml_data(sipe_xml_child(node
, "state"));
707 char* zipcode
= sipe_xml_data(sipe_xml_child(node
, "zipcode"));
708 char* country_code
= sipe_xml_data(sipe_xml_child(node
, "countryCode"));
710 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_STREET
, street
);
711 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_CITY
, city
);
712 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_STATE
, state
);
713 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_ZIPCODE
, zipcode
);
714 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_COUNTRY
, country_code
);
720 g_free(country_code
);
726 for (node
= sipe_xml_child(card
, "photo");
728 node
= sipe_xml_twin(node
)) {
729 const gchar
*type
= sipe_xml_attribute(node
, "type");
732 gboolean found
= FALSE
;
734 if (sipe_strequal(type
, "default") &&
735 !SIPE_CORE_PUBLIC_FLAG_IS(ALLOW_WEB_PHOTO
)) {
736 SIPE_DEBUG_INFO("process_incoming_notify_rlmi: skipping download of web profile picture for %s", uri
);
740 photo_url
= sipe_xml_data(sipe_xml_child(node
, "uri"));
741 hash
= sipe_xml_data(sipe_xml_child(node
, "hash"));
743 if (!is_empty(photo_url
) && !is_empty(hash
)) {
744 sipe_buddy_update_photo(sipe_private
,
761 else if (sipe_strequal(attrVar
, "note"))
763 if (!has_note_cleaned
) {
764 has_note_cleaned
= TRUE
;
766 g_free(sbuddy
->note
);
768 sbuddy
->is_oof_note
= FALSE
;
769 sbuddy
->note_since
= publish_time
;
771 do_update_status
= TRUE
;
773 if (publish_time
>= sbuddy
->note_since
) {
774 /* clean up in case no 'note' element is supplied
775 * which indicate note removal in client
777 g_free(sbuddy
->note
);
779 sbuddy
->is_oof_note
= FALSE
;
780 sbuddy
->note_since
= publish_time
;
782 xn_node
= sipe_xml_child(xn_category
, "note/body");
785 sbuddy
->note
= g_markup_escape_text((tmp
= sipe_xml_data(xn_node
)), -1);
787 sbuddy
->is_oof_note
= sipe_strequal(sipe_xml_attribute(xn_node
, "type"), "OOF");
788 sbuddy
->note_since
= publish_time
;
790 SIPE_DEBUG_INFO("process_incoming_notify_rlmi: uri(%s), note(%s)",
791 uri
, sbuddy
->note
? sbuddy
->note
: "");
793 /* to trigger UI refresh in case no status info is supplied in this update */
794 do_update_status
= TRUE
;
798 else if(sipe_strequal(attrVar
, "state"))
802 const sipe_xml
*xn_availability
;
803 const sipe_xml
*xn_activity
;
804 const sipe_xml
*xn_device
;
805 const sipe_xml
*xn_meeting_subject
;
806 const sipe_xml
*xn_meeting_location
;
807 const gchar
*legacy_activity
;
809 xn_node
= sipe_xml_child(xn_category
, "state");
810 if (!xn_node
) continue;
811 xn_availability
= sipe_xml_child(xn_node
, "availability");
812 if (!xn_availability
) continue;
813 xn_activity
= sipe_xml_child(xn_node
, "activity");
814 xn_meeting_subject
= sipe_xml_child(xn_node
, "meetingSubject");
815 xn_meeting_location
= sipe_xml_child(xn_node
, "meetingLocation");
817 tmp
= sipe_xml_data(xn_availability
);
818 availability
= atoi(tmp
);
821 sbuddy
->is_mobile
= FALSE
;
822 xn_device
= sipe_xml_child(xn_node
, "device");
824 tmp
= sipe_xml_data(xn_device
);
825 sbuddy
->is_mobile
= !g_ascii_strcasecmp(tmp
, "Mobile");
830 g_free(sbuddy
->activity
);
831 sbuddy
->activity
= NULL
;
833 const char *token
= sipe_xml_attribute(xn_activity
, "token");
834 const sipe_xml
*xn_custom
= sipe_xml_child(xn_activity
, "custom");
837 if (!is_empty(token
)) {
838 sbuddy
->activity
= g_strdup(sipe_core_activity_description(sipe_status_token_to_activity(token
)));
840 /* from custom element */
842 char *custom
= sipe_xml_data(xn_custom
);
844 if (!is_empty(custom
)) {
845 g_free(sbuddy
->activity
);
846 sbuddy
->activity
= custom
;
852 /* meeting_subject */
853 g_free(sbuddy
->meeting_subject
);
854 sbuddy
->meeting_subject
= NULL
;
855 if (xn_meeting_subject
) {
856 char *meeting_subject
= sipe_xml_data(xn_meeting_subject
);
858 if (!is_empty(meeting_subject
)) {
859 sbuddy
->meeting_subject
= meeting_subject
;
860 meeting_subject
= NULL
;
862 g_free(meeting_subject
);
864 /* meeting_location */
865 g_free(sbuddy
->meeting_location
);
866 sbuddy
->meeting_location
= NULL
;
867 if (xn_meeting_location
) {
868 char *meeting_location
= sipe_xml_data(xn_meeting_location
);
870 if (!is_empty(meeting_location
)) {
871 sbuddy
->meeting_location
= meeting_location
;
872 meeting_location
= NULL
;
874 g_free(meeting_location
);
877 status
= sipe_ocs2007_status_from_legacy_availability(availability
, NULL
);
878 legacy_activity
= sipe_ocs2007_legacy_activity_description(availability
);
879 if (sbuddy
->activity
&& legacy_activity
) {
880 gchar
*tmp2
= sbuddy
->activity
;
882 sbuddy
->activity
= g_strdup_printf("%s, %s", sbuddy
->activity
, legacy_activity
);
884 } else if (legacy_activity
) {
885 sbuddy
->activity
= g_strdup(legacy_activity
);
888 do_update_status
= TRUE
;
891 else if(sipe_strequal(attrVar
, "calendarData"))
893 const sipe_xml
*xn_free_busy
= sipe_xml_child(xn_category
, "calendarData/freeBusy");
894 const sipe_xml
*xn_working_hours
= sipe_xml_child(xn_category
, "calendarData/WorkingHours");
897 if (!has_free_busy_cleaned
) {
898 has_free_busy_cleaned
= TRUE
;
900 g_free(sbuddy
->cal_start_time
);
901 sbuddy
->cal_start_time
= NULL
;
903 g_free(sbuddy
->cal_free_busy_base64
);
904 sbuddy
->cal_free_busy_base64
= NULL
;
906 g_free(sbuddy
->cal_free_busy
);
907 sbuddy
->cal_free_busy
= NULL
;
909 sbuddy
->cal_free_busy_published
= publish_time
;
912 if (publish_time
>= sbuddy
->cal_free_busy_published
) {
913 g_free(sbuddy
->cal_start_time
);
914 sbuddy
->cal_start_time
= g_strdup(sipe_xml_attribute(xn_free_busy
, "startTime"));
916 sbuddy
->cal_granularity
= sipe_strcase_equal(sipe_xml_attribute(xn_free_busy
, "granularity"), "PT15M") ?
919 g_free(sbuddy
->cal_free_busy_base64
);
920 sbuddy
->cal_free_busy_base64
= sipe_xml_data(xn_free_busy
);
922 g_free(sbuddy
->cal_free_busy
);
923 sbuddy
->cal_free_busy
= NULL
;
925 sbuddy
->cal_free_busy_published
= publish_time
;
927 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
);
931 if (xn_working_hours
) {
932 sipe_cal_parse_working_hours(xn_working_hours
, sbuddy
);
937 if (do_update_status
) {
941 SIPE_DEBUG_INFO("process_incoming_notify_rlmi: %s", status
);
942 activity
= sipe_status_token_to_activity(status
);
944 /* no status category in this update,
945 using contact's current status */
946 activity
= sipe_backend_buddy_get_status(SIPE_CORE_PUBLIC
,
950 sipe_core_buddy_got_status(SIPE_CORE_PUBLIC
, uri
, activity
);
953 sipe_backend_buddy_refresh_properties(SIPE_CORE_PUBLIC
, uri
);
955 sipe_xml_free(xn_categories
);
958 static void sipe_buddy_status_from_activity(struct sipe_core_private
*sipe_private
,
960 const gchar
*activity
,
964 const gchar
*status_id
= NULL
;
966 if (sipe_strequal(activity
,
967 sipe_status_activity_to_token(SIPE_ACTIVITY_BUSY
))) {
968 status_id
= sipe_status_activity_to_token(SIPE_ACTIVITY_BUSY
);
969 } else if (sipe_strequal(activity
,
970 sipe_status_activity_to_token(SIPE_ACTIVITY_AWAY
))) {
971 status_id
= sipe_status_activity_to_token(SIPE_ACTIVITY_AWAY
);
976 status_id
= sipe_status_activity_to_token(SIPE_ACTIVITY_AVAILABLE
);
979 SIPE_DEBUG_INFO("sipe_buddy_status_from_activity: status_id(%s)", status_id
);
980 sipe_core_buddy_got_status(SIPE_CORE_PUBLIC
, uri
,
981 sipe_status_token_to_activity(status_id
));
983 sipe_core_buddy_got_status(SIPE_CORE_PUBLIC
, uri
,
984 SIPE_ACTIVITY_OFFLINE
);
988 static void process_incoming_notify_pidf(struct sipe_core_private
*sipe_private
,
994 gchar
*activity
= NULL
;
996 const sipe_xml
*basicstatus
= NULL
, *tuple
, *status
;
997 gboolean isonline
= FALSE
;
998 const sipe_xml
*display_name_node
;
1000 pidf
= sipe_xml_parse(data
, len
);
1002 SIPE_DEBUG_INFO("process_incoming_notify_pidf: no parseable pidf:%s", data
);
1006 if ((tuple
= sipe_xml_child(pidf
, "tuple")))
1008 if ((status
= sipe_xml_child(tuple
, "status"))) {
1009 basicstatus
= sipe_xml_child(status
, "basic");
1014 SIPE_DEBUG_INFO_NOFORMAT("process_incoming_notify_pidf: no basic found");
1015 sipe_xml_free(pidf
);
1019 getbasic
= sipe_xml_data(basicstatus
);
1021 SIPE_DEBUG_INFO_NOFORMAT("process_incoming_notify_pidf: no basic data found");
1022 sipe_xml_free(pidf
);
1026 SIPE_DEBUG_INFO("process_incoming_notify_pidf: basic-status(%s)", getbasic
);
1027 if (strstr(getbasic
, "open")) {
1032 uri
= sip_uri(sipe_xml_attribute(pidf
, "entity")); /* with 'sip:' prefix */ /* AOL comes without the prefix */
1034 display_name_node
= sipe_xml_child(pidf
, "display-name");
1035 if (display_name_node
) {
1036 char * display_name
= sipe_xml_data(display_name_node
);
1038 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_DISPLAY_NAME
, display_name
);
1039 g_free(display_name
);
1041 sipe_backend_buddy_refresh_properties(SIPE_CORE_PUBLIC
, uri
);
1044 if ((tuple
= sipe_xml_child(pidf
, "tuple"))) {
1045 if ((status
= sipe_xml_child(tuple
, "status"))) {
1046 if ((basicstatus
= sipe_xml_child(status
, "activities"))) {
1047 if ((basicstatus
= sipe_xml_child(basicstatus
, "activity"))) {
1048 activity
= sipe_xml_data(basicstatus
);
1049 SIPE_DEBUG_INFO("process_incoming_notify_pidf: activity(%s)", activity
);
1055 sipe_buddy_status_from_activity(sipe_private
,
1062 sipe_xml_free(pidf
);
1065 static void sipe_presence_mime_cb(gpointer user_data
, /* sipe_core_private */
1066 const GSList
*fields
,
1070 const gchar
*type
= sipe_utils_nameval_find(fields
, "Content-Type");
1072 if (strstr(type
,"application/rlmi+xml")) {
1073 process_incoming_notify_rlmi_resub(user_data
, body
, length
);
1074 } else if (strstr(type
, "text/xml+msrtc.pidf")) {
1075 process_incoming_notify_msrtc(user_data
, body
, length
);
1077 process_incoming_notify_rlmi(user_data
, body
, length
);
1081 static void sipe_process_presence(struct sipe_core_private
*sipe_private
,
1084 const char *ctype
= sipmsg_find_header(msg
, "Content-Type");
1086 SIPE_DEBUG_INFO("sipe_process_presence: Content-Type: %s", ctype
? ctype
: "");
1089 (strstr(ctype
, "application/rlmi+xml") ||
1090 strstr(ctype
, "application/msrtc-event-categories+xml")))
1092 if (strstr(ctype
, "multipart"))
1094 sipe_mime_parts_foreach(ctype
, msg
->body
, sipe_presence_mime_cb
, sipe_private
);
1096 else if(strstr(ctype
, "application/msrtc-event-categories+xml") )
1098 process_incoming_notify_rlmi(sipe_private
, msg
->body
, msg
->bodylen
);
1100 else if(strstr(ctype
, "application/rlmi+xml"))
1102 process_incoming_notify_rlmi_resub(sipe_private
, msg
->body
, msg
->bodylen
);
1105 else if(ctype
&& strstr(ctype
, "text/xml+msrtc.pidf"))
1107 process_incoming_notify_msrtc(sipe_private
, msg
->body
, msg
->bodylen
);
1111 process_incoming_notify_pidf(sipe_private
, msg
->body
, msg
->bodylen
);
1116 * Fires on deregistration event initiated by server.
1117 * [MS-SIPREGE] SIP extension.
1121 * Content-Type: text/registration-event
1122 * subscription-state: terminated;expires=0
1123 * ms-diagnostics-public: 4141;reason="User disabled"
1125 * deregistered;event=rejected
1127 static void sipe_process_registration_notify(struct sipe_core_private
*sipe_private
,
1130 const gchar
*contenttype
= sipmsg_find_header(msg
, "Content-Type");
1131 gchar
*event
= NULL
;
1132 gchar
*reason
= NULL
;
1135 SIPE_DEBUG_INFO_NOFORMAT("sipe_process_registration_notify: deregistration received.");
1137 if (!g_ascii_strncasecmp(contenttype
, "text/registration-event", 23)) {
1138 event
= sipmsg_find_part_of_header(msg
->body
, "event=", NULL
, NULL
);
1139 //@TODO have proper parameter extraction _by_name_ func, case insesitive.
1140 event
= event
? event
: sipmsg_find_part_of_header(msg
->body
, "event=", ";", NULL
);
1142 SIPE_DEBUG_INFO_NOFORMAT("sipe_process_registration_notify: unknown content type, exiting.");
1146 reason
= sipmsg_get_ms_diagnostics_reason(msg
);
1147 reason
= reason
? reason
: sipmsg_get_ms_diagnostics_public_reason(msg
);
1148 if (!reason
) { // for LCS2005
1149 if (event
&& sipe_strcase_equal(event
, "unregistered")) {
1150 //reason = g_strdup(_("User logged out")); // [MS-OCER]
1151 reason
= g_strdup(_("you are already signed in at another location"));
1152 } else if (event
&& sipe_strcase_equal(event
, "rejected")) {
1153 reason
= g_strdup(_("user disabled")); // [MS-OCER]
1154 } else if (event
&& sipe_strcase_equal(event
, "deactivated")) {
1155 reason
= g_strdup(_("user moved")); // [MS-OCER]
1159 warning
= g_strdup_printf(_("You have been rejected by the server: %s"), reason
? reason
: _("no reason given"));
1162 sipe_backend_connection_error(SIPE_CORE_PUBLIC
,
1163 SIPE_CONNECTION_ERROR_INVALID_USERNAME
,
1169 /* Replace "~" with localized version of "Other Contacts" */
1170 static const gchar
*get_group_name(const sipe_xml
*node
)
1172 const gchar
*name
= sipe_xml_attribute(node
, "name");
1173 return(g_str_has_prefix(name
, "~") ? _("Other Contacts") : name
);
1176 static void add_new_group(struct sipe_core_private
*sipe_private
,
1177 const sipe_xml
*node
)
1179 sipe_group_add(sipe_private
,
1180 get_group_name(node
),
1183 sipe_xml_int_attribute(node
, "id", 0));
1186 static void add_new_buddy(struct sipe_core_private
*sipe_private
,
1187 const sipe_xml
*node
,
1190 const gchar
*name
= sipe_xml_attribute(node
, "name");
1191 struct sipe_buddy
*buddy
= NULL
;
1193 gchar
**item_groups
;
1196 /* "name" attribute is a contact alias which user can manually assign by
1197 * renaming the item in the contact list. Empty string means no alias
1198 * and the display name from the contact card should be used instead. */
1199 if (name
&& strlen(name
) == 0) {
1203 /* assign to group Other Contacts if nothing else received */
1204 tmp
= g_strdup(sipe_xml_attribute(node
, "groups"));
1205 if (is_empty(tmp
)) {
1206 struct sipe_group
*group
= sipe_group_find_by_name(sipe_private
,
1207 _("Other Contacts"));
1209 tmp
= group
? g_strdup_printf("%d", group
->id
) : g_strdup("1");
1211 item_groups
= g_strsplit(tmp
, " ", 0);
1214 while (item_groups
[i
]) {
1215 struct sipe_group
*group
= sipe_group_find_by_id(sipe_private
,
1216 g_ascii_strtod(item_groups
[i
],
1219 /* If couldn't find the right group for this contact, */
1220 /* then just put it in the first group we have */
1222 group
= sipe_group_first(sipe_private
);
1226 buddy
= sipe_buddy_add(sipe_private
,
1231 sipe_buddy_add_to_group(sipe_private
,
1236 SIPE_DEBUG_INFO("No group found for contact %s! Unable to add to buddy list",
1243 g_strfreev(item_groups
);
1246 static gboolean
sipe_process_roaming_contacts(struct sipe_core_private
*sipe_private
,
1249 int len
= msg
->bodylen
;
1251 const gchar
*tmp
= sipmsg_find_header(msg
, "Event");
1252 const sipe_xml
*item
;
1255 const sipe_xml
*group_node
;
1257 if (!g_str_has_prefix(tmp
, "vnd-microsoft-roaming-contacts")) {
1261 /* Convert the contact from XML to backend Buddies */
1262 isc
= sipe_xml_parse(msg
->body
, len
);
1267 /* [MS-SIP]: deltaNum MUST be non-zero */
1268 delta
= sipe_xml_int_attribute(isc
, "deltaNum", 0);
1270 sipe_private
->deltanum_contacts
= delta
;
1274 * Process whole buddy list
1278 * * Lync 2013 (and later) with buddy list not migrated
1280 * - Lync 2013 with buddy list migrated to Unified Contact Store (UCS)
1281 * * Notify piggy-backed on SUBSCRIBE response with empty list
1282 * * NOTIFY send by server with standard list (ignored by us)
1284 if (sipe_strequal(sipe_xml_name(isc
), "contactList")) {
1285 const gchar
*ucsmode
= sipe_xml_attribute(isc
, "ucsmode");
1287 SIPE_CORE_PRIVATE_FLAG_UNSET(LYNC2013
);
1289 gboolean migrated
= sipe_strcase_equal(ucsmode
,
1291 SIPE_CORE_PRIVATE_FLAG_SET(LYNC2013
);
1292 SIPE_LOG_INFO_NOFORMAT("sipe_process_roaming_contacts: contact list contains 'ucsmode' attribute (indicates Lync 2013+)");
1295 SIPE_LOG_INFO_NOFORMAT("sipe_process_roaming_contacts: contact list has been migrated to Unified Contact Store (UCS)");
1296 sipe_ucs_init(sipe_private
, migrated
);
1299 if (!sipe_ucs_is_migrated(sipe_private
)) {
1300 /* Start processing contact list */
1301 sipe_backend_buddy_list_processing_start(SIPE_CORE_PUBLIC
);
1304 for (group_node
= sipe_xml_child(isc
, "group"); group_node
; group_node
= sipe_xml_twin(group_node
))
1305 add_new_group(sipe_private
, group_node
);
1307 /* Make sure we have at least one group */
1308 if (sipe_group_count(sipe_private
) == 0) {
1309 sipe_group_create(sipe_private
,
1311 _("Other Contacts"),
1315 /* Parse contacts */
1316 for (item
= sipe_xml_child(isc
, "contact"); item
; item
= sipe_xml_twin(item
)) {
1317 const gchar
*name
= sipe_xml_attribute(item
, "uri");
1318 gchar
*uri
= sip_uri_from_name(name
);
1319 add_new_buddy(sipe_private
, item
, uri
);
1323 sipe_buddy_cleanup_local_list(sipe_private
);
1325 /* Add self-contact if not there yet. 2005 systems. */
1326 /* This will resemble subscription to roaming_self in 2007 systems */
1327 if (!SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
1328 gchar
*self_uri
= sip_uri_self(sipe_private
);
1329 sipe_buddy_add(sipe_private
,
1336 /* Finished processing contact list */
1337 sipe_backend_buddy_list_processing_finish(SIPE_CORE_PUBLIC
);
1340 /* Process buddy list updates */
1341 } else if (sipe_strequal(sipe_xml_name(isc
), "contactDelta")) {
1343 /* Process new groups */
1344 for (group_node
= sipe_xml_child(isc
, "addedGroup"); group_node
; group_node
= sipe_xml_twin(group_node
))
1345 add_new_group(sipe_private
, group_node
);
1347 /* Process modified groups */
1348 for (group_node
= sipe_xml_child(isc
, "modifiedGroup"); group_node
; group_node
= sipe_xml_twin(group_node
)) {
1349 struct sipe_group
*group
= sipe_group_find_by_id(sipe_private
,
1350 (int)g_ascii_strtod(sipe_xml_attribute(group_node
, "id"),
1353 const gchar
*name
= get_group_name(group_node
);
1355 if (!(is_empty(name
) ||
1356 sipe_strequal(group
->name
, name
)) &&
1357 sipe_group_rename(sipe_private
,
1360 SIPE_DEBUG_INFO("Replaced group %d name with %s", group
->id
, name
);
1364 /* Process new buddies */
1365 for (item
= sipe_xml_child(isc
, "addedContact"); item
; item
= sipe_xml_twin(item
)) {
1366 add_new_buddy(sipe_private
,
1368 sipe_xml_attribute(item
, "uri"));
1371 /* Process modified buddies */
1372 for (item
= sipe_xml_child(isc
, "modifiedContact"); item
; item
= sipe_xml_twin(item
)) {
1373 const gchar
*uri
= sipe_xml_attribute(item
, "uri");
1374 struct sipe_buddy
*buddy
= sipe_buddy_find_by_uri(sipe_private
,
1378 gchar
**item_groups
= g_strsplit(sipe_xml_attribute(item
,
1382 /* this should be defined. Otherwise we would get "deletedContact" */
1384 const gchar
*name
= sipe_xml_attribute(item
, "name");
1385 gboolean empty_name
= is_empty(name
);
1386 GSList
*found
= NULL
;
1389 while (item_groups
[i
]) {
1390 struct sipe_group
*group
= sipe_group_find_by_id(sipe_private
,
1391 g_ascii_strtod(item_groups
[i
],
1393 /* ignore unkown groups */
1395 sipe_backend_buddy b
= sipe_backend_buddy_find(SIPE_CORE_PUBLIC
,
1399 /* add group to found list */
1400 found
= g_slist_prepend(found
, group
);
1404 gchar
*b_alias
= sipe_backend_buddy_get_alias(SIPE_CORE_PUBLIC
,
1408 sipe_strequal(b_alias
, name
))) {
1409 sipe_backend_buddy_set_alias(SIPE_CORE_PUBLIC
,
1412 SIPE_DEBUG_INFO("Replaced for buddy %s in group '%s' old alias '%s' with '%s'",
1413 uri
, group
->name
, b_alias
, name
);
1418 const gchar
*alias
= empty_name
? uri
: name
;
1419 /* buddy was not in this group */
1420 sipe_backend_buddy_add(SIPE_CORE_PUBLIC
,
1424 sipe_buddy_insert_group(buddy
, group
);
1425 SIPE_DEBUG_INFO("Added buddy %s (alias '%s' to group '%s'",
1426 uri
, alias
, group
->name
);
1433 g_strfreev(item_groups
);
1435 /* removed from groups? */
1436 sipe_buddy_update_groups(sipe_private
,
1439 g_slist_free(found
);
1444 /* Process deleted buddies */
1445 for (item
= sipe_xml_child(isc
, "deletedContact"); item
; item
= sipe_xml_twin(item
)) {
1446 const gchar
*uri
= sipe_xml_attribute(item
, "uri");
1447 struct sipe_buddy
*buddy
= sipe_buddy_find_by_uri(sipe_private
,
1451 SIPE_DEBUG_INFO("Removing buddy %s", uri
);
1452 sipe_buddy_remove(sipe_private
, buddy
);
1456 /* Process deleted groups
1458 * NOTE: all buddies will already have been removed from the
1459 * group prior to this. The log shows that OCS actually
1460 * sends two separate updates when you delete a group:
1462 * - first one with "modifiedContact" removing buddies
1463 * from the group, leaving it empty, and
1465 * - then one with "deletedGroup" removing the group
1467 for (group_node
= sipe_xml_child(isc
, "deletedGroup"); group_node
; group_node
= sipe_xml_twin(group_node
))
1468 sipe_group_remove(sipe_private
,
1469 sipe_group_find_by_id(sipe_private
,
1470 (int)g_ascii_strtod(sipe_xml_attribute(group_node
, "id"),
1476 /* Subscribe to buddies, if contact list not migrated to UCS */
1477 if (!sipe_ucs_is_migrated(sipe_private
))
1478 sipe_subscribe_presence_initial(sipe_private
);
1480 /* for 2005 systems schedule contacts' status update
1481 * based on their calendar information
1483 if (!SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
1484 sipe_ocs2005_schedule_status_update(sipe_private
, time(NULL
));
1490 static void sipe_process_roaming_acl(struct sipe_core_private
*sipe_private
,
1496 xml
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1500 /* [MS-SIP]: deltaNum MUST be non-zero */
1501 delta
= sipe_xml_int_attribute(xml
, "deltaNum", 0);
1503 sipe_private
->deltanum_acl
= delta
;
1509 struct sipe_auth_job
{
1511 struct sipe_core_private
*sipe_private
;
1514 void sipe_core_contact_allow_deny(struct sipe_core_public
*sipe_public
,
1518 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1521 SIPE_DEBUG_INFO("sipe_core_contact_allow_deny: authorizing contact %s", who
);
1523 SIPE_DEBUG_INFO("sipe_core_contact_allow_deny: blocking contact %s", who
);
1526 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
1527 sipe_ocs2007_change_access_level(sipe_private
,
1528 (allow
? -1 : 32000),
1530 sipe_get_no_sip_uri(who
));
1532 sip_soap_ocs2005_setacl(sipe_private
, who
, allow
);
1537 static void sipe_auth_user_cb(gpointer data
)
1539 struct sipe_auth_job
*job
= (struct sipe_auth_job
*) data
;
1542 sipe_core_contact_allow_deny((struct sipe_core_public
*)job
->sipe_private
,
1548 static void sipe_deny_user_cb(gpointer data
)
1550 struct sipe_auth_job
*job
= (struct sipe_auth_job
*) data
;
1553 sipe_core_contact_allow_deny((struct sipe_core_public
*)job
->sipe_private
,
1560 static void sipe_process_presence_wpending (struct sipe_core_private
*sipe_private
,
1561 struct sipmsg
* msg
)
1564 const sipe_xml
*watcher
;
1565 // Ensure it's either not a response (eg it's a BENOTIFY) or that it's a 200 OK response
1566 if (msg
->response
!= 0 && msg
->response
!= 200) return;
1568 if (msg
->bodylen
== 0 || msg
->body
== NULL
|| sipe_strequal(sipmsg_find_header(msg
, "Event"), "msrtc.wpending")) return;
1570 watchers
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1571 if (!watchers
) return;
1573 for (watcher
= sipe_xml_child(watchers
, "watcher"); watcher
; watcher
= sipe_xml_twin(watcher
)) {
1574 gchar
* remote_user
= g_strdup(sipe_xml_attribute(watcher
, "uri"));
1575 gchar
* alias
= g_strdup(sipe_xml_attribute(watcher
, "displayName"));
1576 gboolean on_list
= sipe_buddy_find_by_uri(sipe_private
, remote_user
) != NULL
;
1578 // TODO pull out optional displayName to pass as alias
1580 struct sipe_auth_job
* job
= g_new0(struct sipe_auth_job
, 1);
1581 job
->who
= remote_user
;
1582 job
->sipe_private
= sipe_private
;
1583 sipe_backend_buddy_request_authorization(SIPE_CORE_PUBLIC
,
1594 sipe_xml_free(watchers
);
1599 * Dispatcher for all incoming subscription information
1600 * whether it comes from NOTIFY, BENOTIFY requests or
1601 * piggy-backed to subscription's OK responce.
1603 void process_incoming_notify(struct sipe_core_private
*sipe_private
,
1606 const gchar
*content_type
= sipmsg_find_header(msg
, "Content-Type");
1607 const gchar
*event
= sipmsg_find_header(msg
, "Event");
1608 const gchar
*subscription_state
= sipmsg_find_header(msg
, "subscription-state");
1610 SIPE_DEBUG_INFO("process_incoming_notify: subscription_state: %s", subscription_state
? subscription_state
: "");
1612 /* implicit subscriptions */
1613 if (content_type
&& g_str_has_prefix(content_type
, "application/ms-imdn+xml")) {
1614 sipe_process_imdn(sipe_private
, msg
);
1616 /* event subscriptions */
1619 /* One-off subscriptions - sent with "Expires: 0" */
1620 if (sipe_strcase_equal(event
, "vnd-microsoft-provisioning-v2")) {
1621 sipe_process_provisioning_v2(sipe_private
, msg
);
1622 } else if (sipe_strcase_equal(event
, "vnd-microsoft-provisioning")) {
1623 sipe_process_provisioning(sipe_private
, msg
);
1624 } else if (sipe_strcase_equal(event
, "presence")) {
1625 sipe_process_presence(sipe_private
, msg
);
1626 } else if (sipe_strcase_equal(event
, "registration-notify")) {
1627 sipe_process_registration_notify(sipe_private
, msg
);
1629 /* Subscriptions with timeout */
1630 } else if (!subscription_state
|| strstr(subscription_state
, "active")) {
1631 if (sipe_strcase_equal(event
, "vnd-microsoft-roaming-contacts")) {
1632 sipe_process_roaming_contacts(sipe_private
, msg
);
1633 } else if (sipe_strcase_equal(event
, "vnd-microsoft-roaming-self")) {
1634 sipe_ocs2007_process_roaming_self(sipe_private
, msg
);
1635 } else if (sipe_strcase_equal(event
, "vnd-microsoft-roaming-ACL")) {
1636 sipe_process_roaming_acl(sipe_private
, msg
);
1637 } else if (sipe_strcase_equal(event
, "presence.wpending")) {
1638 sipe_process_presence_wpending(sipe_private
, msg
);
1639 } else if (sipe_strcase_equal(event
, "conference")) {
1640 sipe_process_conference(sipe_private
, msg
);