27 ["http://www.w3.org/XML/1998/namespace"] = "xml"; |
27 ["http://www.w3.org/XML/1998/namespace"] = "xml"; |
28 } |
28 } |
29 |
29 |
30 function init_xmlhandlers(session, stream_callbacks) |
30 function init_xmlhandlers(session, stream_callbacks) |
31 local ns_stack = { "" }; |
31 local ns_stack = { "" }; |
32 local curr_ns, name = ""; |
|
33 local curr_tag; |
32 local curr_tag; |
34 local chardata = {}; |
33 local chardata = {}; |
35 local xml_handlers = {}; |
34 local xml_handlers = {}; |
36 local log = session.log or default_log; |
35 local log = session.log or default_log; |
37 |
36 |
48 if stanza and #chardata > 0 then |
47 if stanza and #chardata > 0 then |
49 -- We have some character data in the buffer |
48 -- We have some character data in the buffer |
50 stanza:text(t_concat(chardata)); |
49 stanza:text(t_concat(chardata)); |
51 chardata = {}; |
50 chardata = {}; |
52 end |
51 end |
53 local curr_ns,name = tagname:match("^(.-)|?([^%|]-)$"); |
52 local curr_ns,name = tagname:match("^([^\1]*)\1?(.*)$"); |
54 if not name then |
53 if not name then |
55 curr_ns, name = "", curr_ns; |
54 curr_ns, name = "", curr_ns; |
56 end |
55 end |
57 |
56 |
58 if curr_ns ~= stream_default_ns then |
57 if curr_ns ~= stream_default_ns then |
103 if stanza then |
102 if stanza then |
104 t_insert(chardata, data); |
103 t_insert(chardata, data); |
105 end |
104 end |
106 end |
105 end |
107 function xml_handlers:EndElement(tagname) |
106 function xml_handlers:EndElement(tagname) |
108 curr_ns,name = tagname:match("^(.-)|?([^%|]-)$"); |
107 local curr_ns,name = tagname:match("^([^\1]*)\1?(.*)$"); |
109 if not name then |
108 if not name then |
110 curr_ns, name = "", curr_ns; |
109 curr_ns, name = "", curr_ns; |
111 end |
110 end |
112 if (not stanza) or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then |
111 if (not stanza) or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then |
113 if tagname == stream_tag then |
112 if tagname == stream_tag then |