changeset 27334:ea9df9bfa921

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).
author Paul Aurich <paul@darkrain42.org>
date Thu, 02 Jul 2009 22:03:21 +0000
parents c408e4dc3101
children beb33c984100
files libpurple/protocols/jabber/buddy.c
diffstat 1 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/buddy.c	Thu Jul 02 21:55:15 2009 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Thu Jul 02 22:03:21 2009 +0000
@@ -1725,6 +1725,7 @@
 	GList *resources;
 	JabberBuddy *jb;
 	JabberBuddyInfo *jbi;
+	const char *slash;
 	gboolean is_bare_jid;
 
 	jb = jabber_buddy_find(js, jid, TRUE);
@@ -1733,7 +1734,8 @@
 	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 @@
 
 	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) {