cpw.darkrain42.xmpp.iq-handlers: c9b9cf5f: Pass IQ handlers type, from, id, and the...

paul at darkrain42.org paul at darkrain42.org
Sun Feb 8 02:15:46 EST 2009


-----------------------------------------------------------------
Revision: c9b9cf5faea6a28039d60ea19874de22834f9069
Ancestor: 5224382f81d105bd5d72ac3e55cc95b894bb824e
Author: paul at darkrain42.org
Date: 2009-02-08T06:31:18
Branch: im.pidgin.cpw.darkrain42.xmpp.iq-handlers
URL: http://d.pidgin.im/viewmtn/revision/info/c9b9cf5faea6a28039d60ea19874de22834f9069

Modified files:
        libpurple/protocols/jabber/data.c
        libpurple/protocols/jabber/data.h
        libpurple/protocols/jabber/disco.c
        libpurple/protocols/jabber/disco.h
        libpurple/protocols/jabber/google.c
        libpurple/protocols/jabber/google.h
        libpurple/protocols/jabber/iq.c
        libpurple/protocols/jabber/iq.h
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/jabber.h
        libpurple/protocols/jabber/oob.c
        libpurple/protocols/jabber/oob.h
        libpurple/protocols/jabber/ping.c
        libpurple/protocols/jabber/ping.h
        libpurple/protocols/jabber/roster.c
        libpurple/protocols/jabber/roster.h
        libpurple/protocols/jabber/si.c
        libpurple/protocols/jabber/si.h

ChangeLog: 

Pass IQ handlers type, from, id, and the child node

As QuLogic pointed out in 8a80f271, it's pointless for the handlers to re-get
the information from the IQ stanza. Additionally, instead of string-matching
the type everywhere, pass around a JabberIqType.

Last, 'child' cannot be NULL, but 'from' may be.


-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/data.c	479b5c3440f041763c657afda16047f8880745eb
+++ libpurple/protocols/jabber/data.c	74794d63d2e2fd48e83cb8bf632f3d6411533fdb
@@ -200,25 +200,26 @@ void
 }
 
 void
