Software /
code /
prosody
Annotate
tools/migration/migrator/jabberd14.lua @ 5147:0ca4185a3d39
storagemanager: Fix argument (Thanks Maranda)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 19 Sep 2012 16:39:19 +0200 |
parent | 4445:0434eb77d18c |
child | 5218:8350eaa3f3f3 |
rev | line source |
---|---|
4417
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 local lfs = require "lfs"; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 local lxp = require "lxp"; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 local st = require "util.stanza"; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 local os_getenv = os.getenv; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 local io_open = io.open; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 local assert = assert; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 local ipairs = ipairs; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 local coroutine = coroutine; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local print = print; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 module "jabberd14" |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 local function is_dir(path) return lfs.attributes(path, "mode") == "directory"; end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 local function is_file(path) return lfs.attributes(path, "mode") == "file"; end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 local function clean_path(path) |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 return path:gsub("\\", "/"):gsub("//+", "/"):gsub("^~", os_getenv("HOME") or "~"); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 local parse_xml = (function() |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 local ns_prefixes = { |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 ["http://www.w3.org/XML/1998/namespace"] = "xml"; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 }; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 local ns_separator = "\1"; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$"; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 return function(xml) |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 local handler = {}; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 local stanza = st.stanza("root"); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 function handler:StartElement(tagname, attr) |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 local curr_ns,name = tagname:match(ns_pattern); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 if name == "" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 curr_ns, name = "", curr_ns; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 if curr_ns ~= "" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 attr.xmlns = curr_ns; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 for i=1,#attr do |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 local k = attr[i]; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 attr[i] = nil; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 local ns, nm = k:match(ns_pattern); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 if nm ~= "" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 ns = ns_prefixes[ns]; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 if ns then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 attr[ns..":"..nm] = attr[k]; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 attr[k] = nil; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 stanza:tag(name, attr); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 function handler:CharacterData(data) |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 stanza:text(data); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 function handler:EndElement(tagname) |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 stanza:up(); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 local parser = lxp.new(handler, "\1"); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 local ok, err, line, col = parser:parse(xml); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 if ok then ok, err, line, col = parser:parse(); end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 --parser:close(); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 if ok then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 return stanza.tags[1]; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 else |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 return ok, err.." (line "..line..", col "..col..")"; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 end; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 end)(); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 local function load_xml(path) |
4445
0434eb77d18c
migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
4417
diff
changeset
|
70 local f, err = io_open(path); |
0434eb77d18c
migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
4417
diff
changeset
|
71 if not f then return f, err; end |
0434eb77d18c
migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
4417
diff
changeset
|
72 local data = f:read("*a"); |
0434eb77d18c
migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
4417
diff
changeset
|
73 f:close(); |
0434eb77d18c
migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
4417
diff
changeset
|
74 if not data then return; end |
0434eb77d18c
migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
4417
diff
changeset
|
75 return parse_xml(data); |
4417
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
76 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
77 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
78 local function load_spool_file(host, filename, path) |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
79 local xml = load_xml(path); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
80 if not xml then return; end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
81 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
82 local register_element = xml:get_child("query", "jabber:iq:register"); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
83 local username_element = register_element and register_element:get_child("username", "jabber:iq:register"); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
84 local password_element = register_element and register_element:get_child("password", "jabber:iq:auth"); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
85 local username = username_element and username_element:get_text(); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
86 local password = password_element and password_element:get_text(); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
87 if not username then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
88 print("[warn] Missing /xdb/{jabber:iq:register}register/username> in file "..filename) |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
89 return; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
90 elseif username..".xml" ~= filename then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
91 print("[warn] Missing /xdb/{jabber:iq:register}register/username does not match filename "..filename); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
92 return; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
93 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
94 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
95 local userdata = { |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
96 user = username; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
97 host = host; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
98 stores = {}; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
99 }; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
100 local stores = userdata.stores; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
101 stores.accounts = { password = password }; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
102 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
103 for i=1,#xml.tags do |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
104 local tag = xml.tags[i]; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
105 local xname = (tag.attr.xmlns or "")..":"..tag.name; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
106 if tag.attr.j_private_flag == "1" and tag.attr.xmlns then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
107 -- Private XML |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
108 stores.private = stores.private or {}; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
109 tag.attr.j_private_flag = nil; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
110 stores.private[tag.attr.xmlns] = st.preserialize(tag); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
111 elseif xname == "jabber:iq:auth:password" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
112 if stores.accounts.password ~= tag:get_text() then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
113 if password then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
114 print("[warn] conflicting passwords") |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
115 else |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
116 stores.accounts.password = tag:get_text(); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
117 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
118 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
119 elseif xname == "jabber:iq:register:query" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
120 -- already processed |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
121 elseif xname == "jabber:xdb:nslist:foo" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
122 -- ignore |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
123 elseif xname == "jabber:iq:auth:0k:zerok" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
124 -- ignore |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
125 elseif xname == "jabber:iq:roster:query" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
126 -- Roster |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
127 local roster = {}; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
128 local subscription_types = { from = true, to = true, both = true, none = true }; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
129 for _,item_element in ipairs(tag.tags) do |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
130 assert(item_element.name == "item"); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
131 assert(item_element.attr.jid); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
132 assert(subscription_types[item_element.attr.subscription]); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
133 assert((item_element.attr.ask or "subscribe") == "subscribe") |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
134 if item_element.name == "item" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
135 local groups = {}; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
136 for _,group_element in ipairs(item_element.tags) do |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
137 assert(group_element.name == "group"); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
138 groups[group_element:get_text()] = true; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
139 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
140 local item = { |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
141 name = item_element.attr.name; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
142 subscription = item_element.attr.subscription; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
143 ask = item_element.attr.ask; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
144 groups = groups; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
145 }; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
146 roster[item_element.attr.jid] = item; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
147 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
148 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
149 stores.roster = roster; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
150 elseif xname == "jabber:iq:last:query" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
151 -- Last activity |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
152 elseif xname == "jabber:x:offline:foo" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
153 -- Offline messages |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
154 elseif xname == "vcard-temp:vCard" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
155 -- vCards |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
156 stores.vcard = st.preserialize(tag); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
157 else |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
158 print("[warn] Unknown tag: "..xname); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
159 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
160 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
161 return userdata; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
162 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
163 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
164 local function loop_over_users(path, host, cb) |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
165 for file in lfs.dir(path) do |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
166 if file:match("%.xml$") then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
167 local user = load_spool_file(host, file, path.."/"..file); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
168 if user then cb(user); end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
169 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
170 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
171 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
172 local function loop_over_hosts(path, cb) |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
173 for host in lfs.dir(path) do |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
174 if host ~= "." and host ~= ".." and is_dir(path.."/"..host) then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
175 loop_over_users(path.."/"..host, host, cb); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
176 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
177 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
178 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
179 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
180 function reader(input) |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
181 local path = clean_path(assert(input.path, "no input.path specified")); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
182 assert(is_dir(path), "input.path is not a directory"); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
183 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
184 if input.host then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
185 return coroutine.wrap(function() loop_over_users(input.path, input.host, coroutine.yield) end); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
186 else |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
187 return coroutine.wrap(function() loop_over_hosts(input.path, coroutine.yield) end); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
188 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
189 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
190 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
191 return _M; |