2 * @file purple-plugin-common.c
6 * Copyright (C) 2010-2018 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
30 #include "sipe-common.h"
33 #include "accountopt.h"
40 #include "purple-dbus.h"
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
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
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
73 #include "sipe-backend.h"
74 #include "sipe-core.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
88 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
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_ACTIVITY_IN_PRES */ "presenting",
115 /* SIPE_ACTIVIY_NUM_TYPES == 18 -> compare to sipe_purple_status_types() */
118 GHashTable
*purple_token_map
;
120 static void sipe_purple_activity_init(void)
124 purple_token_map
= g_hash_table_new(g_str_hash
, g_str_equal
);
125 for (index
= SIPE_ACTIVITY_UNSET
;
126 index
< SIPE_ACTIVITY_NUM_TYPES
;
128 g_hash_table_insert(purple_token_map
,
129 (gchar
*) activity_to_purple_map
[index
],
130 GUINT_TO_POINTER(index
));
134 static void sipe_purple_activity_shutdown(void)
136 g_hash_table_destroy(purple_token_map
);
139 const gchar
*sipe_purple_activity_to_token(guint type
)
141 return(activity_to_purple_map
[type
]);
144 guint
sipe_purple_token_to_activity(const gchar
*token
)
146 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map
, token
)));
149 gchar
*sipe_backend_version(void)
151 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
154 const char *sipe_purple_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount
*a
,
155 SIPE_UNUSED_PARAMETER PurpleBuddy
*b
)
160 gchar
*sipe_purple_status_text(PurpleBuddy
*buddy
)
162 const PurpleStatus
*status
= purple_presence_get_active_status(purple_buddy_get_presence(buddy
));
163 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
164 purple_buddy_get_name(buddy
),
165 sipe_purple_token_to_activity(purple_status_get_id(status
)),
166 purple_status_get_name(status
));
169 void sipe_purple_tooltip_text(PurpleBuddy
*buddy
,
170 PurpleNotifyUserInfo
*user_info
,
171 SIPE_UNUSED_PARAMETER gboolean full
)
173 const PurplePresence
*presence
= purple_buddy_get_presence(buddy
);
174 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
175 purple_buddy_get_name(buddy
),
176 purple_status_get_name(purple_presence_get_active_status(presence
)),
177 purple_presence_is_online(presence
),
178 (struct sipe_backend_buddy_tooltip
*) user_info
);
181 GList
*sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount
*acc
)
183 PurpleStatusType
*type
;
186 /* Macro to reduce code repetition
188 #define SIPE_ADD_STATUS(prim,activity,user) type = purple_status_type_new_with_attrs( \
190 sipe_purple_activity_to_token(activity), \
191 sipe_core_activity_description(activity), \
193 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
195 types = g_list_append(types, type);
198 * NOTE: needs to be kept in sync with activity_to_purple_map[],
199 * i.e. for each SIPE_ACTIVITY_xxx value there must be an
200 * entry on this list.
202 * NOTE: the following code is sorted by purple primitive type not
203 * by SIPE_ACTIVITY_xxx value.
206 /* 1: Unset - special case: no entry needed */
209 * Status list entries for primitive type AVAILABLE
212 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE
,
213 SIPE_ACTIVITY_AVAILABLE
,
217 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE
,
218 SIPE_ACTIVITY_ONLINE
,
221 /* 4: Inactive (Idle) */
222 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE
,
223 SIPE_ACTIVITY_INACTIVE
,
227 * Status list entries for primitive type UNAVAILABLE
230 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
235 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
236 SIPE_ACTIVITY_BUSYIDLE
,
239 /* 7: Do Not Disturb */
240 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
245 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
246 SIPE_ACTIVITY_ON_PHONE
,
249 /* 9: In a conference call */
250 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
251 SIPE_ACTIVITY_IN_CONF
,
254 /* 10: In a meeting */
255 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
256 SIPE_ACTIVITY_IN_MEETING
,
259 /* 11: Urgent interruptions only */
260 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
261 SIPE_ACTIVITY_URGENT_ONLY
,
265 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
266 SIPE_ACTIVITY_IN_PRES
,
270 * Status list entries for primitive type AWAY
272 * 12: Away - special case: needs to go first in the list as purple
273 * picks the first status with primitive type AWAY for idle
275 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
279 /* 13: Be Right Back */
280 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
284 /* 14: Out to lunch */
285 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
290 * Status list entries for primitive type EXTENDED_AWAY
292 * 15: Out of office */
293 SIPE_ADD_STATUS(PURPLE_STATUS_EXTENDED_AWAY
,
298 * Status list entries for primitive type INVISIBLE
300 * 16: Appear Offline */
301 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE
,
302 SIPE_ACTIVITY_INVISIBLE
,
306 * Status list entries for primitive type OFFLINE
308 * NOTE: this is always the last entry. Compare the number
309 * with the comment in activity_to_purple_map[].
311 * 17: Offline - special case: no message text */
312 type
= purple_status_type_new(PURPLE_STATUS_OFFLINE
,
316 types
= g_list_append(types
, type
);
321 GList
*sipe_purple_blist_node_menu(PurpleBlistNode
*node
)
323 if (PURPLE_IS_BUDDY(node
))
325 return sipe_purple_buddy_menu((PurpleBuddy
*) node
);
327 if (PURPLE_IS_CHAT(node
))
329 return sipe_purple_chat_menu((PurpleChat
*)node
);
335 static guint
get_authentication_type(PurpleAccount
*account
)
337 const gchar
*auth
= purple_account_get_string(account
, "authentication", "ntlm");
339 /* map option list to type - default is automatic */
340 guint authentication_type
= SIPE_AUTHENTICATION_TYPE_AUTOMATIC
;
341 if (sipe_strequal(auth
, "ntlm")) {
342 authentication_type
= SIPE_AUTHENTICATION_TYPE_NTLM
;
344 #if PURPLE_SIPE_SSO_AND_KERBEROS
345 if (sipe_strequal(auth
, "krb5")) {
346 authentication_type
= SIPE_AUTHENTICATION_TYPE_KERBEROS
;
349 if (sipe_strequal(auth
, "tls-dsk")) {
350 authentication_type
= SIPE_AUTHENTICATION_TYPE_TLS_DSK
;
353 return(authentication_type
);
356 static gboolean
get_sso_flag(PurpleAccount
*account
)
358 #if PURPLE_SIPE_SSO_AND_KERBEROS
360 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
361 * SIPE that it is OK to use Single Sign-On or not.
363 return(purple_account_get_bool(account
, "sso", FALSE
));
365 (void) account
; /* keep compiler happy */
370 static gboolean
get_dont_publish_flag(PurpleAccount
*account
)
372 /* default is to publish calendar information */
373 return(purple_account_get_bool(account
, "dont-publish", FALSE
));
376 static gboolean
get_allow_web_photo_flag(PurpleAccount
*account
)
378 /* default is to not allow insecure download of buddy icons from web */
379 return purple_account_get_bool(account
, "allow-web-photo", FALSE
);
382 static void connect_to_core(PurpleConnection
*gc
,
383 PurpleAccount
*account
,
384 const gchar
*password
)
386 const gchar
*username
= purple_account_get_username(account
);
387 const gchar
*email
= purple_account_get_string(account
, "email", NULL
);
388 const gchar
*email_url
= purple_account_get_string(account
, "email_url", NULL
);
389 const gchar
*transport
= purple_account_get_string(account
, "transport", "auto");
390 struct sipe_core_public
*sipe_public
;
391 gchar
**username_split
;
393 guint transport_type
;
394 struct sipe_backend_private
*purple_private
;
396 /* username format: <username>,[<optional login>] */
397 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username
);
398 username_split
= g_strsplit(username
, ",", 2);
400 sipe_public
= sipe_core_allocate(username_split
[0],
401 get_sso_flag(account
),
407 g_strfreev(username_split
);
410 purple_connection_error(gc
,
411 PURPLE_CONNECTION_ERROR_INVALID_USERNAME
,
416 sipe_public
->backend_private
= purple_private
= g_new0(struct sipe_backend_private
, 1);
417 purple_private
->public = sipe_public
;
418 purple_private
->gc
= gc
;
419 purple_private
->account
= account
;
421 sipe_purple_chat_setup_rejoin(purple_private
);
423 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH
);
424 if (get_dont_publish_flag(account
))
425 SIPE_CORE_FLAG_SET(DONT_PUBLISH
);
426 SIPE_CORE_FLAG_UNSET(ALLOW_WEB_PHOTO
);
427 if (get_allow_web_photo_flag(account
))
428 SIPE_CORE_FLAG_SET(ALLOW_WEB_PHOTO
);
430 purple_connection_set_protocol_data(gc
, sipe_public
);
431 purple_connection_set_flags(gc
,
432 purple_connection_get_flags(gc
) |
433 PURPLE_CONNECTION_FLAG_HTML
|
434 PURPLE_CONNECTION_FLAG_FORMATTING_WBFO
|
435 PURPLE_CONNECTION_FLAG_NO_BGCOLOR
|
436 PURPLE_CONNECTION_FLAG_NO_FONTSIZE
|
437 PURPLE_CONNECTION_FLAG_NO_URLDESC
|
438 PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY
);
439 purple_connection_set_display_name(gc
, sipe_public
->sip_name
);
440 purple_connection_update_progress(gc
, _("Connecting"), 1, 2);
442 username_split
= g_strsplit(purple_account_get_string(account
, "server", ""), ":", 2);
443 if (sipe_strequal(transport
, "auto")) {
444 transport_type
= (username_split
[0] == NULL
) ?
445 SIPE_TRANSPORT_AUTO
: SIPE_TRANSPORT_TLS
;
446 } else if (sipe_strequal(transport
, "tls")) {
447 transport_type
= SIPE_TRANSPORT_TLS
;
449 transport_type
= SIPE_TRANSPORT_TCP
;
451 sipe_core_transport_sip_connect(sipe_public
,
453 get_authentication_type(account
),
455 username_split
[0] ? username_split
[1] : NULL
);
456 g_strfreev(username_split
);
459 static void password_required_cb(PurpleConnection
*gc
,
460 SIPE_UNUSED_PARAMETER PurpleRequestFields
*fields
)
462 #if !PURPLE_VERSION_CHECK(3,0,0)
463 if (!PURPLE_CONNECTION_IS_VALID(gc
)) {
468 purple_connection_error(gc
,
469 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
,
470 _("Password required"));
473 static void password_ok_cb(PurpleConnection
*gc
,
474 PurpleRequestFields
*fields
)
476 const gchar
*password
;
478 #if !PURPLE_VERSION_CHECK(3,0,0)
479 if (!PURPLE_CONNECTION_IS_VALID(gc
)) {
484 password
= purple_request_fields_get_string(fields
, "password");
486 if (password
&& strlen(password
)) {
487 PurpleAccount
*account
= purple_connection_get_account(gc
);
489 if (purple_request_fields_get_bool(fields
, "remember"))
490 purple_account_set_remember_password(account
, TRUE
);
491 purple_account_set_password(account
, password
492 #if PURPLE_VERSION_CHECK(3,0,0)
497 /* Now we have a password and we can connect */
498 connect_to_core(gc
, account
, password
);
501 /* reject an empty password */
502 password_required_cb(gc
, fields
);
505 void sipe_purple_login(PurpleAccount
*account
)
507 PurpleConnection
*gc
= purple_account_get_connection(account
);
508 const gchar
*password
= purple_connection_get_password(gc
);
510 /* Password required? */
511 if (sipe_core_transport_sip_requires_password(get_authentication_type(account
),
512 get_sso_flag(account
)) &&
513 (!password
|| !strlen(password
)))
514 /* No password set - request one from user */
515 purple_account_request_password(account
,
516 G_CALLBACK(password_ok_cb
),
517 G_CALLBACK(password_required_cb
),
520 /* No password required or saved password - connect now */
521 connect_to_core(gc
, account
, password
);
525 void sipe_purple_close(PurpleConnection
*gc
)
527 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
530 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
532 sipe_core_deallocate(sipe_public
);
534 /* anything left after that must be in pending state... */
535 sipe_purple_dns_query_cancel_all(purple_private
);
536 sipe_purple_transport_close_all(purple_private
);
538 if (purple_private
->roomlist_map
)
539 g_hash_table_destroy(purple_private
->roomlist_map
);
540 sipe_purple_chat_destroy_rejoin(purple_private
);
542 if (purple_private
->deferred_status_timeout
)
543 g_source_remove(purple_private
->deferred_status_timeout
);
544 g_free(purple_private
->deferred_status_note
);
546 g_free(purple_private
);
547 purple_connection_set_protocol_data(gc
, NULL
);
551 unsigned int sipe_purple_send_typing(PurpleConnection
*gc
,
553 PurpleIMTypingState state
)
555 gboolean typing
= (state
== PURPLE_IM_TYPING
);
557 /* only enable this debug output while testing
558 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
561 * libpurple calls this function with PURPLE_NOT_TYPING *after*
562 * calling sipe_purple_send_im() with the message. This causes
563 * SIPE core to send out two SIP messages to the same dialog in
564 * short succession without waiting for the response to the first
565 * one. Some servers then reject the first one with
567 * SIP/2.0 500 Stale CSeq Value
569 * which triggers a "message not delivered" error for the user.
571 * Work around this by filtering out PURPLE_NOT_TYPING events.
573 if (state
!= PURPLE_IM_NOT_TYPING
)
574 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
578 /* tell libpurple to send typing indications every 4 seconds */
579 return(typing
? 4 : 0);
582 void sipe_purple_get_info(PurpleConnection
*gc
, const char *who
)
584 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
588 void sipe_purple_add_permit(PurpleConnection
*gc
, const char *name
)
590 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, TRUE
);
593 void sipe_purple_add_deny(PurpleConnection
*gc
, const char *name
)
595 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, FALSE
);
598 void sipe_purple_alias_buddy(PurpleConnection
*gc
, const char *name
,
601 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, alias
);
604 void sipe_purple_group_rename(PurpleConnection
*gc
, const char *old_name
,
606 SIPE_UNUSED_PARAMETER GList
*moved_buddies
)
608 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
610 purple_group_get_name(group
));
613 void sipe_purple_convo_closed(PurpleConnection
*gc
, const char *who
)
615 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
);
618 void sipe_purple_group_remove(PurpleConnection
*gc
, PurpleGroup
*group
)
620 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
621 purple_group_get_name(group
));
625 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount
*account
)
628 table
= g_hash_table_new(g_str_hash
, g_str_equal
);
629 g_hash_table_insert(table
, "login_label", (gpointer
)_("user@company.com"));
636 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER
int signum
)
638 capture_pipeline("PURPLE_SIPE_PIPELINE");
641 gboolean
sipe_purple_initiate_media(PurpleAccount
*account
, const char *who
,
642 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type
)
644 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC
,
646 (type
& PURPLE_MEDIA_VIDEO
));
650 PurpleMediaCaps
sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount
*account
,
651 SIPE_UNUSED_PARAMETER
const char *who
)
653 return PURPLE_MEDIA_CAPS_AUDIO
654 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
655 | PURPLE_MEDIA_CAPS_MODIFY_SESSION
;
659 /* PurplePluginInfo function calls & data structure */
660 gboolean
sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
663 if (purple_dbus_get_init_error() == NULL
) {
664 SIPE_DEBUG_INFO_NOFORMAT("sipe_purple_plugin_load: registering D-Bus bindings");
665 purple_dbus_register_bindings(plugin
, sipe_purple_dbus_bindings
);
671 struct sigaction action
;
672 memset(&action
, 0, sizeof (action
));
673 action
.sa_handler
= sipe_purple_sigusr1_handler
;
674 sigaction(SIGUSR1
, &action
, NULL
);
678 sipe_purple_activity_init();
683 gboolean
sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
686 struct sigaction action
;
687 memset(&action
, 0, sizeof (action
));
688 action
.sa_handler
= SIG_DFL
;
689 sigaction(SIGUSR1
, &action
, NULL
);
692 sipe_purple_activity_shutdown();
697 static void sipe_purple_show_about_plugin(PurpleProtocolAction
*action
)
699 gchar
*tmp
= sipe_core_about();
700 purple_notify_formatted(SIPE_PURPLE_ACTION_TO_CONNECTION
,
701 NULL
, " ", NULL
, tmp
, NULL
, NULL
);
705 static void sipe_purple_join_conference_cb(PurpleConnection
*gc
,
706 PurpleRequestFields
*fields
)
708 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
711 const gchar
*location
= purple_request_fields_get_string(fields
,
713 const gchar
*organizer
= purple_request_fields_get_string(fields
,
715 const gchar
*meeting_id
= purple_request_fields_get_string(fields
,
717 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
726 static void sipe_purple_phone_call_cb(PurpleConnection
*gc
,
727 PurpleRequestFields
*fields
)
729 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
732 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
733 purple_request_fields_get_string(fields
,
737 static void sipe_purple_phone_call(PurpleProtocolAction
*action
)
739 PurpleConnection
*gc
= SIPE_PURPLE_ACTION_TO_CONNECTION
;
740 PurpleRequestFields
*fields
;
741 PurpleRequestFieldGroup
*group
;
742 PurpleRequestField
*field
;
744 fields
= purple_request_fields_new();
745 group
= purple_request_field_group_new(NULL
);
746 purple_request_fields_add_group(fields
, group
);
748 field
= purple_request_field_string_new("phoneNumber", _("Phone number"), NULL
, FALSE
);
749 purple_request_field_group_add_field(group
, field
);
751 purple_request_fields(gc
,
752 _("Call a phone number"),
753 _("Call a phone number"),
756 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb
),
758 #if PURPLE_VERSION_CHECK(3,0,0)
759 purple_request_cpar_from_connection(gc
),
761 purple_connection_get_account(gc
), NULL
, NULL
,
766 static void sipe_purple_test_call(PurpleProtocolAction
*action
)
768 PurpleConnection
*gc
= SIPE_PURPLE_ACTION_TO_CONNECTION
;
769 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
773 static void sipe_purple_show_join_conference(PurpleProtocolAction
*action
)
775 PurpleConnection
*gc
= SIPE_PURPLE_ACTION_TO_CONNECTION
;
776 PurpleRequestFields
*fields
;
777 PurpleRequestFieldGroup
*group
;
778 PurpleRequestField
*field
;
780 fields
= purple_request_fields_new();
781 group
= purple_request_field_group_new(NULL
);
782 purple_request_fields_add_group(fields
, group
);
784 field
= purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL
, FALSE
);
785 purple_request_field_group_add_field(group
, field
);
786 field
= purple_request_field_label_new("separator", _("Alternatively"));
787 purple_request_field_group_add_field(group
, field
);
788 field
= purple_request_field_string_new("meetingOrganizer", _("Organizer email"), NULL
, FALSE
);
789 purple_request_field_group_add_field(group
, field
);
790 field
= purple_request_field_string_new("meetingID", _("Meeting ID"), NULL
, FALSE
);
791 purple_request_field_group_add_field(group
, field
);
793 purple_request_fields(gc
,
794 _("Join conference"),
795 _("Join scheduled conference"),
796 _("Enter meeting location string you received in the invitation.\n"
798 "Valid location will be something like\n"
799 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
800 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
802 "https://meet.company.com/someone/abcdef1234"),
804 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb
),
806 #if PURPLE_VERSION_CHECK(3,0,0)
807 purple_request_cpar_from_connection(gc
),
809 purple_connection_get_account(gc
), NULL
, NULL
,
814 void sipe_purple_republish_calendar(PurpleAccount
*account
)
816 struct sipe_core_public
*sipe_public
= PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC
;
817 if (get_dont_publish_flag(account
)) {
818 sipe_backend_notify_error(sipe_public
,
819 _("Publishing of calendar information has been disabled"),
822 sipe_core_update_calendar(sipe_public
);
826 static void sipe_purple_republish_calendar_action(PurpleProtocolAction
*action
)
828 PurpleConnection
*gc
= SIPE_PURPLE_ACTION_TO_CONNECTION
;
829 PurpleAccount
*account
= purple_connection_get_account(gc
);
830 sipe_purple_republish_calendar(account
);
833 void sipe_purple_reset_status(PurpleAccount
*account
)
835 if (get_dont_publish_flag(account
)) {
836 sipe_backend_notify_error(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC
,
837 _("Publishing of calendar information has been disabled"),
840 sipe_core_reset_status(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC
);
844 static void sipe_purple_reset_status_action(PurpleProtocolAction
*action
)
846 PurpleConnection
*gc
= SIPE_PURPLE_ACTION_TO_CONNECTION
;
847 PurpleAccount
*account
= purple_connection_get_account(gc
);
848 sipe_purple_reset_status(account
);
851 GList
*sipe_purple_actions()
854 PurpleProtocolAction
*act
;
856 act
= purple_protocol_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin
);
857 menu
= g_list_prepend(menu
, act
);
859 act
= purple_protocol_action_new(_("Contact search..."), sipe_purple_show_find_contact
);
860 menu
= g_list_prepend(menu
, act
);
863 act
= purple_protocol_action_new(_("Call a phone number..."), sipe_purple_phone_call
);
864 menu
= g_list_prepend(menu
, act
);
866 act
= purple_protocol_action_new(_("Test call"), sipe_purple_test_call
);
867 menu
= g_list_prepend(menu
, act
);
870 act
= purple_protocol_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference
);
871 menu
= g_list_prepend(menu
, act
);
873 act
= purple_protocol_action_new(_("Republish Calendar"), sipe_purple_republish_calendar_action
);
874 menu
= g_list_prepend(menu
, act
);
876 act
= purple_protocol_action_new(_("Reset status"), sipe_purple_reset_status_action
);
877 menu
= g_list_prepend(menu
, act
);
879 return g_list_reverse(menu
);
882 GList
* sipe_purple_account_options()
884 PurpleAccountOption
*option
;
885 GList
*options
= NULL
;
888 * When adding new string settings please make sure to keep these
892 * purple-settings.c:setting_name[]
894 option
= purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
895 options
= g_list_append(options
, option
);
897 option
= purple_account_option_list_new(_("Connection type"), "transport", NULL
);
898 purple_account_option_add_list_item(option
, _("Auto"), "auto");
899 purple_account_option_add_list_item(option
, _("SSL/TLS"), "tls");
900 purple_account_option_add_list_item(option
, _("TCP"), "tcp");
901 options
= g_list_append(options
, option
);
903 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
904 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
906 option
= purple_account_option_string_new(_("User Agent"), "useragent", "");
907 options
= g_list_append(options
, option
);
909 option
= purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL
);
910 purple_account_option_add_list_item(option
, _("Auto"), "auto");
911 purple_account_option_add_list_item(option
, _("NTLM"), "ntlm");
912 #if PURPLE_SIPE_SSO_AND_KERBEROS
913 purple_account_option_add_list_item(option
, _("Kerberos"), "krb5");
915 purple_account_option_add_list_item(option
, _("TLS-DSK"), "tls-dsk");
916 options
= g_list_append(options
, option
);
918 #if PURPLE_SIPE_SSO_AND_KERBEROS
920 * When the user selects Single Sign-On then SIPE will ignore the
921 * settings for "login name" and "password". Instead it will use the
922 * default credentials provided by the OS.
924 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
925 * SIPE that it is OK to use Single Sign-On or not.
927 * Configurations that are known to support Single Sign-On:
929 * - Windows, host joined to domain, SIPE with SSPI: NTLM
930 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
931 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
933 option
= purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE
);
934 options
= g_list_append(options
, option
);
937 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
938 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
940 option
= purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE
);
941 options
= g_list_append(options
, option
);
943 option
= purple_account_option_bool_new(_("Show profile pictures from web\n(potentially dangerous)"), "allow-web-photo", FALSE
);
944 options
= g_list_append(options
, option
);
946 option
= purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
947 options
= g_list_append(options
, option
);
949 option
= purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
950 options
= g_list_append(options
, option
);
952 /** Example (Exchange): DOMAIN\user or user@company.com
953 * Example (Domino) : email_address
955 option
= purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
956 options
= g_list_append(options
, option
);
958 option
= purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
959 purple_account_option_string_set_masked(option
, TRUE
);
960 options
= g_list_append(options
, option
);
962 /** Example (federated domain): company.com (i.e. ocschat@company.com)
963 * Example (non-default user): user@company.com
965 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", "");
966 options
= g_list_append(options
, option
);
969 option
= purple_account_option_string_new(_("Remote desktop client"), "rdp_client", "");
970 options
= g_list_append(options
, option
);
974 option
= purple_account_option_list_new(_("Media encryption"), "encryption-policy", NULL
);
975 purple_account_option_add_list_item(option
, _("Obey server policy"), "obey-server");
976 purple_account_option_add_list_item(option
, _("Always"), "required");
977 purple_account_option_add_list_item(option
, _("Optional"), "optional");
978 purple_account_option_add_list_item(option
, _("Disabled"), "disabled");
979 options
= g_list_append(options
, option
);
985 gpointer
sipe_purple_user_split()
987 PurpleAccountUserSplit
*split
=
988 purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL
, ',');
989 purple_account_user_split_set_reverse(split
, FALSE
);