Comparison

plugins/mod_disco.lua @ 1701:ceab61010f87

mod_disco: Handle disco#items queries using new APIs
author Waqas Hussain <waqas20@gmail.com>
date Tue, 18 Aug 2009 12:39:00 +0500
parent 1700:255935c7a915
child 1702:0e56819ee51b
comparison
equal deleted inserted replaced
1700:255935c7a915 1701:ceab61010f87
5 -- This project is MIT/X11 licensed. Please see the 5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 8
9 local discomanager_handle = require "core.discomanager".handle; 9 local discomanager_handle = require "core.discomanager".handle;
10 local componentmanager_get_children = require "core.componentmanager".get_children;
10 11
11 module:add_feature("http://jabber.org/protocol/disco#info"); 12 module:add_feature("http://jabber.org/protocol/disco#info");
12 module:add_feature("http://jabber.org/protocol/disco#items"); 13 module:add_feature("http://jabber.org/protocol/disco#items");
13 14
14 module:add_iq_handler({"c2s", "s2sin"}, "http://jabber.org/protocol/disco#info", function (session, stanza) 15 module:add_iq_handler({"c2s", "s2sin"}, "http://jabber.org/protocol/disco#info", function (session, stanza)
42 end 43 end
43 end 44 end
44 origin.send(reply); 45 origin.send(reply);
45 return true; 46 return true;
46 end); 47 end);
48 module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function(event)
49 local origin, stanza = event.origin, event.stanza;
50 if stanza.attr.type ~= "get" then return; end
51 local node = stanza.tags[1].attr.node;
52 if node and node ~= "" then return; end -- TODO fire event?
53
54 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items");
55 for jid in pairs(componentmanager_get_children(module.host)) do
56 reply:tag("item", {jid = jid}):up();
57 end
58 origin.send(reply);
59 return true;
60 end);