prosodyctl: Fix import of util.iterators
[prosody.git] / core / moduleapi.lua
index 1c676bc3bb5bdacabd42e561324a70d6d83d3750..57367255a32d285321a09225f3d0719ab8c23502 100644 (file)
@@ -12,6 +12,7 @@ local array = require "util.array";
 local set = require "util.set";
 local logger = require "util.logger";
 local pluginloader = require "util.pluginloader";
+local timer = require "util.timer";
 
 local multitable_new = require "util.multitable".new;
 
@@ -42,7 +43,7 @@ function api:get_host()
 end
 
 function api:get_host_type()
-       return hosts[self.host].type;
+       return self.host ~= "*" and hosts[self.host].type or nil;
 end
 
 function api:set_global()
@@ -73,7 +74,7 @@ function api:hook_object_event(object, event, handler, priority)
        return object.add_handler(event, handler, priority);
 end
 
-function api:unhook_object_event(event, handler)
+function api:unhook_object_event(object, event, handler)
        return object.remove_handler(event, handler);
 end
 
@@ -85,7 +86,7 @@ function api:hook_global(event, handler, priority)
        return self:hook_object_event(prosody.events, event, handler, priority);
 end
 
-function api:hook_stanza(xmlns, name, handler, priority)
+function api:hook_tag(xmlns, name, handler, priority)
        if not handler and type(name) == "function" then
                -- If only 2 options then they specified no xmlns
                xmlns, name, handler, priority = nil, xmlns, name, handler;
@@ -95,6 +96,7 @@ function api:hook_stanza(xmlns, name, handler, priority)
        end
        return self:hook("stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end, priority);
 end
+api.hook_stanza = api.hook_tag; -- COMPAT w/pre-0.9
 
 function api:require(lib)
        local f, n = pluginloader.load_code(self.name, lib..".lib.lua");
@@ -254,7 +256,6 @@ function api:get_option_set(name, ...)
        return set.new(value);
 end
 
-local module_items = multitable_new();
 function api:add_item(key, value)
        self.items = self.items or {};
        self.items[key] = self.items[key] or {};
@@ -328,4 +329,14 @@ function api:add_timer(delay, callback)
        end);
 end
 
+local path_sep = package.config:sub(1,1);
+function api:get_directory()
+       return self.path and (self.path:gsub("%"..path_sep.."[^"..path_sep.."]*$", "")) or nil;
+end
+
+function api:load_resource(path, mode)
+       path = config.resolve_relative_path(self:get_directory(), path);
+       return io.open(path, mode);
+end
+
 return api;