6 * Copyright (C) 2010-11 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
32 #include "sipe-common.h"
36 #include "sip-transport.h"
37 #include "sipe-backend.h"
38 #include "sipe-buddy.h"
40 #include "sipe-chat.h"
41 #include "sipe-conf.h"
42 #include "sipe-core.h"
43 #include "sipe-core-private.h"
44 #include "sipe-group.h"
47 #include "sipe-ocs2005.h"
48 #include "sipe-ocs2007.h"
49 #include "sipe-schedule.h"
50 #include "sipe-session.h"
51 #include "sipe-subscriptions.h"
53 #include "sipe-utils.h"
54 #include "sipe-webticket.h"
57 static void buddy_free(struct sipe_buddy
*buddy
)
61 * We are calling g_hash_table_foreach_steal(). That means that no
62 * key/value deallocation functions are called. Therefore the glib
63 * hash code does not touch the key (buddy->name) or value (buddy)
64 * of the to-be-deleted hash node at all. It follows that we
66 * - MUST free the memory for the key ourselves and
67 * - ARE allowed to do it in this function
69 * Conclusion: glib must be broken on the Windows platform if sipe
70 * crashes with SIGTRAP when closing. You'll have to live
71 * with the memory leak until this is fixed.
75 g_free(buddy
->activity
);
76 g_free(buddy
->meeting_subject
);
77 g_free(buddy
->meeting_location
);
80 g_free(buddy
->cal_start_time
);
81 g_free(buddy
->cal_free_busy_base64
);
82 g_free(buddy
->cal_free_busy
);
83 g_free(buddy
->last_non_cal_activity
);
85 sipe_cal_free_working_hours(buddy
->cal_working_hours
);
87 g_free(buddy
->device_name
);
88 g_slist_free(buddy
->groups
);
92 static gboolean
buddy_free_cb(SIPE_UNUSED_PARAMETER gpointer key
,
94 SIPE_UNUSED_PARAMETER gpointer user_data
)
97 /* We must return TRUE as the key/value have already been deleted */
101 void sipe_buddy_free_all(struct sipe_core_private
*sipe_private
)
103 g_hash_table_foreach_steal(sipe_private
->buddies
,
108 gchar
*sipe_core_buddy_status(struct sipe_core_public
*sipe_public
,
111 const gchar
*status_text
)
113 struct sipe_buddy
*sbuddy
;
114 const char *activity_str
;
116 if (!sipe_public
) return NULL
; /* happens on pidgin exit */
118 sbuddy
= g_hash_table_lookup(SIPE_CORE_PRIVATE
->buddies
, uri
);
119 if (!sbuddy
) return NULL
;
121 activity_str
= sbuddy
->activity
? sbuddy
->activity
:
122 (activity
== SIPE_ACTIVITY_BUSY
) || (activity
== SIPE_ACTIVITY_BRB
) ?
125 if (activity_str
&& sbuddy
->note
) {
126 return g_strdup_printf("%s - <i>%s</i>", activity_str
, sbuddy
->note
);
127 } else if (activity_str
) {
128 return g_strdup(activity_str
);
129 } else if (sbuddy
->note
) {
130 return g_strdup_printf("<i>%s</i>", sbuddy
->note
);
136 gchar
*sipe_buddy_get_alias(struct sipe_core_private
*sipe_private
,
139 sipe_backend_buddy pbuddy
;
141 if ((pbuddy
= sipe_backend_buddy_find(SIPE_CORE_PUBLIC
, with
, NULL
))) {
142 alias
= sipe_backend_buddy_get_alias(SIPE_CORE_PUBLIC
, pbuddy
);
147 void sipe_core_buddy_group(struct sipe_core_public
*sipe_public
,
149 const gchar
*old_group_name
,
150 const gchar
*new_group_name
)
152 struct sipe_buddy
* buddy
= g_hash_table_lookup(SIPE_CORE_PRIVATE
->buddies
, who
);
153 struct sipe_group
* old_group
= NULL
;
154 struct sipe_group
* new_group
;
156 SIPE_DEBUG_INFO("sipe_core_buddy_group: who:%s old_group_name:%s new_group_name:%s",
157 who
? who
: "", old_group_name
? old_group_name
: "", new_group_name
? new_group_name
: "");
159 if(!buddy
) { // buddy not in roaming list
163 if (old_group_name
) {
164 old_group
= sipe_group_find_by_name(SIPE_CORE_PRIVATE
, old_group_name
);
166 new_group
= sipe_group_find_by_name(SIPE_CORE_PRIVATE
, new_group_name
);
169 buddy
->groups
= g_slist_remove(buddy
->groups
, old_group
);
170 SIPE_DEBUG_INFO("sipe_core_buddy_group: buddy %s removed from old group %s", who
, old_group_name
);
174 sipe_group_create(SIPE_CORE_PRIVATE
, new_group_name
, who
);
176 buddy
->groups
= slist_insert_unique_sorted(buddy
->groups
, new_group
, (GCompareFunc
)sipe_group_compare
);
177 sipe_core_group_set_user(sipe_public
, who
);
181 void sipe_core_buddy_add(struct sipe_core_public
*sipe_public
,
183 const gchar
*group_name
)
185 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
187 if (!g_hash_table_lookup(sipe_private
->buddies
, uri
)) {
188 struct sipe_buddy
*b
= g_new0(struct sipe_buddy
, 1);
190 SIPE_DEBUG_INFO("sipe_core_buddy_add: %s", uri
);
192 b
->name
= g_strdup(uri
);
193 b
->just_added
= TRUE
;
194 g_hash_table_insert(sipe_private
->buddies
, b
->name
, b
);
196 /* @TODO should go to callback */
197 sipe_subscribe_presence_single(sipe_private
, b
->name
);
200 SIPE_DEBUG_INFO("sipe_core_buddy_add: buddy %s already in internal list",
204 sipe_core_buddy_group(sipe_public
,
211 * Unassociates buddy from group first.
212 * Then see if no groups left, removes buddy completely.
213 * Otherwise updates buddy groups on server.
215 void sipe_core_buddy_remove(struct sipe_core_public
*sipe_public
,
217 const gchar
*group_name
)
219 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
220 struct sipe_buddy
*b
= g_hash_table_lookup(sipe_private
->buddies
,
226 struct sipe_group
*g
= sipe_group_find_by_name(sipe_private
,
229 b
->groups
= g_slist_remove(b
->groups
, g
);
230 SIPE_DEBUG_INFO("sipe_core_buddy_remove: buddy %s removed from group %s",
235 if (g_slist_length(b
->groups
) < 1) {
236 gchar
*action_name
= sipe_utils_presence_key(uri
);
237 sipe_schedule_cancel(sipe_private
, action_name
);
240 g_hash_table_remove(sipe_private
->buddies
, uri
);
243 gchar
*request
= g_strdup_printf("<m:URI>%s</m:URI>",
245 sip_soap_request(sipe_private
,
253 /* updates groups on server */
254 sipe_core_group_set_user(sipe_public
, b
->name
);
259 void sipe_core_buddy_got_status(struct sipe_core_public
*sipe_public
,
261 const gchar
*status_id
)
263 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
264 struct sipe_buddy
*sbuddy
= g_hash_table_lookup(sipe_private
->buddies
,
269 /* Check if on 2005 system contact's calendar,
270 * then set/preserve it.
272 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
273 sipe_backend_buddy_set_status(sipe_public
, uri
, status_id
);
275 sipe_ocs2005_apply_calendar_status(sipe_private
,
281 void sipe_core_buddy_tooltip_info(struct sipe_core_public
*sipe_public
,
283 const gchar
*status_name
,
285 struct sipe_backend_buddy_tooltip
*tooltip
)
287 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
289 gboolean is_oof_note
= FALSE
;
290 const gchar
*activity
= NULL
;
291 gchar
*calendar
= NULL
;
292 const gchar
*meeting_subject
= NULL
;
293 const gchar
*meeting_location
= NULL
;
294 gchar
*access_text
= NULL
;
296 #define SIPE_ADD_BUDDY_INFO(l, t) \
298 gchar *tmp = g_markup_escape_text((t), -1); \
299 sipe_backend_buddy_tooltip_add(sipe_public, tooltip, (l), tmp); \
302 #define SIPE_ADD_BUDDY_INFO_NOESCAPE(l, t) \
303 sipe_backend_buddy_tooltip_add(sipe_public, tooltip, (l), (t))
305 if (sipe_public
) { /* happens on pidgin exit */
306 struct sipe_buddy
*sbuddy
= g_hash_table_lookup(sipe_private
->buddies
, uri
);
309 is_oof_note
= sbuddy
->is_oof_note
;
310 activity
= sbuddy
->activity
;
311 calendar
= sipe_cal_get_description(sbuddy
);
312 meeting_subject
= sbuddy
->meeting_subject
;
313 meeting_location
= sbuddy
->meeting_location
;
315 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
316 gboolean is_group_access
= FALSE
;
317 const int container_id
= sipe_ocs2007_find_access_level(sipe_private
,
319 sipe_get_no_sip_uri(uri
),
321 const char *access_level
= sipe_ocs2007_access_level_name(container_id
);
322 access_text
= is_group_access
?
323 g_strdup(access_level
) :
324 g_strdup_printf(SIPE_OCS2007_INDENT_MARKED_FMT
,
330 const gchar
*status_str
= activity
? activity
: status_name
;
332 SIPE_ADD_BUDDY_INFO(_("Status"), status_str
);
334 if (is_online
&& !is_empty(calendar
)) {
335 SIPE_ADD_BUDDY_INFO(_("Calendar"), calendar
);
338 if (!is_empty(meeting_location
)) {
339 SIPE_DEBUG_INFO("sipe_tooltip_text: %s meeting location: '%s'", uri
, meeting_location
);
340 SIPE_ADD_BUDDY_INFO(_("Meeting in"), meeting_location
);
342 if (!is_empty(meeting_subject
)) {
343 SIPE_DEBUG_INFO("sipe_tooltip_text: %s meeting subject: '%s'", uri
, meeting_subject
);
344 SIPE_ADD_BUDDY_INFO(_("Meeting about"), meeting_subject
);
347 SIPE_DEBUG_INFO("sipe_tooltip_text: %s note: '%s'", uri
, note
);
348 SIPE_ADD_BUDDY_INFO_NOESCAPE(is_oof_note
? _("Out of office note") : _("Note"),
349 g_strdup_printf("<i>%s</i>", note
));
352 SIPE_ADD_BUDDY_INFO(_("Access level"), access_text
);
357 void sipe_buddy_update_property(struct sipe_core_private
*sipe_private
,
359 sipe_buddy_info_fields propkey
,
360 char *property_value
)
362 GSList
*buddies
, *entry
;
365 property_value
= g_strstrip(property_value
);
367 entry
= buddies
= sipe_backend_buddy_find_all(SIPE_CORE_PUBLIC
, uri
, NULL
); /* all buddies in different groups */
372 sipe_backend_buddy p_buddy
= entry
->data
;
374 /* for Display Name */
375 if (propkey
== SIPE_BUDDY_INFO_DISPLAY_NAME
) {
376 alias
= sipe_backend_buddy_get_alias(SIPE_CORE_PUBLIC
, p_buddy
);
377 if (property_value
&& sipe_is_bad_alias(uri
, alias
)) {
378 SIPE_DEBUG_INFO("Replacing alias for %s with %s", uri
, property_value
);
379 sipe_backend_buddy_set_alias(SIPE_CORE_PUBLIC
, p_buddy
, property_value
);
383 server_alias
= sipe_backend_buddy_get_server_alias(SIPE_CORE_PUBLIC
, p_buddy
);
384 if (!is_empty(property_value
) &&
385 (!sipe_strequal(property_value
, server_alias
) || is_empty(server_alias
)) )
387 SIPE_DEBUG_INFO("Replacing service alias for %s with %s", uri
, property_value
);
388 sipe_backend_buddy_set_server_alias(SIPE_CORE_PUBLIC
, p_buddy
, property_value
);
390 g_free(server_alias
);
392 /* for other properties */
394 if (!is_empty(property_value
)) {
395 prop_str
= sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC
, p_buddy
, propkey
);
396 if (!prop_str
|| !sipe_strcase_equal(prop_str
, property_value
)) {
397 sipe_backend_buddy_set_string(SIPE_CORE_PUBLIC
, p_buddy
, propkey
, property_value
);
405 g_slist_free(buddies
);
415 sipe_svc_callback
*callback
;
416 /* must call ms_dlx_free() */
417 void (*failed_callback
)(struct sipe_core_private
*sipe_private
,
418 struct ms_dlx_data
*mdd
);
421 static void ms_dlx_free(struct ms_dlx_data
*mdd
)
428 static void ms_dlx_webticket(struct sipe_core_private
*sipe_private
,
429 const gchar
*base_uri
,
430 const gchar
*auth_uri
,
431 const gchar
*wsse_security
,
432 gpointer callback_data
)
434 struct ms_dlx_data
*mdd
= callback_data
;
437 SIPE_DEBUG_INFO("ms_dlx_webticket: got ticket for %s",
440 if (sipe_svc_ab_entry_request(sipe_private
,
448 /* callback data passed down the line */
453 /* no ticket: this will show the minmum information */
454 SIPE_DEBUG_ERROR("ms_dlx_webticket: no web ticket for %s",
459 mdd
->failed_callback(sipe_private
, mdd
);
462 static void ms_dlx_webticket_request(struct sipe_core_private
*sipe_private
,
463 struct ms_dlx_data
*mdd
)
465 if (!sipe_webticket_request(sipe_private
,
466 sipe_private
->dlx_uri
,
467 "AddressBookWebTicketBearer",
470 SIPE_DEBUG_ERROR("ms_dlx_webticket_request: couldn't request webticket for %s",
471 sipe_private
->dlx_uri
);
472 mdd
->failed_callback(sipe_private
, mdd
);
476 static void search_contacts_finalize(struct sipe_core_private
*sipe_private
,
477 struct sipe_backend_search_results
*results
,
481 gchar
*secondary
= g_strdup_printf(
482 dngettext(PACKAGE_NAME
,
483 "Found %d contact%s:",
484 "Found %d contacts%s:", match_count
),
485 match_count
, more
? _(" (more matched your query)") : "");
487 sipe_backend_search_results_finalize(SIPE_CORE_PUBLIC
,
494 static void search_ab_entry_response(struct sipe_core_private
*sipe_private
,
496 SIPE_UNUSED_PARAMETER
const gchar
*raw
,
498 gpointer callback_data
)
500 struct ms_dlx_data
*mdd
= callback_data
;
503 const sipe_xml
*node
;
504 struct sipe_backend_search_results
*results
;
507 SIPE_DEBUG_INFO("search_ab_entry_response: received valid SOAP message from service %s",
511 node
= sipe_xml_child(soap_body
, "Body/SearchAbEntryResponse/SearchAbEntryResult/Items/AbEntry");
513 SIPE_DEBUG_ERROR_NOFORMAT("search_ab_entry_response: no matches");
514 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
515 _("No contacts found"),
521 /* OK, we found something - show the results to the user */
522 results
= sipe_backend_search_results_start(SIPE_CORE_PUBLIC
);
524 SIPE_DEBUG_ERROR_NOFORMAT("search_ab_entry_response: Unable to display the search results.");
525 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
526 _("Unable to display the search results"),
532 /* SearchAbEntryResult can contain duplicates */
533 found
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
536 for (/* initialized above */ ; node
; node
= sipe_xml_twin(node
)) {
537 const sipe_xml
*attrs
;
538 gchar
*sip_uri
= NULL
;
539 gchar
*displayname
= NULL
;
540 gchar
*company
= NULL
;
541 gchar
*country
= NULL
;
544 for (attrs
= sipe_xml_child(node
, "Attributes/Attribute");
546 attrs
= sipe_xml_twin(attrs
)) {
547 gchar
*name
= sipe_xml_data(sipe_xml_child(attrs
,
549 gchar
*value
= sipe_xml_data(sipe_xml_child(attrs
,
552 if (!is_empty(value
)) {
553 if (sipe_strcase_equal(name
, "msrtcsip-primaryuseraddress")) {
557 } else if (sipe_strcase_equal(name
, "displayname")) {
561 } else if (sipe_strcase_equal(name
, "mail")) {
565 } else if (sipe_strcase_equal(name
, "company")) {
569 } else if (sipe_strcase_equal(name
, "country")) {
580 if (sip_uri
&& !g_hash_table_lookup(found
, sip_uri
)) {
581 gchar
**uri_parts
= g_strsplit(sip_uri
, ":", 2);
582 sipe_backend_search_results_add(SIPE_CORE_PUBLIC
,
589 g_strfreev(uri_parts
);
591 g_hash_table_insert(found
, sip_uri
, (gpointer
) TRUE
);
602 search_contacts_finalize(sipe_private
, results
,
603 g_hash_table_size(found
),
605 g_hash_table_destroy(found
);
609 mdd
->failed_callback(sipe_private
, mdd
);
613 static void search_ab_entry_failed(struct sipe_core_private
*sipe_private
,
614 struct ms_dlx_data
*mdd
)
616 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
617 _("Contact search failed"),
622 static gboolean
process_search_contact_response(struct sipe_core_private
*sipe_private
,
624 SIPE_UNUSED_PARAMETER
struct transaction
*trans
)
626 struct sipe_backend_search_results
*results
;
627 sipe_xml
*searchResults
;
628 const sipe_xml
*mrow
;
629 guint match_count
= 0;
630 gboolean more
= FALSE
;
632 /* valid response? */
633 if (msg
->response
!= 200) {
634 SIPE_DEBUG_ERROR("process_search_contact_response: request failed (%d)",
636 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
637 _("Contact search failed"),
642 SIPE_DEBUG_INFO("process_search_contact_response: body:\n%s", msg
->body
? msg
->body
: "");
645 searchResults
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
646 if (!searchResults
) {
647 SIPE_DEBUG_INFO_NOFORMAT("process_search_contact_response: no parseable searchResults");
648 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
649 _("Contact search failed"),
655 mrow
= sipe_xml_child(searchResults
, "Body/Array/row");
657 SIPE_DEBUG_ERROR_NOFORMAT("process_search_contact_response: no matches");
658 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
659 _("No contacts found"),
662 sipe_xml_free(searchResults
);
666 /* OK, we found something - show the results to the user */
667 results
= sipe_backend_search_results_start(SIPE_CORE_PUBLIC
);
669 SIPE_DEBUG_ERROR_NOFORMAT("process_search_contact_response: Unable to display the search results.");
670 sipe_backend_notify_error(SIPE_CORE_PUBLIC
,
671 _("Unable to display the search results"),
674 sipe_xml_free(searchResults
);
678 for (/* initialized above */ ; mrow
; mrow
= sipe_xml_twin(mrow
)) {
679 gchar
**uri_parts
= g_strsplit(sipe_xml_attribute(mrow
, "uri"), ":", 2);
680 sipe_backend_search_results_add(SIPE_CORE_PUBLIC
,
683 sipe_xml_attribute(mrow
, "displayName"),
684 sipe_xml_attribute(mrow
, "company"),
685 sipe_xml_attribute(mrow
, "country"),
686 sipe_xml_attribute(mrow
, "email"));
687 g_strfreev(uri_parts
);
691 if ((mrow
= sipe_xml_child(searchResults
, "Body/directorySearch/moreAvailable")) != NULL
) {
692 char *data
= sipe_xml_data(mrow
);
693 more
= (g_strcasecmp(data
, "true") == 0);
697 search_contacts_finalize(sipe_private
, results
, match_count
, more
);
698 sipe_xml_free(searchResults
);
703 #define SIPE_SOAP_SEARCH_ROW "<m:row m:attrib=\"%s\" m:value=\"%s\"/>"
704 #define DLX_SEARCH_ITEM \
705 "<AbEntryRequest.ChangeSearchQuery>" \
706 " <SearchOn>%s</SearchOn>" \
707 " <Value>%s</Value>" \
708 "</AbEntryRequest.ChangeSearchQuery>"
710 void sipe_core_buddy_search(struct sipe_core_public
*sipe_public
,
711 const gchar
*given_name
,
712 const gchar
*surname
,
713 const gchar
*company
,
714 const gchar
*country
)
716 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
717 gchar
**attrs
= g_new(gchar
*, 5);
719 gboolean dlx
= (sipe_private
->dlx_uri
!= NULL
);
721 #define ADD_QUERY_ROW(a, v) \
722 if (v) attrs[i++] = g_markup_printf_escaped(dlx ? DLX_SEARCH_ITEM : SIPE_SOAP_SEARCH_ROW, \
726 ADD_QUERY_ROW("givenName", given_name
);
727 ADD_QUERY_ROW("sn", surname
);
728 ADD_QUERY_ROW("company", company
);
729 ADD_QUERY_ROW("c", country
);
735 query
= g_strjoinv(NULL
, attrs
);
736 SIPE_DEBUG_INFO("sipe_core_buddy_search: rows:\n%s",
740 struct ms_dlx_data
*mdd
= g_new0(struct ms_dlx_data
, 1);
744 mdd
->max_returns
= 100;
745 mdd
->callback
= search_ab_entry_response
;
746 mdd
->failed_callback
= search_ab_entry_failed
;
748 ms_dlx_webticket_request(sipe_private
, mdd
);
751 /* no [MS-DLX] server, use Active Directory search instead */
752 sip_soap_directory_search(SIPE_CORE_PRIVATE
,
755 process_search_contact_response
,
764 static void get_info_finalize(struct sipe_core_private
*sipe_private
,
765 struct sipe_backend_buddy_info
*info
,
767 const gchar
*server_alias
,
770 sipe_backend_buddy bbuddy
;
771 struct sipe_buddy
*sbuddy
;
776 info
= sipe_backend_buddy_info_start(SIPE_CORE_PUBLIC
);
778 sipe_backend_buddy_info_break(SIPE_CORE_PUBLIC
, info
);
783 bbuddy
= sipe_backend_buddy_find(SIPE_CORE_PUBLIC
, uri
, NULL
);
785 if (is_empty(server_alias
)) {
786 value
= sipe_backend_buddy_get_server_alias(SIPE_CORE_PUBLIC
,
789 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
791 SIPE_BUDDY_INFO_DISPLAY_NAME
,
795 value
= g_strdup(server_alias
);
798 /* present alias if it differs from server alias */
799 alias
= sipe_backend_buddy_get_local_alias(SIPE_CORE_PUBLIC
, bbuddy
);
800 if (alias
&& !sipe_strequal(alias
, value
))
802 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
804 SIPE_BUDDY_INFO_ALIAS
,
810 if (is_empty(email
)) {
811 value
= sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC
,
813 SIPE_BUDDY_INFO_EMAIL
);
815 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
817 SIPE_BUDDY_INFO_EMAIL
,
823 value
= sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC
,
825 SIPE_BUDDY_INFO_SITE
);
827 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
829 SIPE_BUDDY_INFO_SITE
,
834 sbuddy
= g_hash_table_lookup(sipe_private
->buddies
, uri
);
835 if (sbuddy
&& sbuddy
->device_name
) {
836 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
838 SIPE_BUDDY_INFO_DEVICE
,
839 sbuddy
->device_name
);
842 sipe_backend_buddy_info_finalize(SIPE_CORE_PUBLIC
, info
, uri
);
846 static void get_info_ab_entry_response(struct sipe_core_private
*sipe_private
,
848 SIPE_UNUSED_PARAMETER
const gchar
*raw
,
850 gpointer callback_data
)
852 struct ms_dlx_data
*mdd
= callback_data
;
853 struct sipe_backend_buddy_info
*info
= NULL
;
854 gchar
*server_alias
= NULL
;
858 const sipe_xml
*node
;
860 SIPE_DEBUG_INFO("get_info_ab_entry_response: received valid SOAP message from service %s",
863 info
= sipe_backend_buddy_info_start(SIPE_CORE_PUBLIC
);
865 for (node
= sipe_xml_child(soap_body
, "Body/SearchAbEntryResponse/SearchAbEntryResult/Items/AbEntry/Attributes/Attribute");
867 node
= sipe_xml_twin(node
)) {
868 gchar
*name
= sipe_xml_data(sipe_xml_child(node
,
870 gchar
*value
= sipe_xml_data(sipe_xml_child(node
,
872 const sipe_xml
*values
= sipe_xml_child(node
,
875 /* Single value entries */
876 if (!is_empty(value
)) {
878 if (sipe_strcase_equal(name
, "displayname")) {
879 g_free(server_alias
);
880 server_alias
= value
;
882 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
884 SIPE_BUDDY_INFO_DISPLAY_NAME
,
886 } else if (sipe_strcase_equal(name
, "mail")) {
890 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
892 SIPE_BUDDY_INFO_EMAIL
,
894 } else if (sipe_strcase_equal(name
, "title")) {
895 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
897 SIPE_BUDDY_INFO_JOB_TITLE
,
899 } else if (sipe_strcase_equal(name
, "company")) {
900 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
902 SIPE_BUDDY_INFO_COMPANY
,
904 } else if (sipe_strcase_equal(name
, "country")) {
905 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
907 SIPE_BUDDY_INFO_COUNTRY
,
912 gchar
*first
= sipe_xml_data(sipe_xml_child(values
,
915 if (sipe_strcase_equal(name
, "telephonenumber")) {
916 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
918 SIPE_BUDDY_INFO_WORK_PHONE
,
930 /* this will show the minmum information */
931 get_info_finalize(sipe_private
,
938 g_free(server_alias
);
942 static void get_info_ab_entry_failed(struct sipe_core_private
*sipe_private
,
943 struct ms_dlx_data
*mdd
)
945 /* request failed: this will show the minmum information */
946 get_info_finalize(sipe_private
,
954 static gboolean
process_get_info_response(struct sipe_core_private
*sipe_private
,
956 struct transaction
*trans
)
958 const gchar
*uri
= trans
->payload
->data
;
959 struct sipe_backend_buddy_info
*info
= NULL
;
960 gchar
*server_alias
= NULL
;
963 SIPE_DEBUG_INFO("Fetching %s's user info for %s",
964 uri
, sipe_private
->username
);
966 if (msg
->response
!= 200) {
967 SIPE_DEBUG_INFO("process_get_info_response: SERVICE response is %d", msg
->response
);
969 sipe_xml
*searchResults
;
970 const sipe_xml
*mrow
;
972 SIPE_DEBUG_INFO("process_get_info_response: body:\n%s",
973 msg
->body
? msg
->body
: "");
975 searchResults
= sipe_xml_parse(msg
->body
, msg
->bodylen
);
976 if (!searchResults
) {
978 SIPE_DEBUG_INFO_NOFORMAT("process_get_info_response: no parseable searchResults");
980 } else if ((mrow
= sipe_xml_child(searchResults
, "Body/Array/row"))) {
984 info
= sipe_backend_buddy_info_start(SIPE_CORE_PUBLIC
);
986 server_alias
= g_strdup(sipe_xml_attribute(mrow
, "displayName"));
987 email
= g_strdup(sipe_xml_attribute(mrow
, "email"));
988 phone_number
= g_strdup(sipe_xml_attribute(mrow
, "phone"));
991 * For 2007 system we will take this from ContactCard -
992 * it has cleaner tel: URIs at least
994 if (!SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
995 char *tel_uri
= sip_to_tel_uri(phone_number
);
996 /* trims its parameters, so call first */
997 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_DISPLAY_NAME
, server_alias
);
998 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_EMAIL
, email
);
999 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_WORK_PHONE
, tel_uri
);
1000 sipe_buddy_update_property(sipe_private
, uri
, SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY
, phone_number
);
1004 if (!is_empty(server_alias
)) {
1005 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1007 SIPE_BUDDY_INFO_DISPLAY_NAME
,
1010 if ((value
= sipe_xml_attribute(mrow
, "title")) && strlen(value
) > 0) {
1011 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1013 SIPE_BUDDY_INFO_JOB_TITLE
,
1016 if ((value
= sipe_xml_attribute(mrow
, "office")) && strlen(value
) > 0) {
1017 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1019 SIPE_BUDDY_INFO_OFFICE
,
1022 if (!is_empty(phone_number
)) {
1023 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1025 SIPE_BUDDY_INFO_WORK_PHONE
,
1028 g_free(phone_number
);
1029 if ((value
= sipe_xml_attribute(mrow
, "company")) && strlen(value
) > 0) {
1030 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1032 SIPE_BUDDY_INFO_COMPANY
,
1035 if ((value
= sipe_xml_attribute(mrow
, "city")) && strlen(value
) > 0) {
1036 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1038 SIPE_BUDDY_INFO_CITY
,
1041 if ((value
= sipe_xml_attribute(mrow
, "state")) && strlen(value
) > 0) {
1042 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1044 SIPE_BUDDY_INFO_STATE
,
1047 if ((value
= sipe_xml_attribute(mrow
, "country")) && strlen(value
) > 0) {
1048 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1050 SIPE_BUDDY_INFO_COUNTRY
,
1053 if (!is_empty(email
)) {
1054 sipe_backend_buddy_info_add(SIPE_CORE_PUBLIC
,
1056 SIPE_BUDDY_INFO_EMAIL
,
1060 sipe_xml_free(searchResults
);
1063 /* this will show the minmum information */
1064 get_info_finalize(sipe_private
,
1070 g_free(server_alias
);
1076 void sipe_core_buddy_get_info(struct sipe_core_public
*sipe_public
,
1079 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1081 if (sipe_private
->dlx_uri
) {
1082 struct ms_dlx_data
*mdd
= g_new0(struct ms_dlx_data
, 1);
1084 mdd
->search
= g_markup_printf_escaped(DLX_SEARCH_ITEM
,
1085 "msRTCSIP-PrimaryUserAddress",
1087 mdd
->other
= g_strdup(who
);
1089 mdd
->max_returns
= 1;
1090 mdd
->callback
= get_info_ab_entry_response
;
1091 mdd
->failed_callback
= get_info_ab_entry_failed
;
1093 ms_dlx_webticket_request(sipe_private
, mdd
);
1096 /* no [MS-DLX] server, use Active Directory search instead */
1097 gchar
*row
= g_markup_printf_escaped(SIPE_SOAP_SEARCH_ROW
,
1098 "msRTCSIP-PrimaryUserAddress",
1100 struct transaction_payload
*payload
= g_new0(struct transaction_payload
, 1);
1102 SIPE_DEBUG_INFO("sipe_core_buddy_get_info: row: %s",
1105 payload
->destroy
= g_free
;
1106 payload
->data
= g_strdup(who
);
1108 sip_soap_directory_search(sipe_private
,
1111 process_get_info_response
,
1117 /* Buddy menu callbacks*/
1119 void sipe_core_buddy_new_chat(struct sipe_core_public
*sipe_public
,
1122 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1124 /* 2007+ conference */
1125 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
)) {
1126 sipe_conf_add(sipe_private
, who
);
1128 /* 2005- multiparty chat */
1130 gchar
*self
= sip_uri_self(sipe_private
);
1131 struct sip_session
*session
;
1133 session
= sipe_session_add_chat(sipe_private
,
1137 session
->chat_session
->backend
= sipe_backend_chat_create(SIPE_CORE_PUBLIC
,
1138 session
->chat_session
,
1139 session
->chat_session
->title
,
1143 sipe_im_invite(sipe_private
, session
, who
,
1144 NULL
, NULL
, NULL
, FALSE
);
1148 void sipe_core_buddy_send_email(struct sipe_core_public
*sipe_public
,
1151 sipe_backend_buddy buddy
= sipe_backend_buddy_find(sipe_public
,
1154 gchar
*email
= sipe_backend_buddy_get_string(sipe_public
,
1156 SIPE_BUDDY_INFO_EMAIL
);
1159 gchar
*command_line
= g_strdup_printf(
1165 " mailto:%s", email
);
1168 SIPE_DEBUG_INFO("sipe_core_buddy_send_email: going to call email client: %s",
1170 g_spawn_command_line_async(command_line
, NULL
);
1171 g_free(command_line
);
1174 SIPE_DEBUG_INFO("sipe_core_buddy_send_email: no email address stored for buddy=%s",
1181 static struct sipe_backend_buddy_menu
*buddy_menu_phone(struct sipe_core_public
*sipe_public
,
1182 struct sipe_backend_buddy_menu
*menu
,
1183 sipe_backend_buddy buddy
,
1184 sipe_buddy_info_fields id_phone
,
1185 sipe_buddy_info_fields id_display
,
1188 gchar
*phone
= sipe_backend_buddy_get_string(sipe_public
,
1192 gchar
*display
= sipe_backend_buddy_get_string(sipe_public
,
1196 gchar
*label
= g_strdup_printf("%s %s",
1199 (tmp
= sip_tel_uri_denormalize(phone
)));
1200 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1203 SIPE_BUDDY_MENU_MAKE_CALL
,
1214 struct sipe_backend_buddy_menu
*sipe_core_buddy_create_menu(struct sipe_core_public
*sipe_public
,
1215 const gchar
*buddy_name
,
1216 struct sipe_backend_buddy_menu
*menu
)
1218 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
1219 sipe_backend_buddy buddy
= sipe_backend_buddy_find(sipe_public
,
1222 gchar
*self
= sip_uri_self(sipe_private
);
1224 SIPE_SESSION_FOREACH
{
1225 if (!sipe_strcase_equal(self
, buddy_name
) && session
->chat_session
)
1227 struct sipe_chat_session
*chat_session
= session
->chat_session
;
1228 gboolean is_conf
= (chat_session
->type
== SIPE_CHAT_TYPE_CONFERENCE
);
1230 if (sipe_backend_chat_find(chat_session
->backend
, buddy_name
))
1232 gboolean conf_op
= sipe_backend_chat_is_operator(chat_session
->backend
, self
);
1236 !sipe_backend_chat_is_operator(chat_session
->backend
, buddy_name
) &&
1237 /* We are a conf OP */
1239 gchar
*label
= g_strdup_printf(_("Make leader of '%s'"),
1240 chat_session
->title
);
1241 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1244 SIPE_BUDDY_MENU_MAKE_CHAT_LEADER
,
1250 /* We are a conf OP */
1252 gchar
*label
= g_strdup_printf(_("Remove from '%s'"),
1253 chat_session
->title
);
1254 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1257 SIPE_BUDDY_MENU_REMOVE_FROM_CHAT
,
1265 (is_conf
&& !session
->locked
)) {
1266 gchar
*label
= g_strdup_printf(_("Invite to '%s'"),
1267 chat_session
->title
);
1268 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1271 SIPE_BUDDY_MENU_INVITE_TO_CHAT
,
1277 } SIPE_SESSION_FOREACH_END
;
1280 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1283 SIPE_BUDDY_MENU_NEW_CHAT
,
1286 /* add buddy's phone numbers if we have call control */
1287 if (sip_csta_is_idle(sipe_private
)) {
1290 menu
= buddy_menu_phone(sipe_public
,
1293 SIPE_BUDDY_INFO_WORK_PHONE
,
1294 SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY
,
1297 menu
= buddy_menu_phone(sipe_public
,
1300 SIPE_BUDDY_INFO_MOBILE_PHONE
,
1301 SIPE_BUDDY_INFO_MOBILE_PHONE_DISPLAY
,
1305 menu
= buddy_menu_phone(sipe_public
,
1308 SIPE_BUDDY_INFO_HOME_PHONE
,
1309 SIPE_BUDDY_INFO_HOME_PHONE_DISPLAY
,
1313 menu
= buddy_menu_phone(sipe_public
,
1316 SIPE_BUDDY_INFO_OTHER_PHONE
,
1317 SIPE_BUDDY_INFO_OTHER_PHONE_DISPLAY
,
1321 menu
= buddy_menu_phone(sipe_public
,
1324 SIPE_BUDDY_INFO_CUSTOM1_PHONE
,
1325 SIPE_BUDDY_INFO_CUSTOM1_PHONE_DISPLAY
,
1330 gchar
*email
= sipe_backend_buddy_get_string(sipe_public
,
1332 SIPE_BUDDY_INFO_EMAIL
);
1334 menu
= sipe_backend_buddy_menu_add(sipe_public
,
1337 SIPE_BUDDY_MENU_SEND_EMAIL
,
1343 /* access level control */
1344 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
))
1345 menu
= sipe_backend_buddy_sub_menu_add(sipe_public
,
1348 sipe_ocs2007_access_control_menu(sipe_private
,