Created
March 13, 2010 20:03
-
-
Save zeen/331514 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- expects XML file as first argument | |
-- call in a loop over all files | |
-- e.g., on windows I can do: for %x in (xml\*.xml) do @ j2offline.lua %x | |
-- prosody stuff needs to be on LUA_PATH and LUA_CPATH, or add it here: | |
package.path = "../?.lua;"..package.path; | |
package.cpath = "../?.dll;../?.so;"..package.cpath; | |
prosody = { } | |
local init_xmlhandlers = require "core.xmlhandlers"; | |
local lxp = require "lxp"; | |
local datamanager = require "util.datamanager"; | |
local st = require "util.stanza"; | |
local jid_split = require "util.jid".split; | |
datamanager.set_data_path("./data"); | |
local cb = { stream_tag = "stream", default_ns = "jabber:client"}; | |
function cb.streamopened(stream) stream.notopen = nil; end | |
local pcount, mcount, ocount = 0, 0, 0; | |
function cb.handlestanza(_, stanza) | |
if not stanza.attr.xmlns or stanza.attr.xmlns == "jabber:client" then | |
if stanza.name == "presence" then | |
pcount = pcount + 1; | |
elseif stanza.name == "message" then | |
local node, host = jid_split(stanza.attr.to); | |
if mcount == 0 then datamanager.list_store(node, host, "offline", nil); end | |
local delay = stanza:get_child("delay", "jabber:x:delay"); | |
if delay then | |
stanza.attr.stamp = delay.attr.stamp; | |
stanza.attr.stamp_legacy = delay.attr.stamp:gsub("(....)(..)(..)T(..):(..):(..)", function(Y,M,D,h,m,s) return ("%s-%s-%sT%d:%s:%sZ"):format(Y,M,D,h,m,s) end); | |
end | |
datamanager.list_append(node, host, "offline", st.preserialize(stanza)); | |
mcount = mcount + 1; | |
else | |
ocount = ocount + 1; | |
end | |
else | |
ocount = ocount + 1; | |
end | |
end | |
local parser = lxp.new(init_xmlhandlers({ | |
notopen = true, | |
}, cb), "\1"); | |
--"<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client'>"); | |
local f = io.open(arg[1]); | |
local xml = f:read("*a"); | |
io.write(arg[1]..": "); | |
local ok, err = parser:parse(xml); | |
f:close(); | |
print(("m:%s, p:%s, o:%s"):format(mcount, pcount, ocount)); | |
if not ok then error("Error parsing offline messages for "..filename..": "..err); os.exit(1); end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment