Bumper commit for the new modulemanager API \o/ Updates all the modules, though some...
[prosody.git] / core / discomanager.lua
1 \r
2 local helper = require "util.discohelper".new();\r
3 local hosts = hosts;\r
4 local jid_split = require "util.jid".split;\r
5 local jid_bare = require "util.jid".bare;\r
6 local usermanager_user_exists = require "core.usermanager".user_exists;\r
7 local rostermanager_is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;\r
8 local print = print;\r
9 \r
10 do\r
11         helper:addDiscoInfoHandler("*host", function(reply, to, from, node)\r
12                 if hosts[to] then\r
13                         reply:tag("identity", {category="server", type="im", name="lxmppd"}):up();\r
14                         return true;\r
15                 end\r
16         end);\r
17         helper:addDiscoInfoHandler("*node", function(reply, to, from, node)\r
18                 local node, host = jid_split(to);\r
19                 if hosts[host] and rostermanager_is_contact_subscribed(node, host, jid_bare(from)) then\r
20                         reply:tag("identity", {category="account", type="registered"}):up();\r
21                         return true;\r
22                 end\r
23         end);\r
24 end\r
25 \r
26 module "discomanager"\r
27 \r
28 function handle(stanza)\r
29         return helper:handle(stanza);\r
30 end\r
31 \r
32 function addDiscoItemsHandler(jid, func)\r
33         return helper:addDiscoItemsHandler(jid, func);\r
34 end\r
35 \r
36 function addDiscoInfoHandler(jid, func)\r
37         return helper:addDiscoInfoHandler(jid, func);\r
38 end\r
39 \r
40 function set(plugin, var, origin)\r
41         -- TODO handle origin and host based on plugin.\r
42         local handler = function(reply, to, from, node) -- service discovery\r
43                 if #node == 0 then\r
44                         reply:tag("feature", {var = var}):up();\r
45                         return true;\r
46                 end\r
47         end\r
48         addDiscoInfoHandler("*node", handler);\r
49         addDiscoInfoHandler("*host", handler);\r
50 end\r
51 \r
52 return _M;\r