Software /
code /
prosody
Comparison
util/xmppstream.lua @ 3633:4069c37c54bc
util.xmppstream: Preserve the stream content namespace on descendents of elements which are in another namespace.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 20 Nov 2010 02:28:40 +0500 |
parent | 3540:bc139431830b |
child | 3638:6f58a3063c14 |
comparison
equal
deleted
inserted
replaced
3632:d82189efecc0 | 3633:4069c37c54bc |
---|---|
46 local stream_error_tag = stream_ns..ns_separator..(stream_callbacks.error_tag or "error"); | 46 local stream_error_tag = stream_ns..ns_separator..(stream_callbacks.error_tag or "error"); |
47 | 47 |
48 local stream_default_ns = stream_callbacks.default_ns; | 48 local stream_default_ns = stream_callbacks.default_ns; |
49 | 49 |
50 local chardata, stanza = {}; | 50 local chardata, stanza = {}; |
51 local non_streamns_depth = 0; | |
51 function xml_handlers:StartElement(tagname, attr) | 52 function xml_handlers:StartElement(tagname, attr) |
52 if stanza and #chardata > 0 then | 53 if stanza and #chardata > 0 then |
53 -- We have some character data in the buffer | 54 -- We have some character data in the buffer |
54 stanza:text(t_concat(chardata)); | 55 stanza:text(t_concat(chardata)); |
55 chardata = {}; | 56 chardata = {}; |
57 local curr_ns,name = tagname:match(ns_pattern); | 58 local curr_ns,name = tagname:match(ns_pattern); |
58 if name == "" then | 59 if name == "" then |
59 curr_ns, name = "", curr_ns; | 60 curr_ns, name = "", curr_ns; |
60 end | 61 end |
61 | 62 |
62 if curr_ns ~= stream_default_ns then | 63 if curr_ns ~= stream_default_ns or non_streamns_depth > 0 then |
63 attr.xmlns = curr_ns; | 64 attr.xmlns = curr_ns; |
65 non_streamns_depth = non_streamns_depth + 1; | |
64 end | 66 end |
65 | 67 |
66 -- FIXME !!!!! | 68 -- FIXME !!!!! |
67 for i=1,#attr do | 69 for i=1,#attr do |
68 local k = attr[i]; | 70 local k = attr[i]; |
78 end | 80 end |
79 | 81 |
80 if not stanza then --if we are not currently inside a stanza | 82 if not stanza then --if we are not currently inside a stanza |
81 if session.notopen then | 83 if session.notopen then |
82 if tagname == stream_tag then | 84 if tagname == stream_tag then |
85 non_streamns_depth = 0; | |
83 if cb_streamopened then | 86 if cb_streamopened then |
84 cb_streamopened(session, attr); | 87 cb_streamopened(session, attr); |
85 end | 88 end |
86 else | 89 else |
87 -- Garbage before stream? | 90 -- Garbage before stream? |
102 if stanza then | 105 if stanza then |
103 t_insert(chardata, data); | 106 t_insert(chardata, data); |
104 end | 107 end |
105 end | 108 end |
106 function xml_handlers:EndElement(tagname) | 109 function xml_handlers:EndElement(tagname) |
110 if non_streamns_depth > 0 then | |
111 non_streamns_depth = non_streamns_depth - 1; | |
112 end | |
107 if stanza then | 113 if stanza then |
108 if #chardata > 0 then | 114 if #chardata > 0 then |
109 -- We have some character data in the buffer | 115 -- We have some character data in the buffer |
110 stanza:text(t_concat(chardata)); | 116 stanza:text(t_concat(chardata)); |
111 chardata = {}; | 117 chardata = {}; |