-jabber_data_parse(JabberStream *js, xmlnode *packet)
+jabber_data_parse(JabberStream *js, const char *who, JabberIqType type,
+                  const char *id, xmlnode *data_node)
 {
 	JabberIq *result = NULL;
-	const char *who = xmlnode_get_attrib(packet, "from");
-	xmlnode *data_node = xmlnode_get_child(packet, "data");
-	const JabberData *data =
-		jabber_data_find_local_by_cid(xmlnode_get_attrib(data_node, "cid"));
+	const char *cid = xmlnode_get_attrib(data_node, "cid");
+	const JabberData *data = cid ? jabber_data_find_local_by_cid(cid) : NULL;
 
 	if (!data) {
 		xmlnode *item_not_found = xmlnode_new("item-not-found");
 
 		result = jabber_iq_new(js, JABBER_IQ_ERROR);
-		xmlnode_set_attrib(result->node, "to", who);
-		xmlnode_set_attrib(result->node, "id", xmlnode_get_attrib(packet, "id"));
+		if (who)
+			xmlnode_set_attrib(result->node, "to", who);
+		xmlnode_set_attrib(result->node, "id", id);
 		xmlnode_insert_child(result->node, item_not_found);
 	} else {
 		result = jabber_iq_new(js, JABBER_IQ_RESULT);
-		xmlnode_set_attrib(result->node, "to", who);
-		xmlnode_set_attrib(result->node, "id", xmlnode_get_attrib(packet, "id"));
+		if (who)
+			xmlnode_set_attrib(result->node, "to", who);
+		xmlnode_set_attrib(result->node, "id", id);
 		xmlnode_insert_child(result->node,
 							 jabber_data_get_xml_definition(data));
 	}
============================================================
--- libpurple/protocols/jabber/data.h	4e41b1878db90fbb1cd27d32fa73d7d2bee9be5e
+++ libpurple/protocols/jabber/data.h	469b30a3789506a04ae6e7dc587a6ad7d0040510
@@ -65,7 +65,8 @@ void jabber_data_associate_remote(Jabber
 void jabber_data_associate_remote(JabberData *data);
 
 /* handles iq requests */
-void jabber_data_parse(JabberStream *js, xmlnode *packet);
+void jabber_data_parse(JabberStream *js, const char *who, JabberIqType type,
+                       const char *id, xmlnode *data_node);
 
 void jabber_data_init(void);
 void jabber_data_uninit(void);
============================================================
--- libpurple/protocols/jabber/disco.c	084668a54e394a962b6d6e25f2bcb433013fb3eb
+++ libpurple/protocols/jabber/disco.c	57a5079e09922e411c32a282a3f4d5e75dfb1a63
@@ -85,29 +85,22 @@ jabber_disco_bytestream_server_cb(Jabber
 }
 
 
-void jabber_disco_info_parse(JabberStream *js, xmlnode *packet) {
-	const char *from = xmlnode_get_attrib(packet, "from");
-	const char *type = xmlnode_get_attrib(packet, "type");
+void jabber_disco_info_parse(JabberStream *js, const char *from,
+                             JabberIqType type, const char *id,
+                             xmlnode *in_query) {
 
-	if(!from || !type)
+	if(!from)
 		return;
 
-	if(!strcmp(type, "get")) {
+	if(type == JABBER_IQ_GET) {
 		xmlnode *query, *identity, *feature;
 		JabberIq *iq;
+		const char *node = xmlnode_get_attrib(in_query, "node");
 
-		xmlnode *in_query;
-		const char *node = NULL;
-
-		if((in_query = xmlnode_get_child(packet, "query"))) {
-			node = xmlnode_get_attrib(in_query, "node");
-		}
-
-
 		iq = jabber_iq_new_query(js, JABBER_IQ_RESULT,
 				"http://jabber.org/protocol/disco#info");
 
-		jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id"));
+		jabber_iq_set_id(iq, id);
 
 		xmlnode_set_attrib(iq->node, "to", from);
 		query = xmlnode_get_child(iq->node, "query");
@@ -200,8 +193,7 @@ void jabber_disco_info_parse(JabberStrea
 		}
 
 		jabber_iq_send(iq);
-	} else if(!strcmp(type, "result")) {
-		xmlnode *query = xmlnode_get_child(packet, "query");
+	} else if(type == JABBER_IQ_RESULT) {
 		xmlnode *child;
 		JabberID *jid;
 		JabberBuddy *jb;
@@ -218,7 +210,7 @@ void jabber_disco_info_parse(JabberStrea
 		if(jbr)
 			capabilities = jbr->capabilities;
 
-		for(child = query->child; child; child = child->next) {
+		for(child = in_query->child; child; child = child->next) {
 			if(child->type != XMLNODE_TYPE_TAG)
 				continue;
 
@@ -285,7 +277,7 @@ void jabber_disco_info_parse(JabberStrea
 			jdicd->callback(js, from, capabilities, jdicd->data);
 			g_hash_table_remove(js->disco_callbacks, from);
 		}
-	} else if(!strcmp(type, "error")) {
+	} else if(type == JABBER_IQ_ERROR) {
 		JabberID *jid;
 		JabberBuddy *jb;
 		JabberBuddyResource *jbr = NULL;
@@ -309,28 +301,23 @@ void jabber_disco_info_parse(JabberStrea
 	}
 }
 
-void jabber_disco_items_parse(JabberStream *js, xmlnode *packet) {
-	const char *from = xmlnode_get_attrib(packet, "from");
-	const char *type = xmlnode_get_attrib(packet, "type");
-
-	if(type && !strcmp(type, "get")) {
+void jabber_disco_items_parse(JabberStream *js, const char *from,
+                              JabberIqType type, const char *id,
+                              xmlnode *query) {
+	if(type == JABBER_IQ_GET) {
 		JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_RESULT,
 				"http://jabber.org/protocol/disco#items");
 		
 		/* preserve node */
-		xmlnode *iq_query = xmlnode_get_child_with_namespace(iq->node,"query","http://jabber.org/protocol/disco#items");
-		if(iq_query) {
-			xmlnode *query = xmlnode_get_child_with_namespace(packet,"query","http://jabber.org/protocol/disco#items");
-			if(query) {
-				const char *node = xmlnode_get_attrib(query,"node");
-				if(node)
-					xmlnode_set_attrib(iq_query,"node",node);
-			}
-		}
+		xmlnode *iq_query = xmlnode_get_child(iq->node, "query");
+		const char *node = xmlnode_get_attrib(query, "node");
+		if(node)
+			xmlnode_set_attrib(iq_query,"node",node);
 
-		jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id"));
+		jabber_iq_set_id(iq, id);
 
-		xmlnode_set_attrib(iq->node, "to", from);
+		if (from)
+			xmlnode_set_attrib(iq->node, "to", from);
 		jabber_iq_send(iq);
 	}
 }
============================================================
--- libpurple/protocols/jabber/disco.h	f30f10709e0282c73ff287b1c373440f9ae41e81
+++ libpurple/protocols/jabber/disco.h	2e2cd8127090a517c803b5ffd232b23c5dd6f8e4
@@ -27,8 +27,10 @@ typedef void (JabberDiscoInfoCallback)(J
 typedef void (JabberDiscoInfoCallback)(JabberStream *js, const char *who,
 		JabberCapabilities capabilities, gpointer data);
 
-void jabber_disco_info_parse(JabberStream *js, xmlnode *packet);
-void jabber_disco_items_parse(JabberStream *js, xmlnode *packet);
+void jabber_disco_info_parse(JabberStream *js, const char *from,
+                             JabberIqType type, const char *id, xmlnode *in_query);
+void jabber_disco_items_parse(JabberStream *js, const char *from,
+                              JabberIqType type, const char *id, xmlnode *query);
 
 void jabber_disco_items_server(JabberStream *js);
 
============================================================
--- libpurple/protocols/jabber/google.c	f0624dcce3f7675f95224023738a5bc83d8f8fbb
+++ libpurple/protocols/jabber/google.c	4a18c3c07e9e244a652495452b5eed9688d075aa
@@ -144,9 +144,9 @@ void
 }
 
 void
-jabber_gmail_poke(JabberStream *js, xmlnode *packet)
+jabber_gmail_poke(JabberStream *js, const char *from, JabberIqType type,
+                  const char *id, xmlnode *new_mail)
 {
-	const char *type;
 	xmlnode *query;
 	JabberIq *iq;
 
@@ -154,11 +154,8 @@ jabber_gmail_poke(JabberStream *js, xmln
 	if (!purple_account_get_check_mail(js->gc->account))
 		return;
 
-	type = xmlnode_get_attrib(packet, "type");
-
-
 	/* Is this an initial incoming mail notification? If so, send a request for more info */
-	if (strcmp(type, "set") || !xmlnode_get_child(packet, "new-mail"))
+	if (type != JABBER_IQ_SET)
 		return;
 
 	purple_debug(PURPLE_DEBUG_MISC, "jabber",
============================================================
--- libpurple/protocols/jabber/google.h	07da034a30ee0cda826d180de291cf48ed3b8126
+++ libpurple/protocols/jabber/google.h	e38b8009e89a53cf859a3e9d23928c5b2bea6b8f
@@ -27,7 +27,8 @@ void jabber_gmail_init(JabberStream *js)
 #include "jabber.h"
 
 void jabber_gmail_init(JabberStream *js);
-void jabber_gmail_poke(JabberStream *js, xmlnode *node);
+void jabber_gmail_poke(JabberStream *js, const char *from, JabberIqType type,
+                       const char *id, xmlnode *new_mail);
 
 void jabber_google_roster_init(JabberStream *js);
 void jabber_google_roster_outgoing(JabberStream *js, xmlnode *query, xmlnode *item);
============================================================
--- libpurple/protocols/jabber/iq.c	f45b12d0f2ffe36f7fd9970fdb522b56a77a2cbb
+++ libpurple/protocols/jabber/iq.c	6e32ebc6c1f5b7f7412eb46c35a435bfdb62250d
@@ -172,20 +172,15 @@ void jabber_iq_free(JabberIq *iq)
 	g_free(iq);
 }
 
-static void jabber_iq_last_parse(JabberStream *js, xmlnode *packet)
+static void jabber_iq_last_parse(JabberStream *js, const char *from,
+                                 JabberIqType type, const char *id,
+                                 xmlnode *packet)
 {
 	JabberIq *iq;
-	const char *type;
-	const char *from;
-	const char *id;
 	xmlnode *query;
 	char *idle_time;
 
-	type = xmlnode_get_attrib(packet, "type");
-	from = xmlnode_get_attrib(packet, "from");
-	id = xmlnode_get_attrib(packet, "id");
-
-	if(type && !strcmp(type, "get")) {
+	if(type == JABBER_IQ_GET) {
 		iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:last");
 		jabber_iq_set_id(iq, id);
 		xmlnode_set_attrib(iq->node, "to", from);
@@ -200,31 +195,21 @@ static void jabber_iq_last_parse(JabberS
 	}
 }
 
-static void jabber_iq_time_parse(JabberStream *js, xmlnode *packet)
+static void jabber_iq_time_parse(JabberStream *js, const char *from,
+                                 JabberIqType type, const char *id,
+                                 xmlnode *child)
 {
-	const char *type, *from, *id, *xmlns;
+	const char *xmlns;
 	JabberIq *iq;
-	xmlnode *child;
 	time_t now_t;
 	struct tm *now;
 
 	time(&now_t);
 	now = localtime(&now_t);
 
-	type = xmlnode_get_attrib(packet, "type");
-	from = xmlnode_get_attrib(packet, "from");
-	id = xmlnode_get_attrib(packet, "id");
+	xmlns = xmlnode_get_namespace(child);
 
-	if ((child = xmlnode_get_child(packet, "query"))) {
-		xmlns = "jabber:iq:time";
-	} else if ((child = xmlnode_get_child(packet, "time"))) {
-		xmlns = "urn:xmpp:time";
-	} else {
-		purple_debug_warning("jabber", "Malformed IQ time packet\n");
-		return;
-	}
-
-	if(type && !strcmp(type, "get")) {
+	if(type == JABBER_IQ_GET) {
 		xmlnode *utc;
 		const char *date, *tz, *display;
 
@@ -233,6 +218,7 @@ static void jabber_iq_time_parse(JabberS
 		xmlnode_set_attrib(iq->node, "to", from);
 
 		child = xmlnode_new_child(iq->node, child->name);
+		xmlnode_set_namespace(child, xmlns);
 		utc = xmlnode_new_child(child, "utc");
 
 		if(!strcmp("urn:xmpp:time", xmlns)) {
@@ -256,15 +242,14 @@ static void jabber_iq_time_parse(JabberS
 	}
 }
 
-static void jabber_iq_version_parse(JabberStream *js, xmlnode *packet)
+static void jabber_iq_version_parse(JabberStream *js, const char *from,
+                                    JabberIqType type, const char *id,
+                                    xmlnode *packet)
 {
 	JabberIq *iq;
-	const char *type, *from, *id;
 	xmlnode *query;
 
-	type = xmlnode_get_attrib(packet, "type");
-
-	if(type && !strcmp(type, "get")) {
+	if(type == JABBER_IQ_GET) {
 		GHashTable *ui_info;
 		const char *ui_name = NULL, *ui_version = NULL;
 #if 0
@@ -277,8 +262,6 @@ static void jabber_iq_version_parse(Jabb
 					osinfo.machine);
 		}
 #endif
-		from = xmlnode_get_attrib(packet, "from");
-		id = xmlnode_get_attrib(packet, "id");
 
 		iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:version");
 		xmlnode_set_attrib(iq->node, "to", from);
@@ -324,7 +307,8 @@ void jabber_iq_parse(JabberStream *js, x
 	JabberCallbackData *jcd;
 	xmlnode *child, *error, *x;
 	const char *xmlns;
-	const char *type, *id, *from;
+	const char *iq_type, *id, *from;
+	JabberIqType type = JABBER_IQ_NONE;
 	JabberIqHandler *jih;
 
 	/*
@@ -338,21 +322,31 @@ void jabber_iq_parse(JabberStream *js, x
 			break;
 	}
 
-	type = xmlnode_get_attrib(packet, "type");
+	iq_type = xmlnode_get_attrib(packet, "type");
 	from = xmlnode_get_attrib(packet, "from");
 	id = xmlnode_get_attrib(packet, "id");
 
-	if(type == NULL || !(!strcmp(type, "get") || !strcmp(type, "set")
-			|| !strcmp(type, "result") || !strcmp(type, "error"))) {
+	if (iq_type) {
+		if (!strcmp(iq_type, "get"))
+			type = JABBER_IQ_GET;
+		else if (!strcmp(iq_type, "set"))
+			type = JABBER_IQ_SET;
+		else if (!strcmp(iq_type, "result"))
+			type = JABBER_IQ_RESULT;
+		else if (!strcmp(iq_type, "error"))
+			type = JABBER_IQ_ERROR;
+	}
+
+	if (type == JABBER_IQ_NONE) {
 		purple_debug_error("jabber", "IQ with invalid type ('%s') - ignoring.\n",
-						   type ? type : "(null)");
+						   iq_type ? iq_type : "(null)");
 		return;
 	}
 
 	/* All IQs must have an ID, so send an error for a set/get that doesn't */
 	if(!id || !*id) {
 
-		if(!strcmp(type, "set") || !strcmp(type, "get")) {
+		if(type == JABBER_IQ_SET || type == JABBER_IQ_GET) {
 			JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR);
 
 			xmlnode_free(iq->node);
@@ -370,13 +364,14 @@ void jabber_iq_parse(JabberStream *js, x
 
 			jabber_iq_send(iq);
 		} else
-			purple_debug_error("jabber", "IQ of type '%s' missing id - ignoring.\n", type);
+			purple_debug_error("jabber", "IQ of type '%s' missing id - ignoring.\n",
+			                   iq_type);
 
 		return;
 	}
 
 	/* First, lets see if a special callback got registered */
-	if(!strcmp(type, "result") || !strcmp(type, "error")) {
+	if(type == JABBER_IQ_RESULT || type == JABBER_IQ_ERROR) {
 		if(id && *id && (jcd = g_hash_table_lookup(js->iq_callbacks, id))) {
 			jcd->callback(js, packet, jcd->data);
 			jabber_iq_remove_callback_by_id(js, id);
@@ -391,7 +386,7 @@ void jabber_iq_parse(JabberStream *js, x
 		/* xmlns isn't being modified, I promise */
 		key.xmlns = (char *)xmlns;
 		if((jih = g_hash_table_lookup(iq_handlers, &key))) {
-			jih(js, packet);
+			jih(js, from, type, id, child);
 			return;
 		}
 	}
@@ -399,7 +394,7 @@ void jabber_iq_parse(JabberStream *js, x
 	purple_debug_info("jabber", "jabber_iq_parse\n");
 
 	/* If we get here, send the default error reply mandated by XMPP-CORE */
-	if(!strcmp(type, "set") || !strcmp(type, "get")) {
+	if(type == JABBER_IQ_SET || type == JABBER_IQ_GET) {
 		JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR);
 
 		xmlnode_free(iq->node);
============================================================
--- libpurple/protocols/jabber/iq.h	c61208d4b8c3f2b4ed63bfcd6494bacf120df348
+++ libpurple/protocols/jabber/iq.h	d2b38aca858a2177f36dc16f3446178a7b041b36
@@ -22,10 +22,6 @@
 #ifndef _PURPLE_JABBER_IQ_H_
 #define _PURPLE_JABBER_IQ_H_
 
-#include "jabber.h"
-
-typedef struct _JabberIq JabberIq;
-
 typedef enum {
 	JABBER_IQ_SET,
 	JABBER_IQ_GET,
@@ -34,8 +30,14 @@ typedef enum {
 	JABBER_IQ_NONE
 } JabberIqType;
 
-typedef void (JabberIqHandler)(JabberStream *js, xmlnode *packet);
+#include "jabber.h"
 
+typedef struct _JabberIq JabberIq;
+
+typedef void (JabberIqHandler)(JabberStream *js, const char *from,
+                               JabberIqType type, const char *id,
+                               xmlnode *child);
+
 typedef void (JabberIqCallback)(JabberStream *js, xmlnode *packet, gpointer data);
 
 struct _JabberIq {
============================================================
--- libpurple/protocols/jabber/jabber.c	c5ac57ab8074c25a40ab4b0459d6d518209e64e5
+++ libpurple/protocols/jabber/jabber.c	441463735bf689b7f1cbd91350e0d762badbcdd6
@@ -969,23 +969,21 @@ static void jabber_register_x_data_cb(Ja
 	jabber_iq_send(iq);
 }
 
-void jabber_register_parse(JabberStream *js, xmlnode *packet)
+void jabber_register_parse(JabberStream *js, const char *from, JabberIqType type,
+                           const char *id, xmlnode *query)
 {
 	PurpleAccount *account = purple_connection_get_account(js->gc);
-	const char *type;
-	const char *from;
 	PurpleRequestFields *fields;
 	PurpleRequestFieldGroup *group;
 	PurpleRequestField *field;
-	xmlnode *query, *x, *y;
+	xmlnode *x, *y;
 	char *instructions;
 	JabberRegisterCBData *cbdata;
 	gboolean registered = FALSE;
 
-	if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result"))
+	if (type != JABBER_IQ_RESULT)
 		return;
 
-	from = xmlnode_get_attrib(packet, "from");
 	if (!from)
 		from = js->serverFQDN;
 	g_return_if_fail(from != NULL);
@@ -995,8 +993,6 @@ void jabber_register_parse(JabberStream 
 		purple_connection_set_state(js->gc, PURPLE_CONNECTED);
 	}
 
-	query = xmlnode_get_child(packet, "query");
-
 	if(xmlnode_get_child(query, "registered")) {
 		registered = TRUE;
 
============================================================
--- libpurple/protocols/jabber/jabber.h	df574ab651cdebe290c7ce7f0a329167c562919a
+++ libpurple/protocols/jabber/jabber.h	daab62a104d9f6fd7c795e3154d621f5f246756a
@@ -57,6 +57,7 @@ typedef struct _JabberStream JabberStrea
 #include "roomlist.h"
 #include "sslconn.h"
 
+#include "iq.h"
 #include "jutil.h"
 #include "xmlnode.h"
 #include "buddy.h"
@@ -269,7 +270,8 @@ void jabber_stream_set_state(JabberStrea
 
 void jabber_stream_set_state(JabberStream *js, JabberStreamState state);
 
-void jabber_register_parse(JabberStream *js, xmlnode *packet);
+void jabber_register_parse(JabberStream *js, const char *from,
+                           JabberIqType type, const char *id, xmlnode *query);
 void jabber_register_start(JabberStream *js);
 
 char *jabber_get_next_id(JabberStream *js);
============================================================
--- libpurple/protocols/jabber/oob.c	cb310fdba1498e02094662c003a340c42424a5bc
+++ libpurple/protocols/jabber/oob.c	49825e6b1badd0b43637ff3a0c1716849b04ae28
@@ -187,18 +187,18 @@ static void jabber_oob_xfer_recv_cancele
 	jabber_oob_xfer_recv_error(xfer, "404");
 }
 
-void jabber_oob_parse(JabberStream *js, xmlnode *packet) {
+void jabber_oob_parse(JabberStream *js, const char *from, JabberIqType type,
+                      const char *id, xmlnode *querynode) {
 	JabberOOBXfer *jox;
 	PurpleXfer *xfer;
 	char *filename;
 	char *url;
-	const char *type;
-	xmlnode *querynode, *urlnode;
+	xmlnode *urlnode;
 
-	if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "set"))
+	if(type != JABBER_IQ_SET)
 		return;
 
-	if(!(querynode = xmlnode_get_child(packet, "query")))
+	if(!querynode)
 		return;
 
 	if(!(urlnode = xmlnode_get_child(querynode, "url")))
@@ -211,10 +211,9 @@ void jabber_oob_parse(JabberStream *js, 
 	g_free(url);
 	jox->js = js;
 	jox->headers = g_string_new("");
-	jox->iq_id = g_strdup(xmlnode_get_attrib(packet, "id"));
+	jox->iq_id = g_strdup(id);
 
-	xfer = purple_xfer_new(js->gc->account, PURPLE_XFER_RECEIVE,
-			xmlnode_get_attrib(packet, "from"));
+	xfer = purple_xfer_new(js->gc->account, PURPLE_XFER_RECEIVE, from);
 	if (xfer)
 	{
 		xfer->data = jox;
============================================================
--- libpurple/protocols/jabber/oob.h	37d1bec5215ba0a3a8db2abdd98aed1653871abe
+++ libpurple/protocols/jabber/oob.h	3c38cf401d5e380de983937455aa8233aba8b32a
@@ -22,6 +22,9 @@
 #ifndef _PURPLE_JABBER_OOB_H_
 #define _PURPLE_JABBER_OOB_H_
 
-void jabber_oob_parse(JabberStream *js, xmlnode *packet);
+#include "jabber.h"
 
+void jabber_oob_parse(JabberStream *js, const char *from, JabberIqType type,
+                      const char *id, xmlnode *querynode);
+
 #endif /* _PURPLE_JABBER_OOB_H_ */
============================================================
--- libpurple/protocols/jabber/ping.c	e412dd4726c1517ab22f22a280be7829d08fe12c
+++ libpurple/protocols/jabber/ping.c	80fd859d8a83cfd9ecb46c7391387ef57585cbec
@@ -35,29 +35,19 @@ void
 }
 
 void
-jabber_ping_parse(JabberStream *js, xmlnode *packet)
+jabber_ping_parse(JabberStream *js, const char *from,
+                  JabberIqType type, const char *id, xmlnode *ping)
 {
-	const char *type, *id, *from;
-
-	type = xmlnode_get_attrib(packet, "type");
-	from = xmlnode_get_attrib(packet, "from");
-	id   = xmlnode_get_attrib(packet, "id");
-
-	if (!type) {
-		purple_debug_warning("jabber", "jabber_ping with no type\n");
-		return;
-	}
-	
 	purple_debug_info("jabber", "jabber_ping_parse\n");
 
-	if (!strcmp(type, "get")) {
+	if (type == JABBER_IQ_GET) {
 		JabberIq *iq = jabber_iq_new(js, JABBER_IQ_RESULT);
 
 		xmlnode_set_attrib(iq->node, "to", from);
 		xmlnode_set_attrib(iq->node, "id", id);
 
 		jabber_iq_send(iq);
-	} else if (!strcmp(type, "set")) {
+	} else if (type == JABBER_IQ_SET) {
 		/* XXX: error */
 	}
 }
============================================================
--- libpurple/protocols/jabber/ping.h	1d6faea661ed7a6b77368e334563d7a7a6a01eb1
+++ libpurple/protocols/jabber/ping.h	f88c230d00db70e9b1ce9cfbf28730a832778549
@@ -23,9 +23,11 @@
 #define _PURPLE_JABBER_PING_H_
 
 #include "jabber.h"
+#include "iq.h"
 #include "xmlnode.h"
 
-void jabber_ping_parse(JabberStream *js, xmlnode *packet);
+void jabber_ping_parse(JabberStream *js, const char *from,
+                       JabberIqType, const char *id, xmlnode *child);
 gboolean jabber_ping_jid(JabberStream *js, const char *jid);
 
 #endif /* _PURPLE_JABBER_PING_H_ */
============================================================
--- libpurple/protocols/jabber/roster.c	a384763565f91ecfa641f97f9ba59f697fa9169a
+++ libpurple/protocols/jabber/roster.c	78836488751a51388b0210ff508aa2940b0e9a24
@@ -142,10 +142,10 @@ static void add_purple_buddies_to_groups
 	g_slist_free(buddies);
 }
 
-void jabber_roster_parse(JabberStream *js, xmlnode *packet)
+void jabber_roster_parse(JabberStream *js, const char *from,
+                         JabberIqType type, const char *id, xmlnode *query)
 {
-	xmlnode *query, *item, *group;
-	const char *from = xmlnode_get_attrib(packet, "from");
+	xmlnode *item, *group;
 
 	if(from) {
 		char *from_norm;
@@ -166,10 +166,6 @@ void jabber_roster_parse(JabberStream *j
 			return;
 	}
 
-	query = xmlnode_get_child(packet, "query");
-	if(!query)
-		return;
-
 	js->currently_parsing_roster_push = TRUE;
 
 	for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item))
============================================================
--- libpurple/protocols/jabber/roster.h	e2221db51cca3a2ed1bd267425db65a921ef76be
+++ libpurple/protocols/jabber/roster.h	7606311fb1037ff3c2391e2ba9595ccdb4614b38
@@ -26,7 +26,8 @@ void jabber_roster_request(JabberStream 
 
 void jabber_roster_request(JabberStream *js);
 
-void jabber_roster_parse(JabberStream *js, xmlnode *packet);
+void jabber_roster_parse(JabberStream *js, const char *from,
+                         JabberIqType type, const char *id, xmlnode *query);
 
 void jabber_roster_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy,
 		PurpleGroup *group);
============================================================
--- libpurple/protocols/jabber/si.c	89f1f349908491771cadac3c2ba0fbf7c247688b
+++ libpurple/protocols/jabber/si.c	8a3cc4553d58ec08f4d53e43c9a9313014016c94
@@ -256,22 +256,20 @@ static void jabber_si_bytestreams_attemp
 	}
 }
 
-void jabber_bytestreams_parse(JabberStream *js, xmlnode *packet)
+void jabber_bytestreams_parse(JabberStream *js, const char *from,
+                              JabberIqType type, const char *id, xmlnode *query)
 {
 	PurpleXfer *xfer;
 	JabberSIXfer *jsx;
-	xmlnode *query, *streamhost;
-	const char *sid, *from, *type;
+	xmlnode *streamhost;
+	const char *sid;
 
-	if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "set"))
+	if(type != JABBER_IQ_SET)
 		return;
 
-	if(!(from = xmlnode_get_attrib(packet, "from")))
+	if(!from)
 		return;
 
-	if(!(query = xmlnode_get_child(packet, "query")))
-		return;
-
 	if(!(sid = xmlnode_get_attrib(query, "sid")))
 		return;
 
@@ -285,7 +283,7 @@ void jabber_bytestreams_parse(JabberStre
 
 	if(jsx->iq_id)
 		g_free(jsx->iq_id);
-	jsx->iq_id = g_strdup(xmlnode_get_attrib(packet, "id"));
+	jsx->iq_id = g_strdup(id);
 
 	for(streamhost = xmlnode_get_child(query, "streamhost"); streamhost;
 			streamhost = xmlnode_get_next_twin(streamhost)) {
@@ -1182,17 +1180,15 @@ void jabber_si_xfer_send(PurpleConnectio
 		purple_xfer_request(xfer);
 }
 
-void jabber_si_parse(JabberStream *js, xmlnode *packet)
+void jabber_si_parse(JabberStream *js, const char *from, JabberIqType type,
+                     const char *id, xmlnode *si)
 {
 	JabberSIXfer *jsx;
 	PurpleXfer *xfer;
-	xmlnode *si, *file, *feature, *x, *field, *option, *value;
-	const char *stream_id, *filename, *filesize_c, *profile, *from;
+	xmlnode *file, *feature, *x, *field, *option, *value;
+	const char *stream_id, *filename, *filesize_c, *profile;
 	size_t filesize = 0;
 
-	if(!(si = xmlnode_get_child(packet, "si")))
-		return;
-
 	if(!(profile = xmlnode_get_attrib(si, "profile")) ||
 			strcmp(profile, "http://jabber.org/protocol/si/profile/file-transfer"))
 		return;
@@ -1215,7 +1211,7 @@ void jabber_si_parse(JabberStream *js, x
 	if(!(x = xmlnode_get_child_with_namespace(feature, "x", "jabber:x:data")))
 		return;
 
-	if(!(from = xmlnode_get_attrib(packet, "from")))
+	if(!from)
 		return;
 
 	/* if they've already sent us this file transfer with the same damn id
@@ -1256,7 +1252,7 @@ void jabber_si_parse(JabberStream *js, x
 
 	jsx->js = js;
 	jsx->stream_id = g_strdup(stream_id);
-	jsx->iq_id = g_strdup(xmlnode_get_attrib(packet, "id"));
+	jsx->iq_id = g_strdup(id);
 
 	xfer = purple_xfer_new(js->gc->account, PURPLE_XFER_RECEIVE, from);
 	if (xfer)
============================================================
--- libpurple/protocols/jabber/si.h	5efdeacc163a9ff870a2234edc0678540596dc74
+++ libpurple/protocols/jabber/si.h	23d401e4bfdd9098c131848dd1e0db2620a1be02
@@ -26,8 +26,10 @@
 
 #include "jabber.h"
 
-void jabber_bytestreams_parse(JabberStream *js, xmlnode *packet);
-void jabber_si_parse(JabberStream *js, xmlnode *packet);
+void jabber_bytestreams_parse(JabberStream *js, const char *from,
+                              JabberIqType type, const char *id, xmlnode *query);
+void jabber_si_parse(JabberStream *js, const char *from, JabberIqType type,
+                     const char *id, xmlnode *si);
 PurpleXfer *jabber_si_new_xfer(PurpleConnection *gc, const char *who);
 void jabber_si_xfer_send(PurpleConnection *gc, const char *who, const char *file);
 


More information about the Commits mailing list