Software / code / prosody
Comparison
plugins/mod_disco.lua @ 1699:53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Tue, 18 Aug 2009 12:37:40 +0500 |
| parent | 1523:841d61be198f |
| child | 1700:255935c7a915 |
comparison
equal
deleted
inserted
replaced
| 1698:af89f646200f | 1699:53d16a28ee00 |
|---|---|
| 3 -- Copyright (C) 2008-2009 Waqas Hussain | 3 -- Copyright (C) 2008-2009 Waqas Hussain |
| 4 -- | 4 -- |
| 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 | |
| 9 | |
| 10 | 8 |
| 11 local discomanager_handle = require "core.discomanager".handle; | 9 local discomanager_handle = require "core.discomanager".handle; |
| 12 | 10 |
| 13 module:add_feature("http://jabber.org/protocol/disco#info"); | 11 module:add_feature("http://jabber.org/protocol/disco#info"); |
| 14 module:add_feature("http://jabber.org/protocol/disco#items"); | 12 module:add_feature("http://jabber.org/protocol/disco#items"); |
| 17 session.send(discomanager_handle(stanza)); | 15 session.send(discomanager_handle(stanza)); |
| 18 end); | 16 end); |
| 19 module:add_iq_handler({"c2s", "s2sin"}, "http://jabber.org/protocol/disco#items", function (session, stanza) | 17 module:add_iq_handler({"c2s", "s2sin"}, "http://jabber.org/protocol/disco#items", function (session, stanza) |
| 20 session.send(discomanager_handle(stanza)); | 18 session.send(discomanager_handle(stanza)); |
| 21 end); | 19 end); |
| 20 | |
| 21 local st = require "util.stanza" | |
| 22 module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event) | |
| 23 local origin, stanza = event.origin, event.stanza; | |
| 24 if stanza.attr.type ~= "get" then return; end | |
| 25 local node = stanza.tags[1].attr.node; | |
| 26 if node and node ~= "" then return; end -- TODO fire event? | |
| 27 | |
| 28 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#info"); | |
| 29 local done = {}; | |
| 30 for _,identity in ipairs(module:get_host_items("identity")) do | |
| 31 local identity_s = identity.category.."\0"..identity.type; | |
| 32 if not done[identity_s] then | |
| 33 reply:tag("identity", identity):up(); | |
| 34 done[identity_s] = true; | |
| 35 end | |
| 36 end | |
| 37 for _,feature in ipairs(module:get_host_items("feature")) do | |
| 38 if not done[feature] then | |
| 39 reply:tag("feature", {var=feature}):up(); | |
| 40 done[feature] = true; | |
| 41 end | |
| 42 end | |
| 43 origin.send(reply); | |
| 44 return true; | |
| 45 end); |