aboutsummaryrefslogtreecommitdiffstats
path: root/tools/ejabberdsql2prosody.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2012-12-03 06:07:00 +0500
committerWaqas Hussain <waqas20@gmail.com>2012-12-03 06:07:00 +0500
commitd753412283d3b5042ad8f47741adcf49ab29621c (patch)
tree32193989f72cd93a36bea4a74cfbfb547277fe8b /tools/ejabberdsql2prosody.lua
parent8674db94117611ef4790c1d2859fd144c12dd7d1 (diff)
parent52a43878396f739d35f49a6194241878c47f6b26 (diff)
downloadprosody-d753412283d3b5042ad8f47741adcf49ab29621c.tar.gz
prosody-d753412283d3b5042ad8f47741adcf49ab29621c.zip
Merge 0.9->trunk.
Diffstat (limited to 'tools/ejabberdsql2prosody.lua')
-rw-r--r--tools/ejabberdsql2prosody.lua53
1 files changed, 1 insertions, 52 deletions
diff --git a/tools/ejabberdsql2prosody.lua b/tools/ejabberdsql2prosody.lua
index c64faee0..43720643 100644
--- a/tools/ejabberdsql2prosody.lua
+++ b/tools/ejabberdsql2prosody.lua
@@ -12,6 +12,7 @@ prosody = {};
package.path = package.path ..";../?.lua";
local serialize = require "util.serialization".serialize;
local st = require "util.stanza";
+local parse_xml = require "util.xml".parse;
package.loaded["util.logger"] = {init = function() return function() end; end}
local dm = require "util.datamanager"
dm.set_data_path("data");
@@ -167,58 +168,6 @@ return readFile(filename);
------
end
--- XML parser
-local parse_xml = (function()
- local entity_map = setmetatable({
- ["amp"] = "&";
- ["gt"] = ">";
- ["lt"] = "<";
- ["apos"] = "'";
- ["quot"] = "\"";
- }, {__index = function(_, s)
- if s:sub(1,1) == "#" then
- if s:sub(2,2) == "x" then
- return string.char(tonumber(s:sub(3), 16));
- else
- return string.char(tonumber(s:sub(2)));
- end
- end
- end
- });
- local function xml_unescape(str)
- return (str:gsub("&(.-);", entity_map));
- end
- local function parse_tag(s)
- local name,sattr=(s):gmatch("([^%s]+)(.*)")();
- local attr = {};
- for a,b in (sattr):gmatch("([^=%s]+)=['\"]([^'\"]*)['\"]") do attr[a] = xml_unescape(b); end
- return name, attr;
- end
- return function(xml)
- local stanza = st.stanza("root");
- local regexp = "<([^>]*)>([^<]*)";
- for elem, text in xml:gmatch(regexp) do
- if elem:sub(1,1) == "!" or elem:sub(1,1) == "?" then -- neglect comments and processing-instructions
- elseif elem:sub(1,1) == "/" then -- end tag
- elem = elem:sub(2);
- stanza:up(); -- TODO check for start-end tag name match
- elseif elem:sub(-1,-1) == "/" then -- empty tag
- elem = elem:sub(1,-2);
- local name,attr = parse_tag(elem);
- stanza:tag(name, attr):up();
- else -- start tag
- local name,attr = parse_tag(elem);
- stanza:tag(name, attr);
- end
- if #text ~= 0 then -- text
- stanza:text(xml_unescape(text));
- end
- end
- return stanza.tags[1];
- end
-end)();
--- end of XML parser
-
local arg, host = ...;
local help = "/? -? ? /h -h /help -help --help";
if not(arg and host) or help:find(arg, 1, true) then