X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_disco.lua;h=8654e46b91c036d5ca2e4d24cbf2c3c22794b093;hb=6f173ad80ffa26258cfafda9a5da0ef2b806a481;hp=c43f13dd179c34a7ea7b847b3ced6f000b4c83dd;hpb=fcd80078c2ef2ef920c13d5ab92e0a5a1838efd9;p=prosody.git diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index c43f13dd..8654e46b 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.4 +-- Prosody IM -- Copyright (C) 2008-2009 Matthew Wild -- Copyright (C) 2008-2009 Waqas Hussain -- @@ -6,16 +6,48 @@ -- 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"); 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)); +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 + 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); -module:add_iq_handler({"c2s", "s2sin"}, "http://jabber.org/protocol/disco#items", function (session, stanza) - session.send(discomanager_handle(stanza)); +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);