pidgin: f02baf42: jabber: Correctly handle the unsetting c...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Tue May 3 01:20:37 EDT 2011


----------------------------------------------------------------------
Revision: f02baf428501d0fb764628538fa150c7111e789f
Parent:   e94114863f0a88734486a256f21a13697c6711a6
Author:   matthew at bells23.org.uk
Date:     05/03/11 01:02:00
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/f02baf428501d0fb764628538fa150c7111e789f

Changelog: 

jabber: Correctly handle the unsetting case for a contact's vCard avatar.

Patch from Matthew (mentor) W.S. Bell.  Closes #13370

Changes against parent e94114863f0a88734486a256f21a13697c6711a6

  patched  COPYRIGHT
  patched  ChangeLog
  patched  libpurple/protocols/jabber/presence.c

-------------- next part --------------
============================================================
--- ChangeLog	262ea1345dfe09b2f7e7a3f74f061e537aa0911d
+++ ChangeLog	740aec16ff21f68cc842edf49161bf2213ba4dfe
@@ -86,6 +86,8 @@ version 2.8.0 (??/??/????):
 	XMPP:
 	* Remember the previously entered user directory when searching.
 	  (Keith Moyer) (#12451)
+	* Correctly handle a buddy's unsetting his/her vCard-based avatar.
+	  (Matthew W.S. Bell) (#13370)
 
 	Plugins:
 	* The Voice/Video Settings plugin now includes the ability to test
============================================================
--- libpurple/protocols/jabber/presence.c	9e9a6b1ef69731d0e6bcbaee086d6b0551a0764f
+++ libpurple/protocols/jabber/presence.c	8a283ca07bac62d7e2f33fba244785f734deb677
@@ -450,21 +450,23 @@ jabber_vcard_parse_avatar(JabberStream *
 			g_free(nickname);
 		}
 
-		if ((photo = xmlnode_get_child(vcard, "PHOTO")) &&
-				(binval = xmlnode_get_child(photo, "BINVAL")) &&
-				(text = xmlnode_get_data(binval))) {
-			guchar *data;
-			gsize size;
+		if ((photo = xmlnode_get_child(vcard, "PHOTO"))) {
+			guchar *data = NULL;
+			gchar *hash = NULL;
+			gsize size = 0;
 
-			data = purple_base64_decode(text, &size);
-			if (data) {
-				gchar *hash = jabber_calculate_data_hash(data, size, "sha1");
-				purple_buddy_icons_set_for_user(js->gc->account, from, data,
-				                                size, hash);
-				g_free(hash);
+			if ((binval = xmlnode_get_child(photo, "BINVAL")) &&
+					(text = xmlnode_get_data(binval))) {
+				data = purple_base64_decode(text, &size);
+				g_free(text);
+
+				if (data)
+					hash = jabber_calculate_data_hash(data, size, "sha1");
 			}
 
-			g_free(text);
+			purple_buddy_icons_set_for_user(js->gc->account, from, data, size, hash);
+
+			g_free(hash);
 		}
 	}
 }
@@ -840,20 +842,22 @@ handle_presence_contact(JabberStream *js
 		}
 	}
 
-	if(b && presence->vcard_avatar_hash) {
-		const char *avatar_hash2 = purple_buddy_icons_get_checksum_for_user(b);
-		if(!avatar_hash2 || strcmp(presence->vcard_avatar_hash, avatar_hash2)) {
-			JabberIq *iq;
-			xmlnode *vcard;
-
+	if (b && presence->vcard_avatar_hash) {
+		const char *ah = presence->vcard_avatar_hash[0] != '\0' ?
+				presence->vcard_avatar_hash : NULL;
+		const char *ah2 = purple_buddy_icons_get_checksum_for_user(b);
+		if (!purple_strequal(ah, ah2)) {
 			/* XXX this is a crappy way of trying to prevent
 			 * someone from spamming us with presence packets
 			 * and causing us to DoS ourselves...what we really
 			 * need is a queue system that can throttle itself,
 			 * but i'm too tired to write that right now */
 			if(!g_slist_find(js->pending_avatar_requests, presence->jb)) {
+				JabberIq *iq;
+				xmlnode *vcard;
 
-				js->pending_avatar_requests = g_slist_prepend(js->pending_avatar_requests, presence->jb);
+				js->pending_avatar_requests =
+					g_slist_prepend(js->pending_avatar_requests, presence->jb);
 
 				iq = jabber_iq_new(js, JABBER_IQ_GET);
 				xmlnode_set_attrib(iq->node, "to", buddy_name);
@@ -1206,9 +1210,13 @@ parse_vcard_avatar(JabberStream *js, Jab
 parse_vcard_avatar(JabberStream *js, JabberPresence *presence, xmlnode *x)
 {
 	xmlnode *photo = xmlnode_get_child(x, "photo");
+	char *hash_tmp;	
+
 	if (photo) {
 		g_free(presence->vcard_avatar_hash);
-		presence->vcard_avatar_hash = xmlnode_get_data(photo);
+		hash_tmp = xmlnode_get_data(photo);
+		presence->vcard_avatar_hash = 
+			hash_tmp ? hash_tmp : g_strdup("");
 	}
 }
 
============================================================
--- COPYRIGHT	477b68d5c528b803176dca9957d8c5754042b195
+++ COPYRIGHT	08d916b42af25ad73a6aabcff2c6c8c4a57e9999
@@ -48,6 +48,7 @@ Dave Bell
 Stefan Becker
 Carlos Bederian
 Dave Bell
+Matthew W.S. Bell
 Igor Belyi
 David Benjamin
 Brian Bernas


More information about the Commits mailing list