changeset 25937:a4cba207068f

merge of '1f6758f8bdba42d2eeca66535d11e7de12d9e715' and '7960f1ad9847ca6bd1918ccc6407afbcdc6cfcb8'
author Paul Aurich <paul@darkrain42.org>
date Sun, 08 Feb 2009 07:07:25 +0000
parents d7c195489af3 (current diff) 89c4edb5e545 (diff)
children 45c33d60c547
files libpurple/protocols/jabber/iq.c libpurple/protocols/jabber/iq.h
diffstat 2 files changed, 30 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/iq.c	Sun Feb 08 07:07:23 2009 +0000
+++ b/libpurple/protocols/jabber/iq.c	Sun Feb 08 07:07:25 2009 +0000
@@ -282,7 +282,6 @@
 	const char *xmlns;
 	const char *iq_type, *id, *from;
 	JabberIqType type = JABBER_IQ_NONE;
-	JabberIqHandler *jih;
 
 	/*
 	 * child will be either the first tag child or NULL if there is no child.
@@ -357,7 +356,11 @@
 
 	/* Apparently not, so lets see if we have a pre-defined handler */
 	if(child && (xmlns = xmlnode_get_namespace(child))) {
-		if((jih = g_hash_table_lookup(iq_handlers, xmlns))) {
+		char *key = g_strdup_printf("%s %s", child->name, xmlns);
+		JabberIqHandler *jih = g_hash_table_lookup(iq_handlers, key);
+		g_free(key);
+
+		if(jih) {
 			jih(js, from, type, id, child);
 			return;
 		}
@@ -387,29 +390,36 @@
 	}
 }
 
-void jabber_iq_register_handler(const char *xmlns, JabberIqHandler *handlerfunc)
+void jabber_iq_register_handler(const char *node, const char *xmlns, JabberIqHandler *handlerfunc)
 {
-	g_hash_table_replace(iq_handlers, g_strdup(xmlns), handlerfunc);
+	/*
+	 * This is valid because nodes nor namespaces cannot have spaces in them
+	 * (see http://www.w3.org/TR/2006/REC-xml-20060816/ and
+	 * http://www.w3.org/TR/REC-xml-names/)
+	 */
+	char *key = g_strdup_printf("%s %s", node, xmlns);
+	g_hash_table_replace(iq_handlers, key, handlerfunc);
 }
 
 void jabber_iq_init(void)
 {
 	iq_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 
-	jabber_iq_register_handler("google:mail:notify", jabber_gmail_poke);
-	jabber_iq_register_handler("http://jabber.org/protocol/bytestreams", jabber_bytestreams_parse);
-	jabber_iq_register_handler("http://jabber.org/protocol/disco#info", jabber_disco_info_parse);
-	jabber_iq_register_handler("http://jabber.org/protocol/disco#items", jabber_disco_items_parse);
-	jabber_iq_register_handler("http://jabber.org/protocol/si", jabber_si_parse);
-	jabber_iq_register_handler("jabber:iq:last", jabber_iq_last_parse);
-	jabber_iq_register_handler("jabber:iq:oob", jabber_oob_parse);
-	jabber_iq_register_handler("jabber:iq:register", jabber_register_parse);
-	jabber_iq_register_handler("jabber:iq:roster", jabber_roster_parse);
-	jabber_iq_register_handler("jabber:iq:time", jabber_iq_time_parse);
-	jabber_iq_register_handler("jabber:iq:version", jabber_iq_version_parse);
-	jabber_iq_register_handler(XEP_0231_NAMESPACE, jabber_data_parse);
-	jabber_iq_register_handler("urn:xmpp:ping", jabber_ping_parse);
-	jabber_iq_register_handler("urn:xmpp:time", jabber_iq_time_parse);
+	jabber_iq_register_handler("mailbox", "google:mail:notify", jabber_gmail_poke);
+	jabber_iq_register_handler("new-mail", "google:mail:notify", jabber_gmail_poke);
+	jabber_iq_register_handler("query", "http://jabber.org/protocol/bytestreams", jabber_bytestreams_parse);
+	jabber_iq_register_handler("query", "http://jabber.org/protocol/disco#info", jabber_disco_info_parse);
+	jabber_iq_register_handler("query", "http://jabber.org/protocol/disco#items", jabber_disco_items_parse);
+	jabber_iq_register_handler("si", "http://jabber.org/protocol/si", jabber_si_parse);
+	jabber_iq_register_handler("query", "jabber:iq:last", jabber_iq_last_parse);
+	jabber_iq_register_handler("query", "jabber:iq:oob", jabber_oob_parse);
+	jabber_iq_register_handler("query", "jabber:iq:register", jabber_register_parse);
+	jabber_iq_register_handler("query", "jabber:iq:roster", jabber_roster_parse);
+	jabber_iq_register_handler("query", "jabber:iq:time", jabber_iq_time_parse);
+	jabber_iq_register_handler("query", "jabber:iq:version", jabber_iq_version_parse);
+	jabber_iq_register_handler("data", XEP_0231_NAMESPACE, jabber_data_parse);
+	jabber_iq_register_handler("ping", "urn:xmpp:ping", jabber_ping_parse);
+	jabber_iq_register_handler("time", "urn:xmpp:time", jabber_iq_time_parse);
 }
 
 void jabber_iq_uninit(void)
--- a/libpurple/protocols/jabber/iq.h	Sun Feb 08 07:07:23 2009 +0000
+++ b/libpurple/protocols/jabber/iq.h	Sun Feb 08 07:07:25 2009 +0000
@@ -67,6 +67,7 @@
 void jabber_iq_init(void);
 void jabber_iq_uninit(void);
 
-void jabber_iq_register_handler(const char *xmlns, JabberIqHandler *func);
+void jabber_iq_register_handler(const char *node, const char *xmlns,
+                                JabberIqHandler *func);
 
 #endif /* _PURPLE_JABBER_IQ_H_ */