Convert XMPP console dialogs to popovers.
[pidgin-git.git] / libpurple / protocol.c
bloba462668dc1278b6eb44fb1be82d32826cf2a4f5c
1 /*
2 * purple
4 * Purple is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include "protocol.h"
25 static GObjectClass *parent_class;
27 /**************************************************************************
28 * Protocol Object API
29 **************************************************************************/
30 const char *
31 purple_protocol_get_id(const PurpleProtocol *protocol)
33 g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
35 return protocol->id;
38 const char *
39 purple_protocol_get_name(const PurpleProtocol *protocol)
41 g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
43 return protocol->name;
46 PurpleProtocolOptions
47 purple_protocol_get_options(const PurpleProtocol *protocol)
49 g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), 0);
51 return protocol->options;
54 GList *
55 purple_protocol_get_user_splits(const PurpleProtocol *protocol)
57 g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
59 return protocol->user_splits;
62 GList *
63 purple_protocol_get_account_options(const PurpleProtocol *protocol)
65 g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
67 return protocol->account_options;
70 PurpleBuddyIconSpec *
71 purple_protocol_get_icon_spec(const PurpleProtocol *protocol)
73 g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
75 return protocol->icon_spec;
78 PurpleWhiteboardOps *
79 purple_protocol_get_whiteboard_ops(const PurpleProtocol *protocol)
81 g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
83 return protocol->whiteboard_ops;
86 static void
87 user_splits_free(PurpleProtocol *protocol)
89 g_return_if_fail(PURPLE_IS_PROTOCOL(protocol));
91 while (protocol->user_splits) {
92 PurpleAccountUserSplit *split = protocol->user_splits->data;
93 purple_account_user_split_destroy(split);
94 protocol->user_splits = g_list_delete_link(protocol->user_splits,
95 protocol->user_splits);
99 static void
100 account_options_free(PurpleProtocol *protocol)
102 g_return_if_fail(PURPLE_IS_PROTOCOL(protocol));
104 while (protocol->account_options) {
105 PurpleAccountOption *option = protocol->account_options->data;
106 purple_account_option_destroy(option);
107 protocol->account_options =
108 g_list_delete_link(protocol->account_options,
109 protocol->account_options);
113 static void
114 icon_spec_free(PurpleProtocol *protocol)
116 g_return_if_fail(PURPLE_IS_PROTOCOL(protocol));
118 g_free(protocol->icon_spec);
119 protocol->icon_spec = NULL;
122 void
123 purple_protocol_override(PurpleProtocol *protocol,
124 PurpleProtocolOverrideFlags flags)
126 g_return_if_fail(PURPLE_IS_PROTOCOL(protocol));
128 if (flags & PURPLE_PROTOCOL_OVERRIDE_USER_SPLITS)
129 user_splits_free(protocol);
130 if (flags & PURPLE_PROTOCOL_OVERRIDE_PROTOCOL_OPTIONS)
131 account_options_free(protocol);
132 if (flags & PURPLE_PROTOCOL_OVERRIDE_ICON_SPEC)
133 icon_spec_free(protocol);
136 /**************************************************************************
137 * GObject stuff
138 **************************************************************************/
139 static void
140 purple_protocol_init(GTypeInstance *instance, gpointer klass)
144 static void
145 purple_protocol_finalize(GObject *object)
147 PurpleProtocol *protocol = PURPLE_PROTOCOL(object);
148 GList *accounts, *l;
150 accounts = purple_accounts_get_all_active();
151 for (l = accounts; l != NULL; l = l->next) {
152 PurpleAccount *account = PURPLE_ACCOUNT(l->data);
153 if (purple_account_is_disconnected(account))
154 continue;
156 if (purple_strequal(protocol->id,
157 purple_account_get_protocol_id(account)))
158 purple_account_disconnect(account);
161 g_list_free(accounts);
163 purple_request_close_with_handle(protocol);
164 purple_notify_close_with_handle(protocol);
166 purple_signals_disconnect_by_handle(protocol);
167 purple_signals_unregister_by_instance(protocol);
169 purple_prefs_disconnect_by_handle(protocol);
171 user_splits_free(protocol);
172 account_options_free(protocol);
173 icon_spec_free(protocol);
175 parent_class->finalize(object);
178 static void
179 purple_protocol_class_init(PurpleProtocolClass *klass)
181 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
183 parent_class = g_type_class_peek_parent(klass);
185 obj_class->finalize = purple_protocol_finalize;
188 GType
189 purple_protocol_get_type(void)
191 static GType type = 0;
193 if (G_UNLIKELY(type == 0)) {
194 static const GTypeInfo info = {
195 .class_size = sizeof(PurpleProtocolClass),
196 .class_init = (GClassInitFunc)purple_protocol_class_init,
197 .instance_size = sizeof(PurpleProtocol),
198 .instance_init = (GInstanceInitFunc)purple_protocol_init,
201 type = g_type_register_static(G_TYPE_OBJECT, "PurpleProtocol",
202 &info, G_TYPE_FLAG_ABSTRACT);
205 return type;
208 /**************************************************************************
209 * Protocol Class API
210 **************************************************************************/
211 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
212 PurpleProtocolClass *klass = PURPLE_PROTOCOL_GET_CLASS(protocol); \
213 g_return_if_fail(klass != NULL); \
214 if (klass->funcname) \
215 klass->funcname(__VA_ARGS__);
217 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
218 PurpleProtocolClass *klass = PURPLE_PROTOCOL_GET_CLASS(protocol); \
219 g_return_val_if_fail(klass != NULL, defaultreturn); \
220 if (klass->funcname) \
221 return klass->funcname(__VA_ARGS__); \
222 else \
223 return defaultreturn;
225 void
226 purple_protocol_class_login(PurpleProtocol *protocol, PurpleAccount *account)
228 DEFINE_PROTOCOL_FUNC(protocol, login, account);
231 void
232 purple_protocol_class_close(PurpleProtocol *protocol, PurpleConnection *gc)
234 DEFINE_PROTOCOL_FUNC(protocol, close, gc);
237 GList *
238 purple_protocol_class_status_types(PurpleProtocol *protocol,
239 PurpleAccount *account)
241 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, status_types, account);
244 const char *
245 purple_protocol_class_list_icon(PurpleProtocol *protocol,
246 PurpleAccount *account, PurpleBuddy *buddy)
248 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, list_icon, account, buddy);
251 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
252 #undef DEFINE_PROTOCOL_FUNC
254 /**************************************************************************
255 * Protocol Client Interface API
256 **************************************************************************/
257 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
258 PurpleProtocolClientInterface *client_iface = \
259 PURPLE_PROTOCOL_CLIENT_GET_IFACE(protocol); \
260 if (client_iface && client_iface->funcname) \
261 client_iface->funcname(__VA_ARGS__);
263 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
264 PurpleProtocolClientInterface *client_iface = \
265 PURPLE_PROTOCOL_CLIENT_GET_IFACE(protocol); \
266 if (client_iface && client_iface->funcname) \
267 return client_iface->funcname(__VA_ARGS__); \
268 else \
269 return defaultreturn;
271 GType
272 purple_protocol_client_iface_get_type(void)
274 static GType type = 0;
276 if (G_UNLIKELY(type == 0)) {
277 static const GTypeInfo info = {
278 .class_size = sizeof(PurpleProtocolClientInterface),
281 type = g_type_register_static(G_TYPE_INTERFACE,
282 "PurpleProtocolClientInterface", &info, 0);
284 return type;
287 GList *
288 purple_protocol_client_iface_get_actions(PurpleProtocol *protocol,
289 PurpleConnection *gc)
291 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, get_actions, gc);
294 const char *
295 purple_protocol_client_iface_list_emblem(PurpleProtocol *protocol,
296 PurpleBuddy *buddy)
298 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, list_emblem, buddy);
301 char *
302 purple_protocol_client_iface_status_text(PurpleProtocol *protocol,
303 PurpleBuddy *buddy)
305 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, status_text, buddy);
308 void
309 purple_protocol_client_iface_tooltip_text(PurpleProtocol *protocol,
310 PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info, gboolean full)
312 DEFINE_PROTOCOL_FUNC(protocol, tooltip_text, buddy, user_info, full);
315 GList *
316 purple_protocol_client_iface_blist_node_menu(PurpleProtocol *protocol,
317 PurpleBlistNode *node)
319 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, blist_node_menu, node);
322 void
323 purple_protocol_client_iface_buddy_free(PurpleProtocol *protocol,
324 PurpleBuddy *buddy)
326 DEFINE_PROTOCOL_FUNC(protocol, buddy_free, buddy);
329 void
330 purple_protocol_client_iface_convo_closed(PurpleProtocol *protocol,
331 PurpleConnection *gc, const char *who)
333 DEFINE_PROTOCOL_FUNC(protocol, convo_closed, gc, who);
336 const char *
337 purple_protocol_client_iface_normalize(PurpleProtocol *protocol,
338 const PurpleAccount *account, const char *who)
340 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, normalize, account, who);
343 PurpleChat *
344 purple_protocol_client_iface_find_blist_chat(PurpleProtocol *protocol,
345 PurpleAccount *account, const char *name)
347 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, find_blist_chat, account,
348 name);
351 gboolean
352 purple_protocol_client_iface_offline_message(PurpleProtocol *protocol,
353 const PurpleBuddy *buddy)
355 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, FALSE, offline_message, buddy);
358 GHashTable *
359 purple_protocol_client_iface_get_account_text_table(PurpleProtocol *protocol,
360 PurpleAccount *account)
362 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, get_account_text_table,
363 account);
366 PurpleMood *
367 purple_protocol_client_iface_get_moods(PurpleProtocol *protocol,
368 PurpleAccount *account)
370 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, get_moods, account);
373 gssize
374 purple_protocol_client_iface_get_max_message_size(PurpleProtocol *protocol,
375 PurpleConversation *conv)
377 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 0, get_max_message_size, conv);
380 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
381 #undef DEFINE_PROTOCOL_FUNC
383 /**************************************************************************
384 * Protocol Server Interface API
385 **************************************************************************/
386 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
387 PurpleProtocolServerInterface *server_iface = \
388 PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol); \
389 if (server_iface && server_iface->funcname) \
390 server_iface->funcname(__VA_ARGS__);
392 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
393 PurpleProtocolServerInterface *server_iface = \
394 PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol); \
395 if (server_iface && server_iface->funcname) \
396 return server_iface->funcname(__VA_ARGS__); \
397 else \
398 return defaultreturn;
400 GType
401 purple_protocol_server_iface_get_type(void)
403 static GType type = 0;
405 if (G_UNLIKELY(type == 0)) {
406 static const GTypeInfo info = {
407 .class_size = sizeof(PurpleProtocolServerInterface),
410 type = g_type_register_static(G_TYPE_INTERFACE,
411 "PurpleProtocolServerInterface", &info, 0);
413 return type;
416 void
417 purple_protocol_server_iface_register_user(PurpleProtocol *protocol,
418 PurpleAccount *account)
420 DEFINE_PROTOCOL_FUNC(protocol, register_user, account);
423 void
424 purple_protocol_server_iface_unregister_user(PurpleProtocol *protocol,
425 PurpleAccount *account, PurpleAccountUnregistrationCb cb,
426 void *user_data)
428 DEFINE_PROTOCOL_FUNC(protocol, unregister_user, account, cb, user_data);
431 void
432 purple_protocol_server_iface_set_info(PurpleProtocol *protocol,
433 PurpleConnection *gc, const char *info)
435 DEFINE_PROTOCOL_FUNC(protocol, set_info, gc, info);
438 void
439 purple_protocol_server_iface_get_info(PurpleProtocol *protocol,
440 PurpleConnection *gc, const char *who)
442 DEFINE_PROTOCOL_FUNC(protocol, get_info, gc, who);
445 void
446 purple_protocol_server_iface_set_status(PurpleProtocol *protocol,
447 PurpleAccount *account, PurpleStatus *status)
449 DEFINE_PROTOCOL_FUNC(protocol, set_status, account, status);
452 void
453 purple_protocol_server_iface_set_idle(PurpleProtocol *protocol,
454 PurpleConnection *gc, int idletime)
456 DEFINE_PROTOCOL_FUNC(protocol, set_idle, gc, idletime);
459 void
460 purple_protocol_server_iface_change_passwd(PurpleProtocol *protocol,
461 PurpleConnection *gc, const char *old_pass, const char *new_pass)
463 DEFINE_PROTOCOL_FUNC(protocol, change_passwd, gc, old_pass, new_pass);
466 void
467 purple_protocol_server_iface_add_buddy(PurpleProtocol *protocol,
468 PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group,
469 const char *message)
471 DEFINE_PROTOCOL_FUNC(protocol, add_buddy, gc, buddy, group, message);
474 void
475 purple_protocol_server_iface_add_buddies(PurpleProtocol *protocol,
476 PurpleConnection *gc, GList *buddies, GList *groups,
477 const char *message)
479 DEFINE_PROTOCOL_FUNC(protocol, add_buddies, gc, buddies, groups, message);
482 void
483 purple_protocol_server_iface_remove_buddy(PurpleProtocol *protocol,
484 PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
486 DEFINE_PROTOCOL_FUNC(protocol, remove_buddy, gc, buddy, group);
489 void
490 purple_protocol_server_iface_remove_buddies(PurpleProtocol *protocol,
491 PurpleConnection *gc, GList *buddies, GList *groups)
493 DEFINE_PROTOCOL_FUNC(protocol, remove_buddies, gc, buddies, groups);
496 void
497 purple_protocol_server_iface_keepalive(PurpleProtocol *protocol,
498 PurpleConnection *gc)
500 DEFINE_PROTOCOL_FUNC(protocol, keepalive, gc);
504 purple_protocol_server_iface_get_keepalive_interval(PurpleProtocol *protocol)
506 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 30, get_keepalive_interval);
509 void
510 purple_protocol_server_iface_alias_buddy(PurpleProtocol *protocol,
511 PurpleConnection *gc, const char *who, const char *alias)
513 DEFINE_PROTOCOL_FUNC(protocol, alias_buddy, gc, who, alias);
516 void
517 purple_protocol_server_iface_group_buddy(PurpleProtocol *protocol,
518 PurpleConnection *gc, const char *who, const char *old_group,
519 const char *new_group)
521 DEFINE_PROTOCOL_FUNC(protocol, group_buddy, gc, who, old_group, new_group);
524 void
525 purple_protocol_server_iface_rename_group(PurpleProtocol *protocol,
526 PurpleConnection *gc, const char *old_name, PurpleGroup *group,
527 GList *moved_buddies)
529 DEFINE_PROTOCOL_FUNC(protocol, rename_group, gc, old_name, group,
530 moved_buddies);
533 void
534 purple_protocol_server_iface_set_buddy_icon(PurpleProtocol *protocol,
535 PurpleConnection *gc, PurpleImage *img)
537 DEFINE_PROTOCOL_FUNC(protocol, set_buddy_icon, gc, img);
540 void
541 purple_protocol_server_iface_remove_group(PurpleProtocol *protocol,
542 PurpleConnection *gc, PurpleGroup *group)
544 DEFINE_PROTOCOL_FUNC(protocol, remove_group, gc, group);
548 purple_protocol_server_iface_send_raw(PurpleProtocol *protocol,
549 PurpleConnection *gc, const char *buf, int len)
551 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 0, send_raw, gc, buf, len);
554 void
555 purple_protocol_server_iface_set_public_alias(PurpleProtocol *protocol,
556 PurpleConnection *gc, const char *alias,
557 PurpleSetPublicAliasSuccessCallback success_cb,
558 PurpleSetPublicAliasFailureCallback failure_cb)
560 DEFINE_PROTOCOL_FUNC(protocol, set_public_alias, gc, alias, success_cb,
561 failure_cb);
564 void
565 purple_protocol_server_iface_get_public_alias(PurpleProtocol *protocol,
566 PurpleConnection *gc, PurpleGetPublicAliasSuccessCallback success_cb,
567 PurpleGetPublicAliasFailureCallback failure_cb)
569 DEFINE_PROTOCOL_FUNC(protocol, get_public_alias, gc, success_cb,
570 failure_cb);
573 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
574 #undef DEFINE_PROTOCOL_FUNC
576 /**************************************************************************
577 * Protocol IM Interface API
578 **************************************************************************/
579 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
580 PurpleProtocolIMInterface *im_iface = \
581 PURPLE_PROTOCOL_IM_GET_IFACE(protocol); \
582 if (im_iface && im_iface->funcname) \
583 im_iface->funcname(__VA_ARGS__);
585 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
586 PurpleProtocolIMInterface *im_iface = \
587 PURPLE_PROTOCOL_IM_GET_IFACE(protocol); \
588 if (im_iface && im_iface->funcname) \
589 return im_iface->funcname(__VA_ARGS__); \
590 else \
591 return defaultreturn;
593 GType
594 purple_protocol_im_iface_get_type(void)
596 static GType type = 0;
598 if (G_UNLIKELY(type == 0)) {
599 static const GTypeInfo info = {
600 .class_size = sizeof(PurpleProtocolIMInterface),
603 type = g_type_register_static(G_TYPE_INTERFACE,
604 "PurpleProtocolIMInterface", &info, 0);
606 return type;
610 purple_protocol_im_iface_send(PurpleProtocol *protocol, PurpleConnection *gc,
611 PurpleMessage *msg)
613 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 0, send, gc, msg);
616 unsigned int
617 purple_protocol_im_iface_send_typing(PurpleProtocol *protocol,
618 PurpleConnection *gc, const char *name, PurpleIMTypingState state)
620 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 0, send_typing, gc, name, state);
623 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
624 #undef DEFINE_PROTOCOL_FUNC
626 /**************************************************************************
627 * Protocol Chat Interface API
628 **************************************************************************/
629 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
630 PurpleProtocolChatInterface *chat_iface = \
631 PURPLE_PROTOCOL_CHAT_GET_IFACE(protocol); \
632 if (chat_iface && chat_iface->funcname) \
633 chat_iface->funcname(__VA_ARGS__);
635 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
636 PurpleProtocolChatInterface *chat_iface = \
637 PURPLE_PROTOCOL_CHAT_GET_IFACE(protocol); \
638 if (chat_iface && chat_iface->funcname) \
639 return chat_iface->funcname(__VA_ARGS__); \
640 else \
641 return defaultreturn;
643 GType
644 purple_protocol_chat_iface_get_type(void)
646 static GType type = 0;
648 if (G_UNLIKELY(type == 0)) {
649 static const GTypeInfo info = {
650 .class_size = sizeof(PurpleProtocolChatInterface),
653 type = g_type_register_static(G_TYPE_INTERFACE,
654 "PurpleProtocolChatInterface", &info, 0);
656 return type;
659 GList *
660 purple_protocol_chat_iface_info(PurpleProtocol *protocol, PurpleConnection *gc)
662 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, info, gc);
665 GHashTable *
666 purple_protocol_chat_iface_info_defaults(PurpleProtocol *protocol,
667 PurpleConnection *gc, const char *chat_name)
669 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, info_defaults, gc,
670 chat_name);
673 void
674 purple_protocol_chat_iface_join(PurpleProtocol *protocol, PurpleConnection *gc,
675 GHashTable *components)
677 DEFINE_PROTOCOL_FUNC(protocol, join, gc, components);
680 void
681 purple_protocol_chat_iface_reject(PurpleProtocol *protocol,
682 PurpleConnection *gc, GHashTable *components)
684 DEFINE_PROTOCOL_FUNC(protocol, reject, gc, components);
687 char *
688 purple_protocol_chat_iface_get_name(PurpleProtocol *protocol,
689 GHashTable *components)
691 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, get_name, components);
694 void
695 purple_protocol_chat_iface_invite(PurpleProtocol *protocol,
696 PurpleConnection *gc, int id, const char *message, const char *who)
698 DEFINE_PROTOCOL_FUNC(protocol, invite, gc, id, message, who);
701 void
702 purple_protocol_chat_iface_leave(PurpleProtocol *protocol, PurpleConnection *gc,
703 int id)
705 DEFINE_PROTOCOL_FUNC(protocol, leave, gc, id);
708 int
709 purple_protocol_chat_iface_send(PurpleProtocol *protocol, PurpleConnection *gc,
710 int id, PurpleMessage *msg)
712 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 0, send, gc, id, msg);
715 char *
716 purple_protocol_chat_iface_get_user_real_name(PurpleProtocol *protocol,
717 PurpleConnection *gc, int id, const char *who)
719 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, get_user_real_name, gc, id,
720 who);
723 void
724 purple_protocol_chat_iface_set_topic(PurpleProtocol *protocol,
725 PurpleConnection *gc, int id, const char *topic)
727 DEFINE_PROTOCOL_FUNC(protocol, set_topic, gc, id, topic);
730 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
731 #undef DEFINE_PROTOCOL_FUNC
733 /**************************************************************************
734 * Protocol Privacy Interface API
735 **************************************************************************/
736 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
737 PurpleProtocolPrivacyInterface *privacy_iface = \
738 PURPLE_PROTOCOL_PRIVACY_GET_IFACE(protocol); \
739 if (privacy_iface && privacy_iface->funcname) \
740 privacy_iface->funcname(__VA_ARGS__);
742 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
743 PurpleProtocolPrivacyInterface *privacy_iface = \
744 PURPLE_PROTOCOL_PRIVACY_GET_IFACE(protocol); \
745 if (privacy_iface && privacy_iface->funcname) \
746 return privacy_iface->funcname(__VA_ARGS__); \
747 else \
748 return defaultreturn;
750 GType
751 purple_protocol_privacy_iface_get_type(void)
753 static GType type = 0;
755 if (G_UNLIKELY(type == 0)) {
756 static const GTypeInfo info = {
757 .class_size = sizeof(PurpleProtocolPrivacyInterface),
760 type = g_type_register_static(G_TYPE_INTERFACE,
761 "PurpleProtocolPrivacyInterface", &info, 0);
763 return type;
766 void
767 purple_protocol_privacy_iface_add_permit(PurpleProtocol *protocol,
768 PurpleConnection *gc, const char *name)
770 DEFINE_PROTOCOL_FUNC(protocol, add_permit, gc, name);
773 void
774 purple_protocol_privacy_iface_add_deny(PurpleProtocol *protocol,
775 PurpleConnection *gc, const char *name)
777 DEFINE_PROTOCOL_FUNC(protocol, add_deny, gc, name);
780 void
781 purple_protocol_privacy_iface_rem_permit(PurpleProtocol *protocol,
782 PurpleConnection *gc, const char *name)
784 DEFINE_PROTOCOL_FUNC(protocol, rem_permit, gc, name);
787 void
788 purple_protocol_privacy_iface_rem_deny(PurpleProtocol *protocol,
789 PurpleConnection *gc, const char *name)
791 DEFINE_PROTOCOL_FUNC(protocol, rem_deny, gc, name);
794 void
795 purple_protocol_privacy_iface_set_permit_deny(PurpleProtocol *protocol,
796 PurpleConnection *gc)
798 DEFINE_PROTOCOL_FUNC(protocol, set_permit_deny, gc);
801 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
802 #undef DEFINE_PROTOCOL_FUNC
804 /**************************************************************************
805 * Protocol Roomlist Interface API
806 **************************************************************************/
807 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
808 PurpleProtocolRoomlistInterface *roomlist_iface = \
809 PURPLE_PROTOCOL_ROOMLIST_GET_IFACE(protocol); \
810 if (roomlist_iface && roomlist_iface->funcname) \
811 roomlist_iface->funcname(__VA_ARGS__);
813 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
814 PurpleProtocolRoomlistInterface *roomlist_iface = \
815 PURPLE_PROTOCOL_ROOMLIST_GET_IFACE(protocol); \
816 if (roomlist_iface && roomlist_iface->funcname) \
817 return roomlist_iface->funcname(__VA_ARGS__); \
818 else \
819 return defaultreturn;
821 GType
822 purple_protocol_roomlist_iface_get_type(void)
824 static GType type = 0;
826 if (G_UNLIKELY(type == 0)) {
827 static const GTypeInfo info = {
828 .class_size = sizeof(PurpleProtocolRoomlistInterface),
831 type = g_type_register_static(G_TYPE_INTERFACE,
832 "PurpleProtocolRoomlistInterface", &info, 0);
834 return type;
837 PurpleRoomlist *
838 purple_protocol_roomlist_iface_get_list(PurpleProtocol *protocol,
839 PurpleConnection *gc)
841 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, get_list, gc);
844 void
845 purple_protocol_roomlist_iface_cancel(PurpleProtocol *protocol,
846 PurpleRoomlist *list)
848 DEFINE_PROTOCOL_FUNC(protocol, cancel, list);
851 void
852 purple_protocol_roomlist_iface_expand_category(PurpleProtocol *protocol,
853 PurpleRoomlist *list, PurpleRoomlistRoom *category)
855 DEFINE_PROTOCOL_FUNC(protocol, expand_category, list, category);
858 char *
859 purple_protocol_roomlist_iface_room_serialize(PurpleProtocol *protocol,
860 PurpleRoomlistRoom *room)
862 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, room_serialize, room);
865 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
866 #undef DEFINE_PROTOCOL_FUNC
868 /**************************************************************************
869 * Protocol Media Interface API
870 **************************************************************************/
871 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
872 PurpleProtocolMediaInterface *media_iface = \
873 PURPLE_PROTOCOL_MEDIA_GET_IFACE(protocol); \
874 if (media_iface && media_iface->funcname) \
875 media_iface->funcname(__VA_ARGS__);
877 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
878 PurpleProtocolMediaInterface *media_iface = \
879 PURPLE_PROTOCOL_MEDIA_GET_IFACE(protocol); \
880 if (media_iface && media_iface->funcname) \
881 return media_iface->funcname(__VA_ARGS__); \
882 else \
883 return defaultreturn;
885 GType
886 purple_protocol_media_iface_get_type(void)
888 static GType type = 0;
890 if (G_UNLIKELY(type == 0)) {
891 static const GTypeInfo info = {
892 .class_size = sizeof(PurpleProtocolMediaInterface),
895 type = g_type_register_static(G_TYPE_INTERFACE,
896 "PurpleProtocolMediaInterface", &info, 0);
898 return type;
901 gboolean
902 purple_protocol_media_iface_initiate_session(PurpleProtocol *protocol,
903 PurpleAccount *account, const char *who, PurpleMediaSessionType type)
905 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, FALSE, initiate_session, account,
906 who, type);
909 PurpleMediaCaps
910 purple_protocol_media_iface_get_caps(PurpleProtocol *protocol,
911 PurpleAccount *account, const char *who)
913 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 0, get_caps, account, who);
916 gboolean purple_protocol_media_iface_send_dtmf(PurpleProtocol *protocol,
917 PurpleMedia *media, gchar dtmf, guint8 volume, guint8 duration)
919 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, FALSE, send_dtmf, media,
920 dtmf, volume, duration);
923 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
924 #undef DEFINE_PROTOCOL_FUNC
926 /**************************************************************************
927 * Protocol Factory Interface API
928 **************************************************************************/
929 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
930 PurpleProtocolFactoryInterface *factory_iface = \
931 PURPLE_PROTOCOL_FACTORY_GET_IFACE(protocol); \
932 if (factory_iface && factory_iface->funcname) \
933 factory_iface->funcname(__VA_ARGS__);
935 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
936 PurpleProtocolFactoryInterface *factory_iface = \
937 PURPLE_PROTOCOL_FACTORY_GET_IFACE(protocol); \
938 if (factory_iface && factory_iface->funcname) \
939 return factory_iface->funcname(__VA_ARGS__); \
940 else \
941 return defaultreturn;
943 GType
944 purple_protocol_factory_iface_get_type(void)
946 static GType type = 0;
948 if (G_UNLIKELY(type == 0)) {
949 static const GTypeInfo info = {
950 .class_size = sizeof(PurpleProtocolFactoryInterface),
953 type = g_type_register_static(G_TYPE_INTERFACE,
954 "PurpleProtocolFactoryInterface", &info, 0);
956 return type;
959 PurpleConnection *
960 purple_protocol_factory_iface_connection_new(PurpleProtocol *protocol,
961 PurpleAccount *account, const char *password)
963 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, connection_new, protocol,
964 account, password);
967 PurpleRoomlist *
968 purple_protocol_factory_iface_roomlist_new(PurpleProtocol *protocol,
969 PurpleAccount *account)
971 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, roomlist_new, account);
974 PurpleWhiteboard *
975 purple_protocol_factory_iface_whiteboard_new(PurpleProtocol *protocol,
976 PurpleAccount *account, const char *who, int state)
978 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, whiteboard_new, account,
979 who, state);
982 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
983 #undef DEFINE_PROTOCOL_FUNC