Comparison

tools/ejabberdsql2prosody.lua @ 7567:495de404a8ae

ejabberdsql2prosody: rename variable 'host' to prevent shadowing upvalue [luacheck] Functions roster(), roster_pending(), roster_group(), private_storage() and offline_msg() have argument named "host", which used to shadow upvalue of this variable before this change. Instead of renaming this argument, let's rename the variable to match what the script says in usage: Usage: ejabberdsql2prosody.lua filename.txt hostname
author Anton Shestakov <av6@dwimlabs.net>
date Fri, 12 Aug 2016 13:44:47 +0800
parent 7566:e4f9c192b797
child 7568:4f7990902874
comparison
equal deleted inserted replaced
7566:e4f9c192b797 7567:495de404a8ae
170 return readFile(filename); 170 return readFile(filename);
171 171
172 ------ 172 ------
173 end 173 end
174 174
175 local arg, host = ...; 175 local arg, hostname = ...;
176 local help = "/? -? ? /h -h /help -help --help"; 176 local help = "/? -? ? /h -h /help -help --help";
177 if not(arg and host) or help:find(arg, 1, true) then 177 if not(arg and hostname) or help:find(arg, 1, true) then
178 print([[ejabberd SQL DB dump importer for Prosody 178 print([[ejabberd SQL DB dump importer for Prosody
179 179
180 Usage: ejabberdsql2prosody.lua filename.txt hostname 180 Usage: ejabberdsql2prosody.lua filename.txt hostname
181 181
182 The file can be generated using mysqldump: 182 The file can be generated using mysqldump:
215 end 215 end
216 --print(serialize(t)); 216 --print(serialize(t));
217 217
218 for _, row in ipairs(t["users"] or NULL) do 218 for _, row in ipairs(t["users"] or NULL) do
219 local node, password = row.username, row.password; 219 local node, password = row.username, row.password;
220 local ret, err = dm.store(node, host, "accounts", {password = password}); 220 local ret, err = dm.store(node, hostname, "accounts", {password = password});
221 print("["..(err or "success").."] accounts: "..node.."@"..host); 221 print("["..(err or "success").."] accounts: "..node.."@"..hostname);
222 end 222 end
223 223
224 function roster(node, host, jid, item) 224 function roster(node, host, jid, item)
225 local roster = dm.load(node, host, "roster") or {}; 225 local roster = dm.load(node, host, "roster") or {};
226 roster[jid] = item; 226 roster[jid] = item;
272 if ask == "N" then 272 if ask == "N" then
273 ask = nil; 273 ask = nil;
274 elseif ask == "O" then 274 elseif ask == "O" then
275 ask = "subscribe"; 275 ask = "subscribe";
276 elseif ask == "I" then 276 elseif ask == "I" then
277 roster_pending(node, host, contact); 277 roster_pending(node, hostname, contact);
278 ask = nil; 278 ask = nil;
279 elseif ask == "B" then 279 elseif ask == "B" then
280 roster_pending(node, host, contact); 280 roster_pending(node, hostname, contact);
281 ask = "subscribe"; 281 ask = "subscribe";
282 else error("Unknown ask type: "..ask); end 282 else error("Unknown ask type: "..ask); end
283 local item = {name = name, ask = ask, subscription = subscription, groups = {}}; 283 local item = {name = name, ask = ask, subscription = subscription, groups = {}};
284 roster(node, host, contact, item); 284 roster(node, hostname, contact, item);
285 end 285 end
286 for _, row in ipairs(t["rostergroups"] or NULL) do 286 for _, row in ipairs(t["rostergroups"] or NULL) do
287 roster_group(row.username, host, row.jid, row.grp); 287 roster_group(row.username, hostname, row.jid, row.grp);
288 end 288 end
289 for _, row in ipairs(t["vcard"] or NULL) do 289 for _, row in ipairs(t["vcard"] or NULL) do
290 local stanza, err = parse_xml(row.vcard); 290 local stanza, err = parse_xml(row.vcard);
291 if stanza then 291 if stanza then
292 local ret, err = dm.store(row.username, host, "vcard", st.preserialize(stanza)); 292 local ret, err = dm.store(row.username, hostname, "vcard", st.preserialize(stanza));
293 print("["..(err or "success").."] vCard: "..row.username.."@"..host); 293 print("["..(err or "success").."] vCard: "..row.username.."@"..hostname);
294 else 294 else
295 print("[error] vCard XML parse failed: "..row.username.."@"..host); 295 print("[error] vCard XML parse failed: "..row.username.."@"..hostname);
296 end 296 end
297 end 297 end
298 for _, row in ipairs(t["private_storage"] or NULL) do 298 for _, row in ipairs(t["private_storage"] or NULL) do
299 local stanza, err = parse_xml(row.data); 299 local stanza, err = parse_xml(row.data);
300 if stanza then 300 if stanza then
301 private_storage(row.username, host, row.namespace, stanza); 301 private_storage(row.username, hostname, row.namespace, stanza);
302 else 302 else
303 print("[error] Private XML parse failed: "..row.username.."@"..host); 303 print("[error] Private XML parse failed: "..row.username.."@"..hostname);
304 end 304 end
305 end 305 end
306 table.sort(t["spool"] or NULL, function(a,b) return a.seq < b.seq; end); -- sort by sequence number, just in case 306 table.sort(t["spool"] or NULL, function(a,b) return a.seq < b.seq; end); -- sort by sequence number, just in case
307 local time_offset = os.difftime(os.time(os.date("!*t")), os.time(os.date("*t"))) -- to deal with timezones 307 local time_offset = os.difftime(os.time(os.date("!*t")), os.time(os.date("*t"))) -- to deal with timezones
308 local date_parse = function(s) 308 local date_parse = function(s)
315 local last_child = stanza.tags[#stanza.tags]; 315 local last_child = stanza.tags[#stanza.tags];
316 if not last_child or last_child ~= stanza[#stanza] then error("Last child of offline message is not a tag"); end 316 if not last_child or last_child ~= stanza[#stanza] then error("Last child of offline message is not a tag"); end
317 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 317 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
318 stanza[#stanza], stanza.tags[#stanza.tags] = nil, nil; 318 stanza[#stanza], stanza.tags[#stanza.tags] = nil, nil;
319 local t = date_parse(last_child.attr.stamp); 319 local t = date_parse(last_child.attr.stamp);
320 offline_msg(row.username, host, t, stanza); 320 offline_msg(row.username, hostname, t, stanza);
321 else 321 else
322 print("[error] Offline message XML parsing failed: "..row.username.."@"..host); 322 print("[error] Offline message XML parsing failed: "..row.username.."@"..hostname);
323 end 323 end
324 end 324 end