Mercurial > pidgin.yaz
changeset 27086:60cb86295f08
Examples for the namespace-(un)registering of IQs and added IPC versions
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Wed, 03 Jun 2009 05:51:51 +0000 |
parents | 61d817c4c935 |
children | 8502d69e45ed |
files | libpurple/plugins/signals-test.c libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/libxmpp.c |
diffstat | 3 files changed, 68 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/plugins/signals-test.c Wed Jun 03 04:55:06 2009 +0000 +++ b/libpurple/plugins/signals-test.c Wed Jun 03 05:51:51 2009 +0000 @@ -661,6 +661,37 @@ return FALSE; } +static gboolean +jabber_watched_iq(PurpleConnection *pc, const char *type, const char *id, + const char *from, xmlnode *child) +{ + purple_debug_misc("signals test", "jabber watched IQ (type=%s, id=%s, from=%s)\n" + "child %p name=%s, namespace=%s\n", + type, id, from, child, child->name, + xmlnode_get_namespace(child)); + + if (g_str_equal(type, "get") || g_str_equal(type, "set")) { + PurplePlugin *prpl; + PurplePluginProtocolInfo *prpl_info; + char *str; + + /* Send the requisite reply */ + xmlnode *iq = xmlnode_new("iq"); + xmlnode_set_attrib(iq, "to", from); + xmlnode_set_attrib(iq, "id", id); + xmlnode_set_attrib(iq, "type", "result"); + + str = xmlnode_to_str(iq, NULL); + prpl = purple_connection_get_prpl(pc); + prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); + prpl_info->send_raw(pc, str, -1); + g_free(str); + } + + /* Cookie monster eats IQ stanzas; the prpl shouldn't keep processing */ + return TRUE; +} + /************************************************************************** * Plugin stuff **************************************************************************/ @@ -830,6 +861,16 @@ PURPLE_CALLBACK(jabber_message_received), NULL); purple_signal_connect(jabber_handle, "jabber-receiving-presence", plugin, PURPLE_CALLBACK(jabber_presence_received), NULL); + + /* IQ namespace signals */ + purple_signal_emit(jabber_handle, "jabber-register-namespace-watcher", + "bogus_node", "super-duper-namespace"); + /* The above is equivalent to doing: + int result = GPOINTER_TO_INT(purple_plugin_ipc_call(jabber_handle, "register_namespace_watcher", &ok, "bogus_node", "super-duper-namespace")); + */ + + purple_signal_connect(jabber_handle, "jabber-watched-iq", plugin, + PURPLE_CALLBACK(jabber_watched_iq), NULL); } return TRUE; @@ -838,8 +879,19 @@ static gboolean plugin_unload(PurplePlugin *plugin) { + void *jabber_handle = purple_plugins_find_with_id("prpl-jabber"); + purple_signals_disconnect_by_handle(plugin); + if (jabber_handle) { + /* Unregister watched namespaces */ + purple_signal_emit(jabber_handle, "jabber-unregister-namespace-watcher", + "bogus_node", "super-duper-namespace"); + /* The above is equivalent to doing: + int result = GPOINTER_TO_INT(purple_plugin_ipc_call(jabber_handle, "unregister_namespace_watcher", &ok, "bogus_node", "super-duper-namespace")); + */ + } + return TRUE; }
--- a/libpurple/protocols/jabber/jabber.c Wed Jun 03 04:55:06 2009 +0000 +++ b/libpurple/protocols/jabber/jabber.c Wed Jun 03 05:51:51 2009 +0000 @@ -3451,6 +3451,21 @@ purple_marshal_VOID__POINTER, NULL, 1, purple_value_new(PURPLE_TYPE_STRING)); + + /* Modifying these? Look at libxmpp.c:load_plugin for the signal versions */ + purple_plugin_ipc_register(plugin, "register_namespace_watcher", + PURPLE_CALLBACK(jabber_iq_signal_register), + purple_marshal_VOID__POINTER_POINTER, + NULL, 2, + purple_value_new(PURPLE_TYPE_STRING), /* node */ + purple_value_new(PURPLE_TYPE_STRING)); /* namespace */ + + purple_plugin_ipc_register(plugin, "unregister_namespace_watcher", + PURPLE_CALLBACK(jabber_iq_signal_unregister), + purple_marshal_VOID__POINTER_POINTER, + NULL, 2, + purple_value_new(PURPLE_TYPE_STRING), /* node */ + purple_value_new(PURPLE_TYPE_STRING)); /* namespace */ } void
--- a/libpurple/protocols/jabber/libxmpp.c Wed Jun 03 04:55:06 2009 +0000 +++ b/libpurple/protocols/jabber/libxmpp.c Wed Jun 03 05:51:51 2009 +0000 @@ -170,6 +170,7 @@ purple_value_new(PURPLE_TYPE_STRING), /* from */ purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_XMLNODE)); /* child */ + /* Modifying these? Look at jabber_init_plugin for the ipc versions */ purple_signal_register(plugin, "jabber-register-namespace-watcher", purple_marshal_VOID__POINTER_POINTER, NULL, 2,