purple: fix compatibility with libpurple 3.x
[siplcs.git] / src / purple / purple-plugin-common.c
bloba1f7ce14db9813e85edf21826ecc59ee177f0295
1 /**
2 * @file purple-plugin-common.c
4 * pidgin-sipe
6 * Copyright (C) 2010-2015 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>
29 #include "sipe-common.h"
31 #include "account.h"
32 #include "accountopt.h"
33 #include "core.h"
34 #include "notify.h"
35 #include "request.h"
36 #include "version.h"
38 /* Backward compatibility when compiling against 2.4.x API */
39 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
40 #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100
41 #endif
43 #if PURPLE_VERSION_CHECK(3,0,0)
44 #define PURPLE_TYPE_STRING G_TYPE_STRING
45 #define SIPE_PURPLE_ACTION_TO_CONNECTION action->connection
46 #else
47 #include "blist.h"
48 #define PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
49 #define PURPLE_CONNECTION_FLAG_FORMATTING_WBFO PURPLE_CONNECTION_FORMATTING_WBFO
50 #define PURPLE_CONNECTION_FLAG_HTML PURPLE_CONNECTION_HTML
51 #define PURPLE_CONNECTION_FLAG_NO_BGCOLOR PURPLE_CONNECTION_NO_BGCOLOR
52 #define PURPLE_CONNECTION_FLAG_NO_FONTSIZE PURPLE_CONNECTION_NO_FONTSIZE
53 #define PURPLE_CONNECTION_FLAG_NO_URLDESC PURPLE_CONNECTION_NO_URLDESC
54 #define PURPLE_IS_BUDDY(n) PURPLE_BLIST_NODE_IS_BUDDY(n)
55 #define PURPLE_IS_CHAT(n) PURPLE_BLIST_NODE_IS_CHAT(n)
56 #define PURPLE_IM_TYPING PURPLE_TYPING
57 #define PURPLE_IM_NOT_TYPING PURPLE_NOT_TYPING
58 #define purple_account_option_string_set_masked(o, f) purple_account_option_set_masked(o, f)
59 #define purple_connection_error(g, e, m) purple_connection_error_reason(g, e, m)
60 #define purple_connection_get_flags(gc) 0
61 #define purple_connection_set_flags(gc, f) gc->flags |= f
62 #define purple_protocol_action_new(l, c) purple_plugin_action_new(l, c)
63 #define PurpleProtocolAction PurplePluginAction
64 #define SIPE_PURPLE_ACTION_TO_CONNECTION action->context
65 #endif
67 #include "sipe-backend.h"
68 #include "sipe-core.h"
69 #include "sipe-nls.h"
71 #include "purple-private.h"
74 * NOTE: this flag means two things:
76 * - is Single Sign-On supported, and
77 * - is Kerberos supported
79 #if defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_SSPI)
80 #define PURPLE_SIPE_SSO_AND_KERBEROS 1
81 #else
82 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
83 #endif
86 * SIPE core activity <-> Purple status mapping
88 * NOTE: this needs to be kept in sync with sipe_purple_status_types()
90 static const gchar * const activity_to_purple_map[SIPE_ACTIVITY_NUM_TYPES] = {
91 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
92 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
93 /* SIPE_ACTIVITY_ONLINE */ "online",
94 /* SIPE_ACTIVITY_INACTIVE */ "idle",
95 /* SIPE_ACTIVITY_BUSY */ "busy",
96 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
97 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
98 /* SIPE_ACTIVITY_BRB */ "be-right-back",
99 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
100 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
101 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
102 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
103 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
104 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
105 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
106 /* SIPE_ACTIVITY_OOF */ "out-of-office",
107 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
108 /* SIPE_ACTIVIY_NUM_TYPES == 17 -> compare to sipe_purple_status_types() */
111 GHashTable *purple_token_map;
113 static void sipe_purple_activity_init(void)
115 guint index;
117 purple_token_map = g_hash_table_new(g_str_hash, g_str_equal);
118 for (index = SIPE_ACTIVITY_UNSET;
119 index < SIPE_ACTIVITY_NUM_TYPES;
120 index++) {
121 g_hash_table_insert(purple_token_map,
122 (gchar *) activity_to_purple_map[index],
123 GUINT_TO_POINTER(index));
127 static void sipe_purple_activity_shutdown(void)
129 g_hash_table_destroy(purple_token_map);
132 const gchar *sipe_purple_activity_to_token(guint type)
134 return(activity_to_purple_map[type]);
137 guint sipe_purple_token_to_activity(const gchar *token)
139 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map, token)));
142 gchar *sipe_backend_version(void)
144 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
147 const char *sipe_purple_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount *a,
148 SIPE_UNUSED_PARAMETER PurpleBuddy *b)
150 return "sipe";
153 gchar *sipe_purple_status_text(PurpleBuddy *buddy)
155 const PurpleStatus *status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
156 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
157 purple_buddy_get_name(buddy),
158 sipe_purple_token_to_activity(purple_status_get_id(status)),
159 purple_status_get_name(status));
162 void sipe_purple_tooltip_text(PurpleBuddy *buddy,
163 PurpleNotifyUserInfo *user_info,
164 SIPE_UNUSED_PARAMETER gboolean full)
166 const PurplePresence *presence = purple_buddy_get_presence(buddy);
167 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
168 purple_buddy_get_name(buddy),
169 purple_status_get_name(purple_presence_get_active_status(presence)),
170 purple_presence_is_online(presence),
171 (struct sipe_backend_buddy_tooltip *) user_info);
174 GList *sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount *acc)
176 PurpleStatusType *type;
177 GList *types = NULL;
179 /* Macro to reduce code repetition
180 Translators: noun */
181 #define SIPE_ADD_STATUS(prim,activity,user) type = purple_status_type_new_with_attrs( \
182 prim, \
183 sipe_purple_activity_to_token(activity), \
184 sipe_core_activity_description(activity), \
185 TRUE, user, FALSE, \
186 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
187 NULL); \
188 types = g_list_append(types, type);
191 * NOTE: needs to be kept in sync with activity_to_purple_map[],
192 * i.e. for each SIPE_ACTIVITY_xxx value there must be an
193 * entry on this list.
195 * NOTE: the following code is sorted by purple primitive type not
196 * by SIPE_ACTIVITY_xxx value.
199 /* 1: Unset - special case: no entry needed */
202 * Status list entries for primitive type AVAILABLE
204 * 2: Available */
205 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
206 SIPE_ACTIVITY_AVAILABLE,
207 TRUE);
209 /* 3: Online */
210 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
211 SIPE_ACTIVITY_ONLINE,
212 FALSE);
214 /* 4: Inactive (Idle) */
215 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
216 SIPE_ACTIVITY_INACTIVE,
217 FALSE);
220 * Status list entries for primitive type UNAVAILABLE
222 * 5: Busy */
223 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
224 SIPE_ACTIVITY_BUSY,
225 TRUE);
227 /* 6: Busy-Idle */
228 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
229 SIPE_ACTIVITY_BUSYIDLE,
230 FALSE);
232 /* 7: Do Not Disturb */
233 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
234 SIPE_ACTIVITY_DND,
235 TRUE);
237 /* 8: In a call */
238 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
239 SIPE_ACTIVITY_ON_PHONE,
240 FALSE);
242 /* 9: In a conference call */
243 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
244 SIPE_ACTIVITY_IN_CONF,
245 FALSE);
247 /* 10: In a meeting */
248 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
249 SIPE_ACTIVITY_IN_MEETING,
250 FALSE);
252 /* 11: Urgent interruptions only */
253 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
254 SIPE_ACTIVITY_URGENT_ONLY,
255 FALSE);
258 * Status list entries for primitive type AWAY
260 * 12: Away - special case: needs to go first in the list as purple
261 * picks the first status with primitive type AWAY for idle
263 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
264 SIPE_ACTIVITY_AWAY,
265 TRUE);
267 /* 13: Be Right Back */
268 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
269 SIPE_ACTIVITY_BRB,
270 TRUE);
272 /* 14: Out to lunch */
273 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
274 SIPE_ACTIVITY_LUNCH,
275 FALSE);
278 * Status list entries for primitive type EXTENDED_AWAY
280 * 15: Out of office */
281 SIPE_ADD_STATUS(PURPLE_STATUS_EXTENDED_AWAY,
282 SIPE_ACTIVITY_OOF,
283 FALSE);
286 * Status list entries for primitive type INVISIBLE
288 * 16: Appear Offline */
289 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE,
290 SIPE_ACTIVITY_INVISIBLE,
291 TRUE);
294 * Status list entries for primitive type OFFLINE
296 * NOTE: this is always the last entry. Compare the number
297 * with the comment in activity_to_purple_map[].
299 * 17: Offline - special case: no message text */
300 type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
301 NULL,
302 NULL,
303 TRUE);
304 types = g_list_append(types, type);
306 return types;
309 GList *sipe_purple_blist_node_menu(PurpleBlistNode *node)
311 if (PURPLE_IS_BUDDY(node))
313 return sipe_purple_buddy_menu((PurpleBuddy *) node);
314 } else
315 if (PURPLE_IS_CHAT(node))
317 return sipe_purple_chat_menu((PurpleChat *)node);
318 } else {
319 return NULL;
323 static guint get_authentication_type(PurpleAccount *account)
325 const gchar *auth = purple_account_get_string(account, "authentication", "ntlm");
327 /* map option list to type - default is automatic */
328 guint authentication_type = SIPE_AUTHENTICATION_TYPE_AUTOMATIC;
329 if (sipe_strequal(auth, "ntlm")) {
330 authentication_type = SIPE_AUTHENTICATION_TYPE_NTLM;
331 } else
332 #if PURPLE_SIPE_SSO_AND_KERBEROS
333 if (sipe_strequal(auth, "krb5")) {
334 authentication_type = SIPE_AUTHENTICATION_TYPE_KERBEROS;
335 } else
336 #endif
337 if (sipe_strequal(auth, "tls-dsk")) {
338 authentication_type = SIPE_AUTHENTICATION_TYPE_TLS_DSK;
341 return(authentication_type);
344 static gboolean get_sso_flag(PurpleAccount *account)
346 #if PURPLE_SIPE_SSO_AND_KERBEROS
348 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
349 * SIPE that it is OK to use Single Sign-On or not.
351 return(purple_account_get_bool(account, "sso", FALSE));
352 #else
353 (void) account; /* keep compiler happy */
354 return(FALSE);
355 #endif
358 static gboolean get_dont_publish_flag(PurpleAccount *account)
360 /* default is to publish calendar information */
361 return(purple_account_get_bool(account, "dont-publish", FALSE));
364 static void connect_to_core(PurpleConnection *gc,
365 PurpleAccount *account,
366 const gchar *password)
368 const gchar *username = purple_account_get_username(account);
369 const gchar *email = purple_account_get_string(account, "email", NULL);
370 const gchar *email_url = purple_account_get_string(account, "email_url", NULL);
371 const gchar *transport = purple_account_get_string(account, "transport", "auto");
372 struct sipe_core_public *sipe_public;
373 gchar **username_split;
374 const gchar *errmsg;
375 guint transport_type;
376 struct sipe_backend_private *purple_private;
378 /* username format: <username>,[<optional login>] */
379 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username);
380 username_split = g_strsplit(username, ",", 2);
382 sipe_public = sipe_core_allocate(username_split[0],
383 get_sso_flag(account),
384 username_split[1],
385 password,
386 email,
387 email_url,
388 &errmsg);
389 g_strfreev(username_split);
391 if (!sipe_public) {
392 purple_connection_error(gc,
393 PURPLE_CONNECTION_ERROR_INVALID_USERNAME,
394 errmsg);
395 return;
398 sipe_public->backend_private = purple_private = g_new0(struct sipe_backend_private, 1);
399 purple_private->public = sipe_public;
400 purple_private->gc = gc;
401 purple_private->account = account;
403 sipe_purple_chat_setup_rejoin(purple_private);
405 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH);
406 if (get_dont_publish_flag(account))
407 SIPE_CORE_FLAG_SET(DONT_PUBLISH);
409 purple_connection_set_protocol_data(gc, sipe_public);
410 purple_connection_set_flags(gc,
411 purple_connection_get_flags(gc) |
412 PURPLE_CONNECTION_FLAG_HTML |
413 PURPLE_CONNECTION_FLAG_FORMATTING_WBFO |
414 PURPLE_CONNECTION_FLAG_NO_BGCOLOR |
415 PURPLE_CONNECTION_FLAG_NO_FONTSIZE |
416 PURPLE_CONNECTION_FLAG_NO_URLDESC |
417 PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY);
418 purple_connection_set_display_name(gc, sipe_public->sip_name);
419 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
421 username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2);
422 if (sipe_strequal(transport, "auto")) {
423 transport_type = (username_split[0] == NULL) ?
424 SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS;
425 } else if (sipe_strequal(transport, "tls")) {
426 transport_type = SIPE_TRANSPORT_TLS;
427 } else {
428 transport_type = SIPE_TRANSPORT_TCP;
430 sipe_core_transport_sip_connect(sipe_public,
431 transport_type,
432 get_authentication_type(account),
433 username_split[0],
434 username_split[0] ? username_split[1] : NULL);
435 g_strfreev(username_split);
438 static void password_required_cb(PurpleConnection *gc,
439 SIPE_UNUSED_PARAMETER PurpleRequestFields *fields)
441 #if !PURPLE_VERSION_CHECK(3,0,0)
442 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
443 return;
445 #endif
447 purple_connection_error(gc,
448 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
449 _("Password required"));
452 static void password_ok_cb(PurpleConnection *gc,
453 PurpleRequestFields *fields)
455 const gchar *password;
457 #if !PURPLE_VERSION_CHECK(3,0,0)
458 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
459 return;
461 #endif
463 password = purple_request_fields_get_string(fields, "password");
465 if (password && strlen(password)) {
466 PurpleAccount *account = purple_connection_get_account(gc);
468 if (purple_request_fields_get_bool(fields, "remember"))
469 purple_account_set_remember_password(account, TRUE);
470 purple_account_set_password(account, password
471 #if PURPLE_VERSION_CHECK(3,0,0)
472 , NULL, NULL
473 #endif
476 /* Now we have a password and we can connect */
477 connect_to_core(gc, account, password);
479 } else
480 /* reject an empty password */
481 password_required_cb(gc, fields);
484 void sipe_purple_login(PurpleAccount *account)
486 PurpleConnection *gc = purple_account_get_connection(account);
487 const gchar *password = purple_connection_get_password(gc);
489 /* Password required? */
490 if (sipe_core_transport_sip_requires_password(get_authentication_type(account),
491 get_sso_flag(account)) &&
492 (!password || !strlen(password)))
493 /* No password set - request one from user */
494 purple_account_request_password(account,
495 G_CALLBACK(password_ok_cb),
496 G_CALLBACK(password_required_cb),
497 gc);
498 else
499 /* No password required or saved password - connect now */
500 connect_to_core(gc, account, password);
504 void sipe_purple_close(PurpleConnection *gc)
506 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
508 if (sipe_public) {
509 struct sipe_backend_private *purple_private = sipe_public->backend_private;
511 sipe_core_deallocate(sipe_public);
513 /* anything left after that must be in pending state... */
514 sipe_purple_dns_query_cancel_all(purple_private);
515 sipe_purple_transport_close_all(purple_private);
517 if (purple_private->roomlist_map)
518 g_hash_table_destroy(purple_private->roomlist_map);
519 sipe_purple_chat_destroy_rejoin(purple_private);
521 if (purple_private->deferred_status_timeout)
522 purple_timeout_remove(purple_private->deferred_status_timeout);
523 g_free(purple_private->deferred_status_note);
525 g_free(purple_private);
526 purple_connection_set_protocol_data(gc, NULL);
530 unsigned int sipe_purple_send_typing(PurpleConnection *gc,
531 const char *who,
532 PurpleIMTypingState state)
534 gboolean typing = (state == PURPLE_IM_TYPING);
536 /* only enable this debug output while testing
537 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
540 * libpurple calls this function with PURPLE_NOT_TYPING *after*
541 * calling sipe_purple_send_im() with the message. This causes
542 * SIPE core to send out two SIP messages to the same dialog in
543 * short succession without waiting for the response to the first
544 * one. Some servers then reject the first one with
546 * SIP/2.0 500 Stale CSeq Value
548 * which triggers a "message not delivered" error for the user.
550 * Work around this by filtering out PURPLE_NOT_TYPING events.
552 if (state != PURPLE_IM_NOT_TYPING)
553 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
554 who,
555 typing);
557 /* tell libpurple to send typing indications every 4 seconds */
558 return(typing ? 4 : 0);
561 void sipe_purple_get_info(PurpleConnection *gc, const char *who)
563 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
564 who);
567 void sipe_purple_add_permit(PurpleConnection *gc, const char *name)
569 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE);
572 void sipe_purple_add_deny(PurpleConnection *gc, const char *name)
574 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, FALSE);
577 void sipe_purple_alias_buddy(PurpleConnection *gc, const char *name,
578 const char *alias)
580 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, alias);
583 void sipe_purple_group_rename(PurpleConnection *gc, const char *old_name,
584 PurpleGroup *group,
585 SIPE_UNUSED_PARAMETER GList *moved_buddies)
587 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
588 old_name,
589 purple_group_get_name(group));
592 void sipe_purple_convo_closed(PurpleConnection *gc, const char *who)
594 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who);
597 void sipe_purple_group_remove(PurpleConnection *gc, PurpleGroup *group)
599 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
600 purple_group_get_name(group));
603 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
604 GHashTable *
605 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount *account)
607 GHashTable *table;
608 table = g_hash_table_new(g_str_hash, g_str_equal);
609 g_hash_table_insert(table, "login_label", (gpointer)_("user@company.com"));
610 return table;
613 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
614 #ifdef HAVE_VV
616 static void
617 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER int signum)
619 capture_pipeline("PURPLE_SIPE_PIPELINE");
622 gboolean sipe_purple_initiate_media(PurpleAccount *account, const char *who,
623 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type)
625 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
626 who,
627 (type & PURPLE_MEDIA_VIDEO));
628 return TRUE;
631 PurpleMediaCaps sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount *account,
632 SIPE_UNUSED_PARAMETER const char *who)
634 return PURPLE_MEDIA_CAPS_AUDIO
635 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
636 | PURPLE_MEDIA_CAPS_MODIFY_SESSION;
638 #endif
639 #endif
640 #endif
642 /* PurplePluginInfo function calls & data structure */
643 gboolean sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
645 #ifdef HAVE_VV
646 struct sigaction action;
647 memset(&action, 0, sizeof (action));
648 action.sa_handler = sipe_purple_sigusr1_handler;
649 sigaction(SIGUSR1, &action, NULL);
650 #endif
652 sipe_purple_activity_init();
654 return TRUE;
657 gboolean sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
659 #ifdef HAVE_VV
660 struct sigaction action;
661 memset(&action, 0, sizeof (action));
662 action.sa_handler = SIG_DFL;
663 sigaction(SIGUSR1, &action, NULL);
664 #endif
666 sipe_purple_activity_shutdown();
668 return TRUE;
671 static void sipe_purple_show_about_plugin(PurpleProtocolAction *action)
673 gchar *tmp = sipe_core_about();
674 purple_notify_formatted(SIPE_PURPLE_ACTION_TO_CONNECTION,
675 NULL, " ", NULL, tmp, NULL, NULL);
676 g_free(tmp);
679 static void sipe_purple_join_conference_cb(PurpleConnection *gc,
680 PurpleRequestFields *fields)
682 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
684 if (entries) {
685 PurpleRequestField *field = entries->data;
686 const char *id = purple_request_field_get_id(field);
687 const char *value = purple_request_field_string_get_value(field);
689 if (!sipe_strequal(id, "meetingLocation"))
690 return;
692 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC, value);
696 #ifdef HAVE_VV
698 static void sipe_purple_phone_call_cb(PurpleConnection *gc,
699 PurpleRequestFields *fields)
701 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
703 if (entries) {
704 PurpleRequestField *field = entries->data;
705 const char *id = purple_request_field_get_id(field);
706 const char *value = purple_request_field_string_get_value(field);
708 if (!sipe_strequal(id, "phoneNumber"))
709 return;
711 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC, value);
715 static void sipe_purple_phone_call(PurpleProtocolAction *action)
717 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
718 PurpleRequestFields *fields;
719 PurpleRequestFieldGroup *group;
720 PurpleRequestField *field;
722 fields = purple_request_fields_new();
723 group = purple_request_field_group_new(NULL);
724 purple_request_fields_add_group(fields, group);
726 field = purple_request_field_string_new("phoneNumber", _("Phone number"), NULL, FALSE);
727 purple_request_field_group_add_field(group, field);
729 purple_request_fields(gc,
730 _("Call a phone number"),
731 _("Call a phone number"),
732 NULL,
733 fields,
734 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb),
735 _("_Cancel"), NULL,
736 #if PURPLE_VERSION_CHECK(3,0,0)
737 purple_request_cpar_from_connection(gc),
738 #else
739 purple_connection_get_account(gc), NULL, NULL,
740 #endif
741 gc);
744 static void sipe_purple_test_call(PurpleProtocolAction *action)
746 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
747 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
749 #endif
751 static void sipe_purple_show_join_conference(PurpleProtocolAction *action)
753 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
754 PurpleRequestFields *fields;
755 PurpleRequestFieldGroup *group;
756 PurpleRequestField *field;
758 fields = purple_request_fields_new();
759 group = purple_request_field_group_new(NULL);
760 purple_request_fields_add_group(fields, group);
762 field = purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL, FALSE);
763 purple_request_field_group_add_field(group, field);
765 purple_request_fields(gc,
766 _("Join conference"),
767 _("Join scheduled conference"),
768 _("Enter meeting location string you received in the invitation.\n"
769 "\n"
770 "Valid location will be something like\n"
771 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
772 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
773 "or\n"
774 "https://meet.company.com/someone/abcdef1234"),
775 fields,
776 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb),
777 _("_Cancel"), NULL,
778 #if PURPLE_VERSION_CHECK(3,0,0)
779 purple_request_cpar_from_connection(gc),
780 #else
781 purple_connection_get_account(gc), NULL, NULL,
782 #endif
783 gc);
786 static void sipe_purple_republish_calendar(PurpleProtocolAction *action)
788 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
789 PurpleAccount *account = purple_connection_get_account(gc);
791 if (get_dont_publish_flag(account)) {
792 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
793 _("Publishing of calendar information has been disabled"),
794 NULL);
795 } else {
796 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
800 static void sipe_purple_reset_status(PurpleProtocolAction *action)
802 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
803 PurpleAccount *account = purple_connection_get_account(gc);
805 if (get_dont_publish_flag(account)) {
806 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
807 _("Publishing of calendar information has been disabled"),
808 NULL);
809 } else {
810 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
814 GList *sipe_purple_actions()
816 GList *menu = NULL;
817 PurpleProtocolAction *act;
819 act = purple_protocol_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin);
820 menu = g_list_prepend(menu, act);
822 act = purple_protocol_action_new(_("Contact search..."), sipe_purple_show_find_contact);
823 menu = g_list_prepend(menu, act);
825 #ifdef HAVE_VV
826 act = purple_protocol_action_new(_("Call a phone number..."), sipe_purple_phone_call);
827 menu = g_list_prepend(menu, act);
829 act = purple_protocol_action_new(_("Test call"), sipe_purple_test_call);
830 menu = g_list_prepend(menu, act);
831 #endif
833 act = purple_protocol_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference);
834 menu = g_list_prepend(menu, act);
836 act = purple_protocol_action_new(_("Republish Calendar"), sipe_purple_republish_calendar);
837 menu = g_list_prepend(menu, act);
839 act = purple_protocol_action_new(_("Reset status"), sipe_purple_reset_status);
840 menu = g_list_prepend(menu, act);
842 return g_list_reverse(menu);
845 GList * sipe_purple_account_options()
847 PurpleAccountOption *option;
848 GList *options = NULL;
851 * When adding new string settings please make sure to keep these
852 * in sync:
854 * api/sipe-backend.h
855 * purple-settings.c:setting_name[]
857 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
858 options = g_list_append(options, option);
860 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
861 purple_account_option_add_list_item(option, _("Auto"), "auto");
862 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
863 purple_account_option_add_list_item(option, _("TCP"), "tcp");
864 options = g_list_append(options, option);
866 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
867 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
869 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
870 options = g_list_append(options, option);
872 option = purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL);
873 purple_account_option_add_list_item(option, _("Auto"), "auto");
874 purple_account_option_add_list_item(option, _("NTLM"), "ntlm");
875 #if PURPLE_SIPE_SSO_AND_KERBEROS
876 purple_account_option_add_list_item(option, _("Kerberos"), "krb5");
877 #endif
878 purple_account_option_add_list_item(option, _("TLS-DSK"), "tls-dsk");
879 options = g_list_append(options, option);
881 #if PURPLE_SIPE_SSO_AND_KERBEROS
883 * When the user selects Single Sign-On then SIPE will ignore the
884 * settings for "login name" and "password". Instead it will use the
885 * default credentials provided by the OS.
887 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
888 * SIPE that it is OK to use Single Sign-On or not.
890 * Configurations that are known to support Single Sign-On:
892 * - Windows, host joined to domain, SIPE with SSPI: NTLM
893 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
894 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
896 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE);
897 options = g_list_append(options, option);
898 #endif
900 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
901 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
903 option = purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE);
904 options = g_list_append(options, option);
906 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
907 options = g_list_append(options, option);
909 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
910 options = g_list_append(options, option);
912 /** Example (Exchange): DOMAIN\user or user@company.com
913 * Example (Domino) : email_address
915 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
916 options = g_list_append(options, option);
918 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
919 purple_account_option_string_set_masked(option, TRUE);
920 options = g_list_append(options, option);
922 /** Example (federated domain): company.com (i.e. ocschat@company.com)
923 * Example (non-default user): user@company.com
925 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", "");
926 options = g_list_append(options, option);
928 #ifdef HAVE_SRTP
929 option = purple_account_option_list_new(_("Media encryption"), "encryption-policy", NULL);
930 purple_account_option_add_list_item(option, _("Obey server policy"), "obey-server");
931 purple_account_option_add_list_item(option, _("Always"), "required");
932 purple_account_option_add_list_item(option, _("Optional"), "optional");
933 purple_account_option_add_list_item(option, _("Disabled"), "disabled");
934 options = g_list_append(options, option);
935 #endif
937 return options;
940 gpointer sipe_purple_user_split()
942 PurpleAccountUserSplit *split =
943 purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL, ',');
944 purple_account_user_split_set_reverse(split, FALSE);
946 return split;
950 Local Variables:
951 mode: c
952 c-file-style: "bsd"
953 indent-tabs-mode: t
954 tab-width: 8
955 End: