Software /
code /
prosody
Comparison
tools/ejabberdsql2prosody.lua @ 7568:4f7990902874
ejabberdsql2prosody: rename variable 't' to prevent shadowing upvalues [luacheck]
Let's make the result of parseFile() have a more descriptive name.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Fri, 12 Aug 2016 13:51:38 +0800 |
parent | 7567:495de404a8ae |
child | 13142:879a6a33c21b |
comparison
equal
deleted
inserted
replaced
7567:495de404a8ae | 7568:4f7990902874 |
---|---|
195 ["users"] = {"username", "password"}; | 195 ["users"] = {"username", "password"}; |
196 ["vcard"] = {"username", "vcard"}; | 196 ["vcard"] = {"username", "vcard"}; |
197 --["vcard_search"] = {}; | 197 --["vcard_search"] = {}; |
198 } | 198 } |
199 local NULL = {}; | 199 local NULL = {}; |
200 local t = parseFile(arg); | 200 local parsed = parseFile(arg); |
201 for name, data in pairs(t) do | 201 for name, data in pairs(parsed) do |
202 local m = map[name]; | 202 local m = map[name]; |
203 if m then | 203 if m then |
204 if #data > 0 and #data[1] ~= #m then | 204 if #data > 0 and #data[1] ~= #m then |
205 print("[warning] expected "..#m.." columns for table `"..name.."`, found "..#data[1]); | 205 print("[warning] expected "..#m.." columns for table `"..name.."`, found "..#data[1]); |
206 end | 206 end |
213 end | 213 end |
214 end | 214 end |
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(parsed["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, hostname, "accounts", {password = password}); | 220 local ret, err = dm.store(node, hostname, "accounts", {password = password}); |
221 print("["..(err or "success").."] accounts: "..node.."@"..hostname); | 221 print("["..(err or "success").."] accounts: "..node.."@"..hostname); |
222 end | 222 end |
223 | 223 |
252 stanza.attr.stamp = os.date("!%Y-%m-%dT%H:%M:%SZ", t); | 252 stanza.attr.stamp = os.date("!%Y-%m-%dT%H:%M:%SZ", t); |
253 stanza.attr.stamp_legacy = os.date("!%Y%m%dT%H:%M:%S", t); | 253 stanza.attr.stamp_legacy = os.date("!%Y%m%dT%H:%M:%S", t); |
254 local ret, err = dm.list_append(node, host, "offline", st.preserialize(stanza)); | 254 local ret, err = dm.list_append(node, host, "offline", st.preserialize(stanza)); |
255 print("["..(err or "success").."] offline: " ..node.."@"..host.." - "..os.date("!%Y-%m-%dT%H:%M:%SZ", t)); | 255 print("["..(err or "success").."] offline: " ..node.."@"..host.." - "..os.date("!%Y-%m-%dT%H:%M:%SZ", t)); |
256 end | 256 end |
257 for _, row in ipairs(t["rosterusers"] or NULL) do | 257 for _, row in ipairs(parsed["rosterusers"] or NULL) do |
258 local node, contact = row.username, row.jid; | 258 local node, contact = row.username, row.jid; |
259 local name = row.nick; | 259 local name = row.nick; |
260 if name == "" then name = nil; end | 260 if name == "" then name = nil; end |
261 local subscription = row.subscription; | 261 local subscription = row.subscription; |
262 if subscription == "N" then | 262 if subscription == "N" then |
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, hostname, 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(parsed["rostergroups"] or NULL) do |
287 roster_group(row.username, hostname, 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(parsed["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, hostname, "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.."@"..hostname); | 293 print("["..(err or "success").."] vCard: "..row.username.."@"..hostname); |
294 else | 294 else |
295 print("[error] vCard XML parse failed: "..row.username.."@"..hostname); | 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(parsed["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, hostname, 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.."@"..hostname); | 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(parsed["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) |
309 local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)"); | 309 local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)"); |
310 return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec-time_offset}); | 310 return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec-time_offset}); |
311 end | 311 end |
312 for _, row in ipairs(t["spool"] or NULL) do | 312 for _, row in ipairs(parsed["spool"] or NULL) do |
313 local stanza, err = parse_xml(row.xml); | 313 local stanza, err = parse_xml(row.xml); |
314 if stanza then | 314 if stanza then |
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 |