comparison mod_storage_xmlarchive/mod_storage_xmlarchive.lua @ 1727:8f12afb633ec

mod_storage_xmlarchive: Attempt to recover after parse failures
author Kim Alvefur <zash@zash.se>
date Mon, 11 May 2015 14:17:35 +0200
parents 160c35d2a5a2
children a51beeb5aecf
comparison
equal deleted inserted replaced
1726:160c35d2a5a2 1727:8f12afb633ec
67 67
68 local stream_sess = { notopen = true }; 68 local stream_sess = { notopen = true };
69 local stream = new_stream(stream_sess, { handlestanza = cb, stream_ns = "jabber:client"}); 69 local stream = new_stream(stream_sess, { handlestanza = cb, stream_ns = "jabber:client"});
70 local dates = dm.list_load(username, module.host, self.store) or empty; 70 local dates = dm.list_load(username, module.host, self.store) or empty;
71 stream:feed(st.stanza("stream", { xmlns = "jabber:client" }):top_tag()); 71 stream:feed(st.stanza("stream", { xmlns = "jabber:client" }):top_tag());
72 stream_sess.notopen = nil; 72 local function reset_stream()
73 stream:reset();
74 stream_sess.notopen = true;
75 stream:feed(st.stanza("stream", { xmlns = "jabber:client" }):top_tag());
76 stream_sess.notopen = nil;
77 end
78 reset_stream();
73 79
74 local limit = query.limit; 80 local limit = query.limit;
75 local start_day, step, last_day = 1, 1, #dates; 81 local start_day, step, last_day = 1, 1, #dates;
76 local count = 0; 82 local count = 0;
77 local rev = query.reverse; 83 local rev = query.reverse;
138 xmlfile:seek("set", item.offset); 144 xmlfile:seek("set", item.offset);
139 local data = xmlfile:read(item.length); 145 local data = xmlfile:read(item.length);
140 local ok, err = stream:feed(data); 146 local ok, err = stream:feed(data);
141 if not ok then 147 if not ok then
142 module:log("warn", "Parse error in %s at %d+%d: %s", filename, item.offset, item.length, err); 148 module:log("warn", "Parse error in %s at %d+%d: %s", filename, item.offset, item.length, err);
149 reset_stream();
143 end 150 end
144 if result then 151 if result then
145 local stanza = result; 152 local stanza = result;
146 result = nil; 153 result = nil;
147 return item.id, stanza, item.when, item.with; 154 return item.id, stanza, item.when, item.with;