aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/componentmanager.lua4
-rw-r--r--core/modulemanager.lua57
-rw-r--r--core/stanza_router.lua7
3 files changed, 39 insertions, 29 deletions
diff --git a/core/componentmanager.lua b/core/componentmanager.lua
index 2d292c8f..833b1fc0 100644
--- a/core/componentmanager.lua
+++ b/core/componentmanager.lua
@@ -67,6 +67,7 @@ function handle_stanza(origin, stanza)
component(origin, stanza, hosts[host]);
else
log("error", "Component manager recieved a stanza for a non-existing component: "..tostring(stanza));
+ default_component_handler(origin, stanza);
end
end
@@ -113,6 +114,7 @@ end
function deregister_component(host)
if components[host] then
+ modulemanager.unload(host, "tls");
modulemanager.unload(host, "dialback");
hosts[host].connected = nil;
local host_config = configmanager.getconfig()[host];
@@ -121,7 +123,7 @@ function deregister_component(host)
components[host] = default_component_handler;
else
-- Component not in config, or disabled, remove
- hosts[host] = nil;
+ hosts[host] = nil; -- FIXME do proper unload of all modules and other cleanup before removing
components[host] = nil;
end
-- remove from disco_items
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index 312ca738..88d07f43 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -65,9 +65,11 @@ function load_modules_for_host(host)
end
-- Load auto-loaded modules for this host
- for _, module in ipairs(autoload_modules) do
- if not disabled_set[module] then
- load(host, module);
+ if hosts[host].type == "local" then
+ for _, module in ipairs(autoload_modules) do
+ if not disabled_set[module] then
+ load(host, module);
+ end
end
end
@@ -104,7 +106,6 @@ function load(host, module_name, config)
if not modulemap[host] then
modulemap[host] = {};
- hosts[host].modules = modulemap[host];
end
if modulemap[host][module_name] then
@@ -127,29 +128,39 @@ function load(host, module_name, config)
local pluginenv = setmetatable({ module = api_instance }, { __index = _G });
setfenv(mod, pluginenv);
- if not hosts[host] then hosts[host] = { type = "component", host = host, connected = false, s2sout = {} }; end
-
- local success, ret = pcall(mod);
- if not success then
- log("error", "Error initialising module '%s': %s", module_name or "nil", ret or "nil");
- return nil, ret;
+ if not hosts[host] then
+ local create_component = _G.require "core.componentmanager".create_component;
+ hosts[host] = create_component(host);
+ hosts[host].connected = false;
+ log("debug", "Created new component: %s", host);
end
+ hosts[host].modules = modulemap[host];
+ modulemap[host][module_name] = pluginenv;
- if module_has_method(pluginenv, "load") then
- local ok, err = call_module_method(pluginenv, "load");
- if (not ok) and err then
- log("warn", "Error loading module '%s' on '%s': %s", module_name, host, err);
+ local success, err = pcall(mod);
+ if success then
+ if module_has_method(pluginenv, "load") then
+ success, err = call_module_method(pluginenv, "load");
+ if not success then
+ log("warn", "Error loading module '%s' on '%s': %s", module_name, host, err or "nil");
+ end
end
- end
- -- Use modified host, if the module set one
- modulemap[api_instance.host][module_name] = pluginenv;
-
- if api_instance.host == "*" and host ~= "*" then
- api_instance:set_global();
+ -- Use modified host, if the module set one
+ if api_instance.host == "*" and host ~= "*" then
+ modulemap[host][module_name] = nil;
+ modulemap["*"][module_name] = pluginenv;
+ api_instance:set_global();
+ end
+ else
+ log("error", "Error initializing module '%s' on '%s': %s", module_name, host, err or "nil");
+ end
+ if success then
+ return true;
+ else -- load failed, unloading
+ unload(api_instance.host, module_name);
+ return nil, err;
end
-
- return true;
end
function get_module(host, name)
@@ -170,7 +181,6 @@ function unload(host, name, ...)
log("warn", "Non-fatal error unloading module '%s' on '%s': %s", name, host, err);
end
end
- modulemap[host][name] = nil;
local params = handler_table:get(host, name); -- , {module.host, origin_type, tag, xmlns}
for _, param in pairs(params or NULL) do
local handlers = stanza_handlers:get(param[1], param[2], param[3], param[4]);
@@ -187,6 +197,7 @@ function unload(host, name, ...)
end
end
hooks:remove(host, name);
+ modulemap[host][name] = nil;
return true;
end
diff --git a/core/stanza_router.lua b/core/stanza_router.lua
index ef4f3695..00c37ed7 100644
--- a/core/stanza_router.lua
+++ b/core/stanza_router.lua
@@ -29,13 +29,10 @@ function core_process_stanza(origin, stanza)
-- TODO verify validity of stanza (as well as JID validity)
if stanza.attr.type == "error" and #stanza.tags == 0 then return; end -- TODO invalid stanza, log
if stanza.name == "iq" then
- local can_reply = stanza.attr.type == "set" or stanza.attr.type == "get"
- local missing_id = not stanza.attr.id;
- if can_reply and (#stanza.tags ~= 1 or missing_id) then
+ if not stanza.attr.id then stanza.attr.id = ""; end -- COMPAT Jabiru doesn't send the id attribute on roster requests
+ if (stanza.attr.type == "set" or stanza.attr.type == "get") and (#stanza.tags ~= 1) then
origin.send(st.error_reply(stanza, "modify", "bad-request"));
return;
- elseif missing_id then
- return;
end
end