changeset 26555:50ff0162fe26

Convert IBB parser (and everything that then stems from that) to new iq-handler Apparently I completely missed this when propagating earlier
author Paul Aurich <paul@darkrain42.org>
date Sat, 04 Apr 2009 07:05:23 +0000
parents 3c684403ea10
children 8399b545925c
files libpurple/protocols/jabber/ibb.c libpurple/protocols/jabber/ibb.h libpurple/protocols/jabber/iq.c libpurple/protocols/jabber/si.c
diffstat 4 files changed, 36 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/ibb.c	Fri Apr 03 17:36:24 2009 +0000
+++ b/libpurple/protocols/jabber/ibb.c	Sat Apr 04 07:05:23 2009 +0000
@@ -46,12 +46,10 @@
 }
 
 JabberIBBSession *
-jabber_ibb_session_create_from_xmlnode(JabberStream *js, xmlnode *packet,
-	gpointer user_data)
+jabber_ibb_session_create_from_xmlnode(JabberStream *js, const char *from,
+	const char *id, xmlnode *open, gpointer user_data)
 {
 	JabberIBBSession *sess = NULL;
-	xmlnode *open = xmlnode_get_child_with_namespace(packet, "open",
-		XEP_0047_NAMESPACE);
 	const gchar *sid = xmlnode_get_attrib(open, "sid");
 	const gchar *block_size = xmlnode_get_attrib(open, "block-size");
 
@@ -66,9 +64,8 @@
 		return NULL;
 	}
 
-	sess = jabber_ibb_session_create(js, sid,
-			xmlnode_get_attrib(packet, "from"), user_data);
-	sess->id = g_strdup(xmlnode_get_attrib(packet, "id"));
+	sess = jabber_ibb_session_create(js, sid, from, user_data);
+	sess->id = g_strdup(id);
 	sess->block_size = atoi(block_size);
 	/* if we create a session from an incoming <open/> request, it means the
 	  session is immediatly open... */
@@ -354,7 +351,7 @@
 }
 
 static void
-jabber_ibb_send_error_response(JabberStream *js, xmlnode *packet)
+jabber_ibb_send_error_response(JabberStream *js, const char *to, const char *id)
 {
 	JabberIq *result = jabber_iq_new(js, JABBER_IQ_ERROR);
 	xmlnode *error = xmlnode_new("error");
@@ -364,9 +361,8 @@
 		"urn:ietf:params:xml:ns:xmpp-stanzas");
 	xmlnode_set_attrib(error, "code", "440");
 	xmlnode_set_attrib(error, "type", "cancel");
-	jabber_iq_set_id(result, xmlnode_get_attrib(packet, "id"));
-	xmlnode_set_attrib(result->node, "to",
-		xmlnode_get_attrib(packet, "from"));
+	jabber_iq_set_id(result, id);
+	xmlnode_set_attrib(result->node, "to", to);
 	xmlnode_insert_child(error, item_not_found);
 	xmlnode_insert_child(result->node, error);
 
@@ -374,20 +370,17 @@
 }
 
 void
-jabber_ibb_parse(JabberStream *js, xmlnode *packet)
+jabber_ibb_parse(JabberStream *js, const char *who, JabberIqType type,
+                 const char *id, xmlnode *child)
 {
-	xmlnode *data = xmlnode_get_child_with_namespace(packet, "data",
-		XEP_0047_NAMESPACE);
-	xmlnode *close = xmlnode_get_child_with_namespace(packet, "close",
-		XEP_0047_NAMESPACE);
-	xmlnode *open = xmlnode_get_child_with_namespace(packet, "open",
-		XEP_0047_NAMESPACE);
-	const gchar *sid =
-		data ? xmlnode_get_attrib(data, "sid") :
-			close ? xmlnode_get_attrib(close, "sid") : NULL;
+	const char *name = child->name;
+	gboolean data  = g_str_equal(name, "data");
+	gboolean close = g_str_equal(name, "close");
+	gboolean open  = g_str_equal(name, "open");
+	const gchar *sid = (data || close) ?
+		xmlnode_get_attrib(child, "sid") : NULL;
 	JabberIBBSession *sess =
 		sid ? g_hash_table_lookup(jabber_ibb_sessions, sid) : NULL;
-	const gchar *who = xmlnode_get_attrib(packet, "from");
 
 	if (sess) {
 
@@ -397,7 +390,7 @@
 			purple_debug_error("jabber",
 				"Got IBB iq from wrong JID, ignoring\n");
 		} else if (data) {
-			const gchar *seq_attr = xmlnode_get_attrib(data, "seq");
+			const gchar *seq_attr = xmlnode_get_attrib(child, "seq");
 			guint16 seq = (seq_attr ? atoi(seq_attr) : 0);
 
 			/* reject the data, and set the session in error if we get an
@@ -406,12 +399,11 @@
 				/* sequence # is the expected... */
 				JabberIq *result = jabber_iq_new(js, JABBER_IQ_RESULT);
 
-				jabber_iq_set_id(result, xmlnode_get_attrib(packet, "id"));
-				xmlnode_set_attrib(result->node, "to",
-					xmlnode_get_attrib(packet, "from"));
+				jabber_iq_set_id(result, id);
+				xmlnode_set_attrib(result->node, "to", who);
 
 				if (sess->data_received_cb) {
-					gchar *base64 = xmlnode_get_data(data);
+					gchar *base64 = xmlnode_get_data(child);
 					gsize size;
 					gpointer rawdata = purple_base64_decode(base64, &size);
 
@@ -478,20 +470,19 @@
 			 iterator = g_list_next(iterator)) {
 			JabberIBBOpenHandler *handler = iterator->data;
 
-			if (handler(js, packet)) {
+			if (handler(js, who, id, child)) {
 				result = jabber_iq_new(js, JABBER_IQ_RESULT);
-				xmlnode_set_attrib(result->node, "to",
-					xmlnode_get_attrib(packet, "from"));
-				jabber_iq_set_id(result, xmlnode_get_attrib(packet, "id"));
+				xmlnode_set_attrib(result->node, "to", who);
+				jabber_iq_set_id(result, id);
 				jabber_iq_send(result);
 				return;
 			}
 		}
 		/* no open callback returned success, reject */
-		jabber_ibb_send_error_response(js, packet);
+		jabber_ibb_send_error_response(js, who, id);
 	} else {
 		/* send error reply */
-		jabber_ibb_send_error_response(js, packet);
+		jabber_ibb_send_error_response(js, who, id);
 	}
 }
 
--- a/libpurple/protocols/jabber/ibb.h	Fri Apr 03 17:36:24 2009 +0000
+++ b/libpurple/protocols/jabber/ibb.h	Sat Apr 04 07:05:23 2009 +0000
@@ -32,7 +32,8 @@
 typedef void (JabberIBBErrorCallback)(JabberIBBSession *);
 typedef void (JabberIBBSentCallback)(JabberIBBSession *);
 
-typedef gboolean (JabberIBBOpenHandler)(JabberStream *js, xmlnode *packet);
+typedef gboolean (JabberIBBOpenHandler)(JabberStream *js, const char *from,
+                                        const char *id, xmlnode *open);
 
 typedef enum {
 	JABBER_IBB_SESSION_NOT_OPENED,
@@ -71,7 +72,7 @@
 JabberIBBSession *jabber_ibb_session_create(JabberStream *js, const gchar *sid,
 	const gchar *who, gpointer user_data);
 JabberIBBSession *jabber_ibb_session_create_from_xmlnode(JabberStream *js,
-	xmlnode *packet, gpointer user_data);
+	const gchar *from, const gchar *id, xmlnode *open, gpointer user_data);
 
 void jabber_ibb_session_destroy(JabberIBBSession *sess);
 
@@ -107,7 +108,8 @@
 gpointer jabber_ibb_session_get_user_data(JabberIBBSession *sess);
 
 /* handle incoming packet */
-void jabber_ibb_parse(JabberStream *js, xmlnode *packet);
+void jabber_ibb_parse(JabberStream *js, const char *who, JabberIqType type,
+                      const char *id, xmlnode *child);
 
 /* add a handler for open session */
 void jabber_ibb_register_open_handler(JabberIBBOpenHandler *cb);
--- a/libpurple/protocols/jabber/iq.c	Fri Apr 03 17:36:24 2009 +0000
+++ b/libpurple/protocols/jabber/iq.c	Sat Apr 04 07:05:23 2009 +0000
@@ -428,6 +428,10 @@
 	jabber_iq_register_handler("ping", "urn:xmpp:ping", jabber_ping_parse);
 	jabber_iq_register_handler("time", "urn:xmpp:time", jabber_iq_time_parse);
 
+	jabber_iq_register_handler("data", XEP_0047_NAMESPACE, jabber_ibb_parse);
+	jabber_iq_register_handler("close", XEP_0047_NAMESPACE, jabber_ibb_parse);
+	jabber_iq_register_handler("open", XEP_0047_NAMESPACE, jabber_ibb_parse);
+
 	jabber_iq_register_handler("jingle", JINGLE, jingle_parse);
 	jabber_iq_register_handler("query", GOOGLE_JINGLE_INFO_NAMESPACE,
 		jabber_google_handle_jingle_info);
--- a/libpurple/protocols/jabber/si.c	Fri Apr 03 17:36:24 2009 +0000
+++ b/libpurple/protocols/jabber/si.c	Sat Apr 04 07:05:23 2009 +0000
@@ -1015,16 +1015,15 @@
 }
 
 static gboolean
-jabber_si_xfer_ibb_open_cb(JabberStream *js, xmlnode *packet)
+jabber_si_xfer_ibb_open_cb(JabberStream *js, const char *who, const char *id,
+                           xmlnode *open)
 {
-	const gchar *who = xmlnode_get_attrib(packet, "from");
-	xmlnode *open = xmlnode_get_child(packet, "open");
 	const gchar *sid = xmlnode_get_attrib(open, "sid");
 	PurpleXfer *xfer = jabber_si_xfer_find(js, sid, who);
 	if (xfer) {
 		JabberSIXfer *jsx = (JabberSIXfer *) xfer->data;
 		JabberIBBSession *sess =
-			jabber_ibb_session_create_from_xmlnode(js, packet, xfer);
+			jabber_ibb_session_create_from_xmlnode(js, who, id, open, xfer);
 		const char *filename;
 
 		jabber_si_bytestreams_ibb_timeout_remove(jsx);