From a299b9096dd1dfdf50e6970784d7f2878b17876d Mon Sep 17 00:00:00 2001 From: Marco Cirillo Date: Mon, 1 Apr 2013 22:34:44 +0000 Subject: modulemanager: add function to retrieve module items from a specific host entity. --- core/modulemanager.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 35b9d0e5..48afe787 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 pairs, type, tostring, t_insert = 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 -- cgit v1.2.3 From 4453095de2be99c78b1cede797cb0c468458e84d Mon Sep 17 00:00:00 2001 From: Marco Cirillo Date: Mon, 1 Apr 2013 23:41:57 +0000 Subject: modulemanager: add missing ipairs import. --- core/modulemanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 48afe787..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, t_insert = pairs, type, tostring, table.insert; +local ipairs, pairs, type, tostring, t_insert = ipairs, pairs, type, tostring, table.insert; local debug_traceback = debug.traceback; local unpack, select = unpack, select; -- cgit v1.2.3 From fd14557245f2033db9c282211f29f5562bc40452 Mon Sep 17 00:00:00 2001 From: Marco Cirillo Date: Mon, 1 Apr 2013 23:44:28 +0000 Subject: moduleapi: have get_host_items wrap on get_items from modulemanager, also add has_{feature/identity} to the API. --- core/moduleapi.lua | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'core') 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 -- cgit v1.2.3 From 245f4609913fed7a5c83ed1f931d3175843ad8c5 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 3 Apr 2013 08:14:55 +0100 Subject: configmanager: Some cleanup, remove unused variables and imports --- core/configmanager.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'core') 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)); -- cgit v1.2.3