From 0c28c1955dcfda7c07b6122a30d2a763435d4784 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sun, 11 Aug 2013 16:25:37 +0300 Subject: [PATCH] buddy: refactor URI normalization code --- src/core/sipe-buddy.c | 19 +++++++++++++------ src/core/sipe-notify.c | 5 +---- src/core/sipe-ucs.c | 17 +++++------------ 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/core/sipe-buddy.c b/src/core/sipe-buddy.c index a5b3b9c8..ddd912c1 100644 --- a/src/core/sipe-buddy.c +++ b/src/core/sipe-buddy.c @@ -80,12 +80,16 @@ struct sipe_buddy *sipe_buddy_add(struct sipe_core_private *sipe_private, const gchar *uri, const gchar *exchange_key) { - struct sipe_buddy *buddy = sipe_buddy_find_by_uri(sipe_private, uri); + /* Buddy name must be lower case as we use purple_normalize_nocase() to compare */ + gchar *normalized_uri = g_ascii_strdown(uri, -1); + struct sipe_buddy *buddy = sipe_buddy_find_by_uri(sipe_private, + normalized_uri); + if (!buddy) { struct sipe_buddies *buddies = sipe_private->buddies; buddy = g_new0(struct sipe_buddy, 1); - buddy->name = g_strdup(uri); + buddy->name = normalized_uri; g_hash_table_insert(buddies->uri, buddy->name, buddy); @@ -98,14 +102,17 @@ struct sipe_buddy *sipe_buddy_add(struct sipe_core_private *sipe_private, } - SIPE_DEBUG_INFO("sipe_buddy_add: Added buddy %s", uri); + SIPE_DEBUG_INFO("sipe_buddy_add: Added buddy %s", normalized_uri); + + buddy_fetch_photo(sipe_private, normalized_uri); - buddy_fetch_photo(sipe_private, uri); + normalized_uri = NULL; /* buddy takes ownership */ } else { - SIPE_DEBUG_INFO("sipe_buddy_add: Buddy %s already exists", uri); + SIPE_DEBUG_INFO("sipe_buddy_add: Buddy %s already exists", normalized_uri); } + g_free(normalized_uri); - return buddy; + return(buddy); } void sipe_buddy_add_to_group(struct sipe_core_private *sipe_private, diff --git a/src/core/sipe-notify.c b/src/core/sipe-notify.c index 7e0ddec9..f5d7b2d5 100644 --- a/src/core/sipe-notify.c +++ b/src/core/sipe-notify.c @@ -1096,8 +1096,6 @@ static void add_new_buddy(struct sipe_core_private *sipe_private, const gchar *uri) { const gchar *name = sipe_xml_attribute(node, "name"); - /* Buddy name must be lower case as we use purple_normalize_nocase() to compare */ - gchar *normalized_uri = g_ascii_strdown(uri, -1); struct sipe_buddy *buddy = NULL; gchar *tmp; gchar **item_groups; @@ -1127,7 +1125,7 @@ static void add_new_buddy(struct sipe_core_private *sipe_private, if (group) { if (!buddy) buddy = sipe_buddy_add(sipe_private, - normalized_uri, + uri, NULL); sipe_buddy_add_to_group(sipe_private, @@ -1143,7 +1141,6 @@ static void add_new_buddy(struct sipe_core_private *sipe_private, } g_strfreev(item_groups); - g_free(normalized_uri); } static gboolean sipe_process_roaming_contacts(struct sipe_core_private *sipe_private, diff --git a/src/core/sipe-ucs.c b/src/core/sipe-ucs.c index 6c60ed4a..a92b34e7 100644 --- a/src/core/sipe-ucs.c +++ b/src/core/sipe-ucs.c @@ -287,21 +287,14 @@ static void sipe_ucs_get_im_item_list_response(struct sipe_core_private *sipe_pr } if (!(is_empty(address) || is_empty(key))) { - /* - * Buddy name must be lower case as we use - * purple_normalize_nocase() to compare - */ - gchar *uri = sip_uri_from_name(address); - gchar *normalized_uri = g_ascii_strdown(uri, -1); + gchar *uri = sip_uri_from_name(address); + struct sipe_buddy *buddy = sipe_buddy_add(sipe_private, + uri, + key); g_free(uri); - sipe_buddy_add(sipe_private, - normalized_uri, - key); - SIPE_DEBUG_INFO("sipe_ucs_get_im_item_list_response: persona URI '%s' key '%s'", - normalized_uri, key); - g_free(normalized_uri); + buddy->name, key); } g_free(address); } -- 2.11.4.GIT