From 23397e26be2b78d1bee69a118c1e1f73eade6a6c Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 25 Apr 2016 17:14:49 +0200 Subject: [PATCH] friendlist: add linphone_friend_list_enable_subscriptions API --- coreapi/friend.c | 3 ++- coreapi/friendlist.c | 26 +++++++++++++++++++------- coreapi/friendlist.h | 9 +++++++-- coreapi/linphonecore.c | 2 +- coreapi/private.h | 1 + 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/coreapi/friend.c b/coreapi/friend.c index 81d9e0f21..eb8c017aa 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -387,8 +387,9 @@ void linphone_friend_remove_incoming_subscription(LinphoneFriend *lf, SalOp *op) static void linphone_friend_unsubscribe(LinphoneFriend *lf){ if (lf->outsub!=NULL) { sal_unsubscribe(lf->outsub); - lf->subscribe_active=FALSE; } + /* for friend list there is no necessary outsub*/ + lf->subscribe_active=FALSE; } void linphone_friend_invalidate_subscription(LinphoneFriend *lf){ diff --git a/coreapi/friendlist.c b/coreapi/friendlist.c index 617631cc5..28ec0adf3 100644 --- a/coreapi/friendlist.c +++ b/coreapi/friendlist.c @@ -285,6 +285,7 @@ static bool_t linphone_friend_list_has_subscribe_inactive(const LinphoneFriendLi static LinphoneFriendList * linphone_friend_list_new(void) { LinphoneFriendList *list = belle_sip_object_new(LinphoneFriendList); list->cbs = linphone_friend_list_cbs_new(); + list->enable_subscriptions = FALSE; belle_sip_object_ref(list); return list; } @@ -541,12 +542,12 @@ static void carddav_updated(LinphoneCardDavContext *cdc, LinphoneFriend *lf_new, void linphone_friend_list_synchronize_friends_from_server(LinphoneFriendList *list) { LinphoneCardDavContext *cdc = NULL; - + if (!list || !list->uri || !list->lc) { ms_error("FATAL"); return; } - + cdc = linphone_carddav_context_new(list); if (cdc) { cdc->contact_created_cb = carddav_created; @@ -606,19 +607,19 @@ LinphoneFriend * linphone_friend_list_find_friend_by_out_subscribe(const Linphon return NULL; } -void linphone_friend_list_close_subscriptions(LinphoneFriendList *list) { - /* FIXME we should wait until subscription to complete. */ +static void linphone_friend_list_close_subscriptions(LinphoneFriendList *list) { + /* FIXME we should wait until subscription to complete. */ if (list->event) { linphone_event_terminate(list->event); linphone_event_unref(list->event); list->event = NULL; - } else if (list->friends) - ms_list_for_each(list->friends, (void (*)(void *))linphone_friend_close_subscriptions); + } + ms_list_for_each(list->friends, (void (*)(void *))linphone_friend_close_subscriptions); } void linphone_friend_list_update_subscriptions(LinphoneFriendList *list, LinphoneProxyConfig *cfg, bool_t only_when_registered) { const MSList *elem; - if (list->rls_uri != NULL) { + 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)) { @@ -852,3 +853,14 @@ void linphone_friend_list_export_friends_as_vcard4_file(LinphoneFriendList *list fclose(file); } + +void linphone_friend_list_enable_subscriptions(LinphoneFriendList *list, bool_t enabled) { + if (list->enable_subscriptions != enabled) { + if (enabled) { + linphone_friend_list_update_subscriptions(list, NULL, TRUE); + } else { + linphone_friend_list_close_subscriptions(list); + } + list->enable_subscriptions = enabled; + } +} diff --git a/coreapi/friendlist.h b/coreapi/friendlist.h index acda26934..567e389e5 100644 --- a/coreapi/friendlist.h +++ b/coreapi/friendlist.h @@ -209,8 +209,6 @@ LINPHONE_PUBLIC LinphoneFriend * linphone_friend_list_find_friend_by_uri(const L **/ LINPHONE_PUBLIC LinphoneFriend * linphone_friend_list_find_friend_by_ref_key(const LinphoneFriendList *list, const char *ref_key); -LINPHONE_PUBLIC void linphone_friend_list_close_subscriptions(LinphoneFriendList *list); - LINPHONE_PUBLIC void linphone_friend_list_update_subscriptions(LinphoneFriendList *list, LinphoneProxyConfig *cfg, bool_t only_when_registered); /** @@ -408,6 +406,13 @@ LINPHONE_PUBLIC int linphone_friend_list_import_friends_from_vcard4_buffer(Linph */ LINPHONE_PUBLIC void linphone_friend_list_export_friends_as_vcard4_file(LinphoneFriendList *list, const char *vcard_file); +/** + * Enable subscription to NOTIFYes of all friends list + * @param[in] list the LinphoneFriendList object + * @param[in] enabled should subscription be enabled or not + */ +LINPHONE_PUBLIC void linphone_friend_list_enable_subscriptions(LinphoneFriendList *list, bool_t enabled); + /** * @} */ diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 82156b1ca..e84f8e5d2 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -6559,7 +6559,7 @@ static void linphone_core_uninit(LinphoneCore *lc) for (elem = lc->friends_lists; elem != NULL; elem = ms_list_next(elem)) { LinphoneFriendList *list = (LinphoneFriendList *)elem->data; - linphone_friend_list_close_subscriptions(list); + linphone_friend_list_enable_subscriptions(list, FALSE); if (list->event) wait_until_unsubscribe = TRUE; } diff --git a/coreapi/private.h b/coreapi/private.h index 28387c426..1cbecf6e4 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -729,6 +729,7 @@ struct _LinphoneFriendList { MSList *dirty_friends_to_update; int revision; LinphoneFriendListCbs *cbs; + bool_t enable_subscriptions; }; BELLE_SIP_DECLARE_VPTR(LinphoneFriendList);