changeset 14296:8342b39f975b

[gaim-migrate @ 16986] I got a patch from Ian Goldberg about a year ago to let plugins tweak XML packets as they were sent or received I finally tweaked it the way I wanted it, and here it is. If it sucks, blame me, otherwise give him credit committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Tue, 22 Aug 2006 19:43:30 +0000
parents b76462fea543
children 3248928fbb00
files COPYRIGHT libgaim/protocols/jabber/jabber.c libgaim/value.h
diffstat 3 files changed, 41 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/COPYRIGHT	Tue Aug 22 19:18:46 2006 +0000
+++ b/COPYRIGHT	Tue Aug 22 19:43:30 2006 +0000
@@ -111,6 +111,7 @@
 Ike Gingerich
 Gustavo Giráldez
 Richard Gobeille
+Ian Goldberg
 Michael Golden
 Charlie Gordon
 Ryan C. Gordon
--- a/libgaim/protocols/jabber/jabber.c	Tue Aug 22 19:18:46 2006 +0000
+++ b/libgaim/protocols/jabber/jabber.c	Tue Aug 22 19:43:30 2006 +0000
@@ -168,6 +168,12 @@
 
 void jabber_process_packet(JabberStream *js, xmlnode *packet)
 {
+	gaim_signal_emit(my_protocol, "jabber-receiving-xmlnode", js->gc, &packet);
+
+	/* if the signal leaves us with a null packet, we're done */
+	if(NULL == packet)
+		return;
+
 	if(!strcmp(packet->name, "iq")) {
 		jabber_iq_parse(js, packet);
 	} else if(!strcmp(packet->name, "presence")) {
@@ -327,6 +333,12 @@
 	char *txt;
 	int len;
 
+	gaim_signal_emit(my_protocol, "jabber-sending-xmlnode", js->gc, &packet);
+
+	/* if we get NULL back, we're done processing */
+	if(NULL == packet)
+		return;
+
 	txt = xmlnode_to_str(packet, &len);
 	jabber_send_raw(js, txt, len);
 	g_free(txt);
@@ -1882,6 +1894,30 @@
 	NULL,							/* whiteboard_prpl_ops */
 };
 
+static gboolean load_plugin(GaimPlugin *plugin)
+{
+	gaim_signal_register(plugin, "jabber-receiving-xmlnode",
+			gaim_marshal_VOID__POINTER_POINTER, NULL, 2,
+			gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_CONNECTION),
+			gaim_value_new_outgoing(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_XMLNODE));
+
+	gaim_signal_register(plugin, "jabber-sending-xmlnode",
+			gaim_marshal_VOID__POINTER_POINTER, NULL, 2,
+			gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_CONNECTION),
+			gaim_value_new_outgoing(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_XMLNODE));
+
+	return TRUE;
+}
+
+static gboolean unload_plugin(GaimPlugin *plugin)
+{
+	gaim_signal_unregister(plugin, "jabber-receiving-xmlnode");
+
+	gaim_signal_unregister(plugin, "jabber-sending-xmlnode");
+
+	return TRUE;
+}
+
 static GaimPluginInfo info =
 {
 	GAIM_PLUGIN_MAGIC,
@@ -1903,8 +1939,8 @@
 	NULL,                                             /**< author         */
 	GAIM_WEBSITE,                                     /**< homepage       */
 
-	NULL,                                             /**< load           */
-	NULL,                                             /**< unload         */
+	load_plugin,                                      /**< load           */
+	unload_plugin,                                    /**< unload         */
 	NULL,                                             /**< destroy        */
 
 	NULL,                                             /**< ui_info        */
--- a/libgaim/value.h	Tue Aug 22 19:18:46 2006 +0000
+++ b/libgaim/value.h	Tue Aug 22 19:43:30 2006 +0000
@@ -74,7 +74,8 @@
 	GAIM_SUBTYPE_STATUS,
 	GAIM_SUBTYPE_LOG,
 	GAIM_SUBTYPE_XFER,
-	GAIM_SUBTYPE_SAVEDSTATUS
+	GAIM_SUBTYPE_SAVEDSTATUS,
+	GAIM_SUBTYPE_XMLNODE
 } GaimSubType;
 
 /**