purple: make plugin functions externally visible
[siplcs.git] / src / purple / purple-plugin.c
blob10bba6b63a1335428f80773ae6995c32bf9b1414
1 /**
2 * @file purple-plugin.c
4 * pidgin-sipe
6 * Copyright (C) 2010-2015 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 "connection.h"
48 #include "core.h"
49 #include "dnssrv.h"
50 #ifdef HAVE_VV
51 #include "media.h"
52 #endif
53 #include "prpl.h"
54 #include "plugin.h"
55 #include "request.h"
56 #include "status.h"
58 #include "version.h"
59 #if PURPLE_VERSION_CHECK(3,0,0)
60 #include "buddylist.h"
61 #define PURPLE_TYPE_STRING G_TYPE_STRING
62 #else
63 #include "blist.h"
64 #define PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
65 #define PURPLE_CONNECTION_FLAG_FORMATTING_WBFO PURPLE_CONNECTION_FORMATTING_WBFO
66 #define PURPLE_CONNECTION_FLAG_HTML PURPLE_CONNECTION_HTML
67 #define PURPLE_CONNECTION_FLAG_NO_BGCOLOR PURPLE_CONNECTION_NO_BGCOLOR
68 #define PURPLE_CONNECTION_FLAG_NO_FONTSIZE PURPLE_CONNECTION_NO_FONTSIZE
69 #define PURPLE_CONNECTION_FLAG_NO_URLDESC PURPLE_CONNECTION_NO_URLDESC
70 #define PURPLE_IS_BUDDY(n) PURPLE_BLIST_NODE_IS_BUDDY(n)
71 #define PURPLE_IS_CHAT(n) PURPLE_BLIST_NODE_IS_CHAT(n)
72 #define PURPLE_IM_TYPING PURPLE_TYPING
73 #define PURPLE_IM_NOT_TYPING PURPLE_NOT_TYPING
74 #define purple_account_option_string_set_masked(o, f) purple_account_option_set_masked(o, f)
75 #define purple_connection_error(g, e, m) purple_connection_error_reason(g, e, m)
76 #define purple_connection_get_flags(gc) 0
77 #define purple_connection_set_protocol_data(gc, p) gc->proto_data = p
78 #define purple_connection_set_flags(gc, f) gc->flags |= f
79 #endif
81 #include "sipe-backend.h"
82 #include "sipe-core.h"
83 #include "sipe-nls.h"
85 #define _PurpleMessageFlags PurpleMessageFlags
86 #include "purple-private.h"
88 /* Backward compatibility when compiling against 2.4.x API */
89 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
90 #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100
91 #endif
94 * NOTE: this flag means two things:
96 * - is Single Sign-On supported, and
97 * - is Kerberos supported
99 #if defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_SSPI)
100 #define PURPLE_SIPE_SSO_AND_KERBEROS 1
101 #else
102 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
103 #endif
106 * SIPE core activity <-> Purple status mapping
108 * NOTE: this needs to be kept in sync with sipe_purple_status_types()
110 static const gchar * const activity_to_purple_map[SIPE_ACTIVITY_NUM_TYPES] = {
111 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
112 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
113 /* SIPE_ACTIVITY_ONLINE */ "online",
114 /* SIPE_ACTIVITY_INACTIVE */ "idle",
115 /* SIPE_ACTIVITY_BUSY */ "busy",
116 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
117 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
118 /* SIPE_ACTIVITY_BRB */ "be-right-back",
119 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
120 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
121 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
122 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
123 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
124 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
125 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
126 /* SIPE_ACTIVITY_OOF */ "out-of-office",
127 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
128 /* SIPE_ACTIVIY_NUM_TYPES == 17 -> compare to sipe_purple_status_types() */
131 GHashTable *purple_token_map;
133 static void sipe_purple_activity_init(void)
135 guint index;
137 purple_token_map = g_hash_table_new(g_str_hash, g_str_equal);
138 for (index = SIPE_ACTIVITY_UNSET;
139 index < SIPE_ACTIVITY_NUM_TYPES;
140 index++) {
141 g_hash_table_insert(purple_token_map,
142 (gchar *) activity_to_purple_map[index],
143 GUINT_TO_POINTER(index));
147 static void sipe_purple_activity_shutdown(void)
149 g_hash_table_destroy(purple_token_map);
152 const gchar *sipe_purple_activity_to_token(guint type)
154 return(activity_to_purple_map[type]);
157 guint sipe_purple_token_to_activity(const gchar *token)
159 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map, token)));
162 gchar *sipe_backend_version(void)
164 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
167 /* PurplePluginProtocolInfo function calls & data structure */
168 const char *sipe_purple_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount *a,
169 SIPE_UNUSED_PARAMETER PurpleBuddy *b)
171 return "sipe";
174 gchar *sipe_purple_status_text(PurpleBuddy *buddy)
176 const PurpleStatus *status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
177 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
178 purple_buddy_get_name(buddy),
179 sipe_purple_token_to_activity(purple_status_get_id(status)),
180 purple_status_get_name(status));
183 void sipe_purple_tooltip_text(PurpleBuddy *buddy,
184 PurpleNotifyUserInfo *user_info,
185 SIPE_UNUSED_PARAMETER gboolean full)
187 const PurplePresence *presence = purple_buddy_get_presence(buddy);
188 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
189 purple_buddy_get_name(buddy),
190 purple_status_get_name(purple_presence_get_active_status(presence)),
191 purple_presence_is_online(presence),
192 (struct sipe_backend_buddy_tooltip *) user_info);
195 GList *sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount *acc)
197 PurpleStatusType *type;
198 GList *types = NULL;
200 /* Macro to reduce code repetition
201 Translators: noun */
202 #define SIPE_ADD_STATUS(prim,activity,user) type = purple_status_type_new_with_attrs( \
203 prim, \
204 sipe_purple_activity_to_token(activity), \
205 sipe_core_activity_description(activity), \
206 TRUE, user, FALSE, \
207 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
208 NULL); \
209 types = g_list_append(types, type);
212 * NOTE: needs to be kept in sync with activity_to_purple_map[],
213 * i.e. for each SIPE_ACTIVITY_xxx value there must be an
214 * entry on this list.
216 * NOTE: the following code is sorted by purple primitive type not
217 * by SIPE_ACTIVITY_xxx value.
220 /* 1: Unset - special case: no entry needed */
223 * Status list entries for primitive type AVAILABLE
225 * 2: Available */
226 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
227 SIPE_ACTIVITY_AVAILABLE,
228 TRUE);
230 /* 3: Online */
231 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
232 SIPE_ACTIVITY_ONLINE,
233 FALSE);
235 /* 4: Inactive (Idle) */
236 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
237 SIPE_ACTIVITY_INACTIVE,
238 FALSE);
241 * Status list entries for primitive type UNAVAILABLE
243 * 5: Busy */
244 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
245 SIPE_ACTIVITY_BUSY,
246 TRUE);
248 /* 6: Busy-Idle */
249 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
250 SIPE_ACTIVITY_BUSYIDLE,
251 FALSE);
253 /* 7: Do Not Disturb */
254 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
255 SIPE_ACTIVITY_DND,
256 TRUE);
258 /* 8: In a call */
259 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
260 SIPE_ACTIVITY_ON_PHONE,
261 FALSE);
263 /* 9: In a conference call */
264 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
265 SIPE_ACTIVITY_IN_CONF,
266 FALSE);
268 /* 10: In a meeting */
269 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
270 SIPE_ACTIVITY_IN_MEETING,
271 FALSE);
273 /* 11: Urgent interruptions only */
274 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
275 SIPE_ACTIVITY_URGENT_ONLY,
276 FALSE);
279 * Status list entries for primitive type AWAY
281 * 12: Away - special case: needs to go first in the list as purple
282 * picks the first status with primitive type AWAY for idle
284 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
285 SIPE_ACTIVITY_AWAY,
286 TRUE);
288 /* 13: Be Right Back */
289 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
290 SIPE_ACTIVITY_BRB,
291 TRUE);
293 /* 14: Out to lunch */
294 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
295 SIPE_ACTIVITY_LUNCH,
296 FALSE);
299 * Status list entries for primitive type EXTENDED_AWAY
301 * 15: Out of office */
302 SIPE_ADD_STATUS(PURPLE_STATUS_EXTENDED_AWAY,
303 SIPE_ACTIVITY_OOF,
304 FALSE);
307 * Status list entries for primitive type INVISIBLE
309 * 16: Appear Offline */
310 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE,
311 SIPE_ACTIVITY_INVISIBLE,
312 TRUE);
315 * Status list entries for primitive type OFFLINE
317 * NOTE: this is always the last entry. Compare the number
318 * with the comment in activity_to_purple_map[].
320 * 17: Offline - special case: no message text */
321 type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
322 NULL,
323 NULL,
324 TRUE);
325 types = g_list_append(types, type);
327 return types;
330 GList *sipe_purple_blist_node_menu(PurpleBlistNode *node)
332 if (PURPLE_IS_BUDDY(node))
334 return sipe_purple_buddy_menu((PurpleBuddy *) node);
335 } else
336 if (PURPLE_IS_CHAT(node))
338 return sipe_purple_chat_menu((PurpleChat *)node);
339 } else {
340 return NULL;
344 static guint get_authentication_type(PurpleAccount *account)
346 const gchar *auth = purple_account_get_string(account, "authentication", "ntlm");
348 /* map option list to type - default is automatic */
349 guint authentication_type = SIPE_AUTHENTICATION_TYPE_AUTOMATIC;
350 if (sipe_strequal(auth, "ntlm")) {
351 authentication_type = SIPE_AUTHENTICATION_TYPE_NTLM;
352 } else
353 #if PURPLE_SIPE_SSO_AND_KERBEROS
354 if (sipe_strequal(auth, "krb5")) {
355 authentication_type = SIPE_AUTHENTICATION_TYPE_KERBEROS;
356 } else
357 #endif
358 if (sipe_strequal(auth, "tls-dsk")) {
359 authentication_type = SIPE_AUTHENTICATION_TYPE_TLS_DSK;
362 return(authentication_type);
365 static gboolean get_sso_flag(PurpleAccount *account)
367 #if PURPLE_SIPE_SSO_AND_KERBEROS
369 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
370 * SIPE that it is OK to use Single Sign-On or not.
372 return(purple_account_get_bool(account, "sso", FALSE));
373 #else
374 (void) account; /* keep compiler happy */
375 return(FALSE);
376 #endif
379 static gboolean get_dont_publish_flag(PurpleAccount *account)
381 /* default is to publish calendar information */
382 return(purple_account_get_bool(account, "dont-publish", FALSE));
385 static void connect_to_core(PurpleConnection *gc,
386 PurpleAccount *account,
387 const gchar *password)
389 const gchar *username = purple_account_get_username(account);
390 const gchar *email = purple_account_get_string(account, "email", NULL);
391 const gchar *email_url = purple_account_get_string(account, "email_url", NULL);
392 const gchar *transport = purple_account_get_string(account, "transport", "auto");
393 struct sipe_core_public *sipe_public;
394 gchar **username_split;
395 const gchar *errmsg;
396 guint transport_type;
397 struct sipe_backend_private *purple_private;
399 /* username format: <username>,[<optional login>] */
400 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username);
401 username_split = g_strsplit(username, ",", 2);
403 sipe_public = sipe_core_allocate(username_split[0],
404 get_sso_flag(account),
405 username_split[1],
406 password,
407 email,
408 email_url,
409 &errmsg);
410 g_strfreev(username_split);
412 if (!sipe_public) {
413 purple_connection_error(gc,
414 PURPLE_CONNECTION_ERROR_INVALID_USERNAME,
415 errmsg);
416 return;
419 sipe_public->backend_private = purple_private = g_new0(struct sipe_backend_private, 1);
420 purple_private->public = sipe_public;
421 purple_private->gc = gc;
422 purple_private->account = account;
424 sipe_purple_chat_setup_rejoin(purple_private);
426 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH);
427 if (get_dont_publish_flag(account))
428 SIPE_CORE_FLAG_SET(DONT_PUBLISH);
430 purple_connection_set_protocol_data(gc, sipe_public);
431 purple_connection_set_flags(gc,
432 purple_connection_get_flags(gc) |
433 PURPLE_CONNECTION_FLAG_HTML |
434 PURPLE_CONNECTION_FLAG_FORMATTING_WBFO |
435 PURPLE_CONNECTION_FLAG_NO_BGCOLOR |
436 PURPLE_CONNECTION_FLAG_NO_FONTSIZE |
437 PURPLE_CONNECTION_FLAG_NO_URLDESC |
438 PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY);
439 purple_connection_set_display_name(gc, sipe_public->sip_name);
440 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
442 username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2);
443 if (sipe_strequal(transport, "auto")) {
444 transport_type = (username_split[0] == NULL) ?
445 SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS;
446 } else if (sipe_strequal(transport, "tls")) {
447 transport_type = SIPE_TRANSPORT_TLS;
448 } else {
449 transport_type = SIPE_TRANSPORT_TCP;
451 sipe_core_transport_sip_connect(sipe_public,
452 transport_type,
453 get_authentication_type(account),
454 username_split[0],
455 username_split[0] ? username_split[1] : NULL);
456 g_strfreev(username_split);
459 static void password_required_cb(PurpleConnection *gc,
460 SIPE_UNUSED_PARAMETER PurpleRequestFields *fields)
462 #if !PURPLE_VERSION_CHECK(3,0,0)
463 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
464 return;
466 #endif
468 purple_connection_error(gc,
469 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
470 _("Password required"));
473 static void password_ok_cb(PurpleConnection *gc,
474 PurpleRequestFields *fields)
476 const gchar *password;
478 #if !PURPLE_VERSION_CHECK(3,0,0)
479 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
480 return;
482 #endif
484 password = purple_request_fields_get_string(fields, "password");
486 if (password && strlen(password)) {
487 PurpleAccount *account = purple_connection_get_account(gc);
489 if (purple_request_fields_get_bool(fields, "remember"))
490 purple_account_set_remember_password(account, TRUE);
491 purple_account_set_password(account, password
492 #if PURPLE_VERSION_CHECK(3,0,0)
493 , NULL, NULL
494 #endif
497 /* Now we have a password and we can connect */
498 connect_to_core(gc, account, password);
500 } else
501 /* reject an empty password */
502 password_required_cb(gc, fields);
505 void sipe_purple_login(PurpleAccount *account)
507 PurpleConnection *gc = purple_account_get_connection(account);
508 const gchar *password = purple_connection_get_password(gc);
510 /* Password required? */
511 if (sipe_core_transport_sip_requires_password(get_authentication_type(account),
512 get_sso_flag(account)) &&
513 (!password || !strlen(password)))
514 /* No password set - request one from user */
515 purple_account_request_password(account,
516 G_CALLBACK(password_ok_cb),
517 G_CALLBACK(password_required_cb),
518 gc);
519 else
520 /* No password required or saved password - connect now */
521 connect_to_core(gc, account, password);
525 void sipe_purple_close(PurpleConnection *gc)
527 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
529 if (sipe_public) {
530 struct sipe_backend_private *purple_private = sipe_public->backend_private;
532 sipe_core_deallocate(sipe_public);
534 /* anything left after that must be in pending state... */
535 sipe_purple_dns_query_cancel_all(purple_private);
536 sipe_purple_transport_close_all(purple_private);
538 if (purple_private->roomlist_map)
539 g_hash_table_destroy(purple_private->roomlist_map);
540 sipe_purple_chat_destroy_rejoin(purple_private);
542 if (purple_private->deferred_status_timeout)
543 purple_timeout_remove(purple_private->deferred_status_timeout);
544 g_free(purple_private->deferred_status_note);
546 g_free(purple_private);
547 purple_connection_set_protocol_data(gc, NULL);
551 #if PURPLE_VERSION_CHECK(3,0,0)
552 static int sipe_purple_send_im(PurpleConnection *gc, PurpleMessage *msg)
554 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
555 purple_message_get_recipient(msg),
556 purple_message_get_contents(msg));
557 return 1;
559 #else
560 static int sipe_purple_send_im(PurpleConnection *gc,
561 const char *who,
562 const char *what,
563 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags)
565 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who, what);
566 return 1;
568 #endif
570 unsigned int sipe_purple_send_typing(PurpleConnection *gc,
571 const char *who,
572 PurpleIMTypingState state)
574 gboolean typing = (state == PURPLE_IM_TYPING);
576 /* only enable this debug output while testing
577 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
580 * libpurple calls this function with PURPLE_NOT_TYPING *after*
581 * calling sipe_purple_send_im() with the message. This causes
582 * SIPE core to send out two SIP messages to the same dialog in
583 * short succession without waiting for the response to the first
584 * one. Some servers then reject the first one with
586 * SIP/2.0 500 Stale CSeq Value
588 * which triggers a "message not delivered" error for the user.
590 * Work around this by filtering out PURPLE_NOT_TYPING events.
592 if (state != PURPLE_IM_NOT_TYPING)
593 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
594 who,
595 typing);
597 /* tell libpurple to send typing indications every 4 seconds */
598 return(typing ? 4 : 0);
601 void sipe_purple_get_info(PurpleConnection *gc, const char *who)
603 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
604 who);
607 void sipe_purple_add_permit(PurpleConnection *gc, const char *name)
609 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE);
612 void sipe_purple_add_deny(PurpleConnection *gc, const char *name)
614 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, FALSE);
617 void sipe_purple_alias_buddy(PurpleConnection *gc, const char *name,
618 const char *alias)
620 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, alias);
623 void sipe_purple_group_rename(PurpleConnection *gc,
624 const char *old_name,
625 PurpleGroup *group,
626 SIPE_UNUSED_PARAMETER GList *moved_buddies)
628 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
629 old_name,
630 purple_group_get_name(group));
633 void sipe_purple_convo_closed(PurpleConnection *gc,
634 const char *who)
636 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who);
639 void sipe_purple_group_remove(PurpleConnection *gc, PurpleGroup *group)
641 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
642 purple_group_get_name(group));
645 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
646 GHashTable *
647 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount *account)
649 GHashTable *table;
650 table = g_hash_table_new(g_str_hash, g_str_equal);
651 g_hash_table_insert(table, "login_label", (gpointer)_("user@company.com"));
652 return table;
655 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
656 #ifdef HAVE_VV
658 static void
659 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER int signum)
661 capture_pipeline("PURPLE_SIPE_PIPELINE");
664 gboolean sipe_purple_initiate_media(PurpleAccount *account, const char *who,
665 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type)
667 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
668 who,
669 (type & PURPLE_MEDIA_VIDEO));
670 return TRUE;
673 PurpleMediaCaps sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount *account,
674 SIPE_UNUSED_PARAMETER const char *who)
676 return PURPLE_MEDIA_CAPS_AUDIO
677 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
678 | PURPLE_MEDIA_CAPS_MODIFY_SESSION;
680 #endif
681 #endif
682 #endif
685 * Simplistic source upward compatibility path for newer libpurple APIs
687 * Usually we compile with -Werror=missing-field-initializers if GCC supports
688 * it. But that means that the compilation of this structure can fail if the
689 * newer API has added additional plugin callbacks. For the benefit of the
690 * user we downgrade it to a warning here.
692 * Diagnostic #pragma was added in GCC 4.2.0
693 * Diagnostic push/pop was added in GCC 4.6.0
695 #ifdef __GNUC__
696 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || (__GNUC__ >= 5)
697 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ >= 5)
698 #pragma GCC diagnostic push
699 #endif
700 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
701 #endif
702 #endif
703 static PurplePluginProtocolInfo sipe_prpl_info =
705 #if PURPLE_VERSION_CHECK(3,0,0)
706 sizeof(PurplePluginProtocolInfo), /* struct_size */
707 #endif
708 OPT_PROTO_CHAT_TOPIC |
709 OPT_PROTO_PASSWORD_OPTIONAL,
710 NULL, /* user_splits */
711 NULL, /* protocol_options */
712 NO_BUDDY_ICONS, /* icon_spec */
713 sipe_purple_list_icon, /* list_icon */
714 NULL, /* list_emblems */
715 sipe_purple_status_text, /* status_text */
716 sipe_purple_tooltip_text, /* tooltip_text */ // add custom info to contact tooltip
717 sipe_purple_status_types, /* away_states */
718 sipe_purple_blist_node_menu, /* blist_node_menu */
719 sipe_purple_chat_info, /* chat_info */
720 sipe_purple_chat_info_defaults, /* chat_info_defaults */
721 sipe_purple_login, /* login */
722 sipe_purple_close, /* close */
723 sipe_purple_send_im, /* send_im */
724 NULL, /* set_info */ // TODO maybe
725 sipe_purple_send_typing, /* send_typing */
726 sipe_purple_get_info, /* get_info */
727 sipe_purple_set_status, /* set_status */
728 sipe_purple_set_idle, /* set_idle */
729 NULL, /* change_passwd */
730 sipe_purple_add_buddy, /* add_buddy */
731 NULL, /* add_buddies */
732 sipe_purple_remove_buddy, /* remove_buddy */
733 NULL, /* remove_buddies */
734 sipe_purple_add_permit, /* add_permit */
735 sipe_purple_add_deny, /* add_deny */
736 sipe_purple_add_deny, /* rem_permit */
737 sipe_purple_add_permit, /* rem_deny */
738 NULL, /* set_permit_deny */
739 sipe_purple_chat_join, /* join_chat */
740 NULL, /* reject_chat */
741 NULL, /* get_chat_name */
742 sipe_purple_chat_invite, /* chat_invite */
743 sipe_purple_chat_leave, /* chat_leave */
744 #if !PURPLE_VERSION_CHECK(3,0,0)
745 NULL, /* chat_whisper */
746 #endif
747 sipe_purple_chat_send, /* chat_send */
748 NULL, /* keepalive */
749 NULL, /* register_user */
750 NULL, /* get_cb_info */ // deprecated
751 #if !PURPLE_VERSION_CHECK(3,0,0)
752 NULL, /* get_cb_away */ // deprecated
753 #endif
754 sipe_purple_alias_buddy, /* alias_buddy */
755 sipe_purple_group_buddy, /* group_buddy */
756 sipe_purple_group_rename, /* rename_group */
757 NULL, /* buddy_free */
758 sipe_purple_convo_closed, /* convo_closed */
759 purple_normalize_nocase, /* normalize */
760 NULL, /* set_buddy_icon */
761 sipe_purple_group_remove, /* remove_group */
762 NULL, /* get_cb_real_name */ // TODO?
763 NULL, /* set_chat_topic */
764 NULL, /* find_blist_chat */
765 sipe_purple_roomlist_get_list, /* roomlist_get_list */
766 sipe_purple_roomlist_cancel, /* roomlist_cancel */
767 NULL, /* roomlist_expand_category */
768 NULL, /* can_receive_file */
769 sipe_purple_ft_send_file, /* send_file */
770 sipe_purple_ft_new_xfer, /* new_xfer */
771 NULL, /* offline_message */
772 NULL, /* whiteboard_prpl_ops */
773 NULL, /* send_raw */
774 NULL, /* roomlist_room_serialize */
775 NULL, /* unregister_user */
776 NULL, /* send_attention */
777 NULL, /* get_attention_types */
778 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
779 /* Backward compatibility when compiling against 2.4.x API */
780 (void (*)(void)) /* _purple_reserved4 */
781 #endif
782 #if !PURPLE_VERSION_CHECK(3,0,0)
783 sizeof(PurplePluginProtocolInfo), /* struct_size */
784 #endif
785 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
786 sipe_purple_get_account_text_table, /* get_account_text_table */
787 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
788 #ifdef HAVE_VV
789 sipe_purple_initiate_media, /* initiate_media */
790 sipe_purple_get_media_caps, /* get_media_caps */
791 #else
792 NULL, /* initiate_media */
793 NULL, /* get_media_caps */
794 #endif
795 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
796 NULL, /* get_moods */
797 NULL, /* set_public_alias */
798 NULL, /* get_public_alias */
799 #if PURPLE_VERSION_CHECK(2,8,0)
800 NULL, /* add_buddy_with_invite */
801 NULL, /* add_buddies_with_invite */
802 #elif PURPLE_VERSION_CHECK(3,0,0)
803 NULL, /* get_max_message_size */
804 NULL, /* media_send_dtmf */
805 #endif
806 #endif
807 #endif
808 #endif
810 #ifdef __GNUC__
811 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ >= 5)
812 #pragma GCC diagnostic pop
813 #endif
814 #endif
815 /* Original GCC error checking restored from here on... (see above) */
817 /* PurplePluginInfo function calls & data structure */
818 gboolean sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
820 #ifdef HAVE_VV
821 struct sigaction action;
822 memset(&action, 0, sizeof (action));
823 action.sa_handler = sipe_purple_sigusr1_handler;
824 sigaction(SIGUSR1, &action, NULL);
825 #endif
826 return TRUE;
829 gboolean sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
831 #ifdef HAVE_VV
832 struct sigaction action;
833 memset(&action, 0, sizeof (action));
834 action.sa_handler = SIG_DFL;
835 sigaction(SIGUSR1, &action, NULL);
836 #endif
837 return TRUE;
840 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
842 GList *entry;
844 sipe_purple_activity_shutdown();
845 sipe_core_destroy();
847 entry = sipe_prpl_info.protocol_options;
848 while (entry) {
849 purple_account_option_destroy(entry->data);
850 entry = g_list_delete_link(entry, entry);
852 sipe_prpl_info.protocol_options = NULL;
854 entry = sipe_prpl_info.user_splits;
855 while (entry) {
856 purple_account_user_split_destroy(entry->data);
857 entry = g_list_delete_link(entry, entry);
859 sipe_prpl_info.user_splits = NULL;
862 static void sipe_purple_show_about_plugin(PurplePluginAction *action)
864 gchar *tmp = sipe_core_about();
865 purple_notify_formatted((PurpleConnection *) action->context,
866 NULL, " ", NULL, tmp, NULL, NULL);
867 g_free(tmp);
870 static void sipe_purple_join_conference_cb(PurpleConnection *gc,
871 PurpleRequestFields *fields)
873 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
875 if (entries) {
876 PurpleRequestField *field = entries->data;
877 const char *id = purple_request_field_get_id(field);
878 const char *value = purple_request_field_string_get_value(field);
880 if (!sipe_strequal(id, "meetingLocation"))
881 return;
883 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC, value);
887 #ifdef HAVE_VV
889 static void sipe_purple_phone_call_cb(PurpleConnection *gc,
890 PurpleRequestFields *fields)
892 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
894 if (entries) {
895 PurpleRequestField *field = entries->data;
896 const char *id = purple_request_field_get_id(field);
897 const char *value = purple_request_field_string_get_value(field);
899 if (!sipe_strequal(id, "phoneNumber"))
900 return;
902 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC, value);
906 static void sipe_purple_phone_call(PurplePluginAction *action)
908 PurpleConnection *gc = (PurpleConnection *) action->context;
909 PurpleRequestFields *fields;
910 PurpleRequestFieldGroup *group;
911 PurpleRequestField *field;
913 fields = purple_request_fields_new();
914 group = purple_request_field_group_new(NULL);
915 purple_request_fields_add_group(fields, group);
917 field = purple_request_field_string_new("phoneNumber", _("Phone number"), NULL, FALSE);
918 purple_request_field_group_add_field(group, field);
920 purple_request_fields(gc,
921 _("Call a phone number"),
922 _("Call a phone number"),
923 NULL,
924 fields,
925 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb),
926 _("_Cancel"), NULL,
927 #if PURPLE_VERSION_CHECK(3,0,0)
928 purple_request_cpar_from_connection(gc),
929 #else
930 purple_connection_get_account(gc), NULL, NULL,
931 #endif
932 gc);
935 static void sipe_purple_test_call(PurplePluginAction *action)
937 PurpleConnection *gc = (PurpleConnection *) action->context;
938 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
940 #endif
942 static void sipe_purple_show_join_conference(PurplePluginAction *action)
944 PurpleConnection *gc = (PurpleConnection *) action->context;
945 PurpleRequestFields *fields;
946 PurpleRequestFieldGroup *group;
947 PurpleRequestField *field;
949 fields = purple_request_fields_new();
950 group = purple_request_field_group_new(NULL);
951 purple_request_fields_add_group(fields, group);
953 field = purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL, FALSE);
954 purple_request_field_group_add_field(group, field);
956 purple_request_fields(gc,
957 _("Join conference"),
958 _("Join scheduled conference"),
959 _("Enter meeting location string you received in the invitation.\n"
960 "\n"
961 "Valid location will be something like\n"
962 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
963 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
964 "or\n"
965 "https://meet.company.com/someone/abcdef1234"),
966 fields,
967 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb),
968 _("_Cancel"), NULL,
969 #if PURPLE_VERSION_CHECK(3,0,0)
970 purple_request_cpar_from_connection(gc),
971 #else
972 purple_connection_get_account(gc), NULL, NULL,
973 #endif
974 gc);
977 static void sipe_purple_republish_calendar(PurplePluginAction *action)
979 PurpleConnection *gc = (PurpleConnection *) action->context;
980 PurpleAccount *account = purple_connection_get_account(gc);
982 if (get_dont_publish_flag(account)) {
983 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
984 _("Publishing of calendar information has been disabled"),
985 NULL);
986 } else {
987 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
991 static void sipe_purple_reset_status(PurplePluginAction *action)
993 PurpleConnection *gc = (PurpleConnection *) action->context;
994 PurpleAccount *account = purple_connection_get_account(gc);
996 if (get_dont_publish_flag(account)) {
997 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
998 _("Publishing of calendar information has been disabled"),
999 NULL);
1000 } else {
1001 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
1005 static GList *purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin *plugin,
1006 SIPE_UNUSED_PARAMETER gpointer context)
1008 return sipe_purple_actions();
1011 GList *sipe_purple_actions()
1013 GList *menu = NULL;
1014 PurplePluginAction *act;
1016 act = purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin);
1017 menu = g_list_prepend(menu, act);
1019 act = purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact);
1020 menu = g_list_prepend(menu, act);
1022 #ifdef HAVE_VV
1023 act = purple_plugin_action_new(_("Call a phone number..."), sipe_purple_phone_call);
1024 menu = g_list_prepend(menu, act);
1026 act = purple_plugin_action_new(_("Test call"), sipe_purple_test_call);
1027 menu = g_list_prepend(menu, act);
1028 #endif
1030 act = purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference);
1031 menu = g_list_prepend(menu, act);
1033 act = purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar);
1034 menu = g_list_prepend(menu, act);
1036 act = purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status);
1037 menu = g_list_prepend(menu, act);
1039 return g_list_reverse(menu);
1042 static PurplePluginInfo sipe_purple_info = {
1043 PURPLE_PLUGIN_MAGIC,
1044 PURPLE_MAJOR_VERSION,
1045 PURPLE_MINOR_VERSION,
1046 PURPLE_PLUGIN_PROTOCOL, /**< type */
1047 NULL, /**< ui_requirement */
1048 0, /**< flags */
1049 NULL, /**< dependencies */
1050 PURPLE_PRIORITY_DEFAULT, /**< priority */
1051 "prpl-sipe", /**< id */
1052 "Office Communicator", /**< name */
1053 PACKAGE_VERSION, /**< version */
1054 "Microsoft Office Communicator Protocol Plugin", /**< summary */
1055 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
1056 "Microsoft Live/Office Communications/Lync Server (LCS2005/OCS2007+)", /**< description */
1057 "Stefan Becker <chemobejk@gmail.com>, " /**< author */
1058 "Jakub Adam <jakub.adam@tieto.com>, " /**< author */
1059 "Anibal Avelar <avelar@gmail.com> (retired), " /**< author */
1060 "pier11 <pier11@operamail.com> (retired), " /**< author */
1061 "Gabriel Burt <gburt@novell.com> (retired)", /**< author */
1062 PACKAGE_URL, /**< homepage */
1063 sipe_purple_plugin_load, /**< load */
1064 sipe_purple_plugin_unload, /**< unload */
1065 sipe_purple_plugin_destroy, /**< destroy */
1066 NULL, /**< ui_info */
1067 &sipe_prpl_info, /**< extra_info */
1068 NULL,
1069 purple_actions,
1070 NULL,
1071 NULL,
1072 NULL,
1073 NULL
1076 static void sipe_purple_init_plugin(PurplePlugin *plugin)
1078 /* This needs to be called first */
1079 sipe_core_init(LOCALEDIR);
1080 sipe_purple_activity_init();
1082 purple_plugin_register(plugin);
1084 sipe_prpl_info.user_splits = g_list_append(sipe_prpl_info.user_splits,
1085 sipe_purple_user_split());
1087 sipe_prpl_info.protocol_options = sipe_purple_account_options();
1090 GList * sipe_purple_account_options()
1092 PurpleAccountOption *option;
1093 GList *options = NULL;
1096 * When adding new string settings please make sure to keep these
1097 * in sync:
1099 * api/sipe-backend.h
1100 * purple-settings.c:setting_name[]
1102 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
1103 options = g_list_append(options, option);
1105 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
1106 purple_account_option_add_list_item(option, _("Auto"), "auto");
1107 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
1108 purple_account_option_add_list_item(option, _("TCP"), "tcp");
1109 options = g_list_append(options, option);
1111 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
1112 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
1114 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
1115 options = g_list_append(options, option);
1117 option = purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL);
1118 purple_account_option_add_list_item(option, _("Auto"), "auto");
1119 purple_account_option_add_list_item(option, _("NTLM"), "ntlm");
1120 #if PURPLE_SIPE_SSO_AND_KERBEROS
1121 purple_account_option_add_list_item(option, _("Kerberos"), "krb5");
1122 #endif
1123 purple_account_option_add_list_item(option, _("TLS-DSK"), "tls-dsk");
1124 options = g_list_append(options, option);
1126 #if PURPLE_SIPE_SSO_AND_KERBEROS
1128 * When the user selects Single Sign-On then SIPE will ignore the
1129 * settings for "login name" and "password". Instead it will use the
1130 * default credentials provided by the OS.
1132 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
1133 * SIPE that it is OK to use Single Sign-On or not.
1135 * Configurations that are known to support Single Sign-On:
1137 * - Windows, host joined to domain, SIPE with SSPI: NTLM
1138 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
1139 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
1141 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE);
1142 options = g_list_append(options, option);
1143 #endif
1145 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
1146 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
1148 option = purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE);
1149 options = g_list_append(options, option);
1151 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
1152 options = g_list_append(options, option);
1154 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
1155 options = g_list_append(options, option);
1157 /** Example (Exchange): DOMAIN\user or user@company.com
1158 * Example (Domino) : email_address
1160 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
1161 options = g_list_append(options, option);
1163 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
1164 purple_account_option_string_set_masked(option, TRUE);
1165 options = g_list_append(options, option);
1167 /** Example (federated domain): company.com (i.e. ocschat@company.com)
1168 * Example (non-default user): user@company.com
1170 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", "");
1171 options = g_list_append(options, option);
1173 #ifdef HAVE_SRTP
1174 option = purple_account_option_list_new(_("Media encryption"), "encryption-policy", NULL);
1175 purple_account_option_add_list_item(option, _("Obey server policy"), "obey-server");
1176 purple_account_option_add_list_item(option, _("Always"), "required");
1177 purple_account_option_add_list_item(option, _("Optional"), "optional");
1178 purple_account_option_add_list_item(option, _("Disabled"), "disabled");
1179 options = g_list_append(options, option);
1180 #endif
1182 return options;
1185 gpointer sipe_purple_user_split()
1187 PurpleAccountUserSplit *split =
1188 purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL, ',');
1189 purple_account_user_split_set_reverse(split, FALSE);
1191 return split;
1194 /* This macro makes the code a purple plugin */
1195 PURPLE_INIT_PLUGIN(sipe, sipe_purple_init_plugin, sipe_purple_info);
1198 Local Variables:
1199 mode: c
1200 c-file-style: "bsd"
1201 indent-tabs-mode: t
1202 tab-width: 8
1203 End: