From 1f0b6e41f2473270e06a7c080cefe158e7d9cc45 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sun, 4 Dec 2011 18:40:01 +0200 Subject: [PATCH] core cleanup: separate code for sipe_get_info() I removed the code for the "LinkedIn URL" info item. - it added no value to the end user - it depended on guessing the name. If that fails then we would show a broken URL which will only confuse the end user - if the LinkedIn URL changes then we will show a broken URL which will only confuse the end user --- src/api/core-depurple.h | 1 - src/api/sipe-backend.h | 41 ++++-- src/api/sipe-core.h | 3 + src/core/sipe-buddy.c | 258 +++++++++++++++++++++++++++++++++++ src/core/sipe.c | 327 --------------------------------------------- src/purple/purple-buddy.c | 46 +++++++ src/purple/purple-plugin.c | 8 +- 7 files changed, 347 insertions(+), 337 deletions(-) diff --git a/src/api/core-depurple.h b/src/api/core-depurple.h index 2afcc63e..0de6d23b 100644 --- a/src/api/core-depurple.h +++ b/src/api/core-depurple.h @@ -28,7 +28,6 @@ struct sipe_core_public; GList *sipe_buddy_menu(PurpleBuddy *buddy); void sipe_purple_setup(struct sipe_core_public *sipe_public, PurpleConnection *gc); -void sipe_get_info(PurpleConnection *gc, const char *username); /* Convenience macros */ #define PURPLE_ACCOUNT_TO_SIPE_CORE_PRIVATE ((struct sipe_core_private *)account->gc->proto_data) diff --git a/src/api/sipe-backend.h b/src/api/sipe-backend.h index a4bbc949..0d5d131d 100644 --- a/src/api/sipe-backend.h +++ b/src/api/sipe-backend.h @@ -706,6 +706,17 @@ gchar* sipe_backend_buddy_get_server_alias(struct sipe_core_public *sipe_public, const sipe_backend_buddy who); /** + * Gets the local alias for a contact + * + * @param sipe_public The handle representing the protocol instance making the call + * @param uri the budyy name + * + * @return the alias. Must be @g_free()'d. + */ +gchar *sipe_backend_buddy_get_local_alias(struct sipe_core_public *sipe_public, + const sipe_backend_buddy who); + +/** * Gets the name of the group a contact belongs to. * * @param sipe_public The handle representing the protocol instance making the call @@ -752,7 +763,7 @@ void sipe_backend_buddy_set_alias(struct sipe_core_public *sipe_public, const sipe_backend_buddy who, const gchar *alias); -/* +/** * Sets the server alias for a contact. * * @param sipe_public The handle representing the protocol instance making the call @@ -763,7 +774,7 @@ void sipe_backend_buddy_set_server_alias(struct sipe_core_public *sipe_public, const sipe_backend_buddy who, const gchar *alias); -/* +/** * Add a contact to the buddy list * * @param sipe_public The handle representing the protocol instance making the call @@ -777,7 +788,7 @@ sipe_backend_buddy sipe_backend_buddy_add(struct sipe_core_public *sipe_public, const gchar *alias, const gchar *groupname); -/* +/** * Remove a contact from the buddy list * * @param sipe_public The handle representing the protocol instance making the call @@ -786,16 +797,16 @@ sipe_backend_buddy sipe_backend_buddy_add(struct sipe_core_public *sipe_public, void sipe_backend_buddy_remove(struct sipe_core_public *sipe_public, const sipe_backend_buddy who); -/* +/** * Notifies the user that a remote user has wants to add the local user to his - * or her buddy list and requires authorization to do so. + * or her buddy list and requires authorization to do so. * * @param sipe_public The handle representing the protocol instance making the call * @param who The name of the user that added this account * @param alias The optional alias of the remote user * @param on_list True if the user is already in our list - * @param auth_cb The callback called when the local user accepts - * @param deny_cb The callback called when the local user rejects + * @param auth_cb The callback called when the local user accepts + * @param deny_cb The callback called when the local user rejects * @param data Data to be passed back to the above callbacks */ typedef void (*sipe_backend_buddy_request_authorization_cb)(void *); @@ -823,7 +834,7 @@ void sipe_backend_buddy_set_status(struct sipe_core_public *sipe_public, const gchar *who, const gchar *status_id); -/* +/** * Called when a new internal group is about to be added. If this returns FALSE, * the group will not be added. * @@ -834,6 +845,20 @@ void sipe_backend_buddy_set_status(struct sipe_core_public *sipe_public, gboolean sipe_backend_buddy_group_add(struct sipe_core_public *sipe_public, const gchar *group_name); +/** + * Present requested buddy information to the user + */ +struct sipe_backend_buddy_info; +struct sipe_backend_buddy_info *sipe_backend_buddy_info_start(struct sipe_core_public *sipe_public); +void sipe_backend_buddy_info_add(struct sipe_core_public *sipe_public, + struct sipe_backend_buddy_info *info, + const gchar *description, + const gchar *value); +void sipe_backend_buddy_info_break(struct sipe_core_public *sipe_public, + struct sipe_backend_buddy_info *info); +void sipe_backend_buddy_info_finalize(struct sipe_core_public *sipe_public, + struct sipe_backend_buddy_info *info, + const gchar *uri); #ifdef __cplusplus } #endif diff --git a/src/api/sipe-core.h b/src/api/sipe-core.h index e165d707..124636bd 100644 --- a/src/api/sipe-core.h +++ b/src/api/sipe-core.h @@ -411,6 +411,9 @@ void sipe_core_buddy_search(struct sipe_core_public *sipe_public, const gchar *company, const gchar *country); +void sipe_core_buddy_get_info(struct sipe_core_public *sipe_public, + const gchar *who); + /* status */ void sipe_core_status_set(struct sipe_core_public *sipe_public, const gchar *status_id, diff --git a/src/core/sipe-buddy.c b/src/core/sipe-buddy.c index afcfab2f..4952c00c 100644 --- a/src/core/sipe-buddy.c +++ b/src/core/sipe-buddy.c @@ -24,6 +24,7 @@ #include "config.h" #endif +#include #include #include @@ -31,7 +32,9 @@ #include "sipe-common.h" #include "http-conn.h" /* sipe-cal.h requires this */ #include "sipmsg.h" +#include "sip-csta.h" #include "sip-soap.h" +#include "sip-transport.h" #include "sipe-backend.h" #include "sipe-buddy.h" #include "sipe-cal.h" @@ -530,6 +533,261 @@ void sipe_core_buddy_search(struct sipe_core_public *sipe_public, g_strfreev(attrs); } +static gboolean process_options_response(SIPE_UNUSED_PARAMETER struct sipe_core_private *sipe_private, + struct sipmsg *msg, + SIPE_UNUSED_PARAMETER struct transaction *trans) +{ + if (msg->response != 200) { + SIPE_DEBUG_INFO("process_options_response: OPTIONS response is %d", + msg->response); + return(FALSE); + } else { + SIPE_DEBUG_INFO("process_options_response: body:\n%s", + msg->body ? msg->body : ""); + return(TRUE); + } +} + +/* Asks UA/proxy about its capabilities */ +static void sipe_options_request(struct sipe_core_private *sipe_private, + const char *who) +{ + gchar *to = sip_uri(who); + gchar *contact = get_contact(sipe_private); + gchar *request = g_strdup_printf("Accept: application/sdp\r\n" + "Contact: %s\r\n", + contact); + g_free(contact); + + sip_transport_request(sipe_private, + "OPTIONS", + to, + to, + request, + NULL, + NULL, + process_options_response); + + g_free(to); + g_free(request); +} + +static gboolean process_get_info_response(struct sipe_core_private *sipe_private, + struct sipmsg *msg, + struct transaction *trans) +{ + const gchar *uri = trans->payload->data; + sipe_backend_buddy bbuddy; + struct sipe_backend_buddy_info *info; + struct sipe_buddy *sbuddy; + gchar *alias = NULL; + gchar *device_name = NULL; + gchar *server_alias = NULL; + gchar *phone_number = NULL; + gchar *email = NULL; + gchar *site; + + info = sipe_backend_buddy_info_start(SIPE_CORE_PUBLIC); + if (info) return(FALSE); + + SIPE_DEBUG_INFO("Fetching %s's user info for %s", + uri, sipe_private->username); + + bbuddy = sipe_backend_buddy_find(SIPE_CORE_PUBLIC, uri, NULL); + alias = sipe_backend_buddy_get_local_alias(SIPE_CORE_PUBLIC, bbuddy); + + /* will query buddy UA's capabilities and send answer to log */ + if (sipe_backend_debug_enabled()) + sipe_options_request(sipe_private, uri); + + sbuddy = g_hash_table_lookup(sipe_private->buddies, uri); + if (sbuddy) { + device_name = sbuddy->device_name ? g_strdup(sbuddy->device_name) : NULL; + } + + if (msg->response != 200) { + SIPE_DEBUG_INFO("process_get_info_response: SERVICE response is %d", msg->response); + } else { + sipe_xml *searchResults; + const sipe_xml *mrow; + + SIPE_DEBUG_INFO("process_get_info_response: body:\n%s", + msg->body ? msg->body : ""); + + searchResults = sipe_xml_parse(msg->body, msg->bodylen); + if (!searchResults) { + + SIPE_DEBUG_INFO_NOFORMAT("process_get_info_response: no parseable searchResults"); + + } else if ((mrow = sipe_xml_child(searchResults, "Body/Array/row"))) { + const gchar *value; + + server_alias = g_strdup(sipe_xml_attribute(mrow, "displayName")); + email = g_strdup(sipe_xml_attribute(mrow, "email")); + phone_number = g_strdup(sipe_xml_attribute(mrow, "phone")); + + /* + * For 2007 system we will take this from ContactCard - + * it has cleaner tel: URIs at least + */ + if (!SIPE_CORE_PRIVATE_FLAG_IS(OCS2007)) { + char *tel_uri = sip_to_tel_uri(phone_number); + /* trims its parameters, so call first */ + sipe_buddy_update_property(sipe_private, uri, SIPE_BUDDY_INFO_DISPLAY_NAME, server_alias); + sipe_buddy_update_property(sipe_private, uri, SIPE_BUDDY_INFO_EMAIL, email); + sipe_buddy_update_property(sipe_private, uri, SIPE_BUDDY_INFO_WORK_PHONE, tel_uri); + sipe_buddy_update_property(sipe_private, uri, SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY, phone_number); + g_free(tel_uri); + } + + if (server_alias && strlen(server_alias) > 0) { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("Display name"), + server_alias); + } + if ((value = sipe_xml_attribute(mrow, "title")) && strlen(value) > 0) { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("Job title"), + value); + } + if ((value = sipe_xml_attribute(mrow, "office")) && strlen(value) > 0) { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("Office"), + value); + } + if (phone_number && strlen(phone_number) > 0) { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("Business phone"), + phone_number); + } + if ((value = sipe_xml_attribute(mrow, "company")) && strlen(value) > 0) { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("Company"), + value); + } + if ((value = sipe_xml_attribute(mrow, "city")) && strlen(value) > 0) { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("City"), + value); + } + if ((value = sipe_xml_attribute(mrow, "state")) && strlen(value) > 0) { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("State"), + value); + } + if ((value = sipe_xml_attribute(mrow, "country")) && strlen(value) > 0) { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("Country"), + value); + } + if (email && strlen(email) > 0) { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("Email address"), + email); + } + + } + sipe_xml_free(searchResults); + } + + sipe_backend_buddy_info_break(SIPE_CORE_PUBLIC, info); + + if (is_empty(server_alias)) { + g_free(server_alias); + server_alias = sipe_backend_buddy_get_server_alias(SIPE_CORE_PUBLIC, + bbuddy); + if (server_alias) { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("Display name"), + server_alias); + } + } + + /* present alias if it differs from server alias */ + if (alias && !sipe_strequal(alias, server_alias)) + { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("Alias"), + alias); + } + + if (is_empty(email)) { + g_free(email); + email = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC, + bbuddy, + SIPE_BUDDY_INFO_EMAIL); + if (email) { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("Email address"), + email); + } + } + + site = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC, + bbuddy, + SIPE_BUDDY_INFO_SITE); + if (site) { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("Site"), + site); + g_free(site); + } + + if (device_name) { + sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC, + info, + _("Device"), + device_name); + } + + sipe_backend_buddy_info_finalize(SIPE_CORE_PUBLIC, info, uri); + + g_free(phone_number); + g_free(server_alias); + g_free(email); + g_free(device_name); + g_free(alias); + + return TRUE; +} + +/** + * AD search first, LDAP based + */ +void sipe_core_buddy_get_info(struct sipe_core_public *sipe_public, + const gchar *who) +{ + char *row = g_markup_printf_escaped(SIPE_SOAP_SEARCH_ROW, + "msRTCSIP-PrimaryUserAddress", + who); + struct transaction_payload *payload = g_new0(struct transaction_payload, 1); + + SIPE_DEBUG_INFO("sipe_core_buddy_info: row: %s", row ? row : ""); + + payload->destroy = g_free; + payload->data = g_strdup(who); + + sip_soap_directory_search(SIPE_CORE_PRIVATE, + 1, + row, + process_get_info_response, + payload); + g_free(row); +} + /* Local Variables: mode: c diff --git a/src/core/sipe.c b/src/core/sipe.c index 82dec82a..282f35bc 100644 --- a/src/core/sipe.c +++ b/src/core/sipe.c @@ -69,7 +69,6 @@ #include "plugin.h" #include "privacy.h" #include "request.h" -#include "version.h" #include "core-depurple.h" /* Temporary for the core de-purple transition */ @@ -77,7 +76,6 @@ #include "sipmsg.h" #include "sip-csta.h" #include "sip-soap.h" -#include "sip-transport.h" #include "sipe-backend.h" #include "sipe-buddy.h" #include "sipe-cal.h" @@ -92,7 +90,6 @@ #include "sipe-session.h" #include "sipe-status.h" #include "sipe-utils.h" -#include "sipe-xml.h" #define _SIPE_NEED_ACTIVITIES /* ugly hack :-( */ #include "sipe.h" @@ -316,142 +313,8 @@ void sipe_buddy_status_from_activity(struct sipe_core_private *sipe_private, } } -/** - * Tries to figure out user first and last name - * based on Display Name and email properties. - * - * Allocates memory - must be g_free()'d - * - * Examples to parse: - * First Last - * First Last - Company Name - * Last, First - * Last, First M. - * Last, First (C)(STP) (Company) - * first.last@company.com (preprocessed as "first last") - * first.last.company.com@reuters.net (preprocessed as "first last company com") - * - * Unusable examples: - * user@company.com (preprocessed as "user") - * first.m.last@company.com (preprocessed as "first m last") - * user.company.com@reuters.net (preprocessed as "user company com") - */ -static void -sipe_get_first_last_names(struct sipe_core_private *sipe_private, - const char *uri, - char **first_name, - char **last_name) -{ - struct sipe_account_data *sip = SIPE_ACCOUNT_DATA_PRIVATE; - sipe_backend_buddy p_buddy; - char *display_name; - gchar *email; - const char *first, *last; - char *tmp; - char **parts; - gboolean has_comma = FALSE; - - if (!sip || !uri) return; - - p_buddy = sipe_backend_buddy_find(SIPE_CORE_PUBLIC, uri, NULL); - - if (!p_buddy) return; - - display_name = sipe_backend_buddy_get_alias(SIPE_CORE_PUBLIC, p_buddy); - email = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC, p_buddy, SIPE_BUDDY_INFO_EMAIL); - - if (!display_name && !email) return; - - /* if no display name, make "first last anything_else" out of email */ - if (email && !display_name) { - display_name = g_strndup(email, strstr(email, "@") - email); - display_name = sipe_utils_str_replace((tmp = display_name), ".", " "); - g_free(tmp); - } - - if (display_name) { - has_comma = (strstr(display_name, ",") != NULL); - display_name = sipe_utils_str_replace((tmp = display_name), ", ", " "); - g_free(tmp); - display_name = sipe_utils_str_replace((tmp = display_name), ",", " "); - g_free(tmp); - } - - parts = g_strsplit(display_name, " ", 0); - - if (!parts[0] || !parts[1]) { - g_free(email); - g_free(display_name); - g_strfreev(parts); - return; - } - - if (has_comma) { - last = parts[0]; - first = parts[1]; - } else { - first = parts[0]; - last = parts[1]; - } - - if (first_name) { - *first_name = g_strstrip(g_strdup(first)); - } - - if (last_name) { - *last_name = g_strstrip(g_strdup(last)); - } - - g_free(email); - g_free(display_name); - g_strfreev(parts); -} - /* IM Session (INVITE and MESSAGE methods) */ -static gboolean -process_options_response(SIPE_UNUSED_PARAMETER struct sipe_core_private *sipe_private, - struct sipmsg *msg, - SIPE_UNUSED_PARAMETER struct transaction *trans) -{ - gboolean ret = TRUE; - - if (msg->response != 200) { - SIPE_DEBUG_INFO("process_options_response: OPTIONS response is %d", msg->response); - return FALSE; - } - - SIPE_DEBUG_INFO("process_options_response: body:\n%s", msg->body ? msg->body : ""); - - return ret; -} - -/** - * Asks UA/proxy about its capabilities. - */ -static void sipe_options_request(struct sipe_core_private *sipe_private, - const char *who) -{ - gchar *to = sip_uri(who); - gchar *contact = get_contact(sipe_private); - gchar *request = g_strdup_printf( - "Accept: application/sdp\r\n" - "Contact: %s\r\n", contact); - g_free(contact); - - sip_transport_request(sipe_private, - "OPTIONS", - to, - to, - request, - NULL, - NULL, - process_options_response); - - g_free(to); - g_free(request); -} - /** * Returns 2005-style activity and Availability. * @@ -1364,196 +1227,6 @@ sipe_get_access_control_menu(struct sipe_core_private *sipe_private, return menu_access_levels; } -static gboolean -process_get_info_response(struct sipe_core_private *sipe_private, - struct sipmsg *msg, struct transaction *trans) -{ - struct sipe_account_data *sip = SIPE_ACCOUNT_DATA_PRIVATE; - char *uri = trans->payload->data; - - PurpleNotifyUserInfo *info; - PurpleBuddy *pbuddy = NULL; - struct sipe_buddy *sbuddy; - const char *alias = NULL; - char *device_name = NULL; - char *server_alias = NULL; - char *phone_number = NULL; - char *email = NULL; - char *site; - char *first_name = NULL; - char *last_name = NULL; - - if (!sip) return FALSE; - - SIPE_DEBUG_INFO("Fetching %s's user info for %s", uri, sipe_private->username); - - pbuddy = purple_find_buddy((PurpleAccount *)sip->account, uri); - alias = purple_buddy_get_local_alias(pbuddy); - - //will query buddy UA's capabilities and send answer to log - sipe_options_request(sipe_private, uri); - - sbuddy = g_hash_table_lookup(sipe_private->buddies, uri); - if (sbuddy) { - device_name = sbuddy->device_name ? g_strdup(sbuddy->device_name) : NULL; - } - - info = purple_notify_user_info_new(); - - if (msg->response != 200) { - SIPE_DEBUG_INFO("process_get_info_response: SERVICE response is %d", msg->response); - } else { - sipe_xml *searchResults; - const sipe_xml *mrow; - - SIPE_DEBUG_INFO("process_get_info_response: body:\n%s", msg->body ? msg->body : ""); - searchResults = sipe_xml_parse(msg->body, msg->bodylen); - if (!searchResults) { - SIPE_DEBUG_INFO_NOFORMAT("process_get_info_response: no parseable searchResults"); - } else if ((mrow = sipe_xml_child(searchResults, "Body/Array/row"))) { - const char *value; - server_alias = g_strdup(sipe_xml_attribute(mrow, "displayName")); - email = g_strdup(sipe_xml_attribute(mrow, "email")); - phone_number = g_strdup(sipe_xml_attribute(mrow, "phone")); - - /* For 2007 system we will take this from ContactCard - - * it has cleaner tel: URIs at least - */ - if (!SIPE_CORE_PRIVATE_FLAG_IS(OCS2007)) { - char *tel_uri = sip_to_tel_uri(phone_number); - /* trims its parameters, so call first */ - sipe_buddy_update_property(sipe_private, uri, SIPE_BUDDY_INFO_DISPLAY_NAME, server_alias); - sipe_buddy_update_property(sipe_private, uri, SIPE_BUDDY_INFO_EMAIL, email); - sipe_buddy_update_property(sipe_private, uri, SIPE_BUDDY_INFO_WORK_PHONE, tel_uri); - sipe_buddy_update_property(sipe_private, uri, SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY, phone_number); - g_free(tel_uri); - } - -#if PURPLE_VERSION_CHECK(3,0,0) -#define PURPLE_NOTIFY_USER_INFO_ADD_PAIR purple_notify_user_info_add_pair_html -#else -#define PURPLE_NOTIFY_USER_INFO_ADD_PAIR purple_notify_user_info_add_pair -#endif - - if (server_alias && strlen(server_alias) > 0) { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("Display name"), server_alias); - } - if ((value = sipe_xml_attribute(mrow, "title")) && strlen(value) > 0) { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("Job title"), value); - } - if ((value = sipe_xml_attribute(mrow, "office")) && strlen(value) > 0) { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("Office"), value); - } - if (phone_number && strlen(phone_number) > 0) { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("Business phone"), phone_number); - } - if ((value = sipe_xml_attribute(mrow, "company")) && strlen(value) > 0) { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("Company"), value); - } - if ((value = sipe_xml_attribute(mrow, "city")) && strlen(value) > 0) { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("City"), value); - } - if ((value = sipe_xml_attribute(mrow, "state")) && strlen(value) > 0) { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("State"), value); - } - if ((value = sipe_xml_attribute(mrow, "country")) && strlen(value) > 0) { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("Country"), value); - } - if (email && strlen(email) > 0) { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("Email address"), email); - } - - } - sipe_xml_free(searchResults); - } - - purple_notify_user_info_add_section_break(info); - - if (is_empty(server_alias)) { - g_free(server_alias); - server_alias = sipe_backend_buddy_get_server_alias(SIPE_CORE_PUBLIC, - pbuddy); - if (server_alias) { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("Display name"), server_alias); - } - } - - /* present alias if it differs from server alias */ - if (alias && !sipe_strequal(alias, server_alias)) - { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("Alias"), alias); - } - - if (is_empty(email)) { - g_free(email); - email = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC, - pbuddy, - SIPE_BUDDY_INFO_EMAIL); - if (email) { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("Email address"), email); - } - } - - site = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC, - pbuddy, - SIPE_BUDDY_INFO_SITE); - if (site) { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("Site"), site); - g_free(site); - } - - sipe_get_first_last_names(sipe_private, uri, &first_name, &last_name); - if (first_name && last_name) { - char *link = g_strconcat("http://www.linkedin.com/pub/dir/", first_name, "/", last_name, NULL); - - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("Find on LinkedIn"), link); - g_free(link); - } - g_free(first_name); - g_free(last_name); - - if (device_name) { - PURPLE_NOTIFY_USER_INFO_ADD_PAIR(info, _("Device"), device_name); - } - - /* show a buddy's user info in a nice dialog box */ - purple_notify_userinfo(sip->gc, /* connection the buddy info came through */ - uri, /* buddy's URI */ - info, /* body */ - NULL, /* callback called when dialog closed */ - NULL); /* userdata for callback */ - - g_free(phone_number); - g_free(server_alias); - g_free(email); - g_free(device_name); - - return TRUE; -} - -#define SIPE_SOAP_SEARCH_ROW "" - -/** - * AD search first, LDAP based - */ -void sipe_get_info(PurpleConnection *gc, const char *username) -{ - struct sipe_core_private *sipe_private = PURPLE_GC_TO_SIPE_CORE_PRIVATE; - char *row = g_markup_printf_escaped(SIPE_SOAP_SEARCH_ROW, "msRTCSIP-PrimaryUserAddress", username); - struct transaction_payload *payload = g_new0(struct transaction_payload, 1); - - payload->destroy = g_free; - payload->data = g_strdup(username); - - SIPE_DEBUG_INFO("sipe_get_info: row: %s", row ? row : ""); - sip_soap_directory_search(sipe_private, - 1, - row, - process_get_info_response, - payload); - g_free(row); -} - /* Local Variables: mode: c diff --git a/src/purple/purple-buddy.c b/src/purple/purple-buddy.c index 879a6c67..c03b55a8 100644 --- a/src/purple/purple-buddy.c +++ b/src/purple/purple-buddy.c @@ -29,7 +29,9 @@ #include "purple-private.h" #include "blist.h" +#include "notify.h" #include "privacy.h" +#include "version.h" #include "sipe-common.h" #include "sipe-backend.h" @@ -157,6 +159,12 @@ gchar* sipe_backend_buddy_get_server_alias(SIPE_UNUSED_PARAMETER struct sipe_cor return g_strdup(purple_buddy_get_server_alias(who)); } +gchar *sipe_backend_buddy_get_local_alias(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public, + const sipe_backend_buddy who) +{ + return g_strdup(purple_buddy_get_local_alias(who)); +} + gchar* sipe_backend_buddy_get_group_name(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public, const sipe_backend_buddy who) { @@ -307,6 +315,44 @@ gboolean sipe_backend_buddy_group_add(SIPE_UNUSED_PARAMETER struct sipe_core_pub return (purple_group != NULL); } +struct sipe_backend_buddy_info *sipe_backend_buddy_info_start(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public) +{ + return((struct sipe_backend_buddy_info *)purple_notify_user_info_new()); +} + +void sipe_backend_buddy_info_add(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public, + struct sipe_backend_buddy_info *info, + const gchar *description, + const gchar *value) +{ +#if PURPLE_VERSION_CHECK(3,0,0) + purple_notify_user_info_add_pair_html +#else + purple_notify_user_info_add_pair +#endif + ((PurpleNotifyUserInfo *) info, description, value); +} + +void sipe_backend_buddy_info_break(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public, + struct sipe_backend_buddy_info *info) +{ + purple_notify_user_info_add_section_break((PurpleNotifyUserInfo *) info); +} + +void sipe_backend_buddy_info_finalize(struct sipe_core_public *sipe_public, + struct sipe_backend_buddy_info *info, + const gchar *uri) +{ + struct sipe_backend_private *purple_private = sipe_public->backend_private; + + /* show a buddy's user info in a nice dialog box */ + purple_notify_userinfo(purple_private->gc, + uri, /* buddy's URI */ + (PurpleNotifyUserInfo *) info, + NULL, /* callback called when dialog closed */ + NULL); /* userdata for callback */ +} + void sipe_purple_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) diff --git a/src/purple/purple-plugin.c b/src/purple/purple-plugin.c index 1fd52558..8336dd96 100644 --- a/src/purple/purple-plugin.c +++ b/src/purple/purple-plugin.c @@ -385,6 +385,12 @@ static unsigned int sipe_purple_send_typing(PurpleConnection *gc, return SIPE_TYPING_SEND_TIMEOUT; } +static void sipe_purple_get_info(PurpleConnection *gc, const char *who) +{ + sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC, + who); +} + static void sipe_purple_add_permit(PurpleConnection *gc, const char *name) { sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE); @@ -514,7 +520,7 @@ static PurplePluginProtocolInfo sipe_prpl_info = sipe_purple_send_im, /* send_im */ NULL, /* set_info */ // TODO maybe sipe_purple_send_typing, /* send_typing */ - sipe_get_info, /* get_info */ + sipe_purple_get_info, /* get_info */ sipe_purple_set_status, /* set_status */ sipe_purple_set_idle, /* set_idle */ NULL, /* change_passwd */ -- 2.11.4.GIT