2 * @file purple-plugin.c
6 * Copyright (C) 2010-2013 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
32 #include "sipe-common.h"
34 /* Flag needed for correct version of PURPLE_INIT_PLUGIN() */
35 #ifndef PURPLE_PLUGINS
36 #define PURPLE_PLUGINS
40 * as it's determined on runtime, as Pidgin installation can be anywhere.
43 #include "win32/win32dep.h"
46 #include "accountopt.h"
48 #include "connection.h"
60 #include "sipe-backend.h"
61 #include "sipe-core.h"
64 #define _PurpleMessageFlags PurpleMessageFlags
65 #include "purple-private.h"
67 /* Backward compatibility when compiling against 2.4.x API */
68 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
69 #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100
73 * NOTE: this flag means two things:
75 * - is Single Sign-On supported, and
76 * - is Kerberos supported
78 #if defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_SSPI)
79 #define PURPLE_SIPE_SSO_AND_KERBEROS 1
81 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
84 /* Sipe core activity <-> Purple status mapping */
85 static const gchar
* const activity_to_purple_map
[SIPE_ACTIVITY_NUM_TYPES
] = {
86 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
87 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
88 /* SIPE_ACTIVITY_ONLINE */ "online",
89 /* SIPE_ACTIVITY_INACTIVE */ "idle",
90 /* SIPE_ACTIVITY_BUSY */ "busy",
91 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
92 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
93 /* SIPE_ACTIVITY_BRB */ "be-right-back",
94 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
95 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
96 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
97 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
98 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
99 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
100 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
101 /* SIPE_ACTIVITY_OOF */ "out-of-office",
102 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
105 GHashTable
*purple_token_map
;
107 static void sipe_purple_activity_init(void)
111 purple_token_map
= g_hash_table_new(g_str_hash
, g_str_equal
);
112 for (index
= SIPE_ACTIVITY_UNSET
;
113 index
< SIPE_ACTIVITY_NUM_TYPES
;
115 g_hash_table_insert(purple_token_map
,
116 (gchar
*) activity_to_purple_map
[index
],
117 GUINT_TO_POINTER(index
));
121 static void sipe_purple_activity_shutdown(void)
123 g_hash_table_destroy(purple_token_map
);
126 const gchar
*sipe_purple_activity_to_token(guint type
)
128 return(activity_to_purple_map
[type
]);
131 guint
sipe_purple_token_to_activity(const gchar
*token
)
133 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map
, token
)));
136 gchar
*sipe_backend_version(void)
138 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
141 /* PurplePluginProtocolInfo function calls & data structure */
142 static const char *sipe_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount
*a
,
143 SIPE_UNUSED_PARAMETER PurpleBuddy
*b
)
148 static gchar
*sipe_purple_status_text(PurpleBuddy
*buddy
)
150 const PurpleStatus
*status
= purple_presence_get_active_status(purple_buddy_get_presence(buddy
));
151 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
153 sipe_purple_token_to_activity(purple_status_get_id(status
)),
154 purple_status_get_name(status
));
157 static void sipe_purple_tooltip_text(PurpleBuddy
*buddy
,
158 PurpleNotifyUserInfo
*user_info
,
159 SIPE_UNUSED_PARAMETER gboolean full
)
161 const PurplePresence
*presence
= purple_buddy_get_presence(buddy
);
162 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
164 purple_status_get_name(purple_presence_get_active_status(presence
)),
165 purple_presence_is_online(presence
),
166 (struct sipe_backend_buddy_tooltip
*) user_info
);
169 static GList
*sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount
*acc
)
171 PurpleStatusType
*type
;
174 /* Macros to reduce code repetition.
176 #define SIPE_ADD_STATUS(prim,id,name,user) type = purple_status_type_new_with_attrs( \
179 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
181 types = g_list_append(types, type);
184 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE
,
190 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
191 sipe_purple_activity_to_token(SIPE_ACTIVITY_BUSY
),
192 sipe_core_activity_description(SIPE_ACTIVITY_BUSY
),
196 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
197 sipe_purple_activity_to_token(SIPE_ACTIVITY_DND
),
202 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
203 sipe_purple_activity_to_token(SIPE_ACTIVITY_ON_PHONE
),
204 sipe_core_activity_description(SIPE_ACTIVITY_ON_PHONE
),
207 /* In a conference call */
208 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
209 sipe_purple_activity_to_token(SIPE_ACTIVITY_IN_CONF
),
210 sipe_core_activity_description(SIPE_ACTIVITY_IN_CONF
),
214 /* Goes first in the list as
215 * purple picks the first status with the AWAY type
218 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
224 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
225 sipe_purple_activity_to_token(SIPE_ACTIVITY_BRB
),
226 sipe_core_activity_description(SIPE_ACTIVITY_BRB
),
230 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE
,
236 type
= purple_status_type_new(PURPLE_STATUS_OFFLINE
,
240 types
= g_list_append(types
, type
);
245 static GList
*sipe_purple_blist_node_menu(PurpleBlistNode
*node
)
247 if(PURPLE_BLIST_NODE_IS_BUDDY(node
)) {
248 return sipe_purple_buddy_menu((PurpleBuddy
*) node
);
249 } else if(PURPLE_BLIST_NODE_IS_CHAT(node
)) {
250 return sipe_purple_chat_menu((PurpleChat
*)node
);
256 static guint
get_authentication_type(PurpleAccount
*account
)
258 const gchar
*auth
= purple_account_get_string(account
, "authentication", "ntlm");
260 /* map option list to type - default is NTLM */
261 guint authentication_type
= SIPE_AUTHENTICATION_TYPE_NTLM
;
262 #if PURPLE_SIPE_SSO_AND_KERBEROS
263 if (sipe_strequal(auth
, "krb5")) {
264 authentication_type
= SIPE_AUTHENTICATION_TYPE_KERBEROS
;
267 if (sipe_strequal(auth
, "tls-dsk")) {
268 authentication_type
= SIPE_AUTHENTICATION_TYPE_TLS_DSK
;
271 return(authentication_type
);
274 static gboolean
get_sso_flag(PurpleAccount
*account
)
276 #if PURPLE_SIPE_SSO_AND_KERBEROS
278 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
279 * SIPE that it is OK to use Single Sign-On or not.
281 return(purple_account_get_bool(account
, "sso", FALSE
));
283 (void) account
; /* keep compiler happy */
288 static gboolean
get_dont_publish_flag(PurpleAccount
*account
)
290 /* default is to publish calendar information */
291 return(purple_account_get_bool(account
, "dont-publish", FALSE
));
294 static void connect_to_core(PurpleConnection
*gc
,
295 PurpleAccount
*account
,
296 const gchar
*password
)
298 const gchar
*username
= purple_account_get_username(account
);
299 const gchar
*email
= purple_account_get_string(account
, "email", NULL
);
300 const gchar
*email_url
= purple_account_get_string(account
, "email_url", NULL
);
301 const gchar
*transport
= purple_account_get_string(account
, "transport", "auto");
302 struct sipe_core_public
*sipe_public
;
303 gchar
**username_split
;
304 gchar
*login_domain
= NULL
;
305 gchar
*login_account
= NULL
;
307 guint transport_type
;
308 struct sipe_backend_private
*purple_private
;
309 gboolean sso
= get_sso_flag(account
);
311 /* username format: <username>,[<optional login>] */
312 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username
);
313 username_split
= g_strsplit(username
, ",", 2);
315 /* login name is ignored when SSO has been selected */
317 /* login name specified? */
318 if (username_split
[1] && strlen(username_split
[1])) {
319 /* Allowed domain-account separators are / or \ */
320 gchar
**domain_user
= g_strsplit_set(username_split
[1], "/\\", 2);
321 gboolean has_domain
= domain_user
[1] != NULL
;
322 SIPE_DEBUG_INFO("sipe_purple_login: login '%s'", username_split
[1]);
323 login_domain
= has_domain
? g_strdup(domain_user
[0]) : NULL
;
324 login_account
= g_strdup(domain_user
[has_domain
? 1 : 0]);
325 SIPE_DEBUG_INFO("sipe_purple_login: auth domain '%s' user '%s'",
326 login_domain
? login_domain
: "",
328 g_strfreev(domain_user
);
330 /* No -> duplicate username */
331 login_account
= g_strdup(username_split
[0]);
335 sipe_public
= sipe_core_allocate(username_split
[0],
337 login_domain
, login_account
,
342 g_free(login_domain
);
343 g_free(login_account
);
344 g_strfreev(username_split
);
347 #if PURPLE_VERSION_CHECK(3,0,0)
348 purple_connection_error(
350 purple_connection_error_reason(
353 PURPLE_CONNECTION_ERROR_INVALID_USERNAME
,
358 sipe_public
->backend_private
= purple_private
= g_new0(struct sipe_backend_private
, 1);
359 purple_private
->public = sipe_public
;
360 purple_private
->gc
= gc
;
361 purple_private
->account
= account
;
363 sipe_purple_chat_setup_rejoin(purple_private
);
365 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH
);
366 if (get_dont_publish_flag(account
))
367 SIPE_CORE_FLAG_SET(DONT_PUBLISH
);
369 gc
->proto_data
= sipe_public
;
370 gc
->flags
|= PURPLE_CONNECTION_HTML
| PURPLE_CONNECTION_FORMATTING_WBFO
| PURPLE_CONNECTION_NO_BGCOLOR
|
371 PURPLE_CONNECTION_NO_FONTSIZE
| PURPLE_CONNECTION_NO_URLDESC
| PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
;
372 purple_connection_set_display_name(gc
, sipe_public
->sip_name
);
373 purple_connection_update_progress(gc
, _("Connecting"), 1, 2);
375 username_split
= g_strsplit(purple_account_get_string(account
, "server", ""), ":", 2);
376 if (sipe_strequal(transport
, "auto")) {
377 transport_type
= (username_split
[0] == NULL
) ?
378 SIPE_TRANSPORT_AUTO
: SIPE_TRANSPORT_TLS
;
379 } else if (sipe_strequal(transport
, "tls")) {
380 transport_type
= SIPE_TRANSPORT_TLS
;
382 transport_type
= SIPE_TRANSPORT_TCP
;
384 sipe_core_transport_sip_connect(sipe_public
,
386 get_authentication_type(account
),
388 username_split
[0] ? username_split
[1] : NULL
);
389 g_strfreev(username_split
);
392 static void password_required_cb(PurpleConnection
*gc
,
393 SIPE_UNUSED_PARAMETER PurpleRequestFields
*fields
)
395 if (!PURPLE_CONNECTION_IS_VALID(gc
))
398 #if PURPLE_VERSION_CHECK(3,0,0)
399 purple_connection_error(
401 purple_connection_error_reason(
404 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
,
405 _("Password required"));
408 static void password_ok_cb(PurpleConnection
*gc
,
409 PurpleRequestFields
*fields
)
411 const gchar
*password
;
413 if (!PURPLE_CONNECTION_IS_VALID(gc
))
416 password
= purple_request_fields_get_string(fields
, "password");
418 if (password
&& strlen(password
)) {
419 PurpleAccount
*account
= purple_connection_get_account(gc
);
421 if (purple_request_fields_get_bool(fields
, "remember"))
422 purple_account_set_remember_password(account
, TRUE
);
423 purple_account_set_password(account
, password
424 #if PURPLE_VERSION_CHECK(3,0,0)
429 /* Now we have a password and we can connect */
430 connect_to_core(gc
, account
, password
);
433 /* reject an empty password */
434 password_required_cb(gc
, fields
);
437 static void sipe_purple_login(PurpleAccount
*account
)
439 PurpleConnection
*gc
= purple_account_get_connection(account
);
440 const gchar
*password
= purple_connection_get_password(gc
);
442 /* Password required? */
443 if (sipe_core_transport_sip_requires_password(get_authentication_type(account
),
444 get_sso_flag(account
)) &&
445 (!password
|| !strlen(password
)))
446 /* No password set - request one from user */
447 purple_account_request_password(account
,
448 G_CALLBACK(password_ok_cb
),
449 G_CALLBACK(password_required_cb
),
452 /* No password required or saved password - connect now */
453 connect_to_core(gc
, account
, password
);
457 static void sipe_purple_close(PurpleConnection
*gc
)
459 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
462 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
464 sipe_core_deallocate(sipe_public
);
466 /* anything left after that must be in pending state... */
467 sipe_purple_dns_query_cancel_all(purple_private
);
468 sipe_purple_transport_close_all(purple_private
);
470 if (purple_private
->roomlist_map
)
471 g_hash_table_destroy(purple_private
->roomlist_map
);
472 sipe_purple_chat_destroy_rejoin(purple_private
);
473 g_free(purple_private
);
474 gc
->proto_data
= NULL
;
478 static int sipe_purple_send_im(PurpleConnection
*gc
,
481 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags
)
483 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
, what
);
487 static unsigned int sipe_purple_send_typing(PurpleConnection
*gc
,
489 PurpleTypingState state
)
491 gboolean typing
= (state
== PURPLE_TYPING
);
493 /* only enable this debug output while testing
494 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
496 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
500 /* tell libpurple to send typing indications every 4 seconds */
501 return(typing
? 4 : 0);
504 static void sipe_purple_get_info(PurpleConnection
*gc
, const char *who
)
506 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
510 static void sipe_purple_add_permit(PurpleConnection
*gc
, const char *name
)
512 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, TRUE
);
515 static void sipe_purple_add_deny(PurpleConnection
*gc
, const char *name
)
517 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, FALSE
);
520 static void sipe_purple_alias_buddy(PurpleConnection
*gc
, const char *name
,
523 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, alias
);
526 static void sipe_purple_group_rename(PurpleConnection
*gc
,
527 const char *old_name
,
529 SIPE_UNUSED_PARAMETER GList
*moved_buddies
)
531 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, old_name
, group
->name
);
534 static void sipe_purple_convo_closed(PurpleConnection
*gc
,
537 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
);
540 static void sipe_purple_group_remove(PurpleConnection
*gc
, PurpleGroup
*group
)
542 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, group
->name
);
545 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
547 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount
*account
)
550 table
= g_hash_table_new(g_str_hash
, g_str_equal
);
551 g_hash_table_insert(table
, "login_label", (gpointer
)_("user@company.com"));
555 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
559 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER
int signum
)
561 capture_pipeline("PURPLE_SIPE_PIPELINE");
564 static gboolean
sipe_purple_initiate_media(PurpleAccount
*account
, const char *who
,
565 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type
)
567 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC
,
569 (type
& PURPLE_MEDIA_VIDEO
));
573 static PurpleMediaCaps
sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount
*account
,
574 SIPE_UNUSED_PARAMETER
const char *who
)
576 return PURPLE_MEDIA_CAPS_AUDIO
577 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
578 | PURPLE_MEDIA_CAPS_MODIFY_SESSION
;
585 * Simplistic source upward compatibility path for newer libpurple APIs
587 * Usually we compile with -Werror=missing-field-initializers if GCC supports
588 * it. But that means that the compilation of this structure can fail if the
589 * newer API has added additional plugin callbacks. For the benefit of the
590 * user we downgrade it to a warning here.
592 * Diagnostic #pragma was added in GCC 4.2.0
593 * Diagnostic push/pop was added in GCC 4.6.0
596 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 2)
597 #if __GNUC_MINOR__ >= 6
598 #pragma GCC diagnostic push
600 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
603 static PurplePluginProtocolInfo sipe_prpl_info
=
605 #if PURPLE_VERSION_CHECK(3,0,0)
606 sizeof(PurplePluginProtocolInfo
), /* struct_size */
608 OPT_PROTO_CHAT_TOPIC
|
609 OPT_PROTO_PASSWORD_OPTIONAL
,
610 NULL
, /* user_splits */
611 NULL
, /* protocol_options */
612 NO_BUDDY_ICONS
, /* icon_spec */
613 sipe_list_icon
, /* list_icon */
614 NULL
, /* list_emblems */
615 sipe_purple_status_text
, /* status_text */
616 sipe_purple_tooltip_text
, /* tooltip_text */ // add custom info to contact tooltip
617 sipe_purple_status_types
, /* away_states */
618 sipe_purple_blist_node_menu
, /* blist_node_menu */
619 sipe_purple_chat_info
, /* chat_info */
620 sipe_purple_chat_info_defaults
, /* chat_info_defaults */
621 sipe_purple_login
, /* login */
622 sipe_purple_close
, /* close */
623 sipe_purple_send_im
, /* send_im */
624 NULL
, /* set_info */ // TODO maybe
625 sipe_purple_send_typing
, /* send_typing */
626 sipe_purple_get_info
, /* get_info */
627 sipe_purple_set_status
, /* set_status */
628 sipe_purple_set_idle
, /* set_idle */
629 NULL
, /* change_passwd */
630 sipe_purple_add_buddy
, /* add_buddy */
631 NULL
, /* add_buddies */
632 sipe_purple_remove_buddy
, /* remove_buddy */
633 NULL
, /* remove_buddies */
634 sipe_purple_add_permit
, /* add_permit */
635 sipe_purple_add_deny
, /* add_deny */
636 sipe_purple_add_deny
, /* rem_permit */
637 sipe_purple_add_permit
, /* rem_deny */
638 NULL
, /* set_permit_deny */
639 sipe_purple_chat_join
, /* join_chat */
640 NULL
, /* reject_chat */
641 NULL
, /* get_chat_name */
642 sipe_purple_chat_invite
, /* chat_invite */
643 sipe_purple_chat_leave
, /* chat_leave */
644 NULL
, /* chat_whisper */
645 sipe_purple_chat_send
, /* chat_send */
646 NULL
, /* keepalive */
647 NULL
, /* register_user */
648 NULL
, /* get_cb_info */ // deprecated
649 #if !PURPLE_VERSION_CHECK(3,0,0)
650 NULL
, /* get_cb_away */ // deprecated
652 sipe_purple_alias_buddy
, /* alias_buddy */
653 sipe_purple_group_buddy
, /* group_buddy */
654 sipe_purple_group_rename
, /* rename_group */
655 NULL
, /* buddy_free */
656 sipe_purple_convo_closed
, /* convo_closed */
657 purple_normalize_nocase
, /* normalize */
658 NULL
, /* set_buddy_icon */
659 sipe_purple_group_remove
, /* remove_group */
660 NULL
, /* get_cb_real_name */ // TODO?
661 NULL
, /* set_chat_topic */
662 NULL
, /* find_blist_chat */
663 sipe_purple_roomlist_get_list
, /* roomlist_get_list */
664 sipe_purple_roomlist_cancel
, /* roomlist_cancel */
665 NULL
, /* roomlist_expand_category */
666 NULL
, /* can_receive_file */
667 sipe_purple_ft_send_file
, /* send_file */
668 sipe_purple_ft_new_xfer
, /* new_xfer */
669 NULL
, /* offline_message */
670 NULL
, /* whiteboard_prpl_ops */
672 NULL
, /* roomlist_room_serialize */
673 NULL
, /* unregister_user */
674 NULL
, /* send_attention */
675 NULL
, /* get_attention_types */
676 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
677 /* Backward compatibility when compiling against 2.4.x API */
678 (void (*)(void)) /* _purple_reserved4 */
680 #if !PURPLE_VERSION_CHECK(3,0,0)
681 sizeof(PurplePluginProtocolInfo
), /* struct_size */
683 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
684 sipe_purple_get_account_text_table
, /* get_account_text_table */
685 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
687 sipe_purple_initiate_media
, /* initiate_media */
688 sipe_purple_get_media_caps
, /* get_media_caps */
690 NULL
, /* initiate_media */
691 NULL
, /* get_media_caps */
693 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
694 NULL
, /* get_moods */
695 NULL
, /* set_public_alias */
696 NULL
, /* get_public_alias */
697 #if PURPLE_VERSION_CHECK(2,8,0)
698 NULL
, /* add_buddy_with_invite */
699 NULL
, /* add_buddies_with_invite */
700 #elif PURPLE_VERSION_CHECK(3,0,0)
701 NULL
, /* get_max_message_size */
708 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 6)
709 #pragma GCC diagnostic pop
712 /* Original GCC error checking restored from here on... (see above) */
714 /* PurplePluginInfo function calls & data structure */
715 static gboolean
sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
718 struct sigaction action
;
719 memset(&action
, 0, sizeof (action
));
720 action
.sa_handler
= sipe_purple_sigusr1_handler
;
721 sigaction(SIGUSR1
, &action
, NULL
);
726 static gboolean
sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
729 struct sigaction action
;
730 memset(&action
, 0, sizeof (action
));
731 action
.sa_handler
= SIG_DFL
;
732 sigaction(SIGUSR1
, &action
, NULL
);
737 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
741 sipe_purple_activity_shutdown();
744 entry
= sipe_prpl_info
.protocol_options
;
746 purple_account_option_destroy(entry
->data
);
747 entry
= g_list_delete_link(entry
, entry
);
749 sipe_prpl_info
.protocol_options
= NULL
;
751 entry
= sipe_prpl_info
.user_splits
;
753 purple_account_user_split_destroy(entry
->data
);
754 entry
= g_list_delete_link(entry
, entry
);
756 sipe_prpl_info
.user_splits
= NULL
;
759 static void sipe_purple_show_about_plugin(PurplePluginAction
*action
)
761 gchar
*tmp
= sipe_core_about();
762 purple_notify_formatted((PurpleConnection
*) action
->context
,
763 NULL
, " ", NULL
, tmp
, NULL
, NULL
);
767 static void sipe_purple_find_contact_cb(PurpleConnection
*gc
,
768 PurpleRequestFields
*fields
)
770 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
771 const gchar
*given_name
= NULL
;
772 const gchar
*surname
= NULL
;
773 const gchar
*email
= NULL
;
774 const gchar
*company
= NULL
;
775 const gchar
*country
= NULL
;
778 PurpleRequestField
*field
= entries
->data
;
779 const char *id
= purple_request_field_get_id(field
);
780 const char *value
= purple_request_field_string_get_value(field
);
782 SIPE_DEBUG_INFO("sipe_purple_find_contact_cb: %s = '%s'", id
, value
? value
: "");
785 if (strcmp(id
, "given") == 0) {
787 } else if (strcmp(id
, "surname") == 0) {
789 } else if (strcmp(id
, "email") == 0) {
791 } else if (strcmp(id
, "company") == 0) {
793 } else if (strcmp(id
, "country") == 0) {
798 entries
= g_list_next(entries
);
801 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
810 static void sipe_purple_show_find_contact(PurplePluginAction
*action
)
812 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
813 PurpleRequestFields
*fields
;
814 PurpleRequestFieldGroup
*group
;
815 PurpleRequestField
*field
;
816 #if PURPLE_VERSION_CHECK(3,0,0)
817 PurpleRequestCommonParameters
*cpar
= purple_request_cpar_from_connection(gc
);
820 fields
= purple_request_fields_new();
821 group
= purple_request_field_group_new(NULL
);
822 purple_request_fields_add_group(fields
, group
);
824 field
= purple_request_field_string_new("given", _("First name"), NULL
, FALSE
);
825 purple_request_field_group_add_field(group
, field
);
826 field
= purple_request_field_string_new("surname", _("Last name"), NULL
, FALSE
);
827 purple_request_field_group_add_field(group
, field
);
828 field
= purple_request_field_string_new("email", _("Email"), NULL
, FALSE
);
829 purple_request_field_group_add_field(group
, field
);
830 field
= purple_request_field_string_new("company", _("Company"), NULL
, FALSE
);
831 purple_request_field_group_add_field(group
, field
);
832 field
= purple_request_field_string_new("country", _("Country"), NULL
, FALSE
);
833 purple_request_field_group_add_field(group
, field
);
835 purple_request_fields(gc
,
837 _("Search for a contact"),
838 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
840 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb
),
842 #if PURPLE_VERSION_CHECK(3,0,0)
844 purple_request_cpar_unref(cpar
);
846 purple_connection_get_account(gc
), NULL
, NULL
, gc
);
850 static void sipe_purple_join_conference_cb(PurpleConnection
*gc
,
851 PurpleRequestFields
*fields
)
853 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
856 PurpleRequestField
*field
= entries
->data
;
857 const char *id
= purple_request_field_get_id(field
);
858 const char *value
= purple_request_field_string_get_value(field
);
860 if (!sipe_strequal(id
, "meetingLocation"))
863 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, value
);
869 static void sipe_purple_phone_call_cb(PurpleConnection
*gc
,
870 PurpleRequestFields
*fields
)
872 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
875 PurpleRequestField
*field
= entries
->data
;
876 const char *id
= purple_request_field_get_id(field
);
877 const char *value
= purple_request_field_string_get_value(field
);
879 if (!sipe_strequal(id
, "phoneNumber"))
882 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, value
);
886 static void sipe_purple_phone_call(PurplePluginAction
*action
)
888 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
889 PurpleRequestFields
*fields
;
890 PurpleRequestFieldGroup
*group
;
891 PurpleRequestField
*field
;
892 #if PURPLE_VERSION_CHECK(3,0,0)
893 PurpleRequestCommonParameters
*cpar
= purple_request_cpar_from_connection(gc
);
896 fields
= purple_request_fields_new();
897 group
= purple_request_field_group_new(NULL
);
898 purple_request_fields_add_group(fields
, group
);
900 field
= purple_request_field_string_new("phoneNumber", _("Phone number"), NULL
, FALSE
);
901 purple_request_field_group_add_field(group
, field
);
903 purple_request_fields(gc
,
904 _("Call a phone number"),
905 _("Call a phone number"),
908 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb
),
910 #if PURPLE_VERSION_CHECK(3,0,0)
912 purple_request_cpar_unref(cpar
);
914 purple_connection_get_account(gc
), NULL
, NULL
, gc
);
918 static void sipe_purple_test_call(PurplePluginAction
*action
)
920 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
921 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
925 static void sipe_purple_show_join_conference(PurplePluginAction
*action
)
927 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
928 PurpleRequestFields
*fields
;
929 PurpleRequestFieldGroup
*group
;
930 PurpleRequestField
*field
;
931 #if PURPLE_VERSION_CHECK(3,0,0)
932 PurpleRequestCommonParameters
*cpar
= purple_request_cpar_from_connection(gc
);
935 fields
= purple_request_fields_new();
936 group
= purple_request_field_group_new(NULL
);
937 purple_request_fields_add_group(fields
, group
);
939 field
= purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL
, FALSE
);
940 purple_request_field_group_add_field(group
, field
);
942 purple_request_fields(gc
,
943 _("Join conference"),
944 _("Join scheduled conference"),
945 _("Enter meeting location string you received in the invitation.\n"
947 "Valid location will be something like\n"
948 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
949 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
951 "https://meet.company.com/someone/abcdef1234"),
953 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb
),
955 #if PURPLE_VERSION_CHECK(3,0,0)
957 purple_request_cpar_unref(cpar
);
959 purple_connection_get_account(gc
), NULL
, NULL
, gc
);
963 static void sipe_purple_republish_calendar(PurplePluginAction
*action
)
965 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
966 PurpleAccount
*account
= purple_connection_get_account(gc
);
968 if (get_dont_publish_flag(account
)) {
969 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
970 _("Publishing of calendar information has been disabled"),
973 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
977 static void sipe_purple_reset_status(PurplePluginAction
*action
)
979 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
980 PurpleAccount
*account
= purple_connection_get_account(gc
);
982 if (get_dont_publish_flag(account
)) {
983 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
984 _("Publishing of calendar information has been disabled"),
987 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
991 static GList
*sipe_purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
,
992 SIPE_UNUSED_PARAMETER gpointer context
)
995 PurplePluginAction
*act
;
997 act
= purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin
);
998 menu
= g_list_prepend(menu
, act
);
1000 act
= purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact
);
1001 menu
= g_list_prepend(menu
, act
);
1004 act
= purple_plugin_action_new(_("Call a phone number..."), sipe_purple_phone_call
);
1005 menu
= g_list_prepend(menu
, act
);
1007 act
= purple_plugin_action_new(_("Test call"), sipe_purple_test_call
);
1008 menu
= g_list_prepend(menu
, act
);
1011 act
= purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference
);
1012 menu
= g_list_prepend(menu
, act
);
1014 act
= purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar
);
1015 menu
= g_list_prepend(menu
, act
);
1017 act
= purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status
);
1018 menu
= g_list_prepend(menu
, act
);
1020 return g_list_reverse(menu
);
1023 static PurplePluginInfo sipe_purple_info
= {
1024 PURPLE_PLUGIN_MAGIC
,
1025 PURPLE_MAJOR_VERSION
,
1026 PURPLE_MINOR_VERSION
,
1027 PURPLE_PLUGIN_PROTOCOL
, /**< type */
1028 NULL
, /**< ui_requirement */
1030 NULL
, /**< dependencies */
1031 PURPLE_PRIORITY_DEFAULT
, /**< priority */
1032 "prpl-sipe", /**< id */
1033 "Office Communicator", /**< name */
1034 PACKAGE_VERSION
, /**< version */
1035 "Microsoft Office Communicator Protocol Plugin", /**< summary */
1036 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
1037 "Microsoft Live/Office Communications/Lync Server (LCS2005/OCS2007+)", /**< description */
1038 "Stefan Becker <chemobejk@gmail.com>, " /**< author */
1039 "Jakub Adam <jakub.adam@tieto.com>, " /**< author */
1040 "Anibal Avelar <avelar@gmail.com> (retired), " /**< author */
1041 "pier11 <pier11@operamail.com> (retired), " /**< author */
1042 "Gabriel Burt <gburt@novell.com> (retired)", /**< author */
1043 PACKAGE_URL
, /**< homepage */
1044 sipe_purple_plugin_load
, /**< load */
1045 sipe_purple_plugin_unload
, /**< unload */
1046 sipe_purple_plugin_destroy
, /**< destroy */
1047 NULL
, /**< ui_info */
1048 &sipe_prpl_info
, /**< extra_info */
1050 sipe_purple_actions
,
1057 static void sipe_purple_init_plugin(PurplePlugin
*plugin
)
1059 PurpleAccountUserSplit
*split
;
1060 PurpleAccountOption
*option
;
1062 /* This needs to be called first */
1063 sipe_core_init(LOCALEDIR
);
1064 sipe_purple_activity_init();
1066 purple_plugin_register(plugin
);
1069 * When adding new string settings please make sure to keep these
1072 * api/sipe-backend.h
1073 * purple-settings.c:setting_name[]
1075 split
= purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL
, ',');
1076 purple_account_user_split_set_reverse(split
, FALSE
);
1077 sipe_prpl_info
.user_splits
= g_list_append(sipe_prpl_info
.user_splits
, split
);
1079 option
= purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
1080 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1082 option
= purple_account_option_list_new(_("Connection type"), "transport", NULL
);
1083 purple_account_option_add_list_item(option
, _("Auto"), "auto");
1084 purple_account_option_add_list_item(option
, _("SSL/TLS"), "tls");
1085 purple_account_option_add_list_item(option
, _("TCP"), "tcp");
1086 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1088 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
1089 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
1091 option
= purple_account_option_string_new(_("User Agent"), "useragent", "");
1092 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1094 option
= purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL
);
1095 purple_account_option_add_list_item(option
, _("NTLM"), "ntlm");
1096 #if PURPLE_SIPE_SSO_AND_KERBEROS
1097 purple_account_option_add_list_item(option
, _("Kerberos"), "krb5");
1099 purple_account_option_add_list_item(option
, _("TLS-DSK"), "tls-dsk");
1100 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1102 #if PURPLE_SIPE_SSO_AND_KERBEROS
1104 * When the user selects Single Sign-On then SIPE will ignore the
1105 * settings for "login name" and "password". Instead it will use the
1106 * default credentials provided by the OS.
1108 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
1109 * SIPE that it is OK to use Single Sign-On or not.
1111 * Configurations that are known to support Single Sign-On:
1113 * - Windows, host joined to domain, SIPE with SSPI: NTLM
1114 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
1115 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
1117 option
= purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE
);
1118 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1121 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
1122 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
1124 option
= purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE
);
1125 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1127 option
= purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
1128 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1130 option
= purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
1131 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1133 /** Example (Exchange): DOMAIN\user or user@company.com
1134 * Example (Domino) : email_address
1136 option
= purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
1137 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1139 option
= purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
1140 #if PURPLE_VERSION_CHECK(3,0,0)
1141 purple_account_option_string_set_masked(
1143 purple_account_option_set_masked(
1146 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1148 /** Example (federated domain): company.com (i.e. ocschat@company.com)
1149 * Example (non-default user): user@company.com
1151 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", "");
1152 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1155 /* This macro makes the code a purple plugin */
1156 PURPLE_INIT_PLUGIN(sipe
, sipe_purple_init_plugin
, sipe_purple_info
);