cpw.darkrain42.xmpp.avatars: 11e989f3: Use a JabberStream variable instead of a...

paul at darkrain42.org paul at darkrain42.org
Sat Feb 14 18:00:42 EST 2009


-----------------------------------------------------------------
Revision: 11e989f3ac36a0f958f031d55245db093923ea76
Ancestor: 3ed150ceb7b010c10dfec35dd0749540a4b0b74b
Author: paul at darkrain42.org
Date: 2009-02-14T18:23:13
Branch: im.pidgin.cpw.darkrain42.xmpp.avatars
URL: http://d.pidgin.im/viewmtn/revision/info/11e989f3ac36a0f958f031d55245db093923ea76

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

ChangeLog: 

Use a JabberStream variable instead of a setting for the initial hash

The hash is only used at login to compare with the PEP avatar(s) and vCard and
is recalculated at each login, so there's no need to store it as a setting.
The variable is eitehr NULL or the hash now, instead of "" or the hash.


-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/buddy.c	f4f3b7cb220e705d73190f732221263bba1cf609
+++ libpurple/protocols/jabber/buddy.c	4bd8b8a67d87736c4afd15a54234b79402b7d683
@@ -496,11 +496,17 @@ void jabber_set_buddy_icon(PurpleConnect
 
 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img)
 {
+	PurpleAccount *account = purple_connection_get_account(gc);
 	jabber_avatar_set(gc->proto_data, img, NULL);
 	/* vCard avatars do not have an image type requirement so update our
 	 * vCard avatar regardless of image type for those poor older clients
 	 */
-	jabber_set_info(gc, purple_account_get_user_info(gc->account));
+	jabber_set_info(gc, purple_account_get_user_info(account));
+
+	/* TODO: Fake image to ourselves, since a number of servers do not echo
+	 * back our presence to us. To do this without uselessly copying the data
+	 * of the image, we need purple_buddy_icons_set_for_user_image (i.e. takes
+	 * an existing icon/stored image). */
 }
 
 /*
@@ -1044,7 +1050,6 @@ static void jabber_vcard_save_mine(Jabbe
 {
 	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")))
@@ -1072,17 +1077,14 @@ static void jabber_vcard_save_mine(Jabbe
 		}
 	}
 
-	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))) {
+	if ((!vcard_hash && js->initial_avatar_hash) ||
+		 (vcard_hash && (!js->initial_avatar_hash || strcmp(vcard_hash, js->initial_avatar_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') {
+	} else if (js->initial_avatar_hash) {
 		/* Our photo is in the vcard, so advertise vcard-temp updates */
-		js->avatar_hash = g_strdup(current_hash);
+		js->avatar_hash = g_strdup(js->initial_avatar_hash);
 	}
 
 	g_free(vcard_hash);
============================================================
--- libpurple/protocols/jabber/jabber.c	73d0dcc29167e7df98fb448c5b4a57029d776e0e
+++ libpurple/protocols/jabber/jabber.c	e1cadc787637090ec1b8ef67e3fd35838eec6158
@@ -739,16 +739,15 @@ jabber_login(PurpleAccount *account)
 		return;
 	}
 
-	/* This account setting is used to determine if we should re-sync our avatar to the
-	 * server at login. */
+	/*
+	 * Calculate the avatar hash for our current image so we know (when we
+	 * fetch our vCard and PEP avatar) if we should send our avatar to the
+	 * server.
+	 */
 	if ((image = purple_buddy_icons_find_account_icon(account))) {
-		char *checksum = jabber_calculate_data_sha1sum(purple_imgstore_get_data(image),
+		js->initial_avatar_hash = jabber_calculate_data_sha1sum(purple_imgstore_get_data(image),
 					purple_imgstore_get_size(image));
-		purple_account_set_string(account, "prpl-jabber_icon_checksum", checksum);
-		g_free(checksum);
 		purple_imgstore_unref(image);
-	} else {
-		purple_account_set_string(account, "prpl-jabber_icon_checksum", "");
 	}
 
 	if((my_jb = jabber_buddy_find(js, purple_account_get_username(account), TRUE)))
@@ -1382,6 +1381,7 @@ void jabber_close(PurpleConnection *gc)
 	g_free(js->stream_id);
 	if(js->user)
 		jabber_id_free(js->user);
+	g_free(js->initial_avatar_hash);
 	g_free(js->avatar_hash);
 
 	purple_circ_buffer_destroy(js->write_buffer);
============================================================
--- libpurple/protocols/jabber/jabber.h	df574ab651cdebe290c7ce7f0a329167c562919a
+++ libpurple/protocols/jabber/jabber.h	7263c4c532c5fe97bc939975313d29464d73b0fd
@@ -161,6 +161,7 @@ struct _JabberStream
 
 	gboolean registration;
 
+	char *initial_avatar_hash;
 	char *avatar_hash;
 	GSList *pending_avatar_requests;
 
============================================================
--- libpurple/protocols/jabber/useravatar.c	0e445024d8cadc3a2acd240ef1df3f4a0b477e67
+++ libpurple/protocols/jabber/useravatar.c	3bd7da1416cacc1f712d7c44315fffff8060635d
@@ -226,7 +226,6 @@ do_got_own_avatar_cb(JabberStream *js, c
 {
 	xmlnode *item = NULL, *metadata = NULL, *info = NULL;
 	PurpleAccount *account = purple_connection_get_account(js->gc);
-	const char *current_hash = purple_account_get_string(account, "prpl-jabber_icon_checksum", "");
 	const char *server_hash = NULL;
 	const char *ns;
 
@@ -244,8 +243,8 @@ do_got_own_avatar_cb(JabberStream *js, c
 		return;
 
 	/* Publish ours if it's different than the server's */
-	if ((!server_hash && current_hash[0] != '\0') ||
-		 (server_hash && strcmp(server_hash, current_hash))) {
+	if ((!server_hash && js->initial_avatar_hash) ||
+		 (server_hash && (!js->initial_avatar_hash || strcmp(server_hash, js->initial_avatar_hash)))) {
 		PurpleStoredImage *img = purple_buddy_icons_find_account_icon(account);
 		jabber_avatar_set(js, img, ns);
 		purple_imgstore_unref(img);


More information about the Commits mailing list