mod_disco: Removed legacy IQ hooks
[prosody.git] / plugins / mod_disco.lua
1 -- Prosody IM
2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
4 -- 
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9 local discomanager_handle = require "core.discomanager".handle;
10 local componentmanager_get_children = require "core.componentmanager".get_children;
11
12 module:add_feature("http://jabber.org/protocol/disco#info");
13 module:add_feature("http://jabber.org/protocol/disco#items");
14
15 module:add_identity("server", "im", "Prosody");
16 local st = require "util.stanza"
17 module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event)
18         local origin, stanza = event.origin, event.stanza;
19         if stanza.attr.type ~= "get" then return; end
20         local node = stanza.tags[1].attr.node;
21         if node and node ~= "" then return; end -- TODO fire event?
22
23         local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#info");
24         local done = {};
25         for _,identity in ipairs(module:get_host_items("identity")) do
26                 local identity_s = identity.category.."\0"..identity.type;
27                 if not done[identity_s] then
28                         reply:tag("identity", identity):up();
29                         done[identity_s] = true;
30                 end
31         end
32         for _,feature in ipairs(module:get_host_items("feature")) do
33                 if not done[feature] then
34                         reply:tag("feature", {var=feature}):up();
35                         done[feature] = true;
36                 end
37         end
38         origin.send(reply);
39         return true;
40 end);
41 module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function(event)
42         local origin, stanza = event.origin, event.stanza;
43         if stanza.attr.type ~= "get" then return; end
44         local node = stanza.tags[1].attr.node;
45         if node and node ~= "" then return; end -- TODO fire event?
46
47         local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items");
48         for jid in pairs(componentmanager_get_children(module.host)) do
49                 reply:tag("item", {jid = jid}):up();
50         end
51         origin.send(reply);
52         return true;
53 end);