purple: register D-Bus extensions at plugin load
[siplcs.git] / src / purple / purple-plugin-common.c
blob8112de31c6ab5a97ea23925f40bf80eeebc786ac
1 /**
2 * @file purple-plugin-common.c
4 * pidgin-sipe
6 * Copyright (C) 2010-2017 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
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include <glib.h>
28 #include <string.h>
30 #include "sipe-common.h"
32 #include "account.h"
33 #include "accountopt.h"
34 #include "core.h"
35 #include "notify.h"
36 #include "request.h"
37 #include "version.h"
39 #ifdef HAVE_DBUS
40 #include "purple-dbus.h"
41 #endif
43 /* Backward compatibility when compiling against 2.4.x API */
44 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
45 #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100
46 #endif
48 #if PURPLE_VERSION_CHECK(3,0,0)
49 #define PURPLE_TYPE_STRING G_TYPE_STRING
50 #define SIPE_PURPLE_ACTION_TO_CONNECTION action->connection
51 #else
52 #include "blist.h"
53 #define g_source_remove(t) purple_timeout_remove(t)
54 #define PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
55 #define PURPLE_CONNECTION_FLAG_FORMATTING_WBFO PURPLE_CONNECTION_FORMATTING_WBFO
56 #define PURPLE_CONNECTION_FLAG_HTML PURPLE_CONNECTION_HTML
57 #define PURPLE_CONNECTION_FLAG_NO_BGCOLOR PURPLE_CONNECTION_NO_BGCOLOR
58 #define PURPLE_CONNECTION_FLAG_NO_FONTSIZE PURPLE_CONNECTION_NO_FONTSIZE
59 #define PURPLE_CONNECTION_FLAG_NO_URLDESC PURPLE_CONNECTION_NO_URLDESC
60 #define PURPLE_IS_BUDDY(n) PURPLE_BLIST_NODE_IS_BUDDY(n)
61 #define PURPLE_IS_CHAT(n) PURPLE_BLIST_NODE_IS_CHAT(n)
62 #define PURPLE_IM_TYPING PURPLE_TYPING
63 #define PURPLE_IM_NOT_TYPING PURPLE_NOT_TYPING
64 #define purple_account_option_string_set_masked(o, f) purple_account_option_set_masked(o, f)
65 #define purple_connection_error(g, e, m) purple_connection_error_reason(g, e, m)
66 #define purple_connection_get_flags(gc) 0
67 #define purple_connection_set_protocol_data(gc, p) gc->proto_data = p
68 #define purple_connection_set_flags(gc, f) gc->flags |= f
69 #define purple_protocol_action_new(l, c) purple_plugin_action_new(l, c)
70 #define PurpleProtocolAction PurplePluginAction
71 #define SIPE_PURPLE_ACTION_TO_CONNECTION action->context
72 #endif
74 #include "sipe-backend.h"
75 #include "sipe-core.h"
76 #include "sipe-nls.h"
78 #include "purple-private.h"
81 * NOTE: this flag means two things:
83 * - is Single Sign-On supported, and
84 * - is Kerberos supported
86 #if defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_SSPI)
87 #define PURPLE_SIPE_SSO_AND_KERBEROS 1
88 #else
89 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
90 #endif
93 * SIPE core activity <-> Purple status mapping
95 * NOTE: this needs to be kept in sync with sipe_purple_status_types()
97 static const gchar * const activity_to_purple_map[SIPE_ACTIVITY_NUM_TYPES] = {
98 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
99 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
100 /* SIPE_ACTIVITY_ONLINE */ "online",
101 /* SIPE_ACTIVITY_INACTIVE */ "idle",
102 /* SIPE_ACTIVITY_BUSY */ "busy",
103 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
104 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
105 /* SIPE_ACTIVITY_BRB */ "be-right-back",
106 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
107 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
108 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
109 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
110 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
111 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
112 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
113 /* SIPE_ACTIVITY_OOF */ "out-of-office",
114 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
115 /* SIPE_ACTIVIY_NUM_TYPES == 17 -> compare to sipe_purple_status_types() */
118 GHashTable *purple_token_map;
120 static void sipe_purple_activity_init(void)
122 guint index;
124 purple_token_map = g_hash_table_new(g_str_hash, g_str_equal);
125 for (index = SIPE_ACTIVITY_UNSET;
126 index < SIPE_ACTIVITY_NUM_TYPES;
127 index++) {
128 g_hash_table_insert(purple_token_map,
129 (gchar *) activity_to_purple_map[index],
130 GUINT_TO_POINTER(index));
134 static void sipe_purple_activity_shutdown(void)
136 g_hash_table_destroy(purple_token_map);
139 const gchar *sipe_purple_activity_to_token(guint type)
141 return(activity_to_purple_map[type]);
144 guint sipe_purple_token_to_activity(const gchar *token)
146 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map, token)));
149 gchar *sipe_backend_version(void)
151 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
154 const char *sipe_purple_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount *a,
155 SIPE_UNUSED_PARAMETER PurpleBuddy *b)
157 return "sipe";
160 gchar *sipe_purple_status_text(PurpleBuddy *buddy)
162 const PurpleStatus *status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
163 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
164 purple_buddy_get_name(buddy),
165 sipe_purple_token_to_activity(purple_status_get_id(status)),
166 purple_status_get_name(status));
169 void sipe_purple_tooltip_text(PurpleBuddy *buddy,
170 PurpleNotifyUserInfo *user_info,
171 SIPE_UNUSED_PARAMETER gboolean full)
173 const PurplePresence *presence = purple_buddy_get_presence(buddy);
174 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
175 purple_buddy_get_name(buddy),
176 purple_status_get_name(purple_presence_get_active_status(presence)),
177 purple_presence_is_online(presence),
178 (struct sipe_backend_buddy_tooltip *) user_info);
181 GList *sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount *acc)
183 PurpleStatusType *type;
184 GList *types = NULL;
186 /* Macro to reduce code repetition
187 Translators: noun */
188 #define SIPE_ADD_STATUS(prim,activity,user) type = purple_status_type_new_with_attrs( \
189 prim, \
190 sipe_purple_activity_to_token(activity), \
191 sipe_core_activity_description(activity), \
192 TRUE, user, FALSE, \
193 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
194 NULL); \
195 types = g_list_append(types, type);
198 * NOTE: needs to be kept in sync with activity_to_purple_map[],
199 * i.e. for each SIPE_ACTIVITY_xxx value there must be an
200 * entry on this list.
202 * NOTE: the following code is sorted by purple primitive type not
203 * by SIPE_ACTIVITY_xxx value.
206 /* 1: Unset - special case: no entry needed */
209 * Status list entries for primitive type AVAILABLE
211 * 2: Available */
212 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
213 SIPE_ACTIVITY_AVAILABLE,
214 TRUE);
216 /* 3: Online */
217 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
218 SIPE_ACTIVITY_ONLINE,
219 FALSE);
221 /* 4: Inactive (Idle) */
222 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
223 SIPE_ACTIVITY_INACTIVE,
224 FALSE);
227 * Status list entries for primitive type UNAVAILABLE
229 * 5: Busy */
230 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
231 SIPE_ACTIVITY_BUSY,
232 TRUE);
234 /* 6: Busy-Idle */
235 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
236 SIPE_ACTIVITY_BUSYIDLE,
237 FALSE);
239 /* 7: Do Not Disturb */
240 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
241 SIPE_ACTIVITY_DND,
242 TRUE);
244 /* 8: In a call */
245 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
246 SIPE_ACTIVITY_ON_PHONE,
247 FALSE);
249 /* 9: In a conference call */
250 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
251 SIPE_ACTIVITY_IN_CONF,
252 FALSE);
254 /* 10: In a meeting */
255 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
256 SIPE_ACTIVITY_IN_MEETING,
257 FALSE);
259 /* 11: Urgent interruptions only */
260 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
261 SIPE_ACTIVITY_URGENT_ONLY,
262 FALSE);
265 * Status list entries for primitive type AWAY
267 * 12: Away - special case: needs to go first in the list as purple
268 * picks the first status with primitive type AWAY for idle
270 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
271 SIPE_ACTIVITY_AWAY,
272 TRUE);
274 /* 13: Be Right Back */
275 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
276 SIPE_ACTIVITY_BRB,
277 TRUE);
279 /* 14: Out to lunch */
280 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
281 SIPE_ACTIVITY_LUNCH,
282 FALSE);
285 * Status list entries for primitive type EXTENDED_AWAY
287 * 15: Out of office */
288 SIPE_ADD_STATUS(PURPLE_STATUS_EXTENDED_AWAY,
289 SIPE_ACTIVITY_OOF,
290 FALSE);
293 * Status list entries for primitive type INVISIBLE
295 * 16: Appear Offline */
296 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE,
297 SIPE_ACTIVITY_INVISIBLE,
298 TRUE);
301 * Status list entries for primitive type OFFLINE
303 * NOTE: this is always the last entry. Compare the number
304 * with the comment in activity_to_purple_map[].
306 * 17: Offline - special case: no message text */
307 type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
308 NULL,
309 NULL,
310 TRUE);
311 types = g_list_append(types, type);
313 return types;
316 GList *sipe_purple_blist_node_menu(PurpleBlistNode *node)
318 if (PURPLE_IS_BUDDY(node))
320 return sipe_purple_buddy_menu((PurpleBuddy *) node);
321 } else
322 if (PURPLE_IS_CHAT(node))
324 return sipe_purple_chat_menu((PurpleChat *)node);
325 } else {
326 return NULL;
330 static guint get_authentication_type(PurpleAccount *account)
332 const gchar *auth = purple_account_get_string(account, "authentication", "ntlm");
334 /* map option list to type - default is automatic */
335 guint authentication_type = SIPE_AUTHENTICATION_TYPE_AUTOMATIC;
336 if (sipe_strequal(auth, "ntlm")) {
337 authentication_type = SIPE_AUTHENTICATION_TYPE_NTLM;
338 } else
339 #if PURPLE_SIPE_SSO_AND_KERBEROS
340 if (sipe_strequal(auth, "krb5")) {
341 authentication_type = SIPE_AUTHENTICATION_TYPE_KERBEROS;
342 } else
343 #endif
344 if (sipe_strequal(auth, "tls-dsk")) {
345 authentication_type = SIPE_AUTHENTICATION_TYPE_TLS_DSK;
348 return(authentication_type);
351 static gboolean get_sso_flag(PurpleAccount *account)
353 #if PURPLE_SIPE_SSO_AND_KERBEROS
355 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
356 * SIPE that it is OK to use Single Sign-On or not.
358 return(purple_account_get_bool(account, "sso", FALSE));
359 #else
360 (void) account; /* keep compiler happy */
361 return(FALSE);
362 #endif
365 static gboolean get_dont_publish_flag(PurpleAccount *account)
367 /* default is to publish calendar information */
368 return(purple_account_get_bool(account, "dont-publish", FALSE));
371 static gboolean get_allow_web_photo_flag(PurpleAccount *account)
373 /* default is to not allow insecure download of buddy icons from web */
374 return purple_account_get_bool(account, "allow-web-photo", FALSE);
377 static void connect_to_core(PurpleConnection *gc,
378 PurpleAccount *account,
379 const gchar *password)
381 const gchar *username = purple_account_get_username(account);
382 const gchar *email = purple_account_get_string(account, "email", NULL);
383 const gchar *email_url = purple_account_get_string(account, "email_url", NULL);
384 const gchar *transport = purple_account_get_string(account, "transport", "auto");
385 struct sipe_core_public *sipe_public;
386 gchar **username_split;
387 const gchar *errmsg;
388 guint transport_type;
389 struct sipe_backend_private *purple_private;
391 /* username format: <username>,[<optional login>] */
392 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username);
393 username_split = g_strsplit(username, ",", 2);
395 sipe_public = sipe_core_allocate(username_split[0],
396 get_sso_flag(account),
397 username_split[1],
398 password,
399 email,
400 email_url,
401 &errmsg);
402 g_strfreev(username_split);
404 if (!sipe_public) {
405 purple_connection_error(gc,
406 PURPLE_CONNECTION_ERROR_INVALID_USERNAME,
407 errmsg);
408 return;
411 sipe_public->backend_private = purple_private = g_new0(struct sipe_backend_private, 1);
412 purple_private->public = sipe_public;
413 purple_private->gc = gc;
414 purple_private->account = account;
416 sipe_purple_chat_setup_rejoin(purple_private);
418 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH);
419 if (get_dont_publish_flag(account))
420 SIPE_CORE_FLAG_SET(DONT_PUBLISH);
421 SIPE_CORE_FLAG_UNSET(ALLOW_WEB_PHOTO);
422 if (get_allow_web_photo_flag(account))
423 SIPE_CORE_FLAG_SET(ALLOW_WEB_PHOTO);
425 purple_connection_set_protocol_data(gc, sipe_public);
426 purple_connection_set_flags(gc,
427 purple_connection_get_flags(gc) |
428 PURPLE_CONNECTION_FLAG_HTML |
429 PURPLE_CONNECTION_FLAG_FORMATTING_WBFO |
430 PURPLE_CONNECTION_FLAG_NO_BGCOLOR |
431 PURPLE_CONNECTION_FLAG_NO_FONTSIZE |
432 PURPLE_CONNECTION_FLAG_NO_URLDESC |
433 PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY);
434 purple_connection_set_display_name(gc, sipe_public->sip_name);
435 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
437 username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2);
438 if (sipe_strequal(transport, "auto")) {
439 transport_type = (username_split[0] == NULL) ?
440 SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS;
441 } else if (sipe_strequal(transport, "tls")) {
442 transport_type = SIPE_TRANSPORT_TLS;
443 } else {
444 transport_type = SIPE_TRANSPORT_TCP;
446 sipe_core_transport_sip_connect(sipe_public,
447 transport_type,
448 get_authentication_type(account),
449 username_split[0],
450 username_split[0] ? username_split[1] : NULL);
451 g_strfreev(username_split);
454 static void password_required_cb(PurpleConnection *gc,
455 SIPE_UNUSED_PARAMETER PurpleRequestFields *fields)
457 #if !PURPLE_VERSION_CHECK(3,0,0)
458 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
459 return;
461 #endif
463 purple_connection_error(gc,
464 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
465 _("Password required"));
468 static void password_ok_cb(PurpleConnection *gc,
469 PurpleRequestFields *fields)
471 const gchar *password;
473 #if !PURPLE_VERSION_CHECK(3,0,0)
474 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
475 return;
477 #endif
479 password = purple_request_fields_get_string(fields, "password");
481 if (password && strlen(password)) {
482 PurpleAccount *account = purple_connection_get_account(gc);
484 if (purple_request_fields_get_bool(fields, "remember"))
485 purple_account_set_remember_password(account, TRUE);
486 purple_account_set_password(account, password
487 #if PURPLE_VERSION_CHECK(3,0,0)
488 , NULL, NULL
489 #endif
492 /* Now we have a password and we can connect */
493 connect_to_core(gc, account, password);
495 } else
496 /* reject an empty password */
497 password_required_cb(gc, fields);
500 void sipe_purple_login(PurpleAccount *account)
502 PurpleConnection *gc = purple_account_get_connection(account);
503 const gchar *password = purple_connection_get_password(gc);
505 /* Password required? */
506 if (sipe_core_transport_sip_requires_password(get_authentication_type(account),
507 get_sso_flag(account)) &&
508 (!password || !strlen(password)))
509 /* No password set - request one from user */
510 purple_account_request_password(account,
511 G_CALLBACK(password_ok_cb),
512 G_CALLBACK(password_required_cb),
513 gc);
514 else
515 /* No password required or saved password - connect now */
516 connect_to_core(gc, account, password);
520 void sipe_purple_close(PurpleConnection *gc)
522 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
524 if (sipe_public) {
525 struct sipe_backend_private *purple_private = sipe_public->backend_private;
527 sipe_core_deallocate(sipe_public);
529 /* anything left after that must be in pending state... */
530 sipe_purple_dns_query_cancel_all(purple_private);
531 sipe_purple_transport_close_all(purple_private);
533 if (purple_private->roomlist_map)
534 g_hash_table_destroy(purple_private->roomlist_map);
535 sipe_purple_chat_destroy_rejoin(purple_private);
537 if (purple_private->deferred_status_timeout)
538 g_source_remove(purple_private->deferred_status_timeout);
539 g_free(purple_private->deferred_status_note);
541 g_free(purple_private);
542 purple_connection_set_protocol_data(gc, NULL);
546 unsigned int sipe_purple_send_typing(PurpleConnection *gc,
547 const char *who,
548 PurpleIMTypingState state)
550 gboolean typing = (state == PURPLE_IM_TYPING);
552 /* only enable this debug output while testing
553 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
556 * libpurple calls this function with PURPLE_NOT_TYPING *after*
557 * calling sipe_purple_send_im() with the message. This causes
558 * SIPE core to send out two SIP messages to the same dialog in
559 * short succession without waiting for the response to the first
560 * one. Some servers then reject the first one with
562 * SIP/2.0 500 Stale CSeq Value
564 * which triggers a "message not delivered" error for the user.
566 * Work around this by filtering out PURPLE_NOT_TYPING events.
568 if (state != PURPLE_IM_NOT_TYPING)
569 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
570 who,
571 typing);
573 /* tell libpurple to send typing indications every 4 seconds */
574 return(typing ? 4 : 0);
577 void sipe_purple_get_info(PurpleConnection *gc, const char *who)
579 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
580 who);
583 void sipe_purple_add_permit(PurpleConnection *gc, const char *name)
585 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE);
588 void sipe_purple_add_deny(PurpleConnection *gc, const char *name)
590 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, FALSE);
593 void sipe_purple_alias_buddy(PurpleConnection *gc, const char *name,
594 const char *alias)
596 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, alias);
599 void sipe_purple_group_rename(PurpleConnection *gc, const char *old_name,
600 PurpleGroup *group,
601 SIPE_UNUSED_PARAMETER GList *moved_buddies)
603 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
604 old_name,
605 purple_group_get_name(group));
608 void sipe_purple_convo_closed(PurpleConnection *gc, const char *who)
610 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who);
613 void sipe_purple_group_remove(PurpleConnection *gc, PurpleGroup *group)
615 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
616 purple_group_get_name(group));
619 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
620 GHashTable *
621 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount *account)
623 GHashTable *table;
624 table = g_hash_table_new(g_str_hash, g_str_equal);
625 g_hash_table_insert(table, "login_label", (gpointer)_("user@company.com"));
626 return table;
629 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
630 #ifdef HAVE_VV
632 static void
633 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER int signum)
635 capture_pipeline("PURPLE_SIPE_PIPELINE");
638 gboolean sipe_purple_initiate_media(PurpleAccount *account, const char *who,
639 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type)
641 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
642 who,
643 (type & PURPLE_MEDIA_VIDEO));
644 return TRUE;
647 PurpleMediaCaps sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount *account,
648 SIPE_UNUSED_PARAMETER const char *who)
650 return PURPLE_MEDIA_CAPS_AUDIO
651 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
652 | PURPLE_MEDIA_CAPS_MODIFY_SESSION;
654 #endif
655 #endif
656 #endif
658 /* PurplePluginInfo function calls & data structure */
659 gboolean sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
661 #ifdef HAVE_DBUS
662 PURPLE_DBUS_RETURN_FALSE_IF_DISABLED(plugin);
663 purple_dbus_register_bindings(plugin, sipe_purple_dbus_bindings);
664 #endif
666 #ifdef HAVE_VV
668 struct sigaction action;
669 memset(&action, 0, sizeof (action));
670 action.sa_handler = sipe_purple_sigusr1_handler;
671 sigaction(SIGUSR1, &action, NULL);
673 #endif
675 sipe_purple_activity_init();
677 return TRUE;
680 gboolean sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
682 #ifdef HAVE_VV
683 struct sigaction action;
684 memset(&action, 0, sizeof (action));
685 action.sa_handler = SIG_DFL;
686 sigaction(SIGUSR1, &action, NULL);
687 #endif
689 sipe_purple_activity_shutdown();
691 return TRUE;
694 static void sipe_purple_show_about_plugin(PurpleProtocolAction *action)
696 gchar *tmp = sipe_core_about();
697 purple_notify_formatted(SIPE_PURPLE_ACTION_TO_CONNECTION,
698 NULL, " ", NULL, tmp, NULL, NULL);
699 g_free(tmp);
702 static void sipe_purple_join_conference_cb(PurpleConnection *gc,
703 PurpleRequestFields *fields)
705 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
707 if (entries) {
708 const gchar *location = purple_request_fields_get_string(fields,
709 "meetingLocation");
710 const gchar *organizer = purple_request_fields_get_string(fields,
711 "meetingOrganizer");
712 const gchar *meeting_id = purple_request_fields_get_string(fields,
713 "meetingID");
714 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
715 location,
716 organizer,
717 meeting_id);
721 #ifdef HAVE_VV
723 static void sipe_purple_phone_call_cb(PurpleConnection *gc,
724 PurpleRequestFields *fields)
726 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
728 if (entries)
729 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
730 purple_request_fields_get_string(fields,
731 "phoneNumber"));
734 static void sipe_purple_phone_call(PurpleProtocolAction *action)
736 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
737 PurpleRequestFields *fields;
738 PurpleRequestFieldGroup *group;
739 PurpleRequestField *field;
741 fields = purple_request_fields_new();
742 group = purple_request_field_group_new(NULL);
743 purple_request_fields_add_group(fields, group);
745 field = purple_request_field_string_new("phoneNumber", _("Phone number"), NULL, FALSE);
746 purple_request_field_group_add_field(group, field);
748 purple_request_fields(gc,
749 _("Call a phone number"),
750 _("Call a phone number"),
751 NULL,
752 fields,
753 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb),
754 _("_Cancel"), NULL,
755 #if PURPLE_VERSION_CHECK(3,0,0)
756 purple_request_cpar_from_connection(gc),
757 #else
758 purple_connection_get_account(gc), NULL, NULL,
759 #endif
760 gc);
763 static void sipe_purple_test_call(PurpleProtocolAction *action)
765 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
766 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
768 #endif
770 static void sipe_purple_show_join_conference(PurpleProtocolAction *action)
772 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
773 PurpleRequestFields *fields;
774 PurpleRequestFieldGroup *group;
775 PurpleRequestField *field;
777 fields = purple_request_fields_new();
778 group = purple_request_field_group_new(NULL);
779 purple_request_fields_add_group(fields, group);
781 field = purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL, FALSE);
782 purple_request_field_group_add_field(group, field);
783 field = purple_request_field_label_new("separator", _("Alternatively"));
784 purple_request_field_group_add_field(group, field);
785 field = purple_request_field_string_new("meetingOrganizer", _("Organizer email"), NULL, FALSE);
786 purple_request_field_group_add_field(group, field);
787 field = purple_request_field_string_new("meetingID", _("Meeting ID"), NULL, FALSE);
788 purple_request_field_group_add_field(group, field);
790 purple_request_fields(gc,
791 _("Join conference"),
792 _("Join scheduled conference"),
793 _("Enter meeting location string you received in the invitation.\n"
794 "\n"
795 "Valid location will be something like\n"
796 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
797 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
798 "or\n"
799 "https://meet.company.com/someone/abcdef1234"),
800 fields,
801 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb),
802 _("_Cancel"), NULL,
803 #if PURPLE_VERSION_CHECK(3,0,0)
804 purple_request_cpar_from_connection(gc),
805 #else
806 purple_connection_get_account(gc), NULL, NULL,
807 #endif
808 gc);
811 static void sipe_purple_republish_calendar(PurpleProtocolAction *action)
813 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
814 PurpleAccount *account = purple_connection_get_account(gc);
816 if (get_dont_publish_flag(account)) {
817 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
818 _("Publishing of calendar information has been disabled"),
819 NULL);
820 } else {
821 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
825 static void sipe_purple_reset_status(PurpleProtocolAction *action)
827 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
828 PurpleAccount *account = purple_connection_get_account(gc);
830 if (get_dont_publish_flag(account)) {
831 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
832 _("Publishing of calendar information has been disabled"),
833 NULL);
834 } else {
835 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
839 GList *sipe_purple_actions()
841 GList *menu = NULL;
842 PurpleProtocolAction *act;
844 act = purple_protocol_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin);
845 menu = g_list_prepend(menu, act);
847 act = purple_protocol_action_new(_("Contact search..."), sipe_purple_show_find_contact);
848 menu = g_list_prepend(menu, act);
850 #ifdef HAVE_VV
851 act = purple_protocol_action_new(_("Call a phone number..."), sipe_purple_phone_call);
852 menu = g_list_prepend(menu, act);
854 act = purple_protocol_action_new(_("Test call"), sipe_purple_test_call);
855 menu = g_list_prepend(menu, act);
856 #endif
858 act = purple_protocol_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference);
859 menu = g_list_prepend(menu, act);
861 act = purple_protocol_action_new(_("Republish Calendar"), sipe_purple_republish_calendar);
862 menu = g_list_prepend(menu, act);
864 act = purple_protocol_action_new(_("Reset status"), sipe_purple_reset_status);
865 menu = g_list_prepend(menu, act);
867 return g_list_reverse(menu);
870 GList * sipe_purple_account_options()
872 PurpleAccountOption *option;
873 GList *options = NULL;
876 * When adding new string settings please make sure to keep these
877 * in sync:
879 * api/sipe-backend.h
880 * purple-settings.c:setting_name[]
882 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
883 options = g_list_append(options, option);
885 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
886 purple_account_option_add_list_item(option, _("Auto"), "auto");
887 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
888 purple_account_option_add_list_item(option, _("TCP"), "tcp");
889 options = g_list_append(options, option);
891 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
892 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
894 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
895 options = g_list_append(options, option);
897 option = purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL);
898 purple_account_option_add_list_item(option, _("Auto"), "auto");
899 purple_account_option_add_list_item(option, _("NTLM"), "ntlm");
900 #if PURPLE_SIPE_SSO_AND_KERBEROS
901 purple_account_option_add_list_item(option, _("Kerberos"), "krb5");
902 #endif
903 purple_account_option_add_list_item(option, _("TLS-DSK"), "tls-dsk");
904 options = g_list_append(options, option);
906 #if PURPLE_SIPE_SSO_AND_KERBEROS
908 * When the user selects Single Sign-On then SIPE will ignore the
909 * settings for "login name" and "password". Instead it will use the
910 * default credentials provided by the OS.
912 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
913 * SIPE that it is OK to use Single Sign-On or not.
915 * Configurations that are known to support Single Sign-On:
917 * - Windows, host joined to domain, SIPE with SSPI: NTLM
918 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
919 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
921 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE);
922 options = g_list_append(options, option);
923 #endif
925 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
926 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
928 option = purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE);
929 options = g_list_append(options, option);
931 option = purple_account_option_bool_new(_("Show profile pictures from web\n(potentially dangerous)"), "allow-web-photo", FALSE);
932 options = g_list_append(options, option);
934 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
935 options = g_list_append(options, option);
937 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
938 options = g_list_append(options, option);
940 /** Example (Exchange): DOMAIN\user or user@company.com
941 * Example (Domino) : email_address
943 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
944 options = g_list_append(options, option);
946 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
947 purple_account_option_string_set_masked(option, TRUE);
948 options = g_list_append(options, option);
950 /** Example (federated domain): company.com (i.e. ocschat@company.com)
951 * Example (non-default user): user@company.com
953 option = purple_account_option_string_new(_("Group Chat Proxy\n company.com or user@company.com\n(leave empty to determine from Username)"), "groupchat_user", "");
954 options = g_list_append(options, option);
956 #ifdef HAVE_APPSHARE
957 option = purple_account_option_string_new(_("Remote desktop client"), "rdp_client", "");
958 options = g_list_append(options, option);
959 #endif
961 #ifdef HAVE_SRTP
962 option = purple_account_option_list_new(_("Media encryption"), "encryption-policy", NULL);
963 purple_account_option_add_list_item(option, _("Obey server policy"), "obey-server");
964 purple_account_option_add_list_item(option, _("Always"), "required");
965 purple_account_option_add_list_item(option, _("Optional"), "optional");
966 purple_account_option_add_list_item(option, _("Disabled"), "disabled");
967 options = g_list_append(options, option);
968 #endif
970 return options;
973 gpointer sipe_purple_user_split()
975 PurpleAccountUserSplit *split =
976 purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL, ',');
977 purple_account_user_split_set_reverse(split, FALSE);
979 return split;
983 Local Variables:
984 mode: c
985 c-file-style: "bsd"
986 indent-tabs-mode: t
987 tab-width: 8
988 End: