verse.client: New stanza dispatcher to fire events based on the name (and in the case of iq, xmlns) of the stanza

Wed, 09 Dec 2009 20:55:34 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 09 Dec 2009 20:55:34 +0000
changeset 28
afe9e6d6c87a
parent 27
a4a6a33a34c1
child 29
0d275519eff4

verse.client: New stanza dispatcher to fire events based on the name (and in the case of iq, xmlns) of the stanza

client.lua file | annotate | diff | comparison | revisions
--- a/client.lua	Wed Dec 09 13:55:58 2009 +0000
+++ b/client.lua	Wed Dec 09 20:55:34 2009 +0000
@@ -33,6 +33,24 @@
 	elseif stanza.attr.xmlns then
 		return stream:event("stream/"..stanza.attr.xmlns, stanza);
 	end
+	
+	stream:hook("stanza", function (stanza)
+		if stanza.attr.xmlns == nil or stanza.attr.xmlns == "jabber:client" then
+			if stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then
+				local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns;
+				if xmlns then
+					ret = stream:event("iq/"..xmlns, stanza);
+					if not ret then
+						ret = stream:event("iq", stanza);
+					end
+				end
+			else
+				ret = stream:event(stanza.name, stanza);
+			end
+		end
+		return ret;
+	end, -1);
+
 	return stream:event("stanza", stanza);
 end
 

mercurial