OBS: updates for Ubuntu 16.04
[siplcs.git] / src / purple / purple-plugin-common.c
blobfb1497424113882e29fb652ac211a5d4bae7cfb9
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>
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 /* Backward compatibility when compiling against 2.4.x API */
40 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
41 #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100
42 #endif
44 #if PURPLE_VERSION_CHECK(3,0,0)
45 #define PURPLE_TYPE_STRING G_TYPE_STRING
46 #define SIPE_PURPLE_ACTION_TO_CONNECTION action->connection
47 #else
48 #include "blist.h"
49 #define PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
50 #define PURPLE_CONNECTION_FLAG_FORMATTING_WBFO PURPLE_CONNECTION_FORMATTING_WBFO
51 #define PURPLE_CONNECTION_FLAG_HTML PURPLE_CONNECTION_HTML
52 #define PURPLE_CONNECTION_FLAG_NO_BGCOLOR PURPLE_CONNECTION_NO_BGCOLOR
53 #define PURPLE_CONNECTION_FLAG_NO_FONTSIZE PURPLE_CONNECTION_NO_FONTSIZE
54 #define PURPLE_CONNECTION_FLAG_NO_URLDESC PURPLE_CONNECTION_NO_URLDESC
55 #define PURPLE_IS_BUDDY(n) PURPLE_BLIST_NODE_IS_BUDDY(n)
56 #define PURPLE_IS_CHAT(n) PURPLE_BLIST_NODE_IS_CHAT(n)
57 #define PURPLE_IM_TYPING PURPLE_TYPING
58 #define PURPLE_IM_NOT_TYPING PURPLE_NOT_TYPING
59 #define purple_account_option_string_set_masked(o, f) purple_account_option_set_masked(o, f)
60 #define purple_connection_error(g, e, m) purple_connection_error_reason(g, e, m)
61 #define purple_connection_get_flags(gc) 0
62 #define purple_connection_set_protocol_data(gc, p) gc->proto_data = p
63 #define purple_connection_set_flags(gc, f) gc->flags |= f
64 #define purple_protocol_action_new(l, c) purple_plugin_action_new(l, c)
65 #define PurpleProtocolAction PurplePluginAction
66 #define SIPE_PURPLE_ACTION_TO_CONNECTION action->context
67 #endif
69 #include "sipe-backend.h"
70 #include "sipe-core.h"
71 #include "sipe-nls.h"
73 #include "purple-private.h"
76 * NOTE: this flag means two things:
78 * - is Single Sign-On supported, and
79 * - is Kerberos supported
81 #if defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_SSPI)
82 #define PURPLE_SIPE_SSO_AND_KERBEROS 1
83 #else
84 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
85 #endif
88 * SIPE core activity <-> Purple status mapping
90 * NOTE: this needs to be kept in sync with sipe_purple_status_types()
92 static const gchar * const activity_to_purple_map[SIPE_ACTIVITY_NUM_TYPES] = {
93 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
94 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
95 /* SIPE_ACTIVITY_ONLINE */ "online",
96 /* SIPE_ACTIVITY_INACTIVE */ "idle",
97 /* SIPE_ACTIVITY_BUSY */ "busy",
98 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
99 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
100 /* SIPE_ACTIVITY_BRB */ "be-right-back",
101 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
102 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
103 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
104 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
105 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
106 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
107 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
108 /* SIPE_ACTIVITY_OOF */ "out-of-office",
109 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
110 /* SIPE_ACTIVIY_NUM_TYPES == 17 -> compare to sipe_purple_status_types() */
113 GHashTable *purple_token_map;
115 static void sipe_purple_activity_init(void)
117 guint index;
119 purple_token_map = g_hash_table_new(g_str_hash, g_str_equal);
120 for (index = SIPE_ACTIVITY_UNSET;
121 index < SIPE_ACTIVITY_NUM_TYPES;
122 index++) {
123 g_hash_table_insert(purple_token_map,
124 (gchar *) activity_to_purple_map[index],
125 GUINT_TO_POINTER(index));
129 static void sipe_purple_activity_shutdown(void)
131 g_hash_table_destroy(purple_token_map);
134 const gchar *sipe_purple_activity_to_token(guint type)
136 return(activity_to_purple_map[type]);
139 guint sipe_purple_token_to_activity(const gchar *token)
141 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map, token)));
144 gchar *sipe_backend_version(void)
146 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
149 const char *sipe_purple_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount *a,
150 SIPE_UNUSED_PARAMETER PurpleBuddy *b)
152 return "sipe";
155 gchar *sipe_purple_status_text(PurpleBuddy *buddy)
157 const PurpleStatus *status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
158 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
159 purple_buddy_get_name(buddy),
160 sipe_purple_token_to_activity(purple_status_get_id(status)),
161 purple_status_get_name(status));
164 void sipe_purple_tooltip_text(PurpleBuddy *buddy,
165 PurpleNotifyUserInfo *user_info,
166 SIPE_UNUSED_PARAMETER gboolean full)
168 const PurplePresence *presence = purple_buddy_get_presence(buddy);
169 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
170 purple_buddy_get_name(buddy),
171 purple_status_get_name(purple_presence_get_active_status(presence)),
172 purple_presence_is_online(presence),
173 (struct sipe_backend_buddy_tooltip *) user_info);
176 GList *sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount *acc)
178 PurpleStatusType *type;
179 GList *types = NULL;
181 /* Macro to reduce code repetition
182 Translators: noun */
183 #define SIPE_ADD_STATUS(prim,activity,user) type = purple_status_type_new_with_attrs( \
184 prim, \
185 sipe_purple_activity_to_token(activity), \
186 sipe_core_activity_description(activity), \
187 TRUE, user, FALSE, \
188 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
189 NULL); \
190 types = g_list_append(types, type);
193 * NOTE: needs to be kept in sync with activity_to_purple_map[],
194 * i.e. for each SIPE_ACTIVITY_xxx value there must be an
195 * entry on this list.
197 * NOTE: the following code is sorted by purple primitive type not
198 * by SIPE_ACTIVITY_xxx value.
201 /* 1: Unset - special case: no entry needed */
204 * Status list entries for primitive type AVAILABLE
206 * 2: Available */
207 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
208 SIPE_ACTIVITY_AVAILABLE,
209 TRUE);
211 /* 3: Online */
212 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
213 SIPE_ACTIVITY_ONLINE,
214 FALSE);
216 /* 4: Inactive (Idle) */
217 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
218 SIPE_ACTIVITY_INACTIVE,
219 FALSE);
222 * Status list entries for primitive type UNAVAILABLE
224 * 5: Busy */
225 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
226 SIPE_ACTIVITY_BUSY,
227 TRUE);
229 /* 6: Busy-Idle */
230 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
231 SIPE_ACTIVITY_BUSYIDLE,
232 FALSE);
234 /* 7: Do Not Disturb */
235 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
236 SIPE_ACTIVITY_DND,
237 TRUE);
239 /* 8: In a call */
240 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
241 SIPE_ACTIVITY_ON_PHONE,
242 FALSE);
244 /* 9: In a conference call */
245 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
246 SIPE_ACTIVITY_IN_CONF,
247 FALSE);
249 /* 10: In a meeting */
250 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
251 SIPE_ACTIVITY_IN_MEETING,
252 FALSE);
254 /* 11: Urgent interruptions only */
255 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
256 SIPE_ACTIVITY_URGENT_ONLY,
257 FALSE);
260 * Status list entries for primitive type AWAY
262 * 12: Away - special case: needs to go first in the list as purple
263 * picks the first status with primitive type AWAY for idle
265 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
266 SIPE_ACTIVITY_AWAY,
267 TRUE);
269 /* 13: Be Right Back */
270 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
271 SIPE_ACTIVITY_BRB,
272 TRUE);
274 /* 14: Out to lunch */
275 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
276 SIPE_ACTIVITY_LUNCH,
277 FALSE);
280 * Status list entries for primitive type EXTENDED_AWAY
282 * 15: Out of office */
283 SIPE_ADD_STATUS(PURPLE_STATUS_EXTENDED_AWAY,
284 SIPE_ACTIVITY_OOF,
285 FALSE);
288 * Status list entries for primitive type INVISIBLE
290 * 16: Appear Offline */
291 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE,
292 SIPE_ACTIVITY_INVISIBLE,
293 TRUE);
296 * Status list entries for primitive type OFFLINE
298 * NOTE: this is always the last entry. Compare the number
299 * with the comment in activity_to_purple_map[].
301 * 17: Offline - special case: no message text */
302 type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
303 NULL,
304 NULL,
305 TRUE);
306 types = g_list_append(types, type);
308 return types;
311 GList *sipe_purple_blist_node_menu(PurpleBlistNode *node)
313 if (PURPLE_IS_BUDDY(node))
315 return sipe_purple_buddy_menu((PurpleBuddy *) node);
316 } else
317 if (PURPLE_IS_CHAT(node))
319 return sipe_purple_chat_menu((PurpleChat *)node);
320 } else {
321 return NULL;
325 static guint get_authentication_type(PurpleAccount *account)
327 const gchar *auth = purple_account_get_string(account, "authentication", "ntlm");
329 /* map option list to type - default is automatic */
330 guint authentication_type = SIPE_AUTHENTICATION_TYPE_AUTOMATIC;
331 if (sipe_strequal(auth, "ntlm")) {
332 authentication_type = SIPE_AUTHENTICATION_TYPE_NTLM;
333 } else
334 #if PURPLE_SIPE_SSO_AND_KERBEROS
335 if (sipe_strequal(auth, "krb5")) {
336 authentication_type = SIPE_AUTHENTICATION_TYPE_KERBEROS;
337 } else
338 #endif
339 if (sipe_strequal(auth, "tls-dsk")) {
340 authentication_type = SIPE_AUTHENTICATION_TYPE_TLS_DSK;
343 return(authentication_type);
346 static gboolean get_sso_flag(PurpleAccount *account)
348 #if PURPLE_SIPE_SSO_AND_KERBEROS
350 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
351 * SIPE that it is OK to use Single Sign-On or not.
353 return(purple_account_get_bool(account, "sso", FALSE));
354 #else
355 (void) account; /* keep compiler happy */
356 return(FALSE);
357 #endif
360 static gboolean get_dont_publish_flag(PurpleAccount *account)
362 /* default is to publish calendar information */
363 return(purple_account_get_bool(account, "dont-publish", FALSE));
366 static void connect_to_core(PurpleConnection *gc,
367 PurpleAccount *account,
368 const gchar *password)
370 const gchar *username = purple_account_get_username(account);
371 const gchar *email = purple_account_get_string(account, "email", NULL);
372 const gchar *email_url = purple_account_get_string(account, "email_url", NULL);
373 const gchar *transport = purple_account_get_string(account, "transport", "auto");
374 struct sipe_core_public *sipe_public;
375 gchar **username_split;
376 const gchar *errmsg;
377 guint transport_type;
378 struct sipe_backend_private *purple_private;
380 /* username format: <username>,[<optional login>] */
381 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username);
382 username_split = g_strsplit(username, ",", 2);
384 sipe_public = sipe_core_allocate(username_split[0],
385 get_sso_flag(account),
386 username_split[1],
387 password,
388 email,
389 email_url,
390 &errmsg);
391 g_strfreev(username_split);
393 if (!sipe_public) {
394 purple_connection_error(gc,
395 PURPLE_CONNECTION_ERROR_INVALID_USERNAME,
396 errmsg);
397 return;
400 sipe_public->backend_private = purple_private = g_new0(struct sipe_backend_private, 1);
401 purple_private->public = sipe_public;
402 purple_private->gc = gc;
403 purple_private->account = account;
405 sipe_purple_chat_setup_rejoin(purple_private);
407 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH);
408 if (get_dont_publish_flag(account))
409 SIPE_CORE_FLAG_SET(DONT_PUBLISH);
411 purple_connection_set_protocol_data(gc, sipe_public);
412 purple_connection_set_flags(gc,
413 purple_connection_get_flags(gc) |
414 PURPLE_CONNECTION_FLAG_HTML |
415 PURPLE_CONNECTION_FLAG_FORMATTING_WBFO |
416 PURPLE_CONNECTION_FLAG_NO_BGCOLOR |
417 PURPLE_CONNECTION_FLAG_NO_FONTSIZE |
418 PURPLE_CONNECTION_FLAG_NO_URLDESC |
419 PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY);
420 purple_connection_set_display_name(gc, sipe_public->sip_name);
421 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
423 username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2);
424 if (sipe_strequal(transport, "auto")) {
425 transport_type = (username_split[0] == NULL) ?
426 SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS;
427 } else if (sipe_strequal(transport, "tls")) {
428 transport_type = SIPE_TRANSPORT_TLS;
429 } else {
430 transport_type = SIPE_TRANSPORT_TCP;
432 sipe_core_transport_sip_connect(sipe_public,
433 transport_type,
434 get_authentication_type(account),
435 username_split[0],
436 username_split[0] ? username_split[1] : NULL);
437 g_strfreev(username_split);
440 static void password_required_cb(PurpleConnection *gc,
441 SIPE_UNUSED_PARAMETER PurpleRequestFields *fields)
443 #if !PURPLE_VERSION_CHECK(3,0,0)
444 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
445 return;
447 #endif
449 purple_connection_error(gc,
450 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
451 _("Password required"));
454 static void password_ok_cb(PurpleConnection *gc,
455 PurpleRequestFields *fields)
457 const gchar *password;
459 #if !PURPLE_VERSION_CHECK(3,0,0)
460 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
461 return;
463 #endif
465 password = purple_request_fields_get_string(fields, "password");
467 if (password && strlen(password)) {
468 PurpleAccount *account = purple_connection_get_account(gc);
470 if (purple_request_fields_get_bool(fields, "remember"))
471 purple_account_set_remember_password(account, TRUE);
472 purple_account_set_password(account, password
473 #if PURPLE_VERSION_CHECK(3,0,0)
474 , NULL, NULL
475 #endif
478 /* Now we have a password and we can connect */
479 connect_to_core(gc, account, password);
481 } else
482 /* reject an empty password */
483 password_required_cb(gc, fields);
486 void sipe_purple_login(PurpleAccount *account)
488 PurpleConnection *gc = purple_account_get_connection(account);
489 const gchar *password = purple_connection_get_password(gc);
491 /* Password required? */
492 if (sipe_core_transport_sip_requires_password(get_authentication_type(account),
493 get_sso_flag(account)) &&
494 (!password || !strlen(password)))
495 /* No password set - request one from user */
496 purple_account_request_password(account,
497 G_CALLBACK(password_ok_cb),
498 G_CALLBACK(password_required_cb),
499 gc);
500 else
501 /* No password required or saved password - connect now */
502 connect_to_core(gc, account, password);
506 void sipe_purple_close(PurpleConnection *gc)
508 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
510 if (sipe_public) {
511 struct sipe_backend_private *purple_private = sipe_public->backend_private;
513 sipe_core_deallocate(sipe_public);
515 /* anything left after that must be in pending state... */
516 sipe_purple_dns_query_cancel_all(purple_private);
517 sipe_purple_transport_close_all(purple_private);
519 if (purple_private->roomlist_map)
520 g_hash_table_destroy(purple_private->roomlist_map);
521 sipe_purple_chat_destroy_rejoin(purple_private);
523 if (purple_private->deferred_status_timeout)
524 purple_timeout_remove(purple_private->deferred_status_timeout);
525 g_free(purple_private->deferred_status_note);
527 g_free(purple_private);
528 purple_connection_set_protocol_data(gc, NULL);
532 unsigned int sipe_purple_send_typing(PurpleConnection *gc,
533 const char *who,
534 PurpleIMTypingState state)
536 gboolean typing = (state == PURPLE_IM_TYPING);
538 /* only enable this debug output while testing
539 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
542 * libpurple calls this function with PURPLE_NOT_TYPING *after*
543 * calling sipe_purple_send_im() with the message. This causes
544 * SIPE core to send out two SIP messages to the same dialog in
545 * short succession without waiting for the response to the first
546 * one. Some servers then reject the first one with
548 * SIP/2.0 500 Stale CSeq Value
550 * which triggers a "message not delivered" error for the user.
552 * Work around this by filtering out PURPLE_NOT_TYPING events.
554 if (state != PURPLE_IM_NOT_TYPING)
555 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
556 who,
557 typing);
559 /* tell libpurple to send typing indications every 4 seconds */
560 return(typing ? 4 : 0);
563 void sipe_purple_get_info(PurpleConnection *gc, const char *who)
565 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
566 who);
569 void sipe_purple_add_permit(PurpleConnection *gc, const char *name)
571 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE);
574 void sipe_purple_add_deny(PurpleConnection *gc, const char *name)
576 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, FALSE);
579 void sipe_purple_alias_buddy(PurpleConnection *gc, const char *name,
580 const char *alias)
582 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, alias);
585 void sipe_purple_group_rename(PurpleConnection *gc, const char *old_name,
586 PurpleGroup *group,
587 SIPE_UNUSED_PARAMETER GList *moved_buddies)
589 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
590 old_name,
591 purple_group_get_name(group));
594 void sipe_purple_convo_closed(PurpleConnection *gc, const char *who)
596 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who);
599 void sipe_purple_group_remove(PurpleConnection *gc, PurpleGroup *group)
601 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
602 purple_group_get_name(group));
605 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
606 GHashTable *
607 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount *account)
609 GHashTable *table;
610 table = g_hash_table_new(g_str_hash, g_str_equal);
611 g_hash_table_insert(table, "login_label", (gpointer)_("user@company.com"));
612 return table;
615 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
616 #ifdef HAVE_VV
618 static void
619 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER int signum)
621 capture_pipeline("PURPLE_SIPE_PIPELINE");
624 gboolean sipe_purple_initiate_media(PurpleAccount *account, const char *who,
625 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type)
627 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
628 who,
629 (type & PURPLE_MEDIA_VIDEO));
630 return TRUE;
633 PurpleMediaCaps sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount *account,
634 SIPE_UNUSED_PARAMETER const char *who)
636 return PURPLE_MEDIA_CAPS_AUDIO
637 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
638 | PURPLE_MEDIA_CAPS_MODIFY_SESSION;
640 #endif
641 #endif
642 #endif
644 /* PurplePluginInfo function calls & data structure */
645 gboolean sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
647 #ifdef HAVE_VV
648 struct sigaction action;
649 memset(&action, 0, sizeof (action));
650 action.sa_handler = sipe_purple_sigusr1_handler;
651 sigaction(SIGUSR1, &action, NULL);
652 #endif
654 sipe_purple_activity_init();
656 return TRUE;
659 gboolean sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
661 #ifdef HAVE_VV
662 struct sigaction action;
663 memset(&action, 0, sizeof (action));
664 action.sa_handler = SIG_DFL;
665 sigaction(SIGUSR1, &action, NULL);
666 #endif
668 sipe_purple_activity_shutdown();
670 return TRUE;
673 static void sipe_purple_show_about_plugin(PurpleProtocolAction *action)
675 gchar *tmp = sipe_core_about();
676 purple_notify_formatted(SIPE_PURPLE_ACTION_TO_CONNECTION,
677 NULL, " ", NULL, tmp, NULL, NULL);
678 g_free(tmp);
681 static void sipe_purple_join_conference_cb(PurpleConnection *gc,
682 PurpleRequestFields *fields)
684 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
686 if (entries) {
687 const gchar *location = purple_request_fields_get_string(fields,
688 "meetingLocation");
689 const gchar *organizer = purple_request_fields_get_string(fields,
690 "meetingOrganizer");
691 const gchar *meeting_id = purple_request_fields_get_string(fields,
692 "meetingID");
693 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
694 location,
695 organizer,
696 meeting_id);
700 #ifdef HAVE_VV
702 static void sipe_purple_phone_call_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 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
709 purple_request_fields_get_string(fields,
710 "phoneNumber"));
713 static void sipe_purple_phone_call(PurpleProtocolAction *action)
715 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
716 PurpleRequestFields *fields;
717 PurpleRequestFieldGroup *group;
718 PurpleRequestField *field;
720 fields = purple_request_fields_new();
721 group = purple_request_field_group_new(NULL);
722 purple_request_fields_add_group(fields, group);
724 field = purple_request_field_string_new("phoneNumber", _("Phone number"), NULL, FALSE);
725 purple_request_field_group_add_field(group, field);
727 purple_request_fields(gc,
728 _("Call a phone number"),
729 _("Call a phone number"),
730 NULL,
731 fields,
732 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb),
733 _("_Cancel"), NULL,
734 #if PURPLE_VERSION_CHECK(3,0,0)
735 purple_request_cpar_from_connection(gc),
736 #else
737 purple_connection_get_account(gc), NULL, NULL,
738 #endif
739 gc);
742 static void sipe_purple_test_call(PurpleProtocolAction *action)
744 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
745 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
747 #endif
749 static void sipe_purple_show_join_conference(PurpleProtocolAction *action)
751 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
752 PurpleRequestFields *fields;
753 PurpleRequestFieldGroup *group;
754 PurpleRequestField *field;
756 fields = purple_request_fields_new();
757 group = purple_request_field_group_new(NULL);
758 purple_request_fields_add_group(fields, group);
760 field = purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL, FALSE);
761 purple_request_field_group_add_field(group, field);
762 field = purple_request_field_label_new("separator", _("Alternatively"));
763 purple_request_field_group_add_field(group, field);
764 field = purple_request_field_string_new("meetingOrganizer", _("Organizer email"), NULL, FALSE);
765 purple_request_field_group_add_field(group, field);
766 field = purple_request_field_string_new("meetingID", _("Meeting ID"), NULL, FALSE);
767 purple_request_field_group_add_field(group, field);
769 purple_request_fields(gc,
770 _("Join conference"),
771 _("Join scheduled conference"),
772 _("Enter meeting location string you received in the invitation.\n"
773 "\n"
774 "Valid location will be something like\n"
775 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
776 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
777 "or\n"
778 "https://meet.company.com/someone/abcdef1234"),
779 fields,
780 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb),
781 _("_Cancel"), NULL,
782 #if PURPLE_VERSION_CHECK(3,0,0)
783 purple_request_cpar_from_connection(gc),
784 #else
785 purple_connection_get_account(gc), NULL, NULL,
786 #endif
787 gc);
790 static void sipe_purple_republish_calendar(PurpleProtocolAction *action)
792 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
793 PurpleAccount *account = purple_connection_get_account(gc);
795 if (get_dont_publish_flag(account)) {
796 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
797 _("Publishing of calendar information has been disabled"),
798 NULL);
799 } else {
800 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
804 static void sipe_purple_reset_status(PurpleProtocolAction *action)
806 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
807 PurpleAccount *account = purple_connection_get_account(gc);
809 if (get_dont_publish_flag(account)) {
810 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
811 _("Publishing of calendar information has been disabled"),
812 NULL);
813 } else {
814 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
818 GList *sipe_purple_actions()
820 GList *menu = NULL;
821 PurpleProtocolAction *act;
823 act = purple_protocol_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin);
824 menu = g_list_prepend(menu, act);
826 act = purple_protocol_action_new(_("Contact search..."), sipe_purple_show_find_contact);
827 menu = g_list_prepend(menu, act);
829 #ifdef HAVE_VV
830 act = purple_protocol_action_new(_("Call a phone number..."), sipe_purple_phone_call);
831 menu = g_list_prepend(menu, act);
833 act = purple_protocol_action_new(_("Test call"), sipe_purple_test_call);
834 menu = g_list_prepend(menu, act);
835 #endif
837 act = purple_protocol_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference);
838 menu = g_list_prepend(menu, act);
840 act = purple_protocol_action_new(_("Republish Calendar"), sipe_purple_republish_calendar);
841 menu = g_list_prepend(menu, act);
843 act = purple_protocol_action_new(_("Reset status"), sipe_purple_reset_status);
844 menu = g_list_prepend(menu, act);
846 return g_list_reverse(menu);
849 GList * sipe_purple_account_options()
851 PurpleAccountOption *option;
852 GList *options = NULL;
855 * When adding new string settings please make sure to keep these
856 * in sync:
858 * api/sipe-backend.h
859 * purple-settings.c:setting_name[]
861 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
862 options = g_list_append(options, option);
864 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
865 purple_account_option_add_list_item(option, _("Auto"), "auto");
866 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
867 purple_account_option_add_list_item(option, _("TCP"), "tcp");
868 options = g_list_append(options, option);
870 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
871 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
873 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
874 options = g_list_append(options, option);
876 option = purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL);
877 purple_account_option_add_list_item(option, _("Auto"), "auto");
878 purple_account_option_add_list_item(option, _("NTLM"), "ntlm");
879 #if PURPLE_SIPE_SSO_AND_KERBEROS
880 purple_account_option_add_list_item(option, _("Kerberos"), "krb5");
881 #endif
882 purple_account_option_add_list_item(option, _("TLS-DSK"), "tls-dsk");
883 options = g_list_append(options, option);
885 #if PURPLE_SIPE_SSO_AND_KERBEROS
887 * When the user selects Single Sign-On then SIPE will ignore the
888 * settings for "login name" and "password". Instead it will use the
889 * default credentials provided by the OS.
891 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
892 * SIPE that it is OK to use Single Sign-On or not.
894 * Configurations that are known to support Single Sign-On:
896 * - Windows, host joined to domain, SIPE with SSPI: NTLM
897 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
898 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
900 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE);
901 options = g_list_append(options, option);
902 #endif
904 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
905 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
907 option = purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE);
908 options = g_list_append(options, option);
910 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
911 options = g_list_append(options, option);
913 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
914 options = g_list_append(options, option);
916 /** Example (Exchange): DOMAIN\user or user@company.com
917 * Example (Domino) : email_address
919 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
920 options = g_list_append(options, option);
922 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
923 purple_account_option_string_set_masked(option, TRUE);
924 options = g_list_append(options, option);
926 /** Example (federated domain): company.com (i.e. ocschat@company.com)
927 * Example (non-default user): user@company.com
929 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", "");
930 options = g_list_append(options, option);
932 #ifdef HAVE_SRTP
933 option = purple_account_option_list_new(_("Media encryption"), "encryption-policy", NULL);
934 purple_account_option_add_list_item(option, _("Obey server policy"), "obey-server");
935 purple_account_option_add_list_item(option, _("Always"), "required");
936 purple_account_option_add_list_item(option, _("Optional"), "optional");
937 purple_account_option_add_list_item(option, _("Disabled"), "disabled");
938 options = g_list_append(options, option);
939 #endif
941 return options;
944 gpointer sipe_purple_user_split()
946 PurpleAccountUserSplit *split =
947 purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL, ',');
948 purple_account_user_split_set_reverse(split, FALSE);
950 return split;
954 Local Variables:
955 mode: c
956 c-file-style: "bsd"
957 indent-tabs-mode: t
958 tab-width: 8
959 End: