changeset 25022:4c97156431b4

* pass hash type to the caps handling functions * fix small bug in generation of caps hash * removed a bit debugging output
author Tobias Markmann <tfar@soc.pidgin.im>
date Tue, 01 Jul 2008 23:16:15 +0000
parents a5e437b7f915
children 623fbda59aa4
files libpurple/protocols/jabber/caps.c libpurple/protocols/jabber/caps.h libpurple/protocols/jabber/presence.c
diffstat 3 files changed, 22 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/caps.c	Sun Jun 29 14:32:33 2008 +0000
+++ b/libpurple/protocols/jabber/caps.c	Tue Jul 01 23:16:15 2008 +0000
@@ -351,6 +351,7 @@
 	char *node;
 	char *ver;
 	GList *ext;
+	char *hash;
 	unsigned extOutstanding;
 } jabber_caps_cbplususerdata;
 
@@ -446,8 +447,15 @@
 	jabber_caps_cbplususerdata *userdata = data;
 
 	/* TODO: Better error checking! */
-	printf("\n\tjabber_caps_client_iqcb for %s", xmlnode_get_attrib(packet, "from"));
 	if (query) {
+		// check hash
+		JabberCapsClientInfo *info = jabber_caps_parse_client_info(query);
+		gchar *sha_hash = jabber_caps_calcualte_hash(info);
+		
+		#warning INSERT HASH CHECKING CODE HERE! ONLY ADD TO CACHE IF HASH IS THE SAME.
+		
+		g_free(info);
+		g_free(sha_hash);
 		
 		JabberCapsValue *value = g_new0(JabberCapsValue, 1);
 		JabberCapsKey *key = g_new0(JabberCapsKey, 1);
@@ -501,7 +509,7 @@
 	jabber_caps_get_info_check_completion(userdata);
 }
 
-void jabber_caps_get_info(JabberStream *js, const char *who, const char *node, const char *ver, const char *ext, jabber_caps_get_info_cb cb, gpointer user_data) {
+void jabber_caps_get_info(JabberStream *js, const char *who, const char *node, const char *ver, const char *hash, jabber_caps_get_info_cb cb, gpointer user_data) {
 	JabberCapsValue *client;
 	JabberCapsKey *key = g_new0(JabberCapsKey, 1);
 	jabber_caps_cbplususerdata *userdata = g_new0(jabber_caps_cbplususerdata, 1);
@@ -510,6 +518,7 @@
 	userdata->who = g_strdup(who);
 	userdata->node = g_strdup(node);
 	userdata->ver = g_strdup(ver);
+	userdata->hash = g_strdup(hash);
 
 	key->node = (char *)node;
 	key->ver = (char *)ver;
@@ -745,7 +754,7 @@
 	
 	/* concat features to the verification string */
 	for(features = info->features; features; features = features->next) {
-		feature_string = g_strdup_printf("%s<", (gchar*)features->data);
+		feature_string = g_strdup_printf("%s", (gchar*)features->data);
 		verification = jabber_caps_verification_append(verification, feature_string);
 		g_free(feature_string);
 	}
@@ -761,7 +770,7 @@
 		
 		for(fields = jabber_caps_xdata_get_fields((xmlnode*)(xdata->data)); fields != 0; fields = fields->next) {
 			GList *value;
-			JabberDataFormField *field = (JabberDataFormField*)fields; 
+			JabberDataFormField *field = (JabberDataFormField*)fields->data; 
 			if(strcmp(field->var, "FORM_TYPE")) {
 				/* Append the value of the "var" attribute, followed by the '<' character. */
 				verification = jabber_caps_verification_append(verification, field->var);
@@ -778,7 +787,7 @@
 		}
 		g_list_free(fields);
 	}
-	
+		
 	/* generate SHA-1 hash */
 	context = purple_cipher_context_new_by_name("sha1", NULL);
 	if (context == NULL) {
@@ -796,7 +805,6 @@
 	
 	g_free(verification);
 	verification = purple_base64_encode(checksum, checksum_size);
-	printf("\n%s", verification);
 	
 	if (caps_hash != 0) g_free(caps_hash);
 	return verification;
--- a/libpurple/protocols/jabber/caps.h	Sun Jun 29 14:32:33 2008 +0000
+++ b/libpurple/protocols/jabber/caps.h	Tue Jul 01 23:16:15 2008 +0000
@@ -45,7 +45,10 @@
 
 void jabber_caps_init(void);
 
-void jabber_caps_get_info(JabberStream *js, const char *who, const char *node, const char *ver, const char *ext, jabber_caps_get_info_cb cb, gpointer user_data);
+/**
+ *	Main entity capabilites function to get the capabilities of a contact.
+ */
+void jabber_caps_get_info(JabberStream *js, const char *who, const char *node, const char *ver, const char *hash, jabber_caps_get_info_cb cb, gpointer user_data);
 void jabber_caps_free_clientinfo(JabberCapsClientInfo *clientinfo);
 
 /**
--- a/libpurple/protocols/jabber/presence.c	Sun Jun 29 14:32:33 2008 +0000
+++ b/libpurple/protocols/jabber/presence.c	Tue Jul 01 23:16:15 2008 +0000
@@ -750,16 +750,17 @@
 			jbr = jabber_buddy_track_resource(jb, jid->resource, priority,
 					state, status);
 			if(caps) {
+				/* handle XEP-0115 */
 				const char *node = xmlnode_get_attrib(caps,"node");
 				const char *ver = xmlnode_get_attrib(caps,"ver");
-				const char *ext = xmlnode_get_attrib(caps,"ext");
+				const char *hash = xmlnode_get_attrib(caps,"hash");
 				
-				if(node && ver) {
+				if(node && ver && hash) {
 					JabberPresenceCapabilities *userdata = g_new0(JabberPresenceCapabilities, 1);
 					userdata->js = js;
 					userdata->jb = jb;
 					userdata->from = g_strdup(from);
-					jabber_caps_get_info(js, from, node, ver, ext, jabber_presence_set_capabilities, userdata);
+					jabber_caps_get_info(js, from, node, ver, hash, jabber_presence_set_capabilities, userdata);
 				}
 			}
 		}