cpw.darkrain42.xmpp.disco: 962bd448: Examples for the namespace-(un)registeri...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Wed Jun 3 01:55:29 EDT 2009


-----------------------------------------------------------------
Revision: 962bd448c2425395084969c7da1ca785d37e598c
Ancestor: f88f493ce9e17c338e5a22edad2aaafb80069813
Author: darkrain42 at pidgin.im
Date: 2009-06-03T05:51:51
Branch: im.pidgin.cpw.darkrain42.xmpp.disco
URL: http://d.pidgin.im/viewmtn/revision/info/962bd448c2425395084969c7da1ca785d37e598c

Modified files:
        libpurple/plugins/signals-test.c
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/libxmpp.c

ChangeLog: 

Examples for the namespace-(un)registering of IQs and added IPC versions

-------------- next part --------------
============================================================
--- libpurple/plugins/signals-test.c	b02b437c5106a8ba6f4cc380472f5161cad87807
+++ libpurple/plugins/signals-test.c	91808836d526c3dd2e3784a31d99110aceb77715
@@ -661,6 +661,37 @@ jabber_presence_received(PurpleConnectio
 	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 @@ plugin_load(PurplePlugin *plugin)
 		                      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 @@ plugin_unload(PurplePlugin *plugin)
 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;
 }
 
============================================================
--- libpurple/protocols/jabber/jabber.c	c28afd5ebcb23331cd235686bbea085d449eca8b
+++ libpurple/protocols/jabber/jabber.c	410b915f8170086de9d98a051ad12ac0244e5ab2
@@ -3451,6 +3451,21 @@ jabber_init_plugin(PurplePlugin *plugin)
 							 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
============================================================
--- libpurple/protocols/jabber/libxmpp.c	13f181b06cc93a337472a6c8c687fe2896dd1edd
+++ libpurple/protocols/jabber/libxmpp.c	10165279c70eaae138f633233dc66c0f3ddb14c1
@@ -170,6 +170,7 @@ static gboolean load_plugin(PurplePlugin
 			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,


More information about the Commits mailing list