pidgin: 8a80f271: In jabber_iq_parse, xmlnode_get_child is...

qulogic at pidgin.im qulogic at pidgin.im
Thu Feb 5 01:25:39 EST 2009


-----------------------------------------------------------------
Revision: 8a80f271858548f73cac50625660e87df1970bcc
Ancestor: 8c0a13aacb02b1142a4fc384273860413f9f1559
Author: qulogic at pidgin.im
Date: 2009-02-05T05:42:58
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/8a80f271858548f73cac50625660e87df1970bcc

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

ChangeLog: 

In jabber_iq_parse, xmlnode_get_child is called for a few special cases,
and then the original xmlnode is passed to the handler. That seems kind of
pointless, since jabber_iq_parse has all the data. So I just passed the
data necessary for each handler instead. I didn't change the query handlers
since they seem to require the parent.
I assume the point was to go for a unified prototype, but since these
handlers are all special cases, I think it's okay to give them a special
signature as well.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/data.c	479b5c3440f041763c657afda16047f8880745eb
+++ libpurple/protocols/jabber/data.c	b31d350c17f5f2d4cd57864e4bd5392f3b9aa95c
@@ -200,11 +200,9 @@ void
 }
 
 void
-jabber_data_parse(JabberStream *js, xmlnode *packet)
+jabber_data_parse(JabberStream *js, xmlnode *data_node, const char *who, const char *id)
 {
 	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"));
 
@@ -213,12 +211,12 @@ jabber_data_parse(JabberStream *js, xmln
 
 		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"));
+		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"));
+		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	ccc56e2e70e42d453eb4ad5932d1595345e0d7c6
@@ -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, xmlnode *data_node,
+                       const char *who, const char *id);
 
 void jabber_data_init(void);
 void jabber_data_uninit(void);
============================================================
--- libpurple/protocols/jabber/google.c	f0624dcce3f7675f95224023738a5bc83d8f8fbb
+++ libpurple/protocols/jabber/google.c	a1b31b5647c3b999fe092afa58d4c79930c3cce2
@@ -144,9 +144,8 @@ void
 }
 
 void
