Changeset

8382:e5d00bf4a4d5

util: Various minor changes to please [luacheck]
author Kim Alvefur <zash@zash.se>
date Fri, 10 Nov 2017 05:42:32 +0100
parents 8381:7f6184474149
children 8383:d967d6f2ad00
files util/adhoc.lua util/debug.lua util/events.lua util/format.lua util/indexedbheap.lua util/ip.lua util/json.lua util/multitable.lua util/openssl.lua util/pluginloader.lua util/pubsub.lua util/sasl.lua util/sasl/anonymous.lua util/sasl/scram.lua util/sql.lua util/stanza.lua util/vcard.lua util/xmppstream.lua
diffstat 18 files changed, 107 insertions(+), 115 deletions(-) [+]
line wrap: on
line diff
--- a/util/adhoc.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/adhoc.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -1,3 +1,5 @@
+-- luacheck: ignore 212/self
+
 local function new_simple_form(form, result_handler)
 	return function(self, data, state)
 		if state then
--- a/util/debug.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/debug.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -113,7 +113,9 @@
 
 local function build_source_boundary_marker(last_source_desc)
 	local padding = string.rep("-", math.floor(((optimal_line_length - 6) - #last_source_desc)/2));
-	return getstring(styles.boundary_padding, "v"..padding).." "..getstring(styles.filename, last_source_desc).." "..getstring(styles.boundary_padding, padding..(#last_source_desc%2==0 and "-v" or "v "));
+	return getstring(styles.boundary_padding, "v"..padding).." "..
+		getstring(styles.filename, last_source_desc).." "..
+		getstring(styles.boundary_padding, padding..(#last_source_desc%2==0 and "-v" or "v "));
 end
 
 local function _traceback(thread, message, level)
@@ -143,9 +145,9 @@
 	local last_source_desc;
 
 	local lines = {};
-	for nlevel, level in ipairs(levels) do
-		local info = level.info;
-		local line = "...";
+	for nlevel, current_level in ipairs(levels) do
+		local info = current_level.info;
+		local line;
 		local func_type = info.namewhat.." ";
 		local source_desc = (info.short_src == "[C]" and "C code") or info.short_src or "Unknown";
 		if func_type == " " then func_type = ""; end;
@@ -161,7 +163,9 @@
 			if func_type == "global " or func_type == "local " then
 				func_type = func_type.."function ";
 			end
-			line = "[Lua] "..getstring(styles.location, info.short_src.." line "..info.currentline).." in "..func_type..getstring(styles.funcname, name).." (defined on line "..info.linedefined..")";
+			line = "[Lua] "..getstring(styles.location, info.short_src.." line "..
+				info.currentline).." in "..func_type..getstring(styles.funcname, name)..
+				" (defined on line "..info.linedefined..")";
 		end
 		if source_desc ~= last_source_desc then -- Venturing into a new source, add marker for previous
 			last_source_desc = source_desc;
@@ -170,13 +174,13 @@
 		nlevel = nlevel-1;
 		table.insert(lines, "\t"..(nlevel==0 and ">" or " ")..getstring(styles.level_num, "("..nlevel..") ")..line);
 		local npadding = (" "):rep(#tostring(nlevel));
-		if level.locals then
-			local locals_str = string_from_var_table(level.locals, optimal_line_length, "\t            "..npadding);
+		if current_level.locals then
+			local locals_str = string_from_var_table(current_level.locals, optimal_line_length, "\t            "..npadding);
 			if locals_str then
 				table.insert(lines, "\t    "..npadding.."Locals: "..locals_str);
 			end
 		end
-		local upvalues_str = string_from_var_table(level.upvalues, optimal_line_length, "\t            "..npadding);
+		local upvalues_str = string_from_var_table(current_level.upvalues, optimal_line_length, "\t            "..npadding);
 		if upvalues_str then
 			table.insert(lines, "\t    "..npadding.."Upvals: "..upvalues_str);
 		end
--- a/util/events.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/events.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -26,7 +26,7 @@
 	-- Event map: event_map[handler_function] = priority_number
 	local event_map = {};
 	-- Called on-demand to build handlers entries
-	local function _rebuild_index(handlers, event)
+	local function _rebuild_index(self, event)
 		local _handlers = event_map[event];
 		if not _handlers or next(_handlers) == nil then return; end
 		local index = {};
@@ -34,7 +34,7 @@
 			t_insert(index, handler);
 		end
 		t_sort(index, function(a, b) return _handlers[a] > _handlers[b]; end);
-		handlers[event] = index;
+		self[event] = index;
 		return index;
 	end;
 	setmetatable(handlers, { __index = _rebuild_index });
@@ -61,13 +61,13 @@
 	local function get_handlers(event)
 		return handlers[event];
 	end;
-	local function add_handlers(handlers)
-		for event, handler in pairs(handlers) do
+	local function add_handlers(self)
+		for event, handler in pairs(self) do
 			add_handler(event, handler);
 		end
 	end;
-	local function remove_handlers(handlers)
-		for event, handler in pairs(handlers) do
+	local function remove_handlers(self)
+		for event, handler in pairs(self) do
 			remove_handler(event, handler);
 		end
 	end;
@@ -81,6 +81,7 @@
 		end
 	end;
 	local function fire_event(event_name, event_data)
+		-- luacheck: ignore 432/event_name 432/event_data
 		local w = wrappers[event_name] or global_wrappers;
 		if w then
 			local curr_wrapper = #w;
--- a/util/format.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/format.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -8,7 +8,7 @@
 local unpack = unpack;
 local type = type;
 
-local function format(format, ...)
+local function format(formatstring, ...)
 	local args, args_length = { ... }, select('#', ...);
 
 	-- format specifier spec:
@@ -25,7 +25,7 @@
 
 	-- process each format specifier
 	local i = 0;
-	format = format:gsub("%%[^cdiouxXaAeEfgGqs%%]*[cdiouxXaAeEfgGqs%%]", function(spec)
+	formatstring = formatstring:gsub("%%[^cdiouxXaAeEfgGqs%%]*[cdiouxXaAeEfgGqs%%]", function(spec)
 		if spec ~= "%%" then
 			i = i + 1;
 			local arg = args[i];
@@ -54,10 +54,10 @@
 		else
 			args[i] = tostring(arg);
 		end
-		format = format .. " [%s]"
+		formatstring = formatstring .. " [%s]"
 	end
 
-	return format:format(unpack(args));
+	return formatstring:format(unpack(args));
 end
 
 local function test()
--- a/util/indexedbheap.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/indexedbheap.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -110,7 +110,7 @@
 	self.priorities[k] = priority;
 
 	k = _percolate_up(self.priorities, k, self.ids, self.index);
-	k = _percolate_down(self.priorities, k, self.ids, self.index);
+	_percolate_down(self.priorities, k, self.ids, self.index);
 end
 function indexed_heap:remove_index(k)
 	local result = self.priorities[k];
@@ -132,7 +132,7 @@
 
 	if size > k then
 		k = _percolate_up(self.priorities, k, self.ids, self.index);
-		k = _percolate_down(self.priorities, k, self.ids, self.index);
+		_percolate_down(self.priorities, k, self.ids, self.index);
 	end
 
 	return result, item, result_sync;
--- a/util/ip.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/ip.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -9,7 +9,12 @@
 local ip_mt = { __index = function (ip, key) return (ip_methods[key])(ip); end,
 		__tostring = function (ip) return ip.addr; end,
 		__eq = function (ipA, ipB) return ipA.addr == ipB.addr; end};
-local hex2bits = { ["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011", ["4"] = "0100", ["5"] = "0101", ["6"] = "0110", ["7"] = "0111", ["8"] = "1000", ["9"] = "1001", ["A"] = "1010", ["B"] = "1011", ["C"] = "1100", ["D"] = "1101", ["E"] = "1110", ["F"] = "1111" };
+local hex2bits = {
+	["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011",
+	["4"] = "0100", ["5"] = "0101", ["6"] = "0110", ["7"] = "0111",
+	["8"] = "1000", ["9"] = "1001", ["A"] = "1010", ["B"] = "1011",
+	["C"] = "1100", ["D"] = "1101", ["E"] = "1110", ["F"] = "1111",
+};
 
 local function new_ip(ipStr, proto)
 	if not proto then
--- a/util/json.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/json.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -27,9 +27,6 @@
 local escapes = {
 	["\""] = "\\\"", ["\\"] = "\\\\", ["\b"] = "\\b",
 	["\f"] = "\\f", ["\n"] = "\\n", ["\r"] = "\\r", ["\t"] = "\\t"};
-local unescapes = {
-	["\""] = "\"", ["\\"] = "\\", ["/"] = "/",
-	b = "\b", f = "\f", n = "\n", r = "\r", t = "\t"};
 for i=0,31 do
 	local ch = s_char(i);
 	if not escapes[ch] then escapes[ch] = ("\\u%.4X"):format(i); end
@@ -249,7 +246,7 @@
 	end
 end
 local _unescape_error;
-local function _unescape_surrogate_func(x)
+local function _unescape_surrogate_func(x) -- luacheck: ignore
 	local lead, trail = tonumber(x:sub(3, 6), 16), tonumber(x:sub(9, 12), 16);
 	local codepoint = lead * 0x400 + trail - 0x35FDC00;
 	local a = codepoint % 64;
--- a/util/multitable.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/multitable.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -132,7 +132,7 @@
 	local maxdepth = select("#", ...);
 	local stack = { self.data };
 	local keys = { };
-	local function it(self)
+	local function it(self) -- luacheck: ignore 432/self
 		local depth = #stack;
 		local key = next(stack[depth], keys[depth]);
 		if key == nil then -- Go up the stack
--- a/util/openssl.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/openssl.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -114,7 +114,7 @@
 		s_format("%s;%s", oid_xmppaddr, utf8string(host)));
 end
 
-function ssl_config:from_prosody(hosts, config, certhosts)
+function ssl_config:from_prosody(hosts, config, certhosts) -- luacheck: ignore 431/config
 	-- TODO Decide if this should go elsewhere
 	local found_matching_hosts = false;
 	for i = 1, #certhosts do
--- a/util/pluginloader.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/pluginloader.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -5,6 +5,7 @@
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
 --
+-- luacheck: ignore 113/CFG_PLUGINDIR
 
 local dir_sep, path_sep = package.config:match("^(%S+)%s(%S+)");
 local plugin_dir = {};
--- a/util/pubsub.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/pubsub.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -177,18 +177,6 @@
 	return true;
 end
 
-function service:remove_all_subscriptions(actor, jid)
-	local normal_jid = self.config.normalize_jid(jid);
-	local subs = self.subscriptions[normal_jid]
-	subs = subs and subs[jid];
-	if subs then
-		for node in pairs(subs) do
-			self:remove_subscription(node, true, jid);
-		end
-	end
-	return true;
-end
-
 function service:get_subscription(node, actor, jid)
 	-- Access checking
 	local cap;
--- a/util/sasl.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/sasl.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -42,7 +42,7 @@
 
 local method = {};
 method.__index = method;
-local mechanisms = {};
+local registered_mechanisms = {};
 local backend_mechanism = {};
 local mechanism_channelbindings = {};
 
@@ -52,7 +52,7 @@
 	assert(type(backends) == "string" or type(backends) == "table", "Parameter backends MUST be either a string or a table.");
 	assert(type(f) == "function", "Parameter f MUST be a function.");
 	if cb_backends then assert(type(cb_backends) == "table"); end
-	mechanisms[name] = f
+	registered_mechanisms[name] = f
 	if cb_backends then
 		mechanism_channelbindings[name] = {};
 		for _, cb_name in ipairs(cb_backends) do
@@ -70,7 +70,7 @@
 	local mechanisms = profile.mechanisms;
 	if not mechanisms then
 		mechanisms = {};
-		for backend, f in pairs(profile) do
+		for backend in pairs(profile) do
 			if backend_mechanism[backend] then
 				for _, mechanism in ipairs(backend_mechanism[backend]) do
 					mechanisms[mechanism] = true;
@@ -128,7 +128,7 @@
 -- feed new messages to process into the library
 function method:process(message)
 	--if message == "" or message == nil then return "failure", "malformed-request" end
-	return mechanisms[self.selected](self, message);
+	return registered_mechanisms[self.selected](self, message);
 end
 
 -- load the mechanisms
--- a/util/sasl/anonymous.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/sasl/anonymous.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -28,7 +28,7 @@
 	end
 ]]
 
-local function anonymous(self, message)
+local function anonymous(self, message) -- luacheck: ignore 212/message
 	local username;
 	repeat
 		username = generate_uuid();
--- a/util/sasl/scram.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/sasl/scram.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -46,7 +46,18 @@
 
 local default_i = 4096
 
-local xor_map = {0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;1;0;3;2;5;4;7;6;9;8;11;10;13;12;15;14;2;3;0;1;6;7;4;5;10;11;8;9;14;15;12;13;3;2;1;0;7;6;5;4;11;10;9;8;15;14;13;12;4;5;6;7;0;1;2;3;12;13;14;15;8;9;10;11;5;4;7;6;1;0;3;2;13;12;15;14;9;8;11;10;6;7;4;5;2;3;0;1;14;15;12;13;10;11;8;9;7;6;5;4;3;2;1;0;15;14;13;12;11;10;9;8;8;9;10;11;12;13;14;15;0;1;2;3;4;5;6;7;9;8;11;10;13;12;15;14;1;0;3;2;5;4;7;6;10;11;8;9;14;15;12;13;2;3;0;1;6;7;4;5;11;10;9;8;15;14;13;12;3;2;1;0;7;6;5;4;12;13;14;15;8;9;10;11;4;5;6;7;0;1;2;3;13;12;15;14;9;8;11;10;5;4;7;6;1;0;3;2;14;15;12;13;10;11;8;9;6;7;4;5;2;3;0;1;15;14;13;12;11;10;9;8;7;6;5;4;3;2;1;0;};
+local xor_map = {
+	0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1,0,3,2,5,4,7,6,9,8,11,10,
+	13,12,15,14,2,3,0,1,6,7,4,5,10,11,8,9,14,15,12,13,3,2,1,0,7,6,5,
+	4,11,10,9,8,15,14,13,12,4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11,5,
+	4,7,6,1,0,3,2,13,12,15,14,9,8,11,10,6,7,4,5,2,3,0,1,14,15,12,13,
+	10,11,8,9,7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8,8,9,10,11,12,13,
+	14,15,0,1,2,3,4,5,6,7,9,8,11,10,13,12,15,14,1,0,3,2,5,4,7,6,10,
+	11,8,9,14,15,12,13,2,3,0,1,6,7,4,5,11,10,9,8,15,14,13,12,3,2,1,
+	0,7,6,5,4,12,13,14,15,8,9,10,11,4,5,6,7,0,1,2,3,13,12,15,14,9,8,
+	11,10,5,4,7,6,1,0,3,2,14,15,12,13,10,11,8,9,6,7,4,5,2,3,0,1,15,
+	14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,
+};
 
 local result = {};
 local function binaryXOR( a, b )
@@ -237,10 +248,14 @@
 
 local function init(registerMechanism)
 	local function registerSCRAMMechanism(hash_name, hash, hmac_hash)
-		registerMechanism("SCRAM-"..hash_name, {"plain", "scram_"..(hashprep(hash_name))}, scram_gen(hash_name:lower(), hash, hmac_hash));
+		registerMechanism("SCRAM-"..hash_name,
+			{"plain", "scram_"..(hashprep(hash_name))},
+			scram_gen(hash_name:lower(), hash, hmac_hash));
 
 		-- register channel binding equivalent
-		registerMechanism("SCRAM-"..hash_name.."-PLUS", {"plain", "scram_"..(hashprep(hash_name))}, scram_gen(hash_name:lower(), hash, hmac_hash), {"tls-unique"});
+		registerMechanism("SCRAM-"..hash_name.."-PLUS",
+			{"plain", "scram_"..(hashprep(hash_name))},
+			scram_gen(hash_name:lower(), hash, hmac_hash), {"tls-unique"});
 	end
 
 	registerSCRAMMechanism("SHA-1", sha1, hmac_sha1);
--- a/util/sql.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/sql.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -1,11 +1,10 @@
 
 local setmetatable, getmetatable = setmetatable, getmetatable;
 local ipairs, unpack, select = ipairs, table.unpack or unpack, select; --luacheck: ignore 113
-local tonumber, tostring = tonumber, tostring;
+local tostring = tostring;
 local type = type;
 local assert, pcall, xpcall, debug_traceback = assert, pcall, xpcall, debug.traceback;
 local t_concat = table.concat;
-local s_char = string.char;
 local log = require "util.logger".init("sql");
 
 local DBI = require "DBI";
@@ -58,9 +57,6 @@
 function table_mt.__index:create(engine)
 	return engine:_create_table(self);
 end
-function table_mt:__call(...)
-	-- TODO
-end
 function column_mt:__tostring()
 	return 'Column{ name="'..self.name..'", type="'..self.type..'" }'
 end
@@ -71,31 +67,6 @@
 --	return 'Index{ name="'..self.name..'", type="'..self.type..'" }'
 end
 
-local function urldecode(s) return s and (s:gsub("%%(%x%x)", function (c) return s_char(tonumber(c,16)); end)); end
-local function parse_url(url)
-	local scheme, secondpart, database = url:match("^([%w%+]+)://([^/]*)/?(.*)");
-	assert(scheme, "Invalid URL format");
-	local username, password, host, port;
-	local authpart, hostpart = secondpart:match("([^@]+)@([^@+])");
-	if not authpart then hostpart = secondpart; end
-	if authpart then
-		username, password = authpart:match("([^:]*):(.*)");
-		username = username or authpart;
-		password = password and urldecode(password);
-	end
-	if hostpart then
-		host, port = hostpart:match("([^:]*):(.*)");
-		host = host or hostpart;
-		port = port and assert(tonumber(port), "Invalid URL format");
-	end
-	return {
-		scheme = scheme:lower();
-		username = username; password = password;
-		host = host; port = port;
-		database = #database > 0 and database or nil;
-	};
-end
-
 local engine = {};
 function engine:connect()
 	if self.conn then return true; end
@@ -123,7 +94,7 @@
 	end
 	return true;
 end
-function engine:onconnect()
+function engine:onconnect() -- luacheck: ignore 212/self
 	-- Override from create_engine()
 end
 
@@ -148,6 +119,7 @@
 		prepared[sql] = stmt;
 	end
 
+	-- luacheck: ignore 411/success
 	local success, err = stmt:execute(...);
 	if not success then return success, err; end
 	return stmt;
@@ -335,7 +307,12 @@
 	local charset = "utf8";
 	if driver == "MySQL" then
 		self:transaction(function()
-			for row in self:select"SELECT \"CHARACTER_SET_NAME\" FROM \"information_schema\".\"CHARACTER_SETS\" WHERE \"CHARACTER_SET_NAME\" LIKE 'utf8%' ORDER BY MAXLEN DESC LIMIT 1;" do
+			for row in self:select[[
+				SELECT "CHARACTER_SET_NAME"
+				FROM "information_schema"."CHARACTER_SETS"
+				WHERE "CHARACTER_SET_NAME" LIKE 'utf8%'
+				ORDER BY MAXLEN DESC LIMIT 1;
+				]] do
 				charset = row and row[1] or charset;
 			end
 		end);
@@ -379,7 +356,7 @@
 	};
 end
 
-local function create_engine(self, params, onconnect)
+local function create_engine(_, params, onconnect)
 	return setmetatable({ url = db2uri(params), params = params, onconnect = onconnect }, engine_mt);
 end
 
--- a/util/stanza.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/stanza.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -367,7 +367,13 @@
 end
 
 local function reply(orig)
-	return new_stanza(orig.name, orig.attr and { to = orig.attr.from, from = orig.attr.to, id = orig.attr.id, type = ((orig.name == "iq" and "result") or orig.attr.type) });
+	return new_stanza(orig.name,
+		orig.attr and {
+			to = orig.attr.from,
+			from = orig.attr.to,
+			id = orig.attr.id,
+			type = ((orig.name == "iq" and "result") or orig.attr.type)
+		});
 end
 
 local xmpp_stanzas_attr = { xmlns = xmlns_stanzas };
--- a/util/vcard.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/vcard.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -10,7 +10,7 @@
 local st = require "util.stanza";
 local t_insert, t_concat = table.insert, table.concat;
 local type = type;
-local next, pairs, ipairs = next, pairs, ipairs;
+local pairs, ipairs = pairs, ipairs;
 
 local from_text, to_text, from_xep54, to_xep54;
 
@@ -19,14 +19,6 @@
 local vCard_dtd; -- See end of file
 local vCard4_dtd;
 
-local function fold_line()
-	error "Not implemented" --TODO
-end
-local function unfold_line()
-	error "Not implemented"
-	-- gsub("\r?\n[ \t]([^\r\n])", "%1");
-end
-
 local function vCard_esc(s)
 	return s:gsub("[,:;\\]", "\\%1"):gsub("\n","\\n");
 end
@@ -116,9 +108,9 @@
 		:gsub("\n ", "")
 		:gsub("\n\n+","\n");
 	local vCards = {};
-	local c; -- current item
+	local current;
 	for line in data:gmatch("[^\n]+") do
-		local line = vCard_unesc(line);
+		line = vCard_unesc(line);
 		local name, params, value = line:match("^([-%a]+)(\30?[^\29]*)\29(.*)$");
 		value = value:gsub("\29",":");
 		if #params > 0 then
@@ -139,23 +131,22 @@
 			params = _params;
 		end
 		if name == "BEGIN" and value == "VCARD" then
-			c = {};
-			vCards[#vCards+1] = c;
+			current = {};
+			vCards[#vCards+1] = current;
 		elseif name == "END" and value == "VCARD" then
-			c = nil;
-		elseif c and vCard_dtd[name] then
+			current = nil;
+		elseif current and vCard_dtd[name] then
 			local dtd = vCard_dtd[name];
-			local p = { name = name };
-			c[#c+1]=p;
-			--c[name]=p;
-			local up = c;
-			c = p;
+			local item = { name = name };
+			t_insert(current, item);
+			local up = current;
+			current = item;
 			if dtd.types then
 				for _, t in ipairs(dtd.types) do
-					local t = t:lower();
+					t = t:lower();
 					if ( params.TYPE and params.TYPE[t] == true)
 							or params[t] == true then
-						c.TYPE=t;
+						current.TYPE=t;
 					end
 				end
 			end
@@ -163,24 +154,23 @@
 				for _, p in ipairs(dtd.props) do
 					if params[p] then
 						if params[p] == true then
-							c[p]=true;
+							current[p]=true;
 						else
 							for _, prop in ipairs(params[p]) do
-								c[p]=prop;
+								current[p]=prop;
 							end
 						end
 					end
 				end
 			end
 			if dtd == "text" or dtd.value then
-				t_insert(c, value);
+				t_insert(current, value);
 			elseif dtd.values then
-				local value = "\30"..value;
-				for p in value:gmatch("\30([^\30]*)") do
-					t_insert(c, p);
+				for p in ("\30"..value):gmatch("\30([^\30]*)") do
+					t_insert(current, p);
 				end
 			end
-			c = up;
+			current = up;
 		end
 	end
 	return vCards;
@@ -322,7 +312,7 @@
 
 local vcard4 = { }
 
-function vcard4:text(node, params, value)
+function vcard4:text(node, params, value) -- luacheck: ignore 212/params
 	self:tag(node:lower())
 	-- FIXME params
 	if type(value) == "string" then
--- a/util/xmppstream.lua	Fri Nov 10 05:34:29 2017 +0100
+++ b/util/xmppstream.lua	Fri Nov 10 05:42:32 2017 +0100
@@ -47,7 +47,10 @@
 
 	local cb_streamopened = stream_callbacks.streamopened;
 	local cb_streamclosed = stream_callbacks.streamclosed;
-	local cb_error = stream_callbacks.error or function(session, e, stanza) error("XML stream error: "..tostring(e)..(stanza and ": "..tostring(stanza) or ""),2); end;
+	local cb_error = stream_callbacks.error or
+		function(_, e, stanza)
+			error("XML stream error: "..tostring(e)..(stanza and ": "..tostring(stanza) or ""),2);
+		end;
 	local cb_handlestanza = stream_callbacks.handlestanza;
 	cb_handleprogress = cb_handleprogress or dummy_cb;
 
@@ -128,6 +131,9 @@
 	end
 	if lxp_supports_xmldecl then
 		function xml_handlers:XmlDecl(version, encoding, standalone)
+			session.xml_version = version;
+			session.xml_encoding = encoding;
+			session.xml_standalone = standalone;
 			if lxp_supports_bytecount then
 				cb_handleprogress(self:getcurrentbytecount());
 			end
@@ -214,7 +220,7 @@
 		stack = {};
 	end
 
-	local function set_session(stream, new_session)
+	local function set_session(stream, new_session) -- luacheck: ignore 212/stream
 		session = new_session;
 	end
 
@@ -238,7 +244,7 @@
 	local parser = new_parser(handlers, ns_separator, false);
 	local parse = parser.parse;
 
-	function session.open_stream(session, from, to)
+	function session.open_stream(session, from, to) -- luacheck: ignore 432/session
 		local send = session.sends2s or session.send;
 
 		local attr = {
@@ -264,7 +270,7 @@
 			n_outstanding_bytes = 0;
 			meta.reset();
 		end,
-		feed = function (self, data)
+		feed = function (self, data) -- luacheck: ignore 212/self
 			if lxp_supports_bytecount then
 				n_outstanding_bytes = n_outstanding_bytes + #data;
 			end