purple: remove purple >= 2.7.0 flagging
[siplcs.git] / src / purple / purple-plugin-common.c
blob84b32c94c7d95745044edef047d243859f9c4561
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 #if !(PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0))
44 #error purple >= 2.7.0 is required to build SIPE
45 #endif
47 #if PURPLE_VERSION_CHECK(3,0,0)
48 #define PURPLE_TYPE_STRING G_TYPE_STRING
49 #define SIPE_PURPLE_ACTION_TO_CONNECTION action->connection
50 #else
51 #include "blist.h"
52 #define g_source_remove(t) purple_timeout_remove(t)
53 #define PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
54 #define PURPLE_CONNECTION_FLAG_FORMATTING_WBFO PURPLE_CONNECTION_FORMATTING_WBFO
55 #define PURPLE_CONNECTION_FLAG_HTML PURPLE_CONNECTION_HTML
56 #define PURPLE_CONNECTION_FLAG_NO_BGCOLOR PURPLE_CONNECTION_NO_BGCOLOR
57 #define PURPLE_CONNECTION_FLAG_NO_FONTSIZE PURPLE_CONNECTION_NO_FONTSIZE
58 #define PURPLE_CONNECTION_FLAG_NO_URLDESC PURPLE_CONNECTION_NO_URLDESC
59 #define PURPLE_IS_BUDDY(n) PURPLE_BLIST_NODE_IS_BUDDY(n)
60 #define PURPLE_IS_CHAT(n) PURPLE_BLIST_NODE_IS_CHAT(n)
61 #define PURPLE_IM_TYPING PURPLE_TYPING
62 #define PURPLE_IM_NOT_TYPING PURPLE_NOT_TYPING
63 #define purple_account_option_string_set_masked(o, f) purple_account_option_set_masked(o, f)
64 #define purple_connection_error(g, e, m) purple_connection_error_reason(g, e, m)
65 #define purple_connection_get_flags(gc) 0
66 #define purple_connection_set_protocol_data(gc, p) gc->proto_data = p
67 #define purple_connection_set_flags(gc, f) gc->flags |= f
68 #define purple_protocol_action_new(l, c) purple_plugin_action_new(l, c)
69 #define PurpleProtocolAction PurplePluginAction
70 #define SIPE_PURPLE_ACTION_TO_CONNECTION action->context
71 #endif
73 #include "sipe-backend.h"
74 #include "sipe-core.h"
75 #include "sipe-nls.h"
77 #include "purple-private.h"
80 * NOTE: this flag means two things:
82 * - is Single Sign-On supported, and
83 * - is Kerberos supported
85 #if defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_SSPI)
86 #define PURPLE_SIPE_SSO_AND_KERBEROS 1
87 #else
88 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
89 #endif
92 * SIPE core activity <-> Purple status mapping
94 * NOTE: this needs to be kept in sync with sipe_purple_status_types()
96 static const gchar * const activity_to_purple_map[SIPE_ACTIVITY_NUM_TYPES] = {
97 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
98 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
99 /* SIPE_ACTIVITY_ONLINE */ "online",
100 /* SIPE_ACTIVITY_INACTIVE */ "idle",
101 /* SIPE_ACTIVITY_BUSY */ "busy",
102 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
103 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
104 /* SIPE_ACTIVITY_BRB */ "be-right-back",
105 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
106 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
107 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
108 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
109 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
110 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
111 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
112 /* SIPE_ACTIVITY_OOF */ "out-of-office",
113 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
114 /* SIPE_ACTIVIY_NUM_TYPES == 17 -> compare to sipe_purple_status_types() */
117 GHashTable *purple_token_map;
119 static void sipe_purple_activity_init(void)
121 guint index;
123 purple_token_map = g_hash_table_new(g_str_hash, g_str_equal);
124 for (index = SIPE_ACTIVITY_UNSET;
125 index < SIPE_ACTIVITY_NUM_TYPES;
126 index++) {
127 g_hash_table_insert(purple_token_map,
128 (gchar *) activity_to_purple_map[index],
129 GUINT_TO_POINTER(index));
133 static void sipe_purple_activity_shutdown(void)
135 g_hash_table_destroy(purple_token_map);
138 const gchar *sipe_purple_activity_to_token(guint type)
140 return(activity_to_purple_map[type]);
143 guint sipe_purple_token_to_activity(const gchar *token)
145 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map, token)));
148 gchar *sipe_backend_version(void)
150 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
153 const char *sipe_purple_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount *a,
154 SIPE_UNUSED_PARAMETER PurpleBuddy *b)
156 return "sipe";
159 gchar *sipe_purple_status_text(PurpleBuddy *buddy)
161 const PurpleStatus *status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
162 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
163 purple_buddy_get_name(buddy),
164 sipe_purple_token_to_activity(purple_status_get_id(status)),
165 purple_status_get_name(status));
168 void sipe_purple_tooltip_text(PurpleBuddy *buddy,
169 PurpleNotifyUserInfo *user_info,
170 SIPE_UNUSED_PARAMETER gboolean full)
172 const PurplePresence *presence = purple_buddy_get_presence(buddy);
173 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
174 purple_buddy_get_name(buddy),
175 purple_status_get_name(purple_presence_get_active_status(presence)),
176 purple_presence_is_online(presence),
177 (struct sipe_backend_buddy_tooltip *) user_info);
180 GList *sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount *acc)
182 PurpleStatusType *type;
183 GList *types = NULL;
185 /* Macro to reduce code repetition
186 Translators: noun */
187 #define SIPE_ADD_STATUS(prim,activity,user) type = purple_status_type_new_with_attrs( \
188 prim, \
189 sipe_purple_activity_to_token(activity), \
190 sipe_core_activity_description(activity), \
191 TRUE, user, FALSE, \
192 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
193 NULL); \
194 types = g_list_append(types, type);
197 * NOTE: needs to be kept in sync with activity_to_purple_map[],
198 * i.e. for each SIPE_ACTIVITY_xxx value there must be an
199 * entry on this list.
201 * NOTE: the following code is sorted by purple primitive type not
202 * by SIPE_ACTIVITY_xxx value.
205 /* 1: Unset - special case: no entry needed */
208 * Status list entries for primitive type AVAILABLE
210 * 2: Available */
211 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
212 SIPE_ACTIVITY_AVAILABLE,
213 TRUE);
215 /* 3: Online */
216 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
217 SIPE_ACTIVITY_ONLINE,
218 FALSE);
220 /* 4: Inactive (Idle) */
221 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
222 SIPE_ACTIVITY_INACTIVE,
223 FALSE);
226 * Status list entries for primitive type UNAVAILABLE
228 * 5: Busy */
229 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
230 SIPE_ACTIVITY_BUSY,
231 TRUE);
233 /* 6: Busy-Idle */
234 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
235 SIPE_ACTIVITY_BUSYIDLE,
236 FALSE);
238 /* 7: Do Not Disturb */
239 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
240 SIPE_ACTIVITY_DND,
241 TRUE);
243 /* 8: In a call */
244 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
245 SIPE_ACTIVITY_ON_PHONE,
246 FALSE);
248 /* 9: In a conference call */
249 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
250 SIPE_ACTIVITY_IN_CONF,
251 FALSE);
253 /* 10: In a meeting */
254 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
255 SIPE_ACTIVITY_IN_MEETING,
256 FALSE);
258 /* 11: Urgent interruptions only */
259 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
260 SIPE_ACTIVITY_URGENT_ONLY,
261 FALSE);
264 * Status list entries for primitive type AWAY
266 * 12: Away - special case: needs to go first in the list as purple
267 * picks the first status with primitive type AWAY for idle
269 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
270 SIPE_ACTIVITY_AWAY,
271 TRUE);
273 /* 13: Be Right Back */
274 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
275 SIPE_ACTIVITY_BRB,
276 TRUE);
278 /* 14: Out to lunch */
279 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
280 SIPE_ACTIVITY_LUNCH,
281 FALSE);
284 * Status list entries for primitive type EXTENDED_AWAY
286 * 15: Out of office */
287 SIPE_ADD_STATUS(PURPLE_STATUS_EXTENDED_AWAY,
288 SIPE_ACTIVITY_OOF,
289 FALSE);
292 * Status list entries for primitive type INVISIBLE
294 * 16: Appear Offline */
295 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE,
296 SIPE_ACTIVITY_INVISIBLE,
297 TRUE);
300 * Status list entries for primitive type OFFLINE
302 * NOTE: this is always the last entry. Compare the number
303 * with the comment in activity_to_purple_map[].
305 * 17: Offline - special case: no message text */
306 type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
307 NULL,
308 NULL,
309 TRUE);
310 types = g_list_append(types, type);
312 return types;
315 GList *sipe_purple_blist_node_menu(PurpleBlistNode *node)
317 if (PURPLE_IS_BUDDY(node))
319 return sipe_purple_buddy_menu((PurpleBuddy *) node);
320 } else
321 if (PURPLE_IS_CHAT(node))
323 return sipe_purple_chat_menu((PurpleChat *)node);
324 } else {
325 return NULL;
329 static guint get_authentication_type(PurpleAccount *account)
331 const gchar *auth = purple_account_get_string(account, "authentication", "ntlm");
333 /* map option list to type - default is automatic */
334 guint authentication_type = SIPE_AUTHENTICATION_TYPE_AUTOMATIC;
335 if (sipe_strequal(auth, "ntlm")) {
336 authentication_type = SIPE_AUTHENTICATION_TYPE_NTLM;
337 } else
338 #if PURPLE_SIPE_SSO_AND_KERBEROS
339 if (sipe_strequal(auth, "krb5")) {
340 authentication_type = SIPE_AUTHENTICATION_TYPE_KERBEROS;
341 } else
342 #endif
343 if (sipe_strequal(auth, "tls-dsk")) {
344 authentication_type = SIPE_AUTHENTICATION_TYPE_TLS_DSK;
347 return(authentication_type);
350 static gboolean get_sso_flag(PurpleAccount *account)
352 #if PURPLE_SIPE_SSO_AND_KERBEROS
354 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
355 * SIPE that it is OK to use Single Sign-On or not.
357 return(purple_account_get_bool(account, "sso", FALSE));
358 #else
359 (void) account; /* keep compiler happy */
360 return(FALSE);
361 #endif
364 static gboolean get_dont_publish_flag(PurpleAccount *account)
366 /* default is to publish calendar information */
367 return(purple_account_get_bool(account, "dont-publish", FALSE));
370 static gboolean get_allow_web_photo_flag(PurpleAccount *account)
372 /* default is to not allow insecure download of buddy icons from web */
373 return purple_account_get_bool(account, "allow-web-photo", FALSE);
376 static void connect_to_core(PurpleConnection *gc,
377 PurpleAccount *account,
378 const gchar *password)
380 const gchar *username = purple_account_get_username(account);
381 const gchar *email = purple_account_get_string(account, "email", NULL);
382 const gchar *email_url = purple_account_get_string(account, "email_url", NULL);
383 const gchar *transport = purple_account_get_string(account, "transport", "auto");
384 struct sipe_core_public *sipe_public;
385 gchar **username_split;
386 const gchar *errmsg;
387 guint transport_type;
388 struct sipe_backend_private *purple_private;
390 /* username format: <username>,[<optional login>] */
391 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username);
392 username_split = g_strsplit(username, ",", 2);
394 sipe_public = sipe_core_allocate(username_split[0],
395 get_sso_flag(account),
396 username_split[1],
397 password,
398 email,
399 email_url,
400 &errmsg);
401 g_strfreev(username_split);
403 if (!sipe_public) {
404 purple_connection_error(gc,
405 PURPLE_CONNECTION_ERROR_INVALID_USERNAME,
406 errmsg);
407 return;
410 sipe_public->backend_private = purple_private = g_new0(struct sipe_backend_private, 1);
411 purple_private->public = sipe_public;
412 purple_private->gc = gc;
413 purple_private->account = account;
415 sipe_purple_chat_setup_rejoin(purple_private);
417 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH);
418 if (get_dont_publish_flag(account))
419 SIPE_CORE_FLAG_SET(DONT_PUBLISH);
420 SIPE_CORE_FLAG_UNSET(ALLOW_WEB_PHOTO);
421 if (get_allow_web_photo_flag(account))
422 SIPE_CORE_FLAG_SET(ALLOW_WEB_PHOTO);
424 purple_connection_set_protocol_data(gc, sipe_public);
425 purple_connection_set_flags(gc,
426 purple_connection_get_flags(gc) |
427 PURPLE_CONNECTION_FLAG_HTML |
428 PURPLE_CONNECTION_FLAG_FORMATTING_WBFO |
429 PURPLE_CONNECTION_FLAG_NO_BGCOLOR |
430 PURPLE_CONNECTION_FLAG_NO_FONTSIZE |
431 PURPLE_CONNECTION_FLAG_NO_URLDESC |
432 PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY);
433 purple_connection_set_display_name(gc, sipe_public->sip_name);
434 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
436 username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2);
437 if (sipe_strequal(transport, "auto")) {
438 transport_type = (username_split[0] == NULL) ?
439 SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS;
440 } else if (sipe_strequal(transport, "tls")) {
441 transport_type = SIPE_TRANSPORT_TLS;
442 } else {
443 transport_type = SIPE_TRANSPORT_TCP;
445 sipe_core_transport_sip_connect(sipe_public,
446 transport_type,
447 get_authentication_type(account),
448 username_split[0],
449 username_split[0] ? username_split[1] : NULL);
450 g_strfreev(username_split);
453 static void password_required_cb(PurpleConnection *gc,
454 SIPE_UNUSED_PARAMETER PurpleRequestFields *fields)
456 #if !PURPLE_VERSION_CHECK(3,0,0)
457 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
458 return;
460 #endif
462 purple_connection_error(gc,
463 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
464 _("Password required"));
467 static void password_ok_cb(PurpleConnection *gc,
468 PurpleRequestFields *fields)
470 const gchar *password;
472 #if !PURPLE_VERSION_CHECK(3,0,0)
473 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
474 return;
476 #endif
478 password = purple_request_fields_get_string(fields, "password");
480 if (password && strlen(password)) {
481 PurpleAccount *account = purple_connection_get_account(gc);
483 if (purple_request_fields_get_bool(fields, "remember"))
484 purple_account_set_remember_password(account, TRUE);
485 purple_account_set_password(account, password
486 #if PURPLE_VERSION_CHECK(3,0,0)
487 , NULL, NULL
488 #endif
491 /* Now we have a password and we can connect */
492 connect_to_core(gc, account, password);
494 } else
495 /* reject an empty password */
496 password_required_cb(gc, fields);
499 void sipe_purple_login(PurpleAccount *account)
501 PurpleConnection *gc = purple_account_get_connection(account);
502 const gchar *password = purple_connection_get_password(gc);
504 /* Password required? */
505 if (sipe_core_transport_sip_requires_password(get_authentication_type(account),
506 get_sso_flag(account)) &&
507 (!password || !strlen(password)))
508 /* No password set - request one from user */
509 purple_account_request_password(account,
510 G_CALLBACK(password_ok_cb),
511 G_CALLBACK(password_required_cb),
512 gc);
513 else
514 /* No password required or saved password - connect now */
515 connect_to_core(gc, account, password);
519 void sipe_purple_close(PurpleConnection *gc)
521 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
523 if (sipe_public) {
524 struct sipe_backend_private *purple_private = sipe_public->backend_private;
526 sipe_core_deallocate(sipe_public);
528 /* anything left after that must be in pending state... */
529 sipe_purple_dns_query_cancel_all(purple_private);
530 sipe_purple_transport_close_all(purple_private);
532 if (purple_private->roomlist_map)
533 g_hash_table_destroy(purple_private->roomlist_map);
534 sipe_purple_chat_destroy_rejoin(purple_private);
536 if (purple_private->deferred_status_timeout)
537 g_source_remove(purple_private->deferred_status_timeout);
538 g_free(purple_private->deferred_status_note);
540 g_free(purple_private);
541 purple_connection_set_protocol_data(gc, NULL);
545 unsigned int sipe_purple_send_typing(PurpleConnection *gc,
546 const char *who,
547 PurpleIMTypingState state)
549 gboolean typing = (state == PURPLE_IM_TYPING);
551 /* only enable this debug output while testing
552 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
555 * libpurple calls this function with PURPLE_NOT_TYPING *after*
556 * calling sipe_purple_send_im() with the message. This causes
557 * SIPE core to send out two SIP messages to the same dialog in
558 * short succession without waiting for the response to the first
559 * one. Some servers then reject the first one with
561 * SIP/2.0 500 Stale CSeq Value
563 * which triggers a "message not delivered" error for the user.
565 * Work around this by filtering out PURPLE_NOT_TYPING events.
567 if (state != PURPLE_IM_NOT_TYPING)
568 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
569 who,
570 typing);
572 /* tell libpurple to send typing indications every 4 seconds */
573 return(typing ? 4 : 0);
576 void sipe_purple_get_info(PurpleConnection *gc, const char *who)
578 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
579 who);
582 void sipe_purple_add_permit(PurpleConnection *gc, const char *name)
584 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE);
587 void sipe_purple_add_deny(PurpleConnection *gc, const char *name)
589 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, FALSE);
592 void sipe_purple_alias_buddy(PurpleConnection *gc, const char *name,
593 const char *alias)
595 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, alias);
598 void sipe_purple_group_rename(PurpleConnection *gc, const char *old_name,
599 PurpleGroup *group,
600 SIPE_UNUSED_PARAMETER GList *moved_buddies)
602 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
603 old_name,
604 purple_group_get_name(group));
607 void sipe_purple_convo_closed(PurpleConnection *gc, const char *who)
609 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who);
612 void sipe_purple_group_remove(PurpleConnection *gc, PurpleGroup *group)
614 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
615 purple_group_get_name(group));
618 GHashTable *
619 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount *account)
621 GHashTable *table;
622 table = g_hash_table_new(g_str_hash, g_str_equal);
623 g_hash_table_insert(table, "login_label", (gpointer)_("user@company.com"));
624 return table;
627 #ifdef HAVE_VV
629 static void
630 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER int signum)
632 capture_pipeline("PURPLE_SIPE_PIPELINE");
635 gboolean sipe_purple_initiate_media(PurpleAccount *account, const char *who,
636 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type)
638 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
639 who,
640 (type & PURPLE_MEDIA_VIDEO));
641 return TRUE;
644 PurpleMediaCaps sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount *account,
645 SIPE_UNUSED_PARAMETER const char *who)
647 return PURPLE_MEDIA_CAPS_AUDIO
648 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
649 | PURPLE_MEDIA_CAPS_MODIFY_SESSION;
651 #endif
653 /* PurplePluginInfo function calls & data structure */
654 gboolean sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
656 #ifdef HAVE_DBUS
657 if (purple_dbus_get_init_error() == NULL) {
658 SIPE_DEBUG_INFO_NOFORMAT("sipe_purple_plugin_load: registering D-Bus bindings");
659 purple_dbus_register_bindings(plugin, sipe_purple_dbus_bindings);
661 #endif
663 #ifdef HAVE_VV
665 struct sigaction action;
666 memset(&action, 0, sizeof (action));
667 action.sa_handler = sipe_purple_sigusr1_handler;
668 sigaction(SIGUSR1, &action, NULL);
670 #endif
672 sipe_purple_activity_init();
674 return TRUE;
677 gboolean sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
679 #ifdef HAVE_VV
680 struct sigaction action;
681 memset(&action, 0, sizeof (action));
682 action.sa_handler = SIG_DFL;
683 sigaction(SIGUSR1, &action, NULL);
684 #endif
686 sipe_purple_activity_shutdown();
688 return TRUE;
691 static void sipe_purple_show_about_plugin(PurpleProtocolAction *action)
693 gchar *tmp = sipe_core_about();
694 purple_notify_formatted(SIPE_PURPLE_ACTION_TO_CONNECTION,
695 NULL, " ", NULL, tmp, NULL, NULL);
696 g_free(tmp);
699 static void sipe_purple_join_conference_cb(PurpleConnection *gc,
700 PurpleRequestFields *fields)
702 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
704 if (entries) {
705 const gchar *location = purple_request_fields_get_string(fields,
706 "meetingLocation");
707 const gchar *organizer = purple_request_fields_get_string(fields,
708 "meetingOrganizer");
709 const gchar *meeting_id = purple_request_fields_get_string(fields,
710 "meetingID");
711 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
712 location,
713 organizer,
714 meeting_id);
718 #ifdef HAVE_VV
720 static void sipe_purple_phone_call_cb(PurpleConnection *gc,
721 PurpleRequestFields *fields)
723 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
725 if (entries)
726 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
727 purple_request_fields_get_string(fields,
728 "phoneNumber"));
731 static void sipe_purple_phone_call(PurpleProtocolAction *action)
733 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
734 PurpleRequestFields *fields;
735 PurpleRequestFieldGroup *group;
736 PurpleRequestField *field;
738 fields = purple_request_fields_new();
739 group = purple_request_field_group_new(NULL);
740 purple_request_fields_add_group(fields, group);
742 field = purple_request_field_string_new("phoneNumber", _("Phone number"), NULL, FALSE);
743 purple_request_field_group_add_field(group, field);
745 purple_request_fields(gc,
746 _("Call a phone number"),
747 _("Call a phone number"),
748 NULL,
749 fields,
750 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb),
751 _("_Cancel"), NULL,
752 #if PURPLE_VERSION_CHECK(3,0,0)
753 purple_request_cpar_from_connection(gc),
754 #else
755 purple_connection_get_account(gc), NULL, NULL,
756 #endif
757 gc);
760 static void sipe_purple_test_call(PurpleProtocolAction *action)
762 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
763 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
765 #endif
767 static void sipe_purple_show_join_conference(PurpleProtocolAction *action)
769 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
770 PurpleRequestFields *fields;
771 PurpleRequestFieldGroup *group;
772 PurpleRequestField *field;
774 fields = purple_request_fields_new();
775 group = purple_request_field_group_new(NULL);
776 purple_request_fields_add_group(fields, group);
778 field = purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL, FALSE);
779 purple_request_field_group_add_field(group, field);
780 field = purple_request_field_label_new("separator", _("Alternatively"));
781 purple_request_field_group_add_field(group, field);
782 field = purple_request_field_string_new("meetingOrganizer", _("Organizer email"), NULL, FALSE);
783 purple_request_field_group_add_field(group, field);
784 field = purple_request_field_string_new("meetingID", _("Meeting ID"), NULL, FALSE);
785 purple_request_field_group_add_field(group, field);
787 purple_request_fields(gc,
788 _("Join conference"),
789 _("Join scheduled conference"),
790 _("Enter meeting location string you received in the invitation.\n"
791 "\n"
792 "Valid location will be something like\n"
793 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
794 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
795 "or\n"
796 "https://meet.company.com/someone/abcdef1234"),
797 fields,
798 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb),
799 _("_Cancel"), NULL,
800 #if PURPLE_VERSION_CHECK(3,0,0)
801 purple_request_cpar_from_connection(gc),
802 #else
803 purple_connection_get_account(gc), NULL, NULL,
804 #endif
805 gc);
808 void sipe_purple_republish_calendar(PurpleAccount *account)
810 struct sipe_core_public *sipe_public = PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC;
811 if (get_dont_publish_flag(account)) {
812 sipe_backend_notify_error(sipe_public,
813 _("Publishing of calendar information has been disabled"),
814 NULL);
815 } else {
816 sipe_core_update_calendar(sipe_public);
820 static void sipe_purple_republish_calendar_action(PurpleProtocolAction *action)
822 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
823 PurpleAccount *account = purple_connection_get_account(gc);
824 sipe_purple_republish_calendar(account);
827 void sipe_purple_reset_status(PurpleAccount *account)
829 if (get_dont_publish_flag(account)) {
830 sipe_backend_notify_error(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
831 _("Publishing of calendar information has been disabled"),
832 NULL);
833 } else {
834 sipe_core_reset_status(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC);
838 static void sipe_purple_reset_status_action(PurpleProtocolAction *action)
840 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
841 PurpleAccount *account = purple_connection_get_account(gc);
842 sipe_purple_reset_status(account);
845 GList *sipe_purple_actions()
847 GList *menu = NULL;
848 PurpleProtocolAction *act;
850 act = purple_protocol_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin);
851 menu = g_list_prepend(menu, act);
853 act = purple_protocol_action_new(_("Contact search..."), sipe_purple_show_find_contact);
854 menu = g_list_prepend(menu, act);
856 #ifdef HAVE_VV
857 act = purple_protocol_action_new(_("Call a phone number..."), sipe_purple_phone_call);
858 menu = g_list_prepend(menu, act);
860 act = purple_protocol_action_new(_("Test call"), sipe_purple_test_call);
861 menu = g_list_prepend(menu, act);
862 #endif
864 act = purple_protocol_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference);
865 menu = g_list_prepend(menu, act);
867 act = purple_protocol_action_new(_("Republish Calendar"), sipe_purple_republish_calendar_action);
868 menu = g_list_prepend(menu, act);
870 act = purple_protocol_action_new(_("Reset status"), sipe_purple_reset_status_action);
871 menu = g_list_prepend(menu, act);
873 return g_list_reverse(menu);
876 GList * sipe_purple_account_options()
878 PurpleAccountOption *option;
879 GList *options = NULL;
882 * When adding new string settings please make sure to keep these
883 * in sync:
885 * api/sipe-backend.h
886 * purple-settings.c:setting_name[]
888 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
889 options = g_list_append(options, option);
891 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
892 purple_account_option_add_list_item(option, _("Auto"), "auto");
893 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
894 purple_account_option_add_list_item(option, _("TCP"), "tcp");
895 options = g_list_append(options, option);
897 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
898 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
900 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
901 options = g_list_append(options, option);
903 option = purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL);
904 purple_account_option_add_list_item(option, _("Auto"), "auto");
905 purple_account_option_add_list_item(option, _("NTLM"), "ntlm");
906 #if PURPLE_SIPE_SSO_AND_KERBEROS
907 purple_account_option_add_list_item(option, _("Kerberos"), "krb5");
908 #endif
909 purple_account_option_add_list_item(option, _("TLS-DSK"), "tls-dsk");
910 options = g_list_append(options, option);
912 #if PURPLE_SIPE_SSO_AND_KERBEROS
914 * When the user selects Single Sign-On then SIPE will ignore the
915 * settings for "login name" and "password". Instead it will use the
916 * default credentials provided by the OS.
918 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
919 * SIPE that it is OK to use Single Sign-On or not.
921 * Configurations that are known to support Single Sign-On:
923 * - Windows, host joined to domain, SIPE with SSPI: NTLM
924 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
925 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
927 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE);
928 options = g_list_append(options, option);
929 #endif
931 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
932 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
934 option = purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE);
935 options = g_list_append(options, option);
937 option = purple_account_option_bool_new(_("Show profile pictures from web\n(potentially dangerous)"), "allow-web-photo", FALSE);
938 options = g_list_append(options, option);
940 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
941 options = g_list_append(options, option);
943 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
944 options = g_list_append(options, option);
946 /** Example (Exchange): DOMAIN\user or user@company.com
947 * Example (Domino) : email_address
949 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
950 options = g_list_append(options, option);
952 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
953 purple_account_option_string_set_masked(option, TRUE);
954 options = g_list_append(options, option);
956 /** Example (federated domain): company.com (i.e. ocschat@company.com)
957 * Example (non-default user): user@company.com
959 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", "");
960 options = g_list_append(options, option);
962 #ifdef HAVE_APPSHARE
963 option = purple_account_option_string_new(_("Remote desktop client"), "rdp_client", "");
964 options = g_list_append(options, option);
965 #endif
967 #ifdef HAVE_SRTP
968 option = purple_account_option_list_new(_("Media encryption"), "encryption-policy", NULL);
969 purple_account_option_add_list_item(option, _("Obey server policy"), "obey-server");
970 purple_account_option_add_list_item(option, _("Always"), "required");
971 purple_account_option_add_list_item(option, _("Optional"), "optional");
972 purple_account_option_add_list_item(option, _("Disabled"), "disabled");
973 options = g_list_append(options, option);
974 #endif
976 return options;
979 gpointer sipe_purple_user_split()
981 PurpleAccountUserSplit *split =
982 purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL, ',');
983 purple_account_user_split_set_reverse(split, FALSE);
985 return split;
989 Local Variables:
990 mode: c
991 c-file-style: "bsd"
992 indent-tabs-mode: t
993 tab-width: 8
994 End: