2 * @file purple-plugin.c
6 * Copyright (C) 2010-11 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "sipe-common.h"
34 /* Flag needed for correct version of PURPLE_INIT_PLUGIN() */
35 #ifndef PURPLE_PLUGINS
36 #define PURPLE_PLUGINS
40 * as it's determined on runtime, as Pidgin installation can be anywhere.
43 #include "win32/win32dep.h"
46 #include "accountopt.h"
48 #include "connection.h"
59 * NOTE: Currently PURPLE_VERSION_CHECK(2,y,z) returns FALSE for libpurple >= 3.0.0.
60 * See also <http://developer.pidgin.im/ticket/14551>
62 * As a workaround an additional PURPLE_VERSION_CHECK(3,0,0) needs to be added.
66 #include "sipe-backend.h"
67 #include "sipe-core.h"
70 #define _PurpleMessageFlags PurpleMessageFlags
71 #include "purple-private.h"
73 /* Backward compatibility when compiling against 2.4.x API */
74 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
75 #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100
78 /* Sipe core activity <-> Purple status mapping */
79 static const gchar
* const activity_to_purple_map
[SIPE_ACTIVITY_NUM_TYPES
] = {
80 /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */
81 /* SIPE_ACTIVITY_AVAILABLE */ "available", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) */
82 /* SIPE_ACTIVITY_ONLINE */ "online",
83 /* SIPE_ACTIVITY_INACTIVE */ "idle",
84 /* SIPE_ACTIVITY_BUSY */ "busy",
85 /* SIPE_ACTIVITY_BUSYIDLE */ "busyidle",
86 /* SIPE_ACTIVITY_DND */ "do-not-disturb",
87 /* SIPE_ACTIVITY_BRB */ "be-right-back",
88 /* SIPE_ACTIVITY_AWAY */ "away", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) */
89 /* SIPE_ACTIVITY_LUNCH */ "out-to-lunch",
90 /* SIPE_ACTIVITY_INVISIBLE */ "invisible", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) */
91 /* SIPE_ACTIVITY_OFFLINE */ "offline", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) */
92 /* SIPE_ACTIVITY_ON_PHONE */ "on-the-phone",
93 /* SIPE_ACTIVITY_IN_CONF */ "in-a-conference",
94 /* SIPE_ACTIVITY_IN_MEETING */ "in-a-meeting",
95 /* SIPE_ACTIVITY_OOF */ "out-of-office",
96 /* SIPE_ACTIVITY_URGENT_ONLY */ "urgent-interruptions-only",
99 GHashTable
*purple_token_map
;
101 static void sipe_purple_activity_init(void)
105 purple_token_map
= g_hash_table_new(g_str_hash
, g_str_equal
);
106 for (index
= SIPE_ACTIVITY_UNSET
;
107 index
< SIPE_ACTIVITY_NUM_TYPES
;
109 g_hash_table_insert(purple_token_map
,
110 (gchar
*) activity_to_purple_map
[index
],
111 GUINT_TO_POINTER(index
));
115 static void sipe_purple_activity_shutdown(void)
117 g_hash_table_destroy(purple_token_map
);
120 const gchar
*sipe_purple_activity_to_token(guint type
)
122 return(activity_to_purple_map
[type
]);
125 guint
sipe_purple_token_to_activity(const gchar
*token
)
127 return(GPOINTER_TO_UINT(g_hash_table_lookup(purple_token_map
, token
)));
130 gchar
*sipe_backend_version(void)
132 return(g_strdup_printf("Purple/%s", purple_core_get_version()));
135 /* PurplePluginProtocolInfo function calls & data structure */
136 static const char *sipe_list_icon(SIPE_UNUSED_PARAMETER PurpleAccount
*a
,
137 SIPE_UNUSED_PARAMETER PurpleBuddy
*b
)
142 static gchar
*sipe_purple_status_text(PurpleBuddy
*buddy
)
144 const PurpleStatus
*status
= purple_presence_get_active_status(purple_buddy_get_presence(buddy
));
145 return sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
147 sipe_purple_token_to_activity(purple_status_get_id(status
)),
148 purple_status_get_name(status
));
151 static void sipe_purple_tooltip_text(PurpleBuddy
*buddy
,
152 PurpleNotifyUserInfo
*user_info
,
153 SIPE_UNUSED_PARAMETER gboolean full
)
155 const PurplePresence
*presence
= purple_buddy_get_presence(buddy
);
156 sipe_core_buddy_tooltip_info(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
158 purple_status_get_name(purple_presence_get_active_status(presence
)),
159 purple_presence_is_online(presence
),
160 (struct sipe_backend_buddy_tooltip
*) user_info
);
163 static GList
*sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount
*acc
)
165 PurpleStatusType
*type
;
168 /* Macros to reduce code repetition.
170 #define SIPE_ADD_STATUS(prim,id,name,user) type = purple_status_type_new_with_attrs( \
173 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, _("Message"), purple_value_new(PURPLE_TYPE_STRING), \
175 types = g_list_append(types, type);
178 SIPE_ADD_STATUS(PURPLE_STATUS_AVAILABLE
,
184 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
185 sipe_purple_activity_to_token(SIPE_ACTIVITY_BUSY
),
186 sipe_core_activity_description(SIPE_ACTIVITY_BUSY
),
190 SIPE_ADD_STATUS(PURPLE_STATUS_UNAVAILABLE
,
191 sipe_purple_activity_to_token(SIPE_ACTIVITY_DND
),
196 /* Goes first in the list as
197 * purple picks the first status with the AWAY type
200 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
206 SIPE_ADD_STATUS(PURPLE_STATUS_AWAY
,
207 sipe_purple_activity_to_token(SIPE_ACTIVITY_BRB
),
208 sipe_core_activity_description(SIPE_ACTIVITY_BRB
),
212 SIPE_ADD_STATUS(PURPLE_STATUS_INVISIBLE
,
218 type
= purple_status_type_new(PURPLE_STATUS_OFFLINE
,
222 types
= g_list_append(types
, type
);
227 static GList
*sipe_purple_blist_node_menu(PurpleBlistNode
*node
)
229 if(PURPLE_BLIST_NODE_IS_BUDDY(node
)) {
230 return sipe_purple_buddy_menu((PurpleBuddy
*) node
);
231 } else if(PURPLE_BLIST_NODE_IS_CHAT(node
)) {
232 return sipe_purple_chat_menu((PurpleChat
*)node
);
238 static void sipe_purple_login(PurpleAccount
*account
)
240 PurpleConnection
*gc
= purple_account_get_connection(account
);
241 const gchar
*username
= purple_account_get_username(account
);
242 const gchar
*email
= purple_account_get_string(account
, "email", NULL
);
243 const gchar
*email_url
= purple_account_get_string(account
, "email_url", NULL
);
244 const gchar
*transport
= purple_account_get_string(account
, "transport", "auto");
245 const gchar
*auth
= purple_account_get_string(account
, "authentication", "ntlm");
246 struct sipe_core_public
*sipe_public
;
247 gchar
**username_split
;
248 gchar
*login_domain
= NULL
;
249 gchar
*login_account
= NULL
;
252 struct sipe_backend_private
*purple_private
;
254 /* username format: <username>,[<optional login>] */
255 SIPE_DEBUG_INFO("sipe_purple_login: username '%s'", username
);
256 username_split
= g_strsplit(username
, ",", 2);
258 /* login name specified? */
259 if (username_split
[1] && strlen(username_split
[1])) {
260 /* Allowed domain-account separators are / or \ */
261 gchar
**domain_user
= g_strsplit_set(username_split
[1], "/\\", 2);
262 gboolean has_domain
= domain_user
[1] != NULL
;
263 SIPE_DEBUG_INFO("sipe_purple_login: login '%s'", username_split
[1]);
264 login_domain
= has_domain
? g_strdup(domain_user
[0]) : NULL
;
265 login_account
= g_strdup(domain_user
[has_domain
? 1 : 0]);
266 SIPE_DEBUG_INFO("sipe_purple_login: auth domain '%s' user '%s'",
267 login_domain
? login_domain
: "",
269 g_strfreev(domain_user
);
272 sipe_public
= sipe_core_allocate(username_split
[0],
273 login_domain
, login_account
,
274 purple_connection_get_password(gc
),
278 g_free(login_domain
);
279 g_free(login_account
);
280 g_strfreev(username_split
);
283 #if PURPLE_VERSION_CHECK(3,0,0)
284 purple_connection_error(
286 purple_connection_error_reason(
289 PURPLE_CONNECTION_ERROR_INVALID_USERNAME
,
294 sipe_public
->backend_private
= purple_private
= g_new0(struct sipe_backend_private
, 1);
295 purple_private
->public = sipe_public
;
296 purple_private
->gc
= gc
;
297 purple_private
->account
= account
;
299 sipe_purple_chat_setup_rejoin(purple_private
);
301 /* map option list to flags - default is NTLM */
302 SIPE_CORE_FLAG_UNSET(KRB5
);
303 SIPE_CORE_FLAG_UNSET(TLS_DSK
);
304 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
305 if (sipe_strequal(auth
, "krb5")) {
306 SIPE_CORE_FLAG_SET(KRB5
);
309 if (sipe_strequal(auth
, "tls-dsk")) {
310 SIPE_CORE_FLAG_SET(TLS_DSK
);
313 /* @TODO: is this correct?
314 "sso" is only available when Kerberos/SSPI support is compiled in */
315 if (purple_account_get_bool(account
, "sso", TRUE
))
316 SIPE_CORE_FLAG_SET(SSO
);
318 gc
->proto_data
= sipe_public
;
319 gc
->flags
|= PURPLE_CONNECTION_HTML
| PURPLE_CONNECTION_FORMATTING_WBFO
| PURPLE_CONNECTION_NO_BGCOLOR
|
320 PURPLE_CONNECTION_NO_FONTSIZE
| PURPLE_CONNECTION_NO_URLDESC
| PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY
;
321 purple_connection_set_display_name(gc
, sipe_public
->sip_name
);
322 purple_connection_update_progress(gc
, _("Connecting"), 1, 2);
324 username_split
= g_strsplit(purple_account_get_string(account
, "server", ""), ":", 2);
325 if (sipe_strequal(transport
, "auto")) {
326 type
= (username_split
[0] == NULL
) ?
327 SIPE_TRANSPORT_AUTO
: SIPE_TRANSPORT_TLS
;
328 } else if (sipe_strequal(transport
, "tls")) {
329 type
= SIPE_TRANSPORT_TLS
;
331 type
= SIPE_TRANSPORT_TCP
;
333 sipe_core_transport_sip_connect(sipe_public
,
336 username_split
[0] ? username_split
[1] : NULL
);
337 g_strfreev(username_split
);
340 static void sipe_purple_close(PurpleConnection
*gc
)
342 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
345 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
347 sipe_core_deallocate(sipe_public
);
349 if (purple_private
->roomlist_map
)
350 g_hash_table_destroy(purple_private
->roomlist_map
);
351 sipe_purple_chat_destroy_rejoin(purple_private
);
352 g_free(purple_private
);
353 gc
->proto_data
= NULL
;
357 static int sipe_purple_send_im(PurpleConnection
*gc
,
360 SIPE_UNUSED_PARAMETER PurpleMessageFlags flags
)
362 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
, what
);
366 #define SIPE_TYPING_SEND_TIMEOUT 4
368 static unsigned int sipe_purple_send_typing(PurpleConnection
*gc
,
370 PurpleTypingState state
)
372 if (state
== PURPLE_NOT_TYPING
)
375 sipe_core_user_feedback_typing(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
378 return SIPE_TYPING_SEND_TIMEOUT
;
381 static void sipe_purple_get_info(PurpleConnection
*gc
, const char *who
)
383 sipe_core_buddy_get_info(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
387 static void sipe_purple_add_permit(PurpleConnection
*gc
, const char *name
)
389 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, TRUE
);
392 static void sipe_purple_add_deny(PurpleConnection
*gc
, const char *name
)
394 sipe_core_contact_allow_deny(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
, FALSE
);
397 static void sipe_purple_keep_alive(PurpleConnection
*gc
)
399 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
400 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
401 time_t now
= time(NULL
);
403 if ((sipe_public
->keepalive_timeout
> 0) &&
404 ((guint
) (now
- purple_private
->last_keepalive
) >= sipe_public
->keepalive_timeout
) &&
405 ((guint
) (now
- gc
->last_received
) >= sipe_public
->keepalive_timeout
)
407 sipe_core_transport_sip_keepalive(sipe_public
);
408 purple_private
->last_keepalive
= now
;
412 static void sipe_purple_alias_buddy(PurpleConnection
*gc
, const char *name
,
413 SIPE_UNUSED_PARAMETER
const char *alias
)
415 sipe_core_group_set_user(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, name
);
418 static void sipe_purple_group_rename(PurpleConnection
*gc
,
419 const char *old_name
,
421 SIPE_UNUSED_PARAMETER GList
*moved_buddies
)
423 sipe_core_group_rename(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, old_name
, group
->name
);
426 static void sipe_purple_convo_closed(PurpleConnection
*gc
,
429 sipe_core_im_close(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
);
432 static void sipe_purple_group_remove(PurpleConnection
*gc
, PurpleGroup
*group
)
434 sipe_core_group_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, group
->name
);
437 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
439 sipe_purple_get_account_text_table(SIPE_UNUSED_PARAMETER PurpleAccount
*account
)
442 table
= g_hash_table_new(g_str_hash
, g_str_equal
);
443 g_hash_table_insert(table
, "login_label", (gpointer
)_("user@company.com"));
447 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
450 extern void capture_pipeline(gchar
*label
);
453 sipe_purple_sigusr1_handler(SIPE_UNUSED_PARAMETER
int signum
)
455 capture_pipeline("PURPLE_SIPE_PIPELINE");
458 static gboolean
sipe_purple_initiate_media(PurpleAccount
*account
, const char *who
,
459 SIPE_UNUSED_PARAMETER PurpleMediaSessionType type
)
461 sipe_core_media_initiate_call(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC
,
463 (type
& PURPLE_MEDIA_VIDEO
));
467 static PurpleMediaCaps
sipe_purple_get_media_caps(SIPE_UNUSED_PARAMETER PurpleAccount
*account
,
468 SIPE_UNUSED_PARAMETER
const char *who
)
470 return PURPLE_MEDIA_CAPS_AUDIO
471 | PURPLE_MEDIA_CAPS_AUDIO_VIDEO
472 | PURPLE_MEDIA_CAPS_MODIFY_SESSION
;
479 * Simplistic source upward compatibility path for newer libpurple APIs
481 * Usually we compile with -Werror=missing-field-initializers if GCC supports
482 * it. But that means that the compilation of this structure can fail if the
483 * newer API has added additional plugin callbacks. For the benefit of the
484 * user we downgrade it to a warning here.
486 * Diagnostic #pragma was added in GCC 4.2.0
487 * Diagnostic push/pop was added in GCC 4.6.0
490 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 2)
491 #if __GNUC_MINOR__ >= 6
492 #pragma GCC diagnostic push
494 #pragma GCC diagnostic warning "-Wmissing-field-initializers"
497 static PurplePluginProtocolInfo sipe_prpl_info
=
499 OPT_PROTO_CHAT_TOPIC
,
500 NULL
, /* user_splits */
501 NULL
, /* protocol_options */
502 NO_BUDDY_ICONS
, /* icon_spec */
503 sipe_list_icon
, /* list_icon */
504 NULL
, /* list_emblems */
505 sipe_purple_status_text
, /* status_text */
506 sipe_purple_tooltip_text
, /* tooltip_text */ // add custom info to contact tooltip
507 sipe_purple_status_types
, /* away_states */
508 sipe_purple_blist_node_menu
, /* blist_node_menu */
509 sipe_purple_chat_info
, /* chat_info */
510 sipe_purple_chat_info_defaults
, /* chat_info_defaults */
511 sipe_purple_login
, /* login */
512 sipe_purple_close
, /* close */
513 sipe_purple_send_im
, /* send_im */
514 NULL
, /* set_info */ // TODO maybe
515 sipe_purple_send_typing
, /* send_typing */
516 sipe_purple_get_info
, /* get_info */
517 sipe_purple_set_status
, /* set_status */
518 sipe_purple_set_idle
, /* set_idle */
519 NULL
, /* change_passwd */
520 sipe_purple_add_buddy
, /* add_buddy */
521 NULL
, /* add_buddies */
522 sipe_purple_remove_buddy
, /* remove_buddy */
523 NULL
, /* remove_buddies */
524 sipe_purple_add_permit
, /* add_permit */
525 sipe_purple_add_deny
, /* add_deny */
526 sipe_purple_add_deny
, /* rem_permit */
527 sipe_purple_add_permit
, /* rem_deny */
528 NULL
, /* set_permit_deny */
529 sipe_purple_chat_join
, /* join_chat */
530 NULL
, /* reject_chat */
531 NULL
, /* get_chat_name */
532 sipe_purple_chat_invite
, /* chat_invite */
533 sipe_purple_chat_leave
, /* chat_leave */
534 NULL
, /* chat_whisper */
535 sipe_purple_chat_send
, /* chat_send */
536 sipe_purple_keep_alive
, /* keepalive */
537 NULL
, /* register_user */
538 NULL
, /* get_cb_info */ // deprecated
539 NULL
, /* get_cb_away */ // deprecated
540 sipe_purple_alias_buddy
, /* alias_buddy */
541 sipe_purple_group_buddy
, /* group_buddy */
542 sipe_purple_group_rename
, /* rename_group */
543 NULL
, /* buddy_free */
544 sipe_purple_convo_closed
, /* convo_closed */
545 purple_normalize_nocase
, /* normalize */
546 NULL
, /* set_buddy_icon */
547 sipe_purple_group_remove
, /* remove_group */
548 NULL
, /* get_cb_real_name */ // TODO?
549 NULL
, /* set_chat_topic */
550 NULL
, /* find_blist_chat */
551 sipe_purple_roomlist_get_list
, /* roomlist_get_list */
552 sipe_purple_roomlist_cancel
, /* roomlist_cancel */
553 NULL
, /* roomlist_expand_category */
554 NULL
, /* can_receive_file */
555 sipe_purple_ft_send_file
, /* send_file */
556 sipe_purple_ft_new_xfer
, /* new_xfer */
557 NULL
, /* offline_message */
558 NULL
, /* whiteboard_prpl_ops */
560 NULL
, /* roomlist_room_serialize */
561 NULL
, /* unregister_user */
562 NULL
, /* send_attention */
563 NULL
, /* get_attention_types */
564 #if !PURPLE_VERSION_CHECK(2,5,0) && !PURPLE_VERSION_CHECK(3,0,0)
565 /* Backward compatibility when compiling against 2.4.x API */
566 (void (*)(void)) /* _purple_reserved4 */
568 sizeof(PurplePluginProtocolInfo
), /* struct_size */
569 #if PURPLE_VERSION_CHECK(2,5,0) || PURPLE_VERSION_CHECK(3,0,0)
570 sipe_purple_get_account_text_table
, /* get_account_text_table */
571 #if PURPLE_VERSION_CHECK(2,6,0) || PURPLE_VERSION_CHECK(3,0,0)
573 sipe_purple_initiate_media
, /* initiate_media */
574 sipe_purple_get_media_caps
, /* get_media_caps */
576 NULL
, /* initiate_media */
577 NULL
, /* get_media_caps */
579 #if PURPLE_VERSION_CHECK(2,7,0) || PURPLE_VERSION_CHECK(3,0,0)
580 NULL
, /* get_moods */
581 NULL
, /* set_public_alias */
582 NULL
, /* get_public_alias */
583 #if PURPLE_VERSION_CHECK(2,8,0) || PURPLE_VERSION_CHECK(3,0,0)
584 NULL
, /* add_buddy_with_invite */
585 NULL
, /* add_buddies_with_invite */
592 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 6)
593 #pragma GCC diagnostic pop
596 /* Original GCC error checking restored from here on... (see above) */
598 /* PurplePluginInfo function calls & data structure */
599 static gboolean
sipe_purple_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
602 struct sigaction action
;
603 memset(&action
, 0, sizeof (action
));
604 action
.sa_handler
= sipe_purple_sigusr1_handler
;
605 sigaction(SIGUSR1
, &action
, NULL
);
610 static gboolean
sipe_purple_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
613 struct sigaction action
;
614 memset(&action
, 0, sizeof (action
));
615 action
.sa_handler
= SIG_DFL
;
616 sigaction(SIGUSR1
, &action
, NULL
);
621 static void sipe_purple_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
)
625 sipe_purple_activity_shutdown();
628 entry
= sipe_prpl_info
.protocol_options
;
630 purple_account_option_destroy(entry
->data
);
631 entry
= g_list_delete_link(entry
, entry
);
633 sipe_prpl_info
.protocol_options
= NULL
;
635 entry
= sipe_prpl_info
.user_splits
;
637 purple_account_user_split_destroy(entry
->data
);
638 entry
= g_list_delete_link(entry
, entry
);
640 sipe_prpl_info
.user_splits
= NULL
;
643 static void sipe_purple_show_about_plugin(PurplePluginAction
*action
)
645 gchar
*tmp
= sipe_core_about();
646 purple_notify_formatted((PurpleConnection
*) action
->context
,
647 NULL
, " ", NULL
, tmp
, NULL
, NULL
);
651 static void sipe_purple_find_contact_cb(PurpleConnection
*gc
,
652 PurpleRequestFields
*fields
)
654 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
655 const gchar
*given_name
= NULL
;
656 const gchar
*surname
= NULL
;
657 const gchar
*email
= NULL
;
658 const gchar
*company
= NULL
;
659 const gchar
*country
= NULL
;
662 PurpleRequestField
*field
= entries
->data
;
663 const char *id
= purple_request_field_get_id(field
);
664 const char *value
= purple_request_field_string_get_value(field
);
666 SIPE_DEBUG_INFO("sipe_purple_find_contact_cb: %s = '%s'", id
, value
? value
: "");
669 if (strcmp(id
, "given") == 0) {
671 } else if (strcmp(id
, "surname") == 0) {
673 } else if (strcmp(id
, "email") == 0) {
675 } else if (strcmp(id
, "company") == 0) {
677 } else if (strcmp(id
, "country") == 0) {
682 entries
= g_list_next(entries
);
685 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
693 static void sipe_purple_show_find_contact(PurplePluginAction
*action
)
695 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
696 PurpleRequestFields
*fields
;
697 PurpleRequestFieldGroup
*group
;
698 PurpleRequestField
*field
;
700 fields
= purple_request_fields_new();
701 group
= purple_request_field_group_new(NULL
);
702 purple_request_fields_add_group(fields
, group
);
704 field
= purple_request_field_string_new("given", _("First name"), NULL
, FALSE
);
705 purple_request_field_group_add_field(group
, field
);
706 field
= purple_request_field_string_new("surname", _("Last name"), NULL
, FALSE
);
707 purple_request_field_group_add_field(group
, field
);
708 field
= purple_request_field_string_new("email", _("Email"), NULL
, FALSE
);
709 purple_request_field_group_add_field(group
, field
);
710 field
= purple_request_field_string_new("company", _("Company"), NULL
, FALSE
);
711 purple_request_field_group_add_field(group
, field
);
712 field
= purple_request_field_string_new("country", _("Country"), NULL
, FALSE
);
713 purple_request_field_group_add_field(group
, field
);
715 purple_request_fields(gc
,
717 _("Search for a contact"),
718 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
720 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb
),
722 purple_connection_get_account(gc
), NULL
, NULL
, gc
);
725 static void sipe_purple_join_conference_cb(PurpleConnection
*gc
,
726 PurpleRequestFields
*fields
)
728 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
731 PurpleRequestField
*field
= entries
->data
;
732 const char *id
= purple_request_field_get_id(field
);
733 const char *value
= purple_request_field_string_get_value(field
);
735 if (!sipe_strequal(id
, "meetingLocation"))
738 sipe_core_conf_create(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, value
);
742 static void sipe_purple_show_join_conference(PurplePluginAction
*action
)
744 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
745 PurpleRequestFields
*fields
;
746 PurpleRequestFieldGroup
*group
;
747 PurpleRequestField
*field
;
749 fields
= purple_request_fields_new();
750 group
= purple_request_field_group_new(NULL
);
751 purple_request_fields_add_group(fields
, group
);
753 field
= purple_request_field_string_new("meetingLocation", _("Meeting location"), NULL
, FALSE
);
754 purple_request_field_group_add_field(group
, field
);
756 purple_request_fields(gc
,
757 _("Join conference"),
758 _("Join scheduled conference"),
759 _("Enter meeting location string you received in the invitation.\n"
761 "Valid location will be something like\n"
762 "meet:sip:someone@company.com;gruu;opaque=app:conf:focus:id:abcdef1234"),
764 _("_Join"), G_CALLBACK(sipe_purple_join_conference_cb
),
766 purple_connection_get_account(gc
), NULL
, NULL
, gc
);
769 static void sipe_purple_republish_calendar(PurplePluginAction
*action
)
771 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
772 sipe_core_update_calendar(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
775 static void sipe_purple_reset_status(PurplePluginAction
*action
)
777 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
778 sipe_core_reset_status(PURPLE_GC_TO_SIPE_CORE_PUBLIC
);
781 static GList
*sipe_purple_actions(SIPE_UNUSED_PARAMETER PurplePlugin
*plugin
,
782 SIPE_UNUSED_PARAMETER gpointer context
)
785 PurplePluginAction
*act
;
787 act
= purple_plugin_action_new(_("About SIPE plugin..."), sipe_purple_show_about_plugin
);
788 menu
= g_list_prepend(menu
, act
);
790 act
= purple_plugin_action_new(_("Contact search..."), sipe_purple_show_find_contact
);
791 menu
= g_list_prepend(menu
, act
);
793 act
= purple_plugin_action_new(_("Join scheduled conference..."), sipe_purple_show_join_conference
);
794 menu
= g_list_prepend(menu
, act
);
796 act
= purple_plugin_action_new(_("Republish Calendar"), sipe_purple_republish_calendar
);
797 menu
= g_list_prepend(menu
, act
);
799 act
= purple_plugin_action_new(_("Reset status"), sipe_purple_reset_status
);
800 menu
= g_list_prepend(menu
, act
);
802 return g_list_reverse(menu
);
805 static PurplePluginInfo sipe_purple_info
= {
807 PURPLE_MAJOR_VERSION
,
808 PURPLE_MINOR_VERSION
,
809 PURPLE_PLUGIN_PROTOCOL
, /**< type */
810 NULL
, /**< ui_requirement */
812 NULL
, /**< dependencies */
813 PURPLE_PRIORITY_DEFAULT
, /**< priority */
814 "prpl-sipe", /**< id */
815 "Office Communicator", /**< name */
816 PACKAGE_VERSION
, /**< version */
817 "Microsoft Office Communicator Protocol Plugin", /**< summary */
818 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
819 "Microsoft Live/Office Communications Server (LCS2005/OCS2007+)", /**< description */
820 "Anibal Avelar <avelar@gmail.com>, " /**< author */
821 "Gabriel Burt <gburt@novell.com>, " /**< author */
822 "Stefan Becker <stefan.becker@nokia.com>, " /**< author */
823 "pier11 <pier11@operamail.com>", /**< author */
824 PACKAGE_URL
, /**< homepage */
825 sipe_purple_plugin_load
, /**< load */
826 sipe_purple_plugin_unload
, /**< unload */
827 sipe_purple_plugin_destroy
, /**< destroy */
828 NULL
, /**< ui_info */
829 &sipe_prpl_info
, /**< extra_info */
838 static void sipe_purple_init_plugin(PurplePlugin
*plugin
)
840 PurpleAccountUserSplit
*split
;
841 PurpleAccountOption
*option
;
843 /* This needs to be called first */
844 sipe_core_init(LOCALEDIR
);
845 sipe_purple_activity_init();
847 purple_plugin_register(plugin
);
850 * When adding new string settings please make sure to keep these
854 * purple-settings.c:setting_name[]
856 split
= purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL
, ',');
857 purple_account_user_split_set_reverse(split
, FALSE
);
858 sipe_prpl_info
.user_splits
= g_list_append(sipe_prpl_info
.user_splits
, split
);
860 option
= purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
861 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
863 option
= purple_account_option_list_new(_("Connection type"), "transport", NULL
);
864 purple_account_option_add_list_item(option
, _("Auto"), "auto");
865 purple_account_option_add_list_item(option
, _("SSL/TLS"), "tls");
866 purple_account_option_add_list_item(option
, _("TCP"), "tcp");
867 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
869 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
870 sipe_prpl_info.protocol_options = g_list_append(sipe_prpl_info.protocol_options, option);*/
872 option
= purple_account_option_string_new(_("User Agent"), "useragent", "");
873 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
875 option
= purple_account_option_list_new(_("Authentication scheme"), "authentication", NULL
);
876 purple_account_option_add_list_item(option
, _("NTLM"), "ntlm");
877 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
878 purple_account_option_add_list_item(option
, _("Kerberos"), "krb5");
880 purple_account_option_add_list_item(option
, _("TLS-DSK"), "tls-dsk");
881 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
883 #if defined(HAVE_LIBKRB5) || defined(HAVE_SSPI)
884 /* Suitable for sspi/NTLM, sspi/Kerberos and krb5 security mechanisms
885 * No login/password is taken into account if this option present,
886 * instead used default credentials stored in OS.
888 option
= purple_account_option_bool_new(_("Use Single Sign-On"), "sso", TRUE
);
889 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
892 /** Example (Exchange): https://server.company.com/EWS/Exchange.asmx
893 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
895 option
= purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
896 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
898 option
= purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
899 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
901 /** Example (Exchange): DOMAIN\user or user@company.com
902 * Example (Domino) : email_address
904 option
= purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
905 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
907 option
= purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
908 purple_account_option_set_masked(option
, TRUE
);
909 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
911 /** Example (federated domain): company.com (i.e. ocschat@company.com)
912 * Example (non-default user): user@company.com
914 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", "");
915 sipe_prpl_info
.protocol_options
= g_list_append(sipe_prpl_info
.protocol_options
, option
);
918 /* This macro makes the code a purple plugin */
919 PURPLE_INIT_PLUGIN(sipe
, sipe_purple_init_plugin
, sipe_purple_info
);