diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/ejabberd2prosody.lua | 26 | ||||
-rw-r--r-- | tools/ejabberdsql2prosody.lua | 27 | ||||
-rw-r--r-- | tools/erlparse.lua | 16 |
3 files changed, 58 insertions, 11 deletions
diff --git a/tools/ejabberd2prosody.lua b/tools/ejabberd2prosody.lua index 4fef3f3a..7b19260d 100755 --- a/tools/ejabberd2prosody.lua +++ b/tools/ejabberd2prosody.lua @@ -9,9 +9,14 @@ +package.path = package.path ..";../?.lua"; + +if arg[0]:match("^./") then + package.path = package.path .. ";"..arg[0]:gsub("/ejabberd2prosody.lua$", "/?.lua"); +end + require "erlparse"; -package.path = package.path ..";../?.lua"; local serialize = require "util.serialization".serialize; local st = require "util.stanza"; package.loaded["util.logger"] = {init = function() return function() end; end} @@ -86,13 +91,24 @@ local filters = { local name = tuple[5]; local subscription = tuple[6]; local ask = tuple[7]; local groups = tuple[8]; if type(name) ~= type("") then name = nil; end - if ask == "none" then ask = nil; elseif ask == "out" then ask = "subscribe" elseif ask == "in" then + if ask == "none" then + ask = nil; + elseif ask == "out" then + ask = "subscribe" + elseif ask == "in" then + roster_pending(node, host, contact); + ask = nil; + elseif ask == "both" then roster_pending(node, host, contact); - return; - else error(ask) end + ask = "subscribe"; + else error("Unknown ask type: "..ask); end if subscription ~= "both" and subscription ~= "from" and subscription ~= "to" and subscription ~= "none" then error(subscription) end local item = {name = name, ask = ask, subscription = subscription, groups = {}}; - for _, g in ipairs(groups) do item.groups[g] = true; end + for _, g in ipairs(groups) do + if type(g) == "string" then + item.groups[g] = true; + end + end roster(node, host, contact, item); end; private_storage = function(tuple) diff --git a/tools/ejabberdsql2prosody.lua b/tools/ejabberdsql2prosody.lua index 4aace085..f652af5b 100644 --- a/tools/ejabberdsql2prosody.lua +++ b/tools/ejabberdsql2prosody.lua @@ -136,8 +136,8 @@ local function readFile(filename) while true do local tname, tuples = readInsert(); if tname then - if t[name] then - local t_name = t[name]; + if t[tname] then + local t_name = t[tname]; for i=1,#tuples do table.insert(t_name, tuples[i]); end @@ -284,6 +284,12 @@ function private_storage(node, host, xmlns, stanza) local ret, err = dm.store(node, host, "private", private); print("["..(err or "success").."] private: " ..node.."@"..host.." - "..xmlns); end +function offline_msg(node, host, t, stanza) + stanza.attr.stamp = os.date("!%Y-%m-%dT%H:%M:%SZ", t); + stanza.attr.stamp_legacy = os.date("!%Y%m%dT%H:%M:%S", t); + local ret, err = dm.list_append(node, host, "offline", st.preserialize(stanza)); + print("["..(err or "success").."] offline: " ..node.."@"..host.." - "..os.date("!%Y-%m-%dT%H:%M:%SZ", t)); +end for i, row in ipairs(t["rosterusers"] or NULL) do local node, contact = row.username, row.jid; local name = row.nick; @@ -321,5 +327,20 @@ for i, row in ipairs(t["vcard"] or NULL) do 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))); + private_storage(row.username, host, row.namespace, parse_xml(row.data)); +end +table.sort(t["spool"] or NULL, function(a,b) return a.seq < b.seq; end); -- sort by sequence number, just in case +local time_offset = os.difftime(os.time(os.date("!*t")), os.time(os.date("*t"))) -- to deal with timezones +local date_parse = function(s) + local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)"); + return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec-time_offset}); +end +for i, row in ipairs(t["spool"] or NULL) do + local stanza = parse_xml(row.xml); + local last_child = stanza.tags[#stanza.tags]; + if not last_child or last_child ~= stanza[#stanza] then error("Last child of offline message is not a tag"); end + if last_child.name ~= "x" and last_child.attr.xmlns ~= "jabber:x:delay" then error("Last child of offline message is not a timestamp"); end + stanza[#stanza], stanza.tags[#stanza.tags] = nil, nil; + local t = date_parse(last_child.attr.stamp); + offline_msg(row.username, host, t, stanza); end diff --git a/tools/erlparse.lua b/tools/erlparse.lua index f2d410a3..bfec3b4d 100644 --- a/tools/erlparse.lua +++ b/tools/erlparse.lua @@ -45,16 +45,26 @@ local function isSpace(ch) return ch <= _space; end +local escapes = {["\\b"]="\b", ["\\d"]="\d", ["\\e"]="\e", ["\\f"]="\f", ["\\n"]="\n", ["\\r"]="\r", ["\\s"]="\s", ["\\t"]="\t", ["\\v"]="\v", ["\\\""]="\"", ["\\'"]="'", ["\\\\"]="\\"}; local function readString() read("\""); -- skip quote local slash = nil; local str = ""; while true do local ch = read(); - if ch == "\"" and not slash then break; end - str = str..ch; + if slash then + slash = slash..ch; + if not escapes[slash] then error("Unknown escape sequence: "..slash); end + str = str..escapes[slash]; + slash = nil; + elseif ch == "\"" then + break; + elseif ch == "\\" then + slash = ch; + else + str = str..ch; + end end - str = str:gsub("\\.", {["\\b"]="\b", ["\\d"]="\d", ["\\e"]="\e", ["\\f"]="\f", ["\\n"]="\n", ["\\r"]="\r", ["\\s"]="\s", ["\\t"]="\t", ["\\v"]="\v", ["\\\""]="\"", ["\\'"]="'", ["\\\\"]="\\"}); return str; end local function readAtom1() |