Newline at end of file for sessionmanager
[prosody.git] / core / discomanager.lua
1 -- Prosody IM v0.1
2 -- Copyright (C) 2008 Matthew Wild
3 -- Copyright (C) 2008 Waqas Hussain
4 -- 
5 -- This program is free software; you can redistribute it and/or
6 -- modify it under the terms of the GNU General Public License
7 -- as published by the Free Software Foundation; either version 2
8 -- of the License, or (at your option) any later version.
9 -- 
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 -- GNU General Public License for more details.
14 -- 
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 --
19
20
21 \r
22 local helper = require "util.discohelper".new();\r
23 local hosts = hosts;\r
24 local jid_split = require "util.jid".split;\r
25 local jid_bare = require "util.jid".bare;\r
26 local usermanager_user_exists = require "core.usermanager".user_exists;\r
27 local rostermanager_is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;\r
28 local print = print;\r
29 \r
30 do\r
31         helper:addDiscoInfoHandler("*host", function(reply, to, from, node)\r
32                 if hosts[to] then\r
33                         reply:tag("identity", {category="server", type="im", name="Prosody"}):up();\r
34                         return true;\r
35                 end\r
36         end);\r
37         helper:addDiscoInfoHandler("*node", function(reply, to, from, node)\r
38                 local node, host = jid_split(to);\r
39                 if hosts[host] and rostermanager_is_contact_subscribed(node, host, jid_bare(from)) then\r
40                         reply:tag("identity", {category="account", type="registered"}):up();\r
41                         return true;\r
42                 end\r
43         end);\r
44 end\r
45 \r
46 module "discomanager"\r
47 \r
48 function handle(stanza)\r
49         return helper:handle(stanza);\r
50 end\r
51 \r
52 function addDiscoItemsHandler(jid, func)\r
53         return helper:addDiscoItemsHandler(jid, func);\r
54 end\r
55 \r
56 function addDiscoInfoHandler(jid, func)\r
57         return helper:addDiscoInfoHandler(jid, func);\r
58 end\r
59 \r
60 function set(plugin, var, origin)\r
61         -- TODO handle origin and host based on plugin.\r
62         local handler = function(reply, to, from, node) -- service discovery\r
63                 if #node == 0 then\r
64                         reply:tag("feature", {var = var}):up();\r
65                         return true;\r
66                 end\r
67         end\r
68         addDiscoInfoHandler("*node", handler);\r
69         addDiscoInfoHandler("*host", handler);\r
70 end\r
71 \r
72 return _M;\r