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"
47 #include "connection.h"
59 #if PURPLE_VERSION_CHECK(3,0,0)
60 #include "buddylist.h"
61 #define PURPLE_TYPE_STRING G_TYPE_STRING
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_GSSAPI_GSSAPI_H) || 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
,
158 purple_buddy_get_name(buddy
),
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
,
169 purple_buddy_get_name(buddy
),
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_VERSION_CHECK(3,0,0)
254 if (PURPLE_IS_BUDDY(node
))
256 if (PURPLE_BLIST_NODE_IS_BUDDY(node
))
259 return sipe_purple_buddy_menu((PurpleBuddy
*) node
);
261 #if PURPLE_VERSION_CHECK(3,0,0)
262 if (PURPLE_IS_CHAT(node
))
264 if (PURPLE_BLIST_NODE_IS_CHAT(node
))
267 return sipe_purple_chat_menu((PurpleChat
*)node
);
273 static guint
get_authentication_type(PurpleAccount
*account
)
275 const gchar
*auth
= purple_account_get_string(account
, "authentication", "ntlm");
277 /* map option list to type - default is NTLM */
278 guint authentication_type
= SIPE_AUTHENTICATION_TYPE_NTLM
;
279 #if PURPLE_SIPE_SSO_AND_KERBEROS
280 if (sipe_strequal(auth
, "krb5")) {
281 authentication_type
= SIPE_AUTHENTICATION_TYPE_KERBEROS
;
284 if (sipe_strequal(auth
, "tls-dsk")) {
285 authentication_type
= SIPE_AUTHENTICATION_TYPE_TLS_DSK
;
288 return(authentication_type
);
291 static gboolean
get_sso_flag(PurpleAccount
*account
)
293 #if PURPLE_SIPE_SSO_AND_KERBEROS
295 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
296 * SIPE that it is OK to use Single Sign-On or not.
298 return(purple_account_get_bool(account
, "sso", FALSE
));
300 (void) account
; /* keep compiler happy */
305 static gboolean
get_dont_publish_flag(PurpleAccount
*account
)
307 /* default is to publish calendar information */
308 return(purple_account_get_bool(account
, "dont-publish", FALSE
));
311 static void connect_to_core(PurpleConnection
*gc
,
312 PurpleAccount
*account
,
313 const gchar
*password
)
315 const gchar
*username
= purple_account_get_username(account
);
316 const gchar
*email
= purple_account_get_string(account
, "email", NULL
);
317 const gchar
*email_url
= purple_account_get_string(account
, "email_url", NULL
);
318 const gchar
*transport
= purple_account_get_string(account
, "transport", "auto");
319 struct sipe_core_public
*sipe_public
;
320 gchar
**username_split
;
321 gchar
*login_domain
= NULL
;
322 gchar
*login_account
= NULL
;
324 guint transport_type
;
325 struct sipe_backend_private
*purple_private
;
326 gboolean sso
= get_sso_flag(account
);
328 /* username format: <username>,[<optional login>] */
329 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username
);
330 username_split
= g_strsplit(username
, ",", 2);
332 /* login name is ignored when SSO has been selected */
334 /* login name specified? */
335 if (username_split
[1] && strlen(username_split
[1])) {
336 /* Allowed domain-account separators are / or \ */
337 gchar
**domain_user
= g_strsplit_set(username_split
[1], "/\\", 2);
338 gboolean has_domain
= domain_user
[1] != NULL
;
339 SIPE_DEBUG_INFO("sipe_purple_login: login '%s'", username_split
[1]);
340 login_domain
= has_domain
? g_strdup(domain_user
[0]) : NULL
;
341 login_account
= g_strdup(domain_user
[has_domain
? 1 : 0]);
342 SIPE_DEBUG_INFO("sipe_purple_login: auth domain '%s' user '%s'",
343 login_domain
? login_domain
: "",
345 g_strfreev(domain_user
);
347 /* No -> duplicate username */
348 login_account
= g_strdup(username_split
[0]);
352 sipe_public
= sipe_core_allocate(username_split
[0],
354 login_domain
, login_account
,
359 g_free(login_domain
);
360 g_free(login_account
);
361 g_strfreev(username_split
);
364 #if PURPLE_VERSION_CHECK(3,0,0)
365 purple_connection_error(
367 purple_connection_error_reason(
370 PURPLE_CONNECTION_ERROR_INVALID_USERNAME
,
375 sipe_public
->backend_private
= purple_private
= g_new0(struct sipe_backend_private
, 1);
376 purple_private
->public = sipe_public
;
377 purple_private
->gc
= gc
;
378 purple_private
->account
= account
;
380 sipe_purple_chat_setup_rejoin(purple_private
);
382 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH
);
383 if (get_dont_publish_flag(account
))
384 SIPE_CORE_FLAG_SET(DONT_PUBLISH
);
386 #if PURPLE_VERSION_CHECK(3,0,0)
387 purple_connection_set_protocol_data(gc
, sipe_public
);
388 purple_connection_set_flags(gc
,
389 purple_connection_get_flags(gc
) |
390 PURPLE_CONNECTION_FLAG_HTML
|
391 PURPLE_CONNECTION_FLAG_FORMATTING_WBFO
|
392 PURPLE_CONNECTION_FLAG_NO_BGCOLOR
|
393 PURPLE_CONNECTION_FLAG_NO_FONTSIZE
|
394 PURPLE_CONNECTION_FLAG_NO_URLDESC
|
395 PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY
);
398 gc
->proto_data
= sipe_public
;
399 gc
->flags
|= PURPLE_CONNECTION_HTML
| PURPLE_CONNECTION_FORMATTING_WBFO
| PURPLE_CONNECTION_NO_BGCOLOR
|
400 PURPLE_CONNECTION_NO_FONTSIZE
| PURPLE_CONNECTION_NO_URLDESC
| PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
;
402 purple_connection_set_display_name(gc
, sipe_public
->sip_name
);
403 purple_connection_update_progress(gc
, _("Connecting"), 1, 2);
405 username_split
= g_strsplit(purple_account_get_string(account
, "server", ""), ":", 2);
406 if (sipe_strequal(transport
, "auto")) {
407 transport_type
= (username_split
[0] == NULL
) ?
408 SIPE_TRANSPORT_AUTO
: SIPE_TRANSPORT_TLS
;
409 } else if (sipe_strequal(transport
, "tls")) {
410 transport_type
= SIPE_TRANSPORT_TLS
;
412 transport_type
= SIPE_TRANSPORT_TCP
;
414 sipe_core_transport_sip_connect(sipe_public
,
416 get_authentication_type(account
),
418 username_split
[0] ? username_split
[1] : NULL
);
419 g_strfreev(username_split
);
422 static void password_required_cb(PurpleConnection
*gc
,
423 SIPE_UNUSED_PARAMETER PurpleRequestFields
*fields
)
425 if (!PURPLE_CONNECTION_IS_VALID(gc
))
428 #if PURPLE_VERSION_CHECK(3,0,0)
429 purple_connection_error(
431 purple_connection_error_reason(
434 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
,
435 _("Password required"));
438 static void password_ok_cb(PurpleConnection
*gc
,
439 PurpleRequestFields
*fields
)
441 const gchar
*password
;
443 if (!PURPLE_CONNECTION_IS_VALID(gc
))
446 password
= purple_request_fields_get_string(fields
, "password");
448 if (password
&& strlen(password
)) {
449 PurpleAccount
*account
= purple_connection_get_account(gc
);
451 if (purple_request_fields_get_bool(fields
, "remember"))
452 purple_account_set_remember_password(account
, TRUE
);
453 purple_account_set_password(account
, password
454 #if PURPLE_VERSION_CHECK(3,0,0)
459 /* Now we have a password and we can connect */
460 connect_to_core(gc
, account
, password
);
463 /* reject an empty password */
464 password_required_cb(gc
, fields
);
467 static void sipe_purple_login(PurpleAccount
*account
)
469 PurpleConnection
*gc
= purple_account_get_connection(account
);
470 const gchar
*password
= purple_connection_get_password(gc
);
472 /* Password required? */
473 if (sipe_core_transport_sip_requires_password(get_authentication_type(account
),
474 get_sso_flag(account
)) &&
475 (!password
|| !strlen(password
)))
476 /* No password set - request one from user */
477 purple_account_request_password(account
,
478 G_CALLBACK(password_ok_cb
),
479 G_CALLBACK(password_required_cb
),
482 /* No password required or saved password - connect now */
483 connect_to_core(gc
, account
, password
);
487 static void sipe_purple_close(PurpleConnection
*gc
)
489 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
492 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
494 sipe_core_deallocate(sipe_public
);
496 /* anything left after that must be in pending state... */
497 sipe_purple_dns_query_cancel_all(purple_private
);
498 sipe_purple_transport_close_all(purple_private
);
500 if (purple_private
->roomlist_map
)
501 g_hash_table_destroy(purple_private
->roomlist_map
);
502 sipe_purple_chat_destroy_rejoin(purple_private
);
503 g_free(purple_private
);
504 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
505 purple_connection_set_protocol_data(gc
, NULL
);
507 gc
->proto_data
= NULL
;
512 static int sipe_purple_send_im(PurpleConnection
*gc
,
515 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags
)
517 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
, what
);
521 static unsigned int sipe_purple_send_typing(PurpleConnection
*gc
,
523 #if PURPLE_VERSION_CHECK(3,0,0)
524 PurpleIMTypingState state
526 PurpleTypingState state
530 gboolean typing
= (state
==
531 #if PURPLE_VERSION_CHECK(3,0,0)
538 /* only enable this debug output while testing
539 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
542 * libpurple calls this function with PURPLE_NOT_TYPING *after*
543 * calling sipe_purple_send_im() with the message. This causes
544 * SIPE core to send out two SIP messages to the same dialog in
545 * short succession without waiting for the response to the first
546 * one. Some servers then reject the first one with
548 * SIP/2.0 500 Stale CSeq Value
550 * which triggers a "message not delivered" error for the user.
552 * Work around this by filtering out PURPLE_NOT_TYPING events.
555 #if PURPLE_VERSION_CHECK(3,0,0)
561 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
565 /* tell libpurple to send typing indications every 4 seconds */
566 return(typing
? 4 : 0);
569 static void sipe_purple_get_info(PurpleConnection
*gc
, const char *who
)
571 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
575 static void sipe_purple_add_permit(PurpleConnection
*gc
, const char *name
)
577 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, TRUE
);
580 static void sipe_purple_add_deny(PurpleConnection
*gc
, const char *name
)
582 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, FALSE
);
585 static void sipe_purple_alias_buddy(PurpleConnection
*gc
, const char *name
,
588 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, alias
);
591 static void sipe_purple_group_rename(PurpleConnection
*gc
,
592 const char *old_name
,
594 SIPE_UNUSED_PARAMETER GList
*moved_buddies
)
596 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
598 purple_group_get_name(group
));
601 static void sipe_purple_convo_closed(PurpleConnection
*gc
,
604 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
);
607 static void sipe_purple_group_remove(PurpleConnection
*gc
, PurpleGroup
*group
)
609 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
610 purple_group_get_name(group
));
613 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
615 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount
*account
)
618 table
= g_hash_table_new(g_str_hash
, g_str_equal
);
619 g_hash_table_insert(table
, "login_label", (gpointer
)_("user@company.com"));
623 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
627 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER
int signum
)
629 capture_pipeline("PURPLE_SIPE_PIPELINE");
632 static gboolean
sipe_purple_initiate_media(PurpleAccount
*account
, const char *who
,
633 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type
)
635 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC
,
637 (type
& PURPLE_MEDIA_VIDEO
));
641 static PurpleMediaCaps
sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount
*account
,
642 SIPE_UNUSED_PARAMETER
const char *who
)
644 return PURPLE_MEDIA_CAPS_AUDIO
645 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
646 | PURPLE_MEDIA_CAPS_MODIFY_SESSION
;
653 * Simplistic source upward compatibility path for newer libpurple APIs
655 * Usually we compile with -Werror=missing-field-initializers if GCC supports
656 * it. But that means that the compilation of this structure can fail if the
657 * newer API has added additional plugin callbacks. For the benefit of the
658 * user we downgrade it to a warning here.
660 * Diagnostic #pragma was added in GCC 4.2.0
661 * Diagnostic push/pop was added in GCC 4.6.0
664 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 2)
665 #if __GNUC_MINOR__ >= 6
666 #pragma GCC diagnostic push
668 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
671 static PurplePluginProtocolInfo sipe_prpl_info
=
673 #if PURPLE_VERSION_CHECK(3,0,0)
674 sizeof(PurplePluginProtocolInfo
), /* struct_size */
676 OPT_PROTO_CHAT_TOPIC
|
677 OPT_PROTO_PASSWORD_OPTIONAL
,
678 NULL
, /* user_splits */
679 NULL
, /* protocol_options */
680 NO_BUDDY_ICONS
, /* icon_spec */
681 sipe_list_icon
, /* list_icon */
682 NULL
, /* list_emblems */
683 sipe_purple_status_text
, /* status_text */
684 sipe_purple_tooltip_text
, /* tooltip_text */ // add custom info to contact tooltip
685 sipe_purple_status_types
, /* away_states */
686 sipe_purple_blist_node_menu
, /* blist_node_menu */
687 sipe_purple_chat_info
, /* chat_info */
688 sipe_purple_chat_info_defaults
, /* chat_info_defaults */
689 sipe_purple_login
, /* login */
690 sipe_purple_close
, /* close */
691 sipe_purple_send_im
, /* send_im */
692 NULL
, /* set_info */ // TODO maybe
693 sipe_purple_send_typing
, /* send_typing */
694 sipe_purple_get_info
, /* get_info */
695 sipe_purple_set_status
, /* set_status */
696 sipe_purple_set_idle
, /* set_idle */
697 NULL
, /* change_passwd */
698 sipe_purple_add_buddy
, /* add_buddy */
699 NULL
, /* add_buddies */
700 sipe_purple_remove_buddy
, /* remove_buddy */
701 NULL
, /* remove_buddies */
702 sipe_purple_add_permit
, /* add_permit */
703 sipe_purple_add_deny
, /* add_deny */
704 sipe_purple_add_deny
, /* rem_permit */
705 sipe_purple_add_permit
, /* rem_deny */
706 NULL
, /* set_permit_deny */
707 sipe_purple_chat_join
, /* join_chat */
708 NULL
, /* reject_chat */
709 NULL
, /* get_chat_name */
710 sipe_purple_chat_invite
, /* chat_invite */
711 sipe_purple_chat_leave
, /* chat_leave */
712 NULL
, /* chat_whisper */
713 sipe_purple_chat_send
, /* chat_send */
714 NULL
, /* keepalive */
715 NULL
, /* register_user */
716 NULL
, /* get_cb_info */ // deprecated
717 #if !PURPLE_VERSION_CHECK(3,0,0)
718 NULL
, /* get_cb_away */ // deprecated
720 sipe_purple_alias_buddy
, /* alias_buddy */
721 sipe_purple_group_buddy
, /* group_buddy */
722 sipe_purple_group_rename
, /* rename_group */
723 NULL
, /* buddy_free */
724 sipe_purple_convo_closed
, /* convo_closed */
725 purple_normalize_nocase
, /* normalize */
726 NULL
, /* set_buddy_icon */
727 sipe_purple_group_remove
, /* remove_group */
728 NULL
, /* get_cb_real_name */ // TODO?
729 NULL
, /* set_chat_topic */
730 NULL
, /* find_blist_chat */
731 sipe_purple_roomlist_get_list
, /* roomlist_get_list */
732 sipe_purple_roomlist_cancel
, /* roomlist_cancel */
733 NULL
, /* roomlist_expand_category */
734 NULL
, /* can_receive_file */
735 sipe_purple_ft_send_file
, /* send_file */
736 sipe_purple_ft_new_xfer
, /* new_xfer */
737 NULL
, /* offline_message */
738 NULL
, /* whiteboard_prpl_ops */
740 NULL
, /* roomlist_room_serialize */
741 NULL
, /* unregister_user */
742 NULL
, /* send_attention */
743 NULL
, /* get_attention_types */
744 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
745 /* Backward compatibility when compiling against 2.4.x API */
746 (void (*)(void)) /* _purple_reserved4 */
748 #if !PURPLE_VERSION_CHECK(3,0,0)
749 sizeof(PurplePluginProtocolInfo
), /* struct_size */
751 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
752 sipe_purple_get_account_text_table
, /* get_account_text_table */
753 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
755 sipe_purple_initiate_media
, /* initiate_media */
756 sipe_purple_get_media_caps
, /* get_media_caps */
758 NULL
, /* initiate_media */
759 NULL
, /* get_media_caps */
761 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
762 NULL
, /* get_moods */
763 NULL
, /* set_public_alias */
764 NULL
, /* get_public_alias */
765 #if PURPLE_VERSION_CHECK(2,8,0)
766 NULL
, /* add_buddy_with_invite */
767 NULL
, /* add_buddies_with_invite */
768 #elif PURPLE_VERSION_CHECK(3,0,0)
769 NULL
, /* get_max_message_size */
776 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 6)
777 #pragma GCC diagnostic pop
780 /* Original GCC error checking restored from here on... (see above) */
782 /* PurplePluginInfo function calls & data structure */
783 static gboolean
sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
786 struct sigaction action
;
787 memset(&action
, 0, sizeof (action
));
788 action
.sa_handler
= sipe_purple_sigusr1_handler
;
789 sigaction(SIGUSR1
, &action
, NULL
);
794 static gboolean
sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
797 struct sigaction action
;
798 memset(&action
, 0, sizeof (action
));
799 action
.sa_handler
= SIG_DFL
;
800 sigaction(SIGUSR1
, &action
, NULL
);
805 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
809 sipe_purple_activity_shutdown();
812 entry
= sipe_prpl_info
.protocol_options
;
814 purple_account_option_destroy(entry
->data
);
815 entry
= g_list_delete_link(entry
, entry
);
817 sipe_prpl_info
.protocol_options
= NULL
;
819 entry
= sipe_prpl_info
.user_splits
;
821 purple_account_user_split_destroy(entry
->data
);
822 entry
= g_list_delete_link(entry
, entry
);
824 sipe_prpl_info
.user_splits
= NULL
;
827 static void sipe_purple_show_about_plugin(PurplePluginAction
*action
)
829 gchar
*tmp
= sipe_core_about();
830 purple_notify_formatted((PurpleConnection
*) action
->context
,
831 NULL
, " ", NULL
, tmp
, NULL
, NULL
);
835 static void sipe_purple_find_contact_cb(PurpleConnection
*gc
,
836 PurpleRequestFields
*fields
)
838 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
839 const gchar
*given_name
= NULL
;
840 const gchar
*surname
= NULL
;
841 const gchar
*email
= NULL
;
842 const gchar
*company
= NULL
;
843 const gchar
*country
= NULL
;
846 PurpleRequestField
*field
= entries
->data
;
847 const char *id
= purple_request_field_get_id(field
);
848 const char *value
= purple_request_field_string_get_value(field
);
850 SIPE_DEBUG_INFO("sipe_purple_find_contact_cb: %s = '%s'", id
, value
? value
: "");
853 if (strcmp(id
, "given") == 0) {
855 } else if (strcmp(id
, "surname") == 0) {
857 } else if (strcmp(id
, "email") == 0) {
859 } else if (strcmp(id
, "company") == 0) {
861 } else if (strcmp(id
, "country") == 0) {
866 entries
= g_list_next(entries
);
869 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
878 static void sipe_purple_show_find_contact(PurplePluginAction
*action
)
880 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
881 PurpleRequestFields
*fields
;
882 PurpleRequestFieldGroup
*group
;
883 PurpleRequestField
*field
;
884 #if PURPLE_VERSION_CHECK(3,0,0)
885 PurpleRequestCommonParameters
*cpar
= purple_request_cpar_from_connection(gc
);
888 fields
= purple_request_fields_new();
889 group
= purple_request_field_group_new(NULL
);
890 purple_request_fields_add_group(fields
, group
);
892 field
= purple_request_field_string_new("given", _("First name"), NULL
, FALSE
);
893 purple_request_field_group_add_field(group
, field
);
894 field
= purple_request_field_string_new("surname", _("Last name"), NULL
, FALSE
);
895 purple_request_field_group_add_field(group
, field
);
896 field
= purple_request_field_string_new("email", _("Email"), NULL
, FALSE
);
897 purple_request_field_group_add_field(group
, field
);
898 field
= purple_request_field_string_new("company", _("Company"), NULL
, FALSE
);
899 purple_request_field_group_add_field(group
, field
);
900 field
= purple_request_field_string_new("country", _("Country"), NULL
, FALSE
);
901 purple_request_field_group_add_field(group
, field
);
903 purple_request_fields(gc
,
905 _("Search for a contact"),
906 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
908 _("_Search"), G_CALLBACK(sipe_purple_find_contact_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_join_conference_cb(PurpleConnection
*gc
,
919 PurpleRequestFields
*fields
)
921 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
924 PurpleRequestField
*field
= entries
->data
;
925 const char *id
= purple_request_field_get_id(field
);
926 const char *value
= purple_request_field_string_get_value(field
);
928 if (!sipe_strequal(id
, "meetingLocation"))
931 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, value
);
937 static void sipe_purple_phone_call_cb(PurpleConnection
*gc
,
938 PurpleRequestFields
*fields
)
940 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
943 PurpleRequestField
*field
= entries
->data
;
944 const char *id
= purple_request_field_get_id(field
);
945 const char *value
= purple_request_field_string_get_value(field
);
947 if (!sipe_strequal(id
, "phoneNumber"))
950 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, value
);
954 static void sipe_purple_phone_call(PurplePluginAction
*action
)
956 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
957 PurpleRequestFields
*fields
;
958 PurpleRequestFieldGroup
*group
;
959 PurpleRequestField
*field
;
960 #if PURPLE_VERSION_CHECK(3,0,0)
961 PurpleRequestCommonParameters
*cpar
= purple_request_cpar_from_connection(gc
);
964 fields
= purple_request_fields_new();
965 group
= purple_request_field_group_new(NULL
);
966 purple_request_fields_add_group(fields
, group
);
968 field
= purple_request_field_string_new("phoneNumber", _("Phone number"), NULL
, FALSE
);
969 purple_request_field_group_add_field(group
, field
);
971 purple_request_fields(gc
,
972 _("Call a phone number"),
973 _("Call a phone number"),
976 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb
),
978 #if PURPLE_VERSION_CHECK(3,0,0)
980 purple_request_cpar_unref(cpar
);
982 purple_connection_get_account(gc
), NULL
, NULL
, gc
);
986 static void sipe_purple_test_call(PurplePluginAction
*action
)
988 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
989 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
993 static void sipe_purple_show_join_conference(PurplePluginAction
*action
)
995 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
996 PurpleRequestFields
*fields
;
997 PurpleRequestFieldGroup
*group
;
998 PurpleRequestField
*field
;
999 #if PURPLE_VERSION_CHECK(3,0,0)
1000 PurpleRequestCommonParameters
*cpar
= purple_request_cpar_from_connection(gc
);
1003 fields
= purple_request_fields_new();
1004 group
= purple_request_field_group_new(NULL
);
1005 purple_request_fields_add_group(fields
, group
);
1007 field
= purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL
, FALSE
);
1008 purple_request_field_group_add_field(group
, field
);
1010 purple_request_fields(gc
,
1011 _("Join conference"),
1012 _("Join scheduled conference"),
1013 _("Enter meeting location string you received in the invitation.\n"
1015 "Valid location will be something like\n"
1016 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
1017 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
1019 "https://meet.company.com/someone/abcdef1234"),
1021 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb
),
1023 #if PURPLE_VERSION_CHECK(3,0,0)
1025 purple_request_cpar_unref(cpar
);
1027 purple_connection_get_account(gc
), NULL
, NULL
, gc
);
1031 static void sipe_purple_republish_calendar(PurplePluginAction
*action
)
1033 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
1034 PurpleAccount
*account
= purple_connection_get_account(gc
);
1036 if (get_dont_publish_flag(account
)) {
1037 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
1038 _("Publishing of calendar information has been disabled"),
1041 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
1045 static void sipe_purple_reset_status(PurplePluginAction
*action
)
1047 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
1048 PurpleAccount
*account
= purple_connection_get_account(gc
);
1050 if (get_dont_publish_flag(account
)) {
1051 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
1052 _("Publishing of calendar information has been disabled"),
1055 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
1059 static GList
*sipe_purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
,
1060 SIPE_UNUSED_PARAMETER gpointer context
)
1063 PurplePluginAction
*act
;
1065 act
= purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin
);
1066 menu
= g_list_prepend(menu
, act
);
1068 act
= purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact
);
1069 menu
= g_list_prepend(menu
, act
);
1072 act
= purple_plugin_action_new(_("Call a phone number..."), sipe_purple_phone_call
);
1073 menu
= g_list_prepend(menu
, act
);
1075 act
= purple_plugin_action_new(_("Test call"), sipe_purple_test_call
);
1076 menu
= g_list_prepend(menu
, act
);
1079 act
= purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference
);
1080 menu
= g_list_prepend(menu
, act
);
1082 act
= purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar
);
1083 menu
= g_list_prepend(menu
, act
);
1085 act
= purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status
);
1086 menu
= g_list_prepend(menu
, act
);
1088 return g_list_reverse(menu
);
1091 static PurplePluginInfo sipe_purple_info
= {
1092 PURPLE_PLUGIN_MAGIC
,
1093 PURPLE_MAJOR_VERSION
,
1094 PURPLE_MINOR_VERSION
,
1095 PURPLE_PLUGIN_PROTOCOL
, /**< type */
1096 NULL
, /**< ui_requirement */
1098 NULL
, /**< dependencies */
1099 PURPLE_PRIORITY_DEFAULT
, /**< priority */
1100 "prpl-sipe", /**< id */
1101 "Office Communicator", /**< name */
1102 PACKAGE_VERSION
, /**< version */
1103 "Microsoft Office Communicator Protocol Plugin", /**< summary */
1104 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
1105 "Microsoft Live/Office Communications/Lync Server (LCS2005/OCS2007+)", /**< description */
1106 "Stefan Becker <chemobejk@gmail.com>, " /**< author */
1107 "Jakub Adam <jakub.adam@tieto.com>, " /**< author */
1108 "Anibal Avelar <avelar@gmail.com> (retired), " /**< author */
1109 "pier11 <pier11@operamail.com> (retired), " /**< author */
1110 "Gabriel Burt <gburt@novell.com> (retired)", /**< author */
1111 PACKAGE_URL
, /**< homepage */
1112 sipe_purple_plugin_load
, /**< load */
1113 sipe_purple_plugin_unload
, /**< unload */
1114 sipe_purple_plugin_destroy
, /**< destroy */
1115 NULL
, /**< ui_info */
1116 &sipe_prpl_info
, /**< extra_info */
1118 sipe_purple_actions
,
1125 static void sipe_purple_init_plugin(PurplePlugin
*plugin
)
1127 PurpleAccountUserSplit
*split
;
1128 PurpleAccountOption
*option
;
1130 /* This needs to be called first */
1131 sipe_core_init(LOCALEDIR
);
1132 sipe_purple_activity_init();
1134 purple_plugin_register(plugin
);
1137 * When adding new string settings please make sure to keep these
1140 * api/sipe-backend.h
1141 * purple-settings.c:setting_name[]
1143 split
= purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL
, ',');
1144 purple_account_user_split_set_reverse(split
, FALSE
);
1145 sipe_prpl_info
.user_splits
= g_list_append(sipe_prpl_info
.user_splits
, split
);
1147 option
= purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
1148 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1150 option
= purple_account_option_list_new(_("Connection type"), "transport", NULL
);
1151 purple_account_option_add_list_item(option
, _("Auto"), "auto");
1152 purple_account_option_add_list_item(option
, _("SSL/TLS"), "tls");
1153 purple_account_option_add_list_item(option
, _("TCP"), "tcp");
1154 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1156 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
1157 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
1159 option
= purple_account_option_string_new(_("User Agent"), "useragent", "");
1160 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1162 option
= purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL
);
1163 purple_account_option_add_list_item(option
, _("NTLM"), "ntlm");
1164 #if PURPLE_SIPE_SSO_AND_KERBEROS
1165 purple_account_option_add_list_item(option
, _("Kerberos"), "krb5");
1167 purple_account_option_add_list_item(option
, _("TLS-DSK"), "tls-dsk");
1168 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1170 #if PURPLE_SIPE_SSO_AND_KERBEROS
1172 * When the user selects Single Sign-On then SIPE will ignore the
1173 * settings for "login name" and "password". Instead it will use the
1174 * default credentials provided by the OS.
1176 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
1177 * SIPE that it is OK to use Single Sign-On or not.
1179 * Configurations that are known to support Single Sign-On:
1181 * - Windows, host joined to domain, SIPE with SSPI: NTLM
1182 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
1183 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
1185 option
= purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE
);
1186 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1189 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
1190 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
1192 option
= purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE
);
1193 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1195 option
= purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
1196 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1198 option
= purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
1199 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1201 /** Example (Exchange): DOMAIN\user or user@company.com
1202 * Example (Domino) : email_address
1204 option
= purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
1205 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1207 option
= purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
1208 #if PURPLE_VERSION_CHECK(3,0,0)
1209 purple_account_option_string_set_masked(
1211 purple_account_option_set_masked(
1214 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1216 /** Example (federated domain): company.com (i.e. ocschat@company.com)
1217 * Example (non-default user): user@company.com
1219 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", "");
1220 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1223 /* This macro makes the code a purple plugin */
1224 PURPLE_INIT_PLUGIN(sipe
, sipe_purple_init_plugin
, sipe_purple_info
);