Comparison

util/xmppstream.lua @ 6777:5de6b93d0190

util.*: Remove use of module() function, make all module functions local and return them in a table at the end
author Kim Alvefur <zash@zash.se>
date Sat, 21 Feb 2015 10:36:37 +0100
parent 6367:769a3577dd85
child 6978:30c96a5db360
comparison
equal deleted inserted replaced
6774:3965662ae091 6777:5de6b93d0190
22 local lxp_supports_xmldecl = pcall(lxp.new, { XmlDecl = false }); 22 local lxp_supports_xmldecl = pcall(lxp.new, { XmlDecl = false });
23 local lxp_supports_bytecount = not not lxp.new({}).getcurrentbytecount; 23 local lxp_supports_bytecount = not not lxp.new({}).getcurrentbytecount;
24 24
25 local default_stanza_size_limit = 1024*1024*10; -- 10MB 25 local default_stanza_size_limit = 1024*1024*10; -- 10MB
26 26
27 module "xmppstream" 27 local _ENV = nil;
28 28
29 local new_parser = lxp.new; 29 local new_parser = lxp.new;
30 30
31 local xml_namespace = { 31 local xml_namespace = {
32 ["http://www.w3.org/XML/1998/namespace\1lang"] = "xml:lang"; 32 ["http://www.w3.org/XML/1998/namespace\1lang"] = "xml:lang";
38 local xmlns_streams = "http://etherx.jabber.org/streams"; 38 local xmlns_streams = "http://etherx.jabber.org/streams";
39 39
40 local ns_separator = "\1"; 40 local ns_separator = "\1";
41 local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$"; 41 local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$";
42 42
43 _M.ns_separator = ns_separator;
44 _M.ns_pattern = ns_pattern;
45
46 local function dummy_cb() end 43 local function dummy_cb() end
47 44
48 function new_sax_handlers(session, stream_callbacks, cb_handleprogress) 45 local function new_sax_handlers(session, stream_callbacks, cb_handleprogress)
49 local xml_handlers = {}; 46 local xml_handlers = {};
50 47
51 local cb_streamopened = stream_callbacks.streamopened; 48 local cb_streamopened = stream_callbacks.streamopened;
52 local cb_streamclosed = stream_callbacks.streamclosed; 49 local cb_streamclosed = stream_callbacks.streamclosed;
53 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 function(session, e, stanza) error("XML stream error: "..tostring(e)..(stanza and ": "..tostring(stanza) or ""),2); end;
222 end 219 end
223 220
224 return xml_handlers, { reset = reset, set_session = set_session }; 221 return xml_handlers, { reset = reset, set_session = set_session };
225 end 222 end
226 223
227 function new(session, stream_callbacks, stanza_size_limit) 224 local function new(session, stream_callbacks, stanza_size_limit)
228 -- Used to track parser progress (e.g. to enforce size limits) 225 -- Used to track parser progress (e.g. to enforce size limits)
229 local n_outstanding_bytes = 0; 226 local n_outstanding_bytes = 0;
230 local handle_progress; 227 local handle_progress;
231 if lxp_supports_bytecount then 228 if lxp_supports_bytecount then
232 function handle_progress(n_parsed_bytes) 229 function handle_progress(n_parsed_bytes)
279 end, 276 end,
280 set_session = meta.set_session; 277 set_session = meta.set_session;
281 }; 278 };
282 end 279 end
283 280
284 return _M; 281 return {
282 ns_separator = ns_separator;
283 ns_pattern = ns_pattern;
284 new_sax_handlers = new_sax_handlers;
285 new = new;
286 };