From 421d73f024c5264ba119d447c75d15a22c9e22f5 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Fri, 9 Aug 2013 20:43:40 +0300 Subject: [PATCH] ucs: extract Exchange Key from persona We need this ID to modify contacts and link them to groups. --- src/core/sipe-buddy.c | 9 ++++++--- src/core/sipe-buddy.h | 7 +++++-- src/core/sipe-notify.c | 5 +++-- src/core/sipe-ucs.c | 23 +++++++++++++++++++++-- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/core/sipe-buddy.c b/src/core/sipe-buddy.c index a4045d29..1a621c32 100644 --- a/src/core/sipe-buddy.c +++ b/src/core/sipe-buddy.c @@ -69,12 +69,14 @@ static void buddy_fetch_photo(struct sipe_core_private *sipe_private, static void photo_response_data_free(struct photo_response_data *data); struct sipe_buddy *sipe_buddy_add(struct sipe_core_private *sipe_private, - const gchar *uri) + const gchar *uri, + const gchar *exchange_key) { struct sipe_buddy *buddy = g_hash_table_lookup(sipe_private->buddies, uri); if (!buddy) { buddy = g_new0(struct sipe_buddy, 1); - buddy->name = g_strdup(uri); + buddy->name = g_strdup(uri); + buddy->exchange_key = g_strdup(exchange_key); g_hash_table_insert(sipe_private->buddies, buddy->name, buddy); SIPE_DEBUG_INFO("sipe_buddy_add: Added buddy %s", uri); @@ -105,6 +107,7 @@ static void buddy_free(struct sipe_buddy *buddy) */ g_free(buddy->name); #endif + g_free(buddy->exchange_key); g_free(buddy->activity); g_free(buddy->meeting_subject); g_free(buddy->meeting_location); @@ -230,7 +233,7 @@ void sipe_core_buddy_add(struct sipe_core_public *sipe_public, struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE; if (!g_hash_table_lookup(sipe_private->buddies, uri)) { - struct sipe_buddy *b = sipe_buddy_add(sipe_private, uri); + struct sipe_buddy *b = sipe_buddy_add(sipe_private, uri, NULL); b->just_added = TRUE; sipe_subscribe_presence_single_cb(sipe_private, b->name); diff --git a/src/core/sipe-buddy.h b/src/core/sipe-buddy.h index 94a733d0..dd927ce9 100644 --- a/src/core/sipe-buddy.h +++ b/src/core/sipe-buddy.h @@ -3,7 +3,7 @@ * * pidgin-sipe * - * Copyright (C) 2010-12 SIPE Project + * Copyright (C) 2010-2013 SIPE Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ struct sipe_cal_working_hours; struct sipe_buddy { gchar *name; + gchar *exchange_key; gchar *activity; gchar *meeting_subject; gchar *meeting_location; @@ -65,11 +66,13 @@ struct sipe_buddy { * * @param sipe_private SIPE core data * @param uri SIP URI of a buddy + * @param exchange_key Exchange key (may be @c NULL) * * @return @c sipe_buddy structure */ struct sipe_buddy *sipe_buddy_add(struct sipe_core_private *sipe_private, - const gchar *uri); + const gchar *uri, + const gchar *exchange_key); /** * Cancels buddy subscriptions and then deletes the buddy diff --git a/src/core/sipe-notify.c b/src/core/sipe-notify.c index 247411f3..7950f468 100644 --- a/src/core/sipe-notify.c +++ b/src/core/sipe-notify.c @@ -1203,7 +1203,8 @@ static void add_new_buddy(struct sipe_core_private *sipe_private, if (!buddy) buddy = sipe_buddy_add(sipe_private, - normalized_uri); + normalized_uri, + NULL); buddy->groups = sipe_utils_slist_insert_unique_sorted(buddy->groups, group, @@ -1304,7 +1305,7 @@ static gboolean sipe_process_roaming_contacts(struct sipe_core_private *sipe_pri /* This will resemble subscription to roaming_self in 2007 systems */ if (!SIPE_CORE_PRIVATE_FLAG_IS(OCS2007)) { gchar *self_uri = sip_uri_self(sipe_private); - sipe_buddy_add(sipe_private, self_uri); + sipe_buddy_add(sipe_private, self_uri, NULL); g_free(self_uri); } diff --git a/src/core/sipe-ucs.c b/src/core/sipe-ucs.c index eae51077..8cddc583 100644 --- a/src/core/sipe-ucs.c +++ b/src/core/sipe-ucs.c @@ -267,8 +267,26 @@ static void sipe_ucs_get_im_item_list_response(struct sipe_core_private *sipe_pr "ImAddress")); gchar *name = sipe_xml_data(sipe_xml_child(persona_node, "DisplayName")); + const gchar *key = NULL; + const sipe_xml *attr_node; + + /* extract Exchange key - not sure if this is correct */ + for (attr_node = sipe_xml_child(persona_node, + "Attributions/Attribution"); + attr_node; + attr_node = sipe_xml_twin(attr_node)) { + const sipe_xml *id_node = sipe_xml_child(attr_node, + "SourceId"); + gchar *type = sipe_xml_data(sipe_xml_child(attr_node, + "DisplayName")); + if (id_node && + sipe_strequal(type, "Lync Contacts")) { + key = sipe_xml_attribute(id_node, "Id"); + break; + } + } - if (!(is_empty(address) || is_empty(name))) { + if (!(is_empty(address) || is_empty(name) || is_empty(key))) { /* * Buddy name must be lower case as we use * purple_normalize_nocase() to compare @@ -278,7 +296,8 @@ static void sipe_ucs_get_im_item_list_response(struct sipe_core_private *sipe_pr g_free(uri); sipe_buddy_add(sipe_private, - normalized_uri); + normalized_uri, + key); g_free(normalized_uri); } g_free(name); -- 2.11.4.GIT