cpw.darkrain42.xmpp.avatars: 640f7901: Publish only 'new' xmlns of avatars and ...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Tue Apr 28 17:21:52 EDT 2009


-----------------------------------------------------------------
Revision: 640f790180ffe11e0cca24d096f4cc182f0e0d53
Ancestor: d33482026d283bfaa087f8cd1580bff079836d64
Author: darkrain42 at pidgin.im
Date: 2009-04-27T05:49:32
Branch: im.pidgin.cpw.darkrain42.xmpp.avatars
URL: http://d.pidgin.im/viewmtn/revision/info/640f790180ffe11e0cca24d096f4cc182f0e0d53

Modified 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

ChangeLog: 

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.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/buddy.c	2713111fa1e33ac57c1a9f9cbe70fb5e1efbd7cb
+++ libpurple/protocols/jabber/buddy.c	c85663936d90791748902caf5fac4e8663fd024a
@@ -485,10 +485,10 @@ 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
-	 */
+
+	/* 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
============================================================
--- libpurple/protocols/jabber/pep.c	2537357d567ca541c9669a692c7487dd5bbdc012
+++ libpurple/protocols/jabber/pep.c	7b9ecacdebc791d858fbc853cd4f0dde37760ffa
@@ -112,6 +112,25 @@ void jabber_handle_event(JabberMessage *
 	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;
============================================================
--- libpurple/protocols/jabber/pep.h	90be9b47f6ea6d8f84b02d7d9b660f8eb254d411
+++ libpurple/protocols/jabber/pep.h	6888fef740f446637bcf1860307ea0eed5aa10b7
@@ -74,6 +74,11 @@ void jabber_handle_event(JabberMessage *
 
 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)
  *
============================================================
--- libpurple/protocols/jabber/useravatar.c	48037cac4adf61e19e1b54e48009c598226c373f
+++ libpurple/protocols/jabber/useravatar.c	c9c88615d2128a7aff0f5675171807a0145d3bc5
@@ -33,10 +33,6 @@ void jabber_avatar_init(void)
 
 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 @@ void jabber_avatar_init(void)
 	                            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;
 
-	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);
+	remove_avatar_0_12_nodes(js);
 
-			item = xmlnode_new_child(publish, "item");
-			metadata = xmlnode_new_child(item, "metadata");
-			xmlnode_set_namespace(metadata, NS_AVATAR_0_12_METADATA);
+	if (!img) {
+		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,36 +119,19 @@ void jabber_avatar_set(JabberStream *js,
 			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);
+			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);
+			item = xmlnode_new_child(publish, "item");
+			xmlnode_set_attrib(item, "id", hash);
 
-				data = xmlnode_new_child(item, "data");
-				xmlnode_set_namespace(data, NS_AVATAR_0_12_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);
 
-			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);
-
-				xmlnode_insert_data(data, base64avatar, -1);
-				/* publish the avatar itself */
-				jabber_pep_publish(js, publish);
-			}
-
 			g_free(base64avatar);
 
 			lengthstring = g_strdup_printf("%" G_GSIZE_FORMAT,
@@ -169,48 +139,25 @@ void jabber_avatar_set(JabberStream *js,
 			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);
+			/* publish the metadata */
+			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);
+			item = xmlnode_new_child(publish, "item");
+			xmlnode_set_attrib(item, "id", hash);
 
-				metadata = xmlnode_new_child(item, "metadata");
-				xmlnode_set_namespace(metadata, NS_AVATAR_0_12_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);
-				/* publish the metadata */
-				jabber_pep_publish(js, publish);
-			}
+			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);
 
-			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);
+			jabber_pep_publish(js, publish);
 
-				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);
-
-				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);
-			}
-
 			g_free(lengthstring);
 			g_free(widthstring);
 			g_free(heightstring);
@@ -242,10 +189,19 @@ do_got_own_avatar_cb(JabberStream *js, c
 	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);
 	}
 }
============================================================
--- libpurple/protocols/jabber/useravatar.h	cf2f7babbbe5a53b7428a7e1c53624ba4e4aa883
+++ libpurple/protocols/jabber/useravatar.h	d1de2ec91c48657c3ee053497342bf12d4853c24
@@ -36,11 +36,7 @@ void jabber_avatar_init(void);
 #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);
 


More information about the Commits mailing list