soc.2008.xmpp: 18ba32c0: * support for calculating both hashes, s...

tfar at soc.pidgin.im tfar at soc.pidgin.im
Sun Jul 6 17:16:31 EDT 2008


-----------------------------------------------------------------
Revision: 18ba32c0561283521f019479fb953f7c006613d1
Ancestor: 9cc147c073408bc27e1576d3a5a76773341b1f69
Author: tfar at soc.pidgin.im
Date: 2008-07-03T22:30:44
Branch: im.pidgin.soc.2008.xmpp
URL: http://d.pidgin.im/viewmtn/revision/info/18ba32c0561283521f019479fb953f7c006613d1

Modified files:
        libpurple/protocols/jabber/caps.c
        libpurple/protocols/jabber/caps.h

ChangeLog: 

* support for calculating both hashes, sha-1 and md5
* preparing merge of two data structres; JabberCapsClientInfo and new one

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/caps.c	b81f420875f73877e81b4ec6be4a51931e4e9735
+++ libpurple/protocols/jabber/caps.c	e8359bd54d5a66f95ffe5af487dd8e9fc24e63f3
@@ -42,6 +42,7 @@ typedef struct _JabberCapsValueExt {
 typedef struct _JabberCapsValueExt {
 	GList *identities; /* JabberCapsIdentity */
 	GList *features; /* char * */
+	GList *xdatas; /* xmlnode * */
 } JabberCapsValueExt;
 
 typedef struct _JabberCapsValue {
@@ -61,7 +62,7 @@ static gboolean jabber_caps_compare(gcon
 static gboolean jabber_caps_compare(gconstpointer v1, gconstpointer v2) {
 	const JabberCapsKey *name1 = v1;
 	const JabberCapsKey *name2 = v2;
-
+	
 	return strcmp(name1->node,name2->node) == 0 && strcmp(name1->ver,name2->ver) == 0;
 }
 
@@ -447,15 +448,35 @@ static void jabber_caps_client_iqcb(Jabb
 	jabber_caps_cbplususerdata *userdata = data;
 
 	/* TODO: Better error checking! */
+	if (!strcmp(xmlnode_get_attrib(packet, "type"), "error"))return;
 	if (query) {
 		// check hash
 		JabberCapsClientInfo *info = jabber_caps_parse_client_info(query);
-		gchar *sha_hash = jabber_caps_calcualte_hash(info);
+		gchar *hash = 0;
+		if (!strcmp(userdata->hash, "sha-1")) {
+			hash = jabber_caps_calcualte_hash(info, "sha1");
+		} else if (!strcmp(userdata->hash, "md5")) {
+			hash = jabber_caps_calcualte_hash(info, "md5");
+		} else {
+			// clean up
+			return;	
+		}
 		
-		#warning INSERT HASH CHECKING CODE HERE! ONLY ADD TO CACHE IF HASH IS THE SAME.
+		printf("\n\tfrom:            %s", xmlnode_get_attrib(packet, "from"));
+		printf("\n\tnode:            %s", xmlnode_get_attrib(query, "node"));
+		printf("\n\tcalculated key:  %s", hash);
+		printf("\n\thash:            %s", userdata->hash);
+		printf("\n");
 		
+		if (strcmp(hash, userdata->ver)) {
+			g_free(info);
+			g_free(hash);
+			printf("\n! ! ! invalid hash ! ! !");
+			return;
+		}
+
 		g_free(info);
-		g_free(sha_hash);
+		g_free(hash);
 		
 		JabberCapsValue *value = g_new0(JabberCapsValue, 1);
 		JabberCapsKey *key = g_new0(JabberCapsKey, 1);
@@ -477,7 +498,9 @@ static void jabber_caps_client_iqcb(Jabb
 				const char *category = xmlnode_get_attrib(child, "category");
 				const char *type = xmlnode_get_attrib(child, "type");
 				const char *name = xmlnode_get_attrib(child, "name");
-
+				
+				if (category == 0 || type == 0 || name == 0) printf("\nMISSING");
+				
 				JabberCapsIdentity *id = g_new0(JabberCapsIdentity, 1);
 				id->category = g_strdup(category);
 				id->type = g_strdup(type);
@@ -486,8 +509,9 @@ static void jabber_caps_client_iqcb(Jabb
 				value->identities = g_list_append(value->identities,id);
 			}
 		}
-		g_hash_table_replace(capstable, key, value);
-		jabber_caps_store();
+
+		//g_hash_table_replace(capstable, key, value);
+		//jabber_caps_store();
 	}
 
 	/* fetch all exts */
@@ -722,7 +746,7 @@ gchar *jabber_caps_verification_append(g
 	return verification;
 }
 
-gchar *jabber_caps_calcualte_hash(JabberCapsClientInfo *info) {
+gchar *jabber_caps_calcualte_hash(JabberCapsClientInfo *info, const char *hash) {
 	GList *identities;
 	GList *features;
 	GList *xdata;
@@ -788,16 +812,16 @@ gchar *jabber_caps_calcualte_hash(Jabber
 		g_list_free(fields);
 	}
 		
-	/* generate SHA-1 hash */
-	context = purple_cipher_context_new_by_name("sha1", NULL);
+	/* generate hash */
+	context = purple_cipher_context_new_by_name(hash, NULL);
 	if (context == NULL) {
-		purple_debug_error("jabber", "Could not find sha1 cipher\n");
+		//purple_debug_error("jabber", "Could not find cipher\n");
 		return 0;
 	}
 	purple_cipher_context_append(context, verification, strlen(verification));
 	
 	if (!purple_cipher_context_digest(context, strlen(verification), checksum, &checksum_size)) {
-		purple_debug_error("util", "Failed to get SHA-1 digest.\n");
+		//purple_debug_error("util", "Failed to get digest.\n");
 	}
 	purple_cipher_context_destroy(context);
 	
============================================================
--- libpurple/protocols/jabber/caps.h	45afe34c1f633fc9f2aea3dffbfd5734b36ee7c8
+++ libpurple/protocols/jabber/caps.h	6a71bd3feae12badcbbb800ca76d4cb1de31da0f
@@ -64,10 +64,11 @@ JabberCapsClientInfo *jabber_caps_parse_
  *	XEP-0115 Version 1.5.
  *
  *	@param info A JabberCapsClientInfo pointer.
+ *	@param hash Hash cipher to be used. Either sha-1 or md5.
  *	@return		The base64 encoded SHA-1 hash; needs to be freed if not needed 
  *				any furthermore. 
  */
-gchar *jabber_caps_calcualte_hash(JabberCapsClientInfo *info);
+gchar *jabber_caps_calcualte_hash(JabberCapsClientInfo *info, const char *hash);
 
 void jabber_caps_calculate_own_hash();
 


More information about the Commits mailing list