diff libpurple/protocols/jabber/useravatar.c @ 29289:45795fd9c0a9

propagate from branch 'im.pidgin.pidgin' (head df25bed2c1c0d097b7f52fbfae76223d8552f0c3) to branch 'im.pidgin.cpw.attention_ui' (head 772ec7058f552b4a4384c599965f99566d903142)
author Marcus Lundblad <ml@update.uu.se>
date Thu, 07 May 2009 21:38:08 +0000
parents df7505e0d64a
children 77cfaae36918
line wrap: on
line diff
--- a/libpurple/protocols/jabber/useravatar.c	Sat May 02 06:39:51 2009 +0000
+++ b/libpurple/protocols/jabber/useravatar.c	Thu May 07 21:38:08 2009 +0000
@@ -33,9 +33,6 @@
 
 void jabber_avatar_init(void)
 {
-	jabber_pep_register_handler(NS_AVATAR_0_12_METADATA,
-	                            update_buddy_metadata);
-
 	jabber_add_feature(NS_AVATAR_1_1_METADATA,
 	                   jabber_pep_namespace_only_when_pep_enabled_cb);
 	jabber_add_feature(NS_AVATAR_1_1_DATA,
@@ -48,6 +45,43 @@
 static void
 remove_avatar_0_12_nodes(JabberStream *js)
 {
+#if 0
+	/* See note below for why this is #if 0'd */
+
+	/* Publish an empty avatar according to the XEP-0084 v0.12 semantics */
+	xmlnode *publish, *item, *metadata;
+	/* publish the metadata */
+	publish = xmlnode_new("publish");
+	xmlnode_set_attrib(publish, "node", NS_AVATAR_0_12_METADATA);
+
+	item = xmlnode_new_child(publish, "item");
+	xmlnode_set_attrib(item, "id", "stop");
+
+	metadata = xmlnode_new_child(item, "metadata");
+	xmlnode_set_namespace(metadata, NS_AVATAR_0_12_METADATA);
+
+	xmlnode_new_child(metadata, "stop");
+
+	/* publish */
+	jabber_pep_publish(js, publish);
+#endif
+
+	/*
+	 * This causes ejabberd 2.0.0 to kill the connection unceremoniously.
+	 * See https://support.process-one.net/browse/EJAB-623. When adiumx.com
+	 * was upgraded, the issue went away.
+	 *
+	 * I think it makes a lot of sense to not have an avatar at the old
+	 * node instead of having something interpreted as "no avatar". When
+	 * a contact with an older client logs in, in the latter situation,
+	 * there's a race between interpreting the <presence/> vcard-temp:x:update
+	 * avatar (non-empty) and the XEP-0084 v0.12 avatar (empty, so show no
+	 * avatar for the buddy) which leads to unhappy and confused users.
+	 *
+	 * A deluge of frustrating "Read error" bug reports may change my mind
+	 * about this.
+	 * --darkrain42
+	 */
 	jabber_pep_delete_node(js, NS_AVATAR_0_12_METADATA);
 	jabber_pep_delete_node(js, NS_AVATAR_0_12_DATA);
 }
@@ -59,6 +93,7 @@
 	if (!js->pep)
 		return;
 
+	/* Hmmm, not sure if this is worth the traffic, but meh */
 	remove_avatar_0_12_nodes(js);
 
 	if (!img) {
@@ -169,35 +204,29 @@
 }
 
 static void
+do_got_own_avatar_0_12_cb(JabberStream *js, const char *from, xmlnode *items)
+{
+	if (items)
+		/* It wasn't an error (i.e. 'item-not-found') */
+		remove_avatar_0_12_nodes(js);
+}
+
+static void
 do_got_own_avatar_cb(JabberStream *js, const char *from, xmlnode *items)
 {
 	xmlnode *item = NULL, *metadata = NULL, *info = NULL;
 	PurpleAccount *account = purple_connection_get_account(js->gc);
 	const char *server_hash = NULL;
-	const char *ns;
 
-	if ((item = xmlnode_get_child(items, "item")) &&
+	if (items && (item = xmlnode_get_child(items, "item")) &&
 	     (metadata = xmlnode_get_child(item, "metadata")) &&
 	     (info = xmlnode_get_child(metadata, "info"))) {
 		server_hash = xmlnode_get_attrib(info, "id");
 	}
 
-	if (!metadata)
-		return;
-
-	ns = xmlnode_get_namespace(metadata);
-	if (!ns)
+	if (items && !metadata)
 		return;
 
-	/*
-	 * We no longer publish avatars to the older namespace. If there is one
-	 * there, delete it.
-	 */
-	if (g_str_equal(ns, NS_AVATAR_0_12_METADATA) && server_hash) {
-		remove_avatar_0_12_nodes(js);
-		return;
-	}
-
 	/* Publish ours if it's different than the server's */
 	if (!purple_strequal(server_hash, js->initial_avatar_hash)) {
 		PurpleStoredImage *img = purple_buddy_icons_find_account_icon(account);
@@ -210,7 +239,7 @@
 {
 	char *jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
 	jabber_pep_request_item(js, jid, NS_AVATAR_0_12_METADATA, NULL,
-	                        do_got_own_avatar_cb);
+	                        do_got_own_avatar_0_12_cb);
 	jabber_pep_request_item(js, jid, NS_AVATAR_1_1_METADATA, NULL,
 	                        do_got_own_avatar_cb);
 	g_free(jid);
@@ -247,7 +276,7 @@
 do_buddy_avatar_update_data(JabberStream *js, const char *from, xmlnode *items)
 {
 	xmlnode *item, *data;
-	const char *checksum, *ns;
+	const char *checksum;
 	char *b64data;
 	void *img;
 	size_t size;
@@ -262,12 +291,6 @@
 	if(!data)
 		return;
 
-	ns = xmlnode_get_namespace(data);
-	/* Make sure the namespace is one of the two valid possibilities */
-	if (!ns || (!g_str_equal(ns, NS_AVATAR_0_12_DATA) &&
-	            !g_str_equal(ns, NS_AVATAR_1_1_DATA)))
-		return;
-
 	checksum = xmlnode_get_attrib(item,"id");
 	if(!checksum)
 		return;
@@ -290,7 +313,7 @@
 update_buddy_metadata(JabberStream *js, const char *from, xmlnode *items)
 {
 	PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(js->gc), from);
-	const char *checksum, *ns;
+	const char *checksum;
 	xmlnode *item, *metadata;
 	if(!buddy)
 		return;
@@ -306,15 +329,9 @@
 	if(!metadata)
 		return;
 
-	ns = xmlnode_get_namespace(metadata);
-	/* Make sure the namespace is one of the two valid possibilities */
-	if (!ns || (!g_str_equal(ns, NS_AVATAR_0_12_METADATA) &&
-	            !g_str_equal(ns, NS_AVATAR_1_1_METADATA)))
-		return;
-
 	checksum = purple_buddy_icons_get_checksum_for_user(buddy);
 
-	/* check if we have received a stop */
+	/* <stop/> was the pre-v1.1 method of publishing an empty avatar */
 	if(xmlnode_get_child(metadata, "stop")) {
 		purple_buddy_icons_set_for_user(purple_connection_get_account(js->gc), from, NULL, 0, NULL);
 	} else {
@@ -347,10 +364,7 @@
 
 			/* the avatar might either be stored in a pep node, or on a HTTP(S) URL */
 			if(!url) {
-				const char *data_ns;
-				data_ns = (g_str_equal(ns, NS_AVATAR_0_12_METADATA) ?
-				               NS_AVATAR_0_12_DATA : NS_AVATAR_1_1_DATA);
-				jabber_pep_request_item(js, from, data_ns, id,
+				jabber_pep_request_item(js, from, NS_AVATAR_1_1_DATA, id,
 				                        do_buddy_avatar_update_data);
 			} else {
 				PurpleUtilFetchUrlData *url_data;