diff libpurple/protocols/jabber/buddy.c @ 25817:9195955395b6

Only (re)publish XMPP avatars at login if the server's avatar differs As part of this, no longer rely on the vcard for determining a need to publish the XEP-0084 avatar; explicitly fetch and compare it. Closes #7734. References #7732. That patch needs updating to apply on top of this.
author Paul Aurich <paul@darkrain42.org>
date Wed, 21 Jan 2009 20:16:22 +0000
parents 5dd25c58b65e
children 370d8eba2ce0
line wrap: on
line diff
--- a/libpurple/protocols/jabber/buddy.c	Wed Jan 21 17:56:07 2009 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Wed Jan 21 20:16:22 2009 +0000
@@ -472,7 +472,6 @@
 		enc = purple_base64_encode(avatar_data, avatar_len);
 
 		js->avatar_hash = jabber_calculate_data_sha1sum(avatar_data, avatar_len);
-
 		xmlnode_insert_data(binval, enc, -1);
 		g_free(enc);
 	} else if (vc_node) {
@@ -494,7 +493,7 @@
 {
 	PurplePresence *gpresence;
 	PurpleStatus *status;
-	
+
 	jabber_avatar_set(gc->proto_data, img);
 	/* vCard avatars do not have an image type requirement so update our
 	 * vCard avatar regardless of image type for those poor older clients
@@ -1046,9 +1045,9 @@
 
 static void jabber_vcard_save_mine(JabberStream *js, xmlnode *packet, gpointer data)
 {
-	xmlnode *vcard;
-	char *txt;
-	PurpleStoredImage *img;
+	xmlnode *vcard, *photo, *binval;
+	char *txt, *vcard_hash = NULL;
+	const char *current_hash;
 
 	if((vcard = xmlnode_get_child(packet, "vCard")) ||
 			(vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp")))
@@ -1063,10 +1062,33 @@
 
 	js->vcard_fetched = TRUE;
 
-	if(NULL != (img = purple_buddy_icons_find_account_icon(js->gc->account))) {
-		jabber_set_buddy_icon(js->gc, img);
-		purple_imgstore_unref(img);
+	if (vcard && (photo = xmlnode_get_child(vcard, "PHOTO")) &&
+	             (binval = xmlnode_get_child(photo, "BINVAL"))) {
+		gsize size;
+		char *bintext = xmlnode_get_data(binval);
+		guchar *data = purple_base64_decode(bintext, &size);
+		g_free(bintext);
+
+		if (data) {
+			vcard_hash = jabber_calculate_data_sha1sum(data, size);
+			g_free(data);
+		}
 	}
+
+	current_hash = purple_account_get_string(js->gc->account,
+	                                         "prpl-jabber_icon_checksum", "");
+
+	/* Republish our vcard if the photo is different than the server's */
+	if ((!vcard_hash && current_hash[0] != '\0') ||
+		 (vcard_hash && strcmp(vcard_hash, current_hash))) {
+		PurpleAccount *account = purple_connection_get_account(js->gc);
+		jabber_set_info(js->gc, purple_account_get_user_info(account));
+	} else if (current_hash != '\0') {
+		/* Our photo is in the vcard, so advertise vcard-temp updates */
+		js->avatar_hash = g_strdup(current_hash);
+	}
+
+	g_free(vcard_hash);
 }
 
 void jabber_vcard_fetch_mine(JabberStream *js)