Comparison

tools/ejabberdsql2prosody.lua @ 5991:a4b4b152a7d6

tools/ejabberdsql2prosody: Skip invalid XML in data, and print out errors.
author Waqas Hussain <waqas20@gmail.com>
date Thu, 16 Jan 2014 14:03:27 -0500
parent 5989:5aaddafe0beb
child 5993:ef11b8bab405
comparison
equal deleted inserted replaced
5990:bcf895ed1b65 5991:a4b4b152a7d6
289 end 289 end
290 for i, row in ipairs(t["rostergroups"] or NULL) do 290 for i, row in ipairs(t["rostergroups"] or NULL) do
291 roster_group(row.username, host, row.jid, row.grp); 291 roster_group(row.username, host, row.jid, row.grp);
292 end 292 end
293 for i, row in ipairs(t["vcard"] or NULL) do 293 for i, row in ipairs(t["vcard"] or NULL) do
294 local ret, err = dm.store(row.username, host, "vcard", st.preserialize(parse_xml(row.vcard))); 294 local stanza, err = parse_xml(row.vcard);
295 print("["..(err or "success").."] vCard: "..row.username.."@"..host); 295 if stanza then
296 local ret, err = dm.store(row.username, host, "vcard", st.preserialize(stanza));
297 print("["..(err or "success").."] vCard: "..row.username.."@"..host);
298 else
299 print("[error] vCard XML parse failed: "..row.username.."@"..host);
300 end
296 end 301 end
297 for i, row in ipairs(t["private_storage"] or NULL) do 302 for i, row in ipairs(t["private_storage"] or NULL) do
298 private_storage(row.username, host, row.namespace, parse_xml(row.data)); 303 local stanza, err = parse_xml(row.data);
304 if stanza then
305 private_storage(row.username, host, row.namespace, stanza);
306 else
307 print("[error] Private XML parse failed: "..row.username.."@"..host);
308 end
299 end 309 end
300 table.sort(t["spool"] or NULL, function(a,b) return a.seq < b.seq; end); -- sort by sequence number, just in case 310 table.sort(t["spool"] or NULL, function(a,b) return a.seq < b.seq; end); -- sort by sequence number, just in case
301 local time_offset = os.difftime(os.time(os.date("!*t")), os.time(os.date("*t"))) -- to deal with timezones 311 local time_offset = os.difftime(os.time(os.date("!*t")), os.time(os.date("*t"))) -- to deal with timezones
302 local date_parse = function(s) 312 local date_parse = function(s)
303 local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)"); 313 local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)");
304 return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec-time_offset}); 314 return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec-time_offset});
305 end 315 end
306 for i, row in ipairs(t["spool"] or NULL) do 316 for i, row in ipairs(t["spool"] or NULL) do
307 local stanza = parse_xml(row.xml); 317 local stanza, err = parse_xml(row.xml);
308 local last_child = stanza.tags[#stanza.tags]; 318 if stanza then
309 if not last_child or last_child ~= stanza[#stanza] then error("Last child of offline message is not a tag"); end 319 local last_child = stanza.tags[#stanza.tags];
310 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 320 if not last_child or last_child ~= stanza[#stanza] then error("Last child of offline message is not a tag"); end
311 stanza[#stanza], stanza.tags[#stanza.tags] = nil, nil; 321 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
312 local t = date_parse(last_child.attr.stamp); 322 stanza[#stanza], stanza.tags[#stanza.tags] = nil, nil;
313 offline_msg(row.username, host, t, stanza); 323 local t = date_parse(last_child.attr.stamp);
314 end 324 offline_msg(row.username, host, t, stanza);
325 else
326 print("[error] Offline message XML parsing failed: "..row.username.."@"..host);
327 end
328 end