changeset 25020:9867a406707e

* defined JabberCapsIdentity as struct _JabberIdentity * added jabber_caps_jabber_xdata_compare() which compares two x-data forms as required by XEP-0115
author Tobias Markmann <tfar@soc.pidgin.im>
date Sun, 22 Jun 2008 18:59:33 +0000
parents f6272b156873
children a5e437b7f915
files libpurple/protocols/jabber/caps.c libpurple/protocols/jabber/caps.h libpurple/protocols/jabber/jabber.h
diffstat 3 files changed, 42 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/caps.c	Sun Jun 22 18:30:12 2008 +0000
+++ b/libpurple/protocols/jabber/caps.c	Sun Jun 22 18:59:33 2008 +0000
@@ -595,6 +595,42 @@
 	return strcmp(ac->namespace, bc->namespace);
 }
 
+static gint jabber_caps_string_compare(gconstpointer a, gconstpointer b) {
+	const gchar *ac;
+	const gchar *bc;
+	
+	ac = a;
+	bc = b;
+	
+	return strcmp(ac, bc);
+}
+
+static gint jabber_caps_jabber_xdata_compare(gconstpointer a, gconstpointer b) {
+	const xmlnode *ac;
+	const xmlnode *bc;
+	xmlnode *aformtypefield;
+	xmlnode *bformtypefield;
+	char *aformtype;
+	char *bformtype;
+	int result;
+	
+	ac = a;
+	bc = b;
+
+	aformtypefield = xmlnode_get_child(ac, "field");
+	while (aformtypefield && strcmp(xmlnode_get_attrib(aformtypefield, "var"), "FORM_TYPE")) aformtypefield = xmlnode_get_next_twin(aformtypefield);
+	aformtype = xmlnode_get_data(aformtypefield);
+	
+	bformtypefield = xmlnode_get_child(bc, "field");
+	while (bformtypefield && strcmp(xmlnode_get_attrib(bformtypefield, "var"), "FORM_TYPE")) bformtypefield = xmlnode_get_next_twin(bformtypefield);
+	bformtype = xmlnode_get_data(bformtypefield);
+	
+	result = strcmp(aformtype, bformtype);
+	g_free(aformtype);
+	g_free(bformtype);
+	return result;
+}
+
 JabberCapsClientInfo *jabber_caps_parse_client_info(xmlnode *query) {
 	xmlnode *child;
 	
@@ -636,6 +672,10 @@
 gchar *jabber_caps_calcualte_hash(JabberCapsClientInfo *info) {
 	if (!info) return 0;
 	
+	/* sort identities, features and x-data forms */
+	info->identities = g_list_sort(info->identities, jabber_caps_jabber_identity_compare);
+	info->features = g_list_sort(info->features, jabber_caps_string_compare);
+	info->forms = g_list_sort(info->forms, jabber_caps_jabber_xdata_compare);
 }
 
 void jabber_caps_calculate_own_hash() {
--- a/libpurple/protocols/jabber/caps.h	Sun Jun 22 18:30:12 2008 +0000
+++ b/libpurple/protocols/jabber/caps.h	Sun Jun 22 18:59:33 2008 +0000
@@ -28,12 +28,7 @@
 
 /* Implementation of XEP-0115 */
 
-typedef struct _JabberCapsIdentity {
-	char *category;
-	char *type;
-	char *name;
-	char *lang;
-} JabberCapsIdentity;
+typedef struct _JabberIdentity JabberCapsIdentity;
 
 struct _JabberCapsClientInfo {
 	GList *identities; /* JabberCapsIdentity */
--- a/libpurple/protocols/jabber/jabber.h	Sun Jun 22 18:30:12 2008 +0000
+++ b/libpurple/protocols/jabber/jabber.h	Sun Jun 22 18:59:33 2008 +0000
@@ -216,6 +216,7 @@
 	gchar *category;
 	gchar *type;
 	gchar *name;
+	gchar *lang;
 } JabberIdentity;
 
 typedef struct _JabberBytestreamsStreamhost {