Software /
code /
prosody
Comparison
core/xmlhandlers.lua @ 2077:e33658f6052c
Changed separator between attribute names and prefixes from '|' to '\1' (optimization and cleanup).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 12 Nov 2009 13:42:44 +0500 |
parent | 2037:a919511c45ac |
child | 2261:13d55c66bf81 |
comparison
equal
deleted
inserted
replaced
2076:de2ae849b0b3 | 2077:e33658f6052c |
---|---|
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 |
61 | 60 |
62 -- FIXME !!!!! | 61 -- FIXME !!!!! |
63 for i=1,#attr do | 62 for i=1,#attr do |
64 local k = attr[i]; | 63 local k = attr[i]; |
65 attr[i] = nil; | 64 attr[i] = nil; |
66 local ns, nm = k:match("^([^|]+)|?([^|]-)$") | 65 local ns, nm = k:match("^([^\1]*)\1?(.*)$"); |
67 if ns and nm then | 66 if ns and nm then |
68 ns = ns_prefixes[ns]; | 67 ns = ns_prefixes[ns]; |
69 if ns then | 68 if ns then |
70 attr[ns..":"..nm] = attr[k]; | 69 attr[ns..":"..nm] = attr[k]; |
71 attr[k] = nil; | 70 attr[k] = nil; |
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 |