core cleanup: separate code for sipe_add_buddy()
[siplcs.git] / src / purple / purple-plugin.c
blob86af3618787c2690a5ecf24f2e2c15a46160c723
1 /**
2 * @file purple-plugin.c
4 * pidgin-sipe
6 * Copyright (C) 2010-11 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 #include "core-depurple.h"
72 #define _PurpleMessageFlags PurpleMessageFlags
73 #include "purple-private.h"
75 /* Backward compatibility when compiling against 2.4.x API */
76 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
77 #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100
78 #endif
80 /* Convenience macros */
81 #define PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC ((struct sipe_core_public *) buddy->account->gc->proto_data)
83 /* Status attributes (see also sipe_status_types() */
84 #define SIPE_STATUS_ATTR_ID_MESSAGE "message"
86 /* Sipe core activity <-> Purple status mapping */
87 static const gchar * const activity_to_purple[SIPE_ACTIVITY_NUM_TYPES] = {
88 /* SIPE_ACTIVITY_UNSET */ "unset",
89 /* SIPE_ACTIVITY_ONLINE */ "online",
90 /* SIPE_ACTIVITY_INACTIVE */ "idle",
91 /* SIPE_ACTIVITY_BUSY */ "busy",
92 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
93 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
94 /* SIPE_ACTIVITY_BRB */ "be-right-back",
95 /* SIPE_ACTIVITY_AWAY */ "away",
96 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
97 /* SIPE_ACTIVITY_OFFLINE */ "offline",
98 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
99 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
100 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
101 /* SIPE_ACTIVITY_OOF */ "out-of-office",
102 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
104 GHashTable *purple_to_activity = NULL;
105 #define PURPLE_STATUS_TO_ACTIVITY(x) \
106 GPOINTER_TO_UINT(g_hash_table_lookup(purple_to_activity, (x)))
108 static void sipe_purple_activity_init(void)
110 sipe_activity index = SIPE_ACTIVITY_UNSET;
111 purple_to_activity = g_hash_table_new(g_str_hash, g_str_equal);
112 while (index < SIPE_ACTIVITY_NUM_TYPES) {
113 g_hash_table_insert(purple_to_activity,
114 (gpointer) activity_to_purple[index],
115 GUINT_TO_POINTER(index));
116 index++;
120 gchar *sipe_backend_version(void)
122 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
125 static void sipe_purple_activity_destroy(void)
127 g_hash_table_destroy(purple_to_activity);
128 purple_to_activity = NULL;
131 /* PurplePluginProtocolInfo function calls & data structure */
132 static const char *sipe_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount *a,
133 SIPE_UNUSED_PARAMETER PurpleBuddy *b)
135 return "sipe";
138 static gchar *sipe_purple_status_text(PurpleBuddy *buddy)
140 const PurpleStatus *status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
141 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
142 buddy->name,
143 PURPLE_STATUS_TO_ACTIVITY(purple_status_get_id(status)),
144 purple_status_get_name(status));
147 static void sipe_purple_tooltip_text(PurpleBuddy *buddy,
148 PurpleNotifyUserInfo *user_info,
149 SIPE_UNUSED_PARAMETER gboolean full)
151 const PurplePresence *presence = purple_buddy_get_presence(buddy);
152 GSList *info = sipe_core_buddy_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
153 buddy->name,
154 purple_status_get_name(purple_presence_get_active_status(presence)),
155 purple_presence_is_online(presence));
157 while (info) {
158 struct sipe_buddy_info *sbi = info->data;
159 #if PURPLE_VERSION_CHECK(3,0,0)
160 purple_notify_user_info_add_pair_html(
161 #else
162 purple_notify_user_info_add_pair(
163 #endif
164 user_info,
165 sbi->label, sbi->text);
166 g_free(sbi->text);
167 g_free(sbi);
168 info = g_slist_delete_link(info, info);
172 static GList *sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount *acc)
174 PurpleStatusType *type;
175 GList *types = NULL;
177 /* Macros to reduce code repetition.
178 Translators: noun */
179 #define SIPE_ADD_STATUS(prim,id,name,user) type = purple_status_type_new_with_attrs( \
180 prim, id, name, \
181 TRUE, user, FALSE, \
182 SIPE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
183 NULL); \
184 types = g_list_append(types, type);
186 /* Online */
187 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
188 NULL,
189 NULL,
190 TRUE);
192 /* Busy */
193 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
194 activity_to_purple[SIPE_ACTIVITY_BUSY],
195 _("Busy"),
196 TRUE);
198 /* Do Not Disturb */
199 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
200 activity_to_purple[SIPE_ACTIVITY_DND],
201 NULL,
202 TRUE);
204 /* Away */
205 /* Goes first in the list as
206 * purple picks the first status with the AWAY type
207 * for idle.
209 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
210 NULL,
211 NULL,
212 TRUE);
214 /* Be Right Back */
215 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
216 activity_to_purple[SIPE_ACTIVITY_BRB],
217 _("Be right back"),
218 TRUE);
220 /* Appear Offline */
221 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE,
222 NULL,
223 NULL,
224 TRUE);
226 /* Offline */
227 type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
228 NULL,
229 NULL,
230 TRUE);
231 types = g_list_append(types, type);
233 return types;
236 static GList *sipe_purple_blist_node_menu(PurpleBlistNode *node)
238 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) {
239 return sipe_buddy_menu((PurpleBuddy *) node);
240 } else if(PURPLE_BLIST_NODE_IS_CHAT(node)) {
241 return sipe_purple_chat_menu((PurpleChat *)node);
242 } else {
243 return NULL;
247 static void sipe_purple_login(PurpleAccount *account)
249 PurpleConnection *gc = purple_account_get_connection(account);
250 const gchar *username = purple_account_get_username(account);
251 const gchar *email = purple_account_get_string(account, "email", NULL);
252 const gchar *email_url = purple_account_get_string(account, "email_url", NULL);
253 const gchar *transport = purple_account_get_string(account, "transport", "auto");
254 const gchar *auth = purple_account_get_string(account, "authentication", "ntlm");
255 struct sipe_core_public *sipe_public;
256 gchar **username_split;
257 gchar *login_domain = NULL;
258 gchar *login_account = NULL;
259 const gchar *errmsg;
260 guint type;
261 struct sipe_backend_private *purple_private;
263 /* username format: <username>,[<optional login>] */
264 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username);
265 username_split = g_strsplit(username, ",", 2);
267 /* login name specified? */
268 if (username_split[1] && strlen(username_split[1])) {
269 /* Allowed domain-account separators are / or \ */
270 gchar **domain_user = g_strsplit_set(username_split[1], "/\\", 2);
271 gboolean has_domain = domain_user[1] != NULL;
272 SIPE_DEBUG_INFO("sipe_purple_login: login '%s'", username_split[1]);
273 login_domain = has_domain ? g_strdup(domain_user[0]) : NULL;
274 login_account = g_strdup(domain_user[has_domain ? 1 : 0]);
275 SIPE_DEBUG_INFO("sipe_purple_login: auth domain '%s' user '%s'",
276 login_domain ? login_domain : "",
277 login_account);
278 g_strfreev(domain_user);
281 sipe_public = sipe_core_allocate(username_split[0],
282 login_domain, login_account,
283 purple_connection_get_password(gc),
284 email,
285 email_url,
286 &errmsg);
287 g_free(login_domain);
288 g_free(login_account);
289 g_strfreev(username_split);
291 if (!sipe_public) {
292 #if PURPLE_VERSION_CHECK(3,0,0)
293 purple_connection_error(
294 #else
295 purple_connection_error_reason(
296 #endif
298 PURPLE_CONNECTION_ERROR_INVALID_USERNAME,
299 errmsg);
300 return;
303 sipe_public->backend_private = purple_private = g_new0(struct sipe_backend_private, 1);
304 purple_private->public = sipe_public;
305 purple_private->gc = gc;
306 purple_private->account = account;
308 sipe_purple_chat_setup_rejoin(purple_private);
310 /* map option list to flags - default is NTLM */
311 SIPE_CORE_FLAG_UNSET(KRB5);
312 SIPE_CORE_FLAG_UNSET(TLS_DSK);
313 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
314 if (sipe_strequal(auth, "krb5")) {
315 SIPE_CORE_FLAG_SET(KRB5);
316 } else
317 #endif
318 if (sipe_strequal(auth, "tls-dsk")) {
319 SIPE_CORE_FLAG_SET(TLS_DSK);
322 /* @TODO: is this correct?
323 "sso" is only available when Kerberos/SSPI support is compiled in */
324 if (purple_account_get_bool(account, "sso", TRUE))
325 SIPE_CORE_FLAG_SET(SSO);
327 gc->proto_data = sipe_public;
328 sipe_purple_setup(sipe_public, gc);
329 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_FORMATTING_WBFO | PURPLE_CONNECTION_NO_BGCOLOR |
330 PURPLE_CONNECTION_NO_FONTSIZE | PURPLE_CONNECTION_NO_URLDESC | PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY;
331 purple_connection_set_display_name(gc, sipe_public->sip_name);
332 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
334 username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2);
335 if (sipe_strequal(transport, "auto")) {
336 type = (username_split[0] == NULL) ?
337 SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS;
338 } else if (sipe_strequal(transport, "tls")) {
339 type = SIPE_TRANSPORT_TLS;
340 } else {
341 type = SIPE_TRANSPORT_TCP;
343 sipe_core_transport_sip_connect(sipe_public,
344 type,
345 username_split[0],
346 username_split[0] ? username_split[1] : NULL);
347 g_strfreev(username_split);
350 static void sipe_purple_close(PurpleConnection *gc)
352 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
354 if (sipe_public) {
355 struct sipe_backend_private *purple_private = sipe_public->backend_private;
357 sipe_core_deallocate(sipe_public);
359 if (purple_private->roomlist_map)
360 g_hash_table_destroy(purple_private->roomlist_map);
361 sipe_purple_chat_destroy_rejoin(purple_private);
362 g_free(purple_private);
363 gc->proto_data = NULL;
367 static int sipe_purple_send_im(PurpleConnection *gc,
368 const char *who,
369 const char *what,
370 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags)
372 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who, what);
373 return 1;
376 #define SIPE_TYPING_SEND_TIMEOUT 4
378 static unsigned int sipe_purple_send_typing(PurpleConnection *gc,
379 const char *who,
380 PurpleTypingState state)
382 if (state == PURPLE_NOT_TYPING)
383 return 0;
385 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
386 who);
388 return SIPE_TYPING_SEND_TIMEOUT;
391 static void sipe_purple_add_permit(PurpleConnection *gc, const char *name)
393 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE);
396 static void sipe_purple_add_deny(PurpleConnection *gc, const char *name)
398 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, FALSE);
401 static void sipe_purple_keep_alive(PurpleConnection *gc)
403 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
404 struct sipe_backend_private *purple_private = sipe_public->backend_private;
405 time_t now = time(NULL);
407 if ((sipe_public->keepalive_timeout > 0) &&
408 ((guint) (now - purple_private->last_keepalive) >= sipe_public->keepalive_timeout) &&
409 ((guint) (now - gc->last_received) >= sipe_public->keepalive_timeout)
411 sipe_core_transport_sip_keepalive(sipe_public);
412 purple_private->last_keepalive = now;
416 static void sipe_purple_alias_buddy(PurpleConnection *gc, const char *name,
417 SIPE_UNUSED_PARAMETER const char *alias)
419 sipe_core_group_set_user(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name);
422 static void sipe_purple_group_rename(PurpleConnection *gc,
423 const char *old_name,
424 PurpleGroup *group,
425 SIPE_UNUSED_PARAMETER GList *moved_buddies)
427 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC, old_name, group->name);
430 static void sipe_purple_group_remove(PurpleConnection *gc, PurpleGroup *group)
432 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC, group->name);
435 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
436 static GHashTable *
437 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount *account)
439 GHashTable *table;
440 table = g_hash_table_new(g_str_hash, g_str_equal);
441 g_hash_table_insert(table, "login_label", (gpointer)_("user@company.com"));
442 return table;
445 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
446 #ifdef HAVE_VV
448 extern void capture_pipeline(gchar *label);
450 static void
451 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER int signum)
453 capture_pipeline("PURPLE_SIPE_PIPELINE");
456 static gboolean sipe_purple_initiate_media(PurpleAccount *account, const char *who,
457 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type)
459 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
460 who,
461 (type & PURPLE_MEDIA_VIDEO));
462 return TRUE;
465 static PurpleMediaCaps sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount *account,
466 SIPE_UNUSED_PARAMETER const char *who)
468 return PURPLE_MEDIA_CAPS_AUDIO
469 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
470 | PURPLE_MEDIA_CAPS_MODIFY_SESSION;
472 #endif
473 #endif
474 #endif
477 * Simplistic source upward compatibility path for newer libpurple APIs
479 * Usually we compile with -Werror=missing-field-initializers if GCC supports
480 * it. But that means that the compilation of this structure can fail if the
481 * newer API has added additional plugin callbacks. For the benefit of the
482 * user we downgrade it to a warning here.
484 * Diagnostic #pragma was added in GCC 4.2.0
485 * Diagnostic push/pop was added in GCC 4.6.0
487 #ifdef __GNUC__
488 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 2)
489 #if __GNUC_MINOR__ >= 6
490 #pragma GCC diagnostic push
491 #endif
492 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
493 #endif
494 #endif
495 static PurplePluginProtocolInfo sipe_prpl_info =
497 OPT_PROTO_CHAT_TOPIC,
498 NULL, /* user_splits */
499 NULL, /* protocol_options */
500 NO_BUDDY_ICONS, /* icon_spec */
501 sipe_list_icon, /* list_icon */
502 NULL, /* list_emblems */
503 sipe_purple_status_text, /* status_text */
504 sipe_purple_tooltip_text, /* tooltip_text */ // add custom info to contact tooltip
505 sipe_purple_status_types, /* away_states */
506 sipe_purple_blist_node_menu, /* blist_node_menu */
507 sipe_purple_chat_info, /* chat_info */
508 sipe_purple_chat_info_defaults, /* chat_info_defaults */
509 sipe_purple_login, /* login */
510 sipe_purple_close, /* close */
511 sipe_purple_send_im, /* send_im */
512 NULL, /* set_info */ // TODO maybe
513 sipe_purple_send_typing, /* send_typing */
514 sipe_get_info, /* get_info */
515 sipe_set_status, /* set_status */
516 sipe_set_idle, /* set_idle */
517 NULL, /* change_passwd */
518 sipe_purple_add_buddy, /* add_buddy */
519 NULL, /* add_buddies */
520 sipe_purple_remove_buddy, /* remove_buddy */
521 NULL, /* remove_buddies */
522 sipe_purple_add_permit, /* add_permit */
523 sipe_purple_add_deny, /* add_deny */
524 sipe_purple_add_deny, /* rem_permit */
525 sipe_purple_add_permit, /* rem_deny */
526 NULL, /* set_permit_deny */
527 sipe_purple_chat_join, /* join_chat */
528 NULL, /* reject_chat */
529 NULL, /* get_chat_name */
530 sipe_purple_chat_invite, /* chat_invite */
531 sipe_purple_chat_leave, /* chat_leave */
532 NULL, /* chat_whisper */
533 sipe_purple_chat_send, /* chat_send */
534 sipe_purple_keep_alive, /* keepalive */
535 NULL, /* register_user */
536 NULL, /* get_cb_info */ // deprecated
537 NULL, /* get_cb_away */ // deprecated
538 sipe_purple_alias_buddy, /* alias_buddy */
539 sipe_purple_group_buddy, /* group_buddy */
540 sipe_purple_group_rename, /* rename_group */
541 NULL, /* buddy_free */
542 sipe_convo_closed, /* convo_closed */
543 purple_normalize_nocase, /* normalize */
544 NULL, /* set_buddy_icon */
545 sipe_purple_group_remove, /* remove_group */
546 NULL, /* get_cb_real_name */ // TODO?
547 NULL, /* set_chat_topic */
548 NULL, /* find_blist_chat */
549 sipe_purple_roomlist_get_list, /* roomlist_get_list */
550 sipe_purple_roomlist_cancel, /* roomlist_cancel */
551 NULL, /* roomlist_expand_category */
552 NULL, /* can_receive_file */
553 sipe_purple_ft_send_file, /* send_file */
554 sipe_purple_ft_new_xfer, /* new_xfer */
555 NULL, /* offline_message */
556 NULL, /* whiteboard_prpl_ops */
557 NULL, /* send_raw */
558 NULL, /* roomlist_room_serialize */
559 NULL, /* unregister_user */
560 NULL, /* send_attention */
561 NULL, /* get_attention_types */
562 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
563 /* Backward compatibility when compiling against 2.4.x API */
564 (void (*)(void)) /* _purple_reserved4 */
565 #endif
566 sizeof(PurplePluginProtocolInfo), /* struct_size */
567 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
568 sipe_purple_get_account_text_table, /* get_account_text_table */
569 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
570 #ifdef HAVE_VV
571 sipe_purple_initiate_media, /* initiate_media */
572 sipe_purple_get_media_caps, /* get_media_caps */
573 #else
574 NULL, /* initiate_media */
575 NULL, /* get_media_caps */
576 #endif
577 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
578 NULL, /* get_moods */
579 NULL, /* set_public_alias */
580 NULL, /* get_public_alias */
581 #if PURPLE_VERSION_CHECK(2,8,0) || PURPLE_VERSION_CHECK(3,0,0)
582 NULL, /* add_buddy_with_invite */
583 NULL, /* add_buddies_with_invite */
584 #endif
585 #endif
586 #endif
587 #endif
589 #ifdef __GNUC__
590 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 6)
591 #pragma GCC diagnostic pop
592 #endif
593 #endif
594 /* Original GCC error checking restored from here on... (see above) */
596 /* PurplePluginInfo function calls & data structure */
597 static gboolean sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
599 #ifdef HAVE_VV
600 struct sigaction action;
601 memset(&action, 0, sizeof (action));
602 action.sa_handler = sipe_purple_sigusr1_handler;
603 sigaction(SIGUSR1, &action, NULL);
604 #endif
605 return TRUE;
608 static gboolean sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
610 #ifdef HAVE_VV
611 struct sigaction action;
612 memset(&action, 0, sizeof (action));
613 action.sa_handler = SIG_DFL;
614 sigaction(SIGUSR1, &action, NULL);
615 #endif
616 return TRUE;
619 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
621 GList *entry;
623 sipe_purple_activity_destroy();
624 sipe_core_destroy();
626 entry = sipe_prpl_info.protocol_options;
627 while (entry) {
628 purple_account_option_destroy(entry->data);
629 entry = g_list_delete_link(entry, entry);
631 sipe_prpl_info.protocol_options = NULL;
633 entry = sipe_prpl_info.user_splits;
634 while (entry) {
635 purple_account_user_split_destroy(entry->data);
636 entry = g_list_delete_link(entry, entry);
638 sipe_prpl_info.user_splits = NULL;
641 static void sipe_purple_show_about_plugin(PurplePluginAction *action)
643 gchar *tmp = sipe_core_about();
644 purple_notify_formatted((PurpleConnection *) action->context,
645 NULL, " ", NULL, tmp, NULL, NULL);
646 g_free(tmp);
649 static void sipe_purple_find_contact_cb(PurpleConnection *gc,
650 PurpleRequestFields *fields)
652 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
653 const gchar *given_name = NULL;
654 const gchar *surname = NULL;
655 const gchar *company = NULL;
656 const gchar *country = NULL;
658 while (entries) {
659 PurpleRequestField *field = entries->data;
660 const char *id = purple_request_field_get_id(field);
661 const char *value = purple_request_field_string_get_value(field);
663 SIPE_DEBUG_INFO("sipe_purple_find_contact_cb: %s = '%s'", id, value ? value : "");
665 if (value) {
666 if (strcmp(id, "given") == 0) {
667 given_name = value;
668 } else if (strcmp(id, "surname") == 0) {
669 surname = value;
670 } else if (strcmp(id, "company") == 0) {
671 company = value;
672 } else if (strcmp(id, "country") == 0) {
673 country = value;
677 entries = g_list_next(entries);
680 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
681 given_name,
682 surname,
683 company,
684 country);
687 static void sipe_purple_show_find_contact(PurplePluginAction *action)
689 PurpleConnection *gc = (PurpleConnection *) action->context;
690 PurpleRequestFields *fields;
691 PurpleRequestFieldGroup *group;
692 PurpleRequestField *field;
694 fields = purple_request_fields_new();
695 group = purple_request_field_group_new(NULL);
696 purple_request_fields_add_group(fields, group);
698 field = purple_request_field_string_new("given", _("First name"), NULL, FALSE);
699 purple_request_field_group_add_field(group, field);
700 field = purple_request_field_string_new("surname", _("Last name"), NULL, FALSE);
701 purple_request_field_group_add_field(group, field);
702 field = purple_request_field_string_new("company", _("Company"), NULL, FALSE);
703 purple_request_field_group_add_field(group, field);
704 field = purple_request_field_string_new("country", _("Country"), NULL, FALSE);
705 purple_request_field_group_add_field(group, field);
707 purple_request_fields(gc,
708 _("Search"),
709 _("Search for a contact"),
710 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
711 fields,
712 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb),
713 _("_Cancel"), NULL,
714 purple_connection_get_account(gc), NULL, NULL, gc);
717 static void sipe_purple_join_conference_cb(PurpleConnection *gc,
718 PurpleRequestFields *fields)
720 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
722 if (entries) {
723 PurpleRequestField *field = entries->data;
724 const char *id = purple_request_field_get_id(field);
725 const char *value = purple_request_field_string_get_value(field);
727 if (!sipe_strequal(id, "meetingLocation"))
728 return;
730 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC, value);
734 static void sipe_purple_show_join_conference(PurplePluginAction *action)
736 PurpleConnection *gc = (PurpleConnection *) action->context;
737 PurpleRequestFields *fields;
738 PurpleRequestFieldGroup *group;
739 PurpleRequestField *field;
741 fields = purple_request_fields_new();
742 group = purple_request_field_group_new(NULL);
743 purple_request_fields_add_group(fields, group);
745 field = purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL, FALSE);
746 purple_request_field_group_add_field(group, field);
748 purple_request_fields(gc,
749 _("Join conference"),
750 _("Join scheduled conference"),
751 _("Enter meeting location string you received in the invitation.\n"
752 "\n"
753 "Valid location will be something like\n"
754 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234"),
755 fields,
756 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb),
757 _("_Cancel"), NULL,
758 purple_connection_get_account(gc), NULL, NULL, gc);
761 static void sipe_purple_republish_calendar(PurplePluginAction *action)
763 PurpleConnection *gc = (PurpleConnection *) action->context;
764 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
767 static void sipe_purple_reset_status(PurplePluginAction *action)
769 PurpleConnection *gc = (PurpleConnection *) action->context;
770 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
773 static GList *sipe_purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin *plugin,
774 SIPE_UNUSED_PARAMETER gpointer context)
776 GList *menu = NULL;
777 PurplePluginAction *act;
779 act = purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin);
780 menu = g_list_prepend(menu, act);
782 act = purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact);
783 menu = g_list_prepend(menu, act);
785 act = purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference);
786 menu = g_list_prepend(menu, act);
788 act = purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar);
789 menu = g_list_prepend(menu, act);
791 act = purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status);
792 menu = g_list_prepend(menu, act);
794 return g_list_reverse(menu);
797 static PurplePluginInfo sipe_purple_info = {
798 PURPLE_PLUGIN_MAGIC,
799 PURPLE_MAJOR_VERSION,
800 PURPLE_MINOR_VERSION,
801 PURPLE_PLUGIN_PROTOCOL, /**< type */
802 NULL, /**< ui_requirement */
803 0, /**< flags */
804 NULL, /**< dependencies */
805 PURPLE_PRIORITY_DEFAULT, /**< priority */
806 "prpl-sipe", /**< id */
807 "Office Communicator", /**< name */
808 PACKAGE_VERSION, /**< version */
809 "Microsoft Office Communicator Protocol Plugin", /**< summary */
810 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
811 "Microsoft Live/Office Communications Server (LCS2005/OCS2007+)", /**< description */
812 "Anibal Avelar <avelar@gmail.com>, " /**< author */
813 "Gabriel Burt <gburt@novell.com>, " /**< author */
814 "Stefan Becker <stefan.becker@nokia.com>, " /**< author */
815 "pier11 <pier11@operamail.com>", /**< author */
816 PACKAGE_URL, /**< homepage */
817 sipe_purple_plugin_load, /**< load */
818 sipe_purple_plugin_unload, /**< unload */
819 sipe_purple_plugin_destroy, /**< destroy */
820 NULL, /**< ui_info */
821 &sipe_prpl_info, /**< extra_info */
822 NULL,
823 sipe_purple_actions,
824 NULL,
825 NULL,
826 NULL,
827 NULL
830 static void sipe_purple_init_plugin(PurplePlugin *plugin)
832 PurpleAccountUserSplit *split;
833 PurpleAccountOption *option;
835 /* This needs to be called first */
836 sipe_core_init(LOCALEDIR);
837 sipe_purple_activity_init();
839 purple_plugin_register(plugin);
842 * When adding new string settings please make sure to keep these
843 * in sync:
845 * api/sipe-backend.h
846 * purple-settings.c:setting_name[]
848 split = purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL, ',');
849 purple_account_user_split_set_reverse(split, FALSE);
850 sipe_prpl_info.user_splits = g_list_append(sipe_prpl_info.user_splits, split);
852 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
853 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
855 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
856 purple_account_option_add_list_item(option, _("Auto"), "auto");
857 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
858 purple_account_option_add_list_item(option, _("TCP"), "tcp");
859 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
861 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
862 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
864 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
865 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
867 option = purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL);
868 purple_account_option_add_list_item(option, _("NTLM"), "ntlm");
869 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
870 purple_account_option_add_list_item(option, _("Kerberos"), "krb5");
871 #endif
872 purple_account_option_add_list_item(option, _("TLS-DSK"), "tls-dsk");
873 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
875 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
876 /* Suitable for sspi/NTLM, sspi/Kerberos and krb5 security mechanisms
877 * No login/password is taken into account if this option present,
878 * instead used default credentials stored in OS.
880 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", TRUE);
881 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
882 #endif
884 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
885 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
887 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
888 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
890 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
891 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
893 /** Example (Exchange): DOMAIN\user or user@company.com
894 * Example (Domino) : email_address
896 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
897 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
899 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
900 purple_account_option_set_masked(option, TRUE);
901 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
903 /** Example (federated domain): company.com (i.e. ocschat@company.com)
904 * Example (non-default user): user@company.com
906 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", "");
907 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
910 /* This macro makes the code a purple plugin */
911 PURPLE_INIT_PLUGIN(sipe, sipe_purple_init_plugin, sipe_purple_info);
914 Local Variables:
915 mode: c
916 c-file-style: "bsd"
917 indent-tabs-mode: t
918 tab-width: 8
919 End: