pidgin: 962c33d6: jabber: Move (and harden) a function to ...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Fri Jul 9 22:15:44 EDT 2010


----------------------------------------------------------------------
Revision: 962c33d65e9071cb4e7327a9766e57bc444157d4
Parent:   cc24d17bab7569a77d933bbc370f107fcbec7aa6
Author:   darkrain42 at pidgin.im
Date:     07/09/10 20:59:19
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/962c33d65e9071cb4e7327a9766e57bc444157d4

Changelog: 

jabber: Move (and harden) a function to xdata.c

Oops, I guess the const change on xmlnode_get_attrib wasn't
necessary since I had to cast away the constness so I could use
xmlnode_get_next_twin.  Oh well.

Changes against parent cc24d17bab7569a77d933bbc370f107fcbec7aa6

  patched  libpurple/protocols/jabber/caps.c
  patched  libpurple/protocols/jabber/xdata.c
  patched  libpurple/protocols/jabber/xdata.h

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/xdata.c	c8feb52b610507e621ff8081cfe33e33485650ed
+++ libpurple/protocols/jabber/xdata.c	864973d948143f2faddd8c7403c2fa84a3a9bc8e
@@ -411,4 +411,30 @@ void *jabber_x_data_request_with_actions
 	return handle;
 }
 
+gchar *
+jabber_x_data_get_formtype(const xmlnode *form)
+{
+	xmlnode *field;
 
+	g_return_val_if_fail(form != NULL, NULL);
+
+	for (field = xmlnode_get_child((xmlnode *)form, "field"); field;
+			field = xmlnode_get_next_twin(field)) {
+		const char *var = xmlnode_get_attrib(field, "var");
+		if (purple_strequal(var, "FORM_TYPE")) {
+			xmlnode *value = xmlnode_get_child(field, "value");
+			if (value)
+				return xmlnode_get_data(value);
+			else
+				/* An interesting corner case... Looking for a second
+				 * FORM_TYPE would be more considerate, but I'm in favor
+				 * of not helping broken clients.
+				 */
+				return NULL;
+		}
+	}
+
+	/* Erm, none found :( */
+	return NULL;
+}
+
============================================================
--- libpurple/protocols/jabber/xdata.h	b59199788fec122a34224e7986da029050094c69
+++ libpurple/protocols/jabber/xdata.h	c0b9c50d80ce45e5920065b7032b0f4d97b68355
@@ -37,4 +37,19 @@ void *jabber_x_data_request_with_actions
 void *jabber_x_data_request(JabberStream *js, xmlnode *packet, jabber_x_data_cb cb, gpointer user_data);
 void *jabber_x_data_request_with_actions(JabberStream *js, xmlnode *packet, GList *actions, int defaultaction, jabber_x_data_action_cb cb, gpointer user_data);
 
+/*
+ * Return the form type (the CDATA of the value child of the FORM_TYPE
+ * field entry.
+ * E.g., for the following, "http://jabber.org/protocol/muc#roominfo".
+ * <x xmlns='jabber:x:data' type='result'>
+ *  <field var='FORM_TYPE' type='hidden'>
+ *    <value>http://jabber.org/protocol/muc#roominfo</value>
+ *  </field>
+ * </x>
+ *
+ * @param form The xmlnode for the form (the 'x' element)
+ * @returns The FORM_TYPE.  Must be freed by caller.
+ */
+gchar *jabber_x_data_get_formtype(const xmlnode *form);
+
 #endif /* PURPLE_JABBER_XDATA_H_ */
============================================================
--- libpurple/protocols/jabber/caps.c	86553c4cadb3953354b7b78ae5d7aa9a21444e68
+++ libpurple/protocols/jabber/caps.c	33afcb40b2ef4fdfb3c0a1948586d8ad99a9f18d
@@ -29,6 +29,7 @@
 #include "iq.h"
 #include "presence.h"
 #include "util.h"
+#include "xdata.h"
 
 #define JABBER_CAPS_FILENAME "xmpp-caps.xml"
 
@@ -732,14 +733,6 @@ jabber_identity_compare(gconstpointer a,
 	}
 }
 
-static gchar *jabber_caps_get_formtype(const xmlnode *x) {
-	xmlnode *formtypefield;
-	formtypefield = xmlnode_get_child(x, "field");
-	while (formtypefield && strcmp(xmlnode_get_attrib(formtypefield, "var"), "FORM_TYPE")) formtypefield = xmlnode_get_next_twin(formtypefield);
-	formtypefield = xmlnode_get_child(formtypefield, "value");
-	return xmlnode_get_data(formtypefield);;
-}
-
 static gint
 jabber_xdata_compare(gconstpointer a, gconstpointer b)
 {
@@ -749,8 +742,8 @@ jabber_xdata_compare(gconstpointer a, gc
 	char *bformtype;
 	int result;
 
-	aformtype = jabber_caps_get_formtype(aformtypefield);
-	bformtype = jabber_caps_get_formtype(bformtypefield);
+	aformtype = jabber_x_data_get_formtype(aformtypefield);
+	bformtype = jabber_x_data_get_formtype(bformtypefield);
 
 	result = strcmp(aformtype, bformtype);
 	g_free(aformtype);
@@ -902,7 +895,7 @@ gchar *jabber_caps_calculate_hash(Jabber
 	/* concat x-data forms to the verification string */
 	for(node = info->forms; node; node = node->next) {
 		xmlnode *data = (xmlnode *)node->data;
-		gchar *formtype = jabber_caps_get_formtype(data);
+		gchar *formtype = jabber_x_data_get_formtype(data);
 		GList *fields = jabber_caps_xdata_get_fields(data);
 
 		/* append FORM_TYPE's field value to the verification string */


More information about the Commits mailing list