Release 1.25.0 -- Buddy Idle Time, RTF
[siplcs.git] / src / purple / purple-plugin-common.c
blob2e624b4dff93788d337528fb2cf61d548a6fe741
1 /**
2 * @file purple-plugin-common.c
4 * pidgin-sipe
6 * Copyright (C) 2010-2019 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 #if PURPLE_VERSION_CHECK(3,0,0)
40 #include "action.h"
41 #define PURPLE_TYPE_STRING G_TYPE_STRING
42 #define SIPE_PURPLE_ACTION_TO_CONNECTION action->connection
43 #else
44 #include "blist.h"
45 #define g_source_remove(t) purple_timeout_remove(t)
46 #define PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
47 #define PURPLE_CONNECTION_FLAG_FORMATTING_WBFO PURPLE_CONNECTION_FORMATTING_WBFO
48 #define PURPLE_CONNECTION_FLAG_HTML PURPLE_CONNECTION_HTML
49 #define PURPLE_CONNECTION_FLAG_NO_BGCOLOR PURPLE_CONNECTION_NO_BGCOLOR
50 #define PURPLE_CONNECTION_FLAG_NO_FONTSIZE PURPLE_CONNECTION_NO_FONTSIZE
51 #define PURPLE_CONNECTION_FLAG_NO_URLDESC PURPLE_CONNECTION_NO_URLDESC
52 #define PURPLE_IS_BUDDY(n) PURPLE_BLIST_NODE_IS_BUDDY(n)
53 #define PURPLE_IS_CHAT(n) PURPLE_BLIST_NODE_IS_CHAT(n)
54 #define PURPLE_IM_TYPING PURPLE_TYPING
55 #define PURPLE_IM_NOT_TYPING PURPLE_NOT_TYPING
56 #define purple_account_option_string_set_masked(o, f) purple_account_option_set_masked(o, f)
57 #define purple_connection_error(g, e, m) purple_connection_error_reason(g, e, m)
58 #define purple_connection_get_flags(gc) 0
59 #define purple_connection_set_protocol_data(gc, p) gc->proto_data = p
60 #define purple_connection_set_flags(gc, f) gc->flags |= f
61 #define purple_protocol_action_new(l, c) purple_plugin_action_new(l, c)
62 #define PurpleProtocolAction PurplePluginAction
63 #define SIPE_PURPLE_ACTION_TO_CONNECTION action->context
64 #endif
66 #include "sipe-backend.h"
67 #include "sipe-core.h"
68 #include "sipe-nls.h"
70 #include "purple-private.h"
73 * NOTE: this flag means two things:
75 * - is Single Sign-On supported, and
76 * - is Kerberos supported
78 #if defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_SSPI)
79 #define PURPLE_SIPE_SSO_AND_KERBEROS 1
80 #else
81 #define PURPLE_SIPE_SSO_AND_KERBEROS 0
82 #endif
85 * SIPE core activity <-> Purple status mapping
87 * NOTE: this needs to be kept in sync with sipe_purple_status_types()
89 static const gchar * const activity_to_purple_map[SIPE_ACTIVITY_NUM_TYPES] = {
90 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
91 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
92 /* SIPE_ACTIVITY_ONLINE */ "online",
93 /* SIPE_ACTIVITY_INACTIVE */ "idle",
94 /* SIPE_ACTIVITY_BUSY */ "busy",
95 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
96 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
97 /* SIPE_ACTIVITY_BRB */ "be-right-back",
98 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
99 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
100 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
101 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
102 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
103 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
104 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
105 /* SIPE_ACTIVITY_OOF */ "out-of-office",
106 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
107 /* SIPE_ACTIVITY_IN_PRES */ "presenting",
108 /* SIPE_ACTIVIY_NUM_TYPES == 18 -> compare to sipe_purple_status_types() */
111 GHashTable *purple_token_map;
113 static void sipe_purple_activity_init(void)
115 guint index;
117 purple_token_map = g_hash_table_new(g_str_hash, g_str_equal);
118 for (index = SIPE_ACTIVITY_UNSET;
119 index < SIPE_ACTIVITY_NUM_TYPES;
120 index++) {
121 g_hash_table_insert(purple_token_map,
122 (gchar *) activity_to_purple_map[index],
123 GUINT_TO_POINTER(index));
127 static void sipe_purple_activity_shutdown(void)
129 g_hash_table_destroy(purple_token_map);
132 const gchar *sipe_purple_activity_to_token(guint type)
134 return(activity_to_purple_map[type]);
137 guint sipe_purple_token_to_activity(const gchar *token)
139 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map, token)));
142 gchar *sipe_backend_version(void)
144 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
147 const char *sipe_purple_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount *a,
148 SIPE_UNUSED_PARAMETER PurpleBuddy *b)
150 return "sipe";
153 gchar *sipe_purple_status_text(PurpleBuddy *buddy)
155 PurpleStatus *status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
156 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
157 purple_buddy_get_name(buddy),
158 sipe_purple_token_to_activity(purple_status_get_id(status)),
159 purple_status_get_name(status));
162 void sipe_purple_tooltip_text(PurpleBuddy *buddy,
163 PurpleNotifyUserInfo *user_info,
164 SIPE_UNUSED_PARAMETER gboolean full)
166 PurplePresence *presence = purple_buddy_get_presence(buddy);
167 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
168 purple_buddy_get_name(buddy),
169 purple_status_get_name(purple_presence_get_active_status(presence)),
170 purple_presence_is_online(presence),
171 (struct sipe_backend_buddy_tooltip *) user_info);
174 GList *sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount *acc)
176 PurpleStatusType *type;
177 GList *types = NULL;
179 /* Macro to reduce code repetition
180 Translators: noun */
181 #define SIPE_ADD_STATUS(prim,activity,user) type = purple_status_type_new_with_attrs( \
182 prim, \
183 sipe_purple_activity_to_token(activity), \
184 sipe_core_activity_description(activity), \
185 TRUE, user, FALSE, \
186 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
187 NULL); \
188 types = g_list_append(types, type);
191 * NOTE: needs to be kept in sync with activity_to_purple_map[],
192 * i.e. for each SIPE_ACTIVITY_xxx value there must be an
193 * entry on this list.
195 * NOTE: the following code is sorted by purple primitive type not
196 * by SIPE_ACTIVITY_xxx value.
199 /* 1: Unset - special case: no entry needed */
202 * Status list entries for primitive type AVAILABLE
204 * 2: Available */
205 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
206 SIPE_ACTIVITY_AVAILABLE,
207 TRUE);
209 /* 3: Online */
210 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
211 SIPE_ACTIVITY_ONLINE,
212 FALSE);
214 /* 4: Inactive (Idle) */
215 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE,
216 SIPE_ACTIVITY_INACTIVE,
217 FALSE);
220 * Status list entries for primitive type UNAVAILABLE
222 * 5: Busy */
223 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
224 SIPE_ACTIVITY_BUSY,
225 TRUE);
227 /* 6: Busy-Idle */
228 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
229 SIPE_ACTIVITY_BUSYIDLE,
230 FALSE);
232 /* 7: Do Not Disturb */
233 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
234 SIPE_ACTIVITY_DND,
235 TRUE);
237 /* 8: In a call */
238 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
239 SIPE_ACTIVITY_ON_PHONE,
240 FALSE);
242 /* 9: In a conference call */
243 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
244 SIPE_ACTIVITY_IN_CONF,
245 FALSE);
247 /* 10: In a meeting */
248 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
249 SIPE_ACTIVITY_IN_MEETING,
250 FALSE);
252 /* 11: Urgent interruptions only */
253 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
254 SIPE_ACTIVITY_URGENT_ONLY,
255 FALSE);
257 /* Presenting */
258 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE,
259 SIPE_ACTIVITY_IN_PRES,
260 FALSE);
263 * Status list entries for primitive type AWAY
265 * 12: Away - special case: needs to go first in the list as purple
266 * picks the first status with primitive type AWAY for idle
268 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
269 SIPE_ACTIVITY_AWAY,
270 TRUE);
272 /* 13: Be Right Back */
273 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
274 SIPE_ACTIVITY_BRB,
275 TRUE);
277 /* 14: Out to lunch */
278 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY,
279 SIPE_ACTIVITY_LUNCH,
280 FALSE);
283 * Status list entries for primitive type EXTENDED_AWAY
285 * 15: Out of office */
286 SIPE_ADD_STATUS(PURPLE_STATUS_EXTENDED_AWAY,
287 SIPE_ACTIVITY_OOF,
288 FALSE);
291 * Status list entries for primitive type INVISIBLE
293 * 16: Appear Offline */
294 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE,
295 SIPE_ACTIVITY_INVISIBLE,
296 TRUE);
299 * Status list entries for primitive type OFFLINE
301 * NOTE: this is always the last entry. Compare the number
302 * with the comment in activity_to_purple_map[].
304 * 17: Offline - special case: no message text */
305 type = purple_status_type_new(PURPLE_STATUS_OFFLINE,
306 NULL,
307 NULL,
308 TRUE);
309 types = g_list_append(types, type);
311 return types;
314 GList *sipe_purple_blist_node_menu(PurpleBlistNode *node)
316 if (PURPLE_IS_BUDDY(node))
318 return sipe_purple_buddy_menu((PurpleBuddy *) node);
319 } else
320 if (PURPLE_IS_CHAT(node))
322 return sipe_purple_chat_menu((PurpleChat *)node);
323 } else {
324 return NULL;
328 static guint get_authentication_type(PurpleAccount *account)
330 const gchar *auth = purple_account_get_string(account, "authentication", "ntlm");
332 /* map option list to type - default is automatic */
333 guint authentication_type = SIPE_AUTHENTICATION_TYPE_AUTOMATIC;
334 if (sipe_strequal(auth, "ntlm")) {
335 authentication_type = SIPE_AUTHENTICATION_TYPE_NTLM;
336 } else
337 #if PURPLE_SIPE_SSO_AND_KERBEROS
338 if (sipe_strequal(auth, "krb5")) {
339 authentication_type = SIPE_AUTHENTICATION_TYPE_KERBEROS;
340 } else
341 #endif
342 if (sipe_strequal(auth, "tls-dsk")) {
343 authentication_type = SIPE_AUTHENTICATION_TYPE_TLS_DSK;
346 return(authentication_type);
349 static gboolean get_sso_flag(PurpleAccount *account)
351 #if PURPLE_SIPE_SSO_AND_KERBEROS
353 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
354 * SIPE that it is OK to use Single Sign-On or not.
356 return(purple_account_get_bool(account, "sso", FALSE));
357 #else
358 (void) account; /* keep compiler happy */
359 return(FALSE);
360 #endif
363 static gboolean get_dont_publish_flag(PurpleAccount *account)
365 /* default is to publish calendar information */
366 return(purple_account_get_bool(account, "dont-publish", FALSE));
369 static gboolean get_allow_web_photo_flag(PurpleAccount *account)
371 /* default is to not allow insecure download of buddy icons from web */
372 return purple_account_get_bool(account, "allow-web-photo", FALSE);
375 static void connect_to_core(PurpleConnection *gc,
376 PurpleAccount *account,
377 const gchar *password)
379 const gchar *username = purple_account_get_username(account);
380 const gchar *email = purple_account_get_string(account, "email", NULL);
381 const gchar *email_url = purple_account_get_string(account, "email_url", NULL);
382 const gchar *transport = purple_account_get_string(account, "transport", "auto");
383 struct sipe_core_public *sipe_public;
384 gchar **username_split;
385 const gchar *errmsg;
386 guint transport_type;
387 struct sipe_backend_private *purple_private;
389 /* username format: <username>,[<optional login>] */
390 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username);
391 username_split = g_strsplit(username, ",", 2);
393 sipe_public = sipe_core_allocate(username_split[0],
394 get_sso_flag(account),
395 username_split[1],
396 password,
397 email,
398 email_url,
399 &errmsg);
400 g_strfreev(username_split);
402 if (!sipe_public) {
403 purple_connection_error(gc,
404 PURPLE_CONNECTION_ERROR_INVALID_USERNAME,
405 errmsg);
406 return;
409 sipe_public->backend_private = purple_private = g_new0(struct sipe_backend_private, 1);
410 purple_private->public = sipe_public;
411 purple_private->gc = gc;
412 purple_private->account = account;
414 sipe_purple_chat_setup_rejoin(purple_private);
416 SIPE_CORE_FLAG_UNSET(DONT_PUBLISH);
417 if (get_dont_publish_flag(account))
418 SIPE_CORE_FLAG_SET(DONT_PUBLISH);
419 SIPE_CORE_FLAG_UNSET(ALLOW_WEB_PHOTO);
420 if (get_allow_web_photo_flag(account))
421 SIPE_CORE_FLAG_SET(ALLOW_WEB_PHOTO);
423 purple_connection_set_protocol_data(gc, sipe_public);
424 purple_connection_set_flags(gc,
425 purple_connection_get_flags(gc) |
426 PURPLE_CONNECTION_FLAG_HTML |
427 PURPLE_CONNECTION_FLAG_FORMATTING_WBFO |
428 PURPLE_CONNECTION_FLAG_NO_BGCOLOR |
429 PURPLE_CONNECTION_FLAG_NO_FONTSIZE |
430 PURPLE_CONNECTION_FLAG_NO_URLDESC |
431 PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY);
432 purple_connection_set_display_name(gc, sipe_public->sip_name);
433 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
435 username_split = g_strsplit(purple_account_get_string(account, "server", ""), ":", 2);
436 if (sipe_strequal(transport, "auto")) {
437 transport_type = (username_split[0] == NULL) ?
438 SIPE_TRANSPORT_AUTO : SIPE_TRANSPORT_TLS;
439 } else if (sipe_strequal(transport, "tls")) {
440 transport_type = SIPE_TRANSPORT_TLS;
441 } else {
442 transport_type = SIPE_TRANSPORT_TCP;
444 sipe_core_transport_sip_connect(sipe_public,
445 transport_type,
446 get_authentication_type(account),
447 username_split[0],
448 username_split[0] ? username_split[1] : NULL);
449 g_strfreev(username_split);
452 static void password_required_cb(PurpleConnection *gc,
453 SIPE_UNUSED_PARAMETER PurpleRequestFields *fields)
455 #if !PURPLE_VERSION_CHECK(3,0,0)
456 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
457 return;
459 #endif
461 purple_connection_error(gc,
462 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
463 _("Password required"));
466 static void password_ok_cb(PurpleConnection *gc,
467 PurpleRequestFields *fields)
469 const gchar *password;
471 #if !PURPLE_VERSION_CHECK(3,0,0)
472 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
473 return;
475 #endif
477 password = purple_request_fields_get_string(fields, "password");
479 if (password && strlen(password)) {
480 PurpleAccount *account = purple_connection_get_account(gc);
482 if (purple_request_fields_get_bool(fields, "remember"))
483 purple_account_set_remember_password(account, TRUE);
484 purple_account_set_password(account, password
485 #if PURPLE_VERSION_CHECK(3,0,0)
486 , NULL, NULL
487 #endif
490 /* Now we have a password and we can connect */
491 connect_to_core(gc, account, password);
493 } else
494 /* reject an empty password */
495 password_required_cb(gc, fields);
498 void sipe_purple_login(PurpleAccount *account)
500 PurpleConnection *gc = purple_account_get_connection(account);
501 const gchar *password = purple_connection_get_password(gc);
503 /* Password required? */
504 if (sipe_core_transport_sip_requires_password(get_authentication_type(account),
505 get_sso_flag(account)) &&
506 (!password || !strlen(password)))
507 /* No password set - request one from user */
508 purple_account_request_password(account,
509 G_CALLBACK(password_ok_cb),
510 G_CALLBACK(password_required_cb),
511 gc);
512 else
513 /* No password required or saved password - connect now */
514 connect_to_core(gc, account, password);
518 void sipe_purple_close(PurpleConnection *gc)
520 struct sipe_core_public *sipe_public = PURPLE_GC_TO_SIPE_CORE_PUBLIC;
522 if (sipe_public) {
523 struct sipe_backend_private *purple_private = sipe_public->backend_private;
525 sipe_core_deallocate(sipe_public);
527 /* anything left after that must be in pending state... */
528 sipe_purple_dns_query_cancel_all(purple_private);
529 sipe_purple_transport_close_all(purple_private);
531 if (purple_private->roomlist_map)
532 g_hash_table_destroy(purple_private->roomlist_map);
533 sipe_purple_chat_destroy_rejoin(purple_private);
535 if (purple_private->deferred_status_timeout)
536 g_source_remove(purple_private->deferred_status_timeout);
537 g_free(purple_private->deferred_status_note);
539 g_free(purple_private);
540 purple_connection_set_protocol_data(gc, NULL);
544 unsigned int sipe_purple_send_typing(PurpleConnection *gc,
545 const char *who,
546 PurpleIMTypingState state)
548 gboolean typing = (state == PURPLE_IM_TYPING);
550 /* only enable this debug output while testing
551 SIPE_DEBUG_INFO("sipe_purple_send_typing: '%s' state %d", who, state); */
554 * libpurple calls this function with PURPLE_NOT_TYPING *after*
555 * calling sipe_purple_send_im() with the message. This causes
556 * SIPE core to send out two SIP messages to the same dialog in
557 * short succession without waiting for the response to the first
558 * one. Some servers then reject the first one with
560 * SIP/2.0 500 Stale CSeq Value
562 * which triggers a "message not delivered" error for the user.
564 * Work around this by filtering out PURPLE_NOT_TYPING events.
566 if (state != PURPLE_IM_NOT_TYPING)
567 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
568 who,
569 typing);
571 /* tell libpurple to send typing indications every 4 seconds */
572 return(typing ? 4 : 0);
575 void sipe_purple_get_info(PurpleConnection *gc, const char *who)
577 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
578 who);
581 void sipe_purple_add_permit(PurpleConnection *gc, const char *name)
583 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, TRUE);
586 void sipe_purple_add_deny(PurpleConnection *gc, const char *name)
588 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, FALSE);
591 void sipe_purple_alias_buddy(PurpleConnection *gc, const char *name,
592 const char *alias)
594 sipe_core_group_set_alias(PURPLE_GC_TO_SIPE_CORE_PUBLIC, name, alias);
597 void sipe_purple_group_rename(PurpleConnection *gc, const char *old_name,
598 PurpleGroup *group,
599 SIPE_UNUSED_PARAMETER GList *moved_buddies)
601 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
602 old_name,
603 purple_group_get_name(group));
606 void sipe_purple_convo_closed(PurpleConnection *gc, const char *who)
608 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who);
611 void sipe_purple_group_remove(PurpleConnection *gc, PurpleGroup *group)
613 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
614 purple_group_get_name(group));
617 GHashTable *
618 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount *account)
620 GHashTable *table;
621 table = g_hash_table_new(g_str_hash, g_str_equal);
622 g_hash_table_insert(table, (char *)"login_label", (gpointer)_("user@company.com"));
623 return table;
626 #ifdef HAVE_VV
628 static void
629 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER int signum)
631 capture_pipeline("PURPLE_SIPE_PIPELINE");
634 gboolean sipe_purple_initiate_media(PurpleAccount *account, const char *who,
635 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type)
637 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
638 who,
639 (type & PURPLE_MEDIA_VIDEO));
640 return TRUE;
643 PurpleMediaCaps sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount *account,
644 SIPE_UNUSED_PARAMETER const char *who)
646 return PURPLE_MEDIA_CAPS_AUDIO
647 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
648 | PURPLE_MEDIA_CAPS_MODIFY_SESSION;
650 #endif
652 /* PurplePluginInfo function calls & data structure */
653 gboolean sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
655 #ifdef HAVE_VV
657 struct sigaction action;
658 memset(&action, 0, sizeof (action));
659 action.sa_handler = sipe_purple_sigusr1_handler;
660 sigaction(SIGUSR1, &action, NULL);
662 #endif
664 sipe_purple_activity_init();
666 return TRUE;
669 gboolean sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
671 #ifdef HAVE_VV
672 struct sigaction action;
673 memset(&action, 0, sizeof (action));
674 action.sa_handler = SIG_DFL;
675 sigaction(SIGUSR1, &action, NULL);
676 #endif
678 sipe_purple_activity_shutdown();
680 return TRUE;
683 static void sipe_purple_show_about_plugin(PurpleProtocolAction *action)
685 gchar *tmp = sipe_core_about();
686 purple_notify_formatted(SIPE_PURPLE_ACTION_TO_CONNECTION,
687 NULL, " ", NULL, tmp, NULL, NULL);
688 g_free(tmp);
691 static void sipe_purple_join_conference_cb(PurpleConnection *gc,
692 PurpleRequestFields *fields)
694 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
696 if (entries) {
697 const gchar *location = purple_request_fields_get_string(fields,
698 "meetingLocation");
699 const gchar *organizer = purple_request_fields_get_string(fields,
700 "meetingOrganizer");
701 const gchar *meeting_id = purple_request_fields_get_string(fields,
702 "meetingID");
703 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
704 location,
705 organizer,
706 meeting_id);
710 #ifdef HAVE_VV
712 static void sipe_purple_phone_call_cb(PurpleConnection *gc,
713 PurpleRequestFields *fields)
715 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
717 if (entries)
718 sipe_core_media_phone_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
719 purple_request_fields_get_string(fields,
720 "phoneNumber"));
723 static void sipe_purple_phone_call(PurpleProtocolAction *action)
725 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
726 PurpleRequestFields *fields;
727 PurpleRequestFieldGroup *group;
728 PurpleRequestField *field;
730 fields = purple_request_fields_new();
731 group = purple_request_field_group_new(NULL);
732 purple_request_fields_add_group(fields, group);
734 field = purple_request_field_string_new("phoneNumber", _("Phone number"), NULL, FALSE);
735 purple_request_field_group_add_field(group, field);
737 purple_request_fields(gc,
738 _("Call a phone number"),
739 _("Call a phone number"),
740 NULL,
741 fields,
742 _("_Call"), G_CALLBACK(sipe_purple_phone_call_cb),
743 _("_Cancel"), NULL,
744 #if PURPLE_VERSION_CHECK(3,0,0)
745 purple_request_cpar_from_connection(gc),
746 #else
747 purple_connection_get_account(gc), NULL, NULL,
748 #endif
749 gc);
752 static void sipe_purple_test_call(PurpleProtocolAction *action)
754 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
755 sipe_core_media_test_call(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
757 #endif
759 static void sipe_purple_show_join_conference(PurpleProtocolAction *action)
761 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
762 PurpleRequestFields *fields;
763 PurpleRequestFieldGroup *group;
764 PurpleRequestField *field;
766 fields = purple_request_fields_new();
767 group = purple_request_field_group_new(NULL);
768 purple_request_fields_add_group(fields, group);
770 field = purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL, FALSE);
771 purple_request_field_group_add_field(group, field);
772 field = purple_request_field_label_new("separator", _("Alternatively"));
773 purple_request_field_group_add_field(group, field);
774 field = purple_request_field_string_new("meetingOrganizer", _("Organizer email"), NULL, FALSE);
775 purple_request_field_group_add_field(group, field);
776 field = purple_request_field_string_new("meetingID", _("Meeting ID"), NULL, FALSE);
777 purple_request_field_group_add_field(group, field);
779 purple_request_fields(gc,
780 _("Join conference"),
781 _("Join scheduled conference"),
782 _("Enter meeting location string you received in the invitation.\n"
783 "\n"
784 "Valid location will be something like\n"
785 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
786 "conf:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234\n"
787 "or\n"
788 "https://meet.company.com/someone/abcdef1234"),
789 fields,
790 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb),
791 _("_Cancel"), NULL,
792 #if PURPLE_VERSION_CHECK(3,0,0)
793 purple_request_cpar_from_connection(gc),
794 #else
795 purple_connection_get_account(gc), NULL, NULL,
796 #endif
797 gc);
800 void sipe_purple_republish_calendar(PurpleAccount *account)
802 struct sipe_core_public *sipe_public = PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC;
803 if (get_dont_publish_flag(account)) {
804 sipe_backend_notify_error(sipe_public,
805 _("Publishing of calendar information has been disabled"),
806 NULL);
807 } else {
808 sipe_core_update_calendar(sipe_public);
812 static void sipe_purple_republish_calendar_action(PurpleProtocolAction *action)
814 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
815 PurpleAccount *account = purple_connection_get_account(gc);
816 sipe_purple_republish_calendar(account);
819 void sipe_purple_reset_status(PurpleAccount *account)
821 if (get_dont_publish_flag(account)) {
822 sipe_backend_notify_error(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
823 _("Publishing of calendar information has been disabled"),
824 NULL);
825 } else {
826 sipe_core_reset_status(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC);
830 static void sipe_purple_reset_status_action(PurpleProtocolAction *action)
832 PurpleConnection *gc = SIPE_PURPLE_ACTION_TO_CONNECTION;
833 PurpleAccount *account = purple_connection_get_account(gc);
834 sipe_purple_reset_status(account);
837 GList *sipe_purple_actions()
839 GList *menu = NULL;
840 PurpleProtocolAction *act;
842 act = purple_protocol_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin);
843 menu = g_list_prepend(menu, act);
845 act = purple_protocol_action_new(_("Contact search..."), sipe_purple_show_find_contact);
846 menu = g_list_prepend(menu, act);
848 #ifdef HAVE_VV
849 act = purple_protocol_action_new(_("Call a phone number..."), sipe_purple_phone_call);
850 menu = g_list_prepend(menu, act);
852 act = purple_protocol_action_new(_("Test call"), sipe_purple_test_call);
853 menu = g_list_prepend(menu, act);
854 #endif
856 act = purple_protocol_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference);
857 menu = g_list_prepend(menu, act);
859 act = purple_protocol_action_new(_("Republish Calendar"), sipe_purple_republish_calendar_action);
860 menu = g_list_prepend(menu, act);
862 act = purple_protocol_action_new(_("Reset status"), sipe_purple_reset_status_action);
863 menu = g_list_prepend(menu, act);
865 return g_list_reverse(menu);
868 GList * sipe_purple_account_options()
870 PurpleAccountOption *option;
871 GList *options = NULL;
874 * When adding new string settings please make sure to keep these
875 * in sync:
877 * api/sipe-backend.h
878 * purple-settings.c:setting_name[]
880 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
881 options = g_list_append(options, option);
883 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
884 purple_account_option_add_list_item(option, _("Auto"), "auto");
885 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
886 purple_account_option_add_list_item(option, _("TCP"), "tcp");
887 options = g_list_append(options, option);
889 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
890 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
892 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
893 options = g_list_append(options, option);
895 option = purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL);
896 purple_account_option_add_list_item(option, _("Auto"), "auto");
897 purple_account_option_add_list_item(option, _("NTLM"), "ntlm");
898 #if PURPLE_SIPE_SSO_AND_KERBEROS
899 purple_account_option_add_list_item(option, _("Kerberos"), "krb5");
900 #endif
901 purple_account_option_add_list_item(option, _("TLS-DSK"), "tls-dsk");
902 options = g_list_append(options, option);
904 #if PURPLE_SIPE_SSO_AND_KERBEROS
906 * When the user selects Single Sign-On then SIPE will ignore the
907 * settings for "login name" and "password". Instead it will use the
908 * default credentials provided by the OS.
910 * NOTE: the default must be *OFF*, i.e. it is up to the user to tell
911 * SIPE that it is OK to use Single Sign-On or not.
913 * Configurations that are known to support Single Sign-On:
915 * - Windows, host joined to domain, SIPE with SSPI: NTLM
916 * - Windows, host joined to domain, SIPE with SSPI: Kerberos
917 * - SIPE with libkrb5, valid TGT in cache (kinit): Kerberos
919 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", FALSE);
920 options = g_list_append(options, option);
921 #endif
923 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
924 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
926 option = purple_account_option_bool_new(_("Don't publish my calendar information"), "dont-publish", FALSE);
927 options = g_list_append(options, option);
929 option = purple_account_option_bool_new(_("Show profile pictures from web\n(potentially dangerous)"), "allow-web-photo", FALSE);
930 options = g_list_append(options, option);
932 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
933 options = g_list_append(options, option);
935 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
936 options = g_list_append(options, option);
938 /** Example (Exchange): DOMAIN\user or user@company.com
939 * Example (Domino) : email_address
941 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
942 options = g_list_append(options, option);
944 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
945 purple_account_option_string_set_masked(option, TRUE);
946 options = g_list_append(options, option);
948 /** Example (federated domain): company.com (i.e. ocschat@company.com)
949 * Example (non-default user): user@company.com
951 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", "");
952 options = g_list_append(options, option);
954 #ifdef HAVE_APPSHARE
955 option = purple_account_option_string_new(_("Remote desktop client"), "rdp_client", "");
956 options = g_list_append(options, option);
957 #endif
959 #ifdef HAVE_SRTP
960 option = purple_account_option_list_new(_("Media encryption"), "encryption-policy", NULL);
961 purple_account_option_add_list_item(option, _("Obey server policy"), "obey-server");
962 purple_account_option_add_list_item(option, _("Always"), "required");
963 purple_account_option_add_list_item(option, _("Optional"), "optional");
964 purple_account_option_add_list_item(option, _("Disabled"), "disabled");
965 options = g_list_append(options, option);
966 #endif
968 return options;
971 gpointer sipe_purple_user_split()
973 PurpleAccountUserSplit *split =
974 purple_account_user_split_new(
975 _("Login\n user or DOMAIN\\user or\n user@company.com"),
977 * pidgin works fine with NULL as default
978 * finch returns string "(null)" for NULL
981 ',');
982 purple_account_user_split_set_reverse(split, FALSE);
984 return split;
988 Local Variables:
989 mode: c
990 c-file-style: "bsd"
991 indent-tabs-mode: t
992 tab-width: 8
993 End: