2 * @file purple-plugin.c
6 * Copyright (C) 2010-2015 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
64 #define PurpleIMTypingState PurpleTypingState
65 #define PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
66 #define PURPLE_CONNECTION_FLAG_FORMATTING_WBFO PURPLE_CONNECTION_FORMATTING_WBFO
67 #define PURPLE_CONNECTION_FLAG_HTML PURPLE_CONNECTION_HTML
68 #define PURPLE_CONNECTION_FLAG_NO_BGCOLOR PURPLE_CONNECTION_NO_BGCOLOR
69 #define PURPLE_CONNECTION_FLAG_NO_FONTSIZE PURPLE_CONNECTION_NO_FONTSIZE
70 #define PURPLE_CONNECTION_FLAG_NO_URLDESC PURPLE_CONNECTION_NO_URLDESC
71 #define PURPLE_IS_BUDDY(n) PURPLE_BLIST_NODE_IS_BUDDY(n)
72 #define PURPLE_IS_CHAT(n) PURPLE_BLIST_NODE_IS_CHAT(n)
73 #define PURPLE_IM_TYPING PURPLE_TYPING
74 #define PURPLE_IM_NOT_TYPING PURPLE_NOT_TYPING
75 #define purple_account_option_string_set_masked(o, f) purple_account_option_set_masked(o, f)
76 #define purple_connection_error(g, e, m) purple_connection_error_reason(g, e, m)
77 #define purple_connection_get_flags(gc) 0
78 #define purple_connection_set_protocol_data(gc, p) gc->proto_data = p
79 #define purple_connection_set_flags(gc, f) gc->flags |= f
82 #include "sipe-backend.h"
83 #include "sipe-core.h"
86 #define _PurpleMessageFlags PurpleMessageFlags
87 #include "purple-private.h"
89 /* Backward compatibility when compiling against 2.4.x API */
90 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
91 #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100
95 * NOTE: this flag means two things:
97 * - is Single Sign-On supported, and
98 * - is Kerberos supported
100 #if defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_SSPI)
101 #define PURPLE_SIPE_SSO_AND_KERBEROS 1
103 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
107 * SIPE core activity <-> Purple status mapping
109 * NOTE: this needs to be kept in sync with sipe_purple_status_types()
111 static const gchar
* const activity_to_purple_map
[SIPE_ACTIVITY_NUM_TYPES
] = {
112 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
113 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
114 /* SIPE_ACTIVITY_ONLINE */ "online",
115 /* SIPE_ACTIVITY_INACTIVE */ "idle",
116 /* SIPE_ACTIVITY_BUSY */ "busy",
117 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
118 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
119 /* SIPE_ACTIVITY_BRB */ "be-right-back",
120 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
121 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
122 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
123 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
124 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
125 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
126 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
127 /* SIPE_ACTIVITY_OOF */ "out-of-office",
128 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
129 /* SIPE_ACTIVIY_NUM_TYPES == 17 -> compare to sipe_purple_status_types() */
132 GHashTable
*purple_token_map
;
134 static void sipe_purple_activity_init(void)
138 purple_token_map
= g_hash_table_new(g_str_hash
, g_str_equal
);
139 for (index
= SIPE_ACTIVITY_UNSET
;
140 index
< SIPE_ACTIVITY_NUM_TYPES
;
142 g_hash_table_insert(purple_token_map
,
143 (gchar
*) activity_to_purple_map
[index
],
144 GUINT_TO_POINTER(index
));
148 static void sipe_purple_activity_shutdown(void)
150 g_hash_table_destroy(purple_token_map
);
153 const gchar
*sipe_purple_activity_to_token(guint type
)
155 return(activity_to_purple_map
[type
]);
158 guint
sipe_purple_token_to_activity(const gchar
*token
)
160 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map
, token
)));
163 gchar
*sipe_backend_version(void)
165 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
168 /* PurplePluginProtocolInfo function calls & data structure */
169 static const char *sipe_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount
*a
,
170 SIPE_UNUSED_PARAMETER PurpleBuddy
*b
)
175 static gchar
*sipe_purple_status_text(PurpleBuddy
*buddy
)
177 const PurpleStatus
*status
= purple_presence_get_active_status(purple_buddy_get_presence(buddy
));
178 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
179 purple_buddy_get_name(buddy
),
180 sipe_purple_token_to_activity(purple_status_get_id(status
)),
181 purple_status_get_name(status
));
184 static void sipe_purple_tooltip_text(PurpleBuddy
*buddy
,
185 PurpleNotifyUserInfo
*user_info
,
186 SIPE_UNUSED_PARAMETER gboolean full
)
188 const PurplePresence
*presence
= purple_buddy_get_presence(buddy
);
189 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
190 purple_buddy_get_name(buddy
),
191 purple_status_get_name(purple_presence_get_active_status(presence
)),
192 purple_presence_is_online(presence
),
193 (struct sipe_backend_buddy_tooltip
*) user_info
);
196 static GList
*sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount
*acc
)
198 PurpleStatusType
*type
;
201 /* Macro to reduce code repetition
203 #define SIPE_ADD_STATUS(prim,activity,user) type = purple_status_type_new_with_attrs( \
205 sipe_purple_activity_to_token(activity), \
206 sipe_core_activity_description(activity), \
208 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
210 types = g_list_append(types, type);
213 * NOTE: needs to be kept in sync with activity_to_purple_map[],
214 * i.e. for each SIPE_ACTIVITY_xxx value there must be an
215 * entry on this list.
217 * NOTE: the following code is sorted by purple primitive type not
218 * by SIPE_ACTIVITY_xxx value.
221 /* 1: Unset - special case: no entry needed */
224 * Status list entries for primitive type AVAILABLE
227 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE
,
228 SIPE_ACTIVITY_AVAILABLE
,
232 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE
,
233 SIPE_ACTIVITY_ONLINE
,
236 /* 4: Inactive (Idle) */
237 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE
,
238 SIPE_ACTIVITY_INACTIVE
,
242 * Status list entries for primitive type UNAVAILABLE
245 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
250 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
251 SIPE_ACTIVITY_BUSYIDLE
,
254 /* 7: Do Not Disturb */
255 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
260 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
261 SIPE_ACTIVITY_ON_PHONE
,
264 /* 9: In a conference call */
265 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
266 SIPE_ACTIVITY_IN_CONF
,
269 /* 10: In a meeting */
270 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
271 SIPE_ACTIVITY_IN_MEETING
,
274 /* 11: Urgent interruptions only */
275 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
276 SIPE_ACTIVITY_URGENT_ONLY
,
280 * Status list entries for primitive type AWAY
282 * 12: Away - special case: needs to go first in the list as purple
283 * picks the first status with primitive type AWAY for idle
285 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
289 /* 13: Be Right Back */
290 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
294 /* 14: Out to lunch */
295 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
300 * Status list entries for primitive type EXTENDED_AWAY
302 * 15: Out of office */
303 SIPE_ADD_STATUS(PURPLE_STATUS_EXTENDED_AWAY
,
308 * Status list entries for primitive type INVISIBLE
310 * 16: Appear Offline */
311 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE
,
312 SIPE_ACTIVITY_INVISIBLE
,
316 * Status list entries for primitive type OFFLINE
318 * NOTE: this is always the last entry. Compare the number
319 * with the comment in activity_to_purple_map[].
321 * 17: Offline - special case: no message text */
322 type
= purple_status_type_new(PURPLE_STATUS_OFFLINE
,
326 types
= g_list_append(types
, type
);
331 static GList
*sipe_purple_blist_node_menu(PurpleBlistNode
*node
)
333 if (PURPLE_IS_BUDDY(node
))
335 return sipe_purple_buddy_menu((PurpleBuddy
*) node
);
337 if (PURPLE_IS_CHAT(node
))
339 return sipe_purple_chat_menu((PurpleChat
*)node
);
345 static guint
get_authentication_type(PurpleAccount
*account
)
347 const gchar
*auth
= purple_account_get_string(account
, "authentication", "ntlm");
349 /* map option list to type - default is automatic */
350 guint authentication_type
= SIPE_AUTHENTICATION_TYPE_AUTOMATIC
;
351 if (sipe_strequal(auth
, "ntlm")) {
352 authentication_type
= SIPE_AUTHENTICATION_TYPE_NTLM
;
354 #if PURPLE_SIPE_SSO_AND_KERBEROS
355 if (sipe_strequal(auth
, "krb5")) {
356 authentication_type
= SIPE_AUTHENTICATION_TYPE_KERBEROS
;
359 if (sipe_strequal(auth
, "tls-dsk")) {
360 authentication_type
= SIPE_AUTHENTICATION_TYPE_TLS_DSK
;
363 return(authentication_type
);
366 static gboolean
get_sso_flag(PurpleAccount
*account
)
368 #if PURPLE_SIPE_SSO_AND_KERBEROS
370 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
371 * SIPE that it is OK to use Single Sign-On or not.
373 return(purple_account_get_bool(account
, "sso", FALSE
));
375 (void) account
; /* keep compiler happy */
380 static gboolean
get_dont_publish_flag(PurpleAccount
*account
)
382 /* default is to publish calendar information */
383 return(purple_account_get_bool(account
, "dont-publish", FALSE
));
386 static void connect_to_core(PurpleConnection
*gc
,
387 PurpleAccount
*account
,
388 const gchar
*password
)
390 const gchar
*username
= purple_account_get_username(account
);
391 const gchar
*email
= purple_account_get_string(account
, "email", NULL
);
392 const gchar
*email_url
= purple_account_get_string(account
, "email_url", NULL
);
393 const gchar
*transport
= purple_account_get_string(account
, "transport", "auto");
394 struct sipe_core_public
*sipe_public
;
395 gchar
**username_split
;
397 guint transport_type
;
398 struct sipe_backend_private
*purple_private
;
400 /* username format: <username>,[<optional login>] */
401 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username
);
402 username_split
= g_strsplit(username
, ",", 2);
404 sipe_public
= sipe_core_allocate(username_split
[0],
405 get_sso_flag(account
),
411 g_strfreev(username_split
);
414 purple_connection_error(gc
,
415 PURPLE_CONNECTION_ERROR_INVALID_USERNAME
,
420 sipe_public
->backend_private
= purple_private
= g_new0(struct sipe_backend_private
, 1);
421 purple_private
->public = sipe_public
;
422 purple_private
->gc
= gc
;
423 purple_private
->account
= account
;
425 sipe_purple_chat_setup_rejoin(purple_private
);
427 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH
);
428 if (get_dont_publish_flag(account
))
429 SIPE_CORE_FLAG_SET(DONT_PUBLISH
);
431 purple_connection_set_protocol_data(gc
, sipe_public
);
432 purple_connection_set_flags(gc
,
433 purple_connection_get_flags(gc
) |
434 PURPLE_CONNECTION_FLAG_HTML
|
435 PURPLE_CONNECTION_FLAG_FORMATTING_WBFO
|
436 PURPLE_CONNECTION_FLAG_NO_BGCOLOR
|
437 PURPLE_CONNECTION_FLAG_NO_FONTSIZE
|
438 PURPLE_CONNECTION_FLAG_NO_URLDESC
|
439 PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY
);
440 purple_connection_set_display_name(gc
, sipe_public
->sip_name
);
441 purple_connection_update_progress(gc
, _("Connecting"), 1, 2);
443 username_split
= g_strsplit(purple_account_get_string(account
, "server", ""), ":", 2);
444 if (sipe_strequal(transport
, "auto")) {
445 transport_type
= (username_split
[0] == NULL
) ?
446 SIPE_TRANSPORT_AUTO
: SIPE_TRANSPORT_TLS
;
447 } else if (sipe_strequal(transport
, "tls")) {
448 transport_type
= SIPE_TRANSPORT_TLS
;
450 transport_type
= SIPE_TRANSPORT_TCP
;
452 sipe_core_transport_sip_connect(sipe_public
,
454 get_authentication_type(account
),
456 username_split
[0] ? username_split
[1] : NULL
);
457 g_strfreev(username_split
);
460 static void password_required_cb(PurpleConnection
*gc
,
461 SIPE_UNUSED_PARAMETER PurpleRequestFields
*fields
)
463 #if !PURPLE_VERSION_CHECK(3,0,0)
464 if (!PURPLE_CONNECTION_IS_VALID(gc
)) {
469 purple_connection_error(gc
,
470 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
,
471 _("Password required"));
474 static void password_ok_cb(PurpleConnection
*gc
,
475 PurpleRequestFields
*fields
)
477 const gchar
*password
;
479 #if !PURPLE_VERSION_CHECK(3,0,0)
480 if (!PURPLE_CONNECTION_IS_VALID(gc
)) {
485 password
= purple_request_fields_get_string(fields
, "password");
487 if (password
&& strlen(password
)) {
488 PurpleAccount
*account
= purple_connection_get_account(gc
);
490 if (purple_request_fields_get_bool(fields
, "remember"))
491 purple_account_set_remember_password(account
, TRUE
);
492 purple_account_set_password(account
, password
493 #if PURPLE_VERSION_CHECK(3,0,0)
498 /* Now we have a password and we can connect */
499 connect_to_core(gc
, account
, password
);
502 /* reject an empty password */
503 password_required_cb(gc
, fields
);
506 static void sipe_purple_login(PurpleAccount
*account
)
508 PurpleConnection
*gc
= purple_account_get_connection(account
);
509 const gchar
*password
= purple_connection_get_password(gc
);
511 /* Password required? */
512 if (sipe_core_transport_sip_requires_password(get_authentication_type(account
),
513 get_sso_flag(account
)) &&
514 (!password
|| !strlen(password
)))
515 /* No password set - request one from user */
516 purple_account_request_password(account
,
517 G_CALLBACK(password_ok_cb
),
518 G_CALLBACK(password_required_cb
),
521 /* No password required or saved password - connect now */
522 connect_to_core(gc
, account
, password
);
526 static void sipe_purple_close(PurpleConnection
*gc
)
528 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
531 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
533 sipe_core_deallocate(sipe_public
);
535 /* anything left after that must be in pending state... */
536 sipe_purple_dns_query_cancel_all(purple_private
);
537 sipe_purple_transport_close_all(purple_private
);
539 if (purple_private
->roomlist_map
)
540 g_hash_table_destroy(purple_private
->roomlist_map
);
541 sipe_purple_chat_destroy_rejoin(purple_private
);
543 if (purple_private
->deferred_status_timeout
)
544 purple_timeout_remove(purple_private
->deferred_status_timeout
);
545 g_free(purple_private
->deferred_status_note
);
547 g_free(purple_private
);
548 purple_connection_set_protocol_data(gc
, NULL
);
552 #if PURPLE_VERSION_CHECK(3,0,0)
553 static int sipe_purple_send_im(PurpleConnection
*gc
, PurpleMessage
*msg
)
555 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
556 purple_message_get_recipient(msg
),
557 purple_message_get_contents(msg
));
561 static int sipe_purple_send_im(PurpleConnection
*gc
,
564 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags
)
566 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
, what
);
571 static unsigned int sipe_purple_send_typing(PurpleConnection
*gc
,
573 PurpleIMTypingState state
)
575 gboolean typing
= (state
== PURPLE_IM_TYPING
);
577 /* only enable this debug output while testing
578 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
581 * libpurple calls this function with PURPLE_NOT_TYPING *after*
582 * calling sipe_purple_send_im() with the message. This causes
583 * SIPE core to send out two SIP messages to the same dialog in
584 * short succession without waiting for the response to the first
585 * one. Some servers then reject the first one with
587 * SIP/2.0 500 Stale CSeq Value
589 * which triggers a "message not delivered" error for the user.
591 * Work around this by filtering out PURPLE_NOT_TYPING events.
593 if (state
!= PURPLE_IM_NOT_TYPING
)
594 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
598 /* tell libpurple to send typing indications every 4 seconds */
599 return(typing
? 4 : 0);
602 static void sipe_purple_get_info(PurpleConnection
*gc
, const char *who
)
604 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
608 static void sipe_purple_add_permit(PurpleConnection
*gc
, const char *name
)
610 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, TRUE
);
613 static void sipe_purple_add_deny(PurpleConnection
*gc
, const char *name
)
615 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, FALSE
);
618 static void sipe_purple_alias_buddy(PurpleConnection
*gc
, const char *name
,
621 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, alias
);
624 static void sipe_purple_group_rename(PurpleConnection
*gc
,
625 const char *old_name
,
627 SIPE_UNUSED_PARAMETER GList
*moved_buddies
)
629 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
631 purple_group_get_name(group
));
634 static void sipe_purple_convo_closed(PurpleConnection
*gc
,
637 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
);
640 static void sipe_purple_group_remove(PurpleConnection
*gc
, PurpleGroup
*group
)
642 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
643 purple_group_get_name(group
));
646 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
648 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount
*account
)
651 table
= g_hash_table_new(g_str_hash
, g_str_equal
);
652 g_hash_table_insert(table
, "login_label", (gpointer
)_("user@company.com"));
656 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
660 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER
int signum
)
662 capture_pipeline("PURPLE_SIPE_PIPELINE");
665 static gboolean
sipe_purple_initiate_media(PurpleAccount
*account
, const char *who
,
666 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type
)
668 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC
,
670 (type
& PURPLE_MEDIA_VIDEO
));
674 static PurpleMediaCaps
sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount
*account
,
675 SIPE_UNUSED_PARAMETER
const char *who
)
677 return PURPLE_MEDIA_CAPS_AUDIO
678 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
679 | PURPLE_MEDIA_CAPS_MODIFY_SESSION
;
686 * Simplistic source upward compatibility path for newer libpurple APIs
688 * Usually we compile with -Werror=missing-field-initializers if GCC supports
689 * it. But that means that the compilation of this structure can fail if the
690 * newer API has added additional plugin callbacks. For the benefit of the
691 * user we downgrade it to a warning here.
693 * Diagnostic #pragma was added in GCC 4.2.0
694 * Diagnostic push/pop was added in GCC 4.6.0
697 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || (__GNUC__ >= 5)
698 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ >= 5)
699 #pragma GCC diagnostic push
701 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
704 static PurplePluginProtocolInfo sipe_prpl_info
=
706 #if PURPLE_VERSION_CHECK(3,0,0)
707 sizeof(PurplePluginProtocolInfo
), /* struct_size */
709 OPT_PROTO_CHAT_TOPIC
|
710 OPT_PROTO_PASSWORD_OPTIONAL
,
711 NULL
, /* user_splits */
712 NULL
, /* protocol_options */
713 NO_BUDDY_ICONS
, /* icon_spec */
714 sipe_list_icon
, /* list_icon */
715 NULL
, /* list_emblems */
716 sipe_purple_status_text
, /* status_text */
717 sipe_purple_tooltip_text
, /* tooltip_text */ // add custom info to contact tooltip
718 sipe_purple_status_types
, /* away_states */
719 sipe_purple_blist_node_menu
, /* blist_node_menu */
720 sipe_purple_chat_info
, /* chat_info */
721 sipe_purple_chat_info_defaults
, /* chat_info_defaults */
722 sipe_purple_login
, /* login */
723 sipe_purple_close
, /* close */
724 sipe_purple_send_im
, /* send_im */
725 NULL
, /* set_info */ // TODO maybe
726 sipe_purple_send_typing
, /* send_typing */
727 sipe_purple_get_info
, /* get_info */
728 sipe_purple_set_status
, /* set_status */
729 sipe_purple_set_idle
, /* set_idle */
730 NULL
, /* change_passwd */
731 sipe_purple_add_buddy
, /* add_buddy */
732 NULL
, /* add_buddies */
733 sipe_purple_remove_buddy
, /* remove_buddy */
734 NULL
, /* remove_buddies */
735 sipe_purple_add_permit
, /* add_permit */
736 sipe_purple_add_deny
, /* add_deny */
737 sipe_purple_add_deny
, /* rem_permit */
738 sipe_purple_add_permit
, /* rem_deny */
739 NULL
, /* set_permit_deny */
740 sipe_purple_chat_join
, /* join_chat */
741 NULL
, /* reject_chat */
742 NULL
, /* get_chat_name */
743 sipe_purple_chat_invite
, /* chat_invite */
744 sipe_purple_chat_leave
, /* chat_leave */
745 #if !PURPLE_VERSION_CHECK(3,0,0)
746 NULL
, /* chat_whisper */
748 sipe_purple_chat_send
, /* chat_send */
749 NULL
, /* keepalive */
750 NULL
, /* register_user */
751 NULL
, /* get_cb_info */ // deprecated
752 #if !PURPLE_VERSION_CHECK(3,0,0)
753 NULL
, /* get_cb_away */ // deprecated
755 sipe_purple_alias_buddy
, /* alias_buddy */
756 sipe_purple_group_buddy
, /* group_buddy */
757 sipe_purple_group_rename
, /* rename_group */
758 NULL
, /* buddy_free */
759 sipe_purple_convo_closed
, /* convo_closed */
760 purple_normalize_nocase
, /* normalize */
761 NULL
, /* set_buddy_icon */
762 sipe_purple_group_remove
, /* remove_group */
763 NULL
, /* get_cb_real_name */ // TODO?
764 NULL
, /* set_chat_topic */
765 NULL
, /* find_blist_chat */
766 sipe_purple_roomlist_get_list
, /* roomlist_get_list */
767 sipe_purple_roomlist_cancel
, /* roomlist_cancel */
768 NULL
, /* roomlist_expand_category */
769 NULL
, /* can_receive_file */
770 sipe_purple_ft_send_file
, /* send_file */
771 sipe_purple_ft_new_xfer
, /* new_xfer */
772 NULL
, /* offline_message */
773 NULL
, /* whiteboard_prpl_ops */
775 NULL
, /* roomlist_room_serialize */
776 NULL
, /* unregister_user */
777 NULL
, /* send_attention */
778 NULL
, /* get_attention_types */
779 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
780 /* Backward compatibility when compiling against 2.4.x API */
781 (void (*)(void)) /* _purple_reserved4 */
783 #if !PURPLE_VERSION_CHECK(3,0,0)
784 sizeof(PurplePluginProtocolInfo
), /* struct_size */
786 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
787 sipe_purple_get_account_text_table
, /* get_account_text_table */
788 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
790 sipe_purple_initiate_media
, /* initiate_media */
791 sipe_purple_get_media_caps
, /* get_media_caps */
793 NULL
, /* initiate_media */
794 NULL
, /* get_media_caps */
796 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
797 NULL
, /* get_moods */
798 NULL
, /* set_public_alias */
799 NULL
, /* get_public_alias */
800 #if PURPLE_VERSION_CHECK(2,8,0)
801 NULL
, /* add_buddy_with_invite */
802 NULL
, /* add_buddies_with_invite */
803 #elif PURPLE_VERSION_CHECK(3,0,0)
804 NULL
, /* get_max_message_size */
805 NULL
, /* media_send_dtmf */
812 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ >= 5)
813 #pragma GCC diagnostic pop
816 /* Original GCC error checking restored from here on... (see above) */
818 /* PurplePluginInfo function calls & data structure */
819 static gboolean
sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
822 struct sigaction action
;
823 memset(&action
, 0, sizeof (action
));
824 action
.sa_handler
= sipe_purple_sigusr1_handler
;
825 sigaction(SIGUSR1
, &action
, NULL
);
830 static gboolean
sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
833 struct sigaction action
;
834 memset(&action
, 0, sizeof (action
));
835 action
.sa_handler
= SIG_DFL
;
836 sigaction(SIGUSR1
, &action
, NULL
);
841 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
845 sipe_purple_activity_shutdown();
848 entry
= sipe_prpl_info
.protocol_options
;
850 purple_account_option_destroy(entry
->data
);
851 entry
= g_list_delete_link(entry
, entry
);
853 sipe_prpl_info
.protocol_options
= NULL
;
855 entry
= sipe_prpl_info
.user_splits
;
857 purple_account_user_split_destroy(entry
->data
);
858 entry
= g_list_delete_link(entry
, entry
);
860 sipe_prpl_info
.user_splits
= NULL
;
863 static void sipe_purple_show_about_plugin(PurplePluginAction
*action
)
865 gchar
*tmp
= sipe_core_about();
866 purple_notify_formatted((PurpleConnection
*) action
->context
,
867 NULL
, " ", NULL
, tmp
, NULL
, NULL
);
871 static void sipe_purple_join_conference_cb(PurpleConnection
*gc
,
872 PurpleRequestFields
*fields
)
874 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
877 PurpleRequestField
*field
= entries
->data
;
878 const char *id
= purple_request_field_get_id(field
);
879 const char *value
= purple_request_field_string_get_value(field
);
881 if (!sipe_strequal(id
, "meetingLocation"))
884 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, value
);
890 static void sipe_purple_phone_call_cb(PurpleConnection
*gc
,
891 PurpleRequestFields
*fields
)
893 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
896 PurpleRequestField
*field
= entries
->data
;
897 const char *id
= purple_request_field_get_id(field
);
898 const char *value
= purple_request_field_string_get_value(field
);
900 if (!sipe_strequal(id
, "phoneNumber"))
903 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, value
);
907 static void sipe_purple_phone_call(PurplePluginAction
*action
)
909 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
910 PurpleRequestFields
*fields
;
911 PurpleRequestFieldGroup
*group
;
912 PurpleRequestField
*field
;
914 fields
= purple_request_fields_new();
915 group
= purple_request_field_group_new(NULL
);
916 purple_request_fields_add_group(fields
, group
);
918 field
= purple_request_field_string_new("phoneNumber", _("Phone number"), NULL
, FALSE
);
919 purple_request_field_group_add_field(group
, field
);
921 purple_request_fields(gc
,
922 _("Call a phone number"),
923 _("Call a phone number"),
926 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb
),
928 #if PURPLE_VERSION_CHECK(3,0,0)
929 purple_request_cpar_from_connection(gc
),
931 purple_connection_get_account(gc
), NULL
, NULL
,
936 static void sipe_purple_test_call(PurplePluginAction
*action
)
938 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
939 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
943 static void sipe_purple_show_join_conference(PurplePluginAction
*action
)
945 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
946 PurpleRequestFields
*fields
;
947 PurpleRequestFieldGroup
*group
;
948 PurpleRequestField
*field
;
950 fields
= purple_request_fields_new();
951 group
= purple_request_field_group_new(NULL
);
952 purple_request_fields_add_group(fields
, group
);
954 field
= purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL
, FALSE
);
955 purple_request_field_group_add_field(group
, field
);
957 purple_request_fields(gc
,
958 _("Join conference"),
959 _("Join scheduled conference"),
960 _("Enter meeting location string you received in the invitation.\n"
962 "Valid location will be something like\n"
963 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
964 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
966 "https://meet.company.com/someone/abcdef1234"),
968 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb
),
970 #if PURPLE_VERSION_CHECK(3,0,0)
971 purple_request_cpar_from_connection(gc
),
973 purple_connection_get_account(gc
), NULL
, NULL
,
978 static void sipe_purple_republish_calendar(PurplePluginAction
*action
)
980 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
981 PurpleAccount
*account
= purple_connection_get_account(gc
);
983 if (get_dont_publish_flag(account
)) {
984 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
985 _("Publishing of calendar information has been disabled"),
988 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
992 static void sipe_purple_reset_status(PurplePluginAction
*action
)
994 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
995 PurpleAccount
*account
= purple_connection_get_account(gc
);
997 if (get_dont_publish_flag(account
)) {
998 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
999 _("Publishing of calendar information has been disabled"),
1002 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
1006 static GList
*sipe_purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
,
1007 SIPE_UNUSED_PARAMETER gpointer context
)
1010 PurplePluginAction
*act
;
1012 act
= purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin
);
1013 menu
= g_list_prepend(menu
, act
);
1015 act
= purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact
);
1016 menu
= g_list_prepend(menu
, act
);
1019 act
= purple_plugin_action_new(_("Call a phone number..."), sipe_purple_phone_call
);
1020 menu
= g_list_prepend(menu
, act
);
1022 act
= purple_plugin_action_new(_("Test call"), sipe_purple_test_call
);
1023 menu
= g_list_prepend(menu
, act
);
1026 act
= purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference
);
1027 menu
= g_list_prepend(menu
, act
);
1029 act
= purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar
);
1030 menu
= g_list_prepend(menu
, act
);
1032 act
= purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status
);
1033 menu
= g_list_prepend(menu
, act
);
1035 return g_list_reverse(menu
);
1038 static PurplePluginInfo sipe_purple_info
= {
1039 PURPLE_PLUGIN_MAGIC
,
1040 PURPLE_MAJOR_VERSION
,
1041 PURPLE_MINOR_VERSION
,
1042 PURPLE_PLUGIN_PROTOCOL
, /**< type */
1043 NULL
, /**< ui_requirement */
1045 NULL
, /**< dependencies */
1046 PURPLE_PRIORITY_DEFAULT
, /**< priority */
1047 "prpl-sipe", /**< id */
1048 "Office Communicator", /**< name */
1049 PACKAGE_VERSION
, /**< version */
1050 "Microsoft Office Communicator Protocol Plugin", /**< summary */
1051 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
1052 "Microsoft Live/Office Communications/Lync Server (LCS2005/OCS2007+)", /**< description */
1053 "Stefan Becker <chemobejk@gmail.com>, " /**< author */
1054 "Jakub Adam <jakub.adam@tieto.com>, " /**< author */
1055 "Anibal Avelar <avelar@gmail.com> (retired), " /**< author */
1056 "pier11 <pier11@operamail.com> (retired), " /**< author */
1057 "Gabriel Burt <gburt@novell.com> (retired)", /**< author */
1058 PACKAGE_URL
, /**< homepage */
1059 sipe_purple_plugin_load
, /**< load */
1060 sipe_purple_plugin_unload
, /**< unload */
1061 sipe_purple_plugin_destroy
, /**< destroy */
1062 NULL
, /**< ui_info */
1063 &sipe_prpl_info
, /**< extra_info */
1065 sipe_purple_actions
,
1072 static void sipe_purple_init_plugin(PurplePlugin
*plugin
)
1074 /* This needs to be called first */
1075 sipe_core_init(LOCALEDIR
);
1076 sipe_purple_activity_init();
1078 purple_plugin_register(plugin
);
1080 sipe_prpl_info
.user_splits
= g_list_append(sipe_prpl_info
.user_splits
,
1081 sipe_purple_user_split());
1083 sipe_prpl_info
.protocol_options
= sipe_purple_account_options();
1086 GList
* sipe_purple_account_options()
1088 PurpleAccountOption
*option
;
1089 GList
*options
= NULL
;
1092 * When adding new string settings please make sure to keep these
1095 * api/sipe-backend.h
1096 * purple-settings.c:setting_name[]
1098 option
= purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
1099 options
= g_list_append(options
, option
);
1101 option
= purple_account_option_list_new(_("Connection type"), "transport", NULL
);
1102 purple_account_option_add_list_item(option
, _("Auto"), "auto");
1103 purple_account_option_add_list_item(option
, _("SSL/TLS"), "tls");
1104 purple_account_option_add_list_item(option
, _("TCP"), "tcp");
1105 options
= g_list_append(options
, option
);
1107 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
1108 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
1110 option
= purple_account_option_string_new(_("User Agent"), "useragent", "");
1111 options
= g_list_append(options
, option
);
1113 option
= purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL
);
1114 purple_account_option_add_list_item(option
, _("Auto"), "auto");
1115 purple_account_option_add_list_item(option
, _("NTLM"), "ntlm");
1116 #if PURPLE_SIPE_SSO_AND_KERBEROS
1117 purple_account_option_add_list_item(option
, _("Kerberos"), "krb5");
1119 purple_account_option_add_list_item(option
, _("TLS-DSK"), "tls-dsk");
1120 options
= g_list_append(options
, option
);
1122 #if PURPLE_SIPE_SSO_AND_KERBEROS
1124 * When the user selects Single Sign-On then SIPE will ignore the
1125 * settings for "login name" and "password". Instead it will use the
1126 * default credentials provided by the OS.
1128 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
1129 * SIPE that it is OK to use Single Sign-On or not.
1131 * Configurations that are known to support Single Sign-On:
1133 * - Windows, host joined to domain, SIPE with SSPI: NTLM
1134 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
1135 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
1137 option
= purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE
);
1138 options
= g_list_append(options
, option
);
1141 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
1142 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
1144 option
= purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE
);
1145 options
= g_list_append(options
, option
);
1147 option
= purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
1148 options
= g_list_append(options
, option
);
1150 option
= purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
1151 options
= g_list_append(options
, option
);
1153 /** Example (Exchange): DOMAIN\user or user@company.com
1154 * Example (Domino) : email_address
1156 option
= purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
1157 options
= g_list_append(options
, option
);
1159 option
= purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
1160 purple_account_option_string_set_masked(option
, TRUE
);
1161 options
= g_list_append(options
, option
);
1163 /** Example (federated domain): company.com (i.e. ocschat@company.com)
1164 * Example (non-default user): user@company.com
1166 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", "");
1167 options
= g_list_append(options
, option
);
1170 option
= purple_account_option_list_new(_("Media encryption"), "encryption-policy", NULL
);
1171 purple_account_option_add_list_item(option
, _("Obey server policy"), "obey-server");
1172 purple_account_option_add_list_item(option
, _("Always"), "required");
1173 purple_account_option_add_list_item(option
, _("Optional"), "optional");
1174 purple_account_option_add_list_item(option
, _("Disabled"), "disabled");
1175 options
= g_list_append(options
, option
);
1181 gpointer
sipe_purple_user_split()
1183 PurpleAccountUserSplit
*split
=
1184 purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL
, ',');
1185 purple_account_user_split_set_reverse(split
, FALSE
);
1190 /* This macro makes the code a purple plugin */
1191 PURPLE_INIT_PLUGIN(sipe
, sipe_purple_init_plugin
, sipe_purple_info
);