Software /
code /
prosody
Comparison
tools/ejabberd2prosody.lua @ 4380:9f1c61805817
ejabberd2prosody: Added a lot more type checks to ensure XML data has proper data types. Ignore attributes of invalid types. Fixes the cause of issue#261.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 17 Sep 2011 20:25:11 +0500 |
parent | 4360:a993a4a2ea0a |
child | 5023:dcc8e789df36 |
comparison
equal
deleted
inserted
replaced
4379:e4d88f4a780c | 4380:9f1c61805817 |
---|---|
24 package.loaded["util.logger"] = {init = function() return function() end; end} | 24 package.loaded["util.logger"] = {init = function() return function() end; end} |
25 local dm = require "util.datamanager" | 25 local dm = require "util.datamanager" |
26 dm.set_data_path("data"); | 26 dm.set_data_path("data"); |
27 | 27 |
28 function build_stanza(tuple, stanza) | 28 function build_stanza(tuple, stanza) |
29 assert(type(tuple) == "table", "XML node is of unexpected type: "..type(tuple)); | |
29 if tuple[1] == "xmlelement" then | 30 if tuple[1] == "xmlelement" then |
31 assert(type(tuple[2]) == "string", "element name has type: "..type(tuple[2])); | |
32 assert(type(tuple[3]) == "table", "element attribute array has type: "..type(tuple[3])); | |
33 assert(type(tuple[4]) == "table", "element children array has type: "..type(tuple[4])); | |
30 local name = tuple[2]; | 34 local name = tuple[2]; |
31 local attr = {}; | 35 local attr = {}; |
32 for _, a in ipairs(tuple[3]) do attr[a[1]] = a[2]; end | 36 for _, a in ipairs(tuple[3]) do |
37 if type(a[1]) == "string" and type(a[2]) == "string" then attr[a[1]] = a[2]; end | |
38 end | |
33 local up; | 39 local up; |
34 if stanza then stanza:tag(name, attr); up = true; else stanza = st.stanza(name, attr); end | 40 if stanza then stanza:tag(name, attr); up = true; else stanza = st.stanza(name, attr); end |
35 for _, a in ipairs(tuple[4]) do build_stanza(a, stanza); end | 41 for _, a in ipairs(tuple[4]) do build_stanza(a, stanza); end |
36 if up then stanza:up(); else return stanza end | 42 if up then stanza:up(); else return stanza end |
37 elseif tuple[1] == "xmlcdata" then | 43 elseif tuple[1] == "xmlcdata" then |
44 assert(type(tuple[2]) == "string", "XML CDATA has unexpected type: "..type(tuple[2])); | |
38 stanza:text(tuple[2]); | 45 stanza:text(tuple[2]); |
39 else | 46 else |
40 error("unknown element type: "..serialize(tuple)); | 47 error("unknown element type: "..serialize(tuple)); |
41 end | 48 end |
42 end | 49 end |