From 42d4cad137c929a61aff5a32fc581861206c91d1 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Aug 2009 16:45:47 +0500 Subject: mod_legacyauth: Removed useless 'require' call on every login attempt --- plugins/mod_legacyauth.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/mod_legacyauth.lua b/plugins/mod_legacyauth.lua index de94411e..3c4e9c82 100644 --- a/plugins/mod_legacyauth.lua +++ b/plugins/mod_legacyauth.lua @@ -47,7 +47,6 @@ module:add_iq_handler("c2s_unauthed", "jabber:iq:auth", else username, password, resource = t_concat(username), t_concat(password), t_concat(resource); local reply = st.reply(stanza); - require "core.usermanager" if usermanager.validate_credentials(session.host, username, password) then -- Authentication successful! local success, err = sessionmanager.make_authenticated(session, username); -- cgit v1.2.3 From ae63e1d1cd5b2d5024e77a32e9af2738db01b400 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Aug 2009 16:46:08 +0500 Subject: mod_legacyauth: Updated to use module:get_option instead of configmanager --- plugins/mod_legacyauth.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/mod_legacyauth.lua b/plugins/mod_legacyauth.lua index 3c4e9c82..c4fec39f 100644 --- a/plugins/mod_legacyauth.lua +++ b/plugins/mod_legacyauth.lua @@ -11,8 +11,7 @@ local st = require "util.stanza"; local t_concat = table.concat; -local config = require "core.configmanager"; -local secure_auth_only = config.get(module:get_host(), "core", "require_encryption"); +local secure_auth_only = module:get_option("require_encryption"); local sessionmanager = require "core.sessionmanager"; local usermanager = require "core.usermanager"; -- cgit v1.2.3 From 3ede8212ce557af2e2f7e08b16a84601b8754d71 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Aug 2009 16:51:35 +0500 Subject: mod_legacyauth: Refactored a bit --- plugins/mod_legacyauth.lua | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/plugins/mod_legacyauth.lua b/plugins/mod_legacyauth.lua index c4fec39f..3d27ba71 100644 --- a/plugins/mod_legacyauth.lua +++ b/plugins/mod_legacyauth.lua @@ -42,7 +42,6 @@ module:add_iq_handler("c2s_unauthed", "jabber:iq:auth", :tag("username"):up() :tag("password"):up() :tag("resource"):up()); - return true; else username, password, resource = t_concat(username), t_concat(password), t_concat(resource); local reply = st.reply(stanza); @@ -58,15 +57,9 @@ module:add_iq_handler("c2s_unauthed", "jabber:iq:auth", end end session.send(st.reply(stanza)); - return true; else - local reply = st.reply(stanza); - reply.attr.type = "error"; - reply:tag("error", { code = "401", type = "auth" }) - :tag("not-authorized", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" }); - session.send(reply); - return true; + session.send(st.error_reply(stanza, "auth", "not-authorized")); end end - + return true; end); -- cgit v1.2.3 From 0373133890c7122a3979253dd402829bf732ee2a Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Aug 2009 16:53:18 +0500 Subject: mod_legacyauth: Added a FIXME --- plugins/mod_legacyauth.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_legacyauth.lua b/plugins/mod_legacyauth.lua index 3d27ba71..9a9c3902 100644 --- a/plugins/mod_legacyauth.lua +++ b/plugins/mod_legacyauth.lua @@ -53,7 +53,7 @@ module:add_iq_handler("c2s_unauthed", "jabber:iq:auth", success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource); if not success then session.send(st.error_reply(stanza, err_type, err, err_msg)); - return true; + return true; -- FIXME need to unauthenticate here end end session.send(st.reply(stanza)); -- cgit v1.2.3 From e928c6f02e4abeb44a243bf05d4223c232a70b2d Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Aug 2009 16:55:44 +0500 Subject: mod_posix: Updated to use module:get_option instead of configmanager --- plugins/mod_posix.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua index 0f46888d..83b8122e 100644 --- a/plugins/mod_posix.lua +++ b/plugins/mod_posix.lua @@ -17,7 +17,6 @@ if type(signal) == "string" then module:log("warn", "Couldn't load signal library, won't respond to SIGTERM"); end -local config_get = require "core.configmanager".get; local logger_set = require "util.logger".setwriter; local prosody = _G.prosody; @@ -26,7 +25,7 @@ module.host = "*"; -- we're a global module -- Don't even think about it! module:add_event_hook("server-starting", function () - if pposix.getuid() == 0 and not config_get("*", "core", "run_as_root") then + if pposix.getuid() == 0 and not module:get_option("run_as_root") then module:log("error", "Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!"); module:log("error", "For more information on running Prosody as root, see http://prosody.im/doc/root"); prosody.shutdown("Refusing to run as root"); @@ -46,7 +45,7 @@ local function write_pidfile() if pidfile_written then remove_pidfile(); end - local pidfile = config_get("*", "core", "pidfile"); + local pidfile = module:get_option("pidfile"); if pidfile then local pf, err = io.open(pidfile, "w+"); if not pf then @@ -76,7 +75,7 @@ function syslog_sink_maker(config) end require "core.loggingmanager".register_sink_type("syslog", syslog_sink_maker); -if not config_get("*", "core", "no_daemonize") then +if not module:get_option("no_daemonize") then local function daemonize_server() local ok, ret = pposix.daemonize(); if not ok then -- cgit v1.2.3 From b5683f55bd23f41df3c90a2f5a6ca60fab56c6e6 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Aug 2009 17:21:44 +0500 Subject: mod_register: Updated to use module:get_option instead of configmanager --- plugins/mod_register.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/mod_register.lua b/plugins/mod_register.lua index 383ab811..0cb8d771 100644 --- a/plugins/mod_register.lua +++ b/plugins/mod_register.lua @@ -9,7 +9,6 @@ local hosts = _G.hosts; local st = require "util.stanza"; -local config = require "core.configmanager"; local datamanager = require "util.datamanager"; local usermanager_user_exists = require "core.usermanager".user_exists; local usermanager_create_user = require "core.usermanager".create_user; @@ -90,16 +89,16 @@ module:add_iq_handler("c2s", "jabber:iq:register", function (session, stanza) end); local recent_ips = {}; -local min_seconds_between_registrations = config.get(module.host, "core", "min_seconds_between_registrations"); -local whitelist_only = config.get(module.host, "core", "whitelist_registration_only"); -local whitelisted_ips = config.get(module.host, "core", "registration_whitelist") or { "127.0.0.1" }; -local blacklisted_ips = config.get(module.host, "core", "registration_blacklist") or {}; +local min_seconds_between_registrations = module:get_option("min_seconds_between_registrations"); +local whitelist_only = module:get_option("whitelist_registration_only"); +local whitelisted_ips = module:get_option("registration_whitelist") or { "127.0.0.1" }; +local blacklisted_ips = module:get_option("registration_blacklist") or {}; for _, ip in ipairs(whitelisted_ips) do whitelisted_ips[ip] = true; end for _, ip in ipairs(blacklisted_ips) do blacklisted_ips[ip] = true; end module:add_iq_handler("c2s_unauthed", "jabber:iq:register", function (session, stanza) - if config.get(module.host, "core", "allow_registration") == false then + if module:get_option("allow_registration") == false then session.send(st.error_reply(stanza, "cancel", "service-unavailable")); elseif stanza.tags[1].name == "query" then local query = stanza.tags[1]; -- cgit v1.2.3 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(+) 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(+) 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(-) 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 2c1d3e4499cf93cd3ff69a843a3db9ef8f9e67cc Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:33:43 +0500 Subject: mod_pep: Added name 'Prosody' to the pubsub/pep identity --- plugins/mod_pep.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua index e07759f0..842f1fce 100644 --- a/plugins/mod_pep.lua +++ b/plugins/mod_pep.lua @@ -25,7 +25,7 @@ local data = {}; local recipients = {}; local hash_map = {}; -module:add_identity("pubsub", "pep"); +module:add_identity("pubsub", "pep", "Prosody"); module:add_feature("http://jabber.org/protocol/pubsub#publish"); local function publish(session, node, item) -- 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(+) 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(+) 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 4e038edbe7034a4119337b3ff6c5b95ece423b8c Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:37:40 +0500 Subject: mod_disco: Handle disco#info queries using new APIs --- plugins/mod_disco.lua | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index 00ea01d8..c6d40c9e 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -6,8 +6,6 @@ -- COPYING file in the source package for more information. -- - - local discomanager_handle = require "core.discomanager".handle; module:add_feature("http://jabber.org/protocol/disco#info"); @@ -19,3 +17,29 @@ end); module:add_iq_handler({"c2s", "s2sin"}, "http://jabber.org/protocol/disco#items", function (session, stanza) session.send(discomanager_handle(stanza)); end); + +local st = require "util.stanza" +module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event) + local origin, stanza = event.origin, event.stanza; + if stanza.attr.type ~= "get" then return; end + local node = stanza.tags[1].attr.node; + if node and node ~= "" then return; end -- TODO fire event? + + local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#info"); + local done = {}; + for _,identity in ipairs(module:get_host_items("identity")) do + local identity_s = identity.category.."\0"..identity.type; + if not done[identity_s] then + reply:tag("identity", identity):up(); + done[identity_s] = true; + end + end + for _,feature in ipairs(module:get_host_items("feature")) do + if not done[feature] then + reply:tag("feature", {var=feature}):up(); + done[feature] = true; + end + end + origin.send(reply); + return true; +end); -- cgit v1.2.3 From 444cc01f25d3c421afd03651c57ecac62b925598 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:38:28 +0500 Subject: mod_disco: Added identity server/im with name 'Prosody' --- plugins/mod_disco.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index c6d40c9e..15c6a2ff 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -18,6 +18,7 @@ module:add_iq_handler({"c2s", "s2sin"}, "http://jabber.org/protocol/disco#items" session.send(discomanager_handle(stanza)); end); +module:add_identity("server", "im", "Prosody"); local st = require "util.stanza" module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event) local origin, stanza = event.origin, event.stanza; -- cgit v1.2.3 From 18d8c7ecfdf6f5fd19f12bea0226b8a1944b4315 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:39:00 +0500 Subject: mod_disco: Handle disco#items queries using new APIs --- plugins/mod_disco.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index 15c6a2ff..73e1921a 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -7,6 +7,7 @@ -- local discomanager_handle = require "core.discomanager".handle; +local componentmanager_get_children = require "core.componentmanager".get_children; module:add_feature("http://jabber.org/protocol/disco#info"); module:add_feature("http://jabber.org/protocol/disco#items"); @@ -44,3 +45,16 @@ module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(even origin.send(reply); return true; end); +module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function(event) + local origin, stanza = event.origin, event.stanza; + if stanza.attr.type ~= "get" then return; end + local node = stanza.tags[1].attr.node; + if node and node ~= "" then return; end -- TODO fire event? + + local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); + for jid in pairs(componentmanager_get_children(module.host)) do + reply:tag("item", {jid = jid}):up(); + end + origin.send(reply); + return true; +end); -- cgit v1.2.3 From 562ba73c2aaa6d83f922307f12a64934c949899c Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:42:56 +0500 Subject: mod_disco: Removed legacy IQ hooks --- plugins/mod_disco.lua | 7 ------- 1 file changed, 7 deletions(-) diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index 73e1921a..8654e46b 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -12,13 +12,6 @@ local componentmanager_get_children = require "core.componentmanager".get_childr module:add_feature("http://jabber.org/protocol/disco#info"); module:add_feature("http://jabber.org/protocol/disco#items"); -module:add_iq_handler({"c2s", "s2sin"}, "http://jabber.org/protocol/disco#info", function (session, stanza) - session.send(discomanager_handle(stanza)); -end); -module:add_iq_handler({"c2s", "s2sin"}, "http://jabber.org/protocol/disco#items", function (session, stanza) - session.send(discomanager_handle(stanza)); -end); - module:add_identity("server", "im", "Prosody"); local st = require "util.stanza" module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event) -- cgit v1.2.3 From 6bb3a75b163375623cdc8dfe1537b0fac5500017 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:43:21 +0500 Subject: mod_disco: Removed reference to core.discomanager --- plugins/mod_disco.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index 8654e46b..31bf90fc 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -6,7 +6,6 @@ -- COPYING file in the source package for more information. -- -local discomanager_handle = require "core.discomanager".handle; local componentmanager_get_children = require "core.componentmanager".get_children; module:add_feature("http://jabber.org/protocol/disco#info"); -- cgit v1.2.3 From 64787ed9eb5f0a5aa31ebe01d3c6360b017fbfbb Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:44:42 +0500 Subject: mod_disco: Rearranged some lines, and added a FIXME comment --- plugins/mod_disco.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index 31bf90fc..06b29f0e 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -7,12 +7,12 @@ -- local componentmanager_get_children = require "core.componentmanager".get_children; +local st = require "util.stanza" +module:add_identity("server", "im", "Prosody"); -- FIXME should be in the non-existing mod_router module:add_feature("http://jabber.org/protocol/disco#info"); module:add_feature("http://jabber.org/protocol/disco#items"); -module:add_identity("server", "im", "Prosody"); -local st = require "util.stanza" module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event) local origin, stanza = event.origin, event.stanza; if stanza.attr.type ~= "get" then return; end -- 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(-) 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(-) 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(-) 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(-) 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(-) 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 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 From dae72952d261b285282add61ba0ea9be9cdaa22a Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:58:34 +0500 Subject: Removed util/discohelper.lua --- util/discohelper.lua | 89 ---------------------------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 util/discohelper.lua diff --git a/util/discohelper.lua b/util/discohelper.lua deleted file mode 100644 index 5d9bf287..00000000 --- a/util/discohelper.lua +++ /dev/null @@ -1,89 +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 t_insert = table.insert; -local jid_split = require "util.jid".split; -local ipairs = ipairs; -local st = require "util.stanza"; - -module "discohelper"; - -local function addDiscoItemsHandler(self, jid, func) - if self.item_handlers[jid] then - t_insert(self.item_handlers[jid], func); - else - self.item_handlers[jid] = {func}; - end -end - -local function addDiscoInfoHandler(self, jid, func) - if self.info_handlers[jid] then - t_insert(self.info_handlers[jid], func); - else - self.info_handlers[jid] = {func}; - end -end - -local function handle(self, stanza) - if stanza.name == "iq" and stanza.tags[1].name == "query" then - local query = stanza.tags[1]; - local to = stanza.attr.to; - local from = stanza.attr.from - local node = query.attr.node or ""; - local to_node, to_host = jid_split(to); - - local reply = st.reply(stanza):query(query.attr.xmlns); - local handlers; - if query.attr.xmlns == "http://jabber.org/protocol/disco#info" then -- select handler set - handlers = self.info_handlers; - elseif query.attr.xmlns == "http://jabber.org/protocol/disco#items" then - handlers = self.item_handlers; - end - local handler; - local found; -- to keep track of any handlers found - if to_node then -- handlers which get called always - handler = handlers["*node"]; - else - handler = handlers["*host"]; - end - if handler then -- call always called handler - for _, h in ipairs(handler) do - if h(reply, to, from, node) then found = true; end - end - end - handler = handlers[to]; -- get the handler - if not handler then -- if not found then use default handler - if to_node then - handler = handlers["*defaultnode"]; - else - handler = handlers["*defaulthost"]; - end - end - if handler then - for _, h in ipairs(handler) do - if h(reply, to, from, node) then found = true; end - end - end - if found then return reply; end -- return the reply if there was one - return st.error_reply(stanza, "cancel", "service-unavailable"); - end -end - -function new() - return { - item_handlers = {}; - info_handlers = {}; - addDiscoItemsHandler = addDiscoItemsHandler; - addDiscoInfoHandler = addDiscoInfoHandler; - handle = handle; - }; -end - -return _M; -- cgit v1.2.3