From 8377540fc541e948eea34d929facb3e5a6d3dd2c Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 29 Apr 2016 15:45:53 +0200 Subject: [PATCH] friendlist.c: fix linphone_friend_list_update_subscriptions to avoid switching to P2P presence in case of disabled subscriptions list --- coreapi/friendlist.c | 82 +++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/coreapi/friendlist.c b/coreapi/friendlist.c index 4b2aea12e..8e4696933 100644 --- a/coreapi/friendlist.c +++ b/coreapi/friendlist.c @@ -619,48 +619,52 @@ static void linphone_friend_list_close_subscriptions(LinphoneFriendList *list) { void linphone_friend_list_update_subscriptions(LinphoneFriendList *list, LinphoneProxyConfig *cfg, bool_t only_when_registered) { const MSList *elem; - if (list->enable_subscriptions && list->rls_uri != NULL) { - LinphoneAddress *address = linphone_address_new(list->rls_uri); - char *xml_content = create_resource_list_xml(list); - if ((address != NULL) && (xml_content != NULL) && (linphone_friend_list_has_subscribe_inactive(list) == TRUE)) { - unsigned char digest[16]; - bctoolbox_md5((unsigned char *)xml_content, strlen(xml_content), digest); - if ((list->event != NULL) && (list->content_digest != NULL) && (memcmp(list->content_digest, digest, sizeof(digest)) == 0)) { - /* The content has not changed, only refresh the event. */ - linphone_event_refresh_subscribe(list->event); - } else { - LinphoneContent *content; - int expires = lp_config_get_int(list->lc->config, "sip", "rls_presence_expires", 3600); - list->expected_notification_version = 0; - if (list->content_digest != NULL) ms_free(list->content_digest); - list->content_digest = ms_malloc(sizeof(digest)); - memcpy(list->content_digest, digest, sizeof(digest)); - if (list->event != NULL) { - linphone_event_terminate(list->event); - linphone_event_unref(list->event); + if (list->rls_uri != NULL) { + if (list->enable_subscriptions) { + LinphoneAddress *address = linphone_address_new(list->rls_uri); + char *xml_content = create_resource_list_xml(list); + if ((address != NULL) && (xml_content != NULL) && (linphone_friend_list_has_subscribe_inactive(list) == TRUE)) { + unsigned char digest[16]; + bctoolbox_md5((unsigned char *)xml_content, strlen(xml_content), digest); + if ((list->event != NULL) && (list->content_digest != NULL) && (memcmp(list->content_digest, digest, sizeof(digest)) == 0)) { + /* The content has not changed, only refresh the event. */ + linphone_event_refresh_subscribe(list->event); + } else { + LinphoneContent *content; + int expires = lp_config_get_int(list->lc->config, "sip", "rls_presence_expires", 3600); + list->expected_notification_version = 0; + if (list->content_digest != NULL) ms_free(list->content_digest); + list->content_digest = ms_malloc(sizeof(digest)); + memcpy(list->content_digest, digest, sizeof(digest)); + if (list->event != NULL) { + linphone_event_terminate(list->event); + linphone_event_unref(list->event); + } + list->event = linphone_core_create_subscribe(list->lc, address, "presence", expires); + linphone_event_ref(list->event); + linphone_event_set_internal(list->event, TRUE); + linphone_event_add_custom_header(list->event, "Require", "recipient-list-subscribe"); + linphone_event_add_custom_header(list->event, "Supported", "eventlist"); + linphone_event_add_custom_header(list->event, "Accept", "multipart/related, application/pidf+xml, application/rlmi+xml"); + linphone_event_add_custom_header(list->event, "Content-Disposition", "recipient-list"); + content = linphone_core_create_content(list->lc); + linphone_content_set_type(content, "application"); + linphone_content_set_subtype(content, "resource-lists+xml"); + linphone_content_set_string_buffer(content, xml_content); + if (linphone_core_content_encoding_supported(list->lc, "deflate")) { + linphone_content_set_encoding(content, "deflate"); + linphone_event_add_custom_header(list->event, "Accept-Encoding", "deflate"); + } + linphone_event_send_subscribe(list->event, content); + linphone_content_unref(content); + linphone_event_set_user_data(list->event, list); } - list->event = linphone_core_create_subscribe(list->lc, address, "presence", expires); - linphone_event_ref(list->event); - linphone_event_set_internal(list->event, TRUE); - linphone_event_add_custom_header(list->event, "Require", "recipient-list-subscribe"); - linphone_event_add_custom_header(list->event, "Supported", "eventlist"); - linphone_event_add_custom_header(list->event, "Accept", "multipart/related, application/pidf+xml, application/rlmi+xml"); - linphone_event_add_custom_header(list->event, "Content-Disposition", "recipient-list"); - content = linphone_core_create_content(list->lc); - linphone_content_set_type(content, "application"); - linphone_content_set_subtype(content, "resource-lists+xml"); - linphone_content_set_string_buffer(content, xml_content); - if (linphone_core_content_encoding_supported(list->lc, "deflate")) { - linphone_content_set_encoding(content, "deflate"); - linphone_event_add_custom_header(list->event, "Accept-Encoding", "deflate"); - } - linphone_event_send_subscribe(list->event, content); - linphone_content_unref(content); - linphone_event_set_user_data(list->event, list); } + if (address != NULL) linphone_address_unref(address); + if (xml_content != NULL) ms_free(xml_content); + } else { + ms_message("Friends list [%p] subscription update skipped since subscriptions not enabled yet", list); } - if (address != NULL) linphone_address_unref(address); - if (xml_content != NULL) ms_free(xml_content); } else { for (elem = list->friends; elem != NULL; elem = elem->next) { LinphoneFriend *lf = (LinphoneFriend *)elem->data;