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"
59 * NOTE: Currently PURPLE_VERSION_CHECK(2,y,z) returns FALSE for libpurple >= 3.0.0.
60 * See also <http://developer.pidgin.im/ticket/14551>
62 * As a workaround an additional PURPLE_VERSION_CHECK(3,0,0) needs to be added.
66 #include "sipe-backend.h"
67 #include "sipe-core.h"
70 #define _PurpleMessageFlags PurpleMessageFlags
71 #include "purple-private.h"
73 /* Backward compatibility when compiling against 2.4.x API */
74 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
75 #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100
79 * NOTE: this flag means two things:
81 * - is Single Sign-On supported, and
82 * - is Kerberos supported
84 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
85 #define PURPLE_SIPE_SSO_AND_KERBEROS 1
87 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
90 /* Sipe core activity <-> Purple status mapping */
91 static const gchar
* const activity_to_purple_map
[SIPE_ACTIVITY_NUM_TYPES
] = {
92 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
93 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
94 /* SIPE_ACTIVITY_ONLINE */ "online",
95 /* SIPE_ACTIVITY_INACTIVE */ "idle",
96 /* SIPE_ACTIVITY_BUSY */ "busy",
97 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
98 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
99 /* SIPE_ACTIVITY_BRB */ "be-right-back",
100 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
101 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
102 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
103 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
104 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
105 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
106 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
107 /* SIPE_ACTIVITY_OOF */ "out-of-office",
108 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
111 GHashTable
*purple_token_map
;
113 static void sipe_purple_activity_init(void)
117 purple_token_map
= g_hash_table_new(g_str_hash
, g_str_equal
);
118 for (index
= SIPE_ACTIVITY_UNSET
;
119 index
< SIPE_ACTIVITY_NUM_TYPES
;
121 g_hash_table_insert(purple_token_map
,
122 (gchar
*) activity_to_purple_map
[index
],
123 GUINT_TO_POINTER(index
));
127 static void sipe_purple_activity_shutdown(void)
129 g_hash_table_destroy(purple_token_map
);
132 const gchar
*sipe_purple_activity_to_token(guint type
)
134 return(activity_to_purple_map
[type
]);
137 guint
sipe_purple_token_to_activity(const gchar
*token
)
139 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map
, token
)));
142 gchar
*sipe_backend_version(void)
144 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
147 /* PurplePluginProtocolInfo function calls & data structure */
148 static const char *sipe_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount
*a
,
149 SIPE_UNUSED_PARAMETER PurpleBuddy
*b
)
154 static gchar
*sipe_purple_status_text(PurpleBuddy
*buddy
)
156 const PurpleStatus
*status
= purple_presence_get_active_status(purple_buddy_get_presence(buddy
));
157 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
159 sipe_purple_token_to_activity(purple_status_get_id(status
)),
160 purple_status_get_name(status
));
163 static void sipe_purple_tooltip_text(PurpleBuddy
*buddy
,
164 PurpleNotifyUserInfo
*user_info
,
165 SIPE_UNUSED_PARAMETER gboolean full
)
167 const PurplePresence
*presence
= purple_buddy_get_presence(buddy
);
168 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
170 purple_status_get_name(purple_presence_get_active_status(presence
)),
171 purple_presence_is_online(presence
),
172 (struct sipe_backend_buddy_tooltip
*) user_info
);
175 static GList
*sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount
*acc
)
177 PurpleStatusType
*type
;
180 /* Macros to reduce code repetition.
182 #define SIPE_ADD_STATUS(prim,id,name,user) type = purple_status_type_new_with_attrs( \
185 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
187 types = g_list_append(types, type);
190 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE
,
196 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
197 sipe_purple_activity_to_token(SIPE_ACTIVITY_BUSY
),
198 sipe_core_activity_description(SIPE_ACTIVITY_BUSY
),
202 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
203 sipe_purple_activity_to_token(SIPE_ACTIVITY_DND
),
208 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
209 sipe_purple_activity_to_token(SIPE_ACTIVITY_ON_PHONE
),
210 sipe_core_activity_description(SIPE_ACTIVITY_ON_PHONE
),
213 /* In a conference call */
214 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
215 sipe_purple_activity_to_token(SIPE_ACTIVITY_IN_CONF
),
216 sipe_core_activity_description(SIPE_ACTIVITY_IN_CONF
),
220 /* Goes first in the list as
221 * purple picks the first status with the AWAY type
224 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
230 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
231 sipe_purple_activity_to_token(SIPE_ACTIVITY_BRB
),
232 sipe_core_activity_description(SIPE_ACTIVITY_BRB
),
236 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE
,
242 type
= purple_status_type_new(PURPLE_STATUS_OFFLINE
,
246 types
= g_list_append(types
, type
);
251 static GList
*sipe_purple_blist_node_menu(PurpleBlistNode
*node
)
253 if(PURPLE_BLIST_NODE_IS_BUDDY(node
)) {
254 return sipe_purple_buddy_menu((PurpleBuddy
*) node
);
255 } else if(PURPLE_BLIST_NODE_IS_CHAT(node
)) {
256 return sipe_purple_chat_menu((PurpleChat
*)node
);
262 static guint
get_authentication_type(PurpleAccount
*account
)
264 const gchar
*auth
= purple_account_get_string(account
, "authentication", "ntlm");
266 /* map option list to type - default is NTLM */
267 guint authentication_type
= SIPE_AUTHENTICATION_TYPE_NTLM
;
268 #if PURPLE_SIPE_SSO_AND_KERBEROS
269 if (sipe_strequal(auth
, "krb5")) {
270 authentication_type
= SIPE_AUTHENTICATION_TYPE_KERBEROS
;
273 if (sipe_strequal(auth
, "tls-dsk")) {
274 authentication_type
= SIPE_AUTHENTICATION_TYPE_TLS_DSK
;
277 return(authentication_type
);
280 static gboolean
get_sso_flag(PurpleAccount
*account
)
282 #if PURPLE_SIPE_SSO_AND_KERBEROS
284 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
285 * SIPE that it is OK to use Single Sign-On or not.
287 return(purple_account_get_bool(account
, "sso", FALSE
));
289 (void) account
; /* keep compiler happy */
294 static gboolean
get_dont_publish_flag(PurpleAccount
*account
)
296 /* default is to publish calendar information */
297 return(purple_account_get_bool(account
, "dont-publish", FALSE
));
300 static void connect_to_core(PurpleConnection
*gc
,
301 PurpleAccount
*account
,
302 const gchar
*password
)
304 const gchar
*username
= purple_account_get_username(account
);
305 const gchar
*email
= purple_account_get_string(account
, "email", NULL
);
306 const gchar
*email_url
= purple_account_get_string(account
, "email_url", NULL
);
307 const gchar
*transport
= purple_account_get_string(account
, "transport", "auto");
308 struct sipe_core_public
*sipe_public
;
309 gchar
**username_split
;
310 gchar
*login_domain
= NULL
;
311 gchar
*login_account
= NULL
;
313 guint transport_type
;
314 struct sipe_backend_private
*purple_private
;
315 gboolean sso
= get_sso_flag(account
);
317 /* username format: <username>,[<optional login>] */
318 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username
);
319 username_split
= g_strsplit(username
, ",", 2);
321 /* login name is ignored when SSO has been selected */
323 /* login name specified? */
324 if (username_split
[1] && strlen(username_split
[1])) {
325 /* Allowed domain-account separators are / or \ */
326 gchar
**domain_user
= g_strsplit_set(username_split
[1], "/\\", 2);
327 gboolean has_domain
= domain_user
[1] != NULL
;
328 SIPE_DEBUG_INFO("sipe_purple_login: login '%s'", username_split
[1]);
329 login_domain
= has_domain
? g_strdup(domain_user
[0]) : NULL
;
330 login_account
= g_strdup(domain_user
[has_domain
? 1 : 0]);
331 SIPE_DEBUG_INFO("sipe_purple_login: auth domain '%s' user '%s'",
332 login_domain
? login_domain
: "",
334 g_strfreev(domain_user
);
336 /* No -> duplicate username */
337 login_account
= g_strdup(username_split
[0]);
341 sipe_public
= sipe_core_allocate(username_split
[0],
343 login_domain
, login_account
,
348 g_free(login_domain
);
349 g_free(login_account
);
350 g_strfreev(username_split
);
353 #if PURPLE_VERSION_CHECK(3,0,0)
354 purple_connection_error(
356 purple_connection_error_reason(
359 PURPLE_CONNECTION_ERROR_INVALID_USERNAME
,
364 sipe_public
->backend_private
= purple_private
= g_new0(struct sipe_backend_private
, 1);
365 purple_private
->public = sipe_public
;
366 purple_private
->gc
= gc
;
367 purple_private
->account
= account
;
369 sipe_purple_chat_setup_rejoin(purple_private
);
371 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH
);
372 if (get_dont_publish_flag(account
))
373 SIPE_CORE_FLAG_SET(DONT_PUBLISH
);
375 gc
->proto_data
= sipe_public
;
376 gc
->flags
|= PURPLE_CONNECTION_HTML
| PURPLE_CONNECTION_FORMATTING_WBFO
| PURPLE_CONNECTION_NO_BGCOLOR
|
377 PURPLE_CONNECTION_NO_FONTSIZE
| PURPLE_CONNECTION_NO_URLDESC
| PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
;
378 purple_connection_set_display_name(gc
, sipe_public
->sip_name
);
379 purple_connection_update_progress(gc
, _("Connecting"), 1, 2);
381 username_split
= g_strsplit(purple_account_get_string(account
, "server", ""), ":", 2);
382 if (sipe_strequal(transport
, "auto")) {
383 transport_type
= (username_split
[0] == NULL
) ?
384 SIPE_TRANSPORT_AUTO
: SIPE_TRANSPORT_TLS
;
385 } else if (sipe_strequal(transport
, "tls")) {
386 transport_type
= SIPE_TRANSPORT_TLS
;
388 transport_type
= SIPE_TRANSPORT_TCP
;
390 sipe_core_transport_sip_connect(sipe_public
,
392 get_authentication_type(account
),
394 username_split
[0] ? username_split
[1] : NULL
);
395 g_strfreev(username_split
);
398 static void password_required_cb(PurpleConnection
*gc
,
399 SIPE_UNUSED_PARAMETER PurpleRequestFields
*fields
)
401 if (!PURPLE_CONNECTION_IS_VALID(gc
))
404 #if PURPLE_VERSION_CHECK(3,0,0)
405 purple_connection_error(
407 purple_connection_error_reason(
410 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
,
411 _("Password required"));
414 static void password_ok_cb(PurpleConnection
*gc
,
415 PurpleRequestFields
*fields
)
417 const gchar
*password
;
419 if (!PURPLE_CONNECTION_IS_VALID(gc
))
422 password
= purple_request_fields_get_string(fields
, "password");
424 if (password
&& strlen(password
)) {
425 PurpleAccount
*account
= purple_connection_get_account(gc
);
427 if (purple_request_fields_get_bool(fields
, "remember"))
428 purple_account_set_remember_password(account
, TRUE
);
429 purple_account_set_password(account
, password
);
431 /* Now we have a password and we can connect */
432 connect_to_core(gc
, account
, password
);
435 /* reject an empty password */
436 password_required_cb(gc
, fields
);
439 static void sipe_purple_login(PurpleAccount
*account
)
441 PurpleConnection
*gc
= purple_account_get_connection(account
);
442 const gchar
*password
= purple_connection_get_password(gc
);
444 /* Password required? */
445 if (sipe_core_transport_sip_requires_password(get_authentication_type(account
),
446 get_sso_flag(account
)) &&
447 (!password
|| !strlen(password
)))
448 /* No password set - request one from user */
449 purple_account_request_password(account
,
450 G_CALLBACK(password_ok_cb
),
451 G_CALLBACK(password_required_cb
),
454 /* No password required or saved password - connect now */
455 connect_to_core(gc
, account
, password
);
459 static void sipe_purple_close(PurpleConnection
*gc
)
461 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
464 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
466 sipe_core_deallocate(sipe_public
);
468 /* anything left after that must be in pending state... */
469 sipe_purple_dns_query_cancel_all(purple_private
);
470 sipe_purple_transport_close_all(purple_private
);
472 if (purple_private
->roomlist_map
)
473 g_hash_table_destroy(purple_private
->roomlist_map
);
474 sipe_purple_chat_destroy_rejoin(purple_private
);
475 g_free(purple_private
);
476 gc
->proto_data
= NULL
;
480 static int sipe_purple_send_im(PurpleConnection
*gc
,
483 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags
)
485 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
, what
);
489 #define SIPE_TYPING_SEND_TIMEOUT 4
491 static unsigned int sipe_purple_send_typing(PurpleConnection
*gc
,
493 PurpleTypingState state
)
495 if (state
== PURPLE_NOT_TYPING
)
498 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
501 return SIPE_TYPING_SEND_TIMEOUT
;
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_keep_alive(PurpleConnection
*gc
)
522 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
523 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
524 time_t now
= time(NULL
);
526 if ((sipe_public
->keepalive_timeout
> 0) &&
527 ((guint
) (now
- purple_private
->last_keepalive
) >= sipe_public
->keepalive_timeout
) &&
528 ((guint
) (now
- gc
->last_received
) >= sipe_public
->keepalive_timeout
)
530 sipe_core_transport_sip_keepalive(sipe_public
);
531 purple_private
->last_keepalive
= now
;
535 static void sipe_purple_alias_buddy(PurpleConnection
*gc
, const char *name
,
538 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, alias
);
541 static void sipe_purple_group_rename(PurpleConnection
*gc
,
542 const char *old_name
,
544 SIPE_UNUSED_PARAMETER GList
*moved_buddies
)
546 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, old_name
, group
->name
);
549 static void sipe_purple_convo_closed(PurpleConnection
*gc
,
552 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
);
555 static void sipe_purple_group_remove(PurpleConnection
*gc
, PurpleGroup
*group
)
557 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, group
->name
);
560 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
562 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount
*account
)
565 table
= g_hash_table_new(g_str_hash
, g_str_equal
);
566 g_hash_table_insert(table
, "login_label", (gpointer
)_("user@company.com"));
570 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
574 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER
int signum
)
576 capture_pipeline("PURPLE_SIPE_PIPELINE");
579 static gboolean
sipe_purple_initiate_media(PurpleAccount
*account
, const char *who
,
580 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type
)
582 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC
,
584 (type
& PURPLE_MEDIA_VIDEO
));
588 static PurpleMediaCaps
sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount
*account
,
589 SIPE_UNUSED_PARAMETER
const char *who
)
591 return PURPLE_MEDIA_CAPS_AUDIO
592 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
593 | PURPLE_MEDIA_CAPS_MODIFY_SESSION
;
600 * Simplistic source upward compatibility path for newer libpurple APIs
602 * Usually we compile with -Werror=missing-field-initializers if GCC supports
603 * it. But that means that the compilation of this structure can fail if the
604 * newer API has added additional plugin callbacks. For the benefit of the
605 * user we downgrade it to a warning here.
607 * Diagnostic #pragma was added in GCC 4.2.0
608 * Diagnostic push/pop was added in GCC 4.6.0
611 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 2)
612 #if __GNUC_MINOR__ >= 6
613 #pragma GCC diagnostic push
615 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
618 static PurplePluginProtocolInfo sipe_prpl_info
=
620 #if PURPLE_VERSION_CHECK(3,0,0)
621 sizeof(PurplePluginProtocolInfo
), /* struct_size */
623 OPT_PROTO_CHAT_TOPIC
|
624 OPT_PROTO_PASSWORD_OPTIONAL
,
625 NULL
, /* user_splits */
626 NULL
, /* protocol_options */
627 NO_BUDDY_ICONS
, /* icon_spec */
628 sipe_list_icon
, /* list_icon */
629 NULL
, /* list_emblems */
630 sipe_purple_status_text
, /* status_text */
631 sipe_purple_tooltip_text
, /* tooltip_text */ // add custom info to contact tooltip
632 sipe_purple_status_types
, /* away_states */
633 sipe_purple_blist_node_menu
, /* blist_node_menu */
634 sipe_purple_chat_info
, /* chat_info */
635 sipe_purple_chat_info_defaults
, /* chat_info_defaults */
636 sipe_purple_login
, /* login */
637 sipe_purple_close
, /* close */
638 sipe_purple_send_im
, /* send_im */
639 NULL
, /* set_info */ // TODO maybe
640 sipe_purple_send_typing
, /* send_typing */
641 sipe_purple_get_info
, /* get_info */
642 sipe_purple_set_status
, /* set_status */
643 sipe_purple_set_idle
, /* set_idle */
644 NULL
, /* change_passwd */
645 sipe_purple_add_buddy
, /* add_buddy */
646 NULL
, /* add_buddies */
647 sipe_purple_remove_buddy
, /* remove_buddy */
648 NULL
, /* remove_buddies */
649 sipe_purple_add_permit
, /* add_permit */
650 sipe_purple_add_deny
, /* add_deny */
651 sipe_purple_add_deny
, /* rem_permit */
652 sipe_purple_add_permit
, /* rem_deny */
653 NULL
, /* set_permit_deny */
654 sipe_purple_chat_join
, /* join_chat */
655 NULL
, /* reject_chat */
656 NULL
, /* get_chat_name */
657 sipe_purple_chat_invite
, /* chat_invite */
658 sipe_purple_chat_leave
, /* chat_leave */
659 NULL
, /* chat_whisper */
660 sipe_purple_chat_send
, /* chat_send */
661 sipe_purple_keep_alive
, /* keepalive */
662 NULL
, /* register_user */
663 NULL
, /* get_cb_info */ // deprecated
664 #if !PURPLE_VERSION_CHECK(3,0,0)
665 NULL
, /* get_cb_away */ // deprecated
667 sipe_purple_alias_buddy
, /* alias_buddy */
668 sipe_purple_group_buddy
, /* group_buddy */
669 sipe_purple_group_rename
, /* rename_group */
670 NULL
, /* buddy_free */
671 sipe_purple_convo_closed
, /* convo_closed */
672 purple_normalize_nocase
, /* normalize */
673 NULL
, /* set_buddy_icon */
674 sipe_purple_group_remove
, /* remove_group */
675 NULL
, /* get_cb_real_name */ // TODO?
676 NULL
, /* set_chat_topic */
677 NULL
, /* find_blist_chat */
678 sipe_purple_roomlist_get_list
, /* roomlist_get_list */
679 sipe_purple_roomlist_cancel
, /* roomlist_cancel */
680 NULL
, /* roomlist_expand_category */
681 NULL
, /* can_receive_file */
682 sipe_purple_ft_send_file
, /* send_file */
683 sipe_purple_ft_new_xfer
, /* new_xfer */
684 NULL
, /* offline_message */
685 NULL
, /* whiteboard_prpl_ops */
687 NULL
, /* roomlist_room_serialize */
688 NULL
, /* unregister_user */
689 NULL
, /* send_attention */
690 NULL
, /* get_attention_types */
691 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
692 /* Backward compatibility when compiling against 2.4.x API */
693 (void (*)(void)) /* _purple_reserved4 */
695 #if !PURPLE_VERSION_CHECK(3,0,0)
696 sizeof(PurplePluginProtocolInfo
), /* struct_size */
698 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
699 sipe_purple_get_account_text_table
, /* get_account_text_table */
700 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
702 sipe_purple_initiate_media
, /* initiate_media */
703 sipe_purple_get_media_caps
, /* get_media_caps */
705 NULL
, /* initiate_media */
706 NULL
, /* get_media_caps */
708 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
709 NULL
, /* get_moods */
710 NULL
, /* set_public_alias */
711 NULL
, /* get_public_alias */
712 #if PURPLE_VERSION_CHECK(2,8,0)
713 NULL
, /* add_buddy_with_invite */
714 NULL
, /* add_buddies_with_invite */
721 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 6)
722 #pragma GCC diagnostic pop
725 /* Original GCC error checking restored from here on... (see above) */
727 /* PurplePluginInfo function calls & data structure */
728 static gboolean
sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
731 struct sigaction action
;
732 memset(&action
, 0, sizeof (action
));
733 action
.sa_handler
= sipe_purple_sigusr1_handler
;
734 sigaction(SIGUSR1
, &action
, NULL
);
739 static gboolean
sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
742 struct sigaction action
;
743 memset(&action
, 0, sizeof (action
));
744 action
.sa_handler
= SIG_DFL
;
745 sigaction(SIGUSR1
, &action
, NULL
);
750 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
754 sipe_purple_activity_shutdown();
757 entry
= sipe_prpl_info
.protocol_options
;
759 purple_account_option_destroy(entry
->data
);
760 entry
= g_list_delete_link(entry
, entry
);
762 sipe_prpl_info
.protocol_options
= NULL
;
764 entry
= sipe_prpl_info
.user_splits
;
766 purple_account_user_split_destroy(entry
->data
);
767 entry
= g_list_delete_link(entry
, entry
);
769 sipe_prpl_info
.user_splits
= NULL
;
772 static void sipe_purple_show_about_plugin(PurplePluginAction
*action
)
774 gchar
*tmp
= sipe_core_about();
775 purple_notify_formatted((PurpleConnection
*) action
->context
,
776 NULL
, " ", NULL
, tmp
, NULL
, NULL
);
780 static void sipe_purple_find_contact_cb(PurpleConnection
*gc
,
781 PurpleRequestFields
*fields
)
783 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
784 const gchar
*given_name
= NULL
;
785 const gchar
*surname
= NULL
;
786 const gchar
*email
= NULL
;
787 const gchar
*company
= NULL
;
788 const gchar
*country
= NULL
;
791 PurpleRequestField
*field
= entries
->data
;
792 const char *id
= purple_request_field_get_id(field
);
793 const char *value
= purple_request_field_string_get_value(field
);
795 SIPE_DEBUG_INFO("sipe_purple_find_contact_cb: %s = '%s'", id
, value
? value
: "");
798 if (strcmp(id
, "given") == 0) {
800 } else if (strcmp(id
, "surname") == 0) {
802 } else if (strcmp(id
, "email") == 0) {
804 } else if (strcmp(id
, "company") == 0) {
806 } else if (strcmp(id
, "country") == 0) {
811 entries
= g_list_next(entries
);
814 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
823 static void sipe_purple_show_find_contact(PurplePluginAction
*action
)
825 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
826 PurpleRequestFields
*fields
;
827 PurpleRequestFieldGroup
*group
;
828 PurpleRequestField
*field
;
830 fields
= purple_request_fields_new();
831 group
= purple_request_field_group_new(NULL
);
832 purple_request_fields_add_group(fields
, group
);
834 field
= purple_request_field_string_new("given", _("First name"), NULL
, FALSE
);
835 purple_request_field_group_add_field(group
, field
);
836 field
= purple_request_field_string_new("surname", _("Last name"), NULL
, FALSE
);
837 purple_request_field_group_add_field(group
, field
);
838 field
= purple_request_field_string_new("email", _("Email"), NULL
, FALSE
);
839 purple_request_field_group_add_field(group
, field
);
840 field
= purple_request_field_string_new("company", _("Company"), NULL
, FALSE
);
841 purple_request_field_group_add_field(group
, field
);
842 field
= purple_request_field_string_new("country", _("Country"), NULL
, FALSE
);
843 purple_request_field_group_add_field(group
, field
);
845 purple_request_fields(gc
,
847 _("Search for a contact"),
848 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
850 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb
),
852 purple_connection_get_account(gc
), NULL
, NULL
, gc
);
855 static void sipe_purple_join_conference_cb(PurpleConnection
*gc
,
856 PurpleRequestFields
*fields
)
858 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
861 PurpleRequestField
*field
= entries
->data
;
862 const char *id
= purple_request_field_get_id(field
);
863 const char *value
= purple_request_field_string_get_value(field
);
865 if (!sipe_strequal(id
, "meetingLocation"))
868 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, value
);
874 static void sipe_purple_phone_call_cb(PurpleConnection
*gc
,
875 PurpleRequestFields
*fields
)
877 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
880 PurpleRequestField
*field
= entries
->data
;
881 const char *id
= purple_request_field_get_id(field
);
882 const char *value
= purple_request_field_string_get_value(field
);
884 if (!sipe_strequal(id
, "phoneNumber"))
887 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, value
);
891 static void sipe_purple_phone_call(PurplePluginAction
*action
)
893 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
894 PurpleRequestFields
*fields
;
895 PurpleRequestFieldGroup
*group
;
896 PurpleRequestField
*field
;
898 fields
= purple_request_fields_new();
899 group
= purple_request_field_group_new(NULL
);
900 purple_request_fields_add_group(fields
, group
);
902 field
= purple_request_field_string_new("phoneNumber", _("Phone number"), NULL
, FALSE
);
903 purple_request_field_group_add_field(group
, field
);
905 purple_request_fields(gc
,
906 _("Call a phone number"),
907 _("Call a phone number"),
910 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb
),
912 purple_connection_get_account(gc
), NULL
, NULL
, gc
);
915 static void sipe_purple_test_call(PurplePluginAction
*action
)
917 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
918 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
922 static void sipe_purple_show_join_conference(PurplePluginAction
*action
)
924 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
925 PurpleRequestFields
*fields
;
926 PurpleRequestFieldGroup
*group
;
927 PurpleRequestField
*field
;
929 fields
= purple_request_fields_new();
930 group
= purple_request_field_group_new(NULL
);
931 purple_request_fields_add_group(fields
, group
);
933 field
= purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL
, FALSE
);
934 purple_request_field_group_add_field(group
, field
);
936 purple_request_fields(gc
,
937 _("Join conference"),
938 _("Join scheduled conference"),
939 _("Enter meeting location string you received in the invitation.\n"
941 "Valid location will be something like\n"
942 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
943 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
945 "https://meet.company.com/someone/abcdef1234"),
947 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb
),
949 purple_connection_get_account(gc
), NULL
, NULL
, gc
);
952 static void sipe_purple_republish_calendar(PurplePluginAction
*action
)
954 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
955 PurpleAccount
*account
= purple_connection_get_account(gc
);
957 if (get_dont_publish_flag(account
)) {
958 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
959 _("Publishing of calendar information has been disabled"),
962 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
966 static void sipe_purple_reset_status(PurplePluginAction
*action
)
968 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
969 PurpleAccount
*account
= purple_connection_get_account(gc
);
971 if (get_dont_publish_flag(account
)) {
972 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
973 _("Publishing of calendar information has been disabled"),
976 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
980 static GList
*sipe_purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
,
981 SIPE_UNUSED_PARAMETER gpointer context
)
984 PurplePluginAction
*act
;
986 act
= purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin
);
987 menu
= g_list_prepend(menu
, act
);
989 act
= purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact
);
990 menu
= g_list_prepend(menu
, act
);
993 act
= purple_plugin_action_new(_("Call a phone number..."), sipe_purple_phone_call
);
994 menu
= g_list_prepend(menu
, act
);
996 act
= purple_plugin_action_new(_("Test call"), sipe_purple_test_call
);
997 menu
= g_list_prepend(menu
, act
);
1000 act
= purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference
);
1001 menu
= g_list_prepend(menu
, act
);
1003 act
= purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar
);
1004 menu
= g_list_prepend(menu
, act
);
1006 act
= purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status
);
1007 menu
= g_list_prepend(menu
, act
);
1009 return g_list_reverse(menu
);
1012 static PurplePluginInfo sipe_purple_info
= {
1013 PURPLE_PLUGIN_MAGIC
,
1014 PURPLE_MAJOR_VERSION
,
1015 PURPLE_MINOR_VERSION
,
1016 PURPLE_PLUGIN_PROTOCOL
, /**< type */
1017 NULL
, /**< ui_requirement */
1019 NULL
, /**< dependencies */
1020 PURPLE_PRIORITY_DEFAULT
, /**< priority */
1021 "prpl-sipe", /**< id */
1022 "Office Communicator", /**< name */
1023 PACKAGE_VERSION
, /**< version */
1024 "Microsoft Office Communicator Protocol Plugin", /**< summary */
1025 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
1026 "Microsoft Live/Office Communications/Lync Server (LCS2005/OCS2007+)", /**< description */
1027 "Stefan Becker <chemobejk@gmail.com>, " /**< author */
1028 "Jakub Adam <jakub.adam@tieto.com>, " /**< author */
1029 "Anibal Avelar <avelar@gmail.com> (retired), " /**< author */
1030 "pier11 <pier11@operamail.com> (retired), " /**< author */
1031 "Gabriel Burt <gburt@novell.com> (retired)", /**< author */
1032 PACKAGE_URL
, /**< homepage */
1033 sipe_purple_plugin_load
, /**< load */
1034 sipe_purple_plugin_unload
, /**< unload */
1035 sipe_purple_plugin_destroy
, /**< destroy */
1036 NULL
, /**< ui_info */
1037 &sipe_prpl_info
, /**< extra_info */
1039 sipe_purple_actions
,
1046 static void sipe_purple_init_plugin(PurplePlugin
*plugin
)
1048 PurpleAccountUserSplit
*split
;
1049 PurpleAccountOption
*option
;
1051 /* This needs to be called first */
1052 sipe_core_init(LOCALEDIR
);
1053 sipe_purple_activity_init();
1055 purple_plugin_register(plugin
);
1058 * When adding new string settings please make sure to keep these
1061 * api/sipe-backend.h
1062 * purple-settings.c:setting_name[]
1064 split
= purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL
, ',');
1065 purple_account_user_split_set_reverse(split
, FALSE
);
1066 sipe_prpl_info
.user_splits
= g_list_append(sipe_prpl_info
.user_splits
, split
);
1068 option
= purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
1069 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1071 option
= purple_account_option_list_new(_("Connection type"), "transport", NULL
);
1072 purple_account_option_add_list_item(option
, _("Auto"), "auto");
1073 purple_account_option_add_list_item(option
, _("SSL/TLS"), "tls");
1074 purple_account_option_add_list_item(option
, _("TCP"), "tcp");
1075 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1077 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
1078 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
1080 option
= purple_account_option_string_new(_("User Agent"), "useragent", "");
1081 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1083 option
= purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL
);
1084 purple_account_option_add_list_item(option
, _("NTLM"), "ntlm");
1085 #if PURPLE_SIPE_SSO_AND_KERBEROS
1086 purple_account_option_add_list_item(option
, _("Kerberos"), "krb5");
1088 purple_account_option_add_list_item(option
, _("TLS-DSK"), "tls-dsk");
1089 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1091 #if PURPLE_SIPE_SSO_AND_KERBEROS
1093 * When the user selects Single Sign-On then SIPE will ignore the
1094 * settings for "login name" and "password". Instead it will use the
1095 * default credentials provided by the OS.
1097 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
1098 * SIPE that it is OK to use Single Sign-On or not.
1100 * Configurations that are known to support Single Sign-On:
1102 * - Windows, host joined to domain, SIPE with SSPI: NTLM
1103 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
1104 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
1106 option
= purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE
);
1107 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1110 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
1111 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
1113 option
= purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE
);
1114 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1116 option
= purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
1117 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1119 option
= purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
1120 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1122 /** Example (Exchange): DOMAIN\user or user@company.com
1123 * Example (Domino) : email_address
1125 option
= purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
1126 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1128 option
= purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
1129 #if PURPLE_VERSION_CHECK(3,0,0)
1130 purple_account_option_string_set_masked(
1132 purple_account_option_set_masked(
1135 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1137 /** Example (federated domain): company.com (i.e. ocschat@company.com)
1138 * Example (non-default user): user@company.com
1140 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", "");
1141 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1144 /* This macro makes the code a purple plugin */
1145 PURPLE_INIT_PLUGIN(sipe
, sipe_purple_init_plugin
, sipe_purple_info
);