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"
61 struct photo_response_data
{
64 struct sipe_http_request
*request
;
67 static void buddy_fetch_photo(struct sipe_core_private
*sipe_private
,
69 static void photo_response_data_free(struct photo_response_data
*data
);
71 struct sipe_buddy
*sipe_buddy_add(struct sipe_core_private
*sipe_private
,
73 const gchar
*exchange_key
)
75 struct sipe_buddy
*buddy
= sipe_buddy_find_by_uri(sipe_private
, uri
);
77 buddy
= g_new0(struct sipe_buddy
, 1);
78 buddy
->name
= g_strdup(uri
);
79 buddy
->exchange_key
= g_strdup(exchange_key
);
80 g_hash_table_insert(sipe_private
->buddies
, buddy
->name
, buddy
);
82 SIPE_DEBUG_INFO("sipe_buddy_add: Added buddy %s", uri
);
84 buddy_fetch_photo(sipe_private
, uri
);
86 SIPE_DEBUG_INFO("sipe_buddy_add: Buddy %s already exists", uri
);
92 struct sipe_buddy
*sipe_buddy_find_by_uri(struct sipe_core_private
*sipe_private
,
95 return(g_hash_table_lookup(sipe_private
->buddies
, uri
));
98 static void buddy_free(struct sipe_buddy
*buddy
)
102 * We are calling g_hash_table_foreach_steal(). That means that no
103 * key/value deallocation functions are called. Therefore the glib
104 * hash code does not touch the key (buddy->name) or value (buddy)
105 * of the to-be-deleted hash node at all. It follows that we
107 * - MUST free the memory for the key ourselves and
108 * - ARE allowed to do it in this function
110 * Conclusion: glib must be broken on the Windows platform if sipe
111 * crashes with SIGTRAP when closing. You'll have to live
112 * with the memory leak until this is fixed.
116 g_free(buddy
->exchange_key
);
117 g_free(buddy
->activity
);
118 g_free(buddy
->meeting_subject
);
119 g_free(buddy
->meeting_location
);
122 g_free(buddy
->cal_start_time
);
123 g_free(buddy
->cal_free_busy_base64
);
124 g_free(buddy
->cal_free_busy
);
125 g_free(buddy
->last_non_cal_activity
);
127 sipe_cal_free_working_hours(buddy
->cal_working_hours
);
129 g_free(buddy
->device_name
);
130 g_slist_free(buddy
->groups
);
134 static gboolean
buddy_free_cb(SIPE_UNUSED_PARAMETER gpointer key
,
136 SIPE_UNUSED_PARAMETER gpointer user_data
)
139 /* We must return TRUE as the key/value have already been deleted */
143 void sipe_buddy_free(struct sipe_core_private
*sipe_private
)
145 g_hash_table_foreach_steal(sipe_private
->buddies
,
149 /* core is being deallocated, remove all its pending photo requests */
150 while (sipe_private
->pending_photo_requests
) {
151 struct photo_response_data
*data
=
152 sipe_private
->pending_photo_requests
->data
;
153 sipe_private
->pending_photo_requests
=
154 g_slist_remove(sipe_private
->pending_photo_requests
, data
);
155 photo_response_data_free(data
);
158 g_hash_table_destroy(sipe_private
->buddies
);
159 sipe_private
->buddies
= NULL
;
162 gchar
*sipe_core_buddy_status(struct sipe_core_public
*sipe_public
,
165 const gchar
*status_text
)
167 struct sipe_buddy
*sbuddy
;
168 const char *activity_str
;
170 if (!sipe_public
) return NULL
; /* happens on pidgin exit */
172 sbuddy
= g_hash_table_lookup(SIPE_CORE_PRIVATE
->buddies
, uri
);
173 if (!sbuddy
) return NULL
;
175 activity_str
= sbuddy
->activity
? sbuddy
->activity
:
176 (activity
== SIPE_ACTIVITY_BUSY
) || (activity
== SIPE_ACTIVITY_BRB
) ?
179 if (activity_str
&& sbuddy
->note
) {
180 return g_strdup_printf("%s - <i>%s</i>", activity_str
, sbuddy
->note
);
181 } else if (activity_str
) {
182 return g_strdup(activity_str
);
183 } else if (sbuddy
->note
) {
184 return g_strdup_printf("<i>%s</i>", sbuddy
->note
);
190 gchar
*sipe_buddy_get_alias(struct sipe_core_private
*sipe_private
,
193 sipe_backend_buddy pbuddy
;
195 if ((pbuddy
= sipe_backend_buddy_find(SIPE_CORE_PUBLIC
, with
, NULL
))) {
196 alias
= sipe_backend_buddy_get_alias(SIPE_CORE_PUBLIC
, pbuddy
);
201 void sipe_core_buddy_group(struct sipe_core_public
*sipe_public
,
203 const gchar
*old_group_name
,
204 const gchar
*new_group_name
)
206 struct sipe_buddy
* buddy
= g_hash_table_lookup(SIPE_CORE_PRIVATE
->buddies
, who
);
207 struct sipe_group
* old_group
= NULL
;
208 struct sipe_group
* new_group
;
210 SIPE_DEBUG_INFO("sipe_core_buddy_group: who:%s old_group_name:%s new_group_name:%s",
211 who
? who
: "", old_group_name
? old_group_name
: "", new_group_name
? new_group_name
: "");
213 if(!buddy
) { // buddy not in roaming list
217 if (old_group_name
) {
218 old_group
= sipe_group_find_by_name(SIPE_CORE_PRIVATE
, old_group_name
);
220 new_group
= sipe_group_find_by_name(SIPE_CORE_PRIVATE
, new_group_name
);
223 buddy
->groups
= g_slist_remove(buddy
->groups
, old_group
);
224 SIPE_DEBUG_INFO("sipe_core_buddy_group: buddy %s removed from old group %s", who
, old_group_name
);
228 sipe_group_create(SIPE_CORE_PRIVATE
, new_group_name
, who
);
230 buddy
->groups
= sipe_utils_slist_insert_unique_sorted(buddy
->groups
,
232 (GCompareFunc
)sipe_group_compare
,
234 sipe_group_update_buddy(SIPE_CORE_PRIVATE
, buddy
);
238 void sipe_core_buddy_add(struct sipe_core_public
*sipe_public
,
240 const gchar
*group_name
)
242 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
244 if (!sipe_buddy_find_by_uri(sipe_private
, uri
)) {
245 struct sipe_buddy
*b
= sipe_buddy_add(sipe_private
, uri
, NULL
);
246 b
->just_added
= TRUE
;
248 sipe_subscribe_presence_single_cb(sipe_private
, b
->name
);
251 SIPE_DEBUG_INFO("sipe_core_buddy_add: buddy %s already in internal list",
255 sipe_core_buddy_group(sipe_public
,
261 void sipe_buddy_remove(struct sipe_core_private
*sipe_private
,
262 struct sipe_buddy
*buddy
)
264 gchar
*action_name
= sipe_utils_presence_key(buddy
->name
);
265 sipe_schedule_cancel(sipe_private
, action_name
);
268 g_hash_table_remove(sipe_private
->buddies
, buddy
->name
);
274 * Unassociates buddy from group first.
275 * Then see if no groups left, removes buddy completely.
276 * Otherwise updates buddy groups on server.
278 void sipe_core_buddy_remove(struct sipe_core_public
*sipe_public
,
280 const gchar
*group_name
)
282 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
283 struct sipe_buddy
*b
= sipe_buddy_find_by_uri(sipe_private
,
289 struct sipe_group
*g
= sipe_group_find_by_name(sipe_private
,
292 b
->groups
= g_slist_remove(b
->groups
, g
);
293 SIPE_DEBUG_INFO("sipe_core_buddy_remove: buddy %s removed from group %s",
298 if (g_slist_length(b
->groups
) < 1) {
299 gchar
*request
= g_strdup_printf("<m:URI>%s</m:URI>",
301 sip_soap_request(sipe_private
,
305 sipe_buddy_remove(sipe_private
, b
);
307 /* updates groups on server */
308 sipe_group_update_buddy(sipe_private
, b
);
313 void sipe_core_buddy_got_status(struct sipe_core_public
*sipe_public
,
317 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
318 struct sipe_buddy
*sbuddy
= sipe_buddy_find_by_uri(sipe_private
,
323 /* Check if on 2005 system contact's calendar,
324 * then set/preserve it.
326 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
327 sipe_backend_buddy_set_status(sipe_public
, uri
, activity
);
329 sipe_ocs2005_apply_calendar_status(sipe_private
,
331 sipe_status_activity_to_token(activity
));
335 void sipe_core_buddy_tooltip_info(struct sipe_core_public
*sipe_public
,
337 const gchar
*status_name
,
339 struct sipe_backend_buddy_tooltip
*tooltip
)
341 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
343 gboolean is_oof_note
= FALSE
;
344 const gchar
*activity
= NULL
;
345 gchar
*calendar
= NULL
;
346 const gchar
*meeting_subject
= NULL
;
347 const gchar
*meeting_location
= NULL
;
348 gchar
*access_text
= NULL
;
350 #define SIPE_ADD_BUDDY_INFO(l, t) \
352 gchar *tmp = g_markup_escape_text((t), -1); \
353 sipe_backend_buddy_tooltip_add(sipe_public, tooltip, (l), tmp); \
356 #define SIPE_ADD_BUDDY_INFO_NOESCAPE(l, t) \
357 sipe_backend_buddy_tooltip_add(sipe_public, tooltip, (l), (t))
359 if (sipe_public
) { /* happens on pidgin exit */
360 struct sipe_buddy
*sbuddy
= sipe_buddy_find_by_uri(sipe_private
,
364 is_oof_note
= sbuddy
->is_oof_note
;
365 activity
= sbuddy
->activity
;
366 calendar
= sipe_cal_get_description(sbuddy
);
367 meeting_subject
= sbuddy
->meeting_subject
;
368 meeting_location
= sbuddy
->meeting_location
;
370 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
371 gboolean is_group_access
= FALSE
;
372 const int container_id
= sipe_ocs2007_find_access_level(sipe_private
,
374 sipe_get_no_sip_uri(uri
),
376 const char *access_level
= sipe_ocs2007_access_level_name(container_id
);
377 access_text
= is_group_access
?
378 g_strdup(access_level
) :
379 g_strdup_printf(SIPE_OCS2007_INDENT_MARKED_FMT
,
385 const gchar
*status_str
= activity
? activity
: status_name
;
387 SIPE_ADD_BUDDY_INFO(_("Status"), status_str
);
389 if (is_online
&& !is_empty(calendar
)) {
390 SIPE_ADD_BUDDY_INFO(_("Calendar"), calendar
);
393 if (!is_empty(meeting_location
)) {
394 SIPE_DEBUG_INFO("sipe_tooltip_text: %s meeting location: '%s'", uri
, meeting_location
);
395 SIPE_ADD_BUDDY_INFO(_("Meeting in"), meeting_location
);
397 if (!is_empty(meeting_subject
)) {
398 SIPE_DEBUG_INFO("sipe_tooltip_text: %s meeting subject: '%s'", uri
, meeting_subject
);
399 SIPE_ADD_BUDDY_INFO(_("Meeting about"), meeting_subject
);
402 gchar
*note_italics
= g_strdup_printf("<i>%s</i>", note
);
403 SIPE_DEBUG_INFO("sipe_tooltip_text: %s note: '%s'", uri
, note
);
404 SIPE_ADD_BUDDY_INFO_NOESCAPE(is_oof_note
? _("Out of office note") : _("Note"),
406 g_free(note_italics
);
409 SIPE_ADD_BUDDY_INFO(_("Access level"), access_text
);
414 void sipe_buddy_update_property(struct sipe_core_private
*sipe_private
,
416 sipe_buddy_info_fields propkey
,
417 char *property_value
)
419 GSList
*buddies
, *entry
;
422 property_value
= g_strstrip(property_value
);
424 entry
= buddies
= sipe_backend_buddy_find_all(SIPE_CORE_PUBLIC
, uri
, NULL
); /* all buddies in different groups */
427 sipe_backend_buddy p_buddy
= entry
->data
;
429 /* for Display Name */
430 if (propkey
== SIPE_BUDDY_INFO_DISPLAY_NAME
) {
432 alias
= sipe_backend_buddy_get_alias(SIPE_CORE_PUBLIC
, p_buddy
);
433 if (property_value
&& sipe_is_bad_alias(uri
, alias
)) {
434 SIPE_DEBUG_INFO("Replacing alias for %s with %s", uri
, property_value
);
435 sipe_backend_buddy_set_alias(SIPE_CORE_PUBLIC
, p_buddy
, property_value
);
439 alias
= sipe_backend_buddy_get_server_alias(SIPE_CORE_PUBLIC
, p_buddy
);
440 if (!is_empty(property_value
) &&
441 (!sipe_strequal(property_value
, alias
) || is_empty(alias
)) )
443 SIPE_DEBUG_INFO("Replacing service alias for %s with %s", uri
, property_value
);
444 sipe_backend_buddy_set_server_alias(SIPE_CORE_PUBLIC
, p_buddy
, property_value
);
448 /* for other properties */
450 if (!is_empty(property_value
)) {
451 prop_str
= sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC
, p_buddy
, propkey
);
452 if (!prop_str
|| !sipe_strcase_equal(prop_str
, property_value
)) {
453 sipe_backend_buddy_set_string(SIPE_CORE_PUBLIC
, p_buddy
, propkey
, property_value
);
461 g_slist_free(buddies
);
470 sipe_svc_callback
*callback
;
471 struct sipe_svc_session
*session
;
472 gchar
*wsse_security
;
473 struct sipe_backend_search_token
*token
;
474 /* must call ms_dlx_free() */
475 void (*failed_callback
)(struct sipe_core_private
*sipe_private
,
476 struct ms_dlx_data
*mdd
);
479 static void ms_dlx_free(struct ms_dlx_data
*mdd
)
481 sipe_utils_slist_free_full(mdd
->search_rows
, g_free
);
482 sipe_svc_session_close(mdd
->session
);
484 g_free(mdd
->wsse_security
);
488 #define SIPE_SOAP_SEARCH_ROW "<m:row m:attrib=\"%s\" m:value=\"%s\"/>"
489 #define DLX_SEARCH_ITEM \
490 "<AbEntryRequest.ChangeSearchQuery>" \
491 " <SearchOn>%s</SearchOn>" \
492 " <Value>%s</Value>" \
493 "</AbEntryRequest.ChangeSearchQuery>"
495 static gchar
* prepare_buddy_search_query(GSList
*query_rows
, gboolean use_dlx
) {
496 gchar
**attrs
= g_new(gchar
*, (g_slist_length(query_rows
) / 2) + 1);
504 attr
= query_rows
->data
;
505 query_rows
= g_slist_next(query_rows
);
506 value
= query_rows
->data
;
507 query_rows
= g_slist_next(query_rows
);
512 attrs
[i
++] = g_markup_printf_escaped(use_dlx
? DLX_SEARCH_ITEM
: SIPE_SOAP_SEARCH_ROW
,
518 query
= g_strjoinv(NULL
, attrs
);
519 SIPE_DEBUG_INFO("prepare_buddy_search_query: rows:\n%s",
528 static void ms_dlx_webticket(struct sipe_core_private
*sipe_private
,
529 const gchar
*base_uri
,
530 const gchar
*auth_uri
,
531 const gchar
*wsse_security
,
532 SIPE_UNUSED_PARAMETER
const gchar
*failure_msg
,
533 gpointer callback_data
)
535 struct ms_dlx_data
*mdd
= callback_data
;
538 gchar
*query
= prepare_buddy_search_query(mdd
->search_rows
, TRUE
);
540 SIPE_DEBUG_INFO("ms_dlx_webticket: got ticket for %s",
543 if (sipe_svc_ab_entry_request(sipe_private
,
548 g_slist_length(mdd
->search_rows
) / 2,
553 /* keep webticket security token for potential further use */
554 mdd
->wsse_security
= g_strdup(wsse_security
);
556 /* callback data passed down the line */
562 /* no ticket: this will show the minmum information */
563 SIPE_DEBUG_ERROR("ms_dlx_webticket: no web ticket for %s",
568 mdd
->failed_callback(sipe_private
, mdd
);
571 static void ms_dlx_webticket_request(struct sipe_core_private
*sipe_private
,
572 struct ms_dlx_data
*mdd
)
574 if (!sipe_webticket_request(sipe_private
,
576 sipe_private
->dlx_uri
,
577 "AddressBookWebTicketBearer",
580 SIPE_DEBUG_ERROR("ms_dlx_webticket_request: couldn't request webticket for %s",
581 sipe_private
->dlx_uri
);
582 mdd
->failed_callback(sipe_private
, mdd
);
586 static void search_contacts_finalize(struct sipe_core_private
*sipe_private
,
587 struct sipe_backend_search_results
*results
,
591 gchar
*secondary
= g_strdup_printf(
592 dngettext(PACKAGE_NAME
,
593 "Found %d contact%s:",
594 "Found %d contacts%s:", match_count
),
595 match_count
, more
? _(" (more matched your query)") : "");
597 sipe_backend_search_results_finalize(SIPE_CORE_PUBLIC
,
604 static void search_ab_entry_response(struct sipe_core_private
*sipe_private
,
606 SIPE_UNUSED_PARAMETER
const gchar
*raw
,
608 gpointer callback_data
)
610 struct ms_dlx_data
*mdd
= callback_data
;
613 const sipe_xml
*node
;
614 struct sipe_backend_search_results
*results
;
617 SIPE_DEBUG_INFO("search_ab_entry_response: received valid SOAP message from service %s",
621 node
= sipe_xml_child(soap_body
, "Body/SearchAbEntryResponse/SearchAbEntryResult/Items/AbEntry");
623 SIPE_DEBUG_ERROR_NOFORMAT("search_ab_entry_response: no matches");
624 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
626 _("No contacts found"));
631 /* OK, we found something - show the results to the user */
632 results
= sipe_backend_search_results_start(SIPE_CORE_PUBLIC
,
635 SIPE_DEBUG_ERROR_NOFORMAT("search_ab_entry_response: Unable to display the search results.");
636 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
638 _("Unable to display the search results"));
643 /* SearchAbEntryResult can contain duplicates */
644 found
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
647 for (/* initialized above */ ; node
; node
= sipe_xml_twin(node
)) {
648 const sipe_xml
*attrs
;
649 gchar
*sip_uri
= NULL
;
650 gchar
*displayname
= NULL
;
651 gchar
*company
= NULL
;
652 gchar
*country
= NULL
;
655 for (attrs
= sipe_xml_child(node
, "Attributes/Attribute");
657 attrs
= sipe_xml_twin(attrs
)) {
658 gchar
*name
= sipe_xml_data(sipe_xml_child(attrs
,
660 gchar
*value
= sipe_xml_data(sipe_xml_child(attrs
,
663 if (!is_empty(value
)) {
664 if (sipe_strcase_equal(name
, "msrtcsip-primaryuseraddress")) {
668 } else if (sipe_strcase_equal(name
, "displayname")) {
672 } else if (sipe_strcase_equal(name
, "mail")) {
676 } else if (sipe_strcase_equal(name
, "company")) {
680 } else if (sipe_strcase_equal(name
, "country")) {
691 if (sip_uri
&& !g_hash_table_lookup(found
, sip_uri
)) {
692 gchar
**uri_parts
= g_strsplit(sip_uri
, ":", 2);
693 sipe_backend_search_results_add(SIPE_CORE_PUBLIC
,
700 g_strfreev(uri_parts
);
702 g_hash_table_insert(found
, sip_uri
, (gpointer
) TRUE
);
713 search_contacts_finalize(sipe_private
, results
,
714 g_hash_table_size(found
),
716 g_hash_table_destroy(found
);
720 mdd
->failed_callback(sipe_private
, mdd
);
724 static gboolean
process_search_contact_response(struct sipe_core_private
*sipe_private
,
726 struct transaction
*trans
)
728 struct sipe_backend_search_token
*token
= trans
->payload
->data
;
729 struct sipe_backend_search_results
*results
;
730 sipe_xml
*searchResults
;
731 const sipe_xml
*mrow
;
732 guint match_count
= 0;
733 gboolean more
= FALSE
;
735 /* valid response? */
736 if (msg
->response
!= 200) {
737 SIPE_DEBUG_ERROR("process_search_contact_response: request failed (%d)",
739 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
741 _("Contact search failed"));
745 SIPE_DEBUG_INFO("process_search_contact_response: body:\n%s", msg
->body
? msg
->body
: "");
748 searchResults
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
749 if (!searchResults
) {
750 SIPE_DEBUG_INFO_NOFORMAT("process_search_contact_response: no parseable searchResults");
751 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
753 _("Contact search failed"));
758 mrow
= sipe_xml_child(searchResults
, "Body/Array/row");
760 SIPE_DEBUG_ERROR_NOFORMAT("process_search_contact_response: no matches");
761 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
763 _("No contacts found"));
765 sipe_xml_free(searchResults
);
769 /* OK, we found something - show the results to the user */
770 results
= sipe_backend_search_results_start(SIPE_CORE_PUBLIC
,
771 trans
->payload
->data
);
773 SIPE_DEBUG_ERROR_NOFORMAT("process_search_contact_response: Unable to display the search results.");
774 sipe_backend_search_failed(SIPE_CORE_PUBLIC
,
776 _("Unable to display the search results"));
778 sipe_xml_free(searchResults
);
782 for (/* initialized above */ ; mrow
; mrow
= sipe_xml_twin(mrow
)) {
783 gchar
**uri_parts
= g_strsplit(sipe_xml_attribute(mrow
, "uri"), ":", 2);
784 sipe_backend_search_results_add(SIPE_CORE_PUBLIC
,
787 sipe_xml_attribute(mrow
, "displayName"),
788 sipe_xml_attribute(mrow
, "company"),
789 sipe_xml_attribute(mrow
, "country"),
790 sipe_xml_attribute(mrow
, "email"));
791 g_strfreev(uri_parts
);
795 if ((mrow
= sipe_xml_child(searchResults
, "Body/directorySearch/moreAvailable")) != NULL
) {
796 char *data
= sipe_xml_data(mrow
);
797 more
= (g_ascii_strcasecmp(data
, "true") == 0);
801 search_contacts_finalize(sipe_private
, results
, match_count
, more
);
802 sipe_xml_free(searchResults
);
807 static void search_soap_request(struct sipe_core_private
*sipe_private
,
808 struct sipe_backend_search_token
*token
,
811 gchar
*query
= prepare_buddy_search_query(search_rows
, FALSE
);
812 struct transaction_payload
*payload
= g_new0(struct transaction_payload
, 1);
814 payload
->data
= token
;
816 sip_soap_directory_search(sipe_private
,
819 process_search_contact_response
,
824 static void search_ab_entry_failed(struct sipe_core_private
*sipe_private
,
825 struct ms_dlx_data
*mdd
)
827 /* error using [MS-DLX] server, retry using Active Directory */
828 search_soap_request(sipe_private
, mdd
->token
, mdd
->search_rows
);
832 void sipe_core_buddy_search(struct sipe_core_public
*sipe_public
,
833 struct sipe_backend_search_token
*token
,
834 const gchar
*given_name
,
835 const gchar
*surname
,
837 const gchar
*company
,
838 const gchar
*country
)
840 GSList
*query_rows
= NULL
;
842 #define ADD_QUERY_ROW(attr, val) \
844 query_rows = g_slist_append(query_rows, g_strdup(attr)); \
845 query_rows = g_slist_append(query_rows, g_strdup(val)); \
848 ADD_QUERY_ROW("givenName", given_name
);
849 ADD_QUERY_ROW("sn", surname
);
850 ADD_QUERY_ROW("mail", email
);
851 ADD_QUERY_ROW("company", company
);
852 ADD_QUERY_ROW("c", country
);
855 if (SIPE_CORE_PRIVATE
->dlx_uri
!= NULL
) {
856 struct ms_dlx_data
*mdd
= g_new0(struct ms_dlx_data
, 1);
858 mdd
->search_rows
= query_rows
;
859 mdd
->max_returns
= 100;
860 mdd
->callback
= search_ab_entry_response
;
861 mdd
->failed_callback
= search_ab_entry_failed
;
862 mdd
->session
= sipe_svc_session_start();
865 ms_dlx_webticket_request(SIPE_CORE_PRIVATE
, mdd
);
868 /* no [MS-DLX] server, use Active Directory search instead */
869 search_soap_request(SIPE_CORE_PRIVATE
, token
, query_rows
);
870 sipe_utils_slist_free_full(query_rows
, g_free
);
873 sipe_backend_search_failed(sipe_public
,
875 _("Invalid contact search query"));
878 static void get_info_finalize(struct sipe_core_private
*sipe_private
,
879 struct sipe_backend_buddy_info
*info
,
881 const gchar
*server_alias
,
884 sipe_backend_buddy bbuddy
;
885 struct sipe_buddy
*sbuddy
;
890 info
= sipe_backend_buddy_info_start(SIPE_CORE_PUBLIC
);
892 sipe_backend_buddy_info_break(SIPE_CORE_PUBLIC
, info
);
897 bbuddy
= sipe_backend_buddy_find(SIPE_CORE_PUBLIC
, uri
, NULL
);
899 if (is_empty(server_alias
)) {
900 value
= sipe_backend_buddy_get_server_alias(SIPE_CORE_PUBLIC
,
903 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
905 SIPE_BUDDY_INFO_DISPLAY_NAME
,
909 value
= g_strdup(server_alias
);
912 /* present alias if it differs from server alias */
913 alias
= sipe_backend_buddy_get_local_alias(SIPE_CORE_PUBLIC
, bbuddy
);
914 if (alias
&& !sipe_strequal(alias
, value
))
916 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
918 SIPE_BUDDY_INFO_ALIAS
,
924 if (is_empty(email
)) {
925 value
= sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC
,
927 SIPE_BUDDY_INFO_EMAIL
);
929 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
931 SIPE_BUDDY_INFO_EMAIL
,
937 value
= sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC
,
939 SIPE_BUDDY_INFO_SITE
);
941 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
943 SIPE_BUDDY_INFO_SITE
,
948 sbuddy
= sipe_buddy_find_by_uri(sipe_private
, uri
);
949 if (sbuddy
&& sbuddy
->device_name
) {
950 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
952 SIPE_BUDDY_INFO_DEVICE
,
953 sbuddy
->device_name
);
956 sipe_backend_buddy_info_finalize(SIPE_CORE_PUBLIC
, info
, uri
);
960 static void get_info_ab_entry_response(struct sipe_core_private
*sipe_private
,
962 SIPE_UNUSED_PARAMETER
const gchar
*raw
,
964 gpointer callback_data
)
966 struct ms_dlx_data
*mdd
= callback_data
;
967 struct sipe_backend_buddy_info
*info
= NULL
;
968 gchar
*server_alias
= NULL
;
972 const sipe_xml
*node
;
974 SIPE_DEBUG_INFO("get_info_ab_entry_response: received valid SOAP message from service %s",
977 info
= sipe_backend_buddy_info_start(SIPE_CORE_PUBLIC
);
979 for (node
= sipe_xml_child(soap_body
, "Body/SearchAbEntryResponse/SearchAbEntryResult/Items/AbEntry/Attributes/Attribute");
981 node
= sipe_xml_twin(node
)) {
982 gchar
*name
= sipe_xml_data(sipe_xml_child(node
,
984 gchar
*value
= sipe_xml_data(sipe_xml_child(node
,
986 const sipe_xml
*values
= sipe_xml_child(node
,
989 /* Single value entries */
990 if (!is_empty(value
)) {
992 if (sipe_strcase_equal(name
, "displayname")) {
993 g_free(server_alias
);
994 server_alias
= value
;
996 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
998 SIPE_BUDDY_INFO_DISPLAY_NAME
,
1000 } else if (sipe_strcase_equal(name
, "mail")) {
1004 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1006 SIPE_BUDDY_INFO_EMAIL
,
1008 } else if (sipe_strcase_equal(name
, "title")) {
1009 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1011 SIPE_BUDDY_INFO_JOB_TITLE
,
1013 } else if (sipe_strcase_equal(name
, "company")) {
1014 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1016 SIPE_BUDDY_INFO_COMPANY
,
1018 } else if (sipe_strcase_equal(name
, "country")) {
1019 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1021 SIPE_BUDDY_INFO_COUNTRY
,
1025 } else if (values
) {
1026 gchar
*first
= sipe_xml_data(sipe_xml_child(values
,
1029 if (sipe_strcase_equal(name
, "telephonenumber")) {
1030 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1032 SIPE_BUDDY_INFO_WORK_PHONE
,
1044 /* this will show the minmum information */
1045 get_info_finalize(sipe_private
,
1052 g_free(server_alias
);
1056 static gboolean
process_get_info_response(struct sipe_core_private
*sipe_private
,
1058 struct transaction
*trans
)
1060 const gchar
*uri
= trans
->payload
->data
;
1061 struct sipe_backend_buddy_info
*info
= NULL
;
1062 gchar
*server_alias
= NULL
;
1063 gchar
*email
= NULL
;
1065 SIPE_DEBUG_INFO("Fetching %s's user info for %s",
1066 uri
, sipe_private
->username
);
1068 if (msg
->response
!= 200) {
1069 SIPE_DEBUG_INFO("process_get_info_response: SERVICE response is %d", msg
->response
);
1071 sipe_xml
*searchResults
;
1072 const sipe_xml
*mrow
;
1074 SIPE_DEBUG_INFO("process_get_info_response: body:\n%s",
1075 msg
->body
? msg
->body
: "");
1077 searchResults
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
1078 if (!searchResults
) {
1080 SIPE_DEBUG_INFO_NOFORMAT("process_get_info_response: no parseable searchResults");
1082 } else if ((mrow
= sipe_xml_child(searchResults
, "Body/Array/row"))) {
1084 gchar
*phone_number
;
1086 info
= sipe_backend_buddy_info_start(SIPE_CORE_PUBLIC
);
1088 server_alias
= g_strdup(sipe_xml_attribute(mrow
, "displayName"));
1089 email
= g_strdup(sipe_xml_attribute(mrow
, "email"));
1090 phone_number
= g_strdup(sipe_xml_attribute(mrow
, "phone"));
1093 * For 2007 system we will take this from ContactCard -
1094 * it has cleaner tel: URIs at least
1096 if (!SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
1097 char *tel_uri
= sip_to_tel_uri(phone_number
);
1098 /* trims its parameters, so call first */
1099 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_DISPLAY_NAME
, server_alias
);
1100 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_EMAIL
, email
);
1101 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_WORK_PHONE
, tel_uri
);
1102 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY
, phone_number
);
1105 sipe_backend_buddy_refresh_properties(SIPE_CORE_PUBLIC
,
1109 if (!is_empty(server_alias
)) {
1110 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1112 SIPE_BUDDY_INFO_DISPLAY_NAME
,
1115 if ((value
= sipe_xml_attribute(mrow
, "title")) && strlen(value
) > 0) {
1116 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1118 SIPE_BUDDY_INFO_JOB_TITLE
,
1121 if ((value
= sipe_xml_attribute(mrow
, "office")) && strlen(value
) > 0) {
1122 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1124 SIPE_BUDDY_INFO_OFFICE
,
1127 if (!is_empty(phone_number
)) {
1128 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1130 SIPE_BUDDY_INFO_WORK_PHONE
,
1133 g_free(phone_number
);
1134 if ((value
= sipe_xml_attribute(mrow
, "company")) && strlen(value
) > 0) {
1135 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1137 SIPE_BUDDY_INFO_COMPANY
,
1140 if ((value
= sipe_xml_attribute(mrow
, "city")) && strlen(value
) > 0) {
1141 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1143 SIPE_BUDDY_INFO_CITY
,
1146 if ((value
= sipe_xml_attribute(mrow
, "state")) && strlen(value
) > 0) {
1147 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1149 SIPE_BUDDY_INFO_STATE
,
1152 if ((value
= sipe_xml_attribute(mrow
, "country")) && strlen(value
) > 0) {
1153 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1155 SIPE_BUDDY_INFO_COUNTRY
,
1158 if (!is_empty(email
)) {
1159 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1161 SIPE_BUDDY_INFO_EMAIL
,
1165 sipe_xml_free(searchResults
);
1168 /* this will show the minmum information */
1169 get_info_finalize(sipe_private
,
1175 g_free(server_alias
);
1181 static void get_info_ab_entry_failed(struct sipe_core_private
*sipe_private
,
1182 struct ms_dlx_data
*mdd
)
1184 /* error using [MS-DLX] server, retry using Active Directory */
1185 gchar
*query
= prepare_buddy_search_query(mdd
->search_rows
, FALSE
);
1186 struct transaction_payload
*payload
= g_new0(struct transaction_payload
, 1);
1188 payload
->destroy
= g_free
;
1189 payload
->data
= mdd
->other
;
1192 sip_soap_directory_search(sipe_private
,
1195 process_get_info_response
,
1202 void sipe_core_buddy_get_info(struct sipe_core_public
*sipe_public
,
1205 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1207 if (sipe_private
->dlx_uri
) {
1208 struct ms_dlx_data
*mdd
= g_new0(struct ms_dlx_data
, 1);
1210 mdd
->search_rows
= g_slist_append(mdd
->search_rows
, g_strdup("msRTCSIP-PrimaryUserAddress"));
1211 mdd
->search_rows
= g_slist_append(mdd
->search_rows
, g_strdup(who
));
1213 mdd
->other
= g_strdup(who
);
1214 mdd
->max_returns
= 1;
1215 mdd
->callback
= get_info_ab_entry_response
;
1216 mdd
->failed_callback
= get_info_ab_entry_failed
;
1217 mdd
->session
= sipe_svc_session_start();
1219 ms_dlx_webticket_request(sipe_private
, mdd
);
1222 /* no [MS-DLX] server, use Active Directory search instead */
1223 gchar
*row
= g_markup_printf_escaped(SIPE_SOAP_SEARCH_ROW
,
1224 "msRTCSIP-PrimaryUserAddress",
1226 struct transaction_payload
*payload
= g_new0(struct transaction_payload
, 1);
1228 SIPE_DEBUG_INFO("sipe_core_buddy_get_info: row: %s",
1231 payload
->destroy
= g_free
;
1232 payload
->data
= g_strdup(who
);
1234 sip_soap_directory_search(sipe_private
,
1237 process_get_info_response
,
1243 static void photo_response_data_free(struct photo_response_data
*data
)
1246 g_free(data
->photo_hash
);
1247 if (data
->request
) {
1248 sipe_http_request_cancel(data
->request
);
1253 static void process_buddy_photo_response(struct sipe_core_private
*sipe_private
,
1259 struct photo_response_data
*rdata
= (struct photo_response_data
*) data
;
1261 rdata
->request
= NULL
;
1263 if (status
== SIPE_HTTP_STATUS_OK
) {
1264 const gchar
*len_str
= sipe_utils_nameval_find(headers
,
1267 gsize photo_size
= atoi(len_str
);
1268 gpointer photo
= g_new(char, photo_size
);
1271 memcpy(photo
, body
, photo_size
);
1273 sipe_backend_buddy_set_photo(SIPE_CORE_PUBLIC
,
1282 sipe_private
->pending_photo_requests
=
1283 g_slist_remove(sipe_private
->pending_photo_requests
, rdata
);
1285 photo_response_data_free(rdata
);
1288 static gchar
*create_x_ms_webticket_header(const gchar
*wsse_security
)
1290 gchar
*assertion
= sipe_xml_extract_raw(wsse_security
, "saml:Assertion", TRUE
);
1291 gchar
*wsse_security_base64
;
1292 gchar
*x_ms_webticket_header
;
1298 wsse_security_base64
= g_base64_encode((const guchar
*)assertion
,
1300 x_ms_webticket_header
= g_strdup_printf("X-MS-WebTicket: opaque=%s\r\n",
1301 wsse_security_base64
);
1304 g_free(wsse_security_base64
);
1306 return x_ms_webticket_header
;
1309 static void get_photo_ab_entry_response(struct sipe_core_private
*sipe_private
,
1311 SIPE_UNUSED_PARAMETER
const gchar
*raw
,
1312 sipe_xml
*soap_body
,
1313 gpointer callback_data
)
1315 struct ms_dlx_data
*mdd
= callback_data
;
1316 gchar
*photo_rel_path
= NULL
;
1317 gchar
*photo_hash
= NULL
;
1318 const gchar
*photo_hash_old
=
1319 sipe_backend_buddy_get_photo_hash(SIPE_CORE_PUBLIC
, mdd
->other
);
1322 const sipe_xml
*node
;
1324 SIPE_DEBUG_INFO("get_photo_ab_entry_response: received valid SOAP message from service %s",
1327 for (node
= sipe_xml_child(soap_body
, "Body/SearchAbEntryResponse/SearchAbEntryResult/Items/AbEntry/Attributes/Attribute");
1329 node
= sipe_xml_twin(node
)) {
1330 gchar
*name
= sipe_xml_data(sipe_xml_child(node
, "Name"));
1331 gchar
*value
= sipe_xml_data(sipe_xml_child(node
, "Value"));
1333 if (!is_empty(value
)) {
1334 if (sipe_strcase_equal(name
, "PhotoRelPath")) {
1335 g_free(photo_rel_path
);
1336 photo_rel_path
= value
;
1338 } else if (sipe_strcase_equal(name
, "PhotoHash")) {
1350 if (sipe_private
->addressbook_uri
&& photo_rel_path
&&
1351 photo_hash
&& !sipe_strequal(photo_hash
, photo_hash_old
)) {
1352 gchar
*photo_url
= g_strdup_printf("%s/%s",
1353 sipe_private
->addressbook_uri
, photo_rel_path
);
1354 gchar
*x_ms_webticket_header
= create_x_ms_webticket_header(mdd
->wsse_security
);
1356 struct photo_response_data
*data
= g_new(struct photo_response_data
, 1);
1357 data
->who
= g_strdup(mdd
->other
);
1358 data
->photo_hash
= photo_hash
;
1361 data
->request
= sipe_http_request_get(sipe_private
,
1363 x_ms_webticket_header
,
1364 process_buddy_photo_response
,
1367 if (data
->request
) {
1368 sipe_private
->pending_photo_requests
=
1369 g_slist_append(sipe_private
->pending_photo_requests
, data
);
1370 sipe_http_request_ready(data
->request
);
1372 photo_response_data_free(data
);
1375 g_free(x_ms_webticket_header
);
1379 g_free(photo_rel_path
);
1384 static void get_photo_ab_entry_failed(SIPE_UNUSED_PARAMETER
struct sipe_core_private
*sipe_private
,
1385 struct ms_dlx_data
*mdd
)
1390 static void buddy_fetch_photo(struct sipe_core_private
*sipe_private
,
1393 if (sipe_backend_uses_photo()) {
1395 /* Lync 2013 or newer: use UCS */
1396 if (SIPE_CORE_PRIVATE_FLAG_IS(LYNC2013
)) {
1398 sipe_ucs_get_photo(sipe_private
, uri
);
1400 /* Lync 2010: use [MS-DLX] */
1401 } else if (sipe_private
->dlx_uri
&&
1402 sipe_private
->addressbook_uri
) {
1403 struct ms_dlx_data
*mdd
= g_new0(struct ms_dlx_data
, 1);
1405 mdd
->search_rows
= g_slist_append(mdd
->search_rows
, g_strdup("msRTCSIP-PrimaryUserAddress"));
1406 mdd
->search_rows
= g_slist_append(mdd
->search_rows
, g_strdup(uri
));
1408 mdd
->other
= g_strdup(uri
);
1409 mdd
->max_returns
= 1;
1410 mdd
->callback
= get_photo_ab_entry_response
;
1411 mdd
->failed_callback
= get_photo_ab_entry_failed
;
1412 mdd
->session
= sipe_svc_session_start();
1414 ms_dlx_webticket_request(sipe_private
, mdd
);
1419 static void buddy_refresh_photos_cb(gpointer uri
,
1420 SIPE_UNUSED_PARAMETER gpointer value
,
1421 gpointer sipe_private
)
1423 buddy_fetch_photo(sipe_private
, uri
);
1426 void sipe_buddy_refresh_photos(struct sipe_core_private
*sipe_private
)
1428 g_hash_table_foreach(sipe_private
->buddies
,
1429 buddy_refresh_photos_cb
,
1433 /* Buddy menu callbacks*/
1435 void sipe_core_buddy_new_chat(struct sipe_core_public
*sipe_public
,
1438 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1440 /* 2007+ conference */
1441 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
1442 sipe_conf_add(sipe_private
, who
);
1444 /* 2005- multiparty chat */
1446 gchar
*self
= sip_uri_self(sipe_private
);
1447 struct sip_session
*session
;
1449 session
= sipe_session_add_chat(sipe_private
,
1453 session
->chat_session
->backend
= sipe_backend_chat_create(SIPE_CORE_PUBLIC
,
1454 session
->chat_session
,
1455 session
->chat_session
->title
,
1459 sipe_im_invite(sipe_private
, session
, who
,
1460 NULL
, NULL
, NULL
, FALSE
);
1464 void sipe_core_buddy_send_email(struct sipe_core_public
*sipe_public
,
1467 sipe_backend_buddy buddy
= sipe_backend_buddy_find(sipe_public
,
1470 gchar
*email
= sipe_backend_buddy_get_string(sipe_public
,
1472 SIPE_BUDDY_INFO_EMAIL
);
1475 gchar
*command_line
= g_strdup_printf(
1481 " mailto:%s", email
);
1484 SIPE_DEBUG_INFO("sipe_core_buddy_send_email: going to call email client: %s",
1486 g_spawn_command_line_async(command_line
, NULL
);
1487 g_free(command_line
);
1490 SIPE_DEBUG_INFO("sipe_core_buddy_send_email: no email address stored for buddy=%s",
1497 static struct sipe_backend_buddy_menu
*buddy_menu_phone(struct sipe_core_public
*sipe_public
,
1498 struct sipe_backend_buddy_menu
*menu
,
1499 sipe_backend_buddy buddy
,
1500 sipe_buddy_info_fields id_phone
,
1501 sipe_buddy_info_fields id_display
,
1504 gchar
*phone
= sipe_backend_buddy_get_string(sipe_public
,
1508 gchar
*display
= sipe_backend_buddy_get_string(sipe_public
,
1512 gchar
*label
= g_strdup_printf("%s %s",
1515 (tmp
= sip_tel_uri_denormalize(phone
)));
1516 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1519 SIPE_BUDDY_MENU_MAKE_CALL
,
1530 struct sipe_backend_buddy_menu
*sipe_core_buddy_create_menu(struct sipe_core_public
*sipe_public
,
1531 const gchar
*buddy_name
,
1532 struct sipe_backend_buddy_menu
*menu
)
1534 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1535 sipe_backend_buddy buddy
= sipe_backend_buddy_find(sipe_public
,
1538 gchar
*self
= sip_uri_self(sipe_private
);
1540 SIPE_SESSION_FOREACH
{
1541 if (!sipe_strcase_equal(self
, buddy_name
) && session
->chat_session
)
1543 struct sipe_chat_session
*chat_session
= session
->chat_session
;
1544 gboolean is_conf
= (chat_session
->type
== SIPE_CHAT_TYPE_CONFERENCE
);
1546 if (sipe_backend_chat_find(chat_session
->backend
, buddy_name
))
1548 gboolean conf_op
= sipe_backend_chat_is_operator(chat_session
->backend
, self
);
1552 !sipe_backend_chat_is_operator(chat_session
->backend
, buddy_name
) &&
1553 /* We are a conf OP */
1555 gchar
*label
= g_strdup_printf(_("Make leader of '%s'"),
1556 chat_session
->title
);
1557 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1560 SIPE_BUDDY_MENU_MAKE_CHAT_LEADER
,
1566 /* We are a conf OP */
1568 gchar
*label
= g_strdup_printf(_("Remove from '%s'"),
1569 chat_session
->title
);
1570 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1573 SIPE_BUDDY_MENU_REMOVE_FROM_CHAT
,
1581 (is_conf
&& !session
->locked
)) {
1582 gchar
*label
= g_strdup_printf(_("Invite to '%s'"),
1583 chat_session
->title
);
1584 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1587 SIPE_BUDDY_MENU_INVITE_TO_CHAT
,
1593 } SIPE_SESSION_FOREACH_END
;
1596 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1599 SIPE_BUDDY_MENU_NEW_CHAT
,
1602 /* add buddy's phone numbers if we have call control */
1603 if (sip_csta_is_idle(sipe_private
)) {
1606 menu
= buddy_menu_phone(sipe_public
,
1609 SIPE_BUDDY_INFO_WORK_PHONE
,
1610 SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY
,
1613 menu
= buddy_menu_phone(sipe_public
,
1616 SIPE_BUDDY_INFO_MOBILE_PHONE
,
1617 SIPE_BUDDY_INFO_MOBILE_PHONE_DISPLAY
,
1621 menu
= buddy_menu_phone(sipe_public
,
1624 SIPE_BUDDY_INFO_HOME_PHONE
,
1625 SIPE_BUDDY_INFO_HOME_PHONE_DISPLAY
,
1629 menu
= buddy_menu_phone(sipe_public
,
1632 SIPE_BUDDY_INFO_OTHER_PHONE
,
1633 SIPE_BUDDY_INFO_OTHER_PHONE_DISPLAY
,
1637 menu
= buddy_menu_phone(sipe_public
,
1640 SIPE_BUDDY_INFO_CUSTOM1_PHONE
,
1641 SIPE_BUDDY_INFO_CUSTOM1_PHONE_DISPLAY
,
1646 gchar
*email
= sipe_backend_buddy_get_string(sipe_public
,
1648 SIPE_BUDDY_INFO_EMAIL
);
1650 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1653 SIPE_BUDDY_MENU_SEND_EMAIL
,
1659 /* access level control */
1660 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
))
1661 menu
= sipe_backend_buddy_sub_menu_add(sipe_public
,
1664 sipe_ocs2007_access_control_menu(sipe_private
,
1670 guint
sipe_buddy_count(struct sipe_core_private
*sipe_private
)
1672 return(g_hash_table_size(sipe_private
->buddies
));
1675 static guint
sipe_ht_hash_nick(const char *nick
)
1677 char *lc
= g_utf8_strdown(nick
, -1);
1678 guint bucket
= g_str_hash(lc
);
1684 static gboolean
sipe_ht_equals_nick(const char *nick1
, const char *nick2
)
1686 char *nick1_norm
= NULL
;
1687 char *nick2_norm
= NULL
;
1690 if (nick1
== NULL
&& nick2
== NULL
) return TRUE
;
1691 if (nick1
== NULL
|| nick2
== NULL
||
1692 !g_utf8_validate(nick1
, -1, NULL
) ||
1693 !g_utf8_validate(nick2
, -1, NULL
)) return FALSE
;
1695 nick1_norm
= g_utf8_casefold(nick1
, -1);
1696 nick2_norm
= g_utf8_casefold(nick2
, -1);
1697 equal
= g_utf8_collate(nick1_norm
, nick2_norm
) == 0;
1704 void sipe_buddy_init(struct sipe_core_private
*sipe_private
)
1706 sipe_private
->buddies
= g_hash_table_new((GHashFunc
) sipe_ht_hash_nick
,
1707 (GEqualFunc
) sipe_ht_equals_nick
);