cpw.darkrain42.xmpp.disco: 0b3b2fbc: Don't match in the disco callbacks hasht...

paul at darkrain42.org paul at darkrain42.org
Sat Apr 25 16:16:06 EDT 2009


-----------------------------------------------------------------
Revision: 0b3b2fbcf7c37afe5fe95c06a5f52be4a84e7c9f
Ancestor: 2dd83860c4947720361945ae2299a3a295dfae2a
Author: paul at darkrain42.org
Date: 2009-03-31T06:43:54
Branch: im.pidgin.cpw.darkrain42.xmpp.disco
URL: http://d.pidgin.im/viewmtn/revision/info/0b3b2fbcf7c37afe5fe95c06a5f52be4a84e7c9f

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

ChangeLog: 

Don't match in the disco callbacks hashtable on remote JID. Use IQ id instead.

This won't break if there are concurrent disco queries out to a remote node.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/disco.c	464c72e8225d77cd282b3343a512c4d34115ec4f
+++ libpurple/protocols/jabber/disco.c	43dc72d4718708a7d4d93371bdd0d6916f06d462
@@ -98,6 +98,7 @@ void jabber_disco_info_parse(JabberStrea
 void jabber_disco_info_parse(JabberStream *js, xmlnode *packet) {
 	const char *from = xmlnode_get_attrib(packet, "from");
 	const char *type = xmlnode_get_attrib(packet, "type");
+	const char *id   = xmlnode_get_attrib(packet, "id");
 
 	if(!from || !type)
 		return;
@@ -117,7 +118,7 @@ void jabber_disco_info_parse(JabberStrea
 		iq = jabber_iq_new_query(js, JABBER_IQ_RESULT,
 				"http://jabber.org/protocol/disco#info");
 
-		jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id"));
+		jabber_iq_set_id(iq, id);
 
 		xmlnode_set_attrib(iq->node, "to", from);
 		query = xmlnode_get_child(iq->node, "query");
@@ -295,9 +296,9 @@ void jabber_disco_info_parse(JabberStrea
 		if(jbr)
 			jbr->capabilities = capabilities;
 
-		if((jdicd = g_hash_table_lookup(js->disco_callbacks, from))) {
+		if((jdicd = g_hash_table_lookup(js->disco_callbacks, id))) {
 			jdicd->callback(js, from, capabilities, jdicd->data);
-			g_hash_table_remove(js->disco_callbacks, from);
+			g_hash_table_remove(js->disco_callbacks, id);
 		}
 	} else if(!strcmp(type, "error")) {
 		JabberID *jid;
@@ -306,7 +307,7 @@ void jabber_disco_info_parse(JabberStrea
 		JabberCapabilities capabilities = JABBER_CAP_NONE;
 		struct _jabber_disco_info_cb_data *jdicd;
 
-		if(!(jdicd = g_hash_table_lookup(js->disco_callbacks, from)))
+		if(!(jdicd = g_hash_table_lookup(js->disco_callbacks, id)))
 			return;
 
 		if((jid = jabber_id_new(from))) {
@@ -319,7 +320,7 @@ void jabber_disco_info_parse(JabberStrea
 			capabilities = jbr->capabilities;
 
 		jdicd->callback(js, from, capabilities, jdicd->data);
-		g_hash_table_remove(js->disco_callbacks, from);
+		g_hash_table_remove(js->disco_callbacks, id);
 	}
 }
 
@@ -552,6 +553,7 @@ void jabber_disco_info_do(JabberStream *
 	JabberBuddy *jb;
 	JabberBuddyResource *jbr = NULL;
 	struct _jabber_disco_info_cb_data *jdicd;
+	const char *id;
 	JabberIq *iq;
 
 	if((jid = jabber_id_new(who))) {
@@ -569,11 +571,13 @@ void jabber_disco_info_do(JabberStream *
 	jdicd->data = data;
 	jdicd->callback = callback;
 
-	g_hash_table_insert(js->disco_callbacks, g_strdup(who), jdicd);
-
 	iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info");
 	xmlnode_set_attrib(iq->node, "to", who);
 
+	id = jabber_get_next_id(js);
+	jabber_iq_set_id(iq, id);
+	g_hash_table_insert(js->disco_callbacks, id, jdicd);
+
 	jabber_iq_send(iq);
 }
 


More information about the Commits mailing list