modulemanager: Removed an unused variable.
[prosody.git] / core / modulemanager.lua
index f5865a314b2df2a34b1671f4b08166b00b2abf00..211b49b631a39729edeff04d881d787d39b9df91 100644 (file)
@@ -6,8 +6,6 @@
 -- COPYING file in the source package for more information.
 --
 
-local plugin_dir = CFG_PLUGINDIR or "./plugins/";
-
 local logger = require "util.logger";
 local log = logger.init("modulemanager");
 local config = require "core.configmanager";
@@ -34,12 +32,13 @@ local unpack, select = unpack, select;
 pcall = function(f, ...)
        local n = select("#", ...);
        local params = {...};
-       return xpcall(function() f(unpack(params, 1, n)) end, function(e) return tostring(e).."\n"..debug_traceback(); end);
+       return xpcall(function() return f(unpack(params, 1, n)) end, function(e) return tostring(e).."\n"..debug_traceback(); end);
 end
 
 local array, set = require "util.array", require "util.set";
 
-local autoload_modules = {"presence", "message", "iq"};
+local autoload_modules = {"presence", "message", "iq", "offline"};
+local component_inheritable_modules = {"tls", "dialback", "iq"};
 
 -- We need this to let modules access the real global namespace
 local _G = _G;
@@ -59,52 +58,45 @@ local NULL = {};
 
 -- Load modules when a host is activated
 function load_modules_for_host(host)
-       local disabled_set = {};
-       local modules_disabled = config.get(host, "core", "modules_disabled");
-       if modules_disabled then
-               for _, module in ipairs(modules_disabled) do
-                       disabled_set[module] = true;
-               end
-       end
-
-       -- Load auto-loaded modules for this host
-       if hosts[host].type == "local" then
-               for _, module in ipairs(autoload_modules) do
-                       if not disabled_set[module] then
-                               load(host, module);
-                       end
-               end
+       local component = config.get(host, "core", "component_module");
+       
+       local global_modules_enabled = config.get("*", "core", "modules_enabled");
+       local global_modules_disabled = config.get("*", "core", "modules_disabled");
+       local host_modules_enabled = config.get(host, "core", "modules_enabled");
+       local host_modules_disabled = config.get(host, "core", "modules_disabled");
+       
+       if host_modules_enabled == global_modules_enabled then host_modules_enabled = nil; end
+       if host_modules_disabled == global_modules_disabled then host_modules_disabled = nil; end
+       
+       local host_modules = set.new(host_modules_enabled) - set.new(host_modules_disabled);
+       local global_modules = set.new(autoload_modules) + set.new(global_modules_enabled) - set.new(global_modules_disabled);
+       if component then
+               global_modules = set.intersection(set.new(component_inheritable_modules), global_modules);
        end
-
-       -- Load modules from global section
-       if config.get(host, "core", "load_global_modules") ~= false then
-               local modules_enabled = config.get("*", "core", "modules_enabled");
-               if modules_enabled then
-                       for _, module in ipairs(modules_enabled) do
-                               if not disabled_set[module] and not is_loaded(host, module) then
-                                       load(host, module);
-                               end
-                       end
-               end
+       local modules = global_modules + host_modules;
+       
+       -- COMPAT w/ pre 0.8
+       if modules:contains("console") then
+               log("error", "The mod_console plugin has been renamed to mod_admin_telnet. Please update your config.");
+               modules:remove("console");
+               modules:add("admin_telnet");
        end
        
-       -- Load modules from just this host
-       local modules_enabled = config.get(host, "core", "modules_enabled");
-       if modules_enabled and modules_enabled ~= config.get("*", "core", "modules_enabled") then
-               for _, module in pairs(modules_enabled) do
-                       if not is_loaded(host, module) then
-                               load(host, module);
-                       end
-               end
+       if component then
+               load(host, component);
+       end
+       for module in modules do
+               load(host, module);
        end
 end
 prosody_events.add_handler("host-activated", load_modules_for_host);
-prosody_events.add_handler("component-activated", load_modules_for_host);
 --
 
 function load(host, module_name, config)
        if not (host and module_name) then
                return nil, "insufficient-parameters";
+       elseif not hosts[host] then
+               return nil, "unknown-host";
        end
        
        if not modulemap[host] then
@@ -132,12 +124,6 @@ function load(host, module_name, config)
        api_instance.environment = pluginenv;
        
        setfenv(mod, pluginenv);
-       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;