Software /
code /
prosody
Annotate
tools/migration/migrator/jabberd14.lua @ 13142:879a6a33c21b
tools: Update imports to use new prosody.* namespace
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 08 Jun 2023 09:37:01 +0200 |
parent | 7881:4e3067272fae |
rev | line source |
---|---|
4417
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
13142
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
7881
diff
changeset
|
2 if not pcall(require, "prosody.loader") then |
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
7881
diff
changeset
|
3 pcall(require, "loader"); |
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
7881
diff
changeset
|
4 end |
4417
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 local lfs = require "lfs"; |
13142
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
7881
diff
changeset
|
6 local st = require "prosody.util.stanza"; |
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
7881
diff
changeset
|
7 local parse_xml = require "prosody.util.xml".parse; |
4417
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 local os_getenv = os.getenv; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 local io_open = io.open; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local assert = assert; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 local ipairs = ipairs; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 local coroutine = coroutine; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 local print = print; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 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
|
17 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
|
18 local function clean_path(path) |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 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
|
20 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 local function load_xml(path) |
4445
0434eb77d18c
migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
4417
diff
changeset
|
23 local f, err = io_open(path); |
0434eb77d18c
migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
4417
diff
changeset
|
24 if not f then return f, err; end |
0434eb77d18c
migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
4417
diff
changeset
|
25 local data = f:read("*a"); |
0434eb77d18c
migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
4417
diff
changeset
|
26 f:close(); |
0434eb77d18c
migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
4417
diff
changeset
|
27 if not data then return; end |
0434eb77d18c
migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
4417
diff
changeset
|
28 return parse_xml(data); |
4417
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 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
|
32 local xml = load_xml(path); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 if not xml then return; end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 if not username then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 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
|
42 return; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 elseif username..".xml" ~= filename then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 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
|
45 return; |
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 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 local userdata = { |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 user = username; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 host = host; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 stores = {}; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 }; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 local stores = userdata.stores; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 stores.accounts = { password = password }; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 for i=1,#xml.tags do |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 local tag = xml.tags[i]; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 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
|
59 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
|
60 -- Private XML |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 stores.private = stores.private or {}; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 tag.attr.j_private_flag = nil; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 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
|
64 elseif xname == "jabber:iq:auth:password" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 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
|
66 if password then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 print("[warn] conflicting passwords") |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 else |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 stores.accounts.password = tag:get_text(); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
70 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
71 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
72 elseif xname == "jabber:iq:register:query" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
73 -- already processed |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
74 elseif xname == "jabber:xdb:nslist:foo" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
75 -- ignore |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
76 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
|
77 -- ignore |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
78 elseif xname == "jabber:iq:roster:query" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
79 -- Roster |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
80 local roster = {}; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
81 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
|
82 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
|
83 assert(item_element.name == "item"); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
84 assert(item_element.attr.jid); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
85 assert(subscription_types[item_element.attr.subscription]); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
86 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
|
87 if item_element.name == "item" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
88 local groups = {}; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
89 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
|
90 assert(group_element.name == "group"); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
91 groups[group_element:get_text()] = true; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
92 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
93 local item = { |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
94 name = item_element.attr.name; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
95 subscription = item_element.attr.subscription; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
96 ask = item_element.attr.ask; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
97 groups = groups; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
98 }; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
99 roster[item_element.attr.jid] = item; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
100 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
101 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
102 stores.roster = roster; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
103 elseif xname == "jabber:iq:last:query" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
104 -- Last activity |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
105 elseif xname == "jabber:x:offline:foo" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
106 -- Offline messages |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
107 elseif xname == "vcard-temp:vCard" then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
108 -- vCards |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
109 stores.vcard = st.preserialize(tag); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
110 else |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
111 print("[warn] Unknown tag: "..xname); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
112 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
113 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
114 return userdata; |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
115 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
116 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
117 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
|
118 for file in lfs.dir(path) do |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
119 if file:match("%.xml$") then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
120 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
|
121 if user then cb(user); end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
122 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
123 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
124 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
125 local function loop_over_hosts(path, cb) |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
126 for host in lfs.dir(path) do |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
127 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
|
128 loop_over_users(path.."/"..host, host, cb); |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
129 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
130 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
131 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
132 |
7881
4e3067272fae
tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents:
5218
diff
changeset
|
133 local function reader(input) |
4417
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
134 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
|
135 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
|
136 |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
137 if input.host then |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
138 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
|
139 else |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
140 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
|
141 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
142 end |
33c149394dcb
migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
143 |
7881
4e3067272fae
tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents:
5218
diff
changeset
|
144 return { |
4e3067272fae
tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents:
5218
diff
changeset
|
145 reader = reader; |
4e3067272fae
tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents:
5218
diff
changeset
|
146 }; |