# HG changeset patch # User Marco Cirillo # Date 1364859868 0 # Node ID a5fcda77c6b1c196b218bc3c1b06beeb9e022a5d # Parent 82b3ddba0ec75c5780016bfbf7c8b387c88a2b1d moduleapi: have get_host_items wrap on get_items from modulemanager, also add has_{feature/identity} to the API. diff -r 82b3ddba0ec7 -r a5fcda77c6b1 core/moduleapi.lua --- a/core/moduleapi.lua Mon Apr 01 23:41:57 2013 +0000 +++ b/core/moduleapi.lua Mon Apr 01 23:44:28 2013 +0000 @@ -62,6 +62,20 @@ 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 @@ 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