Annotate

tools/migration/migrator/jabberd14.lua @ 5233:342c46e62f50

mod_http_files: Return 404 faster if file does not exist
author Kim Alvefur <zash@zash.se>
date Tue, 11 Dec 2012 22:26:41 +0100
parent 5218:8350eaa3f3f3
child 7881:4e3067272fae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 st = require "util.stanza";
5218
8350eaa3f3f3 tools/migration/migrator/jabberd14: Use util.xml.
Waqas Hussain <waqas20@gmail.com>
parents: 4445
diff changeset
4 local parse_xml = require "util.xml".parse;
4417
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 function load_xml(path)
4445
0434eb77d18c migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents: 4417
diff changeset
21 local f, err = io_open(path);
0434eb77d18c migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents: 4417
diff changeset
22 if not f then return f, err; end
0434eb77d18c migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents: 4417
diff changeset
23 local data = f:read("*a");
0434eb77d18c migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents: 4417
diff changeset
24 f:close();
0434eb77d18c migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents: 4417
diff changeset
25 if not data then return; end
0434eb77d18c migrator/jabberd14: Minor refactoring.
Waqas Hussain <waqas20@gmail.com>
parents: 4417
diff changeset
26 return parse_xml(data);
4417
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 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
30 local xml = load_xml(path);
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 if not xml then return; end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 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
34 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
35 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
36 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
37 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
38 if not username then
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 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
40 return;
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 elseif username..".xml" ~= filename then
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 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
43 return;
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 local userdata = {
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 user = username;
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 host = host;
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 stores = {};
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50 };
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 local stores = userdata.stores;
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 stores.accounts = { password = password };
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 for i=1,#xml.tags do
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 local tag = xml.tags[i];
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 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
57 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
58 -- Private XML
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
59 stores.private = stores.private or {};
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
60 tag.attr.j_private_flag = nil;
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
61 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
62 elseif xname == "jabber:iq:auth:password" then
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 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
64 if password then
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65 print("[warn] conflicting passwords")
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 else
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67 stores.accounts.password = tag:get_text();
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
68 end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
69 end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
70 elseif xname == "jabber:iq:register:query" then
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
71 -- already processed
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
72 elseif xname == "jabber:xdb:nslist:foo" then
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
73 -- ignore
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
74 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
75 -- ignore
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
76 elseif xname == "jabber:iq:roster:query" then
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
77 -- Roster
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
78 local roster = {};
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
79 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
80 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
81 assert(item_element.name == "item");
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
82 assert(item_element.attr.jid);
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
83 assert(subscription_types[item_element.attr.subscription]);
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
84 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
85 if item_element.name == "item" then
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
86 local groups = {};
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
87 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
88 assert(group_element.name == "group");
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
89 groups[group_element:get_text()] = true;
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
90 end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
91 local item = {
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
92 name = item_element.attr.name;
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
93 subscription = item_element.attr.subscription;
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
94 ask = item_element.attr.ask;
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
95 groups = groups;
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
96 };
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
97 roster[item_element.attr.jid] = item;
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
98 end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
99 end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
100 stores.roster = roster;
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
101 elseif xname == "jabber:iq:last:query" then
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
102 -- Last activity
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
103 elseif xname == "jabber:x:offline:foo" then
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
104 -- Offline messages
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
105 elseif xname == "vcard-temp:vCard" then
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
106 -- vCards
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
107 stores.vcard = st.preserialize(tag);
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
108 else
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
109 print("[warn] Unknown tag: "..xname);
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
110 end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
111 end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
112 return userdata;
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
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
115 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
116 for file in lfs.dir(path) do
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
117 if file:match("%.xml$") then
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
118 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
119 if user then cb(user); end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
120 end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
121 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 local function loop_over_hosts(path, cb)
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
124 for host in lfs.dir(path) do
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
125 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
126 loop_over_users(path.."/"..host, host, cb);
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
127 end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
128 end
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
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
131 function reader(input)
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
132 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
133 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
134
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
135 if input.host then
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
136 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
137 else
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
138 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
139 end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
140 end
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
141
33c149394dcb migrator/jabberd14: Support for reading jabberd14 spool files.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
142 return _M;