-jabber_gmail_poke(JabberStream *js, xmlnode *packet)
+jabber_gmail_poke(JabberStream *js, const char *type)
 {
-	const char *type;
 	xmlnode *query;
 	JabberIq *iq;
 
@@ -154,11 +153,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 (strcmp(type, "set"))
 		return;
 
 	purple_debug(PURPLE_DEBUG_MISC, "jabber",
============================================================
--- libpurple/protocols/jabber/google.h	07da034a30ee0cda826d180de291cf48ed3b8126
+++ libpurple/protocols/jabber/google.h	72bedbbf105fcad0d6be1f6f37176229dd661957
@@ -27,7 +27,7 @@ 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 *type);
 
 void jabber_google_roster_init(JabberStream *js);
 void jabber_google_roster_outgoing(JabberStream *js, xmlnode *query, xmlnode *item);
============================================================
--- libpurple/protocols/jabber/iq.c	f5aad0682a60133a2e72d09670855a31de4ac71a
+++ libpurple/protocols/jabber/iq.c	4ca7540f6491fcb265dc05a7626a973a8ed05d65
@@ -309,7 +309,7 @@ void jabber_iq_parse(JabberStream *js, x
 void jabber_iq_parse(JabberStream *js, xmlnode *packet)
 {
 	JabberCallbackData *jcd;
-	xmlnode *query, *error, *x;
+	xmlnode *child, *query, *error, *x;
 	const char *xmlns;
 	const char *type, *id, *from;
 	JabberIqHandler *jih;
@@ -371,25 +371,25 @@ void jabber_iq_parse(JabberStream *js, x
 		}
 	}
 
-	if(xmlnode_get_child_with_namespace(packet, "si", "http://jabber.org/protocol/si")) {
-		jabber_si_parse(js, packet);
+	if ((child = xmlnode_get_child_with_namespace(packet, "si", "http://jabber.org/protocol/si"))) {
+		jabber_si_parse(js, child, from, id);
 		return;
 	}
 
-	if(xmlnode_get_child_with_namespace(packet, "new-mail", "google:mail:notify")) {
-		jabber_gmail_poke(js, packet);
+	if (xmlnode_get_child_with_namespace(packet, "new-mail", "google:mail:notify")) {
+		jabber_gmail_poke(js, type);
 		return;
 	}
 
 	purple_debug_info("jabber", "jabber_iq_parse\n");
 
-	if(xmlnode_get_child_with_namespace(packet, "ping", "urn:xmpp:ping")) {
-		jabber_ping_parse(js, packet);
+	if (xmlnode_get_child_with_namespace(packet, "ping", "urn:xmpp:ping")) {
+		jabber_ping_parse(js, from, id);
 		return;
 	}
 
-	if (xmlnode_get_child_with_namespace(packet, "data", XEP_0231_NAMESPACE)) {
-		jabber_data_parse(js, packet);
+	if ((child = xmlnode_get_child_with_namespace(packet, "data", XEP_0231_NAMESPACE))) {
+		jabber_data_parse(js, child, from, id);
 		return;
 	}
 
============================================================
--- libpurple/protocols/jabber/ping.c	4815c966a6e9665f6fef0da7c235ed20c310a90d
+++ libpurple/protocols/jabber/ping.c	fc83cbf0b836a7ffa2cdbf02b54be53dc15cde10
@@ -30,7 +30,7 @@ void
 #include "iq.h"
 
 void
-jabber_ping_parse(JabberStream *js, xmlnode *packet)
+jabber_ping_parse(JabberStream *js, const char *from, const char *id)
 {
 	JabberIq *iq;
 
@@ -38,9 +38,9 @@ jabber_ping_parse(JabberStream *js, xmln
 
 	iq = jabber_iq_new(js, JABBER_IQ_RESULT);
 
-	xmlnode_set_attrib(iq->node, "to", xmlnode_get_attrib(packet, "from") );
+	xmlnode_set_attrib(iq->node, "to", from);
 
-	jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id"));
+	jabber_iq_set_id(iq, id);
 
 	jabber_iq_send(iq);
 }
============================================================
--- libpurple/protocols/jabber/ping.h	40882a772ad4d66936f6543ed7b4d3dc09ed264c
+++ libpurple/protocols/jabber/ping.h	a624d1139f5574c5ab0f3fa85c3ccb698ecf4cef
@@ -26,7 +26,8 @@ void jabber_ping_parse(JabberStream *js,
 #include "conversation.h"
 
 void jabber_ping_parse(JabberStream *js,
-						xmlnode *packet);
+                       const char *from,
+                       const char *id);
 
 
 gboolean jabber_ping_jid(PurpleConversation *conv, const char *jid);
============================================================
--- libpurple/protocols/jabber/si.c	89f1f349908491771cadac3c2ba0fbf7c247688b
+++ libpurple/protocols/jabber/si.c	dbf524d9f05889a868f1ed2d67c3e88f4023841b
@@ -1182,17 +1182,14 @@ void jabber_si_xfer_send(PurpleConnectio
 		purple_xfer_request(xfer);
 }
 
-void jabber_si_parse(JabberStream *js, xmlnode *packet)
+void jabber_si_parse(JabberStream *js, xmlnode *si, const char *from, const char *id)
 {
 	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 +1212,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 +1253,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	5bcfccfa6683df98379c9fe4702c78c8bf945a31
@@ -27,7 +27,7 @@ void jabber_bytestreams_parse(JabberStre
 #include "jabber.h"
 
 void jabber_bytestreams_parse(JabberStream *js, xmlnode *packet);
-void jabber_si_parse(JabberStream *js, xmlnode *packet);
+void jabber_si_parse(JabberStream *js, xmlnode *si, const char *from, const char *id);
 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