From 22ee83cf0c7f03e1d4cba8c564446a782c023708 Mon Sep 17 00:00:00 2001
From: Waqas Hussain <waqas20@gmail.com>
Date: Sat, 20 Nov 2010 02:28:40 +0500
Subject: util.xmppstream: Preserve the stream content namespace on descendents
 of elements which are in another namespace.

---
 util/xmppstream.lua | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

(limited to 'util')

diff --git a/util/xmppstream.lua b/util/xmppstream.lua
index 2f232fd8..0a6d554b 100644
--- a/util/xmppstream.lua
+++ b/util/xmppstream.lua
@@ -48,6 +48,7 @@ function new_sax_handlers(session, stream_callbacks)
 	local stream_default_ns = stream_callbacks.default_ns;
 	
 	local chardata, stanza = {};
+	local non_streamns_depth = 0;
 	function xml_handlers:StartElement(tagname, attr)
 		if stanza and #chardata > 0 then
 			-- We have some character data in the buffer
@@ -59,8 +60,9 @@ function new_sax_handlers(session, stream_callbacks)
 			curr_ns, name = "", curr_ns;
 		end
 
-		if curr_ns ~= stream_default_ns then
+		if curr_ns ~= stream_default_ns or non_streamns_depth > 0 then
 			attr.xmlns = curr_ns;
+			non_streamns_depth = non_streamns_depth + 1;
 		end
 		
 		-- FIXME !!!!!
@@ -80,6 +82,7 @@ function new_sax_handlers(session, stream_callbacks)
 		if not stanza then --if we are not currently inside a stanza
 			if session.notopen then
 				if tagname == stream_tag then
+					non_streamns_depth = 0;
 					if cb_streamopened then
 						cb_streamopened(session, attr);
 					end
@@ -104,6 +107,9 @@ function new_sax_handlers(session, stream_callbacks)
 		end
 	end
 	function xml_handlers:EndElement(tagname)
+		if non_streamns_depth > 0 then
+			non_streamns_depth = non_streamns_depth - 1;
+		end
 		if stanza then
 			if #chardata > 0 then
 				-- We have some character data in the buffer
-- 
cgit v1.2.3