adium.1-4: 41ecbfc1: Strip prefixes of xhtml messages on XMPP...

thijsalkemade at gmail.com thijsalkemade at gmail.com
Sat Aug 20 15:25:54 EDT 2011


----------------------------------------------------------------------
Revision: 41ecbfc19cc8b1a53505ed08eca6ed9944d699de
Parent:   c03d69f8e866e1e33d6cb47455b2c5ff0c9e1e7f
Author:   thijsalkemade at gmail.com
Date:     08/20/11 15:06:34
Branch:   im.pidgin.adium.1-4
URL: http://d.pidgin.im/viewmtn/revision/info/41ecbfc19cc8b1a53505ed08eca6ed9944d699de

Changelog: 

Strip prefixes of xhtml messages on XMPP if they refer to
"http://jabber.org/protocol/xhtml-im" or "http://www.w3.org/1999/xhtml", so
Adium doesn't get confused by xhtml messages on GTalk.

This approach isn't valid in all possible cases, but it's the best approach
with the way xmlnodes work currently.

Fixes #14529

Changes against parent c03d69f8e866e1e33d6cb47455b2c5ff0c9e1e7f

  patched  libpurple/protocols/jabber/message.c

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/message.c	56cb48ae5198a3d7b0180dd2a2facf6999ed83c5
+++ libpurple/protocols/jabber/message.c	1da24e297f1d3e342fa16f4bc317ab526de3b688
@@ -497,6 +497,36 @@ jabber_message_request_data_cb(JabberDat
 	g_free(alt);
 }
 
+void
+jabber_message_xml_strip_prefixes(xmlnode *xhtml)
+{
+	xmlnode *child;
+	char *prefix = xmlnode_get_prefix(xhtml);
+	char *namespace = NULL;
+	xmlnode *current_node = xhtml;
+
+	if (prefix) {
+		/* TODO: (2.11/3.0) Add a helper function to resolve namespace prefixes. */
+		while (!namespace && current_node) {
+			if (current_node->namespace_map) {
+				namespace = (const char *)g_hash_table_lookup(current_node->namespace_map, prefix);
+			}
+
+			current_node = current_node->parent;
+		}
+
+		if (namespace && (!strcmp(namespace, NS_XHTML_IM) || !strcmp(namespace, NS_XHTML))) {
+			xmlnode_set_prefix(xhtml, NULL);
+		}
+	}
+
+	for(child = xhtml->child; child; child = child->next) {
+		if (child->type == XMLNODE_TYPE_TAG) {
+			jabber_message_xml_strip_prefixes(child);
+		}
+	}
+}
+
 void jabber_message_parse(JabberStream *js, xmlnode *packet)
 {
 	JabberMessage *jm;
@@ -638,6 +668,11 @@ void jabber_message_parse(JabberStream *
 					jabber_message_add_remote_smileys(js, to, packet);
 				}
 
+				/* Google started adding xml namespace prefixes inside xhtml messages.
+				 * Strip these to not confuse UIs that are not very smart with xhtml.
+				 */
+				jabber_message_xml_strip_prefixes(child);
+
 				/* reformat xhtml so that img tags with a "cid:" src gets
 				  translated to the bare text of the emoticon (the "alt" attrib) */
 				/* this is done also when custom smiley retrieval is turned off,


More information about the Commits mailing list