Comparison

core/xmlhandlers.lua @ 899:b95368f199a1

core.xmlhandlers: Filter out default stream namespace from stanzas
author Matthew Wild <mwild1@gmail.com>
date Sat, 21 Mar 2009 21:43:50 +0000
parent 896:2c0b9e3c11c3
child 1003:afae75e37ceb
comparison
equal deleted inserted replaced
898:8176d224208a 899:b95368f199a1
46 local cb_streamclosed = stream_callbacks.streamclosed; 46 local cb_streamclosed = stream_callbacks.streamclosed;
47 local cb_error = stream_callbacks.error or function (session, e) error("XML stream error: "..tostring(e)); end; 47 local cb_error = stream_callbacks.error or function (session, e) error("XML stream error: "..tostring(e)); end;
48 local cb_handlestanza = stream_callbacks.handlestanza; 48 local cb_handlestanza = stream_callbacks.handlestanza;
49 49
50 local stream_tag = stream_callbacks.stream_tag; 50 local stream_tag = stream_callbacks.stream_tag;
51 local stream_default_ns = stream_callbacks.default_ns;
51 52
52 local stanza 53 local stanza
53 function xml_handlers:StartElement(tagname, attr) 54 function xml_handlers:StartElement(tagname, attr)
54 if stanza and #chardata > 0 then 55 if stanza and #chardata > 0 then
55 -- We have some character data in the buffer 56 -- We have some character data in the buffer
56 stanza:text(t_concat(chardata)); 57 stanza:text(t_concat(chardata));
57 chardata = {}; 58 chardata = {};
58 end 59 end
59 local curr_ns,name = tagname:match("^(.+)|([%w%-]+)$"); 60 local curr_ns,name = tagname:match("^(.+)|([%w%-]+)$");
60 if curr_ns ~= "jabber:server" then 61 if curr_ns ~= stream_default_ns then
61 attr.xmlns = curr_ns; 62 attr.xmlns = curr_ns;
62 end 63 end
63 64
64 -- FIXME !!!!! 65 -- FIXME !!!!!
65 for i, k in ipairs(attr) do 66 for i, k in ipairs(attr) do
94 95
95 stanza = st.stanza(name, attr); 96 stanza = st.stanza(name, attr);
96 curr_tag = stanza; 97 curr_tag = stanza;
97 else -- we are inside a stanza, so add a tag 98 else -- we are inside a stanza, so add a tag
98 attr.xmlns = nil; 99 attr.xmlns = nil;
99 if curr_ns ~= "jabber:server" and curr_ns ~= "jabber:client" then 100 if curr_ns ~= stream_default_ns then
100 attr.xmlns = curr_ns; 101 attr.xmlns = curr_ns;
101 end 102 end
102 stanza:tag(name, attr); 103 stanza:tag(name, attr);
103 end 104 end
104 end 105 end