Software /
code /
prosody
Comparison
tools/ejabberdsql2prosody.lua @ 1648:b05371e6f058
ejabberdsql2prosody: Added support for offline messages
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 08 Aug 2009 23:17:32 +0500 |
parent | 1647:066cd784d97b |
child | 1649:a6698ab04039 |
comparison
equal
deleted
inserted
replaced
1647:066cd784d97b | 1648:b05371e6f058 |
---|---|
281 function private_storage(node, host, xmlns, stanza) | 281 function private_storage(node, host, xmlns, stanza) |
282 local private = dm.load(node, host, "private") or {}; | 282 local private = dm.load(node, host, "private") or {}; |
283 private[stanza.name..":"..xmlns] = st.preserialize(stanza); | 283 private[stanza.name..":"..xmlns] = st.preserialize(stanza); |
284 local ret, err = dm.store(node, host, "private", private); | 284 local ret, err = dm.store(node, host, "private", private); |
285 print("["..(err or "success").."] private: " ..node.."@"..host.." - "..xmlns); | 285 print("["..(err or "success").."] private: " ..node.."@"..host.." - "..xmlns); |
286 end | |
287 function offline_msg(node, host, t, stanza) | |
288 stanza.attr.stamp = os.date("!%Y-%m-%dT%H:%M:%SZ", t); | |
289 stanza.attr.stamp_legacy = os.date("!%Y%m%dT%H:%M:%S", t); | |
290 local ret, err = dm.list_append(node, host, "offline", st.preserialize(stanza)); | |
291 print("["..(err or "success").."] offline: " ..node.."@"..host.." - "..os.date("!%Y-%m-%dT%H:%M:%SZ", t)); | |
286 end | 292 end |
287 for i, row in ipairs(t["rosterusers"] or NULL) do | 293 for i, row in ipairs(t["rosterusers"] or NULL) do |
288 local node, contact = row.username, row.jid; | 294 local node, contact = row.username, row.jid; |
289 local name = row.nick; | 295 local name = row.nick; |
290 if name == "" then name = nil; end | 296 if name == "" then name = nil; end |
321 print("["..(err or "success").."] vCard: "..row.username.."@"..host); | 327 print("["..(err or "success").."] vCard: "..row.username.."@"..host); |
322 end | 328 end |
323 for i, row in ipairs(t["private_storage"] or NULL) do | 329 for i, row in ipairs(t["private_storage"] or NULL) do |
324 private_storage(row.username, host, row.namespace, st.preserialize(parse_xml(row.data))); | 330 private_storage(row.username, host, row.namespace, st.preserialize(parse_xml(row.data))); |
325 end | 331 end |
332 table.sort(t["spool"] or NULL, function(a,b) return a.seq < b.seq; end); -- sort by sequence number, just in case | |
333 local time_offset = os.difftime(os.time(os.date("!*t")), os.time(os.date("*t"))) -- to deal with timezones | |
334 local date_parse = function(s) | |
335 local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)"); | |
336 return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec-time_offset}); | |
337 end | |
338 for i, row in ipairs(t["spool"] or NULL) do | |
339 local stanza = parse_xml(row.xml); | |
340 local last_child = stanza.tags[#stanza.tags]; | |
341 if not last_child or last_child ~= stanza[#stanza] then error("Last child of offline message is not a tag"); end | |
342 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 | |
343 stanza[#stanza], stanza.tags[#stanza.tags] = nil, nil; | |
344 local t = date_parse(last_child.attr.stamp); | |
345 offline_msg(row.username, host, t, stanza); | |
346 end |