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"
64 /* Pending photo download HTTP requests */
65 GSList
*pending_photo_requests
;
68 struct photo_response_data
{
71 struct sipe_http_request
*request
;
74 static void buddy_fetch_photo(struct sipe_core_private
*sipe_private
,
76 static void photo_response_data_free(struct photo_response_data
*data
);
78 struct sipe_buddy
*sipe_buddy_add(struct sipe_core_private
*sipe_private
,
80 const gchar
*exchange_key
)
82 struct sipe_buddy
*buddy
= sipe_buddy_find_by_uri(sipe_private
, uri
);
84 buddy
= g_new0(struct sipe_buddy
, 1);
85 buddy
->name
= g_strdup(uri
);
86 buddy
->exchange_key
= g_strdup(exchange_key
);
87 g_hash_table_insert(sipe_private
->buddies
->uri
,
91 SIPE_DEBUG_INFO("sipe_buddy_add: Added buddy %s", uri
);
93 buddy_fetch_photo(sipe_private
, uri
);
95 SIPE_DEBUG_INFO("sipe_buddy_add: Buddy %s already exists", uri
);
101 struct sipe_buddy
*sipe_buddy_find_by_uri(struct sipe_core_private
*sipe_private
,
104 return(g_hash_table_lookup(sipe_private
->buddies
->uri
, uri
));
107 void sipe_buddy_foreach(struct sipe_core_private
*sipe_private
,
109 gpointer callback_data
)
111 g_hash_table_foreach(sipe_private
->buddies
->uri
,
116 static void buddy_free(struct sipe_buddy
*buddy
)
120 * We are calling g_hash_table_foreach_steal(). That means that no
121 * key/value deallocation functions are called. Therefore the glib
122 * hash code does not touch the key (buddy->name) or value (buddy)
123 * of the to-be-deleted hash node at all. It follows that we
125 * - MUST free the memory for the key ourselves and
126 * - ARE allowed to do it in this function
128 * Conclusion: glib must be broken on the Windows platform if sipe
129 * crashes with SIGTRAP when closing. You'll have to live
130 * with the memory leak until this is fixed.
134 g_free(buddy
->exchange_key
);
135 g_free(buddy
->activity
);
136 g_free(buddy
->meeting_subject
);
137 g_free(buddy
->meeting_location
);
140 g_free(buddy
->cal_start_time
);
141 g_free(buddy
->cal_free_busy_base64
);
142 g_free(buddy
->cal_free_busy
);
143 g_free(buddy
->last_non_cal_activity
);
145 sipe_cal_free_working_hours(buddy
->cal_working_hours
);
147 g_free(buddy
->device_name
);
148 g_slist_free(buddy
->groups
);
152 static gboolean
buddy_free_cb(SIPE_UNUSED_PARAMETER gpointer key
,
154 SIPE_UNUSED_PARAMETER gpointer user_data
)
157 /* We must return TRUE as the key/value have already been deleted */
161 void sipe_buddy_free(struct sipe_core_private
*sipe_private
)
163 struct sipe_buddies
*buddies
= sipe_private
->buddies
;
165 g_hash_table_foreach_steal(buddies
->uri
,
169 /* core is being deallocated, remove all its pending photo requests */
170 while (buddies
->pending_photo_requests
) {
171 struct photo_response_data
*data
=
172 buddies
->pending_photo_requests
->data
;
173 buddies
->pending_photo_requests
=
174 g_slist_remove(buddies
->pending_photo_requests
, data
);
175 photo_response_data_free(data
);
178 g_hash_table_destroy(buddies
->uri
);
180 sipe_private
->buddies
= NULL
;
183 gchar
*sipe_core_buddy_status(struct sipe_core_public
*sipe_public
,
186 const gchar
*status_text
)
188 struct sipe_buddy
*sbuddy
;
189 const char *activity_str
;
191 if (!sipe_public
) return NULL
; /* happens on pidgin exit */
193 sbuddy
= sipe_buddy_find_by_uri(SIPE_CORE_PRIVATE
, uri
);
194 if (!sbuddy
) return NULL
;
196 activity_str
= sbuddy
->activity
? sbuddy
->activity
:
197 (activity
== SIPE_ACTIVITY_BUSY
) || (activity
== SIPE_ACTIVITY_BRB
) ?
200 if (activity_str
&& sbuddy
->note
) {
201 return g_strdup_printf("%s - <i>%s</i>", activity_str
, sbuddy
->note
);
202 } else if (activity_str
) {
203 return g_strdup(activity_str
);
204 } else if (sbuddy
->note
) {
205 return g_strdup_printf("<i>%s</i>", sbuddy
->note
);
211 gchar
*sipe_buddy_get_alias(struct sipe_core_private
*sipe_private
,
214 sipe_backend_buddy pbuddy
;
216 if ((pbuddy
= sipe_backend_buddy_find(SIPE_CORE_PUBLIC
, with
, NULL
))) {
217 alias
= sipe_backend_buddy_get_alias(SIPE_CORE_PUBLIC
, pbuddy
);
222 void sipe_core_buddy_group(struct sipe_core_public
*sipe_public
,
224 const gchar
*old_group_name
,
225 const gchar
*new_group_name
)
227 struct sipe_buddy
* buddy
= sipe_buddy_find_by_uri(SIPE_CORE_PRIVATE
,
229 struct sipe_group
* old_group
= NULL
;
230 struct sipe_group
* new_group
;
232 SIPE_DEBUG_INFO("sipe_core_buddy_group: who:%s old_group_name:%s new_group_name:%s",
233 who
? who
: "", old_group_name
? old_group_name
: "", new_group_name
? new_group_name
: "");
235 if(!buddy
) { // buddy not in roaming list
239 if (old_group_name
) {
240 old_group
= sipe_group_find_by_name(SIPE_CORE_PRIVATE
, old_group_name
);
242 new_group
= sipe_group_find_by_name(SIPE_CORE_PRIVATE
, new_group_name
);
245 buddy
->groups
= g_slist_remove(buddy
->groups
, old_group
);
246 SIPE_DEBUG_INFO("sipe_core_buddy_group: buddy %s removed from old group %s", who
, old_group_name
);
250 sipe_group_create(SIPE_CORE_PRIVATE
, new_group_name
, who
);
252 buddy
->groups
= sipe_utils_slist_insert_unique_sorted(buddy
->groups
,
254 (GCompareFunc
)sipe_group_compare
,
256 sipe_group_update_buddy(SIPE_CORE_PRIVATE
, buddy
);
260 void sipe_core_buddy_add(struct sipe_core_public
*sipe_public
,
262 const gchar
*group_name
)
264 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
266 if (!sipe_buddy_find_by_uri(sipe_private
, uri
)) {
267 struct sipe_buddy
*b
= sipe_buddy_add(sipe_private
, uri
, NULL
);
268 b
->just_added
= TRUE
;
270 sipe_subscribe_presence_single_cb(sipe_private
, b
->name
);
273 SIPE_DEBUG_INFO("sipe_core_buddy_add: buddy %s already in internal list",
277 sipe_core_buddy_group(sipe_public
,
283 void sipe_buddy_remove(struct sipe_core_private
*sipe_private
,
284 struct sipe_buddy
*buddy
)
286 gchar
*action_name
= sipe_utils_presence_key(buddy
->name
);
287 sipe_schedule_cancel(sipe_private
, action_name
);
290 g_hash_table_remove(sipe_private
->buddies
->uri
, buddy
->name
);
296 * Unassociates buddy from group first.
297 * Then see if no groups left, removes buddy completely.
298 * Otherwise updates buddy groups on server.
300 void sipe_core_buddy_remove(struct sipe_core_public
*sipe_public
,
302 const gchar
*group_name
)
304 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
305 struct sipe_buddy
*b
= sipe_buddy_find_by_uri(sipe_private
,
311 struct sipe_group
*g
= sipe_group_find_by_name(sipe_private
,
314 b
->groups
= g_slist_remove(b
->groups
, g
);
315 SIPE_DEBUG_INFO("sipe_core_buddy_remove: buddy %s removed from group %s",
320 if (g_slist_length(b
->groups
) < 1) {
321 gchar
*request
= g_strdup_printf("<m:URI>%s</m:URI>",
323 sip_soap_request(sipe_private
,
327 sipe_buddy_remove(sipe_private
, b
);
329 /* updates groups on server */
330 sipe_group_update_buddy(sipe_private
, b
);
335 void sipe_core_buddy_got_status(struct sipe_core_public
*sipe_public
,
339 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
340 struct sipe_buddy
*sbuddy
= sipe_buddy_find_by_uri(sipe_private
,
345 /* Check if on 2005 system contact's calendar,
346 * then set/preserve it.
348 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
349 sipe_backend_buddy_set_status(sipe_public
, uri
, activity
);
351 sipe_ocs2005_apply_calendar_status(sipe_private
,
353 sipe_status_activity_to_token(activity
));
357 void sipe_core_buddy_tooltip_info(struct sipe_core_public
*sipe_public
,
359 const gchar
*status_name
,
361 struct sipe_backend_buddy_tooltip
*tooltip
)
363 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
365 gboolean is_oof_note
= FALSE
;
366 const gchar
*activity
= NULL
;
367 gchar
*calendar
= NULL
;
368 const gchar
*meeting_subject
= NULL
;
369 const gchar
*meeting_location
= NULL
;
370 gchar
*access_text
= NULL
;
372 #define SIPE_ADD_BUDDY_INFO(l, t) \
374 gchar *tmp = g_markup_escape_text((t), -1); \
375 sipe_backend_buddy_tooltip_add(sipe_public, tooltip, (l), tmp); \
378 #define SIPE_ADD_BUDDY_INFO_NOESCAPE(l, t) \
379 sipe_backend_buddy_tooltip_add(sipe_public, tooltip, (l), (t))
381 if (sipe_public
) { /* happens on pidgin exit */
382 struct sipe_buddy
*sbuddy
= sipe_buddy_find_by_uri(sipe_private
,
386 is_oof_note
= sbuddy
->is_oof_note
;
387 activity
= sbuddy
->activity
;
388 calendar
= sipe_cal_get_description(sbuddy
);
389 meeting_subject
= sbuddy
->meeting_subject
;
390 meeting_location
= sbuddy
->meeting_location
;
392 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
393 gboolean is_group_access
= FALSE
;
394 const int container_id
= sipe_ocs2007_find_access_level(sipe_private
,
396 sipe_get_no_sip_uri(uri
),
398 const char *access_level
= sipe_ocs2007_access_level_name(container_id
);
399 access_text
= is_group_access
?
400 g_strdup(access_level
) :
401 g_strdup_printf(SIPE_OCS2007_INDENT_MARKED_FMT
,
407 const gchar
*status_str
= activity
? activity
: status_name
;
409 SIPE_ADD_BUDDY_INFO(_("Status"), status_str
);
411 if (is_online
&& !is_empty(calendar
)) {
412 SIPE_ADD_BUDDY_INFO(_("Calendar"), calendar
);
415 if (!is_empty(meeting_location
)) {
416 SIPE_DEBUG_INFO("sipe_tooltip_text: %s meeting location: '%s'", uri
, meeting_location
);
417 SIPE_ADD_BUDDY_INFO(_("Meeting in"), meeting_location
);
419 if (!is_empty(meeting_subject
)) {
420 SIPE_DEBUG_INFO("sipe_tooltip_text: %s meeting subject: '%s'", uri
, meeting_subject
);
421 SIPE_ADD_BUDDY_INFO(_("Meeting about"), meeting_subject
);
424 gchar
*note_italics
= g_strdup_printf("<i>%s</i>", note
);
425 SIPE_DEBUG_INFO("sipe_tooltip_text: %s note: '%s'", uri
, note
);
426 SIPE_ADD_BUDDY_INFO_NOESCAPE(is_oof_note
? _("Out of office note") : _("Note"),
428 g_free(note_italics
);
431 SIPE_ADD_BUDDY_INFO(_("Access level"), access_text
);
436 void sipe_buddy_update_property(struct sipe_core_private
*sipe_private
,
438 sipe_buddy_info_fields propkey
,
439 char *property_value
)
441 GSList
*buddies
, *entry
;
444 property_value
= g_strstrip(property_value
);
446 entry
= buddies
= sipe_backend_buddy_find_all(SIPE_CORE_PUBLIC
, uri
, NULL
); /* all buddies in different groups */
449 sipe_backend_buddy p_buddy
= entry
->data
;
451 /* for Display Name */
452 if (propkey
== SIPE_BUDDY_INFO_DISPLAY_NAME
) {
454 alias
= sipe_backend_buddy_get_alias(SIPE_CORE_PUBLIC
, p_buddy
);
455 if (property_value
&& sipe_is_bad_alias(uri
, alias
)) {
456 SIPE_DEBUG_INFO("Replacing alias for %s with %s", uri
, property_value
);
457 sipe_backend_buddy_set_alias(SIPE_CORE_PUBLIC
, p_buddy
, property_value
);
461 alias
= sipe_backend_buddy_get_server_alias(SIPE_CORE_PUBLIC
, p_buddy
);
462 if (!is_empty(property_value
) &&
463 (!sipe_strequal(property_value
, alias
) || is_empty(alias
)) )
465 SIPE_DEBUG_INFO("Replacing service alias for %s with %s", uri
, property_value
);
466 sipe_backend_buddy_set_server_alias(SIPE_CORE_PUBLIC
, p_buddy
, property_value
);
470 /* for other properties */
472 if (!is_empty(property_value
)) {
473 prop_str
= sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC
, p_buddy
, propkey
);
474 if (!prop_str
|| !sipe_strcase_equal(prop_str
, property_value
)) {
475 sipe_backend_buddy_set_string(SIPE_CORE_PUBLIC
, p_buddy
, propkey
, property_value
);
483 g_slist_free(buddies
);
492 sipe_svc_callback
*callback
;
493 struct sipe_svc_session
*session
;
494 gchar
*wsse_security
;
495 struct sipe_backend_search_token
*token
;
496 /* must call ms_dlx_free() */
497 void (*failed_callback
)(struct sipe_core_private
*sipe_private
,
498 struct ms_dlx_data
*mdd
);
501 static void ms_dlx_free(struct ms_dlx_data
*mdd
)
503 sipe_utils_slist_free_full(mdd
->search_rows
, g_free
);
504 sipe_svc_session_close(mdd
->session
);
506 g_free(mdd
->wsse_security
);
510 #define SIPE_SOAP_SEARCH_ROW "<m:row m:attrib=\"%s\" m:value=\"%s\"/>"
511 #define DLX_SEARCH_ITEM \
512 "<AbEntryRequest.ChangeSearchQuery>" \
513 " <SearchOn>%s</SearchOn>" \
514 " <Value>%s</Value>" \
515 "</AbEntryRequest.ChangeSearchQuery>"
517 static gchar
* prepare_buddy_search_query(GSList
*query_rows
, gboolean use_dlx
) {
518 gchar
**attrs
= g_new(gchar
*, (g_slist_length(query_rows
) / 2) + 1);
526 attr
= query_rows
->data
;
527 query_rows
= g_slist_next(query_rows
);
528 value
= query_rows
->data
;
529 query_rows
= g_slist_next(query_rows
);
534 attrs
[i
++] = g_markup_printf_escaped(use_dlx
? DLX_SEARCH_ITEM
: SIPE_SOAP_SEARCH_ROW
,
540 query
= g_strjoinv(NULL
, attrs
);
541 SIPE_DEBUG_INFO("prepare_buddy_search_query: rows:\n%s",
550 static void ms_dlx_webticket(struct sipe_core_private
*sipe_private
,
551 const gchar
*base_uri
,
552 const gchar
*auth_uri
,
553 const gchar
*wsse_security
,
554 SIPE_UNUSED_PARAMETER
const gchar
*failure_msg
,
555 gpointer callback_data
)
557 struct ms_dlx_data
*mdd
= callback_data
;
560 gchar
*query
= prepare_buddy_search_query(mdd
->search_rows
, TRUE
);
562 SIPE_DEBUG_INFO("ms_dlx_webticket: got ticket for %s",
565 if (sipe_svc_ab_entry_request(sipe_private
,
570 g_slist_length(mdd
->search_rows
) / 2,
575 /* keep webticket security token for potential further use */
576 mdd
->wsse_security
= g_strdup(wsse_security
);
578 /* callback data passed down the line */
584 /* no ticket: this will show the minmum information */
585 SIPE_DEBUG_ERROR("ms_dlx_webticket: no web ticket for %s",
590 mdd
->failed_callback(sipe_private
, mdd
);
593 static void ms_dlx_webticket_request(struct sipe_core_private
*sipe_private
,
594 struct ms_dlx_data
*mdd
)
596 if (!sipe_webticket_request(sipe_private
,
598 sipe_private
->dlx_uri
,
599 "AddressBookWebTicketBearer",
602 SIPE_DEBUG_ERROR("ms_dlx_webticket_request: couldn't request webticket for %s",
603 sipe_private
->dlx_uri
);
604 mdd
->failed_callback(sipe_private
, mdd
);
608 static void search_contacts_finalize(struct sipe_core_private
*sipe_private
,
609 struct sipe_backend_search_results
*results
,
613 gchar
*secondary
= g_strdup_printf(
614 dngettext(PACKAGE_NAME
,
615 "Found %d contact%s:",
616 "Found %d contacts%s:", match_count
),
617 match_count
, more
? _(" (more matched your query)") : "");
619 sipe_backend_search_results_finalize(SIPE_CORE_PUBLIC
,
626 static void search_ab_entry_response(struct sipe_core_private
*sipe_private
,
628 SIPE_UNUSED_PARAMETER
const gchar
*raw
,
630 gpointer callback_data
)
632 struct ms_dlx_data
*mdd
= callback_data
;
635 const sipe_xml
*node
;
636 struct sipe_backend_search_results
*results
;
639 SIPE_DEBUG_INFO("search_ab_entry_response: received valid SOAP message from service %s",
643 node
= sipe_xml_child(soap_body
, "Body/SearchAbEntryResponse/SearchAbEntryResult/Items/AbEntry");
645 SIPE_DEBUG_ERROR_NOFORMAT("search_ab_entry_response: no matches");
646 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
648 _("No contacts found"));
653 /* OK, we found something - show the results to the user */
654 results
= sipe_backend_search_results_start(SIPE_CORE_PUBLIC
,
657 SIPE_DEBUG_ERROR_NOFORMAT("search_ab_entry_response: Unable to display the search results.");
658 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
660 _("Unable to display the search results"));
665 /* SearchAbEntryResult can contain duplicates */
666 found
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
669 for (/* initialized above */ ; node
; node
= sipe_xml_twin(node
)) {
670 const sipe_xml
*attrs
;
671 gchar
*sip_uri
= NULL
;
672 gchar
*displayname
= NULL
;
673 gchar
*company
= NULL
;
674 gchar
*country
= NULL
;
677 for (attrs
= sipe_xml_child(node
, "Attributes/Attribute");
679 attrs
= sipe_xml_twin(attrs
)) {
680 gchar
*name
= sipe_xml_data(sipe_xml_child(attrs
,
682 gchar
*value
= sipe_xml_data(sipe_xml_child(attrs
,
685 if (!is_empty(value
)) {
686 if (sipe_strcase_equal(name
, "msrtcsip-primaryuseraddress")) {
690 } else if (sipe_strcase_equal(name
, "displayname")) {
694 } else if (sipe_strcase_equal(name
, "mail")) {
698 } else if (sipe_strcase_equal(name
, "company")) {
702 } else if (sipe_strcase_equal(name
, "country")) {
713 if (sip_uri
&& !g_hash_table_lookup(found
, sip_uri
)) {
714 gchar
**uri_parts
= g_strsplit(sip_uri
, ":", 2);
715 sipe_backend_search_results_add(SIPE_CORE_PUBLIC
,
722 g_strfreev(uri_parts
);
724 g_hash_table_insert(found
, sip_uri
, (gpointer
) TRUE
);
735 search_contacts_finalize(sipe_private
, results
,
736 g_hash_table_size(found
),
738 g_hash_table_destroy(found
);
742 mdd
->failed_callback(sipe_private
, mdd
);
746 static gboolean
process_search_contact_response(struct sipe_core_private
*sipe_private
,
748 struct transaction
*trans
)
750 struct sipe_backend_search_token
*token
= trans
->payload
->data
;
751 struct sipe_backend_search_results
*results
;
752 sipe_xml
*searchResults
;
753 const sipe_xml
*mrow
;
754 guint match_count
= 0;
755 gboolean more
= FALSE
;
757 /* valid response? */
758 if (msg
->response
!= 200) {
759 SIPE_DEBUG_ERROR("process_search_contact_response: request failed (%d)",
761 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
763 _("Contact search failed"));
767 SIPE_DEBUG_INFO("process_search_contact_response: body:\n%s", msg
->body
? msg
->body
: "");
770 searchResults
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
771 if (!searchResults
) {
772 SIPE_DEBUG_INFO_NOFORMAT("process_search_contact_response: no parseable searchResults");
773 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
775 _("Contact search failed"));
780 mrow
= sipe_xml_child(searchResults
, "Body/Array/row");
782 SIPE_DEBUG_ERROR_NOFORMAT("process_search_contact_response: no matches");
783 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
785 _("No contacts found"));
787 sipe_xml_free(searchResults
);
791 /* OK, we found something - show the results to the user */
792 results
= sipe_backend_search_results_start(SIPE_CORE_PUBLIC
,
793 trans
->payload
->data
);
795 SIPE_DEBUG_ERROR_NOFORMAT("process_search_contact_response: Unable to display the search results.");
796 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
798 _("Unable to display the search results"));
800 sipe_xml_free(searchResults
);
804 for (/* initialized above */ ; mrow
; mrow
= sipe_xml_twin(mrow
)) {
805 gchar
**uri_parts
= g_strsplit(sipe_xml_attribute(mrow
, "uri"), ":", 2);
806 sipe_backend_search_results_add(SIPE_CORE_PUBLIC
,
809 sipe_xml_attribute(mrow
, "displayName"),
810 sipe_xml_attribute(mrow
, "company"),
811 sipe_xml_attribute(mrow
, "country"),
812 sipe_xml_attribute(mrow
, "email"));
813 g_strfreev(uri_parts
);
817 if ((mrow
= sipe_xml_child(searchResults
, "Body/directorySearch/moreAvailable")) != NULL
) {
818 char *data
= sipe_xml_data(mrow
);
819 more
= (g_ascii_strcasecmp(data
, "true") == 0);
823 search_contacts_finalize(sipe_private
, results
, match_count
, more
);
824 sipe_xml_free(searchResults
);
829 static void search_soap_request(struct sipe_core_private
*sipe_private
,
830 struct sipe_backend_search_token
*token
,
833 gchar
*query
= prepare_buddy_search_query(search_rows
, FALSE
);
834 struct transaction_payload
*payload
= g_new0(struct transaction_payload
, 1);
836 payload
->data
= token
;
838 sip_soap_directory_search(sipe_private
,
841 process_search_contact_response
,
846 static void search_ab_entry_failed(struct sipe_core_private
*sipe_private
,
847 struct ms_dlx_data
*mdd
)
849 /* error using [MS-DLX] server, retry using Active Directory */
850 search_soap_request(sipe_private
, mdd
->token
, mdd
->search_rows
);
854 void sipe_core_buddy_search(struct sipe_core_public
*sipe_public
,
855 struct sipe_backend_search_token
*token
,
856 const gchar
*given_name
,
857 const gchar
*surname
,
859 const gchar
*company
,
860 const gchar
*country
)
862 GSList
*query_rows
= NULL
;
864 #define ADD_QUERY_ROW(attr, val) \
866 query_rows = g_slist_append(query_rows, g_strdup(attr)); \
867 query_rows = g_slist_append(query_rows, g_strdup(val)); \
870 ADD_QUERY_ROW("givenName", given_name
);
871 ADD_QUERY_ROW("sn", surname
);
872 ADD_QUERY_ROW("mail", email
);
873 ADD_QUERY_ROW("company", company
);
874 ADD_QUERY_ROW("c", country
);
877 if (SIPE_CORE_PRIVATE
->dlx_uri
!= NULL
) {
878 struct ms_dlx_data
*mdd
= g_new0(struct ms_dlx_data
, 1);
880 mdd
->search_rows
= query_rows
;
881 mdd
->max_returns
= 100;
882 mdd
->callback
= search_ab_entry_response
;
883 mdd
->failed_callback
= search_ab_entry_failed
;
884 mdd
->session
= sipe_svc_session_start();
887 ms_dlx_webticket_request(SIPE_CORE_PRIVATE
, mdd
);
890 /* no [MS-DLX] server, use Active Directory search instead */
891 search_soap_request(SIPE_CORE_PRIVATE
, token
, query_rows
);
892 sipe_utils_slist_free_full(query_rows
, g_free
);
895 sipe_backend_search_failed(sipe_public
,
897 _("Invalid contact search query"));
900 static void get_info_finalize(struct sipe_core_private
*sipe_private
,
901 struct sipe_backend_buddy_info
*info
,
903 const gchar
*server_alias
,
906 sipe_backend_buddy bbuddy
;
907 struct sipe_buddy
*sbuddy
;
912 info
= sipe_backend_buddy_info_start(SIPE_CORE_PUBLIC
);
914 sipe_backend_buddy_info_break(SIPE_CORE_PUBLIC
, info
);
919 bbuddy
= sipe_backend_buddy_find(SIPE_CORE_PUBLIC
, uri
, NULL
);
921 if (is_empty(server_alias
)) {
922 value
= sipe_backend_buddy_get_server_alias(SIPE_CORE_PUBLIC
,
925 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
927 SIPE_BUDDY_INFO_DISPLAY_NAME
,
931 value
= g_strdup(server_alias
);
934 /* present alias if it differs from server alias */
935 alias
= sipe_backend_buddy_get_local_alias(SIPE_CORE_PUBLIC
, bbuddy
);
936 if (alias
&& !sipe_strequal(alias
, value
))
938 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
940 SIPE_BUDDY_INFO_ALIAS
,
946 if (is_empty(email
)) {
947 value
= sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC
,
949 SIPE_BUDDY_INFO_EMAIL
);
951 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
953 SIPE_BUDDY_INFO_EMAIL
,
959 value
= sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC
,
961 SIPE_BUDDY_INFO_SITE
);
963 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
965 SIPE_BUDDY_INFO_SITE
,
970 sbuddy
= sipe_buddy_find_by_uri(sipe_private
, uri
);
971 if (sbuddy
&& sbuddy
->device_name
) {
972 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
974 SIPE_BUDDY_INFO_DEVICE
,
975 sbuddy
->device_name
);
978 sipe_backend_buddy_info_finalize(SIPE_CORE_PUBLIC
, info
, uri
);
982 static void get_info_ab_entry_response(struct sipe_core_private
*sipe_private
,
984 SIPE_UNUSED_PARAMETER
const gchar
*raw
,
986 gpointer callback_data
)
988 struct ms_dlx_data
*mdd
= callback_data
;
989 struct sipe_backend_buddy_info
*info
= NULL
;
990 gchar
*server_alias
= NULL
;
994 const sipe_xml
*node
;
996 SIPE_DEBUG_INFO("get_info_ab_entry_response: received valid SOAP message from service %s",
999 info
= sipe_backend_buddy_info_start(SIPE_CORE_PUBLIC
);
1001 for (node
= sipe_xml_child(soap_body
, "Body/SearchAbEntryResponse/SearchAbEntryResult/Items/AbEntry/Attributes/Attribute");
1003 node
= sipe_xml_twin(node
)) {
1004 gchar
*name
= sipe_xml_data(sipe_xml_child(node
,
1006 gchar
*value
= sipe_xml_data(sipe_xml_child(node
,
1008 const sipe_xml
*values
= sipe_xml_child(node
,
1011 /* Single value entries */
1012 if (!is_empty(value
)) {
1014 if (sipe_strcase_equal(name
, "displayname")) {
1015 g_free(server_alias
);
1016 server_alias
= value
;
1018 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1020 SIPE_BUDDY_INFO_DISPLAY_NAME
,
1022 } else if (sipe_strcase_equal(name
, "mail")) {
1026 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1028 SIPE_BUDDY_INFO_EMAIL
,
1030 } else if (sipe_strcase_equal(name
, "title")) {
1031 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1033 SIPE_BUDDY_INFO_JOB_TITLE
,
1035 } else if (sipe_strcase_equal(name
, "company")) {
1036 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1038 SIPE_BUDDY_INFO_COMPANY
,
1040 } else if (sipe_strcase_equal(name
, "country")) {
1041 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1043 SIPE_BUDDY_INFO_COUNTRY
,
1047 } else if (values
) {
1048 gchar
*first
= sipe_xml_data(sipe_xml_child(values
,
1051 if (sipe_strcase_equal(name
, "telephonenumber")) {
1052 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1054 SIPE_BUDDY_INFO_WORK_PHONE
,
1066 /* this will show the minmum information */
1067 get_info_finalize(sipe_private
,
1074 g_free(server_alias
);
1078 static gboolean
process_get_info_response(struct sipe_core_private
*sipe_private
,
1080 struct transaction
*trans
)
1082 const gchar
*uri
= trans
->payload
->data
;
1083 struct sipe_backend_buddy_info
*info
= NULL
;
1084 gchar
*server_alias
= NULL
;
1085 gchar
*email
= NULL
;
1087 SIPE_DEBUG_INFO("Fetching %s's user info for %s",
1088 uri
, sipe_private
->username
);
1090 if (msg
->response
!= 200) {
1091 SIPE_DEBUG_INFO("process_get_info_response: SERVICE response is %d", msg
->response
);
1093 sipe_xml
*searchResults
;
1094 const sipe_xml
*mrow
;
1096 SIPE_DEBUG_INFO("process_get_info_response: body:\n%s",
1097 msg
->body
? msg
->body
: "");
1099 searchResults
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1100 if (!searchResults
) {
1102 SIPE_DEBUG_INFO_NOFORMAT("process_get_info_response: no parseable searchResults");
1104 } else if ((mrow
= sipe_xml_child(searchResults
, "Body/Array/row"))) {
1106 gchar
*phone_number
;
1108 info
= sipe_backend_buddy_info_start(SIPE_CORE_PUBLIC
);
1110 server_alias
= g_strdup(sipe_xml_attribute(mrow
, "displayName"));
1111 email
= g_strdup(sipe_xml_attribute(mrow
, "email"));
1112 phone_number
= g_strdup(sipe_xml_attribute(mrow
, "phone"));
1115 * For 2007 system we will take this from ContactCard -
1116 * it has cleaner tel: URIs at least
1118 if (!SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
1119 char *tel_uri
= sip_to_tel_uri(phone_number
);
1120 /* trims its parameters, so call first */
1121 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_DISPLAY_NAME
, server_alias
);
1122 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_EMAIL
, email
);
1123 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_WORK_PHONE
, tel_uri
);
1124 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY
, phone_number
);
1127 sipe_backend_buddy_refresh_properties(SIPE_CORE_PUBLIC
,
1131 if (!is_empty(server_alias
)) {
1132 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1134 SIPE_BUDDY_INFO_DISPLAY_NAME
,
1137 if ((value
= sipe_xml_attribute(mrow
, "title")) && strlen(value
) > 0) {
1138 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1140 SIPE_BUDDY_INFO_JOB_TITLE
,
1143 if ((value
= sipe_xml_attribute(mrow
, "office")) && strlen(value
) > 0) {
1144 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1146 SIPE_BUDDY_INFO_OFFICE
,
1149 if (!is_empty(phone_number
)) {
1150 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1152 SIPE_BUDDY_INFO_WORK_PHONE
,
1155 g_free(phone_number
);
1156 if ((value
= sipe_xml_attribute(mrow
, "company")) && strlen(value
) > 0) {
1157 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1159 SIPE_BUDDY_INFO_COMPANY
,
1162 if ((value
= sipe_xml_attribute(mrow
, "city")) && strlen(value
) > 0) {
1163 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1165 SIPE_BUDDY_INFO_CITY
,
1168 if ((value
= sipe_xml_attribute(mrow
, "state")) && strlen(value
) > 0) {
1169 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1171 SIPE_BUDDY_INFO_STATE
,
1174 if ((value
= sipe_xml_attribute(mrow
, "country")) && strlen(value
) > 0) {
1175 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1177 SIPE_BUDDY_INFO_COUNTRY
,
1180 if (!is_empty(email
)) {
1181 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1183 SIPE_BUDDY_INFO_EMAIL
,
1187 sipe_xml_free(searchResults
);
1190 /* this will show the minmum information */
1191 get_info_finalize(sipe_private
,
1197 g_free(server_alias
);
1203 static void get_info_ab_entry_failed(struct sipe_core_private
*sipe_private
,
1204 struct ms_dlx_data
*mdd
)
1206 /* error using [MS-DLX] server, retry using Active Directory */
1207 gchar
*query
= prepare_buddy_search_query(mdd
->search_rows
, FALSE
);
1208 struct transaction_payload
*payload
= g_new0(struct transaction_payload
, 1);
1210 payload
->destroy
= g_free
;
1211 payload
->data
= mdd
->other
;
1214 sip_soap_directory_search(sipe_private
,
1217 process_get_info_response
,
1224 void sipe_core_buddy_get_info(struct sipe_core_public
*sipe_public
,
1227 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1229 if (sipe_private
->dlx_uri
) {
1230 struct ms_dlx_data
*mdd
= g_new0(struct ms_dlx_data
, 1);
1232 mdd
->search_rows
= g_slist_append(mdd
->search_rows
, g_strdup("msRTCSIP-PrimaryUserAddress"));
1233 mdd
->search_rows
= g_slist_append(mdd
->search_rows
, g_strdup(who
));
1235 mdd
->other
= g_strdup(who
);
1236 mdd
->max_returns
= 1;
1237 mdd
->callback
= get_info_ab_entry_response
;
1238 mdd
->failed_callback
= get_info_ab_entry_failed
;
1239 mdd
->session
= sipe_svc_session_start();
1241 ms_dlx_webticket_request(sipe_private
, mdd
);
1244 /* no [MS-DLX] server, use Active Directory search instead */
1245 gchar
*row
= g_markup_printf_escaped(SIPE_SOAP_SEARCH_ROW
,
1246 "msRTCSIP-PrimaryUserAddress",
1248 struct transaction_payload
*payload
= g_new0(struct transaction_payload
, 1);
1250 SIPE_DEBUG_INFO("sipe_core_buddy_get_info: row: %s",
1253 payload
->destroy
= g_free
;
1254 payload
->data
= g_strdup(who
);
1256 sip_soap_directory_search(sipe_private
,
1259 process_get_info_response
,
1265 static void photo_response_data_free(struct photo_response_data
*data
)
1268 g_free(data
->photo_hash
);
1269 if (data
->request
) {
1270 sipe_http_request_cancel(data
->request
);
1275 static void process_buddy_photo_response(struct sipe_core_private
*sipe_private
,
1281 struct photo_response_data
*rdata
= (struct photo_response_data
*) data
;
1283 rdata
->request
= NULL
;
1285 if (status
== SIPE_HTTP_STATUS_OK
) {
1286 const gchar
*len_str
= sipe_utils_nameval_find(headers
,
1289 gsize photo_size
= atoi(len_str
);
1290 gpointer photo
= g_new(char, photo_size
);
1293 memcpy(photo
, body
, photo_size
);
1295 sipe_backend_buddy_set_photo(SIPE_CORE_PUBLIC
,
1304 sipe_private
->buddies
->pending_photo_requests
=
1305 g_slist_remove(sipe_private
->buddies
->pending_photo_requests
, rdata
);
1307 photo_response_data_free(rdata
);
1310 static gchar
*create_x_ms_webticket_header(const gchar
*wsse_security
)
1312 gchar
*assertion
= sipe_xml_extract_raw(wsse_security
, "saml:Assertion", TRUE
);
1313 gchar
*wsse_security_base64
;
1314 gchar
*x_ms_webticket_header
;
1320 wsse_security_base64
= g_base64_encode((const guchar
*)assertion
,
1322 x_ms_webticket_header
= g_strdup_printf("X-MS-WebTicket: opaque=%s\r\n",
1323 wsse_security_base64
);
1326 g_free(wsse_security_base64
);
1328 return x_ms_webticket_header
;
1331 static void get_photo_ab_entry_response(struct sipe_core_private
*sipe_private
,
1333 SIPE_UNUSED_PARAMETER
const gchar
*raw
,
1334 sipe_xml
*soap_body
,
1335 gpointer callback_data
)
1337 struct ms_dlx_data
*mdd
= callback_data
;
1338 gchar
*photo_rel_path
= NULL
;
1339 gchar
*photo_hash
= NULL
;
1340 const gchar
*photo_hash_old
=
1341 sipe_backend_buddy_get_photo_hash(SIPE_CORE_PUBLIC
, mdd
->other
);
1344 const sipe_xml
*node
;
1346 SIPE_DEBUG_INFO("get_photo_ab_entry_response: received valid SOAP message from service %s",
1349 for (node
= sipe_xml_child(soap_body
, "Body/SearchAbEntryResponse/SearchAbEntryResult/Items/AbEntry/Attributes/Attribute");
1351 node
= sipe_xml_twin(node
)) {
1352 gchar
*name
= sipe_xml_data(sipe_xml_child(node
, "Name"));
1353 gchar
*value
= sipe_xml_data(sipe_xml_child(node
, "Value"));
1355 if (!is_empty(value
)) {
1356 if (sipe_strcase_equal(name
, "PhotoRelPath")) {
1357 g_free(photo_rel_path
);
1358 photo_rel_path
= value
;
1360 } else if (sipe_strcase_equal(name
, "PhotoHash")) {
1372 if (sipe_private
->addressbook_uri
&& photo_rel_path
&&
1373 photo_hash
&& !sipe_strequal(photo_hash
, photo_hash_old
)) {
1374 gchar
*photo_url
= g_strdup_printf("%s/%s",
1375 sipe_private
->addressbook_uri
, photo_rel_path
);
1376 gchar
*x_ms_webticket_header
= create_x_ms_webticket_header(mdd
->wsse_security
);
1378 struct photo_response_data
*data
= g_new(struct photo_response_data
, 1);
1379 data
->who
= g_strdup(mdd
->other
);
1380 data
->photo_hash
= photo_hash
;
1383 data
->request
= sipe_http_request_get(sipe_private
,
1385 x_ms_webticket_header
,
1386 process_buddy_photo_response
,
1389 if (data
->request
) {
1390 sipe_private
->buddies
->pending_photo_requests
=
1391 g_slist_append(sipe_private
->buddies
->pending_photo_requests
, data
);
1392 sipe_http_request_ready(data
->request
);
1394 photo_response_data_free(data
);
1397 g_free(x_ms_webticket_header
);
1401 g_free(photo_rel_path
);
1406 static void get_photo_ab_entry_failed(SIPE_UNUSED_PARAMETER
struct sipe_core_private
*sipe_private
,
1407 struct ms_dlx_data
*mdd
)
1412 static void buddy_fetch_photo(struct sipe_core_private
*sipe_private
,
1415 if (sipe_backend_uses_photo()) {
1417 /* Lync 2013 or newer: use UCS */
1418 if (SIPE_CORE_PRIVATE_FLAG_IS(LYNC2013
)) {
1420 sipe_ucs_get_photo(sipe_private
, uri
);
1422 /* Lync 2010: use [MS-DLX] */
1423 } else if (sipe_private
->dlx_uri
&&
1424 sipe_private
->addressbook_uri
) {
1425 struct ms_dlx_data
*mdd
= g_new0(struct ms_dlx_data
, 1);
1427 mdd
->search_rows
= g_slist_append(mdd
->search_rows
, g_strdup("msRTCSIP-PrimaryUserAddress"));
1428 mdd
->search_rows
= g_slist_append(mdd
->search_rows
, g_strdup(uri
));
1430 mdd
->other
= g_strdup(uri
);
1431 mdd
->max_returns
= 1;
1432 mdd
->callback
= get_photo_ab_entry_response
;
1433 mdd
->failed_callback
= get_photo_ab_entry_failed
;
1434 mdd
->session
= sipe_svc_session_start();
1436 ms_dlx_webticket_request(sipe_private
, mdd
);
1441 static void buddy_refresh_photos_cb(gpointer uri
,
1442 SIPE_UNUSED_PARAMETER gpointer value
,
1443 gpointer sipe_private
)
1445 buddy_fetch_photo(sipe_private
, uri
);
1448 void sipe_buddy_refresh_photos(struct sipe_core_private
*sipe_private
)
1450 g_hash_table_foreach(sipe_private
->buddies
->uri
,
1451 buddy_refresh_photos_cb
,
1455 /* Buddy menu callbacks*/
1457 void sipe_core_buddy_new_chat(struct sipe_core_public
*sipe_public
,
1460 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1462 /* 2007+ conference */
1463 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
1464 sipe_conf_add(sipe_private
, who
);
1466 /* 2005- multiparty chat */
1468 gchar
*self
= sip_uri_self(sipe_private
);
1469 struct sip_session
*session
;
1471 session
= sipe_session_add_chat(sipe_private
,
1475 session
->chat_session
->backend
= sipe_backend_chat_create(SIPE_CORE_PUBLIC
,
1476 session
->chat_session
,
1477 session
->chat_session
->title
,
1481 sipe_im_invite(sipe_private
, session
, who
,
1482 NULL
, NULL
, NULL
, FALSE
);
1486 void sipe_core_buddy_send_email(struct sipe_core_public
*sipe_public
,
1489 sipe_backend_buddy buddy
= sipe_backend_buddy_find(sipe_public
,
1492 gchar
*email
= sipe_backend_buddy_get_string(sipe_public
,
1494 SIPE_BUDDY_INFO_EMAIL
);
1497 gchar
*command_line
= g_strdup_printf(
1503 " mailto:%s", email
);
1506 SIPE_DEBUG_INFO("sipe_core_buddy_send_email: going to call email client: %s",
1508 g_spawn_command_line_async(command_line
, NULL
);
1509 g_free(command_line
);
1512 SIPE_DEBUG_INFO("sipe_core_buddy_send_email: no email address stored for buddy=%s",
1519 static struct sipe_backend_buddy_menu
*buddy_menu_phone(struct sipe_core_public
*sipe_public
,
1520 struct sipe_backend_buddy_menu
*menu
,
1521 sipe_backend_buddy buddy
,
1522 sipe_buddy_info_fields id_phone
,
1523 sipe_buddy_info_fields id_display
,
1526 gchar
*phone
= sipe_backend_buddy_get_string(sipe_public
,
1530 gchar
*display
= sipe_backend_buddy_get_string(sipe_public
,
1534 gchar
*label
= g_strdup_printf("%s %s",
1537 (tmp
= sip_tel_uri_denormalize(phone
)));
1538 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1541 SIPE_BUDDY_MENU_MAKE_CALL
,
1552 struct sipe_backend_buddy_menu
*sipe_core_buddy_create_menu(struct sipe_core_public
*sipe_public
,
1553 const gchar
*buddy_name
,
1554 struct sipe_backend_buddy_menu
*menu
)
1556 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1557 sipe_backend_buddy buddy
= sipe_backend_buddy_find(sipe_public
,
1560 gchar
*self
= sip_uri_self(sipe_private
);
1562 SIPE_SESSION_FOREACH
{
1563 if (!sipe_strcase_equal(self
, buddy_name
) && session
->chat_session
)
1565 struct sipe_chat_session
*chat_session
= session
->chat_session
;
1566 gboolean is_conf
= (chat_session
->type
== SIPE_CHAT_TYPE_CONFERENCE
);
1568 if (sipe_backend_chat_find(chat_session
->backend
, buddy_name
))
1570 gboolean conf_op
= sipe_backend_chat_is_operator(chat_session
->backend
, self
);
1574 !sipe_backend_chat_is_operator(chat_session
->backend
, buddy_name
) &&
1575 /* We are a conf OP */
1577 gchar
*label
= g_strdup_printf(_("Make leader of '%s'"),
1578 chat_session
->title
);
1579 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1582 SIPE_BUDDY_MENU_MAKE_CHAT_LEADER
,
1588 /* We are a conf OP */
1590 gchar
*label
= g_strdup_printf(_("Remove from '%s'"),
1591 chat_session
->title
);
1592 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1595 SIPE_BUDDY_MENU_REMOVE_FROM_CHAT
,
1603 (is_conf
&& !session
->locked
)) {
1604 gchar
*label
= g_strdup_printf(_("Invite to '%s'"),
1605 chat_session
->title
);
1606 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1609 SIPE_BUDDY_MENU_INVITE_TO_CHAT
,
1615 } SIPE_SESSION_FOREACH_END
;
1618 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1621 SIPE_BUDDY_MENU_NEW_CHAT
,
1624 /* add buddy's phone numbers if we have call control */
1625 if (sip_csta_is_idle(sipe_private
)) {
1628 menu
= buddy_menu_phone(sipe_public
,
1631 SIPE_BUDDY_INFO_WORK_PHONE
,
1632 SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY
,
1635 menu
= buddy_menu_phone(sipe_public
,
1638 SIPE_BUDDY_INFO_MOBILE_PHONE
,
1639 SIPE_BUDDY_INFO_MOBILE_PHONE_DISPLAY
,
1643 menu
= buddy_menu_phone(sipe_public
,
1646 SIPE_BUDDY_INFO_HOME_PHONE
,
1647 SIPE_BUDDY_INFO_HOME_PHONE_DISPLAY
,
1651 menu
= buddy_menu_phone(sipe_public
,
1654 SIPE_BUDDY_INFO_OTHER_PHONE
,
1655 SIPE_BUDDY_INFO_OTHER_PHONE_DISPLAY
,
1659 menu
= buddy_menu_phone(sipe_public
,
1662 SIPE_BUDDY_INFO_CUSTOM1_PHONE
,
1663 SIPE_BUDDY_INFO_CUSTOM1_PHONE_DISPLAY
,
1668 gchar
*email
= sipe_backend_buddy_get_string(sipe_public
,
1670 SIPE_BUDDY_INFO_EMAIL
);
1672 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1675 SIPE_BUDDY_MENU_SEND_EMAIL
,
1681 /* access level control */
1682 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
))
1683 menu
= sipe_backend_buddy_sub_menu_add(sipe_public
,
1686 sipe_ocs2007_access_control_menu(sipe_private
,
1692 guint
sipe_buddy_count(struct sipe_core_private
*sipe_private
)
1694 return(g_hash_table_size(sipe_private
->buddies
->uri
));
1697 static guint
sipe_ht_hash_nick(const char *nick
)
1699 char *lc
= g_utf8_strdown(nick
, -1);
1700 guint bucket
= g_str_hash(lc
);
1706 static gboolean
sipe_ht_equals_nick(const char *nick1
, const char *nick2
)
1708 char *nick1_norm
= NULL
;
1709 char *nick2_norm
= NULL
;
1712 if (nick1
== NULL
&& nick2
== NULL
) return TRUE
;
1713 if (nick1
== NULL
|| nick2
== NULL
||
1714 !g_utf8_validate(nick1
, -1, NULL
) ||
1715 !g_utf8_validate(nick2
, -1, NULL
)) return FALSE
;
1717 nick1_norm
= g_utf8_casefold(nick1
, -1);
1718 nick2_norm
= g_utf8_casefold(nick2
, -1);
1719 equal
= g_utf8_collate(nick1_norm
, nick2_norm
) == 0;
1726 void sipe_buddy_init(struct sipe_core_private
*sipe_private
)
1728 struct sipe_buddies
*buddies
= g_new0(struct sipe_buddies
, 1);
1729 buddies
->uri
= g_hash_table_new((GHashFunc
) sipe_ht_hash_nick
,
1730 (GEqualFunc
) sipe_ht_equals_nick
);
1731 sipe_private
->buddies
= buddies
;