purple: update status type list
[siplcs.git] / src / purple / purple-plugin.c
blob41bab9058d6b31d889f47f8c10978c21c9fd0dce
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 PurpleIMTypingState PurpleTypingState
65 #define PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
66 #define PURPLE_CONNECTION_FLAG_FORMATTING_WBFO PURPLE_CONNECTION_FORMATTING_WBFO
67 #define PURPLE_CONNECTION_FLAG_HTML PURPLE_CONNECTION_HTML
68 #define PURPLE_CONNECTION_FLAG_NO_BGCOLOR PURPLE_CONNECTION_NO_BGCOLOR
69 #define PURPLE_CONNECTION_FLAG_NO_FONTSIZE PURPLE_CONNECTION_NO_FONTSIZE
70 #define PURPLE_CONNECTION_FLAG_NO_URLDESC PURPLE_CONNECTION_NO_URLDESC
71 #define PURPLE_IS_BUDDY(n) PURPLE_BLIST_NODE_IS_BUDDY(n)
72 #define PURPLE_IS_CHAT(n) PURPLE_BLIST_NODE_IS_CHAT(n)
73 #define PURPLE_IM_TYPING PURPLE_TYPING
74 #define PURPLE_IM_NOT_TYPING PURPLE_NOT_TYPING
75 #define purple_account_option_string_set_masked(o, f) purple_account_option_set_masked(o, f)
76 #define purple_connection_error(g, e, m) purple_connection_error_reason(g, e, m)
77 #define purple_connection_get_flags(gc) 0
78 #define purple_connection_set_protocol_data(gc, p) gc->proto_data = p
79 #define purple_connection_set_flags(gc, f) gc->flags |= f
80 #endif
82 #include "sipe-backend.h"
83 #include "sipe-core.h"
84 #include "sipe-nls.h"
86 #define _PurpleMessageFlags PurpleMessageFlags
87 #include "purple-private.h"
89 /* Backward compatibility when compiling against 2.4.x API */
90 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
91 #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100
92 #endif
95 * NOTE: this flag means two things:
97 * - is Single Sign-On supported, and
98 * - is Kerberos supported
100 #if defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_SSPI)
101 #define PURPLE_SIPE_SSO_AND_KERBEROS 1
102 #else
103 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
104 #endif
107 * SIPE core activity <-> Purple status mapping
109 * NOTE: this needs to be kept in sync with sipe_purple_status_types()
111 static const gchar * const activity_to_purple_map[SIPE_ACTIVITY_NUM_TYPES] = {
112 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
113 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
114 /* SIPE_ACTIVITY_ONLINE */ "online",
115 /* SIPE_ACTIVITY_INACTIVE */ "idle",
116 /* SIPE_ACTIVITY_BUSY */ "busy",
117 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
118 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
119 /* SIPE_ACTIVITY_BRB */ "be-right-back",
120 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
121 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
122 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
123 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
124 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
125 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
126 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
127 /* SIPE_ACTIVITY_OOF */ "out-of-office",
128 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
129 /* SIPE_ACTIVIY_NUM_TYPES == 17 -> compare to sipe_purple_status_types() */
132 GHashTable *purple_token_map;
134 static void sipe_purple_activity_init(void)
136 guint index;
138 purple_token_map = g_hash_table_new(g_str_hash, g_str_equal);
139 for (index = SIPE_ACTIVITY_UNSET;
140 index < SIPE_ACTIVITY_NUM_TYPES;
141 index++) {
142 g_hash_table_insert(purple_token_map,
143 (gchar *) activity_to_purple_map[index],
144 GUINT_TO_POINTER(index));
148 static void sipe_purple_activity_shutdown(void)
150 g_hash_table_destroy(purple_token_map);
153 const gchar *sipe_purple_activity_to_token(guint type)
155 return(activity_to_purple_map[type]);
158 guint sipe_purple_token_to_activity(const gchar *token)
160 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map, token)));
163 gchar *sipe_backend_version(void)
165 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
168 /* PurplePluginProtocolInfo function calls & data structure */
169 static const char *sipe_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount *a,
170 SIPE_UNUSED_PARAMETER PurpleBuddy *b)
172 return "sipe";
175 static gchar *sipe_purple_status_text(PurpleBuddy *buddy)
177 const PurpleStatus *status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
178 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
179 purple_buddy_get_name(buddy),
180 sipe_purple_token_to_activity(purple_status_get_id(status)),
181 purple_status_get_name(status));
184 static void sipe_purple_tooltip_text(PurpleBuddy *buddy,
185 PurpleNotifyUserInfo *user_info,
186 SIPE_UNUSED_PARAMETER gboolean full)
188 const PurplePresence *presence = purple_buddy_get_presence(buddy);
189 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
190 purple_buddy_get_name(buddy),
191 purple_status_get_name(purple_presence_get_active_status(presence)),
192 purple_presence_is_online(presence),
193 (struct sipe_backend_buddy_tooltip *) user_info);
196 static GList *sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount *acc)
198 PurpleStatusType *type;
199 GList *types = NULL;
201 /* Macro to reduce code repetition
202 Translators: noun */
203 #define SIPE_ADD_STATUS(prim,activity,user) type = purple_status_type_new_with_attrs( \
204 prim, \
205 sipe_purple_activity_to_token(activity), \
206 sipe_core_activity_description(activity), \
207 TRUE, user, FALSE, \
208 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
209 NULL); \
210 types = g_list_append(types, type);
213 * NOTE: needs to be kept in sync with activity_to_purple_map[],
214 * i.e. for each SIPE_ACTIVITY_xxx value there must be an
215 * entry on this list.
217 * NOTE: the following code is sorted by purple primitive type not
218 * by SIPE_ACTIVITY_xxx value.
221 /* 1: Unset - special case: no entry needed */
224 * Status list entries for primitive type AVAILABLE
226 * 2: Available */
227 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
228 SIPE_ACTIVITY_AVAILABLE,
229 TRUE);
231 /* 3: Online */
232 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
233 SIPE_ACTIVITY_ONLINE,
234 FALSE);
236 /* 4: Inactive (Idle) */
237 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
238 SIPE_ACTIVITY_INACTIVE,
239 FALSE);
242 * Status list entries for primitive type UNAVAILABLE
244 * 5: Busy */
245 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
246 SIPE_ACTIVITY_BUSY,
247 TRUE);
249 /* 6: Busy-Idle */
250 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
251 SIPE_ACTIVITY_BUSYIDLE,
252 FALSE);
254 /* 7: Do Not Disturb */
255 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
256 SIPE_ACTIVITY_DND,
257 TRUE);
259 /* 8: In a call */
260 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
261 SIPE_ACTIVITY_ON_PHONE,
262 FALSE);
264 /* 9: In a conference call */
265 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
266 SIPE_ACTIVITY_IN_CONF,
267 FALSE);
269 /* 10: In a meeting */
270 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
271 SIPE_ACTIVITY_IN_MEETING,
272 FALSE);
274 /* 11: Urgent interruptions only */
275 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
276 SIPE_ACTIVITY_URGENT_ONLY,
277 FALSE);
280 * Status list entries for primitive type AWAY
282 * 12: Away - special case: needs to go first in the list as purple
283 * picks the first status with primitive type AWAY for idle
285 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
286 SIPE_ACTIVITY_AWAY,
287 TRUE);
289 /* 13: Be Right Back */
290 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
291 SIPE_ACTIVITY_BRB,
292 TRUE);
294 /* 14: Out to lunch */
295 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
296 SIPE_ACTIVITY_LUNCH,
297 FALSE);
300 * Status list entries for primitive type EXTENDED_AWAY
302 * 15: Out of office */
303 SIPE_ADD_STATUS(PURPLE_STATUS_EXTENDED_AWAY,
304 SIPE_ACTIVITY_OOF,
305 FALSE);
308 * Status list entries for primitive type INVISIBLE
310 * 16: Appear Offline */
311 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE,
312 SIPE_ACTIVITY_INVISIBLE,
313 TRUE);
316 * Status list entries for primitive type OFFLINE
318 * NOTE: this is always the last entry. Compare the number
319 * with the comment in activity_to_purple_map[].
321 * 17: Offline - special case: no message text */
322 type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
323 NULL,
324 NULL,
325 TRUE);
326 types = g_list_append(types, type);
328 return types;
331 static GList *sipe_purple_blist_node_menu(PurpleBlistNode *node)
333 if (PURPLE_IS_BUDDY(node))
335 return sipe_purple_buddy_menu((PurpleBuddy *) node);
336 } else
337 if (PURPLE_IS_CHAT(node))
339 return sipe_purple_chat_menu((PurpleChat *)node);
340 } else {
341 return NULL;
345 static guint get_authentication_type(PurpleAccount *account)
347 const gchar *auth = purple_account_get_string(account, "authentication", "ntlm");
349 /* map option list to type - default is automatic */
350 guint authentication_type = SIPE_AUTHENTICATION_TYPE_AUTOMATIC;
351 if (sipe_strequal(auth, "ntlm")) {
352 authentication_type = SIPE_AUTHENTICATION_TYPE_NTLM;
353 } else
354 #if PURPLE_SIPE_SSO_AND_KERBEROS
355 if (sipe_strequal(auth, "krb5")) {
356 authentication_type = SIPE_AUTHENTICATION_TYPE_KERBEROS;
357 } else
358 #endif
359 if (sipe_strequal(auth, "tls-dsk")) {
360 authentication_type = SIPE_AUTHENTICATION_TYPE_TLS_DSK;
363 return(authentication_type);
366 static gboolean get_sso_flag(PurpleAccount *account)
368 #if PURPLE_SIPE_SSO_AND_KERBEROS
370 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
371 * SIPE that it is OK to use Single Sign-On or not.
373 return(purple_account_get_bool(account, "sso", FALSE));
374 #else
375 (void) account; /* keep compiler happy */
376 return(FALSE);
377 #endif
380 static gboolean get_dont_publish_flag(PurpleAccount *account)
382 /* default is to publish calendar information */
383 return(purple_account_get_bool(account, "dont-publish", FALSE));
386 static void connect_to_core(PurpleConnection *gc,
387 PurpleAccount *account,
388 const gchar *password)
390 const gchar *username = purple_account_get_username(account);
391 const gchar *email = purple_account_get_string(account, "email", NULL);
392 const gchar *email_url = purple_account_get_string(account, "email_url", NULL);
393 const gchar *transport = purple_account_get_string(account, "transport", "auto");
394 struct sipe_core_public *sipe_public;
395 gchar **username_split;
396 const gchar *errmsg;
397 guint transport_type;
398 struct sipe_backend_private *purple_private;
400 /* username format: <username>,[<optional login>] */
401 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username);
402 username_split = g_strsplit(username, ",", 2);
404 sipe_public = sipe_core_allocate(username_split[0],
405 get_sso_flag(account),
406 username_split[1],
407 password,
408 email,
409 email_url,
410 &errmsg);
411 g_strfreev(username_split);
413 if (!sipe_public) {
414 purple_connection_error(gc,
415 PURPLE_CONNECTION_ERROR_INVALID_USERNAME,
416 errmsg);
417 return;
420 sipe_public->backend_private = purple_private = g_new0(struct sipe_backend_private, 1);
421 purple_private->public = sipe_public;
422 purple_private->gc = gc;
423 purple_private->account = account;
425 sipe_purple_chat_setup_rejoin(purple_private);
427 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH);
428 if (get_dont_publish_flag(account))
429 SIPE_CORE_FLAG_SET(DONT_PUBLISH);
431 purple_connection_set_protocol_data(gc, sipe_public);
432 purple_connection_set_flags(gc,
433 purple_connection_get_flags(gc) |
434 PURPLE_CONNECTION_FLAG_HTML |
435 PURPLE_CONNECTION_FLAG_FORMATTING_WBFO |
436 PURPLE_CONNECTION_FLAG_NO_BGCOLOR |
437 PURPLE_CONNECTION_FLAG_NO_FONTSIZE |
438 PURPLE_CONNECTION_FLAG_NO_URLDESC |
439 PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY);
440 purple_connection_set_display_name(gc, sipe_public->sip_name);
441 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
443 username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2);
444 if (sipe_strequal(transport, "auto")) {
445 transport_type = (username_split[0] == NULL) ?
446 SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS;
447 } else if (sipe_strequal(transport, "tls")) {
448 transport_type = SIPE_TRANSPORT_TLS;
449 } else {
450 transport_type = SIPE_TRANSPORT_TCP;
452 sipe_core_transport_sip_connect(sipe_public,
453 transport_type,
454 get_authentication_type(account),
455 username_split[0],
456 username_split[0] ? username_split[1] : NULL);
457 g_strfreev(username_split);
460 static void password_required_cb(PurpleConnection *gc,
461 SIPE_UNUSED_PARAMETER PurpleRequestFields *fields)
463 #if !PURPLE_VERSION_CHECK(3,0,0)
464 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
465 return;
467 #endif
469 purple_connection_error(gc,
470 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
471 _("Password required"));
474 static void password_ok_cb(PurpleConnection *gc,
475 PurpleRequestFields *fields)
477 const gchar *password;
479 #if !PURPLE_VERSION_CHECK(3,0,0)
480 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
481 return;
483 #endif
485 password = purple_request_fields_get_string(fields, "password");
487 if (password && strlen(password)) {
488 PurpleAccount *account = purple_connection_get_account(gc);
490 if (purple_request_fields_get_bool(fields, "remember"))
491 purple_account_set_remember_password(account, TRUE);
492 purple_account_set_password(account, password
493 #if PURPLE_VERSION_CHECK(3,0,0)
494 , NULL, NULL
495 #endif
498 /* Now we have a password and we can connect */
499 connect_to_core(gc, account, password);
501 } else
502 /* reject an empty password */
503 password_required_cb(gc, fields);
506 static void sipe_purple_login(PurpleAccount *account)
508 PurpleConnection *gc = purple_account_get_connection(account);
509 const gchar *password = purple_connection_get_password(gc);
511 /* Password required? */
512 if (sipe_core_transport_sip_requires_password(get_authentication_type(account),
513 get_sso_flag(account)) &&
514 (!password || !strlen(password)))
515 /* No password set - request one from user */
516 purple_account_request_password(account,
517 G_CALLBACK(password_ok_cb),
518 G_CALLBACK(password_required_cb),
519 gc);
520 else
521 /* No password required or saved password - connect now */
522 connect_to_core(gc, account, password);
526 static void sipe_purple_close(PurpleConnection *gc)
528 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
530 if (sipe_public) {
531 struct sipe_backend_private *purple_private = sipe_public->backend_private;
533 sipe_core_deallocate(sipe_public);
535 /* anything left after that must be in pending state... */
536 sipe_purple_dns_query_cancel_all(purple_private);
537 sipe_purple_transport_close_all(purple_private);
539 if (purple_private->roomlist_map)
540 g_hash_table_destroy(purple_private->roomlist_map);
541 sipe_purple_chat_destroy_rejoin(purple_private);
542 g_free(purple_private);
543 purple_connection_set_protocol_data(gc, NULL);
547 #if PURPLE_VERSION_CHECK(3,0,0)
548 static int sipe_purple_send_im(PurpleConnection *gc, PurpleMessage *msg)
550 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
551 purple_message_get_recipient(msg),
552 purple_message_get_contents(msg));
553 return 1;
555 #else
556 static int sipe_purple_send_im(PurpleConnection *gc,
557 const char *who,
558 const char *what,
559 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags)
561 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who, what);
562 return 1;
564 #endif
566 static unsigned int sipe_purple_send_typing(PurpleConnection *gc,
567 const char *who,
568 PurpleIMTypingState state)
570 gboolean typing = (state == PURPLE_IM_TYPING);
572 /* only enable this debug output while testing
573 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
576 * libpurple calls this function with PURPLE_NOT_TYPING *after*
577 * calling sipe_purple_send_im() with the message. This causes
578 * SIPE core to send out two SIP messages to the same dialog in
579 * short succession without waiting for the response to the first
580 * one. Some servers then reject the first one with
582 * SIP/2.0 500 Stale CSeq Value
584 * which triggers a "message not delivered" error for the user.
586 * Work around this by filtering out PURPLE_NOT_TYPING events.
588 if (state != PURPLE_IM_NOT_TYPING)
589 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
590 who,
591 typing);
593 /* tell libpurple to send typing indications every 4 seconds */
594 return(typing ? 4 : 0);
597 static void sipe_purple_get_info(PurpleConnection *gc, const char *who)
599 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
600 who);
603 static void sipe_purple_add_permit(PurpleConnection *gc, const char *name)
605 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE);
608 static void sipe_purple_add_deny(PurpleConnection *gc, const char *name)
610 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, FALSE);
613 static void sipe_purple_alias_buddy(PurpleConnection *gc, const char *name,
614 const char *alias)
616 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, alias);
619 static void sipe_purple_group_rename(PurpleConnection *gc,
620 const char *old_name,
621 PurpleGroup *group,
622 SIPE_UNUSED_PARAMETER GList *moved_buddies)
624 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
625 old_name,
626 purple_group_get_name(group));
629 static void sipe_purple_convo_closed(PurpleConnection *gc,
630 const char *who)
632 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who);
635 static void sipe_purple_group_remove(PurpleConnection *gc, PurpleGroup *group)
637 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
638 purple_group_get_name(group));
641 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
642 static GHashTable *
643 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount *account)
645 GHashTable *table;
646 table = g_hash_table_new(g_str_hash, g_str_equal);
647 g_hash_table_insert(table, "login_label", (gpointer)_("user@company.com"));
648 return table;
651 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
652 #ifdef HAVE_VV
654 static void
655 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER int signum)
657 capture_pipeline("PURPLE_SIPE_PIPELINE");
660 static gboolean sipe_purple_initiate_media(PurpleAccount *account, const char *who,
661 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type)
663 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
664 who,
665 (type & PURPLE_MEDIA_VIDEO));
666 return TRUE;
669 static PurpleMediaCaps sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount *account,
670 SIPE_UNUSED_PARAMETER const char *who)
672 return PURPLE_MEDIA_CAPS_AUDIO
673 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
674 | PURPLE_MEDIA_CAPS_MODIFY_SESSION;
676 #endif
677 #endif
678 #endif
681 * Simplistic source upward compatibility path for newer libpurple APIs
683 * Usually we compile with -Werror=missing-field-initializers if GCC supports
684 * it. But that means that the compilation of this structure can fail if the
685 * newer API has added additional plugin callbacks. For the benefit of the
686 * user we downgrade it to a warning here.
688 * Diagnostic #pragma was added in GCC 4.2.0
689 * Diagnostic push/pop was added in GCC 4.6.0
691 #ifdef __GNUC__
692 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || (__GNUC__ >= 5)
693 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ >= 5)
694 #pragma GCC diagnostic push
695 #endif
696 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
697 #endif
698 #endif
699 static PurplePluginProtocolInfo sipe_prpl_info =
701 #if PURPLE_VERSION_CHECK(3,0,0)
702 sizeof(PurplePluginProtocolInfo), /* struct_size */
703 #endif
704 OPT_PROTO_CHAT_TOPIC |
705 OPT_PROTO_PASSWORD_OPTIONAL,
706 NULL, /* user_splits */
707 NULL, /* protocol_options */
708 NO_BUDDY_ICONS, /* icon_spec */
709 sipe_list_icon, /* list_icon */
710 NULL, /* list_emblems */
711 sipe_purple_status_text, /* status_text */
712 sipe_purple_tooltip_text, /* tooltip_text */ // add custom info to contact tooltip
713 sipe_purple_status_types, /* away_states */
714 sipe_purple_blist_node_menu, /* blist_node_menu */
715 sipe_purple_chat_info, /* chat_info */
716 sipe_purple_chat_info_defaults, /* chat_info_defaults */
717 sipe_purple_login, /* login */
718 sipe_purple_close, /* close */
719 sipe_purple_send_im, /* send_im */
720 NULL, /* set_info */ // TODO maybe
721 sipe_purple_send_typing, /* send_typing */
722 sipe_purple_get_info, /* get_info */
723 sipe_purple_set_status, /* set_status */
724 sipe_purple_set_idle, /* set_idle */
725 NULL, /* change_passwd */
726 sipe_purple_add_buddy, /* add_buddy */
727 NULL, /* add_buddies */
728 sipe_purple_remove_buddy, /* remove_buddy */
729 NULL, /* remove_buddies */
730 sipe_purple_add_permit, /* add_permit */
731 sipe_purple_add_deny, /* add_deny */
732 sipe_purple_add_deny, /* rem_permit */
733 sipe_purple_add_permit, /* rem_deny */
734 NULL, /* set_permit_deny */
735 sipe_purple_chat_join, /* join_chat */
736 NULL, /* reject_chat */
737 NULL, /* get_chat_name */
738 sipe_purple_chat_invite, /* chat_invite */
739 sipe_purple_chat_leave, /* chat_leave */
740 #if !PURPLE_VERSION_CHECK(3,0,0)
741 NULL, /* chat_whisper */
742 #endif
743 sipe_purple_chat_send, /* chat_send */
744 NULL, /* keepalive */
745 NULL, /* register_user */
746 NULL, /* get_cb_info */ // deprecated
747 #if !PURPLE_VERSION_CHECK(3,0,0)
748 NULL, /* get_cb_away */ // deprecated
749 #endif
750 sipe_purple_alias_buddy, /* alias_buddy */
751 sipe_purple_group_buddy, /* group_buddy */
752 sipe_purple_group_rename, /* rename_group */
753 NULL, /* buddy_free */
754 sipe_purple_convo_closed, /* convo_closed */
755 purple_normalize_nocase, /* normalize */
756 NULL, /* set_buddy_icon */
757 sipe_purple_group_remove, /* remove_group */
758 NULL, /* get_cb_real_name */ // TODO?
759 NULL, /* set_chat_topic */
760 NULL, /* find_blist_chat */
761 sipe_purple_roomlist_get_list, /* roomlist_get_list */
762 sipe_purple_roomlist_cancel, /* roomlist_cancel */
763 NULL, /* roomlist_expand_category */
764 NULL, /* can_receive_file */
765 sipe_purple_ft_send_file, /* send_file */
766 sipe_purple_ft_new_xfer, /* new_xfer */
767 NULL, /* offline_message */
768 NULL, /* whiteboard_prpl_ops */
769 NULL, /* send_raw */
770 NULL, /* roomlist_room_serialize */
771 NULL, /* unregister_user */
772 NULL, /* send_attention */
773 NULL, /* get_attention_types */
774 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
775 /* Backward compatibility when compiling against 2.4.x API */
776 (void (*)(void)) /* _purple_reserved4 */
777 #endif
778 #if !PURPLE_VERSION_CHECK(3,0,0)
779 sizeof(PurplePluginProtocolInfo), /* struct_size */
780 #endif
781 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
782 sipe_purple_get_account_text_table, /* get_account_text_table */
783 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
784 #ifdef HAVE_VV
785 sipe_purple_initiate_media, /* initiate_media */
786 sipe_purple_get_media_caps, /* get_media_caps */
787 #else
788 NULL, /* initiate_media */
789 NULL, /* get_media_caps */
790 #endif
791 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
792 NULL, /* get_moods */
793 NULL, /* set_public_alias */
794 NULL, /* get_public_alias */
795 #if PURPLE_VERSION_CHECK(2,8,0)
796 NULL, /* add_buddy_with_invite */
797 NULL, /* add_buddies_with_invite */
798 #elif PURPLE_VERSION_CHECK(3,0,0)
799 NULL, /* get_max_message_size */
800 #endif
801 #endif
802 #endif
803 #endif
805 #ifdef __GNUC__
806 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ >= 5)
807 #pragma GCC diagnostic pop
808 #endif
809 #endif
810 /* Original GCC error checking restored from here on... (see above) */
812 /* PurplePluginInfo function calls & data structure */
813 static gboolean sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
815 #ifdef HAVE_VV
816 struct sigaction action;
817 memset(&action, 0, sizeof (action));
818 action.sa_handler = sipe_purple_sigusr1_handler;
819 sigaction(SIGUSR1, &action, NULL);
820 #endif
821 return TRUE;
824 static gboolean sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
826 #ifdef HAVE_VV
827 struct sigaction action;
828 memset(&action, 0, sizeof (action));
829 action.sa_handler = SIG_DFL;
830 sigaction(SIGUSR1, &action, NULL);
831 #endif
832 return TRUE;
835 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
837 GList *entry;
839 sipe_purple_activity_shutdown();
840 sipe_core_destroy();
842 entry = sipe_prpl_info.protocol_options;
843 while (entry) {
844 purple_account_option_destroy(entry->data);
845 entry = g_list_delete_link(entry, entry);
847 sipe_prpl_info.protocol_options = NULL;
849 entry = sipe_prpl_info.user_splits;
850 while (entry) {
851 purple_account_user_split_destroy(entry->data);
852 entry = g_list_delete_link(entry, entry);
854 sipe_prpl_info.user_splits = NULL;
857 static void sipe_purple_show_about_plugin(PurplePluginAction *action)
859 gchar *tmp = sipe_core_about();
860 purple_notify_formatted((PurpleConnection *) action->context,
861 NULL, " ", NULL, tmp, NULL, NULL);
862 g_free(tmp);
865 static void sipe_purple_join_conference_cb(PurpleConnection *gc,
866 PurpleRequestFields *fields)
868 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
870 if (entries) {
871 PurpleRequestField *field = entries->data;
872 const char *id = purple_request_field_get_id(field);
873 const char *value = purple_request_field_string_get_value(field);
875 if (!sipe_strequal(id, "meetingLocation"))
876 return;
878 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC, value);
882 #ifdef HAVE_VV
884 static void sipe_purple_phone_call_cb(PurpleConnection *gc,
885 PurpleRequestFields *fields)
887 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
889 if (entries) {
890 PurpleRequestField *field = entries->data;
891 const char *id = purple_request_field_get_id(field);
892 const char *value = purple_request_field_string_get_value(field);
894 if (!sipe_strequal(id, "phoneNumber"))
895 return;
897 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC, value);
901 static void sipe_purple_phone_call(PurplePluginAction *action)
903 PurpleConnection *gc = (PurpleConnection *) action->context;
904 PurpleRequestFields *fields;
905 PurpleRequestFieldGroup *group;
906 PurpleRequestField *field;
908 fields = purple_request_fields_new();
909 group = purple_request_field_group_new(NULL);
910 purple_request_fields_add_group(fields, group);
912 field = purple_request_field_string_new("phoneNumber", _("Phone number"), NULL, FALSE);
913 purple_request_field_group_add_field(group, field);
915 purple_request_fields(gc,
916 _("Call a phone number"),
917 _("Call a phone number"),
918 NULL,
919 fields,
920 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb),
921 _("_Cancel"), NULL,
922 #if PURPLE_VERSION_CHECK(3,0,0)
923 purple_request_cpar_from_connection(gc),
924 #else
925 purple_connection_get_account(gc), NULL, NULL,
926 #endif
927 gc);
930 static void sipe_purple_test_call(PurplePluginAction *action)
932 PurpleConnection *gc = (PurpleConnection *) action->context;
933 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
935 #endif
937 static void sipe_purple_show_join_conference(PurplePluginAction *action)
939 PurpleConnection *gc = (PurpleConnection *) action->context;
940 PurpleRequestFields *fields;
941 PurpleRequestFieldGroup *group;
942 PurpleRequestField *field;
944 fields = purple_request_fields_new();
945 group = purple_request_field_group_new(NULL);
946 purple_request_fields_add_group(fields, group);
948 field = purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL, FALSE);
949 purple_request_field_group_add_field(group, field);
951 purple_request_fields(gc,
952 _("Join conference"),
953 _("Join scheduled conference"),
954 _("Enter meeting location string you received in the invitation.\n"
955 "\n"
956 "Valid location will be something like\n"
957 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
958 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
959 "or\n"
960 "https://meet.company.com/someone/abcdef1234"),
961 fields,
962 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb),
963 _("_Cancel"), NULL,
964 #if PURPLE_VERSION_CHECK(3,0,0)
965 purple_request_cpar_from_connection(gc),
966 #else
967 purple_connection_get_account(gc), NULL, NULL,
968 #endif
969 gc);
972 static void sipe_purple_republish_calendar(PurplePluginAction *action)
974 PurpleConnection *gc = (PurpleConnection *) action->context;
975 PurpleAccount *account = purple_connection_get_account(gc);
977 if (get_dont_publish_flag(account)) {
978 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
979 _("Publishing of calendar information has been disabled"),
980 NULL);
981 } else {
982 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
986 static void sipe_purple_reset_status(PurplePluginAction *action)
988 PurpleConnection *gc = (PurpleConnection *) action->context;
989 PurpleAccount *account = purple_connection_get_account(gc);
991 if (get_dont_publish_flag(account)) {
992 sipe_backend_notify_error(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
993 _("Publishing of calendar information has been disabled"),
994 NULL);
995 } else {
996 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
1000 static GList *sipe_purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin *plugin,
1001 SIPE_UNUSED_PARAMETER gpointer context)
1003 GList *menu = NULL;
1004 PurplePluginAction *act;
1006 act = purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin);
1007 menu = g_list_prepend(menu, act);
1009 act = purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact);
1010 menu = g_list_prepend(menu, act);
1012 #ifdef HAVE_VV
1013 act = purple_plugin_action_new(_("Call a phone number..."), sipe_purple_phone_call);
1014 menu = g_list_prepend(menu, act);
1016 act = purple_plugin_action_new(_("Test call"), sipe_purple_test_call);
1017 menu = g_list_prepend(menu, act);
1018 #endif
1020 act = purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference);
1021 menu = g_list_prepend(menu, act);
1023 act = purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar);
1024 menu = g_list_prepend(menu, act);
1026 act = purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status);
1027 menu = g_list_prepend(menu, act);
1029 return g_list_reverse(menu);
1032 static PurplePluginInfo sipe_purple_info = {
1033 PURPLE_PLUGIN_MAGIC,
1034 PURPLE_MAJOR_VERSION,
1035 PURPLE_MINOR_VERSION,
1036 PURPLE_PLUGIN_PROTOCOL, /**< type */
1037 NULL, /**< ui_requirement */
1038 0, /**< flags */
1039 NULL, /**< dependencies */
1040 PURPLE_PRIORITY_DEFAULT, /**< priority */
1041 "prpl-sipe", /**< id */
1042 "Office Communicator", /**< name */
1043 PACKAGE_VERSION, /**< version */
1044 "Microsoft Office Communicator Protocol Plugin", /**< summary */
1045 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
1046 "Microsoft Live/Office Communications/Lync Server (LCS2005/OCS2007+)", /**< description */
1047 "Stefan Becker <chemobejk@gmail.com>, " /**< author */
1048 "Jakub Adam <jakub.adam@tieto.com>, " /**< author */
1049 "Anibal Avelar <avelar@gmail.com> (retired), " /**< author */
1050 "pier11 <pier11@operamail.com> (retired), " /**< author */
1051 "Gabriel Burt <gburt@novell.com> (retired)", /**< author */
1052 PACKAGE_URL, /**< homepage */
1053 sipe_purple_plugin_load, /**< load */
1054 sipe_purple_plugin_unload, /**< unload */
1055 sipe_purple_plugin_destroy, /**< destroy */
1056 NULL, /**< ui_info */
1057 &sipe_prpl_info, /**< extra_info */
1058 NULL,
1059 sipe_purple_actions,
1060 NULL,
1061 NULL,
1062 NULL,
1063 NULL
1066 static void sipe_purple_init_plugin(PurplePlugin *plugin)
1068 PurpleAccountUserSplit *split;
1069 PurpleAccountOption *option;
1071 /* This needs to be called first */
1072 sipe_core_init(LOCALEDIR);
1073 sipe_purple_activity_init();
1075 purple_plugin_register(plugin);
1078 * When adding new string settings please make sure to keep these
1079 * in sync:
1081 * api/sipe-backend.h
1082 * purple-settings.c:setting_name[]
1084 split = purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL, ',');
1085 purple_account_user_split_set_reverse(split, FALSE);
1086 sipe_prpl_info.user_splits = g_list_append(sipe_prpl_info.user_splits, split);
1088 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
1089 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1091 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
1092 purple_account_option_add_list_item(option, _("Auto"), "auto");
1093 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
1094 purple_account_option_add_list_item(option, _("TCP"), "tcp");
1095 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1097 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
1098 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
1100 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
1101 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1103 option = purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL);
1104 purple_account_option_add_list_item(option, _("Auto"), "auto");
1105 purple_account_option_add_list_item(option, _("NTLM"), "ntlm");
1106 #if PURPLE_SIPE_SSO_AND_KERBEROS
1107 purple_account_option_add_list_item(option, _("Kerberos"), "krb5");
1108 #endif
1109 purple_account_option_add_list_item(option, _("TLS-DSK"), "tls-dsk");
1110 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1112 #if PURPLE_SIPE_SSO_AND_KERBEROS
1114 * When the user selects Single Sign-On then SIPE will ignore the
1115 * settings for "login name" and "password". Instead it will use the
1116 * default credentials provided by the OS.
1118 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
1119 * SIPE that it is OK to use Single Sign-On or not.
1121 * Configurations that are known to support Single Sign-On:
1123 * - Windows, host joined to domain, SIPE with SSPI: NTLM
1124 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
1125 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
1127 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE);
1128 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1129 #endif
1131 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
1132 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
1134 option = purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE);
1135 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1137 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
1138 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1140 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
1141 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1143 /** Example (Exchange): DOMAIN\user or user@company.com
1144 * Example (Domino) : email_address
1146 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
1147 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1149 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
1150 purple_account_option_string_set_masked(option, TRUE);
1151 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1153 /** Example (federated domain): company.com (i.e. ocschat@company.com)
1154 * Example (non-default user): user@company.com
1156 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", "");
1157 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);
1160 /* This macro makes the code a purple plugin */
1161 PURPLE_INIT_PLUGIN(sipe, sipe_purple_init_plugin, sipe_purple_info);
1164 Local Variables:
1165 mode: c
1166 c-file-style: "bsd"
1167 indent-tabs-mode: t
1168 tab-width: 8
1169 End: