core cleanup: remove struct sipe_account_data
[siplcs.git] / src / purple / purple-plugin.c
blob42dabc93860d82b14c683a12eefb329ebdb7520a
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 /* Sipe core activity <-> Purple status mapping */
84 static const gchar * const activity_to_purple[SIPE_ACTIVITY_NUM_TYPES] = {
85 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
86 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
87 /* SIPE_ACTIVITY_ONLINE */ "online",
88 /* SIPE_ACTIVITY_INACTIVE */ "idle",
89 /* SIPE_ACTIVITY_BUSY */ "busy",
90 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
91 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
92 /* SIPE_ACTIVITY_BRB */ "be-right-back",
93 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
94 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
95 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
96 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
97 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
98 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
99 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
100 /* SIPE_ACTIVITY_OOF */ "out-of-office",
101 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
103 GHashTable *purple_to_activity = NULL;
104 #define PURPLE_STATUS_TO_ACTIVITY(x) \
105 GPOINTER_TO_UINT(g_hash_table_lookup(purple_to_activity, (x)))
107 static void sipe_purple_activity_init(void)
109 guint index = SIPE_ACTIVITY_UNSET;
110 purple_to_activity = g_hash_table_new(g_str_hash, g_str_equal);
111 while (index < SIPE_ACTIVITY_NUM_TYPES) {
112 g_hash_table_insert(purple_to_activity,
113 (gpointer) activity_to_purple[index],
114 GUINT_TO_POINTER(index));
115 index++;
119 const gchar *sipe_backend_activity_to_token(guint type)
121 return(activity_to_purple[type]);
124 guint sipe_backend_token_to_activity(const gchar *token)
126 return(PURPLE_STATUS_TO_ACTIVITY(token));
129 gchar *sipe_backend_version(void)
131 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
134 static void sipe_purple_activity_destroy(void)
136 g_hash_table_destroy(purple_to_activity);
137 purple_to_activity = NULL;
140 /* PurplePluginProtocolInfo function calls & data structure */
141 static const char *sipe_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount *a,
142 SIPE_UNUSED_PARAMETER PurpleBuddy *b)
144 return "sipe";
147 static gchar *sipe_purple_status_text(PurpleBuddy *buddy)
149 const PurpleStatus *status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
150 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
151 buddy->name,
152 PURPLE_STATUS_TO_ACTIVITY(purple_status_get_id(status)),
153 purple_status_get_name(status));
156 static void sipe_purple_tooltip_text(PurpleBuddy *buddy,
157 PurpleNotifyUserInfo *user_info,
158 SIPE_UNUSED_PARAMETER gboolean full)
160 const PurplePresence *presence = purple_buddy_get_presence(buddy);
161 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
162 buddy->name,
163 purple_status_get_name(purple_presence_get_active_status(presence)),
164 purple_presence_is_online(presence),
165 (struct sipe_backend_buddy_tooltip *) user_info);
168 static GList *sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount *acc)
170 PurpleStatusType *type;
171 GList *types = NULL;
173 /* Macros to reduce code repetition.
174 Translators: noun */
175 #define SIPE_ADD_STATUS(prim,id,name,user) type = purple_status_type_new_with_attrs( \
176 prim, id, name, \
177 TRUE, user, FALSE, \
178 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
179 NULL); \
180 types = g_list_append(types, type);
182 /* Online */
183 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
184 NULL,
185 NULL,
186 TRUE);
188 /* Busy */
189 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
190 activity_to_purple[SIPE_ACTIVITY_BUSY],
191 sipe_core_activity_description(SIPE_ACTIVITY_BUSY),
192 TRUE);
194 /* Do Not Disturb */
195 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
196 activity_to_purple[SIPE_ACTIVITY_DND],
197 NULL,
198 TRUE);
200 /* Away */
201 /* Goes first in the list as
202 * purple picks the first status with the AWAY type
203 * for idle.
205 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
206 NULL,
207 NULL,
208 TRUE);
210 /* Be Right Back */
211 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
212 activity_to_purple[SIPE_ACTIVITY_BRB],
213 sipe_core_activity_description(SIPE_ACTIVITY_BRB),
214 TRUE);
216 /* Appear Offline */
217 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE,
218 NULL,
219 NULL,
220 TRUE);
222 /* Offline */
223 type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
224 NULL,
225 NULL,
226 TRUE);
227 types = g_list_append(types, type);
229 return types;
232 static GList *sipe_purple_blist_node_menu(PurpleBlistNode *node)
234 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) {
235 return sipe_buddy_menu((PurpleBuddy *) node);
236 } else if(PURPLE_BLIST_NODE_IS_CHAT(node)) {
237 return sipe_purple_chat_menu((PurpleChat *)node);
238 } else {
239 return NULL;
243 static void sipe_purple_login(PurpleAccount *account)
245 PurpleConnection *gc = purple_account_get_connection(account);
246 const gchar *username = purple_account_get_username(account);
247 const gchar *email = purple_account_get_string(account, "email", NULL);
248 const gchar *email_url = purple_account_get_string(account, "email_url", NULL);
249 const gchar *transport = purple_account_get_string(account, "transport", "auto");
250 const gchar *auth = purple_account_get_string(account, "authentication", "ntlm");
251 struct sipe_core_public *sipe_public;
252 gchar **username_split;
253 gchar *login_domain = NULL;
254 gchar *login_account = NULL;
255 const gchar *errmsg;
256 guint type;
257 struct sipe_backend_private *purple_private;
259 /* username format: <username>,[<optional login>] */
260 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username);
261 username_split = g_strsplit(username, ",", 2);
263 /* login name specified? */
264 if (username_split[1] && strlen(username_split[1])) {
265 /* Allowed domain-account separators are / or \ */
266 gchar **domain_user = g_strsplit_set(username_split[1], "/\\", 2);
267 gboolean has_domain = domain_user[1] != NULL;
268 SIPE_DEBUG_INFO("sipe_purple_login: login '%s'", username_split[1]);
269 login_domain = has_domain ? g_strdup(domain_user[0]) : NULL;
270 login_account = g_strdup(domain_user[has_domain ? 1 : 0]);
271 SIPE_DEBUG_INFO("sipe_purple_login: auth domain '%s' user '%s'",
272 login_domain ? login_domain : "",
273 login_account);
274 g_strfreev(domain_user);
277 sipe_public = sipe_core_allocate(username_split[0],
278 login_domain, login_account,
279 purple_connection_get_password(gc),
280 email,
281 email_url,
282 &errmsg);
283 g_free(login_domain);
284 g_free(login_account);
285 g_strfreev(username_split);
287 if (!sipe_public) {
288 #if PURPLE_VERSION_CHECK(3,0,0)
289 purple_connection_error(
290 #else
291 purple_connection_error_reason(
292 #endif
294 PURPLE_CONNECTION_ERROR_INVALID_USERNAME,
295 errmsg);
296 return;
299 sipe_public->backend_private = purple_private = g_new0(struct sipe_backend_private, 1);
300 purple_private->public = sipe_public;
301 purple_private->gc = gc;
302 purple_private->account = account;
304 sipe_purple_chat_setup_rejoin(purple_private);
306 /* map option list to flags - default is NTLM */
307 SIPE_CORE_FLAG_UNSET(KRB5);
308 SIPE_CORE_FLAG_UNSET(TLS_DSK);
309 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
310 if (sipe_strequal(auth, "krb5")) {
311 SIPE_CORE_FLAG_SET(KRB5);
312 } else
313 #endif
314 if (sipe_strequal(auth, "tls-dsk")) {
315 SIPE_CORE_FLAG_SET(TLS_DSK);
318 /* @TODO: is this correct?
319 "sso" is only available when Kerberos/SSPI support is compiled in */
320 if (purple_account_get_bool(account, "sso", TRUE))
321 SIPE_CORE_FLAG_SET(SSO);
323 gc->proto_data = sipe_public;
324 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_FORMATTING_WBFO | PURPLE_CONNECTION_NO_BGCOLOR |
325 PURPLE_CONNECTION_NO_FONTSIZE | PURPLE_CONNECTION_NO_URLDESC | PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY;
326 purple_connection_set_display_name(gc, sipe_public->sip_name);
327 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
329 username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2);
330 if (sipe_strequal(transport, "auto")) {
331 type = (username_split[0] == NULL) ?
332 SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS;
333 } else if (sipe_strequal(transport, "tls")) {
334 type = SIPE_TRANSPORT_TLS;
335 } else {
336 type = SIPE_TRANSPORT_TCP;
338 sipe_core_transport_sip_connect(sipe_public,
339 type,
340 username_split[0],
341 username_split[0] ? username_split[1] : NULL);
342 g_strfreev(username_split);
345 static void sipe_purple_close(PurpleConnection *gc)
347 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
349 if (sipe_public) {
350 struct sipe_backend_private *purple_private = sipe_public->backend_private;
352 sipe_core_deallocate(sipe_public);
354 if (purple_private->roomlist_map)
355 g_hash_table_destroy(purple_private->roomlist_map);
356 sipe_purple_chat_destroy_rejoin(purple_private);
357 g_free(purple_private);
358 gc->proto_data = NULL;
362 static int sipe_purple_send_im(PurpleConnection *gc,
363 const char *who,
364 const char *what,
365 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags)
367 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who, what);
368 return 1;
371 #define SIPE_TYPING_SEND_TIMEOUT 4
373 static unsigned int sipe_purple_send_typing(PurpleConnection *gc,
374 const char *who,
375 PurpleTypingState state)
377 if (state == PURPLE_NOT_TYPING)
378 return 0;
380 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
381 who);
383 return SIPE_TYPING_SEND_TIMEOUT;
386 static void sipe_purple_get_info(PurpleConnection *gc, const char *who)
388 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
389 who);
392 static void sipe_purple_add_permit(PurpleConnection *gc, const char *name)
394 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE);
397 static void sipe_purple_add_deny(PurpleConnection *gc, const char *name)
399 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, FALSE);
402 static void sipe_purple_keep_alive(PurpleConnection *gc)
404 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
405 struct sipe_backend_private *purple_private = sipe_public->backend_private;
406 time_t now = time(NULL);
408 if ((sipe_public->keepalive_timeout > 0) &&
409 ((guint) (now - purple_private->last_keepalive) >= sipe_public->keepalive_timeout) &&
410 ((guint) (now - gc->last_received) >= sipe_public->keepalive_timeout)
412 sipe_core_transport_sip_keepalive(sipe_public);
413 purple_private->last_keepalive = now;
417 static void sipe_purple_alias_buddy(PurpleConnection *gc, const char *name,
418 SIPE_UNUSED_PARAMETER const char *alias)
420 sipe_core_group_set_user(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name);
423 static void sipe_purple_group_rename(PurpleConnection *gc,
424 const char *old_name,
425 PurpleGroup *group,
426 SIPE_UNUSED_PARAMETER GList *moved_buddies)
428 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC, old_name, group->name);
431 static void sipe_purple_convo_closed(PurpleConnection *gc,
432 const char *who)
434 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who);
437 static void sipe_purple_group_remove(PurpleConnection *gc, PurpleGroup *group)
439 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC, group->name);
442 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
443 static GHashTable *
444 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount *account)
446 GHashTable *table;
447 table = g_hash_table_new(g_str_hash, g_str_equal);
448 g_hash_table_insert(table, "login_label", (gpointer)_("user@company.com"));
449 return table;
452 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
453 #ifdef HAVE_VV
455 extern void capture_pipeline(gchar *label);
457 static void
458 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER int signum)
460 capture_pipeline("PURPLE_SIPE_PIPELINE");
463 static gboolean sipe_purple_initiate_media(PurpleAccount *account, const char *who,
464 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type)
466 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
467 who,
468 (type & PURPLE_MEDIA_VIDEO));
469 return TRUE;
472 static PurpleMediaCaps sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount *account,
473 SIPE_UNUSED_PARAMETER const char *who)
475 return PURPLE_MEDIA_CAPS_AUDIO
476 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
477 | PURPLE_MEDIA_CAPS_MODIFY_SESSION;
479 #endif
480 #endif
481 #endif
484 * Simplistic source upward compatibility path for newer libpurple APIs
486 * Usually we compile with -Werror=missing-field-initializers if GCC supports
487 * it. But that means that the compilation of this structure can fail if the
488 * newer API has added additional plugin callbacks. For the benefit of the
489 * user we downgrade it to a warning here.
491 * Diagnostic #pragma was added in GCC 4.2.0
492 * Diagnostic push/pop was added in GCC 4.6.0
494 #ifdef __GNUC__
495 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 2)
496 #if __GNUC_MINOR__ >= 6
497 #pragma GCC diagnostic push
498 #endif
499 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
500 #endif
501 #endif
502 static PurplePluginProtocolInfo sipe_prpl_info =
504 OPT_PROTO_CHAT_TOPIC,
505 NULL, /* user_splits */
506 NULL, /* protocol_options */
507 NO_BUDDY_ICONS, /* icon_spec */
508 sipe_list_icon, /* list_icon */
509 NULL, /* list_emblems */
510 sipe_purple_status_text, /* status_text */
511 sipe_purple_tooltip_text, /* tooltip_text */ // add custom info to contact tooltip
512 sipe_purple_status_types, /* away_states */
513 sipe_purple_blist_node_menu, /* blist_node_menu */
514 sipe_purple_chat_info, /* chat_info */
515 sipe_purple_chat_info_defaults, /* chat_info_defaults */
516 sipe_purple_login, /* login */
517 sipe_purple_close, /* close */
518 sipe_purple_send_im, /* send_im */
519 NULL, /* set_info */ // TODO maybe
520 sipe_purple_send_typing, /* send_typing */
521 sipe_purple_get_info, /* get_info */
522 sipe_purple_set_status, /* set_status */
523 sipe_purple_set_idle, /* set_idle */
524 NULL, /* change_passwd */
525 sipe_purple_add_buddy, /* add_buddy */
526 NULL, /* add_buddies */
527 sipe_purple_remove_buddy, /* remove_buddy */
528 NULL, /* remove_buddies */
529 sipe_purple_add_permit, /* add_permit */
530 sipe_purple_add_deny, /* add_deny */
531 sipe_purple_add_deny, /* rem_permit */
532 sipe_purple_add_permit, /* rem_deny */
533 NULL, /* set_permit_deny */
534 sipe_purple_chat_join, /* join_chat */
535 NULL, /* reject_chat */
536 NULL, /* get_chat_name */
537 sipe_purple_chat_invite, /* chat_invite */
538 sipe_purple_chat_leave, /* chat_leave */
539 NULL, /* chat_whisper */
540 sipe_purple_chat_send, /* chat_send */
541 sipe_purple_keep_alive, /* keepalive */
542 NULL, /* register_user */
543 NULL, /* get_cb_info */ // deprecated
544 NULL, /* get_cb_away */ // deprecated
545 sipe_purple_alias_buddy, /* alias_buddy */
546 sipe_purple_group_buddy, /* group_buddy */
547 sipe_purple_group_rename, /* rename_group */
548 NULL, /* buddy_free */
549 sipe_purple_convo_closed, /* convo_closed */
550 purple_normalize_nocase, /* normalize */
551 NULL, /* set_buddy_icon */
552 sipe_purple_group_remove, /* remove_group */
553 NULL, /* get_cb_real_name */ // TODO?
554 NULL, /* set_chat_topic */
555 NULL, /* find_blist_chat */
556 sipe_purple_roomlist_get_list, /* roomlist_get_list */
557 sipe_purple_roomlist_cancel, /* roomlist_cancel */
558 NULL, /* roomlist_expand_category */
559 NULL, /* can_receive_file */
560 sipe_purple_ft_send_file, /* send_file */
561 sipe_purple_ft_new_xfer, /* new_xfer */
562 NULL, /* offline_message */
563 NULL, /* whiteboard_prpl_ops */
564 NULL, /* send_raw */
565 NULL, /* roomlist_room_serialize */
566 NULL, /* unregister_user */
567 NULL, /* send_attention */
568 NULL, /* get_attention_types */
569 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
570 /* Backward compatibility when compiling against 2.4.x API */
571 (void (*)(void)) /* _purple_reserved4 */
572 #endif
573 sizeof(PurplePluginProtocolInfo), /* struct_size */
574 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
575 sipe_purple_get_account_text_table, /* get_account_text_table */
576 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
577 #ifdef HAVE_VV
578 sipe_purple_initiate_media, /* initiate_media */
579 sipe_purple_get_media_caps, /* get_media_caps */
580 #else
581 NULL, /* initiate_media */
582 NULL, /* get_media_caps */
583 #endif
584 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
585 NULL, /* get_moods */
586 NULL, /* set_public_alias */
587 NULL, /* get_public_alias */
588 #if PURPLE_VERSION_CHECK(2,8,0) || PURPLE_VERSION_CHECK(3,0,0)
589 NULL, /* add_buddy_with_invite */
590 NULL, /* add_buddies_with_invite */
591 #endif
592 #endif
593 #endif
594 #endif
596 #ifdef __GNUC__
597 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 6)
598 #pragma GCC diagnostic pop
599 #endif
600 #endif
601 /* Original GCC error checking restored from here on... (see above) */
603 /* PurplePluginInfo function calls & data structure */
604 static gboolean sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
606 #ifdef HAVE_VV
607 struct sigaction action;
608 memset(&action, 0, sizeof (action));
609 action.sa_handler = sipe_purple_sigusr1_handler;
610 sigaction(SIGUSR1, &action, NULL);
611 #endif
612 return TRUE;
615 static gboolean sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
617 #ifdef HAVE_VV
618 struct sigaction action;
619 memset(&action, 0, sizeof (action));
620 action.sa_handler = SIG_DFL;
621 sigaction(SIGUSR1, &action, NULL);
622 #endif
623 return TRUE;
626 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
628 GList *entry;
630 sipe_purple_activity_destroy();
631 sipe_core_destroy();
633 entry = sipe_prpl_info.protocol_options;
634 while (entry) {
635 purple_account_option_destroy(entry->data);
636 entry = g_list_delete_link(entry, entry);
638 sipe_prpl_info.protocol_options = NULL;
640 entry = sipe_prpl_info.user_splits;
641 while (entry) {
642 purple_account_user_split_destroy(entry->data);
643 entry = g_list_delete_link(entry, entry);
645 sipe_prpl_info.user_splits = NULL;
648 static void sipe_purple_show_about_plugin(PurplePluginAction *action)
650 gchar *tmp = sipe_core_about();
651 purple_notify_formatted((PurpleConnection *) action->context,
652 NULL, " ", NULL, tmp, NULL, NULL);
653 g_free(tmp);
656 static void sipe_purple_find_contact_cb(PurpleConnection *gc,
657 PurpleRequestFields *fields)
659 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
660 const gchar *given_name = NULL;
661 const gchar *surname = NULL;
662 const gchar *company = NULL;
663 const gchar *country = NULL;
665 while (entries) {
666 PurpleRequestField *field = entries->data;
667 const char *id = purple_request_field_get_id(field);
668 const char *value = purple_request_field_string_get_value(field);
670 SIPE_DEBUG_INFO("sipe_purple_find_contact_cb: %s = '%s'", id, value ? value : "");
672 if (value) {
673 if (strcmp(id, "given") == 0) {
674 given_name = value;
675 } else if (strcmp(id, "surname") == 0) {
676 surname = value;
677 } else if (strcmp(id, "company") == 0) {
678 company = value;
679 } else if (strcmp(id, "country") == 0) {
680 country = value;
684 entries = g_list_next(entries);
687 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
688 given_name,
689 surname,
690 company,
691 country);
694 static void sipe_purple_show_find_contact(PurplePluginAction *action)
696 PurpleConnection *gc = (PurpleConnection *) action->context;
697 PurpleRequestFields *fields;
698 PurpleRequestFieldGroup *group;
699 PurpleRequestField *field;
701 fields = purple_request_fields_new();
702 group = purple_request_field_group_new(NULL);
703 purple_request_fields_add_group(fields, group);
705 field = purple_request_field_string_new("given", _("First name"), NULL, FALSE);
706 purple_request_field_group_add_field(group, field);
707 field = purple_request_field_string_new("surname", _("Last name"), NULL, FALSE);
708 purple_request_field_group_add_field(group, field);
709 field = purple_request_field_string_new("company", _("Company"), NULL, FALSE);
710 purple_request_field_group_add_field(group, field);
711 field = purple_request_field_string_new("country", _("Country"), NULL, FALSE);
712 purple_request_field_group_add_field(group, field);
714 purple_request_fields(gc,
715 _("Search"),
716 _("Search for a contact"),
717 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
718 fields,
719 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb),
720 _("_Cancel"), NULL,
721 purple_connection_get_account(gc), NULL, NULL, gc);
724 static void sipe_purple_join_conference_cb(PurpleConnection *gc,
725 PurpleRequestFields *fields)
727 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
729 if (entries) {
730 PurpleRequestField *field = entries->data;
731 const char *id = purple_request_field_get_id(field);
732 const char *value = purple_request_field_string_get_value(field);
734 if (!sipe_strequal(id, "meetingLocation"))
735 return;
737 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC, value);
741 static void sipe_purple_show_join_conference(PurplePluginAction *action)
743 PurpleConnection *gc = (PurpleConnection *) action->context;
744 PurpleRequestFields *fields;
745 PurpleRequestFieldGroup *group;
746 PurpleRequestField *field;
748 fields = purple_request_fields_new();
749 group = purple_request_field_group_new(NULL);
750 purple_request_fields_add_group(fields, group);
752 field = purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL, FALSE);
753 purple_request_field_group_add_field(group, field);
755 purple_request_fields(gc,
756 _("Join conference"),
757 _("Join scheduled conference"),
758 _("Enter meeting location string you received in the invitation.\n"
759 "\n"
760 "Valid location will be something like\n"
761 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234"),
762 fields,
763 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb),
764 _("_Cancel"), NULL,
765 purple_connection_get_account(gc), NULL, NULL, gc);
768 static void sipe_purple_republish_calendar(PurplePluginAction *action)
770 PurpleConnection *gc = (PurpleConnection *) action->context;
771 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
774 static void sipe_purple_reset_status(PurplePluginAction *action)
776 PurpleConnection *gc = (PurpleConnection *) action->context;
777 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
780 static GList *sipe_purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin *plugin,
781 SIPE_UNUSED_PARAMETER gpointer context)
783 GList *menu = NULL;
784 PurplePluginAction *act;
786 act = purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin);
787 menu = g_list_prepend(menu, act);
789 act = purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact);
790 menu = g_list_prepend(menu, act);
792 act = purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference);
793 menu = g_list_prepend(menu, act);
795 act = purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar);
796 menu = g_list_prepend(menu, act);
798 act = purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status);
799 menu = g_list_prepend(menu, act);
801 return g_list_reverse(menu);
804 static PurplePluginInfo sipe_purple_info = {
805 PURPLE_PLUGIN_MAGIC,
806 PURPLE_MAJOR_VERSION,
807 PURPLE_MINOR_VERSION,
808 PURPLE_PLUGIN_PROTOCOL, /**< type */
809 NULL, /**< ui_requirement */
810 0, /**< flags */
811 NULL, /**< dependencies */
812 PURPLE_PRIORITY_DEFAULT, /**< priority */
813 "prpl-sipe", /**< id */
814 "Office Communicator", /**< name */
815 PACKAGE_VERSION, /**< version */
816 "Microsoft Office Communicator Protocol Plugin", /**< summary */
817 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
818 "Microsoft Live/Office Communications Server (LCS2005/OCS2007+)", /**< description */
819 "Anibal Avelar <avelar@gmail.com>, " /**< author */
820 "Gabriel Burt <gburt@novell.com>, " /**< author */
821 "Stefan Becker <stefan.becker@nokia.com>, " /**< author */
822 "pier11 <pier11@operamail.com>", /**< author */
823 PACKAGE_URL, /**< homepage */
824 sipe_purple_plugin_load, /**< load */
825 sipe_purple_plugin_unload, /**< unload */
826 sipe_purple_plugin_destroy, /**< destroy */
827 NULL, /**< ui_info */
828 &sipe_prpl_info, /**< extra_info */
829 NULL,
830 sipe_purple_actions,
831 NULL,
832 NULL,
833 NULL,
834 NULL
837 static void sipe_purple_init_plugin(PurplePlugin *plugin)
839 PurpleAccountUserSplit *split;
840 PurpleAccountOption *option;
842 /* This needs to be called first */
843 sipe_core_init(LOCALEDIR);
844 sipe_purple_activity_init();
846 purple_plugin_register(plugin);
849 * When adding new string settings please make sure to keep these
850 * in sync:
852 * api/sipe-backend.h
853 * purple-settings.c:setting_name[]
855 split = purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL, ',');
856 purple_account_user_split_set_reverse(split, FALSE);
857 sipe_prpl_info.user_splits = g_list_append(sipe_prpl_info.user_splits, split);
859 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
860 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
862 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
863 purple_account_option_add_list_item(option, _("Auto"), "auto");
864 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
865 purple_account_option_add_list_item(option, _("TCP"), "tcp");
866 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
868 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
869 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
871 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
872 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
874 option = purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL);
875 purple_account_option_add_list_item(option, _("NTLM"), "ntlm");
876 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
877 purple_account_option_add_list_item(option, _("Kerberos"), "krb5");
878 #endif
879 purple_account_option_add_list_item(option, _("TLS-DSK"), "tls-dsk");
880 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
882 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
883 /* Suitable for sspi/NTLM, sspi/Kerberos and krb5 security mechanisms
884 * No login/password is taken into account if this option present,
885 * instead used default credentials stored in OS.
887 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", TRUE);
888 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
889 #endif
891 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
892 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
894 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
895 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
897 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
898 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
900 /** Example (Exchange): DOMAIN\user or user@company.com
901 * Example (Domino) : email_address
903 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
904 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
906 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
907 purple_account_option_set_masked(option, TRUE);
908 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
910 /** Example (federated domain): company.com (i.e. ocschat@company.com)
911 * Example (non-default user): user@company.com
913 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", "");
914 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
917 /* This macro makes the code a purple plugin */
918 PURPLE_INIT_PLUGIN(sipe, sipe_purple_init_plugin, sipe_purple_info);
921 Local Variables:
922 mode: c
923 c-file-style: "bsd"
924 indent-tabs-mode: t
925 tab-width: 8
926 End: