rename accountopt.[ch] to purpleaccountoption.[ch]
[pidgin-git.git] / libpurple / protocol.c
blob3e53e5ba7b5ef252312a1f5acdfd6cd05bff36a1
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 /**************************************************************************
123 * GObject stuff
124 **************************************************************************/
125 static void
126 purple_protocol_init(GTypeInstance *instance, gpointer klass)
130 static void
131 purple_protocol_finalize(GObject *object)
133 PurpleProtocol *protocol = PURPLE_PROTOCOL(object);
134 GList *accounts, *l;
136 accounts = purple_accounts_get_all_active();
137 for (l = accounts; l != NULL; l = l->next) {
138 PurpleAccount *account = PURPLE_ACCOUNT(l->data);
139 if (purple_account_is_disconnected(account))
140 continue;
142 if (purple_strequal(protocol->id,
143 purple_account_get_protocol_id(account)))
144 purple_account_disconnect(account);
147 g_list_free(accounts);
149 purple_request_close_with_handle(protocol);
150 purple_notify_close_with_handle(protocol);
152 purple_signals_disconnect_by_handle(protocol);
153 purple_signals_unregister_by_instance(protocol);
155 purple_prefs_disconnect_by_handle(protocol);
157 user_splits_free(protocol);
158 account_options_free(protocol);
159 icon_spec_free(protocol);
161 parent_class->finalize(object);
164 static void
165 purple_protocol_class_init(PurpleProtocolClass *klass)
167 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
169 parent_class = g_type_class_peek_parent(klass);
171 obj_class->finalize = purple_protocol_finalize;
174 GType
175 purple_protocol_get_type(void)
177 static GType type = 0;
179 if (G_UNLIKELY(type == 0)) {
180 static const GTypeInfo info = {
181 .class_size = sizeof(PurpleProtocolClass),
182 .class_init = (GClassInitFunc)purple_protocol_class_init,
183 .instance_size = sizeof(PurpleProtocol),
184 .instance_init = (GInstanceInitFunc)purple_protocol_init,
187 type = g_type_register_static(G_TYPE_OBJECT, "PurpleProtocol",
188 &info, G_TYPE_FLAG_ABSTRACT);
191 return type;
194 /**************************************************************************
195 * Protocol Class API
196 **************************************************************************/
197 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
198 PurpleProtocolClass *klass = PURPLE_PROTOCOL_GET_CLASS(protocol); \
199 g_return_if_fail(klass != NULL); \
200 if (klass->funcname) \
201 klass->funcname(__VA_ARGS__);
203 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
204 PurpleProtocolClass *klass = PURPLE_PROTOCOL_GET_CLASS(protocol); \
205 g_return_val_if_fail(klass != NULL, defaultreturn); \
206 if (klass->funcname) \
207 return klass->funcname(__VA_ARGS__); \
208 else \
209 return defaultreturn;
211 void
212 purple_protocol_class_login(PurpleProtocol *protocol, PurpleAccount *account)
214 DEFINE_PROTOCOL_FUNC(protocol, login, account);
217 void
218 purple_protocol_class_close(PurpleProtocol *protocol, PurpleConnection *gc)
220 DEFINE_PROTOCOL_FUNC(protocol, close, gc);
223 GList *
224 purple_protocol_class_status_types(PurpleProtocol *protocol,
225 PurpleAccount *account)
227 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, status_types, account);
230 const char *
231 purple_protocol_class_list_icon(PurpleProtocol *protocol,
232 PurpleAccount *account, PurpleBuddy *buddy)
234 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, list_icon, account, buddy);
237 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
238 #undef DEFINE_PROTOCOL_FUNC
240 /**************************************************************************
241 * Protocol Client Interface API
242 **************************************************************************/
243 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
244 PurpleProtocolClientInterface *client_iface = \
245 PURPLE_PROTOCOL_CLIENT_GET_IFACE(protocol); \
246 if (client_iface && client_iface->funcname) \
247 client_iface->funcname(__VA_ARGS__);
249 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
250 PurpleProtocolClientInterface *client_iface = \
251 PURPLE_PROTOCOL_CLIENT_GET_IFACE(protocol); \
252 if (client_iface && client_iface->funcname) \
253 return client_iface->funcname(__VA_ARGS__); \
254 else \
255 return defaultreturn;
257 GType
258 purple_protocol_client_iface_get_type(void)
260 static GType type = 0;
262 if (G_UNLIKELY(type == 0)) {
263 static const GTypeInfo info = {
264 .class_size = sizeof(PurpleProtocolClientInterface),
267 type = g_type_register_static(G_TYPE_INTERFACE,
268 "PurpleProtocolClientInterface", &info, 0);
270 return type;
273 GList *
274 purple_protocol_client_iface_get_actions(PurpleProtocol *protocol,
275 PurpleConnection *gc)
277 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, get_actions, gc);
280 const char *
281 purple_protocol_client_iface_list_emblem(PurpleProtocol *protocol,
282 PurpleBuddy *buddy)
284 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, list_emblem, buddy);
287 char *
288 purple_protocol_client_iface_status_text(PurpleProtocol *protocol,
289 PurpleBuddy *buddy)
291 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, status_text, buddy);
294 void
295 purple_protocol_client_iface_tooltip_text(PurpleProtocol *protocol,
296 PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info, gboolean full)
298 DEFINE_PROTOCOL_FUNC(protocol, tooltip_text, buddy, user_info, full);
301 GList *
302 purple_protocol_client_iface_blist_node_menu(PurpleProtocol *protocol,
303 PurpleBlistNode *node)
305 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, blist_node_menu, node);
308 void
309 purple_protocol_client_iface_buddy_free(PurpleProtocol *protocol,
310 PurpleBuddy *buddy)
312 DEFINE_PROTOCOL_FUNC(protocol, buddy_free, buddy);
315 void
316 purple_protocol_client_iface_convo_closed(PurpleProtocol *protocol,
317 PurpleConnection *gc, const char *who)
319 DEFINE_PROTOCOL_FUNC(protocol, convo_closed, gc, who);
322 const char *
323 purple_protocol_client_iface_normalize(PurpleProtocol *protocol,
324 const PurpleAccount *account, const char *who)
326 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, normalize, account, who);
329 PurpleChat *
330 purple_protocol_client_iface_find_blist_chat(PurpleProtocol *protocol,
331 PurpleAccount *account, const char *name)
333 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, find_blist_chat, account,
334 name);
337 gboolean
338 purple_protocol_client_iface_offline_message(PurpleProtocol *protocol,
339 const PurpleBuddy *buddy)
341 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, FALSE, offline_message, buddy);
344 GHashTable *
345 purple_protocol_client_iface_get_account_text_table(PurpleProtocol *protocol,
346 PurpleAccount *account)
348 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, get_account_text_table,
349 account);
352 PurpleMood *
353 purple_protocol_client_iface_get_moods(PurpleProtocol *protocol,
354 PurpleAccount *account)
356 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, get_moods, account);
359 gssize
360 purple_protocol_client_iface_get_max_message_size(PurpleProtocol *protocol,
361 PurpleConversation *conv)
363 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 0, get_max_message_size, conv);
366 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
367 #undef DEFINE_PROTOCOL_FUNC
369 /**************************************************************************
370 * Protocol Server Interface API
371 **************************************************************************/
372 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
373 PurpleProtocolServerInterface *server_iface = \
374 PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol); \
375 if (server_iface && server_iface->funcname) \
376 server_iface->funcname(__VA_ARGS__);
378 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
379 PurpleProtocolServerInterface *server_iface = \
380 PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol); \
381 if (server_iface && server_iface->funcname) \
382 return server_iface->funcname(__VA_ARGS__); \
383 else \
384 return defaultreturn;
386 GType
387 purple_protocol_server_iface_get_type(void)
389 static GType type = 0;
391 if (G_UNLIKELY(type == 0)) {
392 static const GTypeInfo info = {
393 .class_size = sizeof(PurpleProtocolServerInterface),
396 type = g_type_register_static(G_TYPE_INTERFACE,
397 "PurpleProtocolServerInterface", &info, 0);
399 return type;
402 void
403 purple_protocol_server_iface_register_user(PurpleProtocol *protocol,
404 PurpleAccount *account)
406 DEFINE_PROTOCOL_FUNC(protocol, register_user, account);
409 void
410 purple_protocol_server_iface_unregister_user(PurpleProtocol *protocol,
411 PurpleAccount *account, PurpleAccountUnregistrationCb cb,
412 void *user_data)
414 DEFINE_PROTOCOL_FUNC(protocol, unregister_user, account, cb, user_data);
417 void
418 purple_protocol_server_iface_set_info(PurpleProtocol *protocol,
419 PurpleConnection *gc, const char *info)
421 DEFINE_PROTOCOL_FUNC(protocol, set_info, gc, info);
424 void
425 purple_protocol_server_iface_get_info(PurpleProtocol *protocol,
426 PurpleConnection *gc, const char *who)
428 DEFINE_PROTOCOL_FUNC(protocol, get_info, gc, who);
431 void
432 purple_protocol_server_iface_set_status(PurpleProtocol *protocol,
433 PurpleAccount *account, PurpleStatus *status)
435 DEFINE_PROTOCOL_FUNC(protocol, set_status, account, status);
438 void
439 purple_protocol_server_iface_set_idle(PurpleProtocol *protocol,
440 PurpleConnection *gc, int idletime)
442 DEFINE_PROTOCOL_FUNC(protocol, set_idle, gc, idletime);
445 void
446 purple_protocol_server_iface_change_passwd(PurpleProtocol *protocol,
447 PurpleConnection *gc, const char *old_pass, const char *new_pass)
449 DEFINE_PROTOCOL_FUNC(protocol, change_passwd, gc, old_pass, new_pass);
452 void
453 purple_protocol_server_iface_add_buddy(PurpleProtocol *protocol,
454 PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group,
455 const char *message)
457 DEFINE_PROTOCOL_FUNC(protocol, add_buddy, gc, buddy, group, message);
460 void
461 purple_protocol_server_iface_add_buddies(PurpleProtocol *protocol,
462 PurpleConnection *gc, GList *buddies, GList *groups,
463 const char *message)
465 DEFINE_PROTOCOL_FUNC(protocol, add_buddies, gc, buddies, groups, message);
468 void
469 purple_protocol_server_iface_remove_buddy(PurpleProtocol *protocol,
470 PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
472 DEFINE_PROTOCOL_FUNC(protocol, remove_buddy, gc, buddy, group);
475 void
476 purple_protocol_server_iface_remove_buddies(PurpleProtocol *protocol,
477 PurpleConnection *gc, GList *buddies, GList *groups)
479 DEFINE_PROTOCOL_FUNC(protocol, remove_buddies, gc, buddies, groups);
482 void
483 purple_protocol_server_iface_keepalive(PurpleProtocol *protocol,
484 PurpleConnection *gc)
486 DEFINE_PROTOCOL_FUNC(protocol, keepalive, gc);
490 purple_protocol_server_iface_get_keepalive_interval(PurpleProtocol *protocol)
492 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 30, get_keepalive_interval);
495 void
496 purple_protocol_server_iface_alias_buddy(PurpleProtocol *protocol,
497 PurpleConnection *gc, const char *who, const char *alias)
499 DEFINE_PROTOCOL_FUNC(protocol, alias_buddy, gc, who, alias);
502 void
503 purple_protocol_server_iface_group_buddy(PurpleProtocol *protocol,
504 PurpleConnection *gc, const char *who, const char *old_group,
505 const char *new_group)
507 DEFINE_PROTOCOL_FUNC(protocol, group_buddy, gc, who, old_group, new_group);
510 void
511 purple_protocol_server_iface_rename_group(PurpleProtocol *protocol,
512 PurpleConnection *gc, const char *old_name, PurpleGroup *group,
513 GList *moved_buddies)
515 DEFINE_PROTOCOL_FUNC(protocol, rename_group, gc, old_name, group,
516 moved_buddies);
519 void
520 purple_protocol_server_iface_set_buddy_icon(PurpleProtocol *protocol,
521 PurpleConnection *gc, PurpleImage *img)
523 DEFINE_PROTOCOL_FUNC(protocol, set_buddy_icon, gc, img);
526 void
527 purple_protocol_server_iface_remove_group(PurpleProtocol *protocol,
528 PurpleConnection *gc, PurpleGroup *group)
530 DEFINE_PROTOCOL_FUNC(protocol, remove_group, gc, group);
534 purple_protocol_server_iface_send_raw(PurpleProtocol *protocol,
535 PurpleConnection *gc, const char *buf, int len)
537 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 0, send_raw, gc, buf, len);
540 void
541 purple_protocol_server_iface_set_public_alias(PurpleProtocol *protocol,
542 PurpleConnection *gc, const char *alias,
543 PurpleSetPublicAliasSuccessCallback success_cb,
544 PurpleSetPublicAliasFailureCallback failure_cb)
546 DEFINE_PROTOCOL_FUNC(protocol, set_public_alias, gc, alias, success_cb,
547 failure_cb);
550 void
551 purple_protocol_server_iface_get_public_alias(PurpleProtocol *protocol,
552 PurpleConnection *gc, PurpleGetPublicAliasSuccessCallback success_cb,
553 PurpleGetPublicAliasFailureCallback failure_cb)
555 DEFINE_PROTOCOL_FUNC(protocol, get_public_alias, gc, success_cb,
556 failure_cb);
559 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
560 #undef DEFINE_PROTOCOL_FUNC
562 /**************************************************************************
563 * Protocol IM Interface API
564 **************************************************************************/
565 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
566 PurpleProtocolIMInterface *im_iface = \
567 PURPLE_PROTOCOL_IM_GET_IFACE(protocol); \
568 if (im_iface && im_iface->funcname) \
569 im_iface->funcname(__VA_ARGS__);
571 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
572 PurpleProtocolIMInterface *im_iface = \
573 PURPLE_PROTOCOL_IM_GET_IFACE(protocol); \
574 if (im_iface && im_iface->funcname) \
575 return im_iface->funcname(__VA_ARGS__); \
576 else \
577 return defaultreturn;
579 GType
580 purple_protocol_im_iface_get_type(void)
582 static GType type = 0;
584 if (G_UNLIKELY(type == 0)) {
585 static const GTypeInfo info = {
586 .class_size = sizeof(PurpleProtocolIMInterface),
589 type = g_type_register_static(G_TYPE_INTERFACE,
590 "PurpleProtocolIMInterface", &info, 0);
592 return type;
596 purple_protocol_im_iface_send(PurpleProtocol *protocol, PurpleConnection *gc,
597 PurpleMessage *msg)
599 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 0, send, gc, msg);
602 unsigned int
603 purple_protocol_im_iface_send_typing(PurpleProtocol *protocol,
604 PurpleConnection *gc, const char *name, PurpleIMTypingState state)
606 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 0, send_typing, gc, name, state);
609 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
610 #undef DEFINE_PROTOCOL_FUNC
612 /**************************************************************************
613 * Protocol Chat Interface API
614 **************************************************************************/
615 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
616 PurpleProtocolChatInterface *chat_iface = \
617 PURPLE_PROTOCOL_CHAT_GET_IFACE(protocol); \
618 if (chat_iface && chat_iface->funcname) \
619 chat_iface->funcname(__VA_ARGS__);
621 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
622 PurpleProtocolChatInterface *chat_iface = \
623 PURPLE_PROTOCOL_CHAT_GET_IFACE(protocol); \
624 if (chat_iface && chat_iface->funcname) \
625 return chat_iface->funcname(__VA_ARGS__); \
626 else \
627 return defaultreturn;
629 GType
630 purple_protocol_chat_iface_get_type(void)
632 static GType type = 0;
634 if (G_UNLIKELY(type == 0)) {
635 static const GTypeInfo info = {
636 .class_size = sizeof(PurpleProtocolChatInterface),
639 type = g_type_register_static(G_TYPE_INTERFACE,
640 "PurpleProtocolChatInterface", &info, 0);
642 return type;
645 GList *
646 purple_protocol_chat_iface_info(PurpleProtocol *protocol, PurpleConnection *gc)
648 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, info, gc);
651 GHashTable *
652 purple_protocol_chat_iface_info_defaults(PurpleProtocol *protocol,
653 PurpleConnection *gc, const char *chat_name)
655 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, info_defaults, gc,
656 chat_name);
659 void
660 purple_protocol_chat_iface_join(PurpleProtocol *protocol, PurpleConnection *gc,
661 GHashTable *components)
663 DEFINE_PROTOCOL_FUNC(protocol, join, gc, components);
666 void
667 purple_protocol_chat_iface_reject(PurpleProtocol *protocol,
668 PurpleConnection *gc, GHashTable *components)
670 DEFINE_PROTOCOL_FUNC(protocol, reject, gc, components);
673 char *
674 purple_protocol_chat_iface_get_name(PurpleProtocol *protocol,
675 GHashTable *components)
677 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, get_name, components);
680 void
681 purple_protocol_chat_iface_invite(PurpleProtocol *protocol,
682 PurpleConnection *gc, int id, const char *message, const char *who)
684 DEFINE_PROTOCOL_FUNC(protocol, invite, gc, id, message, who);
687 void
688 purple_protocol_chat_iface_leave(PurpleProtocol *protocol, PurpleConnection *gc,
689 int id)
691 DEFINE_PROTOCOL_FUNC(protocol, leave, gc, id);
694 int
695 purple_protocol_chat_iface_send(PurpleProtocol *protocol, PurpleConnection *gc,
696 int id, PurpleMessage *msg)
698 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 0, send, gc, id, msg);
701 char *
702 purple_protocol_chat_iface_get_user_real_name(PurpleProtocol *protocol,
703 PurpleConnection *gc, int id, const char *who)
705 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, get_user_real_name, gc, id,
706 who);
709 void
710 purple_protocol_chat_iface_set_topic(PurpleProtocol *protocol,
711 PurpleConnection *gc, int id, const char *topic)
713 DEFINE_PROTOCOL_FUNC(protocol, set_topic, gc, id, topic);
716 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
717 #undef DEFINE_PROTOCOL_FUNC
719 /**************************************************************************
720 * Protocol Privacy Interface API
721 **************************************************************************/
722 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
723 PurpleProtocolPrivacyInterface *privacy_iface = \
724 PURPLE_PROTOCOL_PRIVACY_GET_IFACE(protocol); \
725 if (privacy_iface && privacy_iface->funcname) \
726 privacy_iface->funcname(__VA_ARGS__);
728 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
729 PurpleProtocolPrivacyInterface *privacy_iface = \
730 PURPLE_PROTOCOL_PRIVACY_GET_IFACE(protocol); \
731 if (privacy_iface && privacy_iface->funcname) \
732 return privacy_iface->funcname(__VA_ARGS__); \
733 else \
734 return defaultreturn;
736 GType
737 purple_protocol_privacy_iface_get_type(void)
739 static GType type = 0;
741 if (G_UNLIKELY(type == 0)) {
742 static const GTypeInfo info = {
743 .class_size = sizeof(PurpleProtocolPrivacyInterface),
746 type = g_type_register_static(G_TYPE_INTERFACE,
747 "PurpleProtocolPrivacyInterface", &info, 0);
749 return type;
752 void
753 purple_protocol_privacy_iface_add_permit(PurpleProtocol *protocol,
754 PurpleConnection *gc, const char *name)
756 DEFINE_PROTOCOL_FUNC(protocol, add_permit, gc, name);
759 void
760 purple_protocol_privacy_iface_add_deny(PurpleProtocol *protocol,
761 PurpleConnection *gc, const char *name)
763 DEFINE_PROTOCOL_FUNC(protocol, add_deny, gc, name);
766 void
767 purple_protocol_privacy_iface_rem_permit(PurpleProtocol *protocol,
768 PurpleConnection *gc, const char *name)
770 DEFINE_PROTOCOL_FUNC(protocol, rem_permit, gc, name);
773 void
774 purple_protocol_privacy_iface_rem_deny(PurpleProtocol *protocol,
775 PurpleConnection *gc, const char *name)
777 DEFINE_PROTOCOL_FUNC(protocol, rem_deny, gc, name);
780 void
781 purple_protocol_privacy_iface_set_permit_deny(PurpleProtocol *protocol,
782 PurpleConnection *gc)
784 DEFINE_PROTOCOL_FUNC(protocol, set_permit_deny, gc);
787 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
788 #undef DEFINE_PROTOCOL_FUNC
790 /**************************************************************************
791 * Protocol Media Interface API
792 **************************************************************************/
793 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
794 PurpleProtocolMediaInterface *media_iface = \
795 PURPLE_PROTOCOL_MEDIA_GET_IFACE(protocol); \
796 if (media_iface && media_iface->funcname) \
797 media_iface->funcname(__VA_ARGS__);
799 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
800 PurpleProtocolMediaInterface *media_iface = \
801 PURPLE_PROTOCOL_MEDIA_GET_IFACE(protocol); \
802 if (media_iface && media_iface->funcname) \
803 return media_iface->funcname(__VA_ARGS__); \
804 else \
805 return defaultreturn;
807 GType
808 purple_protocol_media_iface_get_type(void)
810 static GType type = 0;
812 if (G_UNLIKELY(type == 0)) {
813 static const GTypeInfo info = {
814 .class_size = sizeof(PurpleProtocolMediaInterface),
817 type = g_type_register_static(G_TYPE_INTERFACE,
818 "PurpleProtocolMediaInterface", &info, 0);
820 return type;
823 gboolean
824 purple_protocol_media_iface_initiate_session(PurpleProtocol *protocol,
825 PurpleAccount *account, const char *who, PurpleMediaSessionType type)
827 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, FALSE, initiate_session, account,
828 who, type);
831 PurpleMediaCaps
832 purple_protocol_media_iface_get_caps(PurpleProtocol *protocol,
833 PurpleAccount *account, const char *who)
835 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, 0, get_caps, account, who);
838 gboolean purple_protocol_media_iface_send_dtmf(PurpleProtocol *protocol,
839 PurpleMedia *media, gchar dtmf, guint8 volume, guint8 duration)
841 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, FALSE, send_dtmf, media,
842 dtmf, volume, duration);
845 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
846 #undef DEFINE_PROTOCOL_FUNC
848 /**************************************************************************
849 * Protocol Factory Interface API
850 **************************************************************************/
851 #define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
852 PurpleProtocolFactoryInterface *factory_iface = \
853 PURPLE_PROTOCOL_FACTORY_GET_IFACE(protocol); \
854 if (factory_iface && factory_iface->funcname) \
855 factory_iface->funcname(__VA_ARGS__);
857 #define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
858 PurpleProtocolFactoryInterface *factory_iface = \
859 PURPLE_PROTOCOL_FACTORY_GET_IFACE(protocol); \
860 if (factory_iface && factory_iface->funcname) \
861 return factory_iface->funcname(__VA_ARGS__); \
862 else \
863 return defaultreturn;
865 GType
866 purple_protocol_factory_iface_get_type(void)
868 static GType type = 0;
870 if (G_UNLIKELY(type == 0)) {
871 static const GTypeInfo info = {
872 .class_size = sizeof(PurpleProtocolFactoryInterface),
875 type = g_type_register_static(G_TYPE_INTERFACE,
876 "PurpleProtocolFactoryInterface", &info, 0);
878 return type;
881 PurpleConnection *
882 purple_protocol_factory_iface_connection_new(PurpleProtocol *protocol,
883 PurpleAccount *account, const char *password)
885 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, connection_new, protocol,
886 account, password);
889 PurpleRoomlist *
890 purple_protocol_factory_iface_roomlist_new(PurpleProtocol *protocol,
891 PurpleAccount *account)
893 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, roomlist_new, account);
896 PurpleWhiteboard *
897 purple_protocol_factory_iface_whiteboard_new(PurpleProtocol *protocol,
898 PurpleAccount *account, const char *who, int state)
900 DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, whiteboard_new, account,
901 who, state);
904 #undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
905 #undef DEFINE_PROTOCOL_FUNC