Feature #3578132: Kerberos configuration should be passwordless
[siplcs.git] / src / purple / purple-plugin.c
blob00fe213976cfc15765ec2382b229520abf6c7c89
1 /**
2 * @file purple-plugin.c
4 * pidgin-sipe
6 * Copyright (C) 2010-12 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
78 /* Sipe core activity <-> Purple status mapping */
79 static const gchar * const activity_to_purple_map[SIPE_ACTIVITY_NUM_TYPES] = {
80 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
81 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
82 /* SIPE_ACTIVITY_ONLINE */ "online",
83 /* SIPE_ACTIVITY_INACTIVE */ "idle",
84 /* SIPE_ACTIVITY_BUSY */ "busy",
85 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
86 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
87 /* SIPE_ACTIVITY_BRB */ "be-right-back",
88 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
89 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
90 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
91 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
92 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
93 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
94 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
95 /* SIPE_ACTIVITY_OOF */ "out-of-office",
96 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
99 GHashTable *purple_token_map;
101 static void sipe_purple_activity_init(void)
103 guint index;
105 purple_token_map = g_hash_table_new(g_str_hash, g_str_equal);
106 for (index = SIPE_ACTIVITY_UNSET;
107 index < SIPE_ACTIVITY_NUM_TYPES;
108 index++) {
109 g_hash_table_insert(purple_token_map,
110 (gchar *) activity_to_purple_map[index],
111 GUINT_TO_POINTER(index));
115 static void sipe_purple_activity_shutdown(void)
117 g_hash_table_destroy(purple_token_map);
120 const gchar *sipe_purple_activity_to_token(guint type)
122 return(activity_to_purple_map[type]);
125 guint sipe_purple_token_to_activity(const gchar *token)
127 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map, token)));
130 gchar *sipe_backend_version(void)
132 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
135 /* PurplePluginProtocolInfo function calls & data structure */
136 static const char *sipe_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount *a,
137 SIPE_UNUSED_PARAMETER PurpleBuddy *b)
139 return "sipe";
142 static gchar *sipe_purple_status_text(PurpleBuddy *buddy)
144 const PurpleStatus *status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
145 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
146 buddy->name,
147 sipe_purple_token_to_activity(purple_status_get_id(status)),
148 purple_status_get_name(status));
151 static void sipe_purple_tooltip_text(PurpleBuddy *buddy,
152 PurpleNotifyUserInfo *user_info,
153 SIPE_UNUSED_PARAMETER gboolean full)
155 const PurplePresence *presence = purple_buddy_get_presence(buddy);
156 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
157 buddy->name,
158 purple_status_get_name(purple_presence_get_active_status(presence)),
159 purple_presence_is_online(presence),
160 (struct sipe_backend_buddy_tooltip *) user_info);
163 static GList *sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount *acc)
165 PurpleStatusType *type;
166 GList *types = NULL;
168 /* Macros to reduce code repetition.
169 Translators: noun */
170 #define SIPE_ADD_STATUS(prim,id,name,user) type = purple_status_type_new_with_attrs( \
171 prim, id, name, \
172 TRUE, user, FALSE, \
173 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
174 NULL); \
175 types = g_list_append(types, type);
177 /* Online */
178 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
179 NULL,
180 NULL,
181 TRUE);
183 /* Busy */
184 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
185 sipe_purple_activity_to_token(SIPE_ACTIVITY_BUSY),
186 sipe_core_activity_description(SIPE_ACTIVITY_BUSY),
187 TRUE);
189 /* Do Not Disturb */
190 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
191 sipe_purple_activity_to_token(SIPE_ACTIVITY_DND),
192 NULL,
193 TRUE);
195 /* In a call */
196 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
197 sipe_purple_activity_to_token(SIPE_ACTIVITY_ON_PHONE),
198 sipe_core_activity_description(SIPE_ACTIVITY_ON_PHONE),
199 FALSE);
201 /* In a conference call */
202 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
203 sipe_purple_activity_to_token(SIPE_ACTIVITY_IN_CONF),
204 sipe_core_activity_description(SIPE_ACTIVITY_IN_CONF),
205 FALSE);
207 /* Away */
208 /* Goes first in the list as
209 * purple picks the first status with the AWAY type
210 * for idle.
212 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
213 NULL,
214 NULL,
215 TRUE);
217 /* Be Right Back */
218 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
219 sipe_purple_activity_to_token(SIPE_ACTIVITY_BRB),
220 sipe_core_activity_description(SIPE_ACTIVITY_BRB),
221 TRUE);
223 /* Appear Offline */
224 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE,
225 NULL,
226 NULL,
227 TRUE);
229 /* Offline */
230 type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
231 NULL,
232 NULL,
233 TRUE);
234 types = g_list_append(types, type);
236 return types;
239 static GList *sipe_purple_blist_node_menu(PurpleBlistNode *node)
241 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) {
242 return sipe_purple_buddy_menu((PurpleBuddy *) node);
243 } else if(PURPLE_BLIST_NODE_IS_CHAT(node)) {
244 return sipe_purple_chat_menu((PurpleChat *)node);
245 } else {
246 return NULL;
250 static void sipe_purple_login(PurpleAccount *account)
252 PurpleConnection *gc = purple_account_get_connection(account);
253 const gchar *username = purple_account_get_username(account);
254 const gchar *password = purple_connection_get_password(gc);
255 const gchar *email = purple_account_get_string(account, "email", NULL);
256 const gchar *email_url = purple_account_get_string(account, "email_url", NULL);
257 const gchar *transport = purple_account_get_string(account, "transport", "auto");
258 const gchar *auth = purple_account_get_string(account, "authentication", "ntlm");
259 struct sipe_core_public *sipe_public;
260 gchar **username_split;
261 gchar *login_domain = NULL;
262 gchar *login_account = NULL;
263 const gchar *errmsg;
264 guint transport_type;
265 guint authentication_type;
266 struct sipe_backend_private *purple_private;
267 gboolean sso = TRUE;
269 /* map option list to type - default is NTLM */
270 authentication_type = SIPE_AUTHENTICATION_TYPE_NTLM;
271 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
272 if (sipe_strequal(auth, "krb5")) {
273 authentication_type = SIPE_AUTHENTICATION_TYPE_KERBEROS;
274 } else
275 #endif
276 #ifndef HAVE_SSPI
278 * @TODO: SSL handshake support isn't implemented in sip-sec-sspi.c.
279 * So ignore configuration setting for now.
281 if (sipe_strequal(auth, "tls-dsk")) {
282 authentication_type = SIPE_AUTHENTICATION_TYPE_TLS_DSK;
284 #endif
286 /* @TODO: is this correct?
287 "sso" is only available when Kerberos/SSPI support is compiled in */
288 sso = purple_account_get_bool(account, "sso", TRUE);
290 /* Password required? */
291 if (sipe_core_transport_sip_requires_password(authentication_type,
292 sso) &&
293 (!password || !strlen(password))) {
294 #if PURPLE_VERSION_CHECK(3,0,0)
295 purple_connection_error(
296 #else
297 purple_connection_error_reason(
298 #endif
300 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
301 _("Password required"));
302 return;
305 /* username format: <username>,[<optional login>] */
306 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username);
307 username_split = g_strsplit(username, ",", 2);
309 /* login name specified? */
310 if (username_split[1] && strlen(username_split[1])) {
311 /* Allowed domain-account separators are / or \ */
312 gchar **domain_user = g_strsplit_set(username_split[1], "/\\", 2);
313 gboolean has_domain = domain_user[1] != NULL;
314 SIPE_DEBUG_INFO("sipe_purple_login: login '%s'", username_split[1]);
315 login_domain = has_domain ? g_strdup(domain_user[0]) : NULL;
316 login_account = g_strdup(domain_user[has_domain ? 1 : 0]);
317 SIPE_DEBUG_INFO("sipe_purple_login: auth domain '%s' user '%s'",
318 login_domain ? login_domain : "",
319 login_account);
320 g_strfreev(domain_user);
323 sipe_public = sipe_core_allocate(username_split[0],
324 login_domain, login_account,
325 password,
326 email,
327 email_url,
328 &errmsg);
329 g_free(login_domain);
330 g_free(login_account);
331 g_strfreev(username_split);
333 if (!sipe_public) {
334 #if PURPLE_VERSION_CHECK(3,0,0)
335 purple_connection_error(
336 #else
337 purple_connection_error_reason(
338 #endif
340 PURPLE_CONNECTION_ERROR_INVALID_USERNAME,
341 errmsg);
342 return;
345 sipe_public->backend_private = purple_private = g_new0(struct sipe_backend_private, 1);
346 purple_private->public = sipe_public;
347 purple_private->gc = gc;
348 purple_private->account = account;
350 sipe_purple_chat_setup_rejoin(purple_private);
352 SIPE_CORE_FLAG_UNSET(SSO);
353 if (sso)
354 SIPE_CORE_FLAG_SET(SSO);
356 gc->proto_data = sipe_public;
357 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_FORMATTING_WBFO | PURPLE_CONNECTION_NO_BGCOLOR |
358 PURPLE_CONNECTION_NO_FONTSIZE | PURPLE_CONNECTION_NO_URLDESC | PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY;
359 purple_connection_set_display_name(gc, sipe_public->sip_name);
360 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
362 username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2);
363 if (sipe_strequal(transport, "auto")) {
364 transport_type = (username_split[0] == NULL) ?
365 SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS;
366 } else if (sipe_strequal(transport, "tls")) {
367 transport_type = SIPE_TRANSPORT_TLS;
368 } else {
369 transport_type = SIPE_TRANSPORT_TCP;
371 sipe_core_transport_sip_connect(sipe_public,
372 transport_type,
373 authentication_type,
374 username_split[0],
375 username_split[0] ? username_split[1] : NULL);
376 g_strfreev(username_split);
379 static void sipe_purple_close(PurpleConnection *gc)
381 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
383 if (sipe_public) {
384 struct sipe_backend_private *purple_private = sipe_public->backend_private;
386 sipe_core_deallocate(sipe_public);
388 if (purple_private->roomlist_map)
389 g_hash_table_destroy(purple_private->roomlist_map);
390 sipe_purple_chat_destroy_rejoin(purple_private);
391 g_free(purple_private);
392 gc->proto_data = NULL;
396 static int sipe_purple_send_im(PurpleConnection *gc,
397 const char *who,
398 const char *what,
399 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags)
401 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who, what);
402 return 1;
405 #define SIPE_TYPING_SEND_TIMEOUT 4
407 static unsigned int sipe_purple_send_typing(PurpleConnection *gc,
408 const char *who,
409 PurpleTypingState state)
411 if (state == PURPLE_NOT_TYPING)
412 return 0;
414 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
415 who);
417 return SIPE_TYPING_SEND_TIMEOUT;
420 static void sipe_purple_get_info(PurpleConnection *gc, const char *who)
422 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
423 who);
426 static void sipe_purple_add_permit(PurpleConnection *gc, const char *name)
428 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE);
431 static void sipe_purple_add_deny(PurpleConnection *gc, const char *name)
433 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, FALSE);
436 static void sipe_purple_keep_alive(PurpleConnection *gc)
438 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
439 struct sipe_backend_private *purple_private = sipe_public->backend_private;
440 time_t now = time(NULL);
442 if ((sipe_public->keepalive_timeout > 0) &&
443 ((guint) (now - purple_private->last_keepalive) >= sipe_public->keepalive_timeout) &&
444 ((guint) (now - gc->last_received) >= sipe_public->keepalive_timeout)
446 sipe_core_transport_sip_keepalive(sipe_public);
447 purple_private->last_keepalive = now;
451 static void sipe_purple_alias_buddy(PurpleConnection *gc, const char *name,
452 const char *alias)
454 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, alias);
457 static void sipe_purple_group_rename(PurpleConnection *gc,
458 const char *old_name,
459 PurpleGroup *group,
460 SIPE_UNUSED_PARAMETER GList *moved_buddies)
462 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC, old_name, group->name);
465 static void sipe_purple_convo_closed(PurpleConnection *gc,
466 const char *who)
468 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who);
471 static void sipe_purple_group_remove(PurpleConnection *gc, PurpleGroup *group)
473 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC, group->name);
476 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
477 static GHashTable *
478 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount *account)
480 GHashTable *table;
481 table = g_hash_table_new(g_str_hash, g_str_equal);
482 g_hash_table_insert(table, "login_label", (gpointer)_("user@company.com"));
483 return table;
486 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
487 #ifdef HAVE_VV
489 static void
490 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER int signum)
492 capture_pipeline("PURPLE_SIPE_PIPELINE");
495 static gboolean sipe_purple_initiate_media(PurpleAccount *account, const char *who,
496 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type)
498 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
499 who,
500 (type & PURPLE_MEDIA_VIDEO));
501 return TRUE;
504 static PurpleMediaCaps sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount *account,
505 SIPE_UNUSED_PARAMETER const char *who)
507 return PURPLE_MEDIA_CAPS_AUDIO
508 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
509 | PURPLE_MEDIA_CAPS_MODIFY_SESSION;
511 #endif
512 #endif
513 #endif
516 * Simplistic source upward compatibility path for newer libpurple APIs
518 * Usually we compile with -Werror=missing-field-initializers if GCC supports
519 * it. But that means that the compilation of this structure can fail if the
520 * newer API has added additional plugin callbacks. For the benefit of the
521 * user we downgrade it to a warning here.
523 * Diagnostic #pragma was added in GCC 4.2.0
524 * Diagnostic push/pop was added in GCC 4.6.0
526 #ifdef __GNUC__
527 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 2)
528 #if __GNUC_MINOR__ >= 6
529 #pragma GCC diagnostic push
530 #endif
531 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
532 #endif
533 #endif
534 static PurplePluginProtocolInfo sipe_prpl_info =
536 #if PURPLE_VERSION_CHECK(3,0,0)
537 sizeof(PurplePluginProtocolInfo), /* struct_size */
538 #endif
539 OPT_PROTO_CHAT_TOPIC |
540 OPT_PROTO_PASSWORD_OPTIONAL,
541 NULL, /* user_splits */
542 NULL, /* protocol_options */
543 NO_BUDDY_ICONS, /* icon_spec */
544 sipe_list_icon, /* list_icon */
545 NULL, /* list_emblems */
546 sipe_purple_status_text, /* status_text */
547 sipe_purple_tooltip_text, /* tooltip_text */ // add custom info to contact tooltip
548 sipe_purple_status_types, /* away_states */
549 sipe_purple_blist_node_menu, /* blist_node_menu */
550 sipe_purple_chat_info, /* chat_info */
551 sipe_purple_chat_info_defaults, /* chat_info_defaults */
552 sipe_purple_login, /* login */
553 sipe_purple_close, /* close */
554 sipe_purple_send_im, /* send_im */
555 NULL, /* set_info */ // TODO maybe
556 sipe_purple_send_typing, /* send_typing */
557 sipe_purple_get_info, /* get_info */
558 sipe_purple_set_status, /* set_status */
559 sipe_purple_set_idle, /* set_idle */
560 NULL, /* change_passwd */
561 sipe_purple_add_buddy, /* add_buddy */
562 NULL, /* add_buddies */
563 sipe_purple_remove_buddy, /* remove_buddy */
564 NULL, /* remove_buddies */
565 sipe_purple_add_permit, /* add_permit */
566 sipe_purple_add_deny, /* add_deny */
567 sipe_purple_add_deny, /* rem_permit */
568 sipe_purple_add_permit, /* rem_deny */
569 NULL, /* set_permit_deny */
570 sipe_purple_chat_join, /* join_chat */
571 NULL, /* reject_chat */
572 NULL, /* get_chat_name */
573 sipe_purple_chat_invite, /* chat_invite */
574 sipe_purple_chat_leave, /* chat_leave */
575 NULL, /* chat_whisper */
576 sipe_purple_chat_send, /* chat_send */
577 sipe_purple_keep_alive, /* keepalive */
578 NULL, /* register_user */
579 NULL, /* get_cb_info */ // deprecated
580 #if !PURPLE_VERSION_CHECK(3,0,0)
581 NULL, /* get_cb_away */ // deprecated
582 #endif
583 sipe_purple_alias_buddy, /* alias_buddy */
584 sipe_purple_group_buddy, /* group_buddy */
585 sipe_purple_group_rename, /* rename_group */
586 NULL, /* buddy_free */
587 sipe_purple_convo_closed, /* convo_closed */
588 purple_normalize_nocase, /* normalize */
589 NULL, /* set_buddy_icon */
590 sipe_purple_group_remove, /* remove_group */
591 NULL, /* get_cb_real_name */ // TODO?
592 NULL, /* set_chat_topic */
593 NULL, /* find_blist_chat */
594 sipe_purple_roomlist_get_list, /* roomlist_get_list */
595 sipe_purple_roomlist_cancel, /* roomlist_cancel */
596 NULL, /* roomlist_expand_category */
597 NULL, /* can_receive_file */
598 sipe_purple_ft_send_file, /* send_file */
599 sipe_purple_ft_new_xfer, /* new_xfer */
600 NULL, /* offline_message */
601 NULL, /* whiteboard_prpl_ops */
602 NULL, /* send_raw */
603 NULL, /* roomlist_room_serialize */
604 NULL, /* unregister_user */
605 NULL, /* send_attention */
606 NULL, /* get_attention_types */
607 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
608 /* Backward compatibility when compiling against 2.4.x API */
609 (void (*)(void)) /* _purple_reserved4 */
610 #endif
611 #if !PURPLE_VERSION_CHECK(3,0,0)
612 sizeof(PurplePluginProtocolInfo), /* struct_size */
613 #endif
614 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
615 sipe_purple_get_account_text_table, /* get_account_text_table */
616 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
617 #ifdef HAVE_VV
618 sipe_purple_initiate_media, /* initiate_media */
619 sipe_purple_get_media_caps, /* get_media_caps */
620 #else
621 NULL, /* initiate_media */
622 NULL, /* get_media_caps */
623 #endif
624 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
625 NULL, /* get_moods */
626 NULL, /* set_public_alias */
627 NULL, /* get_public_alias */
628 #if PURPLE_VERSION_CHECK(2,8,0)
629 NULL, /* add_buddy_with_invite */
630 NULL, /* add_buddies_with_invite */
631 #endif
632 #endif
633 #endif
634 #endif
636 #ifdef __GNUC__
637 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 6)
638 #pragma GCC diagnostic pop
639 #endif
640 #endif
641 /* Original GCC error checking restored from here on... (see above) */
643 /* PurplePluginInfo function calls & data structure */
644 static gboolean sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
646 #ifdef HAVE_VV
647 struct sigaction action;
648 memset(&action, 0, sizeof (action));
649 action.sa_handler = sipe_purple_sigusr1_handler;
650 sigaction(SIGUSR1, &action, NULL);
651 #endif
652 return TRUE;
655 static gboolean sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
657 #ifdef HAVE_VV
658 struct sigaction action;
659 memset(&action, 0, sizeof (action));
660 action.sa_handler = SIG_DFL;
661 sigaction(SIGUSR1, &action, NULL);
662 #endif
663 return TRUE;
666 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
668 GList *entry;
670 sipe_purple_activity_shutdown();
671 sipe_core_destroy();
673 entry = sipe_prpl_info.protocol_options;
674 while (entry) {
675 purple_account_option_destroy(entry->data);
676 entry = g_list_delete_link(entry, entry);
678 sipe_prpl_info.protocol_options = NULL;
680 entry = sipe_prpl_info.user_splits;
681 while (entry) {
682 purple_account_user_split_destroy(entry->data);
683 entry = g_list_delete_link(entry, entry);
685 sipe_prpl_info.user_splits = NULL;
688 static void sipe_purple_show_about_plugin(PurplePluginAction *action)
690 gchar *tmp = sipe_core_about();
691 purple_notify_formatted((PurpleConnection *) action->context,
692 NULL, " ", NULL, tmp, NULL, NULL);
693 g_free(tmp);
696 static void sipe_purple_find_contact_cb(PurpleConnection *gc,
697 PurpleRequestFields *fields)
699 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
700 const gchar *given_name = NULL;
701 const gchar *surname = NULL;
702 const gchar *email = NULL;
703 const gchar *company = NULL;
704 const gchar *country = NULL;
706 while (entries) {
707 PurpleRequestField *field = entries->data;
708 const char *id = purple_request_field_get_id(field);
709 const char *value = purple_request_field_string_get_value(field);
711 SIPE_DEBUG_INFO("sipe_purple_find_contact_cb: %s = '%s'", id, value ? value : "");
713 if (value) {
714 if (strcmp(id, "given") == 0) {
715 given_name = value;
716 } else if (strcmp(id, "surname") == 0) {
717 surname = value;
718 } else if (strcmp(id, "email") == 0) {
719 email = value;
720 } else if (strcmp(id, "company") == 0) {
721 company = value;
722 } else if (strcmp(id, "country") == 0) {
723 country = value;
727 entries = g_list_next(entries);
730 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
731 NULL,
732 given_name,
733 surname,
734 email,
735 company,
736 country);
739 static void sipe_purple_show_find_contact(PurplePluginAction *action)
741 PurpleConnection *gc = (PurpleConnection *) action->context;
742 PurpleRequestFields *fields;
743 PurpleRequestFieldGroup *group;
744 PurpleRequestField *field;
746 fields = purple_request_fields_new();
747 group = purple_request_field_group_new(NULL);
748 purple_request_fields_add_group(fields, group);
750 field = purple_request_field_string_new("given", _("First name"), NULL, FALSE);
751 purple_request_field_group_add_field(group, field);
752 field = purple_request_field_string_new("surname", _("Last name"), NULL, FALSE);
753 purple_request_field_group_add_field(group, field);
754 field = purple_request_field_string_new("email", _("Email"), NULL, FALSE);
755 purple_request_field_group_add_field(group, field);
756 field = purple_request_field_string_new("company", _("Company"), NULL, FALSE);
757 purple_request_field_group_add_field(group, field);
758 field = purple_request_field_string_new("country", _("Country"), NULL, FALSE);
759 purple_request_field_group_add_field(group, field);
761 purple_request_fields(gc,
762 _("Search"),
763 _("Search for a contact"),
764 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
765 fields,
766 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb),
767 _("_Cancel"), NULL,
768 purple_connection_get_account(gc), NULL, NULL, gc);
771 static void sipe_purple_join_conference_cb(PurpleConnection *gc,
772 PurpleRequestFields *fields)
774 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
776 if (entries) {
777 PurpleRequestField *field = entries->data;
778 const char *id = purple_request_field_get_id(field);
779 const char *value = purple_request_field_string_get_value(field);
781 if (!sipe_strequal(id, "meetingLocation"))
782 return;
784 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC, value);
788 #ifdef HAVE_VV
789 static void sipe_purple_test_call(PurplePluginAction *action)
791 PurpleConnection *gc = (PurpleConnection *) action->context;
792 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
794 #endif
796 static void sipe_purple_show_join_conference(PurplePluginAction *action)
798 PurpleConnection *gc = (PurpleConnection *) action->context;
799 PurpleRequestFields *fields;
800 PurpleRequestFieldGroup *group;
801 PurpleRequestField *field;
803 fields = purple_request_fields_new();
804 group = purple_request_field_group_new(NULL);
805 purple_request_fields_add_group(fields, group);
807 field = purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL, FALSE);
808 purple_request_field_group_add_field(group, field);
810 purple_request_fields(gc,
811 _("Join conference"),
812 _("Join scheduled conference"),
813 _("Enter meeting location string you received in the invitation.\n"
814 "\n"
815 "Valid location will be something like\n"
816 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
817 "or\n"
818 "https://meet.company.com/someone/abcdef1234"),
819 fields,
820 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb),
821 _("_Cancel"), NULL,
822 purple_connection_get_account(gc), NULL, NULL, gc);
825 static void sipe_purple_republish_calendar(PurplePluginAction *action)
827 PurpleConnection *gc = (PurpleConnection *) action->context;
828 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
831 static void sipe_purple_reset_status(PurplePluginAction *action)
833 PurpleConnection *gc = (PurpleConnection *) action->context;
834 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
837 static GList *sipe_purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin *plugin,
838 SIPE_UNUSED_PARAMETER gpointer context)
840 GList *menu = NULL;
841 PurplePluginAction *act;
843 act = purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin);
844 menu = g_list_prepend(menu, act);
846 act = purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact);
847 menu = g_list_prepend(menu, act);
849 #ifdef HAVE_VV
850 act = purple_plugin_action_new(_("Test call"), sipe_purple_test_call);
851 menu = g_list_prepend(menu, act);
852 #endif
854 act = purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference);
855 menu = g_list_prepend(menu, act);
857 act = purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar);
858 menu = g_list_prepend(menu, act);
860 act = purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status);
861 menu = g_list_prepend(menu, act);
863 return g_list_reverse(menu);
866 static PurplePluginInfo sipe_purple_info = {
867 PURPLE_PLUGIN_MAGIC,
868 PURPLE_MAJOR_VERSION,
869 PURPLE_MINOR_VERSION,
870 PURPLE_PLUGIN_PROTOCOL, /**< type */
871 NULL, /**< ui_requirement */
872 0, /**< flags */
873 NULL, /**< dependencies */
874 PURPLE_PRIORITY_DEFAULT, /**< priority */
875 "prpl-sipe", /**< id */
876 "Office Communicator", /**< name */
877 PACKAGE_VERSION, /**< version */
878 "Microsoft Office Communicator Protocol Plugin", /**< summary */
879 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
880 "Microsoft Live/Office Communications Server (LCS2005/OCS2007+)", /**< description */
881 "Anibal Avelar <avelar@gmail.com>, " /**< author */
882 "Gabriel Burt <gburt@novell.com>, " /**< author */
883 "Stefan Becker <stefan.becker@nokia.com>, " /**< author */
884 "pier11 <pier11@operamail.com>", /**< author */
885 PACKAGE_URL, /**< homepage */
886 sipe_purple_plugin_load, /**< load */
887 sipe_purple_plugin_unload, /**< unload */
888 sipe_purple_plugin_destroy, /**< destroy */
889 NULL, /**< ui_info */
890 &sipe_prpl_info, /**< extra_info */
891 NULL,
892 sipe_purple_actions,
893 NULL,
894 NULL,
895 NULL,
896 NULL
899 static void sipe_purple_init_plugin(PurplePlugin *plugin)
901 PurpleAccountUserSplit *split;
902 PurpleAccountOption *option;
904 /* This needs to be called first */
905 sipe_core_init(LOCALEDIR);
906 sipe_purple_activity_init();
908 purple_plugin_register(plugin);
911 * When adding new string settings please make sure to keep these
912 * in sync:
914 * api/sipe-backend.h
915 * purple-settings.c:setting_name[]
917 split = purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL, ',');
918 purple_account_user_split_set_reverse(split, FALSE);
919 sipe_prpl_info.user_splits = g_list_append(sipe_prpl_info.user_splits, split);
921 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
922 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
924 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
925 purple_account_option_add_list_item(option, _("Auto"), "auto");
926 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
927 purple_account_option_add_list_item(option, _("TCP"), "tcp");
928 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
930 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
931 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
933 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
934 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
936 option = purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL);
937 purple_account_option_add_list_item(option, _("NTLM"), "ntlm");
938 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
939 purple_account_option_add_list_item(option, _("Kerberos"), "krb5");
940 #endif
941 #ifndef HAVE_SSPI
942 /* see above */
943 purple_account_option_add_list_item(option, _("TLS-DSK"), "tls-dsk");
944 #endif
945 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
947 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
948 /* Suitable for sspi/NTLM, sspi/Kerberos and krb5 security mechanisms
949 * No login/password is taken into account if this option present,
950 * instead used default credentials stored in OS.
952 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", TRUE);
953 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
954 #endif
956 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
957 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
959 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
960 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
962 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
963 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
965 /** Example (Exchange): DOMAIN\user or user@company.com
966 * Example (Domino) : email_address
968 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
969 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
971 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
972 purple_account_option_set_masked(option, TRUE);
973 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
975 /** Example (federated domain): company.com (i.e. ocschat@company.com)
976 * Example (non-default user): user@company.com
978 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", "");
979 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
982 /* This macro makes the code a purple plugin */
983 PURPLE_INIT_PLUGIN(sipe, sipe_purple_init_plugin, sipe_purple_info);
986 Local Variables:
987 mode: c
988 c-file-style: "bsd"
989 indent-tabs-mode: t
990 tab-width: 8
991 End: