changeset 26709:80437c891f92

Publish only 'new' xmlns of avatars and delete old. Instead of publishing our avatar to both PEP nodes, publish only to the new and delete anything at the old. We still support receiving both/either. Backward compatibility is achieved through vcard-temp:x:update.
author Paul Aurich <paul@darkrain42.org>
date Mon, 27 Apr 2009 05:49:32 +0000
parents ca421152b5d4
children aa28018bfa17
files libpurple/protocols/jabber/buddy.c libpurple/protocols/jabber/pep.c libpurple/protocols/jabber/pep.h libpurple/protocols/jabber/useravatar.c libpurple/protocols/jabber/useravatar.h
diffstat 5 files changed, 79 insertions(+), 103 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/buddy.c	Mon Apr 27 02:38:52 2009 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Mon Apr 27 05:49:32 2009 +0000
@@ -485,10 +485,10 @@
 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
-	 */
+
+	/* Publish the avatar as specified in XEP-0084 */
+	jabber_avatar_set(gc->proto_data, img);
+	/* Set the image in our vCard */
 	jabber_set_info(gc, purple_account_get_user_info(account));
 
 	/* TODO: Fake image to ourselves, since a number of servers do not echo
--- a/libpurple/protocols/jabber/pep.c	Mon Apr 27 02:38:52 2009 +0000
+++ b/libpurple/protocols/jabber/pep.c	Mon Apr 27 05:49:32 2009 +0000
@@ -112,6 +112,25 @@
 	g_free(jid);
 }
 
+void jabber_pep_delete_node(JabberStream *js, const gchar *node)
+{
+	JabberIq *iq;
+	xmlnode *pubsub, *del;
+
+	g_return_if_fail(node != NULL);
+	g_return_if_fail(js->pep);
+
+	iq = jabber_iq_new(js, JABBER_IQ_SET);
+
+	pubsub = xmlnode_new_child(iq->node, "pubsub");
+	xmlnode_set_namespace(pubsub, "http://jabber.org/protocol/pubsub#owner");
+
+	del = xmlnode_new_child(pubsub, "delete");
+	xmlnode_set_attrib(del, "node", node);
+
+	jabber_iq_send(iq);
+}
+
 void jabber_pep_publish(JabberStream *js, xmlnode *publish) {
 	JabberIq *iq;
 	xmlnode *pubsub;
--- a/libpurple/protocols/jabber/pep.h	Mon Apr 27 02:38:52 2009 +0000
+++ b/libpurple/protocols/jabber/pep.h	Mon Apr 27 05:49:32 2009 +0000
@@ -74,6 +74,11 @@
 
 void jabber_handle_event(JabberMessage *jm);
 
+/**
+ * Delete the specified PEP node.
+ */
+void jabber_pep_delete_node(JabberStream *js, const gchar *node);
+
 /*
  * Publishes PEP item(s)
  *
--- a/libpurple/protocols/jabber/useravatar.c	Mon Apr 27 02:38:52 2009 +0000
+++ b/libpurple/protocols/jabber/useravatar.c	Mon Apr 27 05:49:32 2009 +0000
@@ -33,10 +33,6 @@
 
 void jabber_avatar_init(void)
 {
-	jabber_add_feature("avatarmeta", NS_AVATAR_0_12_METADATA,
-	                   jabber_pep_namespace_only_when_pep_enabled_cb);
-	jabber_add_feature("avatardata", NS_AVATAR_0_12_DATA,
-	                   jabber_pep_namespace_only_when_pep_enabled_cb);
 	jabber_pep_register_handler("avatar", NS_AVATAR_0_12_METADATA,
 	                            update_buddy_metadata);
 
@@ -49,41 +45,32 @@
 	                            update_buddy_metadata);
 }
 
-void jabber_avatar_set(JabberStream *js, PurpleStoredImage *img, const char *ns)
+static void
+remove_avatar_0_12_nodes(JabberStream *js)
+{
+	jabber_pep_delete_node(js, NS_AVATAR_0_12_METADATA);
+	jabber_pep_delete_node(js, NS_AVATAR_0_12_DATA);
+}
+
+void jabber_avatar_set(JabberStream *js, PurpleStoredImage *img)
 {
 	xmlnode *publish, *metadata, *item;
 
 	if (!js->pep)
 		return;
 
+	remove_avatar_0_12_nodes(js);
+
 	if (!img) {
-		if (ns == NULL || g_str_equal(ns, NS_AVATAR_0_12_METADATA)) {
-			/* remove the metadata */
-			publish = xmlnode_new("publish");
-			xmlnode_set_attrib(publish, "node", NS_AVATAR_0_12_METADATA);
-
-			item = xmlnode_new_child(publish, "item");
-			metadata = xmlnode_new_child(item, "metadata");
-			xmlnode_set_namespace(metadata, NS_AVATAR_0_12_METADATA);
+		publish = xmlnode_new("publish");
+		xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_METADATA);
 
-			xmlnode_new_child(metadata, "stop");
-			/* publish */
-			jabber_pep_publish(js, publish);
-		}
+		item = xmlnode_new_child(publish, "item");
+		metadata = xmlnode_new_child(item, "metadata");
+		xmlnode_set_namespace(metadata, NS_AVATAR_1_1_METADATA);
 
-		if (ns == NULL || g_str_equal(ns, NS_AVATAR_1_1_METADATA)) {
-			/* Now for the XEP-0084 v1.1 namespace, where we publish an empty
-			 * metadata node instead of a <stop/> element */
-			publish = xmlnode_new("publish");
-			xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_METADATA);
-
-			item = xmlnode_new_child(publish, "item");
-			metadata = xmlnode_new_child(item, "metadata");
-			xmlnode_set_namespace(metadata, NS_AVATAR_1_1_METADATA);
-
-			/* publish */
-			jabber_pep_publish(js, publish);
-		}
+		/* publish */
+		jabber_pep_publish(js, publish);
 	} else {
 		/*
 		 * TODO: This is pretty gross.  The Jabber PRPL really shouldn't
@@ -132,35 +119,18 @@
 			char *base64avatar = purple_base64_encode(purple_imgstore_get_data(img),
 			                                          purple_imgstore_get_size(img));
 
-			if (ns == NULL || g_str_equal(ns, NS_AVATAR_0_12_METADATA)) {
-				publish = xmlnode_new("publish");
-				xmlnode_set_attrib(publish, "node", NS_AVATAR_0_12_DATA);
-
-				item = xmlnode_new_child(publish, "item");
-				xmlnode_set_attrib(item, "id", hash);
+			publish = xmlnode_new("publish");
+			xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_DATA);
 
-				data = xmlnode_new_child(item, "data");
-				xmlnode_set_namespace(data, NS_AVATAR_0_12_DATA);
-
-				xmlnode_insert_data(data, base64avatar, -1);
-				/* publish the avatar itself */
-				jabber_pep_publish(js, publish);
-			}
+			item = xmlnode_new_child(publish, "item");
+			xmlnode_set_attrib(item, "id", hash);
 
-			if (ns == NULL || g_str_equal(ns, NS_AVATAR_1_1_METADATA)) {
-				publish = xmlnode_new("publish");
-				xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_DATA);
-
-				item = xmlnode_new_child(publish, "item");
-				xmlnode_set_attrib(item, "id", hash);
+			data = xmlnode_new_child(item, "data");
+			xmlnode_set_namespace(data, NS_AVATAR_1_1_DATA);
 
-				data = xmlnode_new_child(item, "data");
-				xmlnode_set_namespace(data, NS_AVATAR_1_1_DATA);
-
-				xmlnode_insert_data(data, base64avatar, -1);
-				/* publish the avatar itself */
-				jabber_pep_publish(js, publish);
-			}
+			xmlnode_insert_data(data, base64avatar, -1);
+			/* publish the avatar itself */
+			jabber_pep_publish(js, publish);
 
 			g_free(base64avatar);
 
@@ -169,47 +139,24 @@
 			widthstring = g_strdup_printf("%u", width);
 			heightstring = g_strdup_printf("%u", height);
 
-			if (ns == NULL || g_str_equal(ns, NS_AVATAR_0_12_METADATA)) {
-				/* next step: publish the metadata to the old namespace */
-				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", hash);
+			/* publish the metadata */
+			publish = xmlnode_new("publish");
+			xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_METADATA);
 
-				metadata = xmlnode_new_child(item, "metadata");
-				xmlnode_set_namespace(metadata, NS_AVATAR_0_12_METADATA);
-
-				info = xmlnode_new_child(metadata, "info");
-				xmlnode_set_attrib(info, "id", hash);
-				xmlnode_set_attrib(info, "type", "image/png");
-				xmlnode_set_attrib(info, "bytes", lengthstring);
-				xmlnode_set_attrib(info, "width", widthstring);
-				xmlnode_set_attrib(info, "height", heightstring);
-				/* publish the metadata */
-				jabber_pep_publish(js, publish);
-			}
+			item = xmlnode_new_child(publish, "item");
+			xmlnode_set_attrib(item, "id", hash);
 
-			if (ns == NULL || g_str_equal(ns, NS_AVATAR_1_1_METADATA)) {
-				/* publish the metadata to the new namespace */
-				publish = xmlnode_new("publish");
-				xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_METADATA);
-
-				item = xmlnode_new_child(publish, "item");
-				xmlnode_set_attrib(item, "id", hash);
+			metadata = xmlnode_new_child(item, "metadata");
+			xmlnode_set_namespace(metadata, NS_AVATAR_1_1_METADATA);
 
-				metadata = xmlnode_new_child(item, "metadata");
-				xmlnode_set_namespace(metadata, NS_AVATAR_1_1_METADATA);
+			info = xmlnode_new_child(metadata, "info");
+			xmlnode_set_attrib(info, "id", hash);
+			xmlnode_set_attrib(info, "type", "image/png");
+			xmlnode_set_attrib(info, "bytes", lengthstring);
+			xmlnode_set_attrib(info, "width", widthstring);
+			xmlnode_set_attrib(info, "height", heightstring);
 
-				info = xmlnode_new_child(metadata, "info");
-				xmlnode_set_attrib(info, "id", hash);
-				xmlnode_set_attrib(info, "type", "image/png");
-				xmlnode_set_attrib(info, "bytes", lengthstring);
-				xmlnode_set_attrib(info, "width", widthstring);
-				xmlnode_set_attrib(info, "height", heightstring);
-
-				jabber_pep_publish(js, publish);
-			}
+			jabber_pep_publish(js, publish);
 
 			g_free(lengthstring);
 			g_free(widthstring);
@@ -242,10 +189,19 @@
 	if (!ns)
 		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);
-		jabber_avatar_set(js, img, ns);
+		jabber_avatar_set(js, img);
 		purple_imgstore_unref(img);
 	}
 }
--- a/libpurple/protocols/jabber/useravatar.h	Mon Apr 27 02:38:52 2009 +0000
+++ b/libpurple/protocols/jabber/useravatar.h	Mon Apr 27 05:49:32 2009 +0000
@@ -36,11 +36,7 @@
 #define NS_AVATAR_1_1_METADATA  "urn:xmpp:avatar:metadata"
 
 void jabber_avatar_init(void);
-/**
- * @param ns The metadata namespace for which to set the avatar or NULL to set the
- * avatar for both namespaces.
- */
-void jabber_avatar_set(JabberStream *js, PurpleStoredImage *img, const char *ns);
+void jabber_avatar_set(JabberStream *js, PurpleStoredImage *img);
 
 void jabber_avatar_fetch_mine(JabberStream *js);