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
);
542 g_free(purple_private
);
543 purple_connection_set_protocol_data(gc
, NULL
);
547 #if PURPLE_VERSION_CHECK(3,0,0)
548 static int sipe_purple_send_im(PurpleConnection
*gc
, PurpleMessage
*msg
)
550 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
551 purple_message_get_recipient(msg
),
552 purple_message_get_contents(msg
));
556 static int sipe_purple_send_im(PurpleConnection
*gc
,
559 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags
)
561 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
, what
);
566 static unsigned int sipe_purple_send_typing(PurpleConnection
*gc
,
568 PurpleIMTypingState state
)
570 gboolean typing
= (state
== PURPLE_IM_TYPING
);
572 /* only enable this debug output while testing
573 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
576 * libpurple calls this function with PURPLE_NOT_TYPING *after*
577 * calling sipe_purple_send_im() with the message. This causes
578 * SIPE core to send out two SIP messages to the same dialog in
579 * short succession without waiting for the response to the first
580 * one. Some servers then reject the first one with
582 * SIP/2.0 500 Stale CSeq Value
584 * which triggers a "message not delivered" error for the user.
586 * Work around this by filtering out PURPLE_NOT_TYPING events.
588 if (state
!= PURPLE_IM_NOT_TYPING
)
589 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
593 /* tell libpurple to send typing indications every 4 seconds */
594 return(typing
? 4 : 0);
597 static void sipe_purple_get_info(PurpleConnection
*gc
, const char *who
)
599 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
603 static void sipe_purple_add_permit(PurpleConnection
*gc
, const char *name
)
605 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, TRUE
);
608 static void sipe_purple_add_deny(PurpleConnection
*gc
, const char *name
)
610 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, FALSE
);
613 static void sipe_purple_alias_buddy(PurpleConnection
*gc
, const char *name
,
616 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, alias
);
619 static void sipe_purple_group_rename(PurpleConnection
*gc
,
620 const char *old_name
,
622 SIPE_UNUSED_PARAMETER GList
*moved_buddies
)
624 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
626 purple_group_get_name(group
));
629 static void sipe_purple_convo_closed(PurpleConnection
*gc
,
632 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
);
635 static void sipe_purple_group_remove(PurpleConnection
*gc
, PurpleGroup
*group
)
637 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
638 purple_group_get_name(group
));
641 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
643 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount
*account
)
646 table
= g_hash_table_new(g_str_hash
, g_str_equal
);
647 g_hash_table_insert(table
, "login_label", (gpointer
)_("user@company.com"));
651 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
655 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER
int signum
)
657 capture_pipeline("PURPLE_SIPE_PIPELINE");
660 static gboolean
sipe_purple_initiate_media(PurpleAccount
*account
, const char *who
,
661 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type
)
663 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC
,
665 (type
& PURPLE_MEDIA_VIDEO
));
669 static PurpleMediaCaps
sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount
*account
,
670 SIPE_UNUSED_PARAMETER
const char *who
)
672 return PURPLE_MEDIA_CAPS_AUDIO
673 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
674 | PURPLE_MEDIA_CAPS_MODIFY_SESSION
;
681 * Simplistic source upward compatibility path for newer libpurple APIs
683 * Usually we compile with -Werror=missing-field-initializers if GCC supports
684 * it. But that means that the compilation of this structure can fail if the
685 * newer API has added additional plugin callbacks. For the benefit of the
686 * user we downgrade it to a warning here.
688 * Diagnostic #pragma was added in GCC 4.2.0
689 * Diagnostic push/pop was added in GCC 4.6.0
692 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || (__GNUC__ >= 5)
693 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ >= 5)
694 #pragma GCC diagnostic push
696 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
699 static PurplePluginProtocolInfo sipe_prpl_info
=
701 #if PURPLE_VERSION_CHECK(3,0,0)
702 sizeof(PurplePluginProtocolInfo
), /* struct_size */
704 OPT_PROTO_CHAT_TOPIC
|
705 OPT_PROTO_PASSWORD_OPTIONAL
,
706 NULL
, /* user_splits */
707 NULL
, /* protocol_options */
708 NO_BUDDY_ICONS
, /* icon_spec */
709 sipe_list_icon
, /* list_icon */
710 NULL
, /* list_emblems */
711 sipe_purple_status_text
, /* status_text */
712 sipe_purple_tooltip_text
, /* tooltip_text */ // add custom info to contact tooltip
713 sipe_purple_status_types
, /* away_states */
714 sipe_purple_blist_node_menu
, /* blist_node_menu */
715 sipe_purple_chat_info
, /* chat_info */
716 sipe_purple_chat_info_defaults
, /* chat_info_defaults */
717 sipe_purple_login
, /* login */
718 sipe_purple_close
, /* close */
719 sipe_purple_send_im
, /* send_im */
720 NULL
, /* set_info */ // TODO maybe
721 sipe_purple_send_typing
, /* send_typing */
722 sipe_purple_get_info
, /* get_info */
723 sipe_purple_set_status
, /* set_status */
724 sipe_purple_set_idle
, /* set_idle */
725 NULL
, /* change_passwd */
726 sipe_purple_add_buddy
, /* add_buddy */
727 NULL
, /* add_buddies */
728 sipe_purple_remove_buddy
, /* remove_buddy */
729 NULL
, /* remove_buddies */
730 sipe_purple_add_permit
, /* add_permit */
731 sipe_purple_add_deny
, /* add_deny */
732 sipe_purple_add_deny
, /* rem_permit */
733 sipe_purple_add_permit
, /* rem_deny */
734 NULL
, /* set_permit_deny */
735 sipe_purple_chat_join
, /* join_chat */
736 NULL
, /* reject_chat */
737 NULL
, /* get_chat_name */
738 sipe_purple_chat_invite
, /* chat_invite */
739 sipe_purple_chat_leave
, /* chat_leave */
740 #if !PURPLE_VERSION_CHECK(3,0,0)
741 NULL
, /* chat_whisper */
743 sipe_purple_chat_send
, /* chat_send */
744 NULL
, /* keepalive */
745 NULL
, /* register_user */
746 NULL
, /* get_cb_info */ // deprecated
747 #if !PURPLE_VERSION_CHECK(3,0,0)
748 NULL
, /* get_cb_away */ // deprecated
750 sipe_purple_alias_buddy
, /* alias_buddy */
751 sipe_purple_group_buddy
, /* group_buddy */
752 sipe_purple_group_rename
, /* rename_group */
753 NULL
, /* buddy_free */
754 sipe_purple_convo_closed
, /* convo_closed */
755 purple_normalize_nocase
, /* normalize */
756 NULL
, /* set_buddy_icon */
757 sipe_purple_group_remove
, /* remove_group */
758 NULL
, /* get_cb_real_name */ // TODO?
759 NULL
, /* set_chat_topic */
760 NULL
, /* find_blist_chat */
761 sipe_purple_roomlist_get_list
, /* roomlist_get_list */
762 sipe_purple_roomlist_cancel
, /* roomlist_cancel */
763 NULL
, /* roomlist_expand_category */
764 NULL
, /* can_receive_file */
765 sipe_purple_ft_send_file
, /* send_file */
766 sipe_purple_ft_new_xfer
, /* new_xfer */
767 NULL
, /* offline_message */
768 NULL
, /* whiteboard_prpl_ops */
770 NULL
, /* roomlist_room_serialize */
771 NULL
, /* unregister_user */
772 NULL
, /* send_attention */
773 NULL
, /* get_attention_types */
774 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
775 /* Backward compatibility when compiling against 2.4.x API */
776 (void (*)(void)) /* _purple_reserved4 */
778 #if !PURPLE_VERSION_CHECK(3,0,0)
779 sizeof(PurplePluginProtocolInfo
), /* struct_size */
781 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
782 sipe_purple_get_account_text_table
, /* get_account_text_table */
783 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
785 sipe_purple_initiate_media
, /* initiate_media */
786 sipe_purple_get_media_caps
, /* get_media_caps */
788 NULL
, /* initiate_media */
789 NULL
, /* get_media_caps */
791 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
792 NULL
, /* get_moods */
793 NULL
, /* set_public_alias */
794 NULL
, /* get_public_alias */
795 #if PURPLE_VERSION_CHECK(2,8,0)
796 NULL
, /* add_buddy_with_invite */
797 NULL
, /* add_buddies_with_invite */
798 #elif PURPLE_VERSION_CHECK(3,0,0)
799 NULL
, /* get_max_message_size */
806 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ >= 5)
807 #pragma GCC diagnostic pop
810 /* Original GCC error checking restored from here on... (see above) */
812 /* PurplePluginInfo function calls & data structure */
813 static gboolean
sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
816 struct sigaction action
;
817 memset(&action
, 0, sizeof (action
));
818 action
.sa_handler
= sipe_purple_sigusr1_handler
;
819 sigaction(SIGUSR1
, &action
, NULL
);
824 static gboolean
sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
827 struct sigaction action
;
828 memset(&action
, 0, sizeof (action
));
829 action
.sa_handler
= SIG_DFL
;
830 sigaction(SIGUSR1
, &action
, NULL
);
835 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
839 sipe_purple_activity_shutdown();
842 entry
= sipe_prpl_info
.protocol_options
;
844 purple_account_option_destroy(entry
->data
);
845 entry
= g_list_delete_link(entry
, entry
);
847 sipe_prpl_info
.protocol_options
= NULL
;
849 entry
= sipe_prpl_info
.user_splits
;
851 purple_account_user_split_destroy(entry
->data
);
852 entry
= g_list_delete_link(entry
, entry
);
854 sipe_prpl_info
.user_splits
= NULL
;
857 static void sipe_purple_show_about_plugin(PurplePluginAction
*action
)
859 gchar
*tmp
= sipe_core_about();
860 purple_notify_formatted((PurpleConnection
*) action
->context
,
861 NULL
, " ", NULL
, tmp
, NULL
, NULL
);
865 static void sipe_purple_join_conference_cb(PurpleConnection
*gc
,
866 PurpleRequestFields
*fields
)
868 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
871 PurpleRequestField
*field
= entries
->data
;
872 const char *id
= purple_request_field_get_id(field
);
873 const char *value
= purple_request_field_string_get_value(field
);
875 if (!sipe_strequal(id
, "meetingLocation"))
878 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, value
);
884 static void sipe_purple_phone_call_cb(PurpleConnection
*gc
,
885 PurpleRequestFields
*fields
)
887 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
890 PurpleRequestField
*field
= entries
->data
;
891 const char *id
= purple_request_field_get_id(field
);
892 const char *value
= purple_request_field_string_get_value(field
);
894 if (!sipe_strequal(id
, "phoneNumber"))
897 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, value
);
901 static void sipe_purple_phone_call(PurplePluginAction
*action
)
903 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
904 PurpleRequestFields
*fields
;
905 PurpleRequestFieldGroup
*group
;
906 PurpleRequestField
*field
;
908 fields
= purple_request_fields_new();
909 group
= purple_request_field_group_new(NULL
);
910 purple_request_fields_add_group(fields
, group
);
912 field
= purple_request_field_string_new("phoneNumber", _("Phone number"), NULL
, FALSE
);
913 purple_request_field_group_add_field(group
, field
);
915 purple_request_fields(gc
,
916 _("Call a phone number"),
917 _("Call a phone number"),
920 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb
),
922 #if PURPLE_VERSION_CHECK(3,0,0)
923 purple_request_cpar_from_connection(gc
),
925 purple_connection_get_account(gc
), NULL
, NULL
,
930 static void sipe_purple_test_call(PurplePluginAction
*action
)
932 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
933 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
937 static void sipe_purple_show_join_conference(PurplePluginAction
*action
)
939 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
940 PurpleRequestFields
*fields
;
941 PurpleRequestFieldGroup
*group
;
942 PurpleRequestField
*field
;
944 fields
= purple_request_fields_new();
945 group
= purple_request_field_group_new(NULL
);
946 purple_request_fields_add_group(fields
, group
);
948 field
= purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL
, FALSE
);
949 purple_request_field_group_add_field(group
, field
);
951 purple_request_fields(gc
,
952 _("Join conference"),
953 _("Join scheduled conference"),
954 _("Enter meeting location string you received in the invitation.\n"
956 "Valid location will be something like\n"
957 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
958 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
960 "https://meet.company.com/someone/abcdef1234"),
962 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb
),
964 #if PURPLE_VERSION_CHECK(3,0,0)
965 purple_request_cpar_from_connection(gc
),
967 purple_connection_get_account(gc
), NULL
, NULL
,
972 static void sipe_purple_republish_calendar(PurplePluginAction
*action
)
974 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
975 PurpleAccount
*account
= purple_connection_get_account(gc
);
977 if (get_dont_publish_flag(account
)) {
978 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
979 _("Publishing of calendar information has been disabled"),
982 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
986 static void sipe_purple_reset_status(PurplePluginAction
*action
)
988 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
989 PurpleAccount
*account
= purple_connection_get_account(gc
);
991 if (get_dont_publish_flag(account
)) {
992 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
993 _("Publishing of calendar information has been disabled"),
996 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
1000 static GList
*sipe_purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
,
1001 SIPE_UNUSED_PARAMETER gpointer context
)
1004 PurplePluginAction
*act
;
1006 act
= purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin
);
1007 menu
= g_list_prepend(menu
, act
);
1009 act
= purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact
);
1010 menu
= g_list_prepend(menu
, act
);
1013 act
= purple_plugin_action_new(_("Call a phone number..."), sipe_purple_phone_call
);
1014 menu
= g_list_prepend(menu
, act
);
1016 act
= purple_plugin_action_new(_("Test call"), sipe_purple_test_call
);
1017 menu
= g_list_prepend(menu
, act
);
1020 act
= purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference
);
1021 menu
= g_list_prepend(menu
, act
);
1023 act
= purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar
);
1024 menu
= g_list_prepend(menu
, act
);
1026 act
= purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status
);
1027 menu
= g_list_prepend(menu
, act
);
1029 return g_list_reverse(menu
);
1032 static PurplePluginInfo sipe_purple_info
= {
1033 PURPLE_PLUGIN_MAGIC
,
1034 PURPLE_MAJOR_VERSION
,
1035 PURPLE_MINOR_VERSION
,
1036 PURPLE_PLUGIN_PROTOCOL
, /**< type */
1037 NULL
, /**< ui_requirement */
1039 NULL
, /**< dependencies */
1040 PURPLE_PRIORITY_DEFAULT
, /**< priority */
1041 "prpl-sipe", /**< id */
1042 "Office Communicator", /**< name */
1043 PACKAGE_VERSION
, /**< version */
1044 "Microsoft Office Communicator Protocol Plugin", /**< summary */
1045 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
1046 "Microsoft Live/Office Communications/Lync Server (LCS2005/OCS2007+)", /**< description */
1047 "Stefan Becker <chemobejk@gmail.com>, " /**< author */
1048 "Jakub Adam <jakub.adam@tieto.com>, " /**< author */
1049 "Anibal Avelar <avelar@gmail.com> (retired), " /**< author */
1050 "pier11 <pier11@operamail.com> (retired), " /**< author */
1051 "Gabriel Burt <gburt@novell.com> (retired)", /**< author */
1052 PACKAGE_URL
, /**< homepage */
1053 sipe_purple_plugin_load
, /**< load */
1054 sipe_purple_plugin_unload
, /**< unload */
1055 sipe_purple_plugin_destroy
, /**< destroy */
1056 NULL
, /**< ui_info */
1057 &sipe_prpl_info
, /**< extra_info */
1059 sipe_purple_actions
,
1066 static void sipe_purple_init_plugin(PurplePlugin
*plugin
)
1068 PurpleAccountUserSplit
*split
;
1069 PurpleAccountOption
*option
;
1071 /* This needs to be called first */
1072 sipe_core_init(LOCALEDIR
);
1073 sipe_purple_activity_init();
1075 purple_plugin_register(plugin
);
1078 * When adding new string settings please make sure to keep these
1081 * api/sipe-backend.h
1082 * purple-settings.c:setting_name[]
1084 split
= purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL
, ',');
1085 purple_account_user_split_set_reverse(split
, FALSE
);
1086 sipe_prpl_info
.user_splits
= g_list_append(sipe_prpl_info
.user_splits
, split
);
1088 option
= purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
1089 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1091 option
= purple_account_option_list_new(_("Connection type"), "transport", NULL
);
1092 purple_account_option_add_list_item(option
, _("Auto"), "auto");
1093 purple_account_option_add_list_item(option
, _("SSL/TLS"), "tls");
1094 purple_account_option_add_list_item(option
, _("TCP"), "tcp");
1095 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1097 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
1098 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
1100 option
= purple_account_option_string_new(_("User Agent"), "useragent", "");
1101 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1103 option
= purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL
);
1104 purple_account_option_add_list_item(option
, _("Auto"), "auto");
1105 purple_account_option_add_list_item(option
, _("NTLM"), "ntlm");
1106 #if PURPLE_SIPE_SSO_AND_KERBEROS
1107 purple_account_option_add_list_item(option
, _("Kerberos"), "krb5");
1109 purple_account_option_add_list_item(option
, _("TLS-DSK"), "tls-dsk");
1110 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1112 #if PURPLE_SIPE_SSO_AND_KERBEROS
1114 * When the user selects Single Sign-On then SIPE will ignore the
1115 * settings for "login name" and "password". Instead it will use the
1116 * default credentials provided by the OS.
1118 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
1119 * SIPE that it is OK to use Single Sign-On or not.
1121 * Configurations that are known to support Single Sign-On:
1123 * - Windows, host joined to domain, SIPE with SSPI: NTLM
1124 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
1125 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
1127 option
= purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE
);
1128 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1131 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
1132 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
1134 option
= purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE
);
1135 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1137 option
= purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
1138 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1140 option
= purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
1141 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1143 /** Example (Exchange): DOMAIN\user or user@company.com
1144 * Example (Domino) : email_address
1146 option
= purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
1147 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1149 option
= purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
1150 purple_account_option_string_set_masked(option
, TRUE
);
1151 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1153 /** Example (federated domain): company.com (i.e. ocschat@company.com)
1154 * Example (non-default user): user@company.com
1156 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", "");
1157 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1160 /* This macro makes the code a purple plugin */
1161 PURPLE_INIT_PLUGIN(sipe
, sipe_purple_init_plugin
, sipe_purple_info
);