s2smanager: Whitespace
[prosody.git] / core / modulemanager.lua
index d1f7d413cad3866201419766080e710aaef535ba..d8418d832df9cf5008a6cddc41fc98cb80eafcac 100644 (file)
@@ -13,7 +13,6 @@ local log = logger.init("modulemanager");
 local eventmanager = require "core.eventmanager";
 local config = require "core.configmanager";
 local multitable_new = require "util.multitable".new;
-local register_actions = require "core.actions".register;
 local st = require "util.stanza";
 local pluginloader = require "util.pluginloader";
 
@@ -158,6 +157,7 @@ function load(host, module_name, config)
                log("error", "Error initializing module '%s' on '%s': %s", module_name, host, err or "nil");
        end
        if success then
+               hosts[host].events.fire_event("module-loaded", { module = module_name, host = host });
                return true;
        else -- load failed, unloading
                unload(api_instance.host, module_name);
@@ -174,7 +174,7 @@ function is_loaded(host, name)
 end
 
 function unload(host, name, ...)
-       local mod = get_module(host, name); 
+       local mod = get_module(host, name);
        if not mod then return nil, "module-not-loaded"; end
        
        if module_has_method(mod, "unload") then
@@ -199,7 +199,17 @@ function unload(host, name, ...)
                end
        end
        hooks:remove(host, name);
+       if mod.module.items then -- remove items
+               for key,t in pairs(mod.module.items) do
+                       for i = #t,1,-1 do
+                               local value = t[i];
+                               t[i] = nil;
+                               hosts[host].events.fire_event("item-removed/"..key, {source = self, item = value});
+                       end
+               end
+       end
        modulemap[host][name] = nil;
+       hosts[host].events.fire_event("module-unloaded", { module = name, host = host });
        return true;
 end
 
@@ -280,7 +290,7 @@ function module_has_method(module, method)
 end
 
 function call_module_method(module, method, ...)
-       if module_has_method(module, method) then       
+       if module_has_method(module, method) then
                local f = module.module[method];
                return pcall(f, ...);
        else
@@ -289,7 +299,7 @@ function call_module_method(module, method, ...)
 end
 
 ----- API functions exposed to modules -----------
--- Must all be in api.* 
+-- Must all be in api.*
 
 -- Returns the name of the current module
 function api:get_name()
@@ -402,8 +412,8 @@ function api:get_option(name, default_value)
        return value;
 end
 
-function api:get_option_string(...)
-       local value = self:get_option(...);
+function api:get_option_string(name, default_value)
+       local value = self:get_option(name, default_value);
        if type(value) == "table" then
                if #value > 1 then
                        self:log("error", "Config option '%s' does not take a list, using just the first item", name);
@@ -521,19 +531,4 @@ function api:get_host_items(key)
        return result;
 end
 
---------------------------------------------------------------------
-
-local actions = {};
-
-function actions.load(params)
-       --return true, "Module loaded ("..params.module.." on "..params.host..")";
-       return load(params.host, params.module);
-end
-
-function actions.unload(params)
-       return unload(params.host, params.module);
-end
-
-register_actions("/modules", actions);
-
 return _M;