Comparison

util/xmppstream.lua @ 8382:e5d00bf4a4d5

util: Various minor changes to please [luacheck]
author Kim Alvefur <zash@zash.se>
date Fri, 10 Nov 2017 05:42:32 +0100
parent 7240:bf8aa0d1951c
child 8555:4f0f5b49bb03
comparison
equal deleted inserted replaced
8381:7f6184474149 8382:e5d00bf4a4d5
45 local function new_sax_handlers(session, stream_callbacks, cb_handleprogress) 45 local function new_sax_handlers(session, stream_callbacks, cb_handleprogress)
46 local xml_handlers = {}; 46 local xml_handlers = {};
47 47
48 local cb_streamopened = stream_callbacks.streamopened; 48 local cb_streamopened = stream_callbacks.streamopened;
49 local cb_streamclosed = stream_callbacks.streamclosed; 49 local cb_streamclosed = stream_callbacks.streamclosed;
50 local cb_error = stream_callbacks.error or function(session, e, stanza) error("XML stream error: "..tostring(e)..(stanza and ": "..tostring(stanza) or ""),2); end; 50 local cb_error = stream_callbacks.error or
51 function(_, e, stanza)
52 error("XML stream error: "..tostring(e)..(stanza and ": "..tostring(stanza) or ""),2);
53 end;
51 local cb_handlestanza = stream_callbacks.handlestanza; 54 local cb_handlestanza = stream_callbacks.handlestanza;
52 cb_handleprogress = cb_handleprogress or dummy_cb; 55 cb_handleprogress = cb_handleprogress or dummy_cb;
53 56
54 local stream_ns = stream_callbacks.stream_ns or xmlns_streams; 57 local stream_ns = stream_callbacks.stream_ns or xmlns_streams;
55 local stream_tag = stream_callbacks.stream_tag or "stream"; 58 local stream_tag = stream_callbacks.stream_tag or "stream";
126 t_insert(oldstanza.tags, stanza); 129 t_insert(oldstanza.tags, stanza);
127 end 130 end
128 end 131 end
129 if lxp_supports_xmldecl then 132 if lxp_supports_xmldecl then
130 function xml_handlers:XmlDecl(version, encoding, standalone) 133 function xml_handlers:XmlDecl(version, encoding, standalone)
134 session.xml_version = version;
135 session.xml_encoding = encoding;
136 session.xml_standalone = standalone;
131 if lxp_supports_bytecount then 137 if lxp_supports_bytecount then
132 cb_handleprogress(self:getcurrentbytecount()); 138 cb_handleprogress(self:getcurrentbytecount());
133 end 139 end
134 end 140 end
135 end 141 end
212 local function reset() 218 local function reset()
213 stanza, chardata, stanza_size = nil, {}, 0; 219 stanza, chardata, stanza_size = nil, {}, 0;
214 stack = {}; 220 stack = {};
215 end 221 end
216 222
217 local function set_session(stream, new_session) 223 local function set_session(stream, new_session) -- luacheck: ignore 212/stream
218 session = new_session; 224 session = new_session;
219 end 225 end
220 226
221 return xml_handlers, { reset = reset, set_session = set_session }; 227 return xml_handlers, { reset = reset, set_session = set_session };
222 end 228 end
236 242
237 local handlers, meta = new_sax_handlers(session, stream_callbacks, handle_progress); 243 local handlers, meta = new_sax_handlers(session, stream_callbacks, handle_progress);
238 local parser = new_parser(handlers, ns_separator, false); 244 local parser = new_parser(handlers, ns_separator, false);
239 local parse = parser.parse; 245 local parse = parser.parse;
240 246
241 function session.open_stream(session, from, to) 247 function session.open_stream(session, from, to) -- luacheck: ignore 432/session
242 local send = session.sends2s or session.send; 248 local send = session.sends2s or session.send;
243 249
244 local attr = { 250 local attr = {
245 ["xmlns:stream"] = "http://etherx.jabber.org/streams", 251 ["xmlns:stream"] = "http://etherx.jabber.org/streams",
246 ["xml:lang"] = "en", 252 ["xml:lang"] = "en",
262 parser = new_parser(handlers, ns_separator, false); 268 parser = new_parser(handlers, ns_separator, false);
263 parse = parser.parse; 269 parse = parser.parse;
264 n_outstanding_bytes = 0; 270 n_outstanding_bytes = 0;
265 meta.reset(); 271 meta.reset();
266 end, 272 end,
267 feed = function (self, data) 273 feed = function (self, data) -- luacheck: ignore 212/self
268 if lxp_supports_bytecount then 274 if lxp_supports_bytecount then
269 n_outstanding_bytes = n_outstanding_bytes + #data; 275 n_outstanding_bytes = n_outstanding_bytes + #data;
270 end 276 end
271 local ok, err = parse(parser, data); 277 local ok, err = parse(parser, data);
272 if lxp_supports_bytecount and n_outstanding_bytes > stanza_size_limit then 278 if lxp_supports_bytecount and n_outstanding_bytes > stanza_size_limit then