From 1b811608357cb2b249f41672ef285b6baf332fa2 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 18:37:46 +0100 Subject: moduleapi: Add module:broadcast() to send a stanza to a list of JIDs --- core/moduleapi.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'core') diff --git a/core/moduleapi.lua b/core/moduleapi.lua index f3326295..c40363a1 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -10,6 +10,7 @@ local config = require "core.configmanager"; local modulemanager; -- This gets set from modulemanager local array = require "util.array"; local set = require "util.set"; +local it = require "util.iterators"; local logger = require "util.logger"; local pluginloader = require "util.pluginloader"; local timer = require "util.timer"; @@ -362,6 +363,14 @@ function api:send(stanza) return core_post_stanza(hosts[self.host], stanza); end +function api:broadcast(jids, stanza, iter) + for jid in (iter or it.values)(jids) do + local new_stanza = st.clone(stanza); + new_stanza.attr.to = jid; + core_post_stanza(hosts[self.host], new_stanza); + end +end + function api:add_timer(delay, callback) return timer.add_task(delay, function (t) if self.loaded == false then return; end -- cgit v1.2.3 From aec67b444ed2ddaaf7275b8e0dfa1f439ccb600c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 18:58:29 +0100 Subject: moduleapi: Remove accidental use of undefined and unnecessary 'priority' variable --- core/moduleapi.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/moduleapi.lua b/core/moduleapi.lua index c40363a1..62c9f534 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -130,7 +130,7 @@ function api:wrap_event(event, handler) end function api:wrap_global(event, handler) - return self:hook_object_event(prosody.events, event, handler, priority); + return self:hook_object_event(prosody.events, event, handler); end function api:require(lib) -- cgit v1.2.3 From 07fcf555ba90278a318df3a7bdc531cf6c6b9881 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:00:05 +0100 Subject: moduleapi: module:measure_event(), module:measure_global_event(): Fix copy/paste error --- core/moduleapi.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 62c9f534..11d1fdc1 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -408,11 +408,11 @@ function api:measure_object_event(events_object, event_name, stat_name) end function api:measure_event(event_name, stat_name) - return self:hook_object_event((hosts[self.host] or prosody).events.wrappers, event_name, handler); + return self:measure_object_event((hosts[self.host] or prosody).events.wrappers, event_name, stat_name); end function api:measure_global_event(event_name, stat_name) - return self:hook_object_event(prosody.events.wrappers, event_name, handler); + return self:measure_object_event(prosody.events.wrappers, event_name, stat_name); end function api.init(mm) -- cgit v1.2.3 From 343f4f8c29f7c8856f7237c7a3cd16785ee6b86b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:01:16 +0100 Subject: moduleapi: Clear self.event_handlers when unhooking an event, to prevent leaks --- core/moduleapi.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'core') diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 11d1fdc1..c7fadc27 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -94,6 +94,7 @@ function api:hook_object_event(object, event, handler, priority) end function api:unhook_object_event(object, event, handler) + self.event_handlers:set(object, event, handler, nil); return object.remove_handler(event, handler); end -- cgit v1.2.3 From e5323b0c7fac6ae251228473407591139dcd0e58 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:02:07 +0100 Subject: moduleapi: Minor variable renaming to avoid clashes with the 'type' function --- core/moduleapi.lua | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'core') diff --git a/core/moduleapi.lua b/core/moduleapi.lua index c7fadc27..fbb131ec 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -63,8 +63,8 @@ end function api:add_feature(xmlns) self:add_item("feature", xmlns); end -function api:add_identity(category, type, name) - self:add_item("identity", {category = category, type = type, name = name}); +function api:add_identity(category, identity_type, name) + self:add_item("identity", {category = category, type = identity_type, name = name}); end function api:add_extension(data) self:add_item("extension", data); @@ -75,9 +75,9 @@ function api:has_feature(xmlns) end return false; end -function api:has_identity(category, type, name) +function api:has_identity(category, identity_type, name) for _, id in ipairs(self:get_host_items("identity")) do - if id.category == category and id.type == type and id.name == name then + if id.category == category and id.type == identity_type and id.name == name then return true; end end @@ -329,11 +329,11 @@ function api:get_host_items(key) return result; end -function api:handle_items(type, added_cb, removed_cb, existing) - self:hook("item-added/"..type, added_cb); - self:hook("item-removed/"..type, removed_cb); +function api:handle_items(item_type, added_cb, removed_cb, existing) + self:hook("item-added/"..item_type, added_cb); + self:hook("item-removed/"..item_type, removed_cb); if existing ~= false then - for _, item in ipairs(self:get_host_items(type)) do + for _, item in ipairs(self:get_host_items(item_type)) do added_cb({ item = item }); end end @@ -389,19 +389,19 @@ function api:load_resource(path, mode) return io.open(path, mode); end -function api:open_store(name, type) - return require"core.storagemanager".open(self.host, name or self.name, type); +function api:open_store(name, store_type) + return require"core.storagemanager".open(self.host, name or self.name, store_type); end -function api:measure(name, type) - return measure(type, "/"..self.host.."/mod_"..self.name.."/"..name); +function api:measure(name, stat_type) + return measure(stat_type, "/"..self.host.."/mod_"..self.name.."/"..name); end function api:measure_object_event(events_object, event_name, stat_name) local m = self:measure(stat_name or event_name, "duration"); - local function handler(handlers, event_name, event_data) + local function handler(handlers, _event_name, _event_data) local finished = m(); - local ret = handlers(event_name, event_data); + local ret = handlers(_event_name, _event_data); finished(); return ret; end -- cgit v1.2.3 From a068b1d383cec6efe572ade50a60df2f9d6f1de5 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:02:44 +0100 Subject: moduleapi: Add luacheck annotation --- core/moduleapi.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/moduleapi.lua b/core/moduleapi.lua index fbb131ec..9e07d6a9 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -55,7 +55,7 @@ function api:set_global() self.host = "*"; -- Update the logger local _log = logger.init("mod_"..self.name); - self.log = function (self, ...) return _log(...); end; + self.log = function (self, ...) return _log(...); end; --luacheck: ignore self self._log = _log; self.global = true; end -- cgit v1.2.3 From dfcb1b6c064e979fec62de68c40f8c10724de634 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:11:27 +0100 Subject: moduleapi: Import util.stanza required for module:broadcast() --- core/moduleapi.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'core') diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 9e07d6a9..0cb1f1e7 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -16,6 +16,7 @@ local pluginloader = require "util.pluginloader"; local timer = require "util.timer"; local resolve_relative_path = require"util.paths".resolve_relative_path; local measure = require "core.statsmanager".measure; +local st = require "util.stanza"; local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; local error, setmetatable, type = error, setmetatable, type; -- cgit v1.2.3 From 2553822831a3acd9abec3c2f4753a22c025893b0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:15:35 +0100 Subject: modulemanager: Remove unused import of pcall #luacheck --- core/modulemanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 92372ac3..451838ec 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -17,13 +17,13 @@ local new_multitable = require "util.multitable".new; local hosts = hosts; local prosody = prosody; -local pcall, xpcall = pcall, xpcall; +local xpcall = xpcall; local setmetatable, rawget = setmetatable, rawget; local ipairs, pairs, type, tostring, t_insert = ipairs, pairs, type, tostring, table.insert; local debug_traceback = debug.traceback; local unpack, select = unpack, select; -pcall = function(f, ...) +local pcall = function(f, ...) local n = select("#", ...); local params = {...}; return xpcall(function() return f(unpack(params, 1, n)) end, function(e) return tostring(e).."\n"..debug_traceback(); end); -- cgit v1.2.3 From 428f9dc002327398420535814416a7299ad5d65e Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:16:16 +0100 Subject: modulemanager: Add luacheck annotations --- core/modulemanager.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 451838ec..e629b005 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -131,7 +131,7 @@ local function do_load_module(host, module_name, state) local _log = logger.init(host..":"..module_name); local host_module_api = setmetatable({ host = host, event_handlers = new_multitable(), items = {}; - _log = _log, log = function (self, ...) return _log(...); end; + _log = _log, log = function (self, ...) return _log(...); end; --luacheck: ignore 212/self },{ __index = modulemap["*"][module_name].module; }); @@ -152,8 +152,9 @@ local function do_load_module(host, module_name, state) local _log = logger.init(host..":"..module_name); local api_instance = setmetatable({ name = module_name, host = host, - _log = _log, log = function (self, ...) return _log(...); end, event_handlers = new_multitable(), - reloading = not not state, saved_state = state~=true and state or nil } + _log = _log, log = function (self, ...) return _log(...); end, --luacheck: ignore 212/self + event_handlers = new_multitable(), reloading = not not state, + saved_state = state~=true and state or nil } , { __index = api }); local pluginenv = setmetatable({ module = api_instance }, { __index = _G }); -- cgit v1.2.3 From 59c9585f12bbe887886947cd9e878a018e55a59a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:17:59 +0100 Subject: rostermanager: Variable rename for clarity and to avoid name clash [luacheck] --- core/rostermanager.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/rostermanager.lua b/core/rostermanager.lua index 612a349f..a9b26f23 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -213,10 +213,10 @@ end function is_contact_subscribed(username, host, jid) do local selfjid = username.."@"..host; - local subscription = _get_online_roster_subscription(selfjid, jid); - if subscription then return (subscription == "both" or subscription == "from"); end - local subscription = _get_online_roster_subscription(jid, selfjid); - if subscription then return (subscription == "both" or subscription == "to"); end + local user_subscription = _get_online_roster_subscription(selfjid, jid); + if user_subscription then return (user_subscription == "both" or user_subscription == "from"); end + local contact_subscription = _get_online_roster_subscription(jid, selfjid); + if contact_subscription then return (contact_subscription == "both" or contact_subscription == "to"); end end local roster, err = load_roster(username, host); local item = roster[jid]; -- cgit v1.2.3 From 7b3df2bae66c5081cb53c82f93546b1f28549611 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 19:20:07 +0100 Subject: portmanager, s2smanager, sessionmanager, stanza_router, storagemanager, usermanager, util.xml: Add luacheck annotations --- core/portmanager.lua | 2 +- core/s2smanager.lua | 4 ++-- core/sessionmanager.lua | 4 ++-- core/stanza_router.lua | 4 +++- core/storagemanager.lua | 2 +- core/usermanager.lua | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) (limited to 'core') diff --git a/core/portmanager.lua b/core/portmanager.lua index eab2412a..bbb7c215 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -41,7 +41,7 @@ local active_services = multitable.new(); --- Private helpers -local function error_to_friendly_message(service_name, port, err) +local function error_to_friendly_message(service_name, port, err) --luacheck: ignore 212/service_name local friendly_message = err; if err:match(" in use") then -- FIXME: Use service_name here diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 59c1831b..a3a8702a 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -49,11 +49,11 @@ local resting_session = { -- Resting, not dead close = function (session) session.log("debug", "Attempt to close already-closed session"); end; - filter = function (type, data) return data; end; + filter = function (type, data) return data; end; --luacheck: ignore 212/type }; resting_session.__index = resting_session; function retire_session(session, reason) - local log = session.log or log; + local log = session.log or log; --luacheck: ignore 431/log for k in pairs(session) do if k ~= "log" and k ~= "id" and k ~= "conn" then session[k] = nil; diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index d833dbe5..5e4e2991 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -54,11 +54,11 @@ local resting_session = { -- Resting, not dead close = function (session) session.log("debug", "Attempt to close already-closed session"); end; - filter = function (type, data) return data; end; + filter = function (type, data) return data; end; --luacheck: ignore 212/type }; resting_session.__index = resting_session; function retire_session(session) - local log = session.log or log; + local log = session.log or log; --luacheck: ignore 431/log for k in pairs(session) do if k ~= "log" and k ~= "id" then session[k] = nil; diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 8e86b16f..55c94bf4 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -30,7 +30,7 @@ deprecated_warning"core_process_stanza"; deprecated_warning"core_route_stanza"; local valid_stanzas = { message = true, presence = true, iq = true }; -local function handle_unhandled_stanza(host, origin, stanza) +local function handle_unhandled_stanza(host, origin, stanza) --luacheck: ignore 212/host local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns or "jabber:client", origin.type; if xmlns == "jabber:client" and valid_stanzas[name] then -- A normal stanza @@ -221,6 +221,8 @@ function core_route_stanza(origin, stanza) end end end + +--luacheck: ignore 122/prosody prosody.core_process_stanza = core_process_stanza; prosody.core_post_stanza = core_post_stanza; prosody.core_route_stanza = core_route_stanza; diff --git a/core/storagemanager.lua b/core/storagemanager.lua index ad31eb80..0b6679d8 100644 --- a/core/storagemanager.lua +++ b/core/storagemanager.lua @@ -23,7 +23,7 @@ local null_storage_driver = setmetatable( name = "null", open = function (self) return self; end }, { - __index = function (self, method) + __index = function (self, method) --luacheck: ignore 212 return null_storage_method; end } diff --git a/core/usermanager.lua b/core/usermanager.lua index 900531ca..3a2b23a2 100644 --- a/core/usermanager.lua +++ b/core/usermanager.lua @@ -29,7 +29,7 @@ function new_null_provider() local function dummy() return nil, "method not implemented"; end; local function dummy_get_sasl_handler() return sasl_new(nil, {}); end return setmetatable({name = "null", get_sasl_handler = dummy_get_sasl_handler}, { - __index = function(self, method) return dummy; end + __index = function(self, method) return dummy; end --luacheck: ignore 212 }); end -- cgit v1.2.3