Mercurial > prosody-hg
comparison plugins/mod_disco.lua @ 2491:4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Sat, 23 Jan 2010 18:16:10 +0500 |
| parents | 29a30884aadd |
| children | 692b3c6c5bd2 |
comparison
equal
deleted
inserted
replaced
| 2490:6eee75fb3159 | 2491:4be6810914eb |
|---|---|
| 9 local componentmanager_get_children = require "core.componentmanager".get_children; | 9 local componentmanager_get_children = require "core.componentmanager".get_children; |
| 10 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; | 10 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; |
| 11 local jid_split = require "util.jid".split; | 11 local jid_split = require "util.jid".split; |
| 12 local jid_bare = require "util.jid".bare; | 12 local jid_bare = require "util.jid".bare; |
| 13 local st = require "util.stanza" | 13 local st = require "util.stanza" |
| 14 | |
| 15 local disco_items = module:get_option("disco_items") or {}; | |
| 16 do -- validate disco_items | |
| 17 for _, item in ipairs(disco_items) do | |
| 18 local err; | |
| 19 if type(item) ~= "table" then | |
| 20 err = "item is not a table"; | |
| 21 elseif type(item[1]) ~= "string" then | |
| 22 err = "item jid is not a string"; | |
| 23 elseif item[2] and type(item[2]) ~= "string" then | |
| 24 err = "item name is not a string"; | |
| 25 end | |
| 26 if err then | |
| 27 module:log("error", "option disco_items is malformed: %s", err); | |
| 28 disco_items = {}; -- TODO clean up data instead of removing it? | |
| 29 break; | |
| 30 end | |
| 31 end | |
| 32 end | |
| 14 | 33 |
| 15 module:add_identity("server", "im", "Prosody"); -- FIXME should be in the non-existing mod_router | 34 module:add_identity("server", "im", "Prosody"); -- FIXME should be in the non-existing mod_router |
| 16 module:add_feature("http://jabber.org/protocol/disco#info"); | 35 module:add_feature("http://jabber.org/protocol/disco#info"); |
| 17 module:add_feature("http://jabber.org/protocol/disco#items"); | 36 module:add_feature("http://jabber.org/protocol/disco#items"); |
| 18 | 37 |
| 48 | 67 |
| 49 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); | 68 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); |
| 50 for jid in pairs(componentmanager_get_children(module.host)) do | 69 for jid in pairs(componentmanager_get_children(module.host)) do |
| 51 reply:tag("item", {jid = jid}):up(); | 70 reply:tag("item", {jid = jid}):up(); |
| 52 end | 71 end |
| 72 for _, item in ipairs(disco_items) do | |
| 73 reply:tag("item", {jid=item[1], name=item[2]}):up(); | |
| 74 end | |
| 53 origin.send(reply); | 75 origin.send(reply); |
| 54 return true; | 76 return true; |
| 55 end); | 77 end); |
| 56 module:hook("iq/bare/http://jabber.org/protocol/disco#info:query", function(event) | 78 module:hook("iq/bare/http://jabber.org/protocol/disco#info:query", function(event) |
| 57 local origin, stanza = event.origin, event.stanza; | 79 local origin, stanza = event.origin, event.stanza; |
