purple: make status reset function public
[siplcs.git] / src / purple / purple-plugin-common.c
blob1b43316550c59f6c7c4dc2e94b0e0c989a3e2527
1 /**
2 * @file purple-plugin-common.c
4 * pidgin-sipe
6 * Copyright (C) 2010-2017 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 <glib.h>
28 #include <string.h>
30 #include "sipe-common.h"
32 #include "account.h"
33 #include "accountopt.h"
34 #include "core.h"
35 #include "notify.h"
36 #include "request.h"
37 #include "version.h"
39 #ifdef HAVE_DBUS
40 #include "purple-dbus.h"
41 #endif
43 /* Backward compatibility when compiling against 2.4.x API */
44 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
45 #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100
46 #endif
48 #if PURPLE_VERSION_CHECK(3,0,0)
49 #define PURPLE_TYPE_STRING G_TYPE_STRING
50 #define SIPE_PURPLE_ACTION_TO_CONNECTION action->connection
51 #else
52 #include "blist.h"
53 #define g_source_remove(t) purple_timeout_remove(t)
54 #define PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
55 #define PURPLE_CONNECTION_FLAG_FORMATTING_WBFO PURPLE_CONNECTION_FORMATTING_WBFO
56 #define PURPLE_CONNECTION_FLAG_HTML PURPLE_CONNECTION_HTML
57 #define PURPLE_CONNECTION_FLAG_NO_BGCOLOR PURPLE_CONNECTION_NO_BGCOLOR
58 #define PURPLE_CONNECTION_FLAG_NO_FONTSIZE PURPLE_CONNECTION_NO_FONTSIZE
59 #define PURPLE_CONNECTION_FLAG_NO_URLDESC PURPLE_CONNECTION_NO_URLDESC
60 #define PURPLE_IS_BUDDY(n) PURPLE_BLIST_NODE_IS_BUDDY(n)
61 #define PURPLE_IS_CHAT(n) PURPLE_BLIST_NODE_IS_CHAT(n)
62 #define PURPLE_IM_TYPING PURPLE_TYPING
63 #define PURPLE_IM_NOT_TYPING PURPLE_NOT_TYPING
64 #define purple_account_option_string_set_masked(o, f) purple_account_option_set_masked(o, f)
65 #define purple_connection_error(g, e, m) purple_connection_error_reason(g, e, m)
66 #define purple_connection_get_flags(gc) 0
67 #define purple_connection_set_protocol_data(gc, p) gc->proto_data = p
68 #define purple_connection_set_flags(gc, f) gc->flags |= f
69 #define purple_protocol_action_new(l, c) purple_plugin_action_new(l, c)
70 #define PurpleProtocolAction PurplePluginAction
71 #define SIPE_PURPLE_ACTION_TO_CONNECTION action->context
72 #endif
74 #include "sipe-backend.h"
75 #include "sipe-core.h"
76 #include "sipe-nls.h"
78 #include "purple-private.h"
81 * NOTE: this flag means two things:
83 * - is Single Sign-On supported, and
84 * - is Kerberos supported
86 #if defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_SSPI)
87 #define PURPLE_SIPE_SSO_AND_KERBEROS 1
88 #else
89 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
90 #endif
93 * SIPE core activity <-> Purple status mapping
95 * NOTE: this needs to be kept in sync with sipe_purple_status_types()
97 static const gchar * const activity_to_purple_map[SIPE_ACTIVITY_NUM_TYPES] = {
98 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
99 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
100 /* SIPE_ACTIVITY_ONLINE */ "online",
101 /* SIPE_ACTIVITY_INACTIVE */ "idle",
102 /* SIPE_ACTIVITY_BUSY */ "busy",
103 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
104 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
105 /* SIPE_ACTIVITY_BRB */ "be-right-back",
106 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
107 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
108 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
109 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
110 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
111 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
112 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
113 /* SIPE_ACTIVITY_OOF */ "out-of-office",
114 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
115 /* SIPE_ACTIVIY_NUM_TYPES == 17 -> compare to sipe_purple_status_types() */
118 GHashTable *purple_token_map;
120 static void sipe_purple_activity_init(void)
122 guint index;
124 purple_token_map = g_hash_table_new(g_str_hash, g_str_equal);
125 for (index = SIPE_ACTIVITY_UNSET;
126 index < SIPE_ACTIVITY_NUM_TYPES;
127 index++) {
128 g_hash_table_insert(purple_token_map,
129 (gchar *) activity_to_purple_map[index],
130 GUINT_TO_POINTER(index));
134 static void sipe_purple_activity_shutdown(void)
136 g_hash_table_destroy(purple_token_map);
139 const gchar *sipe_purple_activity_to_token(guint type)
141 return(activity_to_purple_map[type]);
144 guint sipe_purple_token_to_activity(const gchar *token)
146 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map, token)));
149 gchar *sipe_backend_version(void)
151 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
154 const char *sipe_purple_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount *a,
155 SIPE_UNUSED_PARAMETER PurpleBuddy *b)
157 return "sipe";
160 gchar *sipe_purple_status_text(PurpleBuddy *buddy)
162 const PurpleStatus *status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
163 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
164 purple_buddy_get_name(buddy),
165 sipe_purple_token_to_activity(purple_status_get_id(status)),
166 purple_status_get_name(status));
169 void sipe_purple_tooltip_text(PurpleBuddy *buddy,
170 PurpleNotifyUserInfo *user_info,
171 SIPE_UNUSED_PARAMETER gboolean full)
173 const PurplePresence *presence = purple_buddy_get_presence(buddy);
174 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
175 purple_buddy_get_name(buddy),
176 purple_status_get_name(purple_presence_get_active_status(presence)),
177 purple_presence_is_online(presence),
178 (struct sipe_backend_buddy_tooltip *) user_info);
181 GList *sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount *acc)
183 PurpleStatusType *type;
184 GList *types = NULL;
186 /* Macro to reduce code repetition
187 Translators: noun */
188 #define SIPE_ADD_STATUS(prim,activity,user) type = purple_status_type_new_with_attrs( \
189 prim, \
190 sipe_purple_activity_to_token(activity), \
191 sipe_core_activity_description(activity), \
192 TRUE, user, FALSE, \
193 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
194 NULL); \
195 types = g_list_append(types, type);
198 * NOTE: needs to be kept in sync with activity_to_purple_map[],
199 * i.e. for each SIPE_ACTIVITY_xxx value there must be an
200 * entry on this list.
202 * NOTE: the following code is sorted by purple primitive type not
203 * by SIPE_ACTIVITY_xxx value.
206 /* 1: Unset - special case: no entry needed */
209 * Status list entries for primitive type AVAILABLE
211 * 2: Available */
212 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
213 SIPE_ACTIVITY_AVAILABLE,
214 TRUE);
216 /* 3: Online */
217 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
218 SIPE_ACTIVITY_ONLINE,
219 FALSE);
221 /* 4: Inactive (Idle) */
222 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
223 SIPE_ACTIVITY_INACTIVE,
224 FALSE);
227 * Status list entries for primitive type UNAVAILABLE
229 * 5: Busy */
230 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
231 SIPE_ACTIVITY_BUSY,
232 TRUE);
234 /* 6: Busy-Idle */
235 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
236 SIPE_ACTIVITY_BUSYIDLE,
237 FALSE);
239 /* 7: Do Not Disturb */
240 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
241 SIPE_ACTIVITY_DND,
242 TRUE);
244 /* 8: In a call */
245 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
246 SIPE_ACTIVITY_ON_PHONE,
247 FALSE);
249 /* 9: In a conference call */
250 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
251 SIPE_ACTIVITY_IN_CONF,
252 FALSE);
254 /* 10: In a meeting */
255 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
256 SIPE_ACTIVITY_IN_MEETING,
257 FALSE);
259 /* 11: Urgent interruptions only */
260 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
261 SIPE_ACTIVITY_URGENT_ONLY,
262 FALSE);
265 * Status list entries for primitive type AWAY
267 * 12: Away - special case: needs to go first in the list as purple
268 * picks the first status with primitive type AWAY for idle
270 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
271 SIPE_ACTIVITY_AWAY,
272 TRUE);
274 /* 13: Be Right Back */
275 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
276 SIPE_ACTIVITY_BRB,
277 TRUE);
279 /* 14: Out to lunch */
280 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
281 SIPE_ACTIVITY_LUNCH,
282 FALSE);
285 * Status list entries for primitive type EXTENDED_AWAY
287 * 15: Out of office */
288 SIPE_ADD_STATUS(PURPLE_STATUS_EXTENDED_AWAY,
289 SIPE_ACTIVITY_OOF,
290 FALSE);
293 * Status list entries for primitive type INVISIBLE
295 * 16: Appear Offline */
296 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE,
297 SIPE_ACTIVITY_INVISIBLE,
298 TRUE);
301 * Status list entries for primitive type OFFLINE
303 * NOTE: this is always the last entry. Compare the number
304 * with the comment in activity_to_purple_map[].
306 * 17: Offline - special case: no message text */
307 type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
308 NULL,
309 NULL,
310 TRUE);
311 types = g_list_append(types, type);
313 return types;
316 GList *sipe_purple_blist_node_menu(PurpleBlistNode *node)
318 if (PURPLE_IS_BUDDY(node))
320 return sipe_purple_buddy_menu((PurpleBuddy *) node);
321 } else
322 if (PURPLE_IS_CHAT(node))
324 return sipe_purple_chat_menu((PurpleChat *)node);
325 } else {
326 return NULL;
330 static guint get_authentication_type(PurpleAccount *account)
332 const gchar *auth = purple_account_get_string(account, "authentication", "ntlm");
334 /* map option list to type - default is automatic */
335 guint authentication_type = SIPE_AUTHENTICATION_TYPE_AUTOMATIC;
336 if (sipe_strequal(auth, "ntlm")) {
337 authentication_type = SIPE_AUTHENTICATION_TYPE_NTLM;
338 } else
339 #if PURPLE_SIPE_SSO_AND_KERBEROS
340 if (sipe_strequal(auth, "krb5")) {
341 authentication_type = SIPE_AUTHENTICATION_TYPE_KERBEROS;
342 } else
343 #endif
344 if (sipe_strequal(auth, "tls-dsk")) {
345 authentication_type = SIPE_AUTHENTICATION_TYPE_TLS_DSK;
348 return(authentication_type);
351 static gboolean get_sso_flag(PurpleAccount *account)
353 #if PURPLE_SIPE_SSO_AND_KERBEROS
355 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
356 * SIPE that it is OK to use Single Sign-On or not.
358 return(purple_account_get_bool(account, "sso", FALSE));
359 #else
360 (void) account; /* keep compiler happy */
361 return(FALSE);
362 #endif
365 static gboolean get_dont_publish_flag(PurpleAccount *account)
367 /* default is to publish calendar information */
368 return(purple_account_get_bool(account, "dont-publish", FALSE));
371 static gboolean get_allow_web_photo_flag(PurpleAccount *account)
373 /* default is to not allow insecure download of buddy icons from web */
374 return purple_account_get_bool(account, "allow-web-photo", FALSE);
377 static void connect_to_core(PurpleConnection *gc,
378 PurpleAccount *account,
379 const gchar *password)
381 const gchar *username = purple_account_get_username(account);
382 const gchar *email = purple_account_get_string(account, "email", NULL);
383 const gchar *email_url = purple_account_get_string(account, "email_url", NULL);
384 const gchar *transport = purple_account_get_string(account, "transport", "auto");
385 struct sipe_core_public *sipe_public;
386 gchar **username_split;
387 const gchar *errmsg;
388 guint transport_type;
389 struct sipe_backend_private *purple_private;
391 /* username format: <username>,[<optional login>] */
392 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username);
393 username_split = g_strsplit(username, ",", 2);
395 sipe_public = sipe_core_allocate(username_split[0],
396 get_sso_flag(account),
397 username_split[1],
398 password,
399 email,
400 email_url,
401 &errmsg);
402 g_strfreev(username_split);
404 if (!sipe_public) {
405 purple_connection_error(gc,
406 PURPLE_CONNECTION_ERROR_INVALID_USERNAME,
407 errmsg);
408 return;
411 sipe_public->backend_private = purple_private = g_new0(struct sipe_backend_private, 1);
412 purple_private->public = sipe_public;
413 purple_private->gc = gc;
414 purple_private->account = account;
416 sipe_purple_chat_setup_rejoin(purple_private);
418 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH);
419 if (get_dont_publish_flag(account))
420 SIPE_CORE_FLAG_SET(DONT_PUBLISH);
421 SIPE_CORE_FLAG_UNSET(ALLOW_WEB_PHOTO);
422 if (get_allow_web_photo_flag(account))
423 SIPE_CORE_FLAG_SET(ALLOW_WEB_PHOTO);
425 purple_connection_set_protocol_data(gc, sipe_public);
426 purple_connection_set_flags(gc,
427 purple_connection_get_flags(gc) |
428 PURPLE_CONNECTION_FLAG_HTML |
429 PURPLE_CONNECTION_FLAG_FORMATTING_WBFO |
430 PURPLE_CONNECTION_FLAG_NO_BGCOLOR |
431 PURPLE_CONNECTION_FLAG_NO_FONTSIZE |
432 PURPLE_CONNECTION_FLAG_NO_URLDESC |
433 PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY);
434 purple_connection_set_display_name(gc, sipe_public->sip_name);
435 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
437 username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2);
438 if (sipe_strequal(transport, "auto")) {
439 transport_type = (username_split[0] == NULL) ?
440 SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS;
441 } else if (sipe_strequal(transport, "tls")) {
442 transport_type = SIPE_TRANSPORT_TLS;
443 } else {
444 transport_type = SIPE_TRANSPORT_TCP;
446 sipe_core_transport_sip_connect(sipe_public,
447 transport_type,
448 get_authentication_type(account),
449 username_split[0],
450 username_split[0] ? username_split[1] : NULL);
451 g_strfreev(username_split);
454 static void password_required_cb(PurpleConnection *gc,
455 SIPE_UNUSED_PARAMETER PurpleRequestFields *fields)
457 #if !PURPLE_VERSION_CHECK(3,0,0)
458 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
459 return;
461 #endif
463 purple_connection_error(gc,
464 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
465 _("Password required"));
468 static void password_ok_cb(PurpleConnection *gc,
469 PurpleRequestFields *fields)
471 const gchar *password;
473 #if !PURPLE_VERSION_CHECK(3,0,0)
474 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
475 return;
477 #endif
479 password = purple_request_fields_get_string(fields, "password");
481 if (password && strlen(password)) {
482 PurpleAccount *account = purple_connection_get_account(gc);
484 if (purple_request_fields_get_bool(fields, "remember"))
485 purple_account_set_remember_password(account, TRUE);
486 purple_account_set_password(account, password
487 #if PURPLE_VERSION_CHECK(3,0,0)
488 , NULL, NULL
489 #endif
492 /* Now we have a password and we can connect */
493 connect_to_core(gc, account, password);
495 } else
496 /* reject an empty password */
497 password_required_cb(gc, fields);
500 void sipe_purple_login(PurpleAccount *account)
502 PurpleConnection *gc = purple_account_get_connection(account);
503 const gchar *password = purple_connection_get_password(gc);
505 /* Password required? */
506 if (sipe_core_transport_sip_requires_password(get_authentication_type(account),
507 get_sso_flag(account)) &&
508 (!password || !strlen(password)))
509 /* No password set - request one from user */
510 purple_account_request_password(account,
511 G_CALLBACK(password_ok_cb),
512 G_CALLBACK(password_required_cb),
513 gc);
514 else
515 /* No password required or saved password - connect now */
516 connect_to_core(gc, account, password);
520 void sipe_purple_close(PurpleConnection *gc)
522 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
524 if (sipe_public) {
525 struct sipe_backend_private *purple_private = sipe_public->backend_private;
527 sipe_core_deallocate(sipe_public);
529 /* anything left after that must be in pending state... */
530 sipe_purple_dns_query_cancel_all(purple_private);
531 sipe_purple_transport_close_all(purple_private);
533 if (purple_private->roomlist_map)
534 g_hash_table_destroy(purple_private->roomlist_map);
535 sipe_purple_chat_destroy_rejoin(purple_private);
537 if (purple_private->deferred_status_timeout)
538 g_source_remove(purple_private->deferred_status_timeout);
539 g_free(purple_private->deferred_status_note);
541 g_free(purple_private);
542 purple_connection_set_protocol_data(gc, NULL);
546 unsigned int sipe_purple_send_typing(PurpleConnection *gc,
547 const char *who,
548 PurpleIMTypingState state)
550 gboolean typing = (state == PURPLE_IM_TYPING);
552 /* only enable this debug output while testing
553 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
556 * libpurple calls this function with PURPLE_NOT_TYPING *after*
557 * calling sipe_purple_send_im() with the message. This causes
558 * SIPE core to send out two SIP messages to the same dialog in
559 * short succession without waiting for the response to the first
560 * one. Some servers then reject the first one with
562 * SIP/2.0 500 Stale CSeq Value
564 * which triggers a "message not delivered" error for the user.
566 * Work around this by filtering out PURPLE_NOT_TYPING events.
568 if (state != PURPLE_IM_NOT_TYPING)
569 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
570 who,
571 typing);
573 /* tell libpurple to send typing indications every 4 seconds */
574 return(typing ? 4 : 0);
577 void sipe_purple_get_info(PurpleConnection *gc, const char *who)
579 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
580 who);
583 void sipe_purple_add_permit(PurpleConnection *gc, const char *name)
585 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE);
588 void sipe_purple_add_deny(PurpleConnection *gc, const char *name)
590 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, FALSE);
593 void sipe_purple_alias_buddy(PurpleConnection *gc, const char *name,
594 const char *alias)
596 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, alias);
599 void sipe_purple_group_rename(PurpleConnection *gc, const char *old_name,
600 PurpleGroup *group,
601 SIPE_UNUSED_PARAMETER GList *moved_buddies)
603 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
604 old_name,
605 purple_group_get_name(group));
608 void sipe_purple_convo_closed(PurpleConnection *gc, const char *who)
610 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who);
613 void sipe_purple_group_remove(PurpleConnection *gc, PurpleGroup *group)
615 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
616 purple_group_get_name(group));
619 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
620 GHashTable *
621 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount *account)
623 GHashTable *table;
624 table = g_hash_table_new(g_str_hash, g_str_equal);
625 g_hash_table_insert(table, "login_label", (gpointer)_("user@company.com"));
626 return table;
629 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
630 #ifdef HAVE_VV
632 static void
633 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER int signum)
635 capture_pipeline("PURPLE_SIPE_PIPELINE");
638 gboolean sipe_purple_initiate_media(PurpleAccount *account, const char *who,
639 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type)
641 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
642 who,
643 (type & PURPLE_MEDIA_VIDEO));
644 return TRUE;
647 PurpleMediaCaps sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount *account,
648 SIPE_UNUSED_PARAMETER const char *who)
650 return PURPLE_MEDIA_CAPS_AUDIO
651 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
652 | PURPLE_MEDIA_CAPS_MODIFY_SESSION;
654 #endif
655 #endif
656 #endif
658 /* PurplePluginInfo function calls & data structure */
659 gboolean sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
661 #ifdef HAVE_DBUS
662 if (purple_dbus_get_init_error() == NULL) {
663 SIPE_DEBUG_INFO_NOFORMAT("sipe_purple_plugin_load: registering D-Bus bindings");
664 purple_dbus_register_bindings(plugin, sipe_purple_dbus_bindings);
666 #endif
668 #ifdef HAVE_VV
670 struct sigaction action;
671 memset(&action, 0, sizeof (action));
672 action.sa_handler = sipe_purple_sigusr1_handler;
673 sigaction(SIGUSR1, &action, NULL);
675 #endif
677 sipe_purple_activity_init();
679 return TRUE;
682 gboolean sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
684 #ifdef HAVE_VV
685 struct sigaction action;
686 memset(&action, 0, sizeof (action));
687 action.sa_handler = SIG_DFL;
688 sigaction(SIGUSR1, &action, NULL);
689 #endif
691 sipe_purple_activity_shutdown();
693 return TRUE;
696 static void sipe_purple_show_about_plugin(PurpleProtocolAction *action)
698 gchar *tmp = sipe_core_about();
699 purple_notify_formatted(SIPE_PURPLE_ACTION_TO_CONNECTION,
700 NULL, " ", NULL, tmp, NULL, NULL);
701 g_free(tmp);
704 static void sipe_purple_join_conference_cb(PurpleConnection *gc,
705 PurpleRequestFields *fields)
707 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
709 if (entries) {
710 const gchar *location = purple_request_fields_get_string(fields,
711 "meetingLocation");
712 const gchar *organizer = purple_request_fields_get_string(fields,
713 "meetingOrganizer");
714 const gchar *meeting_id = purple_request_fields_get_string(fields,
715 "meetingID");
716 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
717 location,
718 organizer,
719 meeting_id);
723 #ifdef HAVE_VV
725 static void sipe_purple_phone_call_cb(PurpleConnection *gc,
726 PurpleRequestFields *fields)
728 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
730 if (entries)
731 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
732 purple_request_fields_get_string(fields,
733 "phoneNumber"));
736 static void sipe_purple_phone_call(PurpleProtocolAction *action)
738 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
739 PurpleRequestFields *fields;
740 PurpleRequestFieldGroup *group;
741 PurpleRequestField *field;
743 fields = purple_request_fields_new();
744 group = purple_request_field_group_new(NULL);
745 purple_request_fields_add_group(fields, group);
747 field = purple_request_field_string_new("phoneNumber", _("Phone number"), NULL, FALSE);
748 purple_request_field_group_add_field(group, field);
750 purple_request_fields(gc,
751 _("Call a phone number"),
752 _("Call a phone number"),
753 NULL,
754 fields,
755 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb),
756 _("_Cancel"), NULL,
757 #if PURPLE_VERSION_CHECK(3,0,0)
758 purple_request_cpar_from_connection(gc),
759 #else
760 purple_connection_get_account(gc), NULL, NULL,
761 #endif
762 gc);
765 static void sipe_purple_test_call(PurpleProtocolAction *action)
767 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
768 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
770 #endif
772 static void sipe_purple_show_join_conference(PurpleProtocolAction *action)
774 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
775 PurpleRequestFields *fields;
776 PurpleRequestFieldGroup *group;
777 PurpleRequestField *field;
779 fields = purple_request_fields_new();
780 group = purple_request_field_group_new(NULL);
781 purple_request_fields_add_group(fields, group);
783 field = purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL, FALSE);
784 purple_request_field_group_add_field(group, field);
785 field = purple_request_field_label_new("separator", _("Alternatively"));
786 purple_request_field_group_add_field(group, field);
787 field = purple_request_field_string_new("meetingOrganizer", _("Organizer email"), NULL, FALSE);
788 purple_request_field_group_add_field(group, field);
789 field = purple_request_field_string_new("meetingID", _("Meeting ID"), NULL, FALSE);
790 purple_request_field_group_add_field(group, field);
792 purple_request_fields(gc,
793 _("Join conference"),
794 _("Join scheduled conference"),
795 _("Enter meeting location string you received in the invitation.\n"
796 "\n"
797 "Valid location will be something like\n"
798 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
799 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
800 "or\n"
801 "https://meet.company.com/someone/abcdef1234"),
802 fields,
803 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb),
804 _("_Cancel"), NULL,
805 #if PURPLE_VERSION_CHECK(3,0,0)
806 purple_request_cpar_from_connection(gc),
807 #else
808 purple_connection_get_account(gc), NULL, NULL,
809 #endif
810 gc);
813 void sipe_purple_republish_calendar(PurpleAccount *account)
815 struct sipe_core_public *sipe_public = PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC;
816 if (get_dont_publish_flag(account)) {
817 sipe_backend_notify_error(sipe_public,
818 _("Publishing of calendar information has been disabled"),
819 NULL);
820 } else {
821 sipe_core_update_calendar(sipe_public);
825 static void sipe_purple_republish_calendar_action(PurpleProtocolAction *action)
827 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
828 PurpleAccount *account = purple_connection_get_account(gc);
829 sipe_purple_republish_calendar(account);
832 void sipe_purple_reset_status(PurpleAccount *account)
834 if (get_dont_publish_flag(account)) {
835 sipe_backend_notify_error(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
836 _("Publishing of calendar information has been disabled"),
837 NULL);
838 } else {
839 sipe_core_reset_status(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC);
843 static void sipe_purple_reset_status_action(PurpleProtocolAction *action)
845 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
846 PurpleAccount *account = purple_connection_get_account(gc);
847 sipe_purple_reset_status(account);
850 GList *sipe_purple_actions()
852 GList *menu = NULL;
853 PurpleProtocolAction *act;
855 act = purple_protocol_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin);
856 menu = g_list_prepend(menu, act);
858 act = purple_protocol_action_new(_("Contact search..."), sipe_purple_show_find_contact);
859 menu = g_list_prepend(menu, act);
861 #ifdef HAVE_VV
862 act = purple_protocol_action_new(_("Call a phone number..."), sipe_purple_phone_call);
863 menu = g_list_prepend(menu, act);
865 act = purple_protocol_action_new(_("Test call"), sipe_purple_test_call);
866 menu = g_list_prepend(menu, act);
867 #endif
869 act = purple_protocol_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference);
870 menu = g_list_prepend(menu, act);
872 act = purple_protocol_action_new(_("Republish Calendar"), sipe_purple_republish_calendar_action);
873 menu = g_list_prepend(menu, act);
875 act = purple_protocol_action_new(_("Reset status"), sipe_purple_reset_status_action);
876 menu = g_list_prepend(menu, act);
878 return g_list_reverse(menu);
881 GList * sipe_purple_account_options()
883 PurpleAccountOption *option;
884 GList *options = NULL;
887 * When adding new string settings please make sure to keep these
888 * in sync:
890 * api/sipe-backend.h
891 * purple-settings.c:setting_name[]
893 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
894 options = g_list_append(options, option);
896 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
897 purple_account_option_add_list_item(option, _("Auto"), "auto");
898 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
899 purple_account_option_add_list_item(option, _("TCP"), "tcp");
900 options = g_list_append(options, option);
902 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
903 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
905 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
906 options = g_list_append(options, option);
908 option = purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL);
909 purple_account_option_add_list_item(option, _("Auto"), "auto");
910 purple_account_option_add_list_item(option, _("NTLM"), "ntlm");
911 #if PURPLE_SIPE_SSO_AND_KERBEROS
912 purple_account_option_add_list_item(option, _("Kerberos"), "krb5");
913 #endif
914 purple_account_option_add_list_item(option, _("TLS-DSK"), "tls-dsk");
915 options = g_list_append(options, option);
917 #if PURPLE_SIPE_SSO_AND_KERBEROS
919 * When the user selects Single Sign-On then SIPE will ignore the
920 * settings for "login name" and "password". Instead it will use the
921 * default credentials provided by the OS.
923 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
924 * SIPE that it is OK to use Single Sign-On or not.
926 * Configurations that are known to support Single Sign-On:
928 * - Windows, host joined to domain, SIPE with SSPI: NTLM
929 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
930 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
932 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE);
933 options = g_list_append(options, option);
934 #endif
936 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
937 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
939 option = purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE);
940 options = g_list_append(options, option);
942 option = purple_account_option_bool_new(_("Show profile pictures from web\n(potentially dangerous)"), "allow-web-photo", FALSE);
943 options = g_list_append(options, option);
945 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
946 options = g_list_append(options, option);
948 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
949 options = g_list_append(options, option);
951 /** Example (Exchange): DOMAIN\user or user@company.com
952 * Example (Domino) : email_address
954 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
955 options = g_list_append(options, option);
957 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
958 purple_account_option_string_set_masked(option, TRUE);
959 options = g_list_append(options, option);
961 /** Example (federated domain): company.com (i.e. ocschat@company.com)
962 * Example (non-default user): user@company.com
964 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", "");
965 options = g_list_append(options, option);
967 #ifdef HAVE_APPSHARE
968 option = purple_account_option_string_new(_("Remote desktop client"), "rdp_client", "");
969 options = g_list_append(options, option);
970 #endif
972 #ifdef HAVE_SRTP
973 option = purple_account_option_list_new(_("Media encryption"), "encryption-policy", NULL);
974 purple_account_option_add_list_item(option, _("Obey server policy"), "obey-server");
975 purple_account_option_add_list_item(option, _("Always"), "required");
976 purple_account_option_add_list_item(option, _("Optional"), "optional");
977 purple_account_option_add_list_item(option, _("Disabled"), "disabled");
978 options = g_list_append(options, option);
979 #endif
981 return options;
984 gpointer sipe_purple_user_split()
986 PurpleAccountUserSplit *split =
987 purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL, ',');
988 purple_account_user_split_set_reverse(split, FALSE);
990 return split;
994 Local Variables:
995 mode: c
996 c-file-style: "bsd"
997 indent-tabs-mode: t
998 tab-width: 8
999 End: