cpw.darkrain42.xmpp.bosh: 6edff60c: Rename user_data to cb_data (there were ...

paul at darkrain42.org paul at darkrain42.org
Sat Jan 17 23:56:14 EST 2009


-----------------------------------------------------------------
Revision: 6edff60c4aff126c95b9a8064e8e8fdfdc2cbb1a
Ancestor: 2dcb02f28f139d6dd326a7ff889f822f189e88e8
Author: paul at darkrain42.org
Date: 2008-12-12T00:00:00
Branch: im.pidgin.cpw.darkrain42.xmpp.bosh
URL: http://d.pidgin.im/viewmtn/revision/info/6edff60c4aff126c95b9a8064e8e8fdfdc2cbb1a

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

ChangeLog: 

Rename user_data to cb_data (there were too many 'userdata'/'user_data's).
Refactor jabber_caps_client_iqcb a bit (less repeating of the clean up)

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/caps.c	c31c48dcbfb65fb19a763a0becc74dd07a9bca04
+++ libpurple/protocols/jabber/caps.c	b625ac2930380d940031b489b3f7ea58c304d55c
@@ -343,8 +343,8 @@ typedef struct _jabber_caps_cbplususerda
 
 typedef struct _jabber_caps_cbplususerdata {
 	jabber_caps_get_info_cb cb;
-	gpointer user_data;
-	
+	gpointer cb_data;
+
 	char *who;
 	char *node;
 	char *ver;
@@ -364,7 +364,7 @@ static void jabber_caps_get_info_check_c
 #if 0
 static void jabber_caps_get_info_check_completion(jabber_caps_cbplususerdata *userdata) {
 	if(userdata->extOutstanding == 0) {
-		userdata->cb(jabber_caps_collect_info(userdata->node, userdata->ver, userdata->ext), userdata->user_data);
+		userdata->cb(jabber_caps_collect_info(userdata->node, userdata->ver, userdata->ext), userdata->cb_data);
 		g_free(userdata->who);
 		g_free(userdata->node);
 		g_free(userdata->ver);
@@ -446,20 +446,14 @@ jabber_caps_client_iqcb(JabberStream *js
 	xmlnode *query = xmlnode_get_child_with_namespace(packet, "query",
 		"http://jabber.org/protocol/disco#info");
 	jabber_caps_cbplususerdata *userdata = data;
-	JabberCapsClientInfo *info, *value;
-	gchar *hash;
+	JabberCapsClientInfo *info = NULL, *value;
+	gchar *hash = NULL;
 	const char *type = xmlnode_get_attrib(packet, "type");
 	JabberCapsKey key;
 
 	if (!query || !strcmp(type, "error")) {
-		userdata->cb(NULL, userdata->user_data);
-
-		g_free(userdata->who);
-		g_free(userdata->node);
-		g_free(userdata->ver);
-		g_free(userdata->hash);
-		g_free(userdata);
-		return;
+		userdata->cb(NULL, userdata->cb_data);
+		goto out;
 	}
 
 	/* check hash */
@@ -469,47 +463,30 @@ jabber_caps_client_iqcb(JabberStream *js
 		hash = jabber_caps_calculate_hash(info, "sha1");
 	} else if (!strcmp(userdata->hash, "md5")) {
 		hash = jabber_caps_calculate_hash(info, "md5");
-	} else {
-		purple_debug_warning("jabber", "unknown caps hash algorithm: %s\n", userdata->hash);
-
-		userdata->cb(NULL, userdata->user_data);
-
-		jabber_caps_client_info_destroy(info);
-		g_free(userdata->who);
-		g_free(userdata->node);
-		g_free(userdata->ver);
-		g_free(userdata->hash);
-		g_free(userdata);		
-		return;	
 	}
 
 	if (!hash || strcmp(hash, userdata->ver)) {
-		purple_debug_warning("jabber", "caps hash from %s did not match\n", xmlnode_get_attrib(packet, "from"));
-		userdata->cb(NULL, userdata->user_data);
+		purple_debug_warning("jabber", "Could not validate caps info from %s\n",
+		                     xmlnode_get_attrib(packet, "from"));
 
+		userdata->cb(NULL, userdata->cb_data);
 		jabber_caps_client_info_destroy(info);
-		g_free(userdata->who);
-		g_free(userdata->node);
-		g_free(userdata->ver);
-		g_free(userdata->hash);
-		g_free(userdata);		
-		g_free(hash);
-		return;
+		goto out;
 	}
 
 	key.node = userdata->node;
-	key.ver = userdata->ver;
+	key.ver  = userdata->ver;
 	key.hash = userdata->hash;
 
-	/* check whether it's not in the table */
+	/* Use the copy of this data already in the table if it exists or insert
+	 * a new one if we need to */
 	if ((value = g_hash_table_lookup(capstable, &key))) {
-		JabberCapsClientInfo *tmp = info;
+		jabber_caps_client_info_destroy(info);
 		info = value;
-		jabber_caps_client_info_destroy(tmp);
 	} else {
 		JabberCapsKey *n_key = g_new(JabberCapsKey, 1);
 		n_key->node = userdata->node;
-		n_key->ver = userdata->ver;
+		n_key->ver  = userdata->ver;
 		n_key->hash = userdata->hash;
 		userdata->node = userdata->ver = userdata->hash = NULL;
 
@@ -517,9 +494,10 @@ jabber_caps_client_iqcb(JabberStream *js
 		jabber_caps_store();
 	}
 
-	userdata->cb(info, userdata->user_data);
+	userdata->cb(info, userdata->cb_data);
+	/* capstable owns info */
 
-	/* capstable will free info */
+out:
 	g_free(userdata->who);
 	g_free(userdata->node);
 	g_free(userdata->ver);
@@ -536,7 +514,7 @@ void jabber_caps_get_info(JabberStream *
 	JabberCapsKey *key = g_new0(JabberCapsKey, 1);
 	jabber_caps_cbplususerdata *userdata = g_new0(jabber_caps_cbplususerdata, 1);
 	userdata->cb = cb;
-	userdata->user_data = user_data;
+	userdata->cb_data = user_data;
 	userdata->who = g_strdup(who);
 	userdata->node = g_strdup(node);
 	userdata->ver = g_strdup(ver);


More information about the Commits mailing list