From 5eb8ab86a2581476c58805c7019e3f7d831c8f5f Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sat, 10 Aug 2013 20:31:20 +0300 Subject: [PATCH] buddy: factor out local list cleanup code This also need to be called after UCS has processed the contact list. --- src/core/sipe-buddy.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/core/sipe-buddy.h | 8 ++++++++ src/core/sipe-notify.c | 49 +------------------------------------------------ src/core/sipe-ucs.c | 1 + 4 files changed, 59 insertions(+), 48 deletions(-) diff --git a/src/core/sipe-buddy.c b/src/core/sipe-buddy.c index 20c78fc9..c074cea4 100644 --- a/src/core/sipe-buddy.c +++ b/src/core/sipe-buddy.c @@ -108,6 +108,55 @@ struct sipe_buddy *sipe_buddy_add(struct sipe_core_private *sipe_private, return buddy; } +void sipe_buddy_cleanup_local_list(struct sipe_core_private *sipe_private) +{ + GSList *buddies = sipe_backend_buddy_find_all(SIPE_CORE_PUBLIC, + NULL, + NULL); + GSList *entry = buddies; + + SIPE_DEBUG_INFO("sipe_buddy_cleanup_local_list: overall %d backend buddies (including clones)", + g_slist_length(buddies)); + SIPE_DEBUG_INFO("sipe_buddy_cleanup_local_list: %d sipe buddies (unique)", + sipe_buddy_count(sipe_private)); + while (entry) { + sipe_backend_buddy bb = entry->data; + gchar *bname = sipe_backend_buddy_get_name(SIPE_CORE_PUBLIC, + bb); + gchar *gname = sipe_backend_buddy_get_group_name(SIPE_CORE_PUBLIC, + bb); + struct sipe_buddy *buddy = sipe_buddy_find_by_uri(sipe_private, + bname); + gboolean in_sipe_groups = FALSE; + + if (buddy) { + GSList *entry2 = buddy->groups; + + while (entry2) { + struct sipe_group *group = entry2->data; + if (sipe_strequal(group->name, gname)) { + in_sipe_groups = TRUE; + break; + } + entry2 = entry2->next; + } + } + + if (!in_sipe_groups) { + SIPE_DEBUG_INFO("sipe_buddy_cleanup_local_list: REMOVING '%s' from local group '%s', as buddy is not in that group on remote contact list", + bname, gname); + sipe_backend_buddy_remove(SIPE_CORE_PUBLIC, bb); + } + + g_free(gname); + g_free(bname); + + entry = entry->next; + } + + g_slist_free(buddies); +} + struct sipe_buddy *sipe_buddy_find_by_uri(struct sipe_core_private *sipe_private, const gchar *uri) { diff --git a/src/core/sipe-buddy.h b/src/core/sipe-buddy.h index 51bc342c..87d2727f 100644 --- a/src/core/sipe-buddy.h +++ b/src/core/sipe-buddy.h @@ -75,6 +75,14 @@ struct sipe_buddy *sipe_buddy_add(struct sipe_core_private *sipe_private, const gchar *exchange_key); /** + * Remove entries from local buddy list that do not have corresponding entries + * in the ones in the contact list sent by the server + * + * @param sipe_private SIPE core data + */ +void sipe_buddy_cleanup_local_list(struct sipe_core_private *sipe_private); + +/** * Find buddy by URI * * @param sipe_private SIPE core data diff --git a/src/core/sipe-notify.c b/src/core/sipe-notify.c index 2c200d1e..9c288de5 100644 --- a/src/core/sipe-notify.c +++ b/src/core/sipe-notify.c @@ -1075,53 +1075,6 @@ static void sipe_process_registration_notify(struct sipe_core_private *sipe_priv } -/** - * Removes entries from local buddy list - * that does not correspond ones in the roaming contact list. - */ -static void sipe_cleanup_local_blist(struct sipe_core_private *sipe_private) -{ - GSList *buddies = sipe_backend_buddy_find_all(SIPE_CORE_PUBLIC, - NULL, NULL); - GSList *entry = buddies; - struct sipe_buddy *buddy; - sipe_backend_buddy b; - gchar *bname; - gchar *gname; - - SIPE_DEBUG_INFO("sipe_cleanup_local_blist: overall %d backend buddies (including clones)", g_slist_length(buddies)); - SIPE_DEBUG_INFO("sipe_cleanup_local_blist: %d sipe buddies (unique)", sipe_buddy_count(sipe_private)); - while (entry) { - b = entry->data; - gname = sipe_backend_buddy_get_group_name(SIPE_CORE_PUBLIC, b); - bname = sipe_backend_buddy_get_name(SIPE_CORE_PUBLIC, b); - buddy = sipe_buddy_find_by_uri(sipe_private, bname); - if(buddy) { - gboolean in_sipe_groups = FALSE; - GSList *entry2 = buddy->groups; - while (entry2) { - struct sipe_group *group = entry2->data; - if (sipe_strequal(group->name, gname)) { - in_sipe_groups = TRUE; - break; - } - entry2 = entry2->next; - } - if(!in_sipe_groups) { - SIPE_DEBUG_INFO("*** REMOVING %s from blist group: %s as not having this group in roaming list", bname, gname); - sipe_backend_buddy_remove(SIPE_CORE_PUBLIC, b); - } - } else { - SIPE_DEBUG_INFO("*** REMOVING %s from blist group: %s as this buddy not in roaming list", bname, gname); - sipe_backend_buddy_remove(SIPE_CORE_PUBLIC, b); - } - g_free(bname); - g_free(gname); - entry = entry->next; - } - g_slist_free(buddies); -} - /* Replace "~" with localized version of "Other Contacts" */ static const gchar *get_group_name(const sipe_xml *node) { @@ -1299,7 +1252,7 @@ static gboolean sipe_process_roaming_contacts(struct sipe_core_private *sipe_pri g_free(uri); } - sipe_cleanup_local_blist(sipe_private); + sipe_buddy_cleanup_local_list(sipe_private); /* Add self-contact if not there yet. 2005 systems. */ /* This will resemble subscription to roaming_self in 2007 systems */ diff --git a/src/core/sipe-ucs.c b/src/core/sipe-ucs.c index fecee67b..926928b5 100644 --- a/src/core/sipe-ucs.c +++ b/src/core/sipe-ucs.c @@ -355,6 +355,7 @@ static void sipe_ucs_get_im_item_list_response(struct sipe_core_private *sipe_pr } /* Finished processing contact list */ + sipe_buddy_cleanup_local_list(sipe_private); sipe_backend_buddy_list_processing_finish(SIPE_CORE_PUBLIC); sipe_subscribe_presence_initial(sipe_private); } -- 2.11.4.GIT