aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-08-03 17:53:02 +0100
committerMatthew Wild <mwild1@gmail.com>2009-08-03 17:53:02 +0100
commitcdd3c546c7ef80cb569aafaaf76cde2d3fd3c1e2 (patch)
treef082821462154bf067f81469c6bb4d7c20a11093
parentb5521c4a1677bbbbc7e3f32d4426800c66749e2b (diff)
parent21801b6bf4a4227ec17c5bab7ea9f07b1d66faa4 (diff)
downloadprosody-cdd3c546c7ef80cb569aafaaf76cde2d3fd3c1e2.tar.gz
prosody-cdd3c546c7ef80cb569aafaaf76cde2d3fd3c1e2.zip
Merge with waqas
-rw-r--r--tools/ejabberdsql2prosody.lua65
1 files changed, 65 insertions, 0 deletions
diff --git a/tools/ejabberdsql2prosody.lua b/tools/ejabberdsql2prosody.lua
index 5b975269..4aace085 100644
--- a/tools/ejabberdsql2prosody.lua
+++ b/tools/ejabberdsql2prosody.lua
@@ -156,6 +156,58 @@ 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
@@ -226,6 +278,12 @@ function roster_group(node, host, jid, group)
local ret, err = dm.store(node, host, "roster", roster);
print("["..(err or "success").."] roster-group: " ..node.."@"..host.." - "..jid.." - "..group);
end
+function private_storage(node, host, xmlns, stanza)
+ local private = dm.load(node, host, "private") or {};
+ private[stanza.name..":"..xmlns] = st.preserialize(stanza);
+ local ret, err = dm.store(node, host, "private", private);
+ print("["..(err or "success").."] private: " ..node.."@"..host.." - "..xmlns);
+end
for i, row in ipairs(t["rosterusers"] or NULL) do
local node, contact = row.username, row.jid;
local name = row.nick;
@@ -258,3 +316,10 @@ end
for i, row in ipairs(t["rostergroups"] or NULL) do
roster_group(row.username, host, row.jid, row.grp);
end
+for i, row in ipairs(t["vcard"] or NULL) do
+ local ret, err = dm.store(row.username, host, "vcard", st.preserialize(parse_xml(row.vcard)));
+ print("["..(err or "success").."] vCard: "..row.username.."@"..host);
+end
+for i, row in ipairs(t["private_storage"] or NULL) do
+ private_storage(row.username, host, row.namespace, st.preserialize(parse_xml(row.data)));
+end