From 3829ac306eaf47e5f056cbe9acbdb81cc60e95ef Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 6 Mar 2017 15:09:22 +0100 Subject: mod_adhoc/adhoc.lib: instantiate table with all fields --- plugins/adhoc/adhoc.lib.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/adhoc/adhoc.lib.lua b/plugins/adhoc/adhoc.lib.lua index 5c90c91b..87415636 100644 --- a/plugins/adhoc/adhoc.lib.lua +++ b/plugins/adhoc/adhoc.lib.lua @@ -27,11 +27,12 @@ end function _M.handle_cmd(command, origin, stanza) local cmdtag = stanza.tags[1] local sessionid = cmdtag.attr.sessionid or uuid.generate(); - local dataIn = {}; - dataIn.to = stanza.attr.to; - dataIn.from = stanza.attr.from; - dataIn.action = cmdtag.attr.action or "execute"; - dataIn.form = cmdtag:get_child("x", "jabber:x:data"); + local dataIn = { + to = stanza.attr.to; + from = stanza.attr.from; + action = cmdtag.attr.action or "execute"; + form = cmdtag:get_child("x", "jabber:x:data"); + }; local data, state = command:handler(dataIn, states[sessionid]); states[sessionid] = state; -- cgit v1.2.3 From aee5e50efaad3559188fac8800fed9540876eaa6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 6 Mar 2017 15:11:37 +0100 Subject: luacheckrc: Include entire module API --- .luacheckrc | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/.luacheckrc b/.luacheckrc index 0040cfbb..e422ea2e 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -14,7 +14,79 @@ files["core/"] = { globals = { "prosody.hosts.?", "hosts.?" }; } files["plugins/"] = { - globals = { "module" }; + read_globals = { + -- Module instance + "module.name", + "module.host", + "module._log", + "module.log", + "module.event_handlers", + "module.reloading", + "module.saved_state", + "module.environment", + "module.global", + "module.path", + + -- Module API + "module.add_extension", + "module.add_feature", + "module.add_identity", + "module.add_item", + "module.add_timer", + "module.broadcast", + "module.context", + "module.depends", + "module.fire_event", + "module.get_directory", + "module.get_host", + "module.get_host_items", + "module.get_host_type", + "module.get_name", + "module.get_option", + "module.get_option_array", + "module.get_option_boolean", + "module.get_option_inherited_set", + "module.get_option_number", + "module.get_option_path", + "module.get_option_set", + "module.get_option_string", + "module.handle_items", + "module.has_feature", + "module.has_identity", + "module.hook", + "module.hook_global", + "module.hook_object_event", + "module.hook_tag", + "module.load_resource", + "module.measure", + "module.measure_event", + "module.measure_global_event", + "module.measure_object_event", + "module.open_store", + "module.provides", + "module.remove_item", + "module.require", + "module.send", + "module.set_global", + "module.shared", + "module.unhook", + "module.unhook_object_event", + "module.wrap_event", + "module.wrap_global", + "module.wrap_object_event", + }; + globals = { + "_M", + + -- Methods that can be set on module API + "module.unload", + "module.add_host", + "module.load", + "module.add_host", + "module.save", + "module.restore", + "module.command", + }; } files["tests/"] = { read_globals = { -- cgit v1.2.3 From d31b2b4f418cb1ef6f19c318f39ea82060108e4f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 6 Mar 2017 15:22:00 +0100 Subject: luacheckrc: Ignore shadowing of logger --- .luacheckrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.luacheckrc b/.luacheckrc index e422ea2e..d931da66 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -5,7 +5,7 @@ allow_defined_top = true module = true unused_secondaries = false codes = true -ignore = { "411/err", "421/err", "411/ok", "421/ok", "211/_ENV" } +ignore = { "411/err", "421/err", "411/ok", "421/ok", "211/_ENV", "431/log" } max_line_length = 150 -- cgit v1.2.3 From 71d437db39b20050a81c6f7d02abbf4e2cca4e31 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 6 Mar 2017 15:24:33 +0100 Subject: mod_c2s: Rename variable no avoid name clash [luacheck] --- plugins/mod_c2s.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index 1374c108..a654213c 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -169,27 +169,27 @@ local function session_close(session, reason) session.send(""); function session.send() return false; end - local reason = (reason and (reason.name or reason.text or reason.condition)) or reason; - session.log("debug", "c2s stream for %s closed: %s", session.full_jid or ("<"..session.ip..">"), reason or "session closed"); + local reason_text = (reason and (reason.name or reason.text or reason.condition)) or reason; + session.log("debug", "c2s stream for %s closed: %s", session.full_jid or ("<"..session.ip..">"), reason_text or "session closed"); -- Authenticated incoming stream may still be sending us stanzas, so wait for from remote local conn = session.conn; - if reason == nil and not session.notopen and session.type == "c2s" then + if reason_text == nil and not session.notopen and session.type == "c2s" then -- Grace time to process data from authenticated cleanly-closed stream add_task(stream_close_timeout, function () if not session.destroyed then session.log("warn", "Failed to receive a stream close response, closing connection anyway..."); - sm_destroy_session(session, reason); + sm_destroy_session(session, reason_text); conn:close(); end end); else - sm_destroy_session(session, reason); + sm_destroy_session(session, reason_text); conn:close(); end else - local reason = (reason and (reason.name or reason.text or reason.condition)) or reason; - sm_destroy_session(session, reason); + local reason_text = (reason and (reason.name or reason.text or reason.condition)) or reason; + sm_destroy_session(session, reason_text); end end -- cgit v1.2.3 From 7e8dcd944e500bb5eae41a50826226bc13e0ae85 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 6 Mar 2017 15:24:44 +0100 Subject: mod_c2s: Rename unused loop variable to _ [luacheck] --- plugins/mod_c2s.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index a654213c..cfeb0f0e 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -197,7 +197,7 @@ module:hook_global("user-deleted", function(event) local username, host = event.username, event.host; local user = hosts[host].sessions[username]; if user and user.sessions then - for jid, session in pairs(user.sessions) do + for _, session in pairs(user.sessions) do session:close{ condition = "not-authorized", text = "Account deleted" }; end end -- cgit v1.2.3 From 11dc53576d751ef7e62bc439831d35f74de74e5b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 6 Mar 2017 15:27:37 +0100 Subject: mod_message: Return early on messages of type error (silences empty if branch warning) [luacheck] --- plugins/mod_message.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_message.lua b/plugins/mod_message.lua index 47da5f46..2ee75c21 100644 --- a/plugins/mod_message.lua +++ b/plugins/mod_message.lua @@ -20,7 +20,7 @@ local function process_to_bare(bare, origin, stanza) local t = stanza.attr.type; if t == "error" then - -- discard + return true; -- discard elseif t == "groupchat" then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); elseif t == "headline" then -- cgit v1.2.3