From dc32d11948edcf57bc8616f54ec558e0aa0e6763 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:25:59 +0500 Subject: componentmanager: Added function to get a list of children for a given hostname --- core/componentmanager.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core') diff --git a/core/componentmanager.lua b/core/componentmanager.lua index 08868236..14f9105b 100644 --- a/core/componentmanager.lua +++ b/core/componentmanager.lua @@ -138,4 +138,8 @@ function set_component_handler(host, handler) components[host] = handler; end +function get_children(host) + return disco_items:get(host) or NULL; +end + return _M; -- cgit v1.2.3 From 3900d20a7cacdfc3c9c72e0da7836954ef6a3511 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:30:06 +0500 Subject: Added: functions add_item and remove_item to add and remove items to the module API --- core/modulemanager.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index c2e6e68e..bc779d76 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -422,6 +422,25 @@ function api:get_option(name, default_value) return config.get(self.host, self.name, name) or config.get(self.host, "core", name) or default_value; end +local t_remove = _G.table.remove; +local module_items = multitable_new(); +function api:add_item(key, value) + self.items = self.items or {}; + self.items[key] = self.items[key] or {}; + t_insert(self.items[key], value); + self:fire_event("item-added/"..key, {source = self, item = value}); +end +function api:remove_item(key, value) + local t = self.items and self.items[key] or NULL; + for i = #t,1,-1 do + if t[i] == value then + t_remove(self.items[key], i); + self:fire_event("item-removed/"..key, {source = self, item = value}); + return value; + end + end +end + -------------------------------------------------------------------- local actions = {}; -- cgit v1.2.3 From 49c8f89be2673c78954a9d8731d434ebc3861819 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:32:38 +0500 Subject: modulemanager: Changed the add_identity module API to accept an optional name parameter (the 'name' attribute for the element) --- core/modulemanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index bc779d76..a2c28070 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -370,8 +370,8 @@ end); function api:add_feature(xmlns) features_table:set(self.host, self.name, xmlns, true); end -function api:add_identity(category, type) - identities_table:set(self.host, self.name, category.."\0"..type, {category = category, type = type}); +function api:add_identity(category, type, name) + identities_table:set(self.host, self.name, category.."\0"..type, {category = category, type = type, name = name}); end local event_hook = function(host, mod_name, event_name, ...) -- cgit v1.2.3 From d772917f2d53a40d2478e6e65fa5b20ed2ee5581 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:34:59 +0500 Subject: modulemanager: Module API functions add_item and add_feature updated to use the add_item API --- core/modulemanager.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index a2c28070..ff31271b 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -368,9 +368,11 @@ addDiscoInfoHandler("*host", function(reply, to, from, node) end); function api:add_feature(xmlns) + self:add_item("feature", xmlns); features_table:set(self.host, self.name, xmlns, true); end function api:add_identity(category, type, name) + self:add_item("identity", {category = category, type = type, name = name}); identities_table:set(self.host, self.name, category.."\0"..type, {category = category, type = type, name = name}); end -- cgit v1.2.3 From ff0bd781d2b360917d1861166657d0e11446d97c Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:35:42 +0500 Subject: modulemanager: Added module API function to get all items for a given host based on a key --- core/modulemanager.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index ff31271b..36403b60 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -443,6 +443,19 @@ function api:remove_item(key, value) end end +function api:get_host_items(key) + local result = {}; + for mod_name, module in pairs(modulemap[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 + return result; +end + -------------------------------------------------------------------- local actions = {}; -- cgit v1.2.3 From 694fbe8f7219e61132abe9ce1e88f15826e06bc3 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:47:37 +0500 Subject: componentmanager: Removed disco#items hook, and reference to core.discomanager --- core/componentmanager.lua | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'core') diff --git a/core/componentmanager.lua b/core/componentmanager.lua index 14f9105b..536d1633 100644 --- a/core/componentmanager.lua +++ b/core/componentmanager.lua @@ -6,8 +6,6 @@ -- COPYING file in the source package for more information. -- - - local prosody = prosody; local log = require "util.logger".init("componentmanager"); local configmanager = require "core.configmanager"; @@ -25,14 +23,6 @@ local components = {}; local disco_items = require "util.multitable".new(); local NULL = {}; -require "core.discomanager".addDiscoItemsHandler("*host", function(reply, to, from, node) - if #node == 0 and hosts[to] then - for jid in pairs(disco_items:get(to) or NULL) do - reply:tag("item", {jid = jid}):up(); - end - return true; - end -end); prosody.events.add_handler("server-starting", function () core_route_stanza = _G.core_route_stanza; end); -- cgit v1.2.3 From f56e892bf8b953761db74e50628aa66c826193b5 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:51:14 +0500 Subject: modulemanager: add_feature and add_identity APIs updated to use only the add_item API --- core/modulemanager.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 36403b60..bb9ab8a7 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -369,11 +369,9 @@ end); function api:add_feature(xmlns) self:add_item("feature", xmlns); - features_table:set(self.host, self.name, xmlns, true); end function api:add_identity(category, type, name) self:add_item("identity", {category = category, type = type, name = name}); - identities_table:set(self.host, self.name, category.."\0"..type, {category = category, type = type, name = name}); end local event_hook = function(host, mod_name, event_name, ...) -- cgit v1.2.3 From ed8982a1e940671b474880f7e33e46516dadd423 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:52:44 +0500 Subject: modulemanager: Removed legacy disco#items hook --- core/modulemanager.lua | 39 --------------------------------------- 1 file changed, 39 deletions(-) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index bb9ab8a7..b756b327 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -328,45 +328,6 @@ function api:add_iq_handler(origin_type, xmlns, handler) self:add_handler(origin_type, "iq", xmlns, handler); end -addDiscoInfoHandler("*host", function(reply, to, from, node) - if #node == 0 then - local done = {}; - for module, identities in pairs(identities_table:get(to) or NULL) do -- for each module - for identity, attr in pairs(identities) do - if not done[identity] then - reply:tag("identity", attr):up(); -- TODO cache - done[identity] = true; - end - end - end - for module, identities in pairs(identities_table:get("*") or NULL) do -- for each module - for identity, attr in pairs(identities) do - if not done[identity] then - reply:tag("identity", attr):up(); -- TODO cache - done[identity] = true; - end - end - end - for module, features in pairs(features_table:get(to) or NULL) do -- for each module - for feature in pairs(features) do - if not done[feature] then - reply:tag("feature", {var = feature}):up(); -- TODO cache - done[feature] = true; - end - end - end - for module, features in pairs(features_table:get("*") or NULL) do -- for each module - for feature in pairs(features) do - if not done[feature] then - reply:tag("feature", {var = feature}):up(); -- TODO cache - done[feature] = true; - end - end - end - return next(done) ~= nil; - end -end); - function api:add_feature(xmlns) self:add_item("feature", xmlns); end -- cgit v1.2.3 From e6991edfc56c5d686bb2a993ca28ae69280ebaea Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:54:16 +0500 Subject: modulemanager: Removed unnecessary code in the unload function --- core/modulemanager.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index b756b327..3634cc23 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -171,8 +171,6 @@ function unload(host, name, ...) end end modulemap[host][name] = nil; - features_table:remove(host, name); - identities_table:remove(host, name); local params = handler_table:get(host, name); -- , {module.host, origin_type, tag, xmlns} for _, param in pairs(params or NULL) do local handlers = stanza_handlers:get(param[1], param[2], param[3], param[4]); -- cgit v1.2.3 From 87af4a64f39b9687db98f779905c546319248ca3 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:55:37 +0500 Subject: modulemanager: Removed unused variables and reference to core.discomanager --- core/modulemanager.lua | 5 ----- 1 file changed, 5 deletions(-) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 3634cc23..7037fc90 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -6,13 +6,10 @@ -- COPYING file in the source package for more information. -- - - local plugin_dir = CFG_PLUGINDIR or "./plugins/"; local logger = require "util.logger"; local log = logger.init("modulemanager"); -local addDiscoInfoHandler = require "core.discomanager".addDiscoInfoHandler; local eventmanager = require "core.eventmanager"; local config = require "core.configmanager"; local multitable_new = require "util.multitable".new; @@ -50,8 +47,6 @@ local handler_info = {}; local modulehelpers = setmetatable({}, { __index = _G }); -local features_table = multitable_new(); -local identities_table = multitable_new(); local handler_table = multitable_new(); local hooked = multitable_new(); local hooks = multitable_new(); -- cgit v1.2.3 From d9be4c4b59ed1bbe7b49bd5845b3dfbc40a3e152 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:57:00 +0500 Subject: Removed core/discomanager.lua --- core/discomanager.lua | 66 --------------------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 core/discomanager.lua (limited to 'core') diff --git a/core/discomanager.lua b/core/discomanager.lua deleted file mode 100644 index 742907dd..00000000 --- a/core/discomanager.lua +++ /dev/null @@ -1,66 +0,0 @@ --- Prosody IM --- Copyright (C) 2008-2009 Matthew Wild --- Copyright (C) 2008-2009 Waqas Hussain --- --- This project is MIT/X11 licensed. Please see the --- COPYING file in the source package for more information. --- - - - -local helper = require "util.discohelper".new(); -local hosts = hosts; -local jid_split = require "util.jid".split; -local jid_bare = require "util.jid".bare; -local usermanager_user_exists = require "core.usermanager".user_exists; -local rostermanager_is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; -local print = print; - -do - helper:addDiscoInfoHandler("*host", function(reply, to, from, node) - if hosts[to] then - reply:tag("identity", {category="server", type="im", name="Prosody"}):up(); - return true; - end - end); - helper:addDiscoInfoHandler("*node", function(reply, to, from, node) - local node, host = jid_split(to); - if hosts[host] and rostermanager_is_contact_subscribed(node, host, jid_bare(from)) then - reply:tag("identity", {category="account", type="registered"}):up(); - return true; - end - end); - helper:addDiscoItemsHandler("*host", function(reply, to, from, node) - if hosts[to] and hosts[to].type == "local" then - return true; - end - end); -end - -module "discomanager" - -function handle(stanza) - return helper:handle(stanza); -end - -function addDiscoItemsHandler(jid, func) - return helper:addDiscoItemsHandler(jid, func); -end - -function addDiscoInfoHandler(jid, func) - return helper:addDiscoInfoHandler(jid, func); -end - -function set(plugin, var, origin) - -- TODO handle origin and host based on plugin. - local handler = function(reply, to, from, node) -- service discovery - if #node == 0 then - reply:tag("feature", {var = var}):up(); - return true; - end - end - addDiscoInfoHandler("*node", handler); - addDiscoInfoHandler("*host", handler); -end - -return _M; -- cgit v1.2.3