purple: fix compilation without SSPI & Kerberos
[siplcs.git] / src / purple / purple-plugin.c
blob9b5387687a080d512cadc1a88893d126836986a2
1 /**
2 * @file purple-plugin.c
4 * pidgin-sipe
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
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include <string.h>
28 #include <time.h>
30 #include <glib.h>
32 #include "sipe-common.h"
34 /* Flag needed for correct version of PURPLE_INIT_PLUGIN() */
35 #ifndef PURPLE_PLUGINS
36 #define PURPLE_PLUGINS
37 #endif
39 /* for LOCALEDIR
40 * as it's determined on runtime, as Pidgin installation can be anywhere.
42 #ifdef _WIN32
43 #include "win32/win32dep.h"
44 #endif
46 #include "accountopt.h"
47 #include "blist.h"
48 #include "connection.h"
49 #include "core.h"
50 #include "dnssrv.h"
51 #ifdef HAVE_VV
52 #include "media.h"
53 #endif
54 #include "prpl.h"
55 #include "plugin.h"
56 #include "request.h"
57 #include "status.h"
59 * NOTE: Currently PURPLE_VERSION_CHECK(2,y,z) returns FALSE for libpurple >= 3.0.0.
60 * See also <http://developer.pidgin.im/ticket/14551>
62 * As a workaround an additional PURPLE_VERSION_CHECK(3,0,0) needs to be added.
64 #include "version.h"
66 #include "sipe-backend.h"
67 #include "sipe-core.h"
68 #include "sipe-nls.h"
70 #define _PurpleMessageFlags PurpleMessageFlags
71 #include "purple-private.h"
73 /* Backward compatibility when compiling against 2.4.x API */
74 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
75 #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100
76 #endif
79 * NOTE: this flag means two things:
81 * - is Single Sign-On supported, and
82 * - is Kerberos supported
84 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
85 #define PURPLE_SIPE_SSO_AND_KERBEROS 1
86 #else
87 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
88 #endif
90 /* Sipe core activity <-> Purple status mapping */
91 static const gchar * const activity_to_purple_map[SIPE_ACTIVITY_NUM_TYPES] = {
92 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
93 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
94 /* SIPE_ACTIVITY_ONLINE */ "online",
95 /* SIPE_ACTIVITY_INACTIVE */ "idle",
96 /* SIPE_ACTIVITY_BUSY */ "busy",
97 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
98 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
99 /* SIPE_ACTIVITY_BRB */ "be-right-back",
100 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
101 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
102 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
103 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
104 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
105 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
106 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
107 /* SIPE_ACTIVITY_OOF */ "out-of-office",
108 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
111 GHashTable *purple_token_map;
113 static void sipe_purple_activity_init(void)
115 guint index;
117 purple_token_map = g_hash_table_new(g_str_hash, g_str_equal);
118 for (index = SIPE_ACTIVITY_UNSET;
119 index < SIPE_ACTIVITY_NUM_TYPES;
120 index++) {
121 g_hash_table_insert(purple_token_map,
122 (gchar *) activity_to_purple_map[index],
123 GUINT_TO_POINTER(index));
127 static void sipe_purple_activity_shutdown(void)
129 g_hash_table_destroy(purple_token_map);
132 const gchar *sipe_purple_activity_to_token(guint type)
134 return(activity_to_purple_map[type]);
137 guint sipe_purple_token_to_activity(const gchar *token)
139 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map, token)));
142 gchar *sipe_backend_version(void)
144 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
147 /* PurplePluginProtocolInfo function calls & data structure */
148 static const char *sipe_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount *a,
149 SIPE_UNUSED_PARAMETER PurpleBuddy *b)
151 return "sipe";
154 static gchar *sipe_purple_status_text(PurpleBuddy *buddy)
156 const PurpleStatus *status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
157 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
158 buddy->name,
159 sipe_purple_token_to_activity(purple_status_get_id(status)),
160 purple_status_get_name(status));
163 static void sipe_purple_tooltip_text(PurpleBuddy *buddy,
164 PurpleNotifyUserInfo *user_info,
165 SIPE_UNUSED_PARAMETER gboolean full)
167 const PurplePresence *presence = purple_buddy_get_presence(buddy);
168 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
169 buddy->name,
170 purple_status_get_name(purple_presence_get_active_status(presence)),
171 purple_presence_is_online(presence),
172 (struct sipe_backend_buddy_tooltip *) user_info);
175 static GList *sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount *acc)
177 PurpleStatusType *type;
178 GList *types = NULL;
180 /* Macros to reduce code repetition.
181 Translators: noun */
182 #define SIPE_ADD_STATUS(prim,id,name,user) type = purple_status_type_new_with_attrs( \
183 prim, id, name, \
184 TRUE, user, FALSE, \
185 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
186 NULL); \
187 types = g_list_append(types, type);
189 /* Online */
190 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
191 NULL,
192 NULL,
193 TRUE);
195 /* Busy */
196 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
197 sipe_purple_activity_to_token(SIPE_ACTIVITY_BUSY),
198 sipe_core_activity_description(SIPE_ACTIVITY_BUSY),
199 TRUE);
201 /* Do Not Disturb */
202 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
203 sipe_purple_activity_to_token(SIPE_ACTIVITY_DND),
204 NULL,
205 TRUE);
207 /* In a call */
208 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
209 sipe_purple_activity_to_token(SIPE_ACTIVITY_ON_PHONE),
210 sipe_core_activity_description(SIPE_ACTIVITY_ON_PHONE),
211 FALSE);
213 /* In a conference call */
214 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
215 sipe_purple_activity_to_token(SIPE_ACTIVITY_IN_CONF),
216 sipe_core_activity_description(SIPE_ACTIVITY_IN_CONF),
217 FALSE);
219 /* Away */
220 /* Goes first in the list as
221 * purple picks the first status with the AWAY type
222 * for idle.
224 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
225 NULL,
226 NULL,
227 TRUE);
229 /* Be Right Back */
230 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
231 sipe_purple_activity_to_token(SIPE_ACTIVITY_BRB),
232 sipe_core_activity_description(SIPE_ACTIVITY_BRB),
233 TRUE);
235 /* Appear Offline */
236 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE,
237 NULL,
238 NULL,
239 TRUE);
241 /* Offline */
242 type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
243 NULL,
244 NULL,
245 TRUE);
246 types = g_list_append(types, type);
248 return types;
251 static GList *sipe_purple_blist_node_menu(PurpleBlistNode *node)
253 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) {
254 return sipe_purple_buddy_menu((PurpleBuddy *) node);
255 } else if(PURPLE_BLIST_NODE_IS_CHAT(node)) {
256 return sipe_purple_chat_menu((PurpleChat *)node);
257 } else {
258 return NULL;
262 static guint get_authentication_type(PurpleAccount *account)
264 const gchar *auth = purple_account_get_string(account, "authentication", "ntlm");
266 /* map option list to type - default is NTLM */
267 guint authentication_type = SIPE_AUTHENTICATION_TYPE_NTLM;
268 #if PURPLE_SIPE_SSO_AND_KERBEROS
269 if (sipe_strequal(auth, "krb5")) {
270 authentication_type = SIPE_AUTHENTICATION_TYPE_KERBEROS;
272 #endif
273 if (sipe_strequal(auth, "tls-dsk")) {
274 authentication_type = SIPE_AUTHENTICATION_TYPE_TLS_DSK;
277 return(authentication_type);
280 static gboolean get_sso_flag(PurpleAccount *account)
282 #if PURPLE_SIPE_SSO_AND_KERBEROS
284 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
285 * SIPE that it is OK to use Single Sign-On or not.
287 return(purple_account_get_bool(account, "sso", FALSE));
288 #else
289 (void) account; /* keep compiler happy */
290 return(FALSE);
291 #endif
294 static void connect_to_core(PurpleConnection *gc,
295 PurpleAccount *account,
296 const gchar *password)
298 const gchar *username = purple_account_get_username(account);
299 const gchar *email = purple_account_get_string(account, "email", NULL);
300 const gchar *email_url = purple_account_get_string(account, "email_url", NULL);
301 const gchar *transport = purple_account_get_string(account, "transport", "auto");
302 struct sipe_core_public *sipe_public;
303 gchar **username_split;
304 gchar *login_domain = NULL;
305 gchar *login_account = NULL;
306 const gchar *errmsg;
307 guint transport_type;
308 struct sipe_backend_private *purple_private;
310 /* username format: <username>,[<optional login>] */
311 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username);
312 username_split = g_strsplit(username, ",", 2);
314 /* login name specified? */
315 if (username_split[1] && strlen(username_split[1])) {
316 /* Allowed domain-account separators are / or \ */
317 gchar **domain_user = g_strsplit_set(username_split[1], "/\\", 2);
318 gboolean has_domain = domain_user[1] != NULL;
319 SIPE_DEBUG_INFO("sipe_purple_login: login '%s'", username_split[1]);
320 login_domain = has_domain ? g_strdup(domain_user[0]) : NULL;
321 login_account = g_strdup(domain_user[has_domain ? 1 : 0]);
322 SIPE_DEBUG_INFO("sipe_purple_login: auth domain '%s' user '%s'",
323 login_domain ? login_domain : "",
324 login_account);
325 g_strfreev(domain_user);
328 sipe_public = sipe_core_allocate(username_split[0],
329 login_domain, login_account,
330 password,
331 email,
332 email_url,
333 &errmsg);
334 g_free(login_domain);
335 g_free(login_account);
336 g_strfreev(username_split);
338 if (!sipe_public) {
339 #if PURPLE_VERSION_CHECK(3,0,0)
340 purple_connection_error(
341 #else
342 purple_connection_error_reason(
343 #endif
345 PURPLE_CONNECTION_ERROR_INVALID_USERNAME,
346 errmsg);
347 return;
350 sipe_public->backend_private = purple_private = g_new0(struct sipe_backend_private, 1);
351 purple_private->public = sipe_public;
352 purple_private->gc = gc;
353 purple_private->account = account;
355 sipe_purple_chat_setup_rejoin(purple_private);
357 SIPE_CORE_FLAG_UNSET(SSO);
358 if (get_sso_flag(account))
359 SIPE_CORE_FLAG_SET(SSO);
361 gc->proto_data = sipe_public;
362 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_FORMATTING_WBFO | PURPLE_CONNECTION_NO_BGCOLOR |
363 PURPLE_CONNECTION_NO_FONTSIZE | PURPLE_CONNECTION_NO_URLDESC | PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY;
364 purple_connection_set_display_name(gc, sipe_public->sip_name);
365 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
367 username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2);
368 if (sipe_strequal(transport, "auto")) {
369 transport_type = (username_split[0] == NULL) ?
370 SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS;
371 } else if (sipe_strequal(transport, "tls")) {
372 transport_type = SIPE_TRANSPORT_TLS;
373 } else {
374 transport_type = SIPE_TRANSPORT_TCP;
376 sipe_core_transport_sip_connect(sipe_public,
377 transport_type,
378 get_authentication_type(account),
379 username_split[0],
380 username_split[0] ? username_split[1] : NULL);
381 g_strfreev(username_split);
384 static void password_required_cb(PurpleConnection *gc,
385 SIPE_UNUSED_PARAMETER PurpleRequestFields *fields)
387 if (!PURPLE_CONNECTION_IS_VALID(gc))
388 return;
390 #if PURPLE_VERSION_CHECK(3,0,0)
391 purple_connection_error(
392 #else
393 purple_connection_error_reason(
394 #endif
396 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
397 _("Password required"));
400 static void password_ok_cb(PurpleConnection *gc,
401 PurpleRequestFields *fields)
403 const gchar *password;
405 if (!PURPLE_CONNECTION_IS_VALID(gc))
406 return;
408 password = purple_request_fields_get_string(fields, "password");
410 if (password && strlen(password)) {
411 PurpleAccount *account = purple_connection_get_account(gc);
413 if (purple_request_fields_get_bool(fields, "remember"))
414 purple_account_set_remember_password(account, TRUE);
415 purple_account_set_password(account, password);
417 /* Now we have a password and we can connect */
418 connect_to_core(gc, account, password);
420 } else
421 /* reject an empty password */
422 password_required_cb(gc, fields);
425 static void sipe_purple_login(PurpleAccount *account)
427 PurpleConnection *gc = purple_account_get_connection(account);
428 const gchar *password = purple_connection_get_password(gc);
430 /* Password required? */
431 if (sipe_core_transport_sip_requires_password(get_authentication_type(account),
432 get_sso_flag(account)) &&
433 (!password || !strlen(password)))
434 /* No password set - request one from user */
435 purple_account_request_password(account,
436 G_CALLBACK(password_ok_cb),
437 G_CALLBACK(password_required_cb),
438 gc);
439 else
440 /* No password required or saved password - connect now */
441 connect_to_core(gc, account, password);
445 static void sipe_purple_close(PurpleConnection *gc)
447 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
449 if (sipe_public) {
450 struct sipe_backend_private *purple_private = sipe_public->backend_private;
452 sipe_core_deallocate(sipe_public);
454 if (purple_private->roomlist_map)
455 g_hash_table_destroy(purple_private->roomlist_map);
456 sipe_purple_chat_destroy_rejoin(purple_private);
457 g_free(purple_private);
458 gc->proto_data = NULL;
462 static int sipe_purple_send_im(PurpleConnection *gc,
463 const char *who,
464 const char *what,
465 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags)
467 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who, what);
468 return 1;
471 #define SIPE_TYPING_SEND_TIMEOUT 4
473 static unsigned int sipe_purple_send_typing(PurpleConnection *gc,
474 const char *who,
475 PurpleTypingState state)
477 if (state == PURPLE_NOT_TYPING)
478 return 0;
480 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
481 who);
483 return SIPE_TYPING_SEND_TIMEOUT;
486 static void sipe_purple_get_info(PurpleConnection *gc, const char *who)
488 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
489 who);
492 static void sipe_purple_add_permit(PurpleConnection *gc, const char *name)
494 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE);
497 static void sipe_purple_add_deny(PurpleConnection *gc, const char *name)
499 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, FALSE);
502 static void sipe_purple_keep_alive(PurpleConnection *gc)
504 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
505 struct sipe_backend_private *purple_private = sipe_public->backend_private;
506 time_t now = time(NULL);
508 if ((sipe_public->keepalive_timeout > 0) &&
509 ((guint) (now - purple_private->last_keepalive) >= sipe_public->keepalive_timeout) &&
510 ((guint) (now - gc->last_received) >= sipe_public->keepalive_timeout)
512 sipe_core_transport_sip_keepalive(sipe_public);
513 purple_private->last_keepalive = now;
517 static void sipe_purple_alias_buddy(PurpleConnection *gc, const char *name,
518 const char *alias)
520 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, alias);
523 static void sipe_purple_group_rename(PurpleConnection *gc,
524 const char *old_name,
525 PurpleGroup *group,
526 SIPE_UNUSED_PARAMETER GList *moved_buddies)
528 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC, old_name, group->name);
531 static void sipe_purple_convo_closed(PurpleConnection *gc,
532 const char *who)
534 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who);
537 static void sipe_purple_group_remove(PurpleConnection *gc, PurpleGroup *group)
539 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC, group->name);
542 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
543 static GHashTable *
544 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount *account)
546 GHashTable *table;
547 table = g_hash_table_new(g_str_hash, g_str_equal);
548 g_hash_table_insert(table, "login_label", (gpointer)_("user@company.com"));
549 return table;
552 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
553 #ifdef HAVE_VV
555 static void
556 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER int signum)
558 capture_pipeline("PURPLE_SIPE_PIPELINE");
561 static gboolean sipe_purple_initiate_media(PurpleAccount *account, const char *who,
562 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type)
564 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
565 who,
566 (type & PURPLE_MEDIA_VIDEO));
567 return TRUE;
570 static PurpleMediaCaps sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount *account,
571 SIPE_UNUSED_PARAMETER const char *who)
573 return PURPLE_MEDIA_CAPS_AUDIO
574 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
575 | PURPLE_MEDIA_CAPS_MODIFY_SESSION;
577 #endif
578 #endif
579 #endif
582 * Simplistic source upward compatibility path for newer libpurple APIs
584 * Usually we compile with -Werror=missing-field-initializers if GCC supports
585 * it. But that means that the compilation of this structure can fail if the
586 * newer API has added additional plugin callbacks. For the benefit of the
587 * user we downgrade it to a warning here.
589 * Diagnostic #pragma was added in GCC 4.2.0
590 * Diagnostic push/pop was added in GCC 4.6.0
592 #ifdef __GNUC__
593 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 2)
594 #if __GNUC_MINOR__ >= 6
595 #pragma GCC diagnostic push
596 #endif
597 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
598 #endif
599 #endif
600 static PurplePluginProtocolInfo sipe_prpl_info =
602 #if PURPLE_VERSION_CHECK(3,0,0)
603 sizeof(PurplePluginProtocolInfo), /* struct_size */
604 #endif
605 OPT_PROTO_CHAT_TOPIC |
606 OPT_PROTO_PASSWORD_OPTIONAL,
607 NULL, /* user_splits */
608 NULL, /* protocol_options */
609 NO_BUDDY_ICONS, /* icon_spec */
610 sipe_list_icon, /* list_icon */
611 NULL, /* list_emblems */
612 sipe_purple_status_text, /* status_text */
613 sipe_purple_tooltip_text, /* tooltip_text */ // add custom info to contact tooltip
614 sipe_purple_status_types, /* away_states */
615 sipe_purple_blist_node_menu, /* blist_node_menu */
616 sipe_purple_chat_info, /* chat_info */
617 sipe_purple_chat_info_defaults, /* chat_info_defaults */
618 sipe_purple_login, /* login */
619 sipe_purple_close, /* close */
620 sipe_purple_send_im, /* send_im */
621 NULL, /* set_info */ // TODO maybe
622 sipe_purple_send_typing, /* send_typing */
623 sipe_purple_get_info, /* get_info */
624 sipe_purple_set_status, /* set_status */
625 sipe_purple_set_idle, /* set_idle */
626 NULL, /* change_passwd */
627 sipe_purple_add_buddy, /* add_buddy */
628 NULL, /* add_buddies */
629 sipe_purple_remove_buddy, /* remove_buddy */
630 NULL, /* remove_buddies */
631 sipe_purple_add_permit, /* add_permit */
632 sipe_purple_add_deny, /* add_deny */
633 sipe_purple_add_deny, /* rem_permit */
634 sipe_purple_add_permit, /* rem_deny */
635 NULL, /* set_permit_deny */
636 sipe_purple_chat_join, /* join_chat */
637 NULL, /* reject_chat */
638 NULL, /* get_chat_name */
639 sipe_purple_chat_invite, /* chat_invite */
640 sipe_purple_chat_leave, /* chat_leave */
641 NULL, /* chat_whisper */
642 sipe_purple_chat_send, /* chat_send */
643 sipe_purple_keep_alive, /* keepalive */
644 NULL, /* register_user */
645 NULL, /* get_cb_info */ // deprecated
646 #if !PURPLE_VERSION_CHECK(3,0,0)
647 NULL, /* get_cb_away */ // deprecated
648 #endif
649 sipe_purple_alias_buddy, /* alias_buddy */
650 sipe_purple_group_buddy, /* group_buddy */
651 sipe_purple_group_rename, /* rename_group */
652 NULL, /* buddy_free */
653 sipe_purple_convo_closed, /* convo_closed */
654 purple_normalize_nocase, /* normalize */
655 NULL, /* set_buddy_icon */
656 sipe_purple_group_remove, /* remove_group */
657 NULL, /* get_cb_real_name */ // TODO?
658 NULL, /* set_chat_topic */
659 NULL, /* find_blist_chat */
660 sipe_purple_roomlist_get_list, /* roomlist_get_list */
661 sipe_purple_roomlist_cancel, /* roomlist_cancel */
662 NULL, /* roomlist_expand_category */
663 NULL, /* can_receive_file */
664 sipe_purple_ft_send_file, /* send_file */
665 sipe_purple_ft_new_xfer, /* new_xfer */
666 NULL, /* offline_message */
667 NULL, /* whiteboard_prpl_ops */
668 NULL, /* send_raw */
669 NULL, /* roomlist_room_serialize */
670 NULL, /* unregister_user */
671 NULL, /* send_attention */
672 NULL, /* get_attention_types */
673 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
674 /* Backward compatibility when compiling against 2.4.x API */
675 (void (*)(void)) /* _purple_reserved4 */
676 #endif
677 #if !PURPLE_VERSION_CHECK(3,0,0)
678 sizeof(PurplePluginProtocolInfo), /* struct_size */
679 #endif
680 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
681 sipe_purple_get_account_text_table, /* get_account_text_table */
682 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
683 #ifdef HAVE_VV
684 sipe_purple_initiate_media, /* initiate_media */
685 sipe_purple_get_media_caps, /* get_media_caps */
686 #else
687 NULL, /* initiate_media */
688 NULL, /* get_media_caps */
689 #endif
690 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
691 NULL, /* get_moods */
692 NULL, /* set_public_alias */
693 NULL, /* get_public_alias */
694 #if PURPLE_VERSION_CHECK(2,8,0)
695 NULL, /* add_buddy_with_invite */
696 NULL, /* add_buddies_with_invite */
697 #endif
698 #endif
699 #endif
700 #endif
702 #ifdef __GNUC__
703 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 6)
704 #pragma GCC diagnostic pop
705 #endif
706 #endif
707 /* Original GCC error checking restored from here on... (see above) */
709 /* PurplePluginInfo function calls & data structure */
710 static gboolean sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
712 #ifdef HAVE_VV
713 struct sigaction action;
714 memset(&action, 0, sizeof (action));
715 action.sa_handler = sipe_purple_sigusr1_handler;
716 sigaction(SIGUSR1, &action, NULL);
717 #endif
718 return TRUE;
721 static gboolean sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
723 #ifdef HAVE_VV
724 struct sigaction action;
725 memset(&action, 0, sizeof (action));
726 action.sa_handler = SIG_DFL;
727 sigaction(SIGUSR1, &action, NULL);
728 #endif
729 return TRUE;
732 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
734 GList *entry;
736 sipe_purple_activity_shutdown();
737 sipe_core_destroy();
739 entry = sipe_prpl_info.protocol_options;
740 while (entry) {
741 purple_account_option_destroy(entry->data);
742 entry = g_list_delete_link(entry, entry);
744 sipe_prpl_info.protocol_options = NULL;
746 entry = sipe_prpl_info.user_splits;
747 while (entry) {
748 purple_account_user_split_destroy(entry->data);
749 entry = g_list_delete_link(entry, entry);
751 sipe_prpl_info.user_splits = NULL;
754 static void sipe_purple_show_about_plugin(PurplePluginAction *action)
756 gchar *tmp = sipe_core_about();
757 purple_notify_formatted((PurpleConnection *) action->context,
758 NULL, " ", NULL, tmp, NULL, NULL);
759 g_free(tmp);
762 static void sipe_purple_find_contact_cb(PurpleConnection *gc,
763 PurpleRequestFields *fields)
765 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
766 const gchar *given_name = NULL;
767 const gchar *surname = NULL;
768 const gchar *email = NULL;
769 const gchar *company = NULL;
770 const gchar *country = NULL;
772 while (entries) {
773 PurpleRequestField *field = entries->data;
774 const char *id = purple_request_field_get_id(field);
775 const char *value = purple_request_field_string_get_value(field);
777 SIPE_DEBUG_INFO("sipe_purple_find_contact_cb: %s = '%s'", id, value ? value : "");
779 if (value) {
780 if (strcmp(id, "given") == 0) {
781 given_name = value;
782 } else if (strcmp(id, "surname") == 0) {
783 surname = value;
784 } else if (strcmp(id, "email") == 0) {
785 email = value;
786 } else if (strcmp(id, "company") == 0) {
787 company = value;
788 } else if (strcmp(id, "country") == 0) {
789 country = value;
793 entries = g_list_next(entries);
796 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
797 NULL,
798 given_name,
799 surname,
800 email,
801 company,
802 country);
805 static void sipe_purple_show_find_contact(PurplePluginAction *action)
807 PurpleConnection *gc = (PurpleConnection *) action->context;
808 PurpleRequestFields *fields;
809 PurpleRequestFieldGroup *group;
810 PurpleRequestField *field;
812 fields = purple_request_fields_new();
813 group = purple_request_field_group_new(NULL);
814 purple_request_fields_add_group(fields, group);
816 field = purple_request_field_string_new("given", _("First name"), NULL, FALSE);
817 purple_request_field_group_add_field(group, field);
818 field = purple_request_field_string_new("surname", _("Last name"), NULL, FALSE);
819 purple_request_field_group_add_field(group, field);
820 field = purple_request_field_string_new("email", _("Email"), NULL, FALSE);
821 purple_request_field_group_add_field(group, field);
822 field = purple_request_field_string_new("company", _("Company"), NULL, FALSE);
823 purple_request_field_group_add_field(group, field);
824 field = purple_request_field_string_new("country", _("Country"), NULL, FALSE);
825 purple_request_field_group_add_field(group, field);
827 purple_request_fields(gc,
828 _("Search"),
829 _("Search for a contact"),
830 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
831 fields,
832 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb),
833 _("_Cancel"), NULL,
834 purple_connection_get_account(gc), NULL, NULL, gc);
837 static void sipe_purple_join_conference_cb(PurpleConnection *gc,
838 PurpleRequestFields *fields)
840 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
842 if (entries) {
843 PurpleRequestField *field = entries->data;
844 const char *id = purple_request_field_get_id(field);
845 const char *value = purple_request_field_string_get_value(field);
847 if (!sipe_strequal(id, "meetingLocation"))
848 return;
850 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC, value);
854 #ifdef HAVE_VV
855 static void sipe_purple_test_call(PurplePluginAction *action)
857 PurpleConnection *gc = (PurpleConnection *) action->context;
858 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
860 #endif
862 static void sipe_purple_show_join_conference(PurplePluginAction *action)
864 PurpleConnection *gc = (PurpleConnection *) action->context;
865 PurpleRequestFields *fields;
866 PurpleRequestFieldGroup *group;
867 PurpleRequestField *field;
869 fields = purple_request_fields_new();
870 group = purple_request_field_group_new(NULL);
871 purple_request_fields_add_group(fields, group);
873 field = purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL, FALSE);
874 purple_request_field_group_add_field(group, field);
876 purple_request_fields(gc,
877 _("Join conference"),
878 _("Join scheduled conference"),
879 _("Enter meeting location string you received in the invitation.\n"
880 "\n"
881 "Valid location will be something like\n"
882 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
883 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
884 "or\n"
885 "https://meet.company.com/someone/abcdef1234"),
886 fields,
887 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb),
888 _("_Cancel"), NULL,
889 purple_connection_get_account(gc), NULL, NULL, gc);
892 static void sipe_purple_republish_calendar(PurplePluginAction *action)
894 PurpleConnection *gc = (PurpleConnection *) action->context;
895 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
898 static void sipe_purple_reset_status(PurplePluginAction *action)
900 PurpleConnection *gc = (PurpleConnection *) action->context;
901 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
904 static GList *sipe_purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin *plugin,
905 SIPE_UNUSED_PARAMETER gpointer context)
907 GList *menu = NULL;
908 PurplePluginAction *act;
910 act = purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin);
911 menu = g_list_prepend(menu, act);
913 act = purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact);
914 menu = g_list_prepend(menu, act);
916 #ifdef HAVE_VV
917 act = purple_plugin_action_new(_("Test call"), sipe_purple_test_call);
918 menu = g_list_prepend(menu, act);
919 #endif
921 act = purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference);
922 menu = g_list_prepend(menu, act);
924 act = purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar);
925 menu = g_list_prepend(menu, act);
927 act = purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status);
928 menu = g_list_prepend(menu, act);
930 return g_list_reverse(menu);
933 static PurplePluginInfo sipe_purple_info = {
934 PURPLE_PLUGIN_MAGIC,
935 PURPLE_MAJOR_VERSION,
936 PURPLE_MINOR_VERSION,
937 PURPLE_PLUGIN_PROTOCOL, /**< type */
938 NULL, /**< ui_requirement */
939 0, /**< flags */
940 NULL, /**< dependencies */
941 PURPLE_PRIORITY_DEFAULT, /**< priority */
942 "prpl-sipe", /**< id */
943 "Office Communicator", /**< name */
944 PACKAGE_VERSION, /**< version */
945 "Microsoft Office Communicator Protocol Plugin", /**< summary */
946 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
947 "Microsoft Live/Office Communications Server (LCS2005/OCS2007+)", /**< description */
948 "Anibal Avelar <avelar@gmail.com>, " /**< author */
949 "Gabriel Burt <gburt@novell.com>, " /**< author */
950 "Stefan Becker <stefan.becker@nokia.com>, " /**< author */
951 "pier11 <pier11@operamail.com>", /**< author */
952 PACKAGE_URL, /**< homepage */
953 sipe_purple_plugin_load, /**< load */
954 sipe_purple_plugin_unload, /**< unload */
955 sipe_purple_plugin_destroy, /**< destroy */
956 NULL, /**< ui_info */
957 &sipe_prpl_info, /**< extra_info */
958 NULL,
959 sipe_purple_actions,
960 NULL,
961 NULL,
962 NULL,
963 NULL
966 static void sipe_purple_init_plugin(PurplePlugin *plugin)
968 PurpleAccountUserSplit *split;
969 PurpleAccountOption *option;
971 /* This needs to be called first */
972 sipe_core_init(LOCALEDIR);
973 sipe_purple_activity_init();
975 purple_plugin_register(plugin);
978 * When adding new string settings please make sure to keep these
979 * in sync:
981 * api/sipe-backend.h
982 * purple-settings.c:setting_name[]
984 split = purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL, ',');
985 purple_account_user_split_set_reverse(split, FALSE);
986 sipe_prpl_info.user_splits = g_list_append(sipe_prpl_info.user_splits, split);
988 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
989 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
991 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
992 purple_account_option_add_list_item(option, _("Auto"), "auto");
993 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
994 purple_account_option_add_list_item(option, _("TCP"), "tcp");
995 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
997 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
998 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
1000 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
1001 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1003 option = purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL);
1004 purple_account_option_add_list_item(option, _("NTLM"), "ntlm");
1005 #if PURPLE_SIPE_SSO_AND_KERBEROS
1006 purple_account_option_add_list_item(option, _("Kerberos"), "krb5");
1007 #endif
1008 purple_account_option_add_list_item(option, _("TLS-DSK"), "tls-dsk");
1009 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1011 #if PURPLE_SIPE_SSO_AND_KERBEROS
1013 * When the user selects Single Sign-On then SIPE will ignore the
1014 * settings for "login name" and "password". Instead it will use the
1015 * default credentials provided by the OS.
1017 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
1018 * SIPE that it is OK to use Single Sign-On or not.
1020 * Configurations that are known to support Single Sign-On:
1022 * - Windows, host joined to domain, SIPE with SSPI: NTLM
1023 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
1024 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
1026 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE);
1027 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1028 #endif
1030 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
1031 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
1033 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
1034 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1036 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
1037 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1039 /** Example (Exchange): DOMAIN\user or user@company.com
1040 * Example (Domino) : email_address
1042 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
1043 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1045 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
1046 #if PURPLE_VERSION_CHECK(3,0,0)
1047 purple_account_option_string_set_masked(
1048 #else
1049 purple_account_option_set_masked(
1050 #endif
1051 option, TRUE);
1052 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1054 /** Example (federated domain): company.com (i.e. ocschat@company.com)
1055 * Example (non-default user): user@company.com
1057 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", "");
1058 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1061 /* This macro makes the code a purple plugin */
1062 PURPLE_INIT_PLUGIN(sipe, sipe_purple_init_plugin, sipe_purple_info);
1065 Local Variables:
1066 mode: c
1067 c-file-style: "bsd"
1068 indent-tabs-mode: t
1069 tab-width: 8
1070 End: