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"
65 #include "sipe-backend.h"
66 #include "sipe-core.h"
69 #define _PurpleMessageFlags PurpleMessageFlags
70 #include "purple-private.h"
72 /* Backward compatibility when compiling against 2.4.x API */
73 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
74 #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100
78 * NOTE: this flag means two things:
80 * - is Single Sign-On supported, and
81 * - is Kerberos supported
83 #if defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_SSPI)
84 #define PURPLE_SIPE_SSO_AND_KERBEROS 1
86 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
89 /* Sipe core activity <-> Purple status mapping */
90 static const gchar
* const activity_to_purple_map
[SIPE_ACTIVITY_NUM_TYPES
] = {
91 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
92 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
93 /* SIPE_ACTIVITY_ONLINE */ "online",
94 /* SIPE_ACTIVITY_INACTIVE */ "idle",
95 /* SIPE_ACTIVITY_BUSY */ "busy",
96 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
97 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
98 /* SIPE_ACTIVITY_BRB */ "be-right-back",
99 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
100 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
101 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
102 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
103 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
104 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
105 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
106 /* SIPE_ACTIVITY_OOF */ "out-of-office",
107 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
110 GHashTable
*purple_token_map
;
112 static void sipe_purple_activity_init(void)
116 purple_token_map
= g_hash_table_new(g_str_hash
, g_str_equal
);
117 for (index
= SIPE_ACTIVITY_UNSET
;
118 index
< SIPE_ACTIVITY_NUM_TYPES
;
120 g_hash_table_insert(purple_token_map
,
121 (gchar
*) activity_to_purple_map
[index
],
122 GUINT_TO_POINTER(index
));
126 static void sipe_purple_activity_shutdown(void)
128 g_hash_table_destroy(purple_token_map
);
131 const gchar
*sipe_purple_activity_to_token(guint type
)
133 return(activity_to_purple_map
[type
]);
136 guint
sipe_purple_token_to_activity(const gchar
*token
)
138 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map
, token
)));
141 gchar
*sipe_backend_version(void)
143 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
146 /* PurplePluginProtocolInfo function calls & data structure */
147 static const char *sipe_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount
*a
,
148 SIPE_UNUSED_PARAMETER PurpleBuddy
*b
)
153 static gchar
*sipe_purple_status_text(PurpleBuddy
*buddy
)
155 const PurpleStatus
*status
= purple_presence_get_active_status(purple_buddy_get_presence(buddy
));
156 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
157 purple_buddy_get_name(buddy
),
158 sipe_purple_token_to_activity(purple_status_get_id(status
)),
159 purple_status_get_name(status
));
162 static void sipe_purple_tooltip_text(PurpleBuddy
*buddy
,
163 PurpleNotifyUserInfo
*user_info
,
164 SIPE_UNUSED_PARAMETER gboolean full
)
166 const PurplePresence
*presence
= purple_buddy_get_presence(buddy
);
167 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
168 purple_buddy_get_name(buddy
),
169 purple_status_get_name(purple_presence_get_active_status(presence
)),
170 purple_presence_is_online(presence
),
171 (struct sipe_backend_buddy_tooltip
*) user_info
);
174 static GList
*sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount
*acc
)
176 PurpleStatusType
*type
;
179 /* Macros to reduce code repetition.
181 #define SIPE_ADD_STATUS(prim,id,name,user) type = purple_status_type_new_with_attrs( \
184 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
186 types = g_list_append(types, type);
189 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE
,
195 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
196 sipe_purple_activity_to_token(SIPE_ACTIVITY_BUSY
),
197 sipe_core_activity_description(SIPE_ACTIVITY_BUSY
),
201 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
202 sipe_purple_activity_to_token(SIPE_ACTIVITY_DND
),
207 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
208 sipe_purple_activity_to_token(SIPE_ACTIVITY_ON_PHONE
),
209 sipe_core_activity_description(SIPE_ACTIVITY_ON_PHONE
),
212 /* In a conference call */
213 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
214 sipe_purple_activity_to_token(SIPE_ACTIVITY_IN_CONF
),
215 sipe_core_activity_description(SIPE_ACTIVITY_IN_CONF
),
219 /* Goes first in the list as
220 * purple picks the first status with the AWAY type
223 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
229 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
230 sipe_purple_activity_to_token(SIPE_ACTIVITY_BRB
),
231 sipe_core_activity_description(SIPE_ACTIVITY_BRB
),
235 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE
,
241 type
= purple_status_type_new(PURPLE_STATUS_OFFLINE
,
245 types
= g_list_append(types
, type
);
250 static GList
*sipe_purple_blist_node_menu(PurpleBlistNode
*node
)
252 if(PURPLE_BLIST_NODE_IS_BUDDY(node
)) {
253 return sipe_purple_buddy_menu((PurpleBuddy
*) node
);
254 } else if(PURPLE_BLIST_NODE_IS_CHAT(node
)) {
255 return sipe_purple_chat_menu((PurpleChat
*)node
);
261 static guint
get_authentication_type(PurpleAccount
*account
)
263 const gchar
*auth
= purple_account_get_string(account
, "authentication", "ntlm");
265 /* map option list to type - default is NTLM */
266 guint authentication_type
= SIPE_AUTHENTICATION_TYPE_NTLM
;
267 #if PURPLE_SIPE_SSO_AND_KERBEROS
268 if (sipe_strequal(auth
, "krb5")) {
269 authentication_type
= SIPE_AUTHENTICATION_TYPE_KERBEROS
;
272 if (sipe_strequal(auth
, "tls-dsk")) {
273 authentication_type
= SIPE_AUTHENTICATION_TYPE_TLS_DSK
;
276 return(authentication_type
);
279 static gboolean
get_sso_flag(PurpleAccount
*account
)
281 #if PURPLE_SIPE_SSO_AND_KERBEROS
283 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
284 * SIPE that it is OK to use Single Sign-On or not.
286 return(purple_account_get_bool(account
, "sso", FALSE
));
288 (void) account
; /* keep compiler happy */
293 static gboolean
get_dont_publish_flag(PurpleAccount
*account
)
295 /* default is to publish calendar information */
296 return(purple_account_get_bool(account
, "dont-publish", FALSE
));
299 static void connect_to_core(PurpleConnection
*gc
,
300 PurpleAccount
*account
,
301 const gchar
*password
)
303 const gchar
*username
= purple_account_get_username(account
);
304 const gchar
*email
= purple_account_get_string(account
, "email", NULL
);
305 const gchar
*email_url
= purple_account_get_string(account
, "email_url", NULL
);
306 const gchar
*transport
= purple_account_get_string(account
, "transport", "auto");
307 struct sipe_core_public
*sipe_public
;
308 gchar
**username_split
;
309 gchar
*login_domain
= NULL
;
310 gchar
*login_account
= NULL
;
312 guint transport_type
;
313 struct sipe_backend_private
*purple_private
;
314 gboolean sso
= get_sso_flag(account
);
316 /* username format: <username>,[<optional login>] */
317 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username
);
318 username_split
= g_strsplit(username
, ",", 2);
320 /* login name is ignored when SSO has been selected */
322 /* login name specified? */
323 if (username_split
[1] && strlen(username_split
[1])) {
324 /* Allowed domain-account separators are / or \ */
325 gchar
**domain_user
= g_strsplit_set(username_split
[1], "/\\", 2);
326 gboolean has_domain
= domain_user
[1] != NULL
;
327 SIPE_DEBUG_INFO("sipe_purple_login: login '%s'", username_split
[1]);
328 login_domain
= has_domain
? g_strdup(domain_user
[0]) : NULL
;
329 login_account
= g_strdup(domain_user
[has_domain
? 1 : 0]);
330 SIPE_DEBUG_INFO("sipe_purple_login: auth domain '%s' user '%s'",
331 login_domain
? login_domain
: "",
333 g_strfreev(domain_user
);
335 /* No -> duplicate username */
336 login_account
= g_strdup(username_split
[0]);
340 sipe_public
= sipe_core_allocate(username_split
[0],
342 login_domain
, login_account
,
347 g_free(login_domain
);
348 g_free(login_account
);
349 g_strfreev(username_split
);
352 #if PURPLE_VERSION_CHECK(3,0,0)
353 purple_connection_error(
355 purple_connection_error_reason(
358 PURPLE_CONNECTION_ERROR_INVALID_USERNAME
,
363 sipe_public
->backend_private
= purple_private
= g_new0(struct sipe_backend_private
, 1);
364 purple_private
->public = sipe_public
;
365 purple_private
->gc
= gc
;
366 purple_private
->account
= account
;
368 sipe_purple_chat_setup_rejoin(purple_private
);
370 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH
);
371 if (get_dont_publish_flag(account
))
372 SIPE_CORE_FLAG_SET(DONT_PUBLISH
);
374 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
375 purple_connection_set_protocol_data(gc
, sipe_public
);
377 gc
->proto_data
= sipe_public
;
379 gc
->flags
|= PURPLE_CONNECTION_HTML
| PURPLE_CONNECTION_FORMATTING_WBFO
| PURPLE_CONNECTION_NO_BGCOLOR
|
380 PURPLE_CONNECTION_NO_FONTSIZE
| PURPLE_CONNECTION_NO_URLDESC
| PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
;
381 purple_connection_set_display_name(gc
, sipe_public
->sip_name
);
382 purple_connection_update_progress(gc
, _("Connecting"), 1, 2);
384 username_split
= g_strsplit(purple_account_get_string(account
, "server", ""), ":", 2);
385 if (sipe_strequal(transport
, "auto")) {
386 transport_type
= (username_split
[0] == NULL
) ?
387 SIPE_TRANSPORT_AUTO
: SIPE_TRANSPORT_TLS
;
388 } else if (sipe_strequal(transport
, "tls")) {
389 transport_type
= SIPE_TRANSPORT_TLS
;
391 transport_type
= SIPE_TRANSPORT_TCP
;
393 sipe_core_transport_sip_connect(sipe_public
,
395 get_authentication_type(account
),
397 username_split
[0] ? username_split
[1] : NULL
);
398 g_strfreev(username_split
);
401 static void password_required_cb(PurpleConnection
*gc
,
402 SIPE_UNUSED_PARAMETER PurpleRequestFields
*fields
)
404 if (!PURPLE_CONNECTION_IS_VALID(gc
))
407 #if PURPLE_VERSION_CHECK(3,0,0)
408 purple_connection_error(
410 purple_connection_error_reason(
413 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
,
414 _("Password required"));
417 static void password_ok_cb(PurpleConnection
*gc
,
418 PurpleRequestFields
*fields
)
420 const gchar
*password
;
422 if (!PURPLE_CONNECTION_IS_VALID(gc
))
425 password
= purple_request_fields_get_string(fields
, "password");
427 if (password
&& strlen(password
)) {
428 PurpleAccount
*account
= purple_connection_get_account(gc
);
430 if (purple_request_fields_get_bool(fields
, "remember"))
431 purple_account_set_remember_password(account
, TRUE
);
432 purple_account_set_password(account
, password
433 #if PURPLE_VERSION_CHECK(3,0,0)
438 /* Now we have a password and we can connect */
439 connect_to_core(gc
, account
, password
);
442 /* reject an empty password */
443 password_required_cb(gc
, fields
);
446 static void sipe_purple_login(PurpleAccount
*account
)
448 PurpleConnection
*gc
= purple_account_get_connection(account
);
449 const gchar
*password
= purple_connection_get_password(gc
);
451 /* Password required? */
452 if (sipe_core_transport_sip_requires_password(get_authentication_type(account
),
453 get_sso_flag(account
)) &&
454 (!password
|| !strlen(password
)))
455 /* No password set - request one from user */
456 purple_account_request_password(account
,
457 G_CALLBACK(password_ok_cb
),
458 G_CALLBACK(password_required_cb
),
461 /* No password required or saved password - connect now */
462 connect_to_core(gc
, account
, password
);
466 static void sipe_purple_close(PurpleConnection
*gc
)
468 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
471 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
473 sipe_core_deallocate(sipe_public
);
475 /* anything left after that must be in pending state... */
476 sipe_purple_dns_query_cancel_all(purple_private
);
477 sipe_purple_transport_close_all(purple_private
);
479 if (purple_private
->roomlist_map
)
480 g_hash_table_destroy(purple_private
->roomlist_map
);
481 sipe_purple_chat_destroy_rejoin(purple_private
);
482 g_free(purple_private
);
483 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
484 purple_connection_set_protocol_data(gc
, NULL
);
486 gc
->proto_data
= NULL
;
491 static int sipe_purple_send_im(PurpleConnection
*gc
,
494 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags
)
496 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
, what
);
500 static unsigned int sipe_purple_send_typing(PurpleConnection
*gc
,
502 PurpleTypingState state
)
504 gboolean typing
= (state
== PURPLE_TYPING
);
506 /* only enable this debug output while testing
507 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
510 * libpurple calls this function with PURPLE_NOT_TYPING *after*
511 * calling sipe_purple_send_im() with the message. This causes
512 * SIPE core to send out two SIP messages to the same dialog in
513 * short succession without waiting for the response to the first
514 * one. Some servers then reject the first one with
516 * SIP/2.0 500 Stale CSeq Value
518 * which triggers a "message not delivered" error for the user.
520 * Work around this by filtering out PURPLE_NOT_TYPING events.
522 if (state
!= PURPLE_NOT_TYPING
)
523 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
527 /* tell libpurple to send typing indications every 4 seconds */
528 return(typing
? 4 : 0);
531 static void sipe_purple_get_info(PurpleConnection
*gc
, const char *who
)
533 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
537 static void sipe_purple_add_permit(PurpleConnection
*gc
, const char *name
)
539 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, TRUE
);
542 static void sipe_purple_add_deny(PurpleConnection
*gc
, const char *name
)
544 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, FALSE
);
547 static void sipe_purple_alias_buddy(PurpleConnection
*gc
, const char *name
,
550 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, alias
);
553 static void sipe_purple_group_rename(PurpleConnection
*gc
,
554 const char *old_name
,
556 SIPE_UNUSED_PARAMETER GList
*moved_buddies
)
558 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
560 purple_group_get_name(group
));
563 static void sipe_purple_convo_closed(PurpleConnection
*gc
,
566 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
);
569 static void sipe_purple_group_remove(PurpleConnection
*gc
, PurpleGroup
*group
)
571 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
572 purple_group_get_name(group
));
575 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
577 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount
*account
)
580 table
= g_hash_table_new(g_str_hash
, g_str_equal
);
581 g_hash_table_insert(table
, "login_label", (gpointer
)_("user@company.com"));
585 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
589 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER
int signum
)
591 capture_pipeline("PURPLE_SIPE_PIPELINE");
594 static gboolean
sipe_purple_initiate_media(PurpleAccount
*account
, const char *who
,
595 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type
)
597 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC
,
599 (type
& PURPLE_MEDIA_VIDEO
));
603 static PurpleMediaCaps
sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount
*account
,
604 SIPE_UNUSED_PARAMETER
const char *who
)
606 return PURPLE_MEDIA_CAPS_AUDIO
607 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
608 | PURPLE_MEDIA_CAPS_MODIFY_SESSION
;
615 * Simplistic source upward compatibility path for newer libpurple APIs
617 * Usually we compile with -Werror=missing-field-initializers if GCC supports
618 * it. But that means that the compilation of this structure can fail if the
619 * newer API has added additional plugin callbacks. For the benefit of the
620 * user we downgrade it to a warning here.
622 * Diagnostic #pragma was added in GCC 4.2.0
623 * Diagnostic push/pop was added in GCC 4.6.0
626 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 2)
627 #if __GNUC_MINOR__ >= 6
628 #pragma GCC diagnostic push
630 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
633 static PurplePluginProtocolInfo sipe_prpl_info
=
635 #if PURPLE_VERSION_CHECK(3,0,0)
636 sizeof(PurplePluginProtocolInfo
), /* struct_size */
638 OPT_PROTO_CHAT_TOPIC
|
639 OPT_PROTO_PASSWORD_OPTIONAL
,
640 NULL
, /* user_splits */
641 NULL
, /* protocol_options */
642 NO_BUDDY_ICONS
, /* icon_spec */
643 sipe_list_icon
, /* list_icon */
644 NULL
, /* list_emblems */
645 sipe_purple_status_text
, /* status_text */
646 sipe_purple_tooltip_text
, /* tooltip_text */ // add custom info to contact tooltip
647 sipe_purple_status_types
, /* away_states */
648 sipe_purple_blist_node_menu
, /* blist_node_menu */
649 sipe_purple_chat_info
, /* chat_info */
650 sipe_purple_chat_info_defaults
, /* chat_info_defaults */
651 sipe_purple_login
, /* login */
652 sipe_purple_close
, /* close */
653 sipe_purple_send_im
, /* send_im */
654 NULL
, /* set_info */ // TODO maybe
655 sipe_purple_send_typing
, /* send_typing */
656 sipe_purple_get_info
, /* get_info */
657 sipe_purple_set_status
, /* set_status */
658 sipe_purple_set_idle
, /* set_idle */
659 NULL
, /* change_passwd */
660 sipe_purple_add_buddy
, /* add_buddy */
661 NULL
, /* add_buddies */
662 sipe_purple_remove_buddy
, /* remove_buddy */
663 NULL
, /* remove_buddies */
664 sipe_purple_add_permit
, /* add_permit */
665 sipe_purple_add_deny
, /* add_deny */
666 sipe_purple_add_deny
, /* rem_permit */
667 sipe_purple_add_permit
, /* rem_deny */
668 NULL
, /* set_permit_deny */
669 sipe_purple_chat_join
, /* join_chat */
670 NULL
, /* reject_chat */
671 NULL
, /* get_chat_name */
672 sipe_purple_chat_invite
, /* chat_invite */
673 sipe_purple_chat_leave
, /* chat_leave */
674 NULL
, /* chat_whisper */
675 sipe_purple_chat_send
, /* chat_send */
676 NULL
, /* keepalive */
677 NULL
, /* register_user */
678 NULL
, /* get_cb_info */ // deprecated
679 #if !PURPLE_VERSION_CHECK(3,0,0)
680 NULL
, /* get_cb_away */ // deprecated
682 sipe_purple_alias_buddy
, /* alias_buddy */
683 sipe_purple_group_buddy
, /* group_buddy */
684 sipe_purple_group_rename
, /* rename_group */
685 NULL
, /* buddy_free */
686 sipe_purple_convo_closed
, /* convo_closed */
687 purple_normalize_nocase
, /* normalize */
688 NULL
, /* set_buddy_icon */
689 sipe_purple_group_remove
, /* remove_group */
690 NULL
, /* get_cb_real_name */ // TODO?
691 NULL
, /* set_chat_topic */
692 NULL
, /* find_blist_chat */
693 sipe_purple_roomlist_get_list
, /* roomlist_get_list */
694 sipe_purple_roomlist_cancel
, /* roomlist_cancel */
695 NULL
, /* roomlist_expand_category */
696 NULL
, /* can_receive_file */
697 sipe_purple_ft_send_file
, /* send_file */
698 sipe_purple_ft_new_xfer
, /* new_xfer */
699 NULL
, /* offline_message */
700 NULL
, /* whiteboard_prpl_ops */
702 NULL
, /* roomlist_room_serialize */
703 NULL
, /* unregister_user */
704 NULL
, /* send_attention */
705 NULL
, /* get_attention_types */
706 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
707 /* Backward compatibility when compiling against 2.4.x API */
708 (void (*)(void)) /* _purple_reserved4 */
710 #if !PURPLE_VERSION_CHECK(3,0,0)
711 sizeof(PurplePluginProtocolInfo
), /* struct_size */
713 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
714 sipe_purple_get_account_text_table
, /* get_account_text_table */
715 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
717 sipe_purple_initiate_media
, /* initiate_media */
718 sipe_purple_get_media_caps
, /* get_media_caps */
720 NULL
, /* initiate_media */
721 NULL
, /* get_media_caps */
723 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
724 NULL
, /* get_moods */
725 NULL
, /* set_public_alias */
726 NULL
, /* get_public_alias */
727 #if PURPLE_VERSION_CHECK(2,8,0)
728 NULL
, /* add_buddy_with_invite */
729 NULL
, /* add_buddies_with_invite */
730 #elif PURPLE_VERSION_CHECK(3,0,0)
731 NULL
, /* get_max_message_size */
738 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 6)
739 #pragma GCC diagnostic pop
742 /* Original GCC error checking restored from here on... (see above) */
744 /* PurplePluginInfo function calls & data structure */
745 static gboolean
sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
748 struct sigaction action
;
749 memset(&action
, 0, sizeof (action
));
750 action
.sa_handler
= sipe_purple_sigusr1_handler
;
751 sigaction(SIGUSR1
, &action
, NULL
);
756 static gboolean
sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
759 struct sigaction action
;
760 memset(&action
, 0, sizeof (action
));
761 action
.sa_handler
= SIG_DFL
;
762 sigaction(SIGUSR1
, &action
, NULL
);
767 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
771 sipe_purple_activity_shutdown();
774 entry
= sipe_prpl_info
.protocol_options
;
776 purple_account_option_destroy(entry
->data
);
777 entry
= g_list_delete_link(entry
, entry
);
779 sipe_prpl_info
.protocol_options
= NULL
;
781 entry
= sipe_prpl_info
.user_splits
;
783 purple_account_user_split_destroy(entry
->data
);
784 entry
= g_list_delete_link(entry
, entry
);
786 sipe_prpl_info
.user_splits
= NULL
;
789 static void sipe_purple_show_about_plugin(PurplePluginAction
*action
)
791 gchar
*tmp
= sipe_core_about();
792 purple_notify_formatted((PurpleConnection
*) action
->context
,
793 NULL
, " ", NULL
, tmp
, NULL
, NULL
);
797 static void sipe_purple_find_contact_cb(PurpleConnection
*gc
,
798 PurpleRequestFields
*fields
)
800 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
801 const gchar
*given_name
= NULL
;
802 const gchar
*surname
= NULL
;
803 const gchar
*email
= NULL
;
804 const gchar
*company
= NULL
;
805 const gchar
*country
= NULL
;
808 PurpleRequestField
*field
= entries
->data
;
809 const char *id
= purple_request_field_get_id(field
);
810 const char *value
= purple_request_field_string_get_value(field
);
812 SIPE_DEBUG_INFO("sipe_purple_find_contact_cb: %s = '%s'", id
, value
? value
: "");
815 if (strcmp(id
, "given") == 0) {
817 } else if (strcmp(id
, "surname") == 0) {
819 } else if (strcmp(id
, "email") == 0) {
821 } else if (strcmp(id
, "company") == 0) {
823 } else if (strcmp(id
, "country") == 0) {
828 entries
= g_list_next(entries
);
831 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
840 static void sipe_purple_show_find_contact(PurplePluginAction
*action
)
842 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
843 PurpleRequestFields
*fields
;
844 PurpleRequestFieldGroup
*group
;
845 PurpleRequestField
*field
;
846 #if PURPLE_VERSION_CHECK(3,0,0)
847 PurpleRequestCommonParameters
*cpar
= purple_request_cpar_from_connection(gc
);
850 fields
= purple_request_fields_new();
851 group
= purple_request_field_group_new(NULL
);
852 purple_request_fields_add_group(fields
, group
);
854 field
= purple_request_field_string_new("given", _("First name"), NULL
, FALSE
);
855 purple_request_field_group_add_field(group
, field
);
856 field
= purple_request_field_string_new("surname", _("Last name"), NULL
, FALSE
);
857 purple_request_field_group_add_field(group
, field
);
858 field
= purple_request_field_string_new("email", _("Email"), NULL
, FALSE
);
859 purple_request_field_group_add_field(group
, field
);
860 field
= purple_request_field_string_new("company", _("Company"), NULL
, FALSE
);
861 purple_request_field_group_add_field(group
, field
);
862 field
= purple_request_field_string_new("country", _("Country"), NULL
, FALSE
);
863 purple_request_field_group_add_field(group
, field
);
865 purple_request_fields(gc
,
867 _("Search for a contact"),
868 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
870 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb
),
872 #if PURPLE_VERSION_CHECK(3,0,0)
874 purple_request_cpar_unref(cpar
);
876 purple_connection_get_account(gc
), NULL
, NULL
, gc
);
880 static void sipe_purple_join_conference_cb(PurpleConnection
*gc
,
881 PurpleRequestFields
*fields
)
883 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
886 PurpleRequestField
*field
= entries
->data
;
887 const char *id
= purple_request_field_get_id(field
);
888 const char *value
= purple_request_field_string_get_value(field
);
890 if (!sipe_strequal(id
, "meetingLocation"))
893 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, value
);
899 static void sipe_purple_phone_call_cb(PurpleConnection
*gc
,
900 PurpleRequestFields
*fields
)
902 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
905 PurpleRequestField
*field
= entries
->data
;
906 const char *id
= purple_request_field_get_id(field
);
907 const char *value
= purple_request_field_string_get_value(field
);
909 if (!sipe_strequal(id
, "phoneNumber"))
912 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, value
);
916 static void sipe_purple_phone_call(PurplePluginAction
*action
)
918 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
919 PurpleRequestFields
*fields
;
920 PurpleRequestFieldGroup
*group
;
921 PurpleRequestField
*field
;
922 #if PURPLE_VERSION_CHECK(3,0,0)
923 PurpleRequestCommonParameters
*cpar
= purple_request_cpar_from_connection(gc
);
926 fields
= purple_request_fields_new();
927 group
= purple_request_field_group_new(NULL
);
928 purple_request_fields_add_group(fields
, group
);
930 field
= purple_request_field_string_new("phoneNumber", _("Phone number"), NULL
, FALSE
);
931 purple_request_field_group_add_field(group
, field
);
933 purple_request_fields(gc
,
934 _("Call a phone number"),
935 _("Call a phone number"),
938 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb
),
940 #if PURPLE_VERSION_CHECK(3,0,0)
942 purple_request_cpar_unref(cpar
);
944 purple_connection_get_account(gc
), NULL
, NULL
, gc
);
948 static void sipe_purple_test_call(PurplePluginAction
*action
)
950 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
951 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
955 static void sipe_purple_show_join_conference(PurplePluginAction
*action
)
957 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
958 PurpleRequestFields
*fields
;
959 PurpleRequestFieldGroup
*group
;
960 PurpleRequestField
*field
;
961 #if PURPLE_VERSION_CHECK(3,0,0)
962 PurpleRequestCommonParameters
*cpar
= purple_request_cpar_from_connection(gc
);
965 fields
= purple_request_fields_new();
966 group
= purple_request_field_group_new(NULL
);
967 purple_request_fields_add_group(fields
, group
);
969 field
= purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL
, FALSE
);
970 purple_request_field_group_add_field(group
, field
);
972 purple_request_fields(gc
,
973 _("Join conference"),
974 _("Join scheduled conference"),
975 _("Enter meeting location string you received in the invitation.\n"
977 "Valid location will be something like\n"
978 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
979 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
981 "https://meet.company.com/someone/abcdef1234"),
983 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb
),
985 #if PURPLE_VERSION_CHECK(3,0,0)
987 purple_request_cpar_unref(cpar
);
989 purple_connection_get_account(gc
), NULL
, NULL
, gc
);
993 static void sipe_purple_republish_calendar(PurplePluginAction
*action
)
995 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
996 PurpleAccount
*account
= purple_connection_get_account(gc
);
998 if (get_dont_publish_flag(account
)) {
999 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
1000 _("Publishing of calendar information has been disabled"),
1003 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
1007 static void sipe_purple_reset_status(PurplePluginAction
*action
)
1009 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
1010 PurpleAccount
*account
= purple_connection_get_account(gc
);
1012 if (get_dont_publish_flag(account
)) {
1013 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
1014 _("Publishing of calendar information has been disabled"),
1017 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
1021 static GList
*sipe_purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
,
1022 SIPE_UNUSED_PARAMETER gpointer context
)
1025 PurplePluginAction
*act
;
1027 act
= purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin
);
1028 menu
= g_list_prepend(menu
, act
);
1030 act
= purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact
);
1031 menu
= g_list_prepend(menu
, act
);
1034 act
= purple_plugin_action_new(_("Call a phone number..."), sipe_purple_phone_call
);
1035 menu
= g_list_prepend(menu
, act
);
1037 act
= purple_plugin_action_new(_("Test call"), sipe_purple_test_call
);
1038 menu
= g_list_prepend(menu
, act
);
1041 act
= purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference
);
1042 menu
= g_list_prepend(menu
, act
);
1044 act
= purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar
);
1045 menu
= g_list_prepend(menu
, act
);
1047 act
= purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status
);
1048 menu
= g_list_prepend(menu
, act
);
1050 return g_list_reverse(menu
);
1053 static PurplePluginInfo sipe_purple_info
= {
1054 PURPLE_PLUGIN_MAGIC
,
1055 PURPLE_MAJOR_VERSION
,
1056 PURPLE_MINOR_VERSION
,
1057 PURPLE_PLUGIN_PROTOCOL
, /**< type */
1058 NULL
, /**< ui_requirement */
1060 NULL
, /**< dependencies */
1061 PURPLE_PRIORITY_DEFAULT
, /**< priority */
1062 "prpl-sipe", /**< id */
1063 "Office Communicator", /**< name */
1064 PACKAGE_VERSION
, /**< version */
1065 "Microsoft Office Communicator Protocol Plugin", /**< summary */
1066 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
1067 "Microsoft Live/Office Communications/Lync Server (LCS2005/OCS2007+)", /**< description */
1068 "Stefan Becker <chemobejk@gmail.com>, " /**< author */
1069 "Jakub Adam <jakub.adam@tieto.com>, " /**< author */
1070 "Anibal Avelar <avelar@gmail.com> (retired), " /**< author */
1071 "pier11 <pier11@operamail.com> (retired), " /**< author */
1072 "Gabriel Burt <gburt@novell.com> (retired)", /**< author */
1073 PACKAGE_URL
, /**< homepage */
1074 sipe_purple_plugin_load
, /**< load */
1075 sipe_purple_plugin_unload
, /**< unload */
1076 sipe_purple_plugin_destroy
, /**< destroy */
1077 NULL
, /**< ui_info */
1078 &sipe_prpl_info
, /**< extra_info */
1080 sipe_purple_actions
,
1087 static void sipe_purple_init_plugin(PurplePlugin
*plugin
)
1089 PurpleAccountUserSplit
*split
;
1090 PurpleAccountOption
*option
;
1092 /* This needs to be called first */
1093 sipe_core_init(LOCALEDIR
);
1094 sipe_purple_activity_init();
1096 purple_plugin_register(plugin
);
1099 * When adding new string settings please make sure to keep these
1102 * api/sipe-backend.h
1103 * purple-settings.c:setting_name[]
1105 split
= purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL
, ',');
1106 purple_account_user_split_set_reverse(split
, FALSE
);
1107 sipe_prpl_info
.user_splits
= g_list_append(sipe_prpl_info
.user_splits
, split
);
1109 option
= purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
1110 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1112 option
= purple_account_option_list_new(_("Connection type"), "transport", NULL
);
1113 purple_account_option_add_list_item(option
, _("Auto"), "auto");
1114 purple_account_option_add_list_item(option
, _("SSL/TLS"), "tls");
1115 purple_account_option_add_list_item(option
, _("TCP"), "tcp");
1116 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1118 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
1119 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
1121 option
= purple_account_option_string_new(_("User Agent"), "useragent", "");
1122 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1124 option
= purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL
);
1125 purple_account_option_add_list_item(option
, _("NTLM"), "ntlm");
1126 #if PURPLE_SIPE_SSO_AND_KERBEROS
1127 purple_account_option_add_list_item(option
, _("Kerberos"), "krb5");
1129 purple_account_option_add_list_item(option
, _("TLS-DSK"), "tls-dsk");
1130 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1132 #if PURPLE_SIPE_SSO_AND_KERBEROS
1134 * When the user selects Single Sign-On then SIPE will ignore the
1135 * settings for "login name" and "password". Instead it will use the
1136 * default credentials provided by the OS.
1138 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
1139 * SIPE that it is OK to use Single Sign-On or not.
1141 * Configurations that are known to support Single Sign-On:
1143 * - Windows, host joined to domain, SIPE with SSPI: NTLM
1144 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
1145 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
1147 option
= purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE
);
1148 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1151 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
1152 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
1154 option
= purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE
);
1155 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1157 option
= purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
1158 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1160 option
= purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
1161 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1163 /** Example (Exchange): DOMAIN\user or user@company.com
1164 * Example (Domino) : email_address
1166 option
= purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
1167 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1169 option
= purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
1170 #if PURPLE_VERSION_CHECK(3,0,0)
1171 purple_account_option_string_set_masked(
1173 purple_account_option_set_masked(
1176 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1178 /** Example (federated domain): company.com (i.e. ocschat@company.com)
1179 * Example (non-default user): user@company.com
1181 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", "");
1182 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
1185 /* This macro makes the code a purple plugin */
1186 PURPLE_INIT_PLUGIN(sipe
, sipe_purple_init_plugin
, sipe_purple_info
);