aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/configmanager.lua9
-rw-r--r--core/moduleapi.lua32
-rw-r--r--core/modulemanager.lua19
3 files changed, 37 insertions, 23 deletions
diff --git a/core/configmanager.lua b/core/configmanager.lua
index e31dbd72..9720f48a 100644
--- a/core/configmanager.lua
+++ b/core/configmanager.lua
@@ -7,8 +7,8 @@
--
local _G = _G;
-local setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table =
- setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table;
+local setmetatable, rawget, rawset, io, error, dofile, type, pairs, table =
+ setmetatable, rawget, rawset, io, error, dofile, type, pairs, table;
local format, math_max = string.format, math.max;
local fire_event = prosody and prosody.events.fire_event or function () end;
@@ -68,7 +68,6 @@ end
-- Helper function to resolve relative paths (needed by config)
do
- local rel_path_start = ".."..path_sep;
function resolve_relative_path(parent_path, path)
if path then
-- Some normalization
@@ -152,7 +151,7 @@ end
-- Built-in Lua parser
do
local pcall, setmetatable = _G.pcall, _G.setmetatable;
- local rawget, tostring = _G.rawget, _G.tostring;
+ local rawget = _G.rawget;
parsers.lua = {};
function parsers.lua.load(data, config_file, config)
local env;
@@ -213,7 +212,7 @@ do
end
env.component = env.Component;
- function env.Include(file, wildcard)
+ function env.Include(file)
if file:match("[*?]") then
local path_pos, glob = file:match("()([^"..path_sep.."]+)$");
local path = file:sub(1, math_max(path_pos-2,0));
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index f9701471..de900bf0 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -62,6 +62,20 @@ end
function api:add_extension(data)
self:add_item("extension", data);
end
+function api:has_feature(xmlns)
+ for _, feature in ipairs(self:get_host_items("feature")) do
+ if feature == xmlns then return true; end
+ end
+ return false;
+end
+function api:has_identity(category, type, name)
+ for _, id in ipairs(self:get_host_items("identity")) do
+ if id.category == category and id.type == type and id.name == name then
+ return true;
+ end
+ end
+ return false;
+end
function api:fire_event(...)
return (hosts[self.host] or prosody).events.fire_event(...);
@@ -271,23 +285,7 @@ function api:remove_item(key, value)
end
function api:get_host_items(key)
- local result = {};
- for mod_name, module in pairs(modulemanager.get_modules(self.host)) do
- module = module.module;
- if module.items then
- for _, item in ipairs(module.items[key] or NULL) do
- t_insert(result, item);
- end
- end
- end
- for mod_name, module in pairs(modulemanager.get_modules("*")) do
- module = module.module;
- if module.items then
- for _, item in ipairs(module.items[key] or NULL) do
- t_insert(result, item);
- end
- end
- end
+ local result = modulemanager.get_items(key, self.host) or {};
return result;
end
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index 35b9d0e5..535c227b 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -19,7 +19,7 @@ local prosody = prosody;
local pcall, xpcall = pcall, xpcall;
local setmetatable, rawget = setmetatable, rawget;
-local pairs, type, tostring = pairs, type, tostring;
+local ipairs, pairs, type, tostring, t_insert = ipairs, pairs, type, tostring, table.insert;
local debug_traceback = debug.traceback;
local unpack, select = unpack, select;
@@ -278,6 +278,23 @@ function get_module(host, name)
return modulemap[host] and modulemap[host][name];
end
+function get_items(key, host)
+ local result = {};
+ local modules = modulemap[host];
+ if not key or not host or not modules then return nil; end
+
+ for _, module in pairs(modules) do
+ local mod = module.module;
+ if mod.items and mod.items[key] then
+ for _, value in ipairs(mod.items[key]) do
+ t_insert(result, value);
+ end
+ end
+ end
+
+ return result;
+end
+
function get_modules(host)
return modulemap[host];
end