media: set "In a call" status when media call is in progress
[siplcs.git] / src / purple / purple-plugin.c
blob9b264c10af85b84585a75cf146d2dc257aa24803
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 /* Away */
202 /* Goes first in the list as
203 * purple picks the first status with the AWAY type
204 * for idle.
206 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
207 NULL,
208 NULL,
209 TRUE);
211 /* Be Right Back */
212 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
213 sipe_purple_activity_to_token(SIPE_ACTIVITY_BRB),
214 sipe_core_activity_description(SIPE_ACTIVITY_BRB),
215 TRUE);
217 /* Appear Offline */
218 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE,
219 NULL,
220 NULL,
221 TRUE);
223 /* Offline */
224 type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
225 NULL,
226 NULL,
227 TRUE);
228 types = g_list_append(types, type);
230 return types;
233 static GList *sipe_purple_blist_node_menu(PurpleBlistNode *node)
235 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) {
236 return sipe_purple_buddy_menu((PurpleBuddy *) node);
237 } else if(PURPLE_BLIST_NODE_IS_CHAT(node)) {
238 return sipe_purple_chat_menu((PurpleChat *)node);
239 } else {
240 return NULL;
244 static void sipe_purple_login(PurpleAccount *account)
246 PurpleConnection *gc = purple_account_get_connection(account);
247 const gchar *username = purple_account_get_username(account);
248 const gchar *email = purple_account_get_string(account, "email", NULL);
249 const gchar *email_url = purple_account_get_string(account, "email_url", NULL);
250 const gchar *transport = purple_account_get_string(account, "transport", "auto");
251 const gchar *auth = purple_account_get_string(account, "authentication", "ntlm");
252 struct sipe_core_public *sipe_public;
253 gchar **username_split;
254 gchar *login_domain = NULL;
255 gchar *login_account = NULL;
256 const gchar *errmsg;
257 guint type;
258 struct sipe_backend_private *purple_private;
260 /* username format: <username>,[<optional login>] */
261 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username);
262 username_split = g_strsplit(username, ",", 2);
264 /* login name specified? */
265 if (username_split[1] && strlen(username_split[1])) {
266 /* Allowed domain-account separators are / or \ */
267 gchar **domain_user = g_strsplit_set(username_split[1], "/\\", 2);
268 gboolean has_domain = domain_user[1] != NULL;
269 SIPE_DEBUG_INFO("sipe_purple_login: login '%s'", username_split[1]);
270 login_domain = has_domain ? g_strdup(domain_user[0]) : NULL;
271 login_account = g_strdup(domain_user[has_domain ? 1 : 0]);
272 SIPE_DEBUG_INFO("sipe_purple_login: auth domain '%s' user '%s'",
273 login_domain ? login_domain : "",
274 login_account);
275 g_strfreev(domain_user);
278 sipe_public = sipe_core_allocate(username_split[0],
279 login_domain, login_account,
280 purple_connection_get_password(gc),
281 email,
282 email_url,
283 &errmsg);
284 g_free(login_domain);
285 g_free(login_account);
286 g_strfreev(username_split);
288 if (!sipe_public) {
289 #if PURPLE_VERSION_CHECK(3,0,0)
290 purple_connection_error(
291 #else
292 purple_connection_error_reason(
293 #endif
295 PURPLE_CONNECTION_ERROR_INVALID_USERNAME,
296 errmsg);
297 return;
300 sipe_public->backend_private = purple_private = g_new0(struct sipe_backend_private, 1);
301 purple_private->public = sipe_public;
302 purple_private->gc = gc;
303 purple_private->account = account;
305 sipe_purple_chat_setup_rejoin(purple_private);
307 /* map option list to flags - default is NTLM */
308 SIPE_CORE_FLAG_UNSET(KRB5);
309 SIPE_CORE_FLAG_UNSET(TLS_DSK);
310 SIPE_CORE_FLAG_UNSET(SSO);
311 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
312 if (sipe_strequal(auth, "krb5")) {
313 SIPE_CORE_FLAG_SET(KRB5);
314 } else
315 #endif
316 #ifndef HAVE_SSPI
318 * @TODO: SSL handshake support isn't implemented in sip-sec-sspi.c.
319 * So ignore configuration setting for now.
321 if (sipe_strequal(auth, "tls-dsk")) {
322 SIPE_CORE_FLAG_SET(TLS_DSK);
324 #endif
326 /* @TODO: is this correct?
327 "sso" is only available when Kerberos/SSPI support is compiled in */
328 if (purple_account_get_bool(account, "sso", TRUE))
329 SIPE_CORE_FLAG_SET(SSO);
331 gc->proto_data = sipe_public;
332 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_FORMATTING_WBFO | PURPLE_CONNECTION_NO_BGCOLOR |
333 PURPLE_CONNECTION_NO_FONTSIZE | PURPLE_CONNECTION_NO_URLDESC | PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY;
334 purple_connection_set_display_name(gc, sipe_public->sip_name);
335 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
337 username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2);
338 if (sipe_strequal(transport, "auto")) {
339 type = (username_split[0] == NULL) ?
340 SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS;
341 } else if (sipe_strequal(transport, "tls")) {
342 type = SIPE_TRANSPORT_TLS;
343 } else {
344 type = SIPE_TRANSPORT_TCP;
346 sipe_core_transport_sip_connect(sipe_public,
347 type,
348 username_split[0],
349 username_split[0] ? username_split[1] : NULL);
350 g_strfreev(username_split);
353 static void sipe_purple_close(PurpleConnection *gc)
355 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
357 if (sipe_public) {
358 struct sipe_backend_private *purple_private = sipe_public->backend_private;
360 sipe_core_deallocate(sipe_public);
362 if (purple_private->roomlist_map)
363 g_hash_table_destroy(purple_private->roomlist_map);
364 sipe_purple_chat_destroy_rejoin(purple_private);
365 g_free(purple_private);
366 gc->proto_data = NULL;
370 static int sipe_purple_send_im(PurpleConnection *gc,
371 const char *who,
372 const char *what,
373 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags)
375 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who, what);
376 return 1;
379 #define SIPE_TYPING_SEND_TIMEOUT 4
381 static unsigned int sipe_purple_send_typing(PurpleConnection *gc,
382 const char *who,
383 PurpleTypingState state)
385 if (state == PURPLE_NOT_TYPING)
386 return 0;
388 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
389 who);
391 return SIPE_TYPING_SEND_TIMEOUT;
394 static void sipe_purple_get_info(PurpleConnection *gc, const char *who)
396 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
397 who);
400 static void sipe_purple_add_permit(PurpleConnection *gc, const char *name)
402 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE);
405 static void sipe_purple_add_deny(PurpleConnection *gc, const char *name)
407 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, FALSE);
410 static void sipe_purple_keep_alive(PurpleConnection *gc)
412 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
413 struct sipe_backend_private *purple_private = sipe_public->backend_private;
414 time_t now = time(NULL);
416 if ((sipe_public->keepalive_timeout > 0) &&
417 ((guint) (now - purple_private->last_keepalive) >= sipe_public->keepalive_timeout) &&
418 ((guint) (now - gc->last_received) >= sipe_public->keepalive_timeout)
420 sipe_core_transport_sip_keepalive(sipe_public);
421 purple_private->last_keepalive = now;
425 static void sipe_purple_alias_buddy(PurpleConnection *gc, const char *name,
426 SIPE_UNUSED_PARAMETER const char *alias)
428 sipe_core_group_set_user(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name);
431 static void sipe_purple_group_rename(PurpleConnection *gc,
432 const char *old_name,
433 PurpleGroup *group,
434 SIPE_UNUSED_PARAMETER GList *moved_buddies)
436 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC, old_name, group->name);
439 static void sipe_purple_convo_closed(PurpleConnection *gc,
440 const char *who)
442 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who);
445 static void sipe_purple_group_remove(PurpleConnection *gc, PurpleGroup *group)
447 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC, group->name);
450 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
451 static GHashTable *
452 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount *account)
454 GHashTable *table;
455 table = g_hash_table_new(g_str_hash, g_str_equal);
456 g_hash_table_insert(table, "login_label", (gpointer)_("user@company.com"));
457 return table;
460 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
461 #ifdef HAVE_VV
463 static void
464 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER int signum)
466 capture_pipeline("PURPLE_SIPE_PIPELINE");
469 static gboolean sipe_purple_initiate_media(PurpleAccount *account, const char *who,
470 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type)
472 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
473 who,
474 (type & PURPLE_MEDIA_VIDEO));
475 return TRUE;
478 static PurpleMediaCaps sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount *account,
479 SIPE_UNUSED_PARAMETER const char *who)
481 return PURPLE_MEDIA_CAPS_AUDIO
482 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
483 | PURPLE_MEDIA_CAPS_MODIFY_SESSION;
485 #endif
486 #endif
487 #endif
490 * Simplistic source upward compatibility path for newer libpurple APIs
492 * Usually we compile with -Werror=missing-field-initializers if GCC supports
493 * it. But that means that the compilation of this structure can fail if the
494 * newer API has added additional plugin callbacks. For the benefit of the
495 * user we downgrade it to a warning here.
497 * Diagnostic #pragma was added in GCC 4.2.0
498 * Diagnostic push/pop was added in GCC 4.6.0
500 #ifdef __GNUC__
501 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 2)
502 #if __GNUC_MINOR__ >= 6
503 #pragma GCC diagnostic push
504 #endif
505 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
506 #endif
507 #endif
508 static PurplePluginProtocolInfo sipe_prpl_info =
510 #if PURPLE_VERSION_CHECK(3,0,0)
511 sizeof(PurplePluginProtocolInfo), /* struct_size */
512 #endif
513 OPT_PROTO_CHAT_TOPIC,
514 NULL, /* user_splits */
515 NULL, /* protocol_options */
516 NO_BUDDY_ICONS, /* icon_spec */
517 sipe_list_icon, /* list_icon */
518 NULL, /* list_emblems */
519 sipe_purple_status_text, /* status_text */
520 sipe_purple_tooltip_text, /* tooltip_text */ // add custom info to contact tooltip
521 sipe_purple_status_types, /* away_states */
522 sipe_purple_blist_node_menu, /* blist_node_menu */
523 sipe_purple_chat_info, /* chat_info */
524 sipe_purple_chat_info_defaults, /* chat_info_defaults */
525 sipe_purple_login, /* login */
526 sipe_purple_close, /* close */
527 sipe_purple_send_im, /* send_im */
528 NULL, /* set_info */ // TODO maybe
529 sipe_purple_send_typing, /* send_typing */
530 sipe_purple_get_info, /* get_info */
531 sipe_purple_set_status, /* set_status */
532 sipe_purple_set_idle, /* set_idle */
533 NULL, /* change_passwd */
534 sipe_purple_add_buddy, /* add_buddy */
535 NULL, /* add_buddies */
536 sipe_purple_remove_buddy, /* remove_buddy */
537 NULL, /* remove_buddies */
538 sipe_purple_add_permit, /* add_permit */
539 sipe_purple_add_deny, /* add_deny */
540 sipe_purple_add_deny, /* rem_permit */
541 sipe_purple_add_permit, /* rem_deny */
542 NULL, /* set_permit_deny */
543 sipe_purple_chat_join, /* join_chat */
544 NULL, /* reject_chat */
545 NULL, /* get_chat_name */
546 sipe_purple_chat_invite, /* chat_invite */
547 sipe_purple_chat_leave, /* chat_leave */
548 NULL, /* chat_whisper */
549 sipe_purple_chat_send, /* chat_send */
550 sipe_purple_keep_alive, /* keepalive */
551 NULL, /* register_user */
552 NULL, /* get_cb_info */ // deprecated
553 #if !PURPLE_VERSION_CHECK(3,0,0)
554 NULL, /* get_cb_away */ // deprecated
555 #endif
556 sipe_purple_alias_buddy, /* alias_buddy */
557 sipe_purple_group_buddy, /* group_buddy */
558 sipe_purple_group_rename, /* rename_group */
559 NULL, /* buddy_free */
560 sipe_purple_convo_closed, /* convo_closed */
561 purple_normalize_nocase, /* normalize */
562 NULL, /* set_buddy_icon */
563 sipe_purple_group_remove, /* remove_group */
564 NULL, /* get_cb_real_name */ // TODO?
565 NULL, /* set_chat_topic */
566 NULL, /* find_blist_chat */
567 sipe_purple_roomlist_get_list, /* roomlist_get_list */
568 sipe_purple_roomlist_cancel, /* roomlist_cancel */
569 NULL, /* roomlist_expand_category */
570 NULL, /* can_receive_file */
571 sipe_purple_ft_send_file, /* send_file */
572 sipe_purple_ft_new_xfer, /* new_xfer */
573 NULL, /* offline_message */
574 NULL, /* whiteboard_prpl_ops */
575 NULL, /* send_raw */
576 NULL, /* roomlist_room_serialize */
577 NULL, /* unregister_user */
578 NULL, /* send_attention */
579 NULL, /* get_attention_types */
580 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
581 /* Backward compatibility when compiling against 2.4.x API */
582 (void (*)(void)) /* _purple_reserved4 */
583 #endif
584 #if !PURPLE_VERSION_CHECK(3,0,0)
585 sizeof(PurplePluginProtocolInfo), /* struct_size */
586 #endif
587 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
588 sipe_purple_get_account_text_table, /* get_account_text_table */
589 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
590 #ifdef HAVE_VV
591 sipe_purple_initiate_media, /* initiate_media */
592 sipe_purple_get_media_caps, /* get_media_caps */
593 #else
594 NULL, /* initiate_media */
595 NULL, /* get_media_caps */
596 #endif
597 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
598 NULL, /* get_moods */
599 NULL, /* set_public_alias */
600 NULL, /* get_public_alias */
601 #if PURPLE_VERSION_CHECK(2,8,0)
602 NULL, /* add_buddy_with_invite */
603 NULL, /* add_buddies_with_invite */
604 #endif
605 #endif
606 #endif
607 #endif
609 #ifdef __GNUC__
610 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 6)
611 #pragma GCC diagnostic pop
612 #endif
613 #endif
614 /* Original GCC error checking restored from here on... (see above) */
616 /* PurplePluginInfo function calls & data structure */
617 static gboolean sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
619 #ifdef HAVE_VV
620 struct sigaction action;
621 memset(&action, 0, sizeof (action));
622 action.sa_handler = sipe_purple_sigusr1_handler;
623 sigaction(SIGUSR1, &action, NULL);
624 #endif
625 return TRUE;
628 static gboolean sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
630 #ifdef HAVE_VV
631 struct sigaction action;
632 memset(&action, 0, sizeof (action));
633 action.sa_handler = SIG_DFL;
634 sigaction(SIGUSR1, &action, NULL);
635 #endif
636 return TRUE;
639 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
641 GList *entry;
643 sipe_purple_activity_shutdown();
644 sipe_core_destroy();
646 entry = sipe_prpl_info.protocol_options;
647 while (entry) {
648 purple_account_option_destroy(entry->data);
649 entry = g_list_delete_link(entry, entry);
651 sipe_prpl_info.protocol_options = NULL;
653 entry = sipe_prpl_info.user_splits;
654 while (entry) {
655 purple_account_user_split_destroy(entry->data);
656 entry = g_list_delete_link(entry, entry);
658 sipe_prpl_info.user_splits = NULL;
661 static void sipe_purple_show_about_plugin(PurplePluginAction *action)
663 gchar *tmp = sipe_core_about();
664 purple_notify_formatted((PurpleConnection *) action->context,
665 NULL, " ", NULL, tmp, NULL, NULL);
666 g_free(tmp);
669 static void sipe_purple_find_contact_cb(PurpleConnection *gc,
670 PurpleRequestFields *fields)
672 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
673 const gchar *given_name = NULL;
674 const gchar *surname = NULL;
675 const gchar *email = NULL;
676 const gchar *company = NULL;
677 const gchar *country = NULL;
679 while (entries) {
680 PurpleRequestField *field = entries->data;
681 const char *id = purple_request_field_get_id(field);
682 const char *value = purple_request_field_string_get_value(field);
684 SIPE_DEBUG_INFO("sipe_purple_find_contact_cb: %s = '%s'", id, value ? value : "");
686 if (value) {
687 if (strcmp(id, "given") == 0) {
688 given_name = value;
689 } else if (strcmp(id, "surname") == 0) {
690 surname = value;
691 } else if (strcmp(id, "email") == 0) {
692 email = value;
693 } else if (strcmp(id, "company") == 0) {
694 company = value;
695 } else if (strcmp(id, "country") == 0) {
696 country = value;
700 entries = g_list_next(entries);
703 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
704 given_name,
705 surname,
706 email,
707 company,
708 country);
711 static void sipe_purple_show_find_contact(PurplePluginAction *action)
713 PurpleConnection *gc = (PurpleConnection *) action->context;
714 PurpleRequestFields *fields;
715 PurpleRequestFieldGroup *group;
716 PurpleRequestField *field;
718 fields = purple_request_fields_new();
719 group = purple_request_field_group_new(NULL);
720 purple_request_fields_add_group(fields, group);
722 field = purple_request_field_string_new("given", _("First name"), NULL, FALSE);
723 purple_request_field_group_add_field(group, field);
724 field = purple_request_field_string_new("surname", _("Last name"), NULL, FALSE);
725 purple_request_field_group_add_field(group, field);
726 field = purple_request_field_string_new("email", _("Email"), NULL, FALSE);
727 purple_request_field_group_add_field(group, field);
728 field = purple_request_field_string_new("company", _("Company"), NULL, FALSE);
729 purple_request_field_group_add_field(group, field);
730 field = purple_request_field_string_new("country", _("Country"), NULL, FALSE);
731 purple_request_field_group_add_field(group, field);
733 purple_request_fields(gc,
734 _("Search"),
735 _("Search for a contact"),
736 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
737 fields,
738 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb),
739 _("_Cancel"), NULL,
740 purple_connection_get_account(gc), NULL, NULL, gc);
743 static void sipe_purple_join_conference_cb(PurpleConnection *gc,
744 PurpleRequestFields *fields)
746 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
748 if (entries) {
749 PurpleRequestField *field = entries->data;
750 const char *id = purple_request_field_get_id(field);
751 const char *value = purple_request_field_string_get_value(field);
753 if (!sipe_strequal(id, "meetingLocation"))
754 return;
756 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC, value);
760 #ifdef HAVE_VV
761 static void sipe_purple_test_call(PurplePluginAction *action)
763 PurpleConnection *gc = (PurpleConnection *) action->context;
764 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
766 #endif
768 static void sipe_purple_show_join_conference(PurplePluginAction *action)
770 PurpleConnection *gc = (PurpleConnection *) action->context;
771 PurpleRequestFields *fields;
772 PurpleRequestFieldGroup *group;
773 PurpleRequestField *field;
775 fields = purple_request_fields_new();
776 group = purple_request_field_group_new(NULL);
777 purple_request_fields_add_group(fields, group);
779 field = purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL, FALSE);
780 purple_request_field_group_add_field(group, field);
782 purple_request_fields(gc,
783 _("Join conference"),
784 _("Join scheduled conference"),
785 _("Enter meeting location string you received in the invitation.\n"
786 "\n"
787 "Valid location will be something like\n"
788 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
789 "or\n"
790 "https://meet.company.com/someone/abcdef1234"),
791 fields,
792 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb),
793 _("_Cancel"), NULL,
794 purple_connection_get_account(gc), NULL, NULL, gc);
797 static void sipe_purple_republish_calendar(PurplePluginAction *action)
799 PurpleConnection *gc = (PurpleConnection *) action->context;
800 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
803 static void sipe_purple_reset_status(PurplePluginAction *action)
805 PurpleConnection *gc = (PurpleConnection *) action->context;
806 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
809 static GList *sipe_purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin *plugin,
810 SIPE_UNUSED_PARAMETER gpointer context)
812 GList *menu = NULL;
813 PurplePluginAction *act;
815 act = purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin);
816 menu = g_list_prepend(menu, act);
818 act = purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact);
819 menu = g_list_prepend(menu, act);
821 #ifdef HAVE_VV
822 act = purple_plugin_action_new(_("Test call"), sipe_purple_test_call);
823 menu = g_list_prepend(menu, act);
824 #endif
826 act = purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference);
827 menu = g_list_prepend(menu, act);
829 act = purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar);
830 menu = g_list_prepend(menu, act);
832 act = purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status);
833 menu = g_list_prepend(menu, act);
835 return g_list_reverse(menu);
838 static PurplePluginInfo sipe_purple_info = {
839 PURPLE_PLUGIN_MAGIC,
840 PURPLE_MAJOR_VERSION,
841 PURPLE_MINOR_VERSION,
842 PURPLE_PLUGIN_PROTOCOL, /**< type */
843 NULL, /**< ui_requirement */
844 0, /**< flags */
845 NULL, /**< dependencies */
846 PURPLE_PRIORITY_DEFAULT, /**< priority */
847 "prpl-sipe", /**< id */
848 "Office Communicator", /**< name */
849 PACKAGE_VERSION, /**< version */
850 "Microsoft Office Communicator Protocol Plugin", /**< summary */
851 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
852 "Microsoft Live/Office Communications Server (LCS2005/OCS2007+)", /**< description */
853 "Anibal Avelar <avelar@gmail.com>, " /**< author */
854 "Gabriel Burt <gburt@novell.com>, " /**< author */
855 "Stefan Becker <stefan.becker@nokia.com>, " /**< author */
856 "pier11 <pier11@operamail.com>", /**< author */
857 PACKAGE_URL, /**< homepage */
858 sipe_purple_plugin_load, /**< load */
859 sipe_purple_plugin_unload, /**< unload */
860 sipe_purple_plugin_destroy, /**< destroy */
861 NULL, /**< ui_info */
862 &sipe_prpl_info, /**< extra_info */
863 NULL,
864 sipe_purple_actions,
865 NULL,
866 NULL,
867 NULL,
868 NULL
871 static void sipe_purple_init_plugin(PurplePlugin *plugin)
873 PurpleAccountUserSplit *split;
874 PurpleAccountOption *option;
876 /* This needs to be called first */
877 sipe_core_init(LOCALEDIR);
878 sipe_purple_activity_init();
880 purple_plugin_register(plugin);
883 * When adding new string settings please make sure to keep these
884 * in sync:
886 * api/sipe-backend.h
887 * purple-settings.c:setting_name[]
889 split = purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL, ',');
890 purple_account_user_split_set_reverse(split, FALSE);
891 sipe_prpl_info.user_splits = g_list_append(sipe_prpl_info.user_splits, split);
893 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
894 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
896 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
897 purple_account_option_add_list_item(option, _("Auto"), "auto");
898 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
899 purple_account_option_add_list_item(option, _("TCP"), "tcp");
900 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
902 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
903 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
905 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
906 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
908 option = purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL);
909 purple_account_option_add_list_item(option, _("NTLM"), "ntlm");
910 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
911 purple_account_option_add_list_item(option, _("Kerberos"), "krb5");
912 #endif
913 #ifndef HAVE_SSPI
914 /* see above */
915 purple_account_option_add_list_item(option, _("TLS-DSK"), "tls-dsk");
916 #endif
917 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
919 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
920 /* Suitable for sspi/NTLM, sspi/Kerberos and krb5 security mechanisms
921 * No login/password is taken into account if this option present,
922 * instead used default credentials stored in OS.
924 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", TRUE);
925 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
926 #endif
928 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
929 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
931 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
932 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
934 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
935 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
937 /** Example (Exchange): DOMAIN\user or user@company.com
938 * Example (Domino) : email_address
940 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
941 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
943 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
944 purple_account_option_set_masked(option, TRUE);
945 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
947 /** Example (federated domain): company.com (i.e. ocschat@company.com)
948 * Example (non-default user): user@company.com
950 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", "");
951 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
954 /* This macro makes the code a purple plugin */
955 PURPLE_INIT_PLUGIN(sipe, sipe_purple_init_plugin, sipe_purple_info);
958 Local Variables:
959 mode: c
960 c-file-style: "bsd"
961 indent-tabs-mode: t
962 tab-width: 8
963 End: