pidgin: d6d62482: If get_info_for_jid is passed a full JID...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Thu Jul 2 18:06:16 EDT 2009


-----------------------------------------------------------------
Revision: d6d62482a33ec2323ec2efb4e5e6be42257e66d3
Ancestor: e703fb0151724a6fb97dff8ea67644dfe33fc922
Author: darkrain42 at pidgin.im
Date: 2009-07-02T22:03:21
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/d6d62482a33ec2323ec2efb4e5e6be42257e66d3

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

ChangeLog: 

If get_info_for_jid is passed a full JID, don't spam that JID with IQs.

Looping over all the resources while using the passed-in JID as the to
address was causing us to generate O(N) queries to a member of a MUC (where
N is the number of people in the room).

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/buddy.c	bf05b5f93ae88a7433e67e1c707db3230bc15cf5
+++ libpurple/protocols/jabber/buddy.c	0442cc5f00afe83ff749ded3c96c32bc89cd694f
@@ -1725,6 +1725,7 @@ static void jabber_buddy_get_info_for_ji
 	GList *resources;
 	JabberBuddy *jb;
 	JabberBuddyInfo *jbi;
+	const char *slash;
 	gboolean is_bare_jid;
 
 	jb = jabber_buddy_find(js, jid, TRUE);
@@ -1733,7 +1734,8 @@ static void jabber_buddy_get_info_for_ji
 	if(!jb)
 		return;
 
-	is_bare_jid = (strchr(jid, '/') == NULL);
+	slash = strchr(jid, '/');
+	is_bare_jid = (slash == NULL);
 
 	jbi = g_new0(JabberBuddyInfo, 1);
 	jbi->jid = g_strdup(jid);
@@ -1753,10 +1755,19 @@ static void jabber_buddy_get_info_for_ji
 
 	jabber_iq_send(iq);
 
-	for(resources = jb->resources; resources; resources = resources->next)
-	{
-		JabberBuddyResource *jbr = resources->data;
-		dispatch_queries_for_resource(js, jbi, is_bare_jid, jid, jbr);
+	if (is_bare_jid) {
+		for(resources = jb->resources; resources; resources = resources->next) {
+			JabberBuddyResource *jbr = resources->data;
+			dispatch_queries_for_resource(js, jbi, is_bare_jid, jid, jbr);
+		}
+	} else {
+		JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, slash + 1);
+		if (jbr)
+			dispatch_queries_for_resource(js, jbi, is_bare_jid, jid, jbr);
+		else
+			purple_debug_warning("jabber", "jabber_buddy_get_info_for_jid() "
+					"was passed JID %s, but there is no corresponding "
+					"JabberBuddyResource!\n", jid);
 	}
 
 	if (!jb->resources && is_bare_jid) {


More information about the Commits mailing list