diff libpurple/protocols/jabber/buddy.c @ 29045:4e7fd81a39c6

jabber: Fix getting info on your own JID, under some circumstances. Prosody doesn't stamp a 'from' on responses from one's own bare JID (and the spec does not require it), so neither of these functions can rely on 'from' being non-NULL. Of course, we shouldn't be sending an NS_LAST_ACTIVITY to our own bare JID, but that's another issue.
author Paul Aurich <paul@darkrain42.org>
date Sun, 14 Feb 2010 23:56:00 +0000
parents b8d47ed6ceb1
children f2949cd7db0a
line wrap: on
line diff
--- a/libpurple/protocols/jabber/buddy.c	Sun Feb 14 20:20:00 2010 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Sun Feb 14 23:56:00 2010 +0000
@@ -980,28 +980,25 @@
 	char *text;
 	char *serverside_alias = NULL;
 	xmlnode *vcard;
-	PurpleBuddy *b;
+	PurpleAccount *account;
 	JabberBuddyInfo *jbi = data;
 	PurpleNotifyUserInfo *user_info;
 
-	if(!jbi)
-		return;
+	g_return_if_fail(jbi != NULL);
 
 	jabber_buddy_info_remove_id(jbi, id);
 
-	if(!from)
+	if (type == JABBER_IQ_ERROR) {
+		purple_debug_info("jabber", "Got error response for vCard\n");
+		jabber_buddy_info_show_if_ready(jbi);
 		return;
-
-	if(!jabber_buddy_find(js, from, FALSE))
-		return;
-
-	/* XXX: handle the error case */
+	}
 
 	user_info = jbi->user_info;
-	bare_jid = jabber_get_bare_jid(from);
+	account = purple_connection_get_account(js->gc);
+	bare_jid = jabber_get_bare_jid(from ? from : purple_account_get_username(account));
 
-	b = purple_find_buddy(js->gc->account, bare_jid);
-
+	/* TODO: Is the query xmlns='vcard-temp' version of this still necessary? */
 	if((vcard = xmlnode_get_child(packet, "vCard")) ||
 			(vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) {
 		xmlnode *child;
@@ -1183,8 +1180,7 @@
 						purple_notify_user_info_add_pair(user_info, (photo ? _("Photo") : _("Logo")), img_text);
 
 						hash = jabber_calculate_data_sha1sum(data, size);
-						purple_buddy_icons_set_for_user(js->gc->account, bare_jid,
-								data, size, hash);
+						purple_buddy_icons_set_for_user(account, bare_jid, data, size, hash);
 						g_free(hash);
 						g_free(img_text);
 					}
@@ -1196,8 +1192,10 @@
 	}
 
 	if (serverside_alias) {
+		PurpleBuddy *b;
 		/* If we found a serverside alias, set it and tell the core */
-		serv_got_alias(js->gc, from, serverside_alias);
+		serv_got_alias(js->gc, bare_jid, serverside_alias);
+		b = purple_find_buddy(account, bare_jid);
 		if (b) {
 			purple_blist_node_set_string((PurpleBlistNode*)b, "servernick", serverside_alias);
 		}
@@ -1363,9 +1361,6 @@
 
 	jabber_buddy_info_remove_id(jbi, id);
 
-	if(!from)
-		return;
-
 	if (type == JABBER_IQ_RESULT) {
 		if((query = xmlnode_get_child(packet, "query"))) {
 			seconds = xmlnode_get_attrib(query, "seconds");
@@ -1587,9 +1582,18 @@
 	jabber_iq_send(iq);
 
 	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);
+		if (jb->resources) {
+			for(resources = jb->resources; resources; resources = resources->next) {
+				JabberBuddyResource *jbr = resources->data;
+				dispatch_queries_for_resource(js, jbi, is_bare_jid, jid, jbr);
+			}
+		} else {
+			/* user is offline, send a jabber:iq:last to find out last time online */
+			iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_LAST_ACTIVITY);
+			xmlnode_set_attrib(iq->node, "to", jid);
+			jabber_iq_set_callback(iq, jabber_last_offline_parse, jbi);
+			jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
+			jabber_iq_send(iq);
 		}
 	} else {
 		JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, slash + 1);
@@ -1601,15 +1605,6 @@
 					"JabberBuddyResource!\n", jid);
 	}
 
-	if (!jb->resources && is_bare_jid) {
-		/* user is offline, send a jabber:iq:last to find out last time online */
-		iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_LAST_ACTIVITY);
-		xmlnode_set_attrib(iq->node, "to", jid);
-		jabber_iq_set_callback(iq, jabber_last_offline_parse, jbi);
-		jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
-		jabber_iq_send(iq);
-	}
-
 	js->pending_buddy_info_requests = g_slist_prepend(js->pending_buddy_info_requests, jbi);
 	jbi->timeout_handle = purple_timeout_add_seconds(30, jabber_buddy_get_info_timeout, jbi);
 }