aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/modulemanager.lua12
-rw-r--r--plugins/mod_disco.lua4
-rw-r--r--plugins/mod_legacyauth.lua2
-rw-r--r--plugins/mod_ping.lua2
-rw-r--r--plugins/mod_private.lua2
-rw-r--r--plugins/mod_register.lua2
-rw-r--r--plugins/mod_roster.lua2
-rw-r--r--plugins/mod_time.lua4
-rw-r--r--plugins/mod_uptime.lua2
-rw-r--r--plugins/mod_vcard.lua2
-rw-r--r--plugins/mod_version.lua2
-rw-r--r--util/discohelper.lua29
12 files changed, 38 insertions, 27 deletions
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index d5360037..532a0f86 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -22,7 +22,8 @@
local plugin_dir = CFG_PLUGINDIR or "./plugins/";
local logger = require "util.logger";
-local log = logger.init("modulemanager")
+local log = logger.init("modulemanager");
+local addDiscoInfoHandler = require "core.discomanager".addDiscoInfoHandler;
local loadfile, pcall = loadfile, pcall;
local setmetatable, setfenv, getfenv = setmetatable, setfenv, getfenv;
@@ -172,6 +173,15 @@ function api:add_iq_handler(origin_type, xmlns, handler)
_add_iq_handler(self, origin_type, xmlns, handler);
end
+function api:add_feature(xmlns)
+ addDiscoInfoHandler(self.host, function(reply, to, from, node)
+ if #node == 0 then
+ reply:tag("feature", {var = xmlns}):up();
+ return true;
+ end
+ end);
+end
+
do
local event_handlers = {};
diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua
index 36e18f75..455f92f1 100644
--- a/plugins/mod_disco.lua
+++ b/plugins/mod_disco.lua
@@ -21,8 +21,8 @@
local discomanager_handle = require "core.discomanager".handle;
-require "core.discomanager".set("disco", "http://jabber.org/protocol/disco#info");
-require "core.discomanager".set("disco", "http://jabber.org/protocol/disco#items");
+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));
diff --git a/plugins/mod_legacyauth.lua b/plugins/mod_legacyauth.lua
index 1f1789a9..ca2d9f78 100644
--- a/plugins/mod_legacyauth.lua
+++ b/plugins/mod_legacyauth.lua
@@ -22,7 +22,7 @@
local st = require "util.stanza";
local t_concat = table.concat;
-require "core.discomanager".set("legacyauth", "jabber:iq:auth");
+module:add_feature("jabber:iq:auth");
module:add_iq_handler("c2s_unauthed", "jabber:iq:auth",
function (session, stanza)
diff --git a/plugins/mod_ping.lua b/plugins/mod_ping.lua
index 78bdb222..922c9390 100644
--- a/plugins/mod_ping.lua
+++ b/plugins/mod_ping.lua
@@ -21,7 +21,7 @@
local st = require "util.stanza";
-require "core.discomanager".set("ping", "urn:xmpp:ping");
+module:add_feature("urn:xmpp:ping");
module:add_iq_handler({"c2s", "s2sin"}, "urn:xmpp:ping",
function(session, stanza)
diff --git a/plugins/mod_private.lua b/plugins/mod_private.lua
index f1eee55e..8bcb6da6 100644
--- a/plugins/mod_private.lua
+++ b/plugins/mod_private.lua
@@ -24,7 +24,7 @@ local st = require "util.stanza"
local jid_split = require "util.jid".split;
local datamanager = require "util.datamanager"
-require "core.discomanager".set("private", "jabber:iq:private");
+module:add_feature("jabber:iq:private");
module:add_iq_handler("c2s", "jabber:iq:private",
function (session, stanza)
diff --git a/plugins/mod_register.lua b/plugins/mod_register.lua
index f9e85fff..29474461 100644
--- a/plugins/mod_register.lua
+++ b/plugins/mod_register.lua
@@ -24,7 +24,7 @@ local usermanager_user_exists = require "core.usermanager".user_exists;
local usermanager_create_user = require "core.usermanager".create_user;
local datamanager_store = require "util.datamanager".store;
-require "core.discomanager".set("register", "jabber:iq:register");
+module:add_feature("jabber:iq:register");
module:add_iq_handler("c2s", "jabber:iq:register", function (session, stanza)
if stanza.tags[1].name == "query" then
diff --git a/plugins/mod_roster.lua b/plugins/mod_roster.lua
index 60d481ce..7e114b17 100644
--- a/plugins/mod_roster.lua
+++ b/plugins/mod_roster.lua
@@ -29,7 +29,7 @@ local rm_remove_from_roster = require "core.rostermanager".remove_from_roster;
local rm_add_to_roster = require "core.rostermanager".add_to_roster;
local rm_roster_push = require "core.rostermanager".roster_push;
-require "core.discomanager".set("roster", "jabber:iq:roster");
+module:add_feature("jabber:iq:roster");
module:add_iq_handler("c2s", "jabber:iq:roster",
function (session, stanza)
diff --git a/plugins/mod_time.lua b/plugins/mod_time.lua
index 9a61d90c..3d73623c 100644
--- a/plugins/mod_time.lua
+++ b/plugins/mod_time.lua
@@ -25,7 +25,7 @@ local legacy = require "util.datetime".legacy;
-- XEP-0202: Entity Time
-require "core.discomanager".set("time", "urn:xmpp:time");
+module:add_feature("urn:xmpp:time");
module:add_iq_handler({"c2s", "s2sin"}, "urn:xmpp:time",
function(session, stanza)
@@ -38,7 +38,7 @@ module:add_iq_handler({"c2s", "s2sin"}, "urn:xmpp:time",
-- XEP-0090: Entity Time (deprecated)
-require "core.discomanager".set("time", "jabber:iq:time");
+module:add_feature("jabber:iq:time");
module:add_iq_handler({"c2s", "s2sin"}, "jabber:iq:time",
function(session, stanza)
diff --git a/plugins/mod_uptime.lua b/plugins/mod_uptime.lua
index 2f04fc6f..51457551 100644
--- a/plugins/mod_uptime.lua
+++ b/plugins/mod_uptime.lua
@@ -26,7 +26,7 @@ local t_concat = table.concat;
local start_time = os.time();
-require "core.discomanager".set("uptime", "jabber:iq:last");
+module:add_feature("jabber:iq:last");
module:add_iq_handler({"c2s", "s2sin"}, "jabber:iq:last",
function (origin, stanza)
diff --git a/plugins/mod_vcard.lua b/plugins/mod_vcard.lua
index 6b8ee23a..4f78867b 100644
--- a/plugins/mod_vcard.lua
+++ b/plugins/mod_vcard.lua
@@ -28,7 +28,7 @@ local t_concat, t_insert = table.concat, table.insert;
require "util.jid"
local jid_split = jid.split;
-require "core.discomanager".set("vcard", "vcard-temp");
+module:add_feature("vcard-temp");
module:add_iq_handler({"c2s", "s2sin"}, "vcard-temp",
function (session, stanza)
diff --git a/plugins/mod_version.lua b/plugins/mod_version.lua
index e16d8aa7..0b7ebfaa 100644
--- a/plugins/mod_version.lua
+++ b/plugins/mod_version.lua
@@ -25,7 +25,7 @@ local log = require "util.logger".init("mod_version");
local xmlns_version = "jabber:iq:version"
-require "core.discomanager".set("version", xmlns_version);
+module:add_feature(xmlns_version);
local function handle_version_request(session, stanza)
if stanza.attr.type == "get" then
diff --git a/util/discohelper.lua b/util/discohelper.lua
index 4d3bc3f6..7966ac55 100644
--- a/util/discohelper.lua
+++ b/util/discohelper.lua
@@ -57,20 +57,8 @@ local function handle(self, stanza)
elseif query.attr.xmlns == "http://jabber.org/protocol/disco#items" then
handlers = self.item_handlers;
end
- local 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
- local found; -- to keep track of any handlers found
- if handler then
- for _, h in ipairs(handler) do
- if h(reply, to, from, node) then found = true; end
- end
- 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
@@ -81,6 +69,19 @@ local function handle(self, stanza)
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