aboutsummaryrefslogtreecommitdiffstats
path: root/core/modulemanager.lua
diff options
context:
space:
mode:
Diffstat (limited to 'core/modulemanager.lua')
-rw-r--r--core/modulemanager.lua38
1 files changed, 20 insertions, 18 deletions
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index 771f6fb1..17602459 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -15,21 +15,13 @@ local set = require "util.set";
local new_multitable = require "util.multitable".new;
local api = require "core.moduleapi"; -- Module API container
-local hosts = hosts;
local prosody = prosody;
+local hosts = prosody.hosts;
-local xpcall = xpcall;
-local setmetatable, rawget = setmetatable, rawget;
-local ipairs, pairs, type, tostring, t_insert = ipairs, pairs, type, tostring, table.insert;
-
+local xpcall = require "util.xpcall".xpcall;
local debug_traceback = debug.traceback;
-local select = select;
-local unpack = table.unpack or unpack; --luacheck: ignore 113
-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);
-end
+local setmetatable, rawget = setmetatable, rawget;
+local ipairs, pairs, type, t_insert = ipairs, pairs, type, table.insert;
local autoload_modules = {prosody.platform, "presence", "message", "iq", "offline", "c2s", "s2s", "s2s_auth_certs"};
local component_inheritable_modules = {"tls", "saslauth", "dialback", "iq", "s2s"};
@@ -38,6 +30,7 @@ local component_inheritable_modules = {"tls", "saslauth", "dialback", "iq", "s2s
local _G = _G;
local _ENV = nil;
+-- luacheck: std none
local load_modules_for_host, load, unload, reload, get_module, get_items;
local get_modules, is_loaded, module_has_method, call_module_method;
@@ -45,8 +38,8 @@ local get_modules, is_loaded, module_has_method, call_module_method;
-- [host] = { [module] = module_env }
local modulemap = { ["*"] = {} };
--- Load modules when a host is activated
-function load_modules_for_host(host)
+-- Get the list of modules to be loaded on a host
+local function get_modules_for_host(host)
local component = config.get(host, "component_module");
local global_modules_enabled = config.get("*", "modules_enabled");
@@ -70,8 +63,16 @@ function load_modules_for_host(host)
modules:add("admin_telnet");
end
- if component then
- load(host, component);
+ return modules, component;
+end
+
+-- Load modules when a host is activated
+function load_modules_for_host(host)
+ local modules, component_module = get_modules_for_host(host);
+
+ -- Ensure component module is loaded first
+ if component_module then
+ load(host, component_module);
end
for module in modules do
load(host, module);
@@ -174,7 +175,7 @@ local function do_load_module(host, module_name, state)
api_instance.path = err;
modulemap[host][module_name] = pluginenv;
- local ok, err = pcall(mod);
+ local ok, err = xpcall(mod, debug_traceback);
if ok then
-- Call module's "load"
if module_has_method(pluginenv, "load") then
@@ -316,13 +317,14 @@ end
function call_module_method(module, method, ...)
local f = rawget(module.module, method);
if type(f) == "function" then
- return pcall(f, ...);
+ return xpcall(f, debug_traceback, ...);
else
return false, "no-such-method";
end
end
return {
+ get_modules_for_host = get_modules_for_host;
load_modules_for_host = load_modules_for_host;
load = load;
unload = unload;