6 * Copyright (C) 2010-2013 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include "sipe-common.h"
37 #include "sip-transport.h"
38 #include "sipe-backend.h"
39 #include "sipe-buddy.h"
41 #include "sipe-chat.h"
42 #include "sipe-conf.h"
43 #include "sipe-core.h"
44 #include "sipe-core-private.h"
45 #include "sipe-group.h"
46 #include "sipe-http.h"
49 #include "sipe-ocs2005.h"
50 #include "sipe-ocs2007.h"
51 #include "sipe-schedule.h"
52 #include "sipe-session.h"
53 #include "sipe-status.h"
54 #include "sipe-subscriptions.h"
57 #include "sipe-utils.h"
58 #include "sipe-webticket.h"
63 GHashTable
*exchange_key
;
65 /* Pending photo download HTTP requests */
66 GSList
*pending_photo_requests
;
69 struct photo_response_data
{
72 struct sipe_http_request
*request
;
75 static void buddy_fetch_photo(struct sipe_core_private
*sipe_private
,
77 static void photo_response_data_free(struct photo_response_data
*data
);
79 struct sipe_buddy
*sipe_buddy_add(struct sipe_core_private
*sipe_private
,
81 const gchar
*exchange_key
)
83 struct sipe_buddy
*buddy
= sipe_buddy_find_by_uri(sipe_private
, uri
);
85 struct sipe_buddies
*buddies
= sipe_private
->buddies
;
87 buddy
= g_new0(struct sipe_buddy
, 1);
88 buddy
->name
= g_strdup(uri
);
89 g_hash_table_insert(buddies
->uri
,
94 buddy
->exchange_key
= g_strdup(exchange_key
);
95 g_hash_table_insert(buddies
->exchange_key
,
101 SIPE_DEBUG_INFO("sipe_buddy_add: Added buddy %s", uri
);
103 buddy_fetch_photo(sipe_private
, uri
);
105 SIPE_DEBUG_INFO("sipe_buddy_add: Buddy %s already exists", uri
);
111 void sipe_buddy_cleanup_local_list(struct sipe_core_private
*sipe_private
)
113 GSList
*buddies
= sipe_backend_buddy_find_all(SIPE_CORE_PUBLIC
,
116 GSList
*entry
= buddies
;
118 SIPE_DEBUG_INFO("sipe_buddy_cleanup_local_list: overall %d backend buddies (including clones)",
119 g_slist_length(buddies
));
120 SIPE_DEBUG_INFO("sipe_buddy_cleanup_local_list: %d sipe buddies (unique)",
121 sipe_buddy_count(sipe_private
));
123 sipe_backend_buddy bb
= entry
->data
;
124 gchar
*bname
= sipe_backend_buddy_get_name(SIPE_CORE_PUBLIC
,
126 gchar
*gname
= sipe_backend_buddy_get_group_name(SIPE_CORE_PUBLIC
,
128 struct sipe_buddy
*buddy
= sipe_buddy_find_by_uri(sipe_private
,
130 gboolean in_sipe_groups
= FALSE
;
133 GSList
*entry2
= buddy
->groups
;
136 struct sipe_group
*group
= entry2
->data
;
137 if (sipe_strequal(group
->name
, gname
)) {
138 in_sipe_groups
= TRUE
;
141 entry2
= entry2
->next
;
145 if (!in_sipe_groups
) {
146 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",
148 sipe_backend_buddy_remove(SIPE_CORE_PUBLIC
, bb
);
157 g_slist_free(buddies
);
160 struct sipe_buddy
*sipe_buddy_find_by_uri(struct sipe_core_private
*sipe_private
,
163 return(g_hash_table_lookup(sipe_private
->buddies
->uri
, uri
));
166 struct sipe_buddy
*sipe_buddy_find_by_exchange_key(struct sipe_core_private
*sipe_private
,
167 const gchar
*exchange_key
)
169 return(g_hash_table_lookup(sipe_private
->buddies
->exchange_key
,
173 void sipe_buddy_foreach(struct sipe_core_private
*sipe_private
,
175 gpointer callback_data
)
177 g_hash_table_foreach(sipe_private
->buddies
->uri
,
182 static void buddy_free(struct sipe_buddy
*buddy
)
186 * We are calling g_hash_table_foreach_steal(). That means that no
187 * key/value deallocation functions are called. Therefore the glib
188 * hash code does not touch the key (buddy->name) or value (buddy)
189 * of the to-be-deleted hash node at all. It follows that we
191 * - MUST free the memory for the key ourselves and
192 * - ARE allowed to do it in this function
194 * Conclusion: glib must be broken on the Windows platform if sipe
195 * crashes with SIGTRAP when closing. You'll have to live
196 * with the memory leak until this is fixed.
200 g_free(buddy
->exchange_key
);
201 g_free(buddy
->activity
);
202 g_free(buddy
->meeting_subject
);
203 g_free(buddy
->meeting_location
);
206 g_free(buddy
->cal_start_time
);
207 g_free(buddy
->cal_free_busy_base64
);
208 g_free(buddy
->cal_free_busy
);
209 g_free(buddy
->last_non_cal_activity
);
211 sipe_cal_free_working_hours(buddy
->cal_working_hours
);
213 g_free(buddy
->device_name
);
214 g_slist_free(buddy
->groups
);
218 static gboolean
buddy_free_cb(SIPE_UNUSED_PARAMETER gpointer key
,
220 SIPE_UNUSED_PARAMETER gpointer user_data
)
223 /* We must return TRUE as the key/value have already been deleted */
227 void sipe_buddy_free(struct sipe_core_private
*sipe_private
)
229 struct sipe_buddies
*buddies
= sipe_private
->buddies
;
231 g_hash_table_foreach_steal(buddies
->uri
,
235 /* core is being deallocated, remove all its pending photo requests */
236 while (buddies
->pending_photo_requests
) {
237 struct photo_response_data
*data
=
238 buddies
->pending_photo_requests
->data
;
239 buddies
->pending_photo_requests
=
240 g_slist_remove(buddies
->pending_photo_requests
, data
);
241 photo_response_data_free(data
);
244 g_hash_table_destroy(buddies
->uri
);
245 g_hash_table_destroy(buddies
->exchange_key
);
247 sipe_private
->buddies
= NULL
;
250 gchar
*sipe_core_buddy_status(struct sipe_core_public
*sipe_public
,
253 const gchar
*status_text
)
255 struct sipe_buddy
*sbuddy
;
256 const char *activity_str
;
258 if (!sipe_public
) return NULL
; /* happens on pidgin exit */
260 sbuddy
= sipe_buddy_find_by_uri(SIPE_CORE_PRIVATE
, uri
);
261 if (!sbuddy
) return NULL
;
263 activity_str
= sbuddy
->activity
? sbuddy
->activity
:
264 (activity
== SIPE_ACTIVITY_BUSY
) || (activity
== SIPE_ACTIVITY_BRB
) ?
267 if (activity_str
&& sbuddy
->note
) {
268 return g_strdup_printf("%s - <i>%s</i>", activity_str
, sbuddy
->note
);
269 } else if (activity_str
) {
270 return g_strdup(activity_str
);
271 } else if (sbuddy
->note
) {
272 return g_strdup_printf("<i>%s</i>", sbuddy
->note
);
278 gchar
*sipe_buddy_get_alias(struct sipe_core_private
*sipe_private
,
281 sipe_backend_buddy pbuddy
;
283 if ((pbuddy
= sipe_backend_buddy_find(SIPE_CORE_PUBLIC
, with
, NULL
))) {
284 alias
= sipe_backend_buddy_get_alias(SIPE_CORE_PUBLIC
, pbuddy
);
289 void sipe_core_buddy_group(struct sipe_core_public
*sipe_public
,
291 const gchar
*old_group_name
,
292 const gchar
*new_group_name
)
294 struct sipe_buddy
* buddy
= sipe_buddy_find_by_uri(SIPE_CORE_PRIVATE
,
296 struct sipe_group
* old_group
= NULL
;
297 struct sipe_group
* new_group
;
299 SIPE_DEBUG_INFO("sipe_core_buddy_group: who:%s old_group_name:%s new_group_name:%s",
300 who
? who
: "", old_group_name
? old_group_name
: "", new_group_name
? new_group_name
: "");
302 if(!buddy
) { // buddy not in roaming list
306 if (old_group_name
) {
307 old_group
= sipe_group_find_by_name(SIPE_CORE_PRIVATE
, old_group_name
);
309 new_group
= sipe_group_find_by_name(SIPE_CORE_PRIVATE
, new_group_name
);
312 buddy
->groups
= g_slist_remove(buddy
->groups
, old_group
);
313 SIPE_DEBUG_INFO("sipe_core_buddy_group: buddy %s removed from old group %s", who
, old_group_name
);
317 sipe_group_create(SIPE_CORE_PRIVATE
, new_group_name
, who
);
319 buddy
->groups
= sipe_utils_slist_insert_unique_sorted(buddy
->groups
,
321 (GCompareFunc
)sipe_group_compare
,
323 sipe_group_update_buddy(SIPE_CORE_PRIVATE
, buddy
);
327 void sipe_core_buddy_add(struct sipe_core_public
*sipe_public
,
329 const gchar
*group_name
)
331 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
333 if (!sipe_buddy_find_by_uri(sipe_private
, uri
)) {
334 struct sipe_buddy
*b
= sipe_buddy_add(sipe_private
, uri
, NULL
);
335 b
->just_added
= TRUE
;
337 sipe_subscribe_presence_single_cb(sipe_private
, b
->name
);
340 SIPE_DEBUG_INFO("sipe_core_buddy_add: buddy %s already in internal list",
344 sipe_core_buddy_group(sipe_public
,
350 void sipe_buddy_remove(struct sipe_core_private
*sipe_private
,
351 struct sipe_buddy
*buddy
)
353 struct sipe_buddies
*buddies
= sipe_private
->buddies
;
354 gchar
*action_name
= sipe_utils_presence_key(buddy
->name
);
355 sipe_schedule_cancel(sipe_private
, action_name
);
358 g_hash_table_remove(buddies
->uri
, buddy
->name
);
359 if (buddy
->exchange_key
)
360 g_hash_table_remove(buddies
->exchange_key
,
361 buddy
->exchange_key
);
367 * Unassociates buddy from group first.
368 * Then see if no groups left, removes buddy completely.
369 * Otherwise updates buddy groups on server.
371 void sipe_core_buddy_remove(struct sipe_core_public
*sipe_public
,
373 const gchar
*group_name
)
375 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
376 struct sipe_buddy
*b
= sipe_buddy_find_by_uri(sipe_private
,
382 struct sipe_group
*g
= sipe_group_find_by_name(sipe_private
,
385 b
->groups
= g_slist_remove(b
->groups
, g
);
386 SIPE_DEBUG_INFO("sipe_core_buddy_remove: buddy %s removed from group %s",
391 if (g_slist_length(b
->groups
) < 1) {
392 gchar
*request
= g_strdup_printf("<m:URI>%s</m:URI>",
394 sip_soap_request(sipe_private
,
398 sipe_buddy_remove(sipe_private
, b
);
400 /* updates groups on server */
401 sipe_group_update_buddy(sipe_private
, b
);
406 void sipe_core_buddy_got_status(struct sipe_core_public
*sipe_public
,
410 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
411 struct sipe_buddy
*sbuddy
= sipe_buddy_find_by_uri(sipe_private
,
416 /* Check if on 2005 system contact's calendar,
417 * then set/preserve it.
419 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
420 sipe_backend_buddy_set_status(sipe_public
, uri
, activity
);
422 sipe_ocs2005_apply_calendar_status(sipe_private
,
424 sipe_status_activity_to_token(activity
));
428 void sipe_core_buddy_tooltip_info(struct sipe_core_public
*sipe_public
,
430 const gchar
*status_name
,
432 struct sipe_backend_buddy_tooltip
*tooltip
)
434 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
436 gboolean is_oof_note
= FALSE
;
437 const gchar
*activity
= NULL
;
438 gchar
*calendar
= NULL
;
439 const gchar
*meeting_subject
= NULL
;
440 const gchar
*meeting_location
= NULL
;
441 gchar
*access_text
= NULL
;
443 #define SIPE_ADD_BUDDY_INFO(l, t) \
445 gchar *tmp = g_markup_escape_text((t), -1); \
446 sipe_backend_buddy_tooltip_add(sipe_public, tooltip, (l), tmp); \
449 #define SIPE_ADD_BUDDY_INFO_NOESCAPE(l, t) \
450 sipe_backend_buddy_tooltip_add(sipe_public, tooltip, (l), (t))
452 if (sipe_public
) { /* happens on pidgin exit */
453 struct sipe_buddy
*sbuddy
= sipe_buddy_find_by_uri(sipe_private
,
457 is_oof_note
= sbuddy
->is_oof_note
;
458 activity
= sbuddy
->activity
;
459 calendar
= sipe_cal_get_description(sbuddy
);
460 meeting_subject
= sbuddy
->meeting_subject
;
461 meeting_location
= sbuddy
->meeting_location
;
463 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
464 gboolean is_group_access
= FALSE
;
465 const int container_id
= sipe_ocs2007_find_access_level(sipe_private
,
467 sipe_get_no_sip_uri(uri
),
469 const char *access_level
= sipe_ocs2007_access_level_name(container_id
);
470 access_text
= is_group_access
?
471 g_strdup(access_level
) :
472 g_strdup_printf(SIPE_OCS2007_INDENT_MARKED_FMT
,
478 const gchar
*status_str
= activity
? activity
: status_name
;
480 SIPE_ADD_BUDDY_INFO(_("Status"), status_str
);
482 if (is_online
&& !is_empty(calendar
)) {
483 SIPE_ADD_BUDDY_INFO(_("Calendar"), calendar
);
486 if (!is_empty(meeting_location
)) {
487 SIPE_DEBUG_INFO("sipe_tooltip_text: %s meeting location: '%s'", uri
, meeting_location
);
488 SIPE_ADD_BUDDY_INFO(_("Meeting in"), meeting_location
);
490 if (!is_empty(meeting_subject
)) {
491 SIPE_DEBUG_INFO("sipe_tooltip_text: %s meeting subject: '%s'", uri
, meeting_subject
);
492 SIPE_ADD_BUDDY_INFO(_("Meeting about"), meeting_subject
);
495 gchar
*note_italics
= g_strdup_printf("<i>%s</i>", note
);
496 SIPE_DEBUG_INFO("sipe_tooltip_text: %s note: '%s'", uri
, note
);
497 SIPE_ADD_BUDDY_INFO_NOESCAPE(is_oof_note
? _("Out of office note") : _("Note"),
499 g_free(note_italics
);
502 SIPE_ADD_BUDDY_INFO(_("Access level"), access_text
);
507 void sipe_buddy_update_property(struct sipe_core_private
*sipe_private
,
509 sipe_buddy_info_fields propkey
,
510 char *property_value
)
512 GSList
*buddies
, *entry
;
515 property_value
= g_strstrip(property_value
);
517 entry
= buddies
= sipe_backend_buddy_find_all(SIPE_CORE_PUBLIC
, uri
, NULL
); /* all buddies in different groups */
520 sipe_backend_buddy p_buddy
= entry
->data
;
522 /* for Display Name */
523 if (propkey
== SIPE_BUDDY_INFO_DISPLAY_NAME
) {
525 alias
= sipe_backend_buddy_get_alias(SIPE_CORE_PUBLIC
, p_buddy
);
526 if (property_value
&& sipe_is_bad_alias(uri
, alias
)) {
527 SIPE_DEBUG_INFO("Replacing alias for %s with %s", uri
, property_value
);
528 sipe_backend_buddy_set_alias(SIPE_CORE_PUBLIC
, p_buddy
, property_value
);
532 alias
= sipe_backend_buddy_get_server_alias(SIPE_CORE_PUBLIC
, p_buddy
);
533 if (!is_empty(property_value
) &&
534 (!sipe_strequal(property_value
, alias
) || is_empty(alias
)) )
536 SIPE_DEBUG_INFO("Replacing service alias for %s with %s", uri
, property_value
);
537 sipe_backend_buddy_set_server_alias(SIPE_CORE_PUBLIC
, p_buddy
, property_value
);
541 /* for other properties */
543 if (!is_empty(property_value
)) {
544 prop_str
= sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC
, p_buddy
, propkey
);
545 if (!prop_str
|| !sipe_strcase_equal(prop_str
, property_value
)) {
546 sipe_backend_buddy_set_string(SIPE_CORE_PUBLIC
, p_buddy
, propkey
, property_value
);
554 g_slist_free(buddies
);
563 sipe_svc_callback
*callback
;
564 struct sipe_svc_session
*session
;
565 gchar
*wsse_security
;
566 struct sipe_backend_search_token
*token
;
567 /* must call ms_dlx_free() */
568 void (*failed_callback
)(struct sipe_core_private
*sipe_private
,
569 struct ms_dlx_data
*mdd
);
572 static void ms_dlx_free(struct ms_dlx_data
*mdd
)
574 sipe_utils_slist_free_full(mdd
->search_rows
, g_free
);
575 sipe_svc_session_close(mdd
->session
);
577 g_free(mdd
->wsse_security
);
581 #define SIPE_SOAP_SEARCH_ROW "<m:row m:attrib=\"%s\" m:value=\"%s\"/>"
582 #define DLX_SEARCH_ITEM \
583 "<AbEntryRequest.ChangeSearchQuery>" \
584 " <SearchOn>%s</SearchOn>" \
585 " <Value>%s</Value>" \
586 "</AbEntryRequest.ChangeSearchQuery>"
588 static gchar
* prepare_buddy_search_query(GSList
*query_rows
, gboolean use_dlx
) {
589 gchar
**attrs
= g_new(gchar
*, (g_slist_length(query_rows
) / 2) + 1);
597 attr
= query_rows
->data
;
598 query_rows
= g_slist_next(query_rows
);
599 value
= query_rows
->data
;
600 query_rows
= g_slist_next(query_rows
);
605 attrs
[i
++] = g_markup_printf_escaped(use_dlx
? DLX_SEARCH_ITEM
: SIPE_SOAP_SEARCH_ROW
,
611 query
= g_strjoinv(NULL
, attrs
);
612 SIPE_DEBUG_INFO("prepare_buddy_search_query: rows:\n%s",
621 static void ms_dlx_webticket(struct sipe_core_private
*sipe_private
,
622 const gchar
*base_uri
,
623 const gchar
*auth_uri
,
624 const gchar
*wsse_security
,
625 SIPE_UNUSED_PARAMETER
const gchar
*failure_msg
,
626 gpointer callback_data
)
628 struct ms_dlx_data
*mdd
= callback_data
;
631 gchar
*query
= prepare_buddy_search_query(mdd
->search_rows
, TRUE
);
633 SIPE_DEBUG_INFO("ms_dlx_webticket: got ticket for %s",
636 if (sipe_svc_ab_entry_request(sipe_private
,
641 g_slist_length(mdd
->search_rows
) / 2,
646 /* keep webticket security token for potential further use */
647 mdd
->wsse_security
= g_strdup(wsse_security
);
649 /* callback data passed down the line */
655 /* no ticket: this will show the minmum information */
656 SIPE_DEBUG_ERROR("ms_dlx_webticket: no web ticket for %s",
661 mdd
->failed_callback(sipe_private
, mdd
);
664 static void ms_dlx_webticket_request(struct sipe_core_private
*sipe_private
,
665 struct ms_dlx_data
*mdd
)
667 if (!sipe_webticket_request(sipe_private
,
669 sipe_private
->dlx_uri
,
670 "AddressBookWebTicketBearer",
673 SIPE_DEBUG_ERROR("ms_dlx_webticket_request: couldn't request webticket for %s",
674 sipe_private
->dlx_uri
);
675 mdd
->failed_callback(sipe_private
, mdd
);
679 static void search_contacts_finalize(struct sipe_core_private
*sipe_private
,
680 struct sipe_backend_search_results
*results
,
684 gchar
*secondary
= g_strdup_printf(
685 dngettext(PACKAGE_NAME
,
686 "Found %d contact%s:",
687 "Found %d contacts%s:", match_count
),
688 match_count
, more
? _(" (more matched your query)") : "");
690 sipe_backend_search_results_finalize(SIPE_CORE_PUBLIC
,
697 static void search_ab_entry_response(struct sipe_core_private
*sipe_private
,
699 SIPE_UNUSED_PARAMETER
const gchar
*raw
,
701 gpointer callback_data
)
703 struct ms_dlx_data
*mdd
= callback_data
;
706 const sipe_xml
*node
;
707 struct sipe_backend_search_results
*results
;
710 SIPE_DEBUG_INFO("search_ab_entry_response: received valid SOAP message from service %s",
714 node
= sipe_xml_child(soap_body
, "Body/SearchAbEntryResponse/SearchAbEntryResult/Items/AbEntry");
716 SIPE_DEBUG_ERROR_NOFORMAT("search_ab_entry_response: no matches");
717 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
719 _("No contacts found"));
724 /* OK, we found something - show the results to the user */
725 results
= sipe_backend_search_results_start(SIPE_CORE_PUBLIC
,
728 SIPE_DEBUG_ERROR_NOFORMAT("search_ab_entry_response: Unable to display the search results.");
729 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
731 _("Unable to display the search results"));
736 /* SearchAbEntryResult can contain duplicates */
737 found
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
740 for (/* initialized above */ ; node
; node
= sipe_xml_twin(node
)) {
741 const sipe_xml
*attrs
;
742 gchar
*sip_uri
= NULL
;
743 gchar
*displayname
= NULL
;
744 gchar
*company
= NULL
;
745 gchar
*country
= NULL
;
748 for (attrs
= sipe_xml_child(node
, "Attributes/Attribute");
750 attrs
= sipe_xml_twin(attrs
)) {
751 gchar
*name
= sipe_xml_data(sipe_xml_child(attrs
,
753 gchar
*value
= sipe_xml_data(sipe_xml_child(attrs
,
756 if (!is_empty(value
)) {
757 if (sipe_strcase_equal(name
, "msrtcsip-primaryuseraddress")) {
761 } else if (sipe_strcase_equal(name
, "displayname")) {
765 } else if (sipe_strcase_equal(name
, "mail")) {
769 } else if (sipe_strcase_equal(name
, "company")) {
773 } else if (sipe_strcase_equal(name
, "country")) {
784 if (sip_uri
&& !g_hash_table_lookup(found
, sip_uri
)) {
785 gchar
**uri_parts
= g_strsplit(sip_uri
, ":", 2);
786 sipe_backend_search_results_add(SIPE_CORE_PUBLIC
,
793 g_strfreev(uri_parts
);
795 g_hash_table_insert(found
, sip_uri
, (gpointer
) TRUE
);
806 search_contacts_finalize(sipe_private
, results
,
807 g_hash_table_size(found
),
809 g_hash_table_destroy(found
);
813 mdd
->failed_callback(sipe_private
, mdd
);
817 static gboolean
process_search_contact_response(struct sipe_core_private
*sipe_private
,
819 struct transaction
*trans
)
821 struct sipe_backend_search_token
*token
= trans
->payload
->data
;
822 struct sipe_backend_search_results
*results
;
823 sipe_xml
*searchResults
;
824 const sipe_xml
*mrow
;
825 guint match_count
= 0;
826 gboolean more
= FALSE
;
828 /* valid response? */
829 if (msg
->response
!= 200) {
830 SIPE_DEBUG_ERROR("process_search_contact_response: request failed (%d)",
832 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
834 _("Contact search failed"));
838 SIPE_DEBUG_INFO("process_search_contact_response: body:\n%s", msg
->body
? msg
->body
: "");
841 searchResults
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
842 if (!searchResults
) {
843 SIPE_DEBUG_INFO_NOFORMAT("process_search_contact_response: no parseable searchResults");
844 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
846 _("Contact search failed"));
851 mrow
= sipe_xml_child(searchResults
, "Body/Array/row");
853 SIPE_DEBUG_ERROR_NOFORMAT("process_search_contact_response: no matches");
854 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
856 _("No contacts found"));
858 sipe_xml_free(searchResults
);
862 /* OK, we found something - show the results to the user */
863 results
= sipe_backend_search_results_start(SIPE_CORE_PUBLIC
,
864 trans
->payload
->data
);
866 SIPE_DEBUG_ERROR_NOFORMAT("process_search_contact_response: Unable to display the search results.");
867 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
869 _("Unable to display the search results"));
871 sipe_xml_free(searchResults
);
875 for (/* initialized above */ ; mrow
; mrow
= sipe_xml_twin(mrow
)) {
876 gchar
**uri_parts
= g_strsplit(sipe_xml_attribute(mrow
, "uri"), ":", 2);
877 sipe_backend_search_results_add(SIPE_CORE_PUBLIC
,
880 sipe_xml_attribute(mrow
, "displayName"),
881 sipe_xml_attribute(mrow
, "company"),
882 sipe_xml_attribute(mrow
, "country"),
883 sipe_xml_attribute(mrow
, "email"));
884 g_strfreev(uri_parts
);
888 if ((mrow
= sipe_xml_child(searchResults
, "Body/directorySearch/moreAvailable")) != NULL
) {
889 char *data
= sipe_xml_data(mrow
);
890 more
= (g_ascii_strcasecmp(data
, "true") == 0);
894 search_contacts_finalize(sipe_private
, results
, match_count
, more
);
895 sipe_xml_free(searchResults
);
900 static void search_soap_request(struct sipe_core_private
*sipe_private
,
901 struct sipe_backend_search_token
*token
,
904 gchar
*query
= prepare_buddy_search_query(search_rows
, FALSE
);
905 struct transaction_payload
*payload
= g_new0(struct transaction_payload
, 1);
907 payload
->data
= token
;
909 sip_soap_directory_search(sipe_private
,
912 process_search_contact_response
,
917 static void search_ab_entry_failed(struct sipe_core_private
*sipe_private
,
918 struct ms_dlx_data
*mdd
)
920 /* error using [MS-DLX] server, retry using Active Directory */
921 search_soap_request(sipe_private
, mdd
->token
, mdd
->search_rows
);
925 void sipe_core_buddy_search(struct sipe_core_public
*sipe_public
,
926 struct sipe_backend_search_token
*token
,
927 const gchar
*given_name
,
928 const gchar
*surname
,
930 const gchar
*company
,
931 const gchar
*country
)
933 GSList
*query_rows
= NULL
;
935 #define ADD_QUERY_ROW(attr, val) \
937 query_rows = g_slist_append(query_rows, g_strdup(attr)); \
938 query_rows = g_slist_append(query_rows, g_strdup(val)); \
941 ADD_QUERY_ROW("givenName", given_name
);
942 ADD_QUERY_ROW("sn", surname
);
943 ADD_QUERY_ROW("mail", email
);
944 ADD_QUERY_ROW("company", company
);
945 ADD_QUERY_ROW("c", country
);
948 if (SIPE_CORE_PRIVATE
->dlx_uri
!= NULL
) {
949 struct ms_dlx_data
*mdd
= g_new0(struct ms_dlx_data
, 1);
951 mdd
->search_rows
= query_rows
;
952 mdd
->max_returns
= 100;
953 mdd
->callback
= search_ab_entry_response
;
954 mdd
->failed_callback
= search_ab_entry_failed
;
955 mdd
->session
= sipe_svc_session_start();
958 ms_dlx_webticket_request(SIPE_CORE_PRIVATE
, mdd
);
961 /* no [MS-DLX] server, use Active Directory search instead */
962 search_soap_request(SIPE_CORE_PRIVATE
, token
, query_rows
);
963 sipe_utils_slist_free_full(query_rows
, g_free
);
966 sipe_backend_search_failed(sipe_public
,
968 _("Invalid contact search query"));
971 static void get_info_finalize(struct sipe_core_private
*sipe_private
,
972 struct sipe_backend_buddy_info
*info
,
974 const gchar
*server_alias
,
977 sipe_backend_buddy bbuddy
;
978 struct sipe_buddy
*sbuddy
;
983 info
= sipe_backend_buddy_info_start(SIPE_CORE_PUBLIC
);
985 sipe_backend_buddy_info_break(SIPE_CORE_PUBLIC
, info
);
990 bbuddy
= sipe_backend_buddy_find(SIPE_CORE_PUBLIC
, uri
, NULL
);
992 if (is_empty(server_alias
)) {
993 value
= sipe_backend_buddy_get_server_alias(SIPE_CORE_PUBLIC
,
996 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
998 SIPE_BUDDY_INFO_DISPLAY_NAME
,
1002 value
= g_strdup(server_alias
);
1005 /* present alias if it differs from server alias */
1006 alias
= sipe_backend_buddy_get_local_alias(SIPE_CORE_PUBLIC
, bbuddy
);
1007 if (alias
&& !sipe_strequal(alias
, value
))
1009 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1011 SIPE_BUDDY_INFO_ALIAS
,
1017 if (is_empty(email
)) {
1018 value
= sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC
,
1020 SIPE_BUDDY_INFO_EMAIL
);
1022 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1024 SIPE_BUDDY_INFO_EMAIL
,
1030 value
= sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC
,
1032 SIPE_BUDDY_INFO_SITE
);
1034 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1036 SIPE_BUDDY_INFO_SITE
,
1041 sbuddy
= sipe_buddy_find_by_uri(sipe_private
, uri
);
1042 if (sbuddy
&& sbuddy
->device_name
) {
1043 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1045 SIPE_BUDDY_INFO_DEVICE
,
1046 sbuddy
->device_name
);
1049 sipe_backend_buddy_info_finalize(SIPE_CORE_PUBLIC
, info
, uri
);
1053 static void get_info_ab_entry_response(struct sipe_core_private
*sipe_private
,
1055 SIPE_UNUSED_PARAMETER
const gchar
*raw
,
1056 sipe_xml
*soap_body
,
1057 gpointer callback_data
)
1059 struct ms_dlx_data
*mdd
= callback_data
;
1060 struct sipe_backend_buddy_info
*info
= NULL
;
1061 gchar
*server_alias
= NULL
;
1062 gchar
*email
= NULL
;
1065 const sipe_xml
*node
;
1067 SIPE_DEBUG_INFO("get_info_ab_entry_response: received valid SOAP message from service %s",
1070 info
= sipe_backend_buddy_info_start(SIPE_CORE_PUBLIC
);
1072 for (node
= sipe_xml_child(soap_body
, "Body/SearchAbEntryResponse/SearchAbEntryResult/Items/AbEntry/Attributes/Attribute");
1074 node
= sipe_xml_twin(node
)) {
1075 gchar
*name
= sipe_xml_data(sipe_xml_child(node
,
1077 gchar
*value
= sipe_xml_data(sipe_xml_child(node
,
1079 const sipe_xml
*values
= sipe_xml_child(node
,
1082 /* Single value entries */
1083 if (!is_empty(value
)) {
1085 if (sipe_strcase_equal(name
, "displayname")) {
1086 g_free(server_alias
);
1087 server_alias
= value
;
1089 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1091 SIPE_BUDDY_INFO_DISPLAY_NAME
,
1093 } else if (sipe_strcase_equal(name
, "mail")) {
1097 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1099 SIPE_BUDDY_INFO_EMAIL
,
1101 } else if (sipe_strcase_equal(name
, "title")) {
1102 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1104 SIPE_BUDDY_INFO_JOB_TITLE
,
1106 } else if (sipe_strcase_equal(name
, "company")) {
1107 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1109 SIPE_BUDDY_INFO_COMPANY
,
1111 } else if (sipe_strcase_equal(name
, "country")) {
1112 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1114 SIPE_BUDDY_INFO_COUNTRY
,
1118 } else if (values
) {
1119 gchar
*first
= sipe_xml_data(sipe_xml_child(values
,
1122 if (sipe_strcase_equal(name
, "telephonenumber")) {
1123 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1125 SIPE_BUDDY_INFO_WORK_PHONE
,
1137 /* this will show the minmum information */
1138 get_info_finalize(sipe_private
,
1145 g_free(server_alias
);
1149 static gboolean
process_get_info_response(struct sipe_core_private
*sipe_private
,
1151 struct transaction
*trans
)
1153 const gchar
*uri
= trans
->payload
->data
;
1154 struct sipe_backend_buddy_info
*info
= NULL
;
1155 gchar
*server_alias
= NULL
;
1156 gchar
*email
= NULL
;
1158 SIPE_DEBUG_INFO("Fetching %s's user info for %s",
1159 uri
, sipe_private
->username
);
1161 if (msg
->response
!= 200) {
1162 SIPE_DEBUG_INFO("process_get_info_response: SERVICE response is %d", msg
->response
);
1164 sipe_xml
*searchResults
;
1165 const sipe_xml
*mrow
;
1167 SIPE_DEBUG_INFO("process_get_info_response: body:\n%s",
1168 msg
->body
? msg
->body
: "");
1170 searchResults
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1171 if (!searchResults
) {
1173 SIPE_DEBUG_INFO_NOFORMAT("process_get_info_response: no parseable searchResults");
1175 } else if ((mrow
= sipe_xml_child(searchResults
, "Body/Array/row"))) {
1177 gchar
*phone_number
;
1179 info
= sipe_backend_buddy_info_start(SIPE_CORE_PUBLIC
);
1181 server_alias
= g_strdup(sipe_xml_attribute(mrow
, "displayName"));
1182 email
= g_strdup(sipe_xml_attribute(mrow
, "email"));
1183 phone_number
= g_strdup(sipe_xml_attribute(mrow
, "phone"));
1186 * For 2007 system we will take this from ContactCard -
1187 * it has cleaner tel: URIs at least
1189 if (!SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
1190 char *tel_uri
= sip_to_tel_uri(phone_number
);
1191 /* trims its parameters, so call first */
1192 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_DISPLAY_NAME
, server_alias
);
1193 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_EMAIL
, email
);
1194 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_WORK_PHONE
, tel_uri
);
1195 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY
, phone_number
);
1198 sipe_backend_buddy_refresh_properties(SIPE_CORE_PUBLIC
,
1202 if (!is_empty(server_alias
)) {
1203 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1205 SIPE_BUDDY_INFO_DISPLAY_NAME
,
1208 if ((value
= sipe_xml_attribute(mrow
, "title")) && strlen(value
) > 0) {
1209 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1211 SIPE_BUDDY_INFO_JOB_TITLE
,
1214 if ((value
= sipe_xml_attribute(mrow
, "office")) && strlen(value
) > 0) {
1215 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1217 SIPE_BUDDY_INFO_OFFICE
,
1220 if (!is_empty(phone_number
)) {
1221 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1223 SIPE_BUDDY_INFO_WORK_PHONE
,
1226 g_free(phone_number
);
1227 if ((value
= sipe_xml_attribute(mrow
, "company")) && strlen(value
) > 0) {
1228 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1230 SIPE_BUDDY_INFO_COMPANY
,
1233 if ((value
= sipe_xml_attribute(mrow
, "city")) && strlen(value
) > 0) {
1234 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1236 SIPE_BUDDY_INFO_CITY
,
1239 if ((value
= sipe_xml_attribute(mrow
, "state")) && strlen(value
) > 0) {
1240 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1242 SIPE_BUDDY_INFO_STATE
,
1245 if ((value
= sipe_xml_attribute(mrow
, "country")) && strlen(value
) > 0) {
1246 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1248 SIPE_BUDDY_INFO_COUNTRY
,
1251 if (!is_empty(email
)) {
1252 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1254 SIPE_BUDDY_INFO_EMAIL
,
1258 sipe_xml_free(searchResults
);
1261 /* this will show the minmum information */
1262 get_info_finalize(sipe_private
,
1268 g_free(server_alias
);
1274 static void get_info_ab_entry_failed(struct sipe_core_private
*sipe_private
,
1275 struct ms_dlx_data
*mdd
)
1277 /* error using [MS-DLX] server, retry using Active Directory */
1278 gchar
*query
= prepare_buddy_search_query(mdd
->search_rows
, FALSE
);
1279 struct transaction_payload
*payload
= g_new0(struct transaction_payload
, 1);
1281 payload
->destroy
= g_free
;
1282 payload
->data
= mdd
->other
;
1285 sip_soap_directory_search(sipe_private
,
1288 process_get_info_response
,
1295 void sipe_core_buddy_get_info(struct sipe_core_public
*sipe_public
,
1298 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1300 if (sipe_private
->dlx_uri
) {
1301 struct ms_dlx_data
*mdd
= g_new0(struct ms_dlx_data
, 1);
1303 mdd
->search_rows
= g_slist_append(mdd
->search_rows
, g_strdup("msRTCSIP-PrimaryUserAddress"));
1304 mdd
->search_rows
= g_slist_append(mdd
->search_rows
, g_strdup(who
));
1306 mdd
->other
= g_strdup(who
);
1307 mdd
->max_returns
= 1;
1308 mdd
->callback
= get_info_ab_entry_response
;
1309 mdd
->failed_callback
= get_info_ab_entry_failed
;
1310 mdd
->session
= sipe_svc_session_start();
1312 ms_dlx_webticket_request(sipe_private
, mdd
);
1315 /* no [MS-DLX] server, use Active Directory search instead */
1316 gchar
*row
= g_markup_printf_escaped(SIPE_SOAP_SEARCH_ROW
,
1317 "msRTCSIP-PrimaryUserAddress",
1319 struct transaction_payload
*payload
= g_new0(struct transaction_payload
, 1);
1321 SIPE_DEBUG_INFO("sipe_core_buddy_get_info: row: %s",
1324 payload
->destroy
= g_free
;
1325 payload
->data
= g_strdup(who
);
1327 sip_soap_directory_search(sipe_private
,
1330 process_get_info_response
,
1336 static void photo_response_data_free(struct photo_response_data
*data
)
1339 g_free(data
->photo_hash
);
1340 if (data
->request
) {
1341 sipe_http_request_cancel(data
->request
);
1346 static void process_buddy_photo_response(struct sipe_core_private
*sipe_private
,
1352 struct photo_response_data
*rdata
= (struct photo_response_data
*) data
;
1354 rdata
->request
= NULL
;
1356 if (status
== SIPE_HTTP_STATUS_OK
) {
1357 const gchar
*len_str
= sipe_utils_nameval_find(headers
,
1360 gsize photo_size
= atoi(len_str
);
1361 gpointer photo
= g_new(char, photo_size
);
1364 memcpy(photo
, body
, photo_size
);
1366 sipe_backend_buddy_set_photo(SIPE_CORE_PUBLIC
,
1375 sipe_private
->buddies
->pending_photo_requests
=
1376 g_slist_remove(sipe_private
->buddies
->pending_photo_requests
, rdata
);
1378 photo_response_data_free(rdata
);
1381 static gchar
*create_x_ms_webticket_header(const gchar
*wsse_security
)
1383 gchar
*assertion
= sipe_xml_extract_raw(wsse_security
, "saml:Assertion", TRUE
);
1384 gchar
*wsse_security_base64
;
1385 gchar
*x_ms_webticket_header
;
1391 wsse_security_base64
= g_base64_encode((const guchar
*)assertion
,
1393 x_ms_webticket_header
= g_strdup_printf("X-MS-WebTicket: opaque=%s\r\n",
1394 wsse_security_base64
);
1397 g_free(wsse_security_base64
);
1399 return x_ms_webticket_header
;
1402 static void get_photo_ab_entry_response(struct sipe_core_private
*sipe_private
,
1404 SIPE_UNUSED_PARAMETER
const gchar
*raw
,
1405 sipe_xml
*soap_body
,
1406 gpointer callback_data
)
1408 struct ms_dlx_data
*mdd
= callback_data
;
1409 gchar
*photo_rel_path
= NULL
;
1410 gchar
*photo_hash
= NULL
;
1411 const gchar
*photo_hash_old
=
1412 sipe_backend_buddy_get_photo_hash(SIPE_CORE_PUBLIC
, mdd
->other
);
1415 const sipe_xml
*node
;
1417 SIPE_DEBUG_INFO("get_photo_ab_entry_response: received valid SOAP message from service %s",
1420 for (node
= sipe_xml_child(soap_body
, "Body/SearchAbEntryResponse/SearchAbEntryResult/Items/AbEntry/Attributes/Attribute");
1422 node
= sipe_xml_twin(node
)) {
1423 gchar
*name
= sipe_xml_data(sipe_xml_child(node
, "Name"));
1424 gchar
*value
= sipe_xml_data(sipe_xml_child(node
, "Value"));
1426 if (!is_empty(value
)) {
1427 if (sipe_strcase_equal(name
, "PhotoRelPath")) {
1428 g_free(photo_rel_path
);
1429 photo_rel_path
= value
;
1431 } else if (sipe_strcase_equal(name
, "PhotoHash")) {
1443 if (sipe_private
->addressbook_uri
&& photo_rel_path
&&
1444 photo_hash
&& !sipe_strequal(photo_hash
, photo_hash_old
)) {
1445 gchar
*photo_url
= g_strdup_printf("%s/%s",
1446 sipe_private
->addressbook_uri
, photo_rel_path
);
1447 gchar
*x_ms_webticket_header
= create_x_ms_webticket_header(mdd
->wsse_security
);
1449 struct photo_response_data
*data
= g_new(struct photo_response_data
, 1);
1450 data
->who
= g_strdup(mdd
->other
);
1451 data
->photo_hash
= photo_hash
;
1454 data
->request
= sipe_http_request_get(sipe_private
,
1456 x_ms_webticket_header
,
1457 process_buddy_photo_response
,
1460 if (data
->request
) {
1461 sipe_private
->buddies
->pending_photo_requests
=
1462 g_slist_append(sipe_private
->buddies
->pending_photo_requests
, data
);
1463 sipe_http_request_ready(data
->request
);
1465 photo_response_data_free(data
);
1468 g_free(x_ms_webticket_header
);
1472 g_free(photo_rel_path
);
1477 static void get_photo_ab_entry_failed(SIPE_UNUSED_PARAMETER
struct sipe_core_private
*sipe_private
,
1478 struct ms_dlx_data
*mdd
)
1483 static void buddy_fetch_photo(struct sipe_core_private
*sipe_private
,
1486 if (sipe_backend_uses_photo()) {
1488 /* Lync 2013 or newer: use UCS */
1489 if (SIPE_CORE_PRIVATE_FLAG_IS(LYNC2013
)) {
1491 sipe_ucs_get_photo(sipe_private
, uri
);
1493 /* Lync 2010: use [MS-DLX] */
1494 } else if (sipe_private
->dlx_uri
&&
1495 sipe_private
->addressbook_uri
) {
1496 struct ms_dlx_data
*mdd
= g_new0(struct ms_dlx_data
, 1);
1498 mdd
->search_rows
= g_slist_append(mdd
->search_rows
, g_strdup("msRTCSIP-PrimaryUserAddress"));
1499 mdd
->search_rows
= g_slist_append(mdd
->search_rows
, g_strdup(uri
));
1501 mdd
->other
= g_strdup(uri
);
1502 mdd
->max_returns
= 1;
1503 mdd
->callback
= get_photo_ab_entry_response
;
1504 mdd
->failed_callback
= get_photo_ab_entry_failed
;
1505 mdd
->session
= sipe_svc_session_start();
1507 ms_dlx_webticket_request(sipe_private
, mdd
);
1512 static void buddy_refresh_photos_cb(gpointer uri
,
1513 SIPE_UNUSED_PARAMETER gpointer value
,
1514 gpointer sipe_private
)
1516 buddy_fetch_photo(sipe_private
, uri
);
1519 void sipe_buddy_refresh_photos(struct sipe_core_private
*sipe_private
)
1521 g_hash_table_foreach(sipe_private
->buddies
->uri
,
1522 buddy_refresh_photos_cb
,
1526 /* Buddy menu callbacks*/
1528 void sipe_core_buddy_new_chat(struct sipe_core_public
*sipe_public
,
1531 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1533 /* 2007+ conference */
1534 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
1535 sipe_conf_add(sipe_private
, who
);
1537 /* 2005- multiparty chat */
1539 gchar
*self
= sip_uri_self(sipe_private
);
1540 struct sip_session
*session
;
1542 session
= sipe_session_add_chat(sipe_private
,
1546 session
->chat_session
->backend
= sipe_backend_chat_create(SIPE_CORE_PUBLIC
,
1547 session
->chat_session
,
1548 session
->chat_session
->title
,
1552 sipe_im_invite(sipe_private
, session
, who
,
1553 NULL
, NULL
, NULL
, FALSE
);
1557 void sipe_core_buddy_send_email(struct sipe_core_public
*sipe_public
,
1560 sipe_backend_buddy buddy
= sipe_backend_buddy_find(sipe_public
,
1563 gchar
*email
= sipe_backend_buddy_get_string(sipe_public
,
1565 SIPE_BUDDY_INFO_EMAIL
);
1568 gchar
*command_line
= g_strdup_printf(
1574 " mailto:%s", email
);
1577 SIPE_DEBUG_INFO("sipe_core_buddy_send_email: going to call email client: %s",
1579 g_spawn_command_line_async(command_line
, NULL
);
1580 g_free(command_line
);
1583 SIPE_DEBUG_INFO("sipe_core_buddy_send_email: no email address stored for buddy=%s",
1590 static struct sipe_backend_buddy_menu
*buddy_menu_phone(struct sipe_core_public
*sipe_public
,
1591 struct sipe_backend_buddy_menu
*menu
,
1592 sipe_backend_buddy buddy
,
1593 sipe_buddy_info_fields id_phone
,
1594 sipe_buddy_info_fields id_display
,
1597 gchar
*phone
= sipe_backend_buddy_get_string(sipe_public
,
1601 gchar
*display
= sipe_backend_buddy_get_string(sipe_public
,
1605 gchar
*label
= g_strdup_printf("%s %s",
1608 (tmp
= sip_tel_uri_denormalize(phone
)));
1609 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1612 SIPE_BUDDY_MENU_MAKE_CALL
,
1623 struct sipe_backend_buddy_menu
*sipe_core_buddy_create_menu(struct sipe_core_public
*sipe_public
,
1624 const gchar
*buddy_name
,
1625 struct sipe_backend_buddy_menu
*menu
)
1627 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1628 sipe_backend_buddy buddy
= sipe_backend_buddy_find(sipe_public
,
1631 gchar
*self
= sip_uri_self(sipe_private
);
1633 SIPE_SESSION_FOREACH
{
1634 if (!sipe_strcase_equal(self
, buddy_name
) && session
->chat_session
)
1636 struct sipe_chat_session
*chat_session
= session
->chat_session
;
1637 gboolean is_conf
= (chat_session
->type
== SIPE_CHAT_TYPE_CONFERENCE
);
1639 if (sipe_backend_chat_find(chat_session
->backend
, buddy_name
))
1641 gboolean conf_op
= sipe_backend_chat_is_operator(chat_session
->backend
, self
);
1645 !sipe_backend_chat_is_operator(chat_session
->backend
, buddy_name
) &&
1646 /* We are a conf OP */
1648 gchar
*label
= g_strdup_printf(_("Make leader of '%s'"),
1649 chat_session
->title
);
1650 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1653 SIPE_BUDDY_MENU_MAKE_CHAT_LEADER
,
1659 /* We are a conf OP */
1661 gchar
*label
= g_strdup_printf(_("Remove from '%s'"),
1662 chat_session
->title
);
1663 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1666 SIPE_BUDDY_MENU_REMOVE_FROM_CHAT
,
1674 (is_conf
&& !session
->locked
)) {
1675 gchar
*label
= g_strdup_printf(_("Invite to '%s'"),
1676 chat_session
->title
);
1677 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1680 SIPE_BUDDY_MENU_INVITE_TO_CHAT
,
1686 } SIPE_SESSION_FOREACH_END
;
1689 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1692 SIPE_BUDDY_MENU_NEW_CHAT
,
1695 /* add buddy's phone numbers if we have call control */
1696 if (sip_csta_is_idle(sipe_private
)) {
1699 menu
= buddy_menu_phone(sipe_public
,
1702 SIPE_BUDDY_INFO_WORK_PHONE
,
1703 SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY
,
1706 menu
= buddy_menu_phone(sipe_public
,
1709 SIPE_BUDDY_INFO_MOBILE_PHONE
,
1710 SIPE_BUDDY_INFO_MOBILE_PHONE_DISPLAY
,
1714 menu
= buddy_menu_phone(sipe_public
,
1717 SIPE_BUDDY_INFO_HOME_PHONE
,
1718 SIPE_BUDDY_INFO_HOME_PHONE_DISPLAY
,
1722 menu
= buddy_menu_phone(sipe_public
,
1725 SIPE_BUDDY_INFO_OTHER_PHONE
,
1726 SIPE_BUDDY_INFO_OTHER_PHONE_DISPLAY
,
1730 menu
= buddy_menu_phone(sipe_public
,
1733 SIPE_BUDDY_INFO_CUSTOM1_PHONE
,
1734 SIPE_BUDDY_INFO_CUSTOM1_PHONE_DISPLAY
,
1739 gchar
*email
= sipe_backend_buddy_get_string(sipe_public
,
1741 SIPE_BUDDY_INFO_EMAIL
);
1743 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1746 SIPE_BUDDY_MENU_SEND_EMAIL
,
1752 /* access level control */
1753 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
))
1754 menu
= sipe_backend_buddy_sub_menu_add(sipe_public
,
1757 sipe_ocs2007_access_control_menu(sipe_private
,
1763 guint
sipe_buddy_count(struct sipe_core_private
*sipe_private
)
1765 return(g_hash_table_size(sipe_private
->buddies
->uri
));
1768 static guint
sipe_ht_hash_nick(const char *nick
)
1770 char *lc
= g_utf8_strdown(nick
, -1);
1771 guint bucket
= g_str_hash(lc
);
1777 static gboolean
sipe_ht_equals_nick(const char *nick1
, const char *nick2
)
1779 char *nick1_norm
= NULL
;
1780 char *nick2_norm
= NULL
;
1783 if (nick1
== NULL
&& nick2
== NULL
) return TRUE
;
1784 if (nick1
== NULL
|| nick2
== NULL
||
1785 !g_utf8_validate(nick1
, -1, NULL
) ||
1786 !g_utf8_validate(nick2
, -1, NULL
)) return FALSE
;
1788 nick1_norm
= g_utf8_casefold(nick1
, -1);
1789 nick2_norm
= g_utf8_casefold(nick2
, -1);
1790 equal
= g_utf8_collate(nick1_norm
, nick2_norm
) == 0;
1797 void sipe_buddy_init(struct sipe_core_private
*sipe_private
)
1799 struct sipe_buddies
*buddies
= g_new0(struct sipe_buddies
, 1);
1800 buddies
->uri
= g_hash_table_new((GHashFunc
) sipe_ht_hash_nick
,
1801 (GEqualFunc
) sipe_ht_equals_nick
);
1802 buddies
->exchange_key
= g_hash_table_new(g_str_hash
,
1804 sipe_private
->buddies
= buddies
;