1 -- Prosody IM |
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
|
4 -- |
|
5 -- This project is MIT/X11 licensed. Please see the |
|
6 -- COPYING file in the source package for more information. |
|
7 -- |
|
8 |
|
9 |
|
10 |
|
11 local helper = require "util.discohelper".new(); |
|
12 local hosts = hosts; |
|
13 local jid_split = require "util.jid".split; |
|
14 local jid_bare = require "util.jid".bare; |
|
15 local usermanager_user_exists = require "core.usermanager".user_exists; |
|
16 local rostermanager_is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; |
|
17 local print = print; |
|
18 |
|
19 do |
|
20 helper:addDiscoInfoHandler("*host", function(reply, to, from, node) |
|
21 if hosts[to] then |
|
22 reply:tag("identity", {category="server", type="im", name="Prosody"}):up(); |
|
23 return true; |
|
24 end |
|
25 end); |
|
26 helper:addDiscoInfoHandler("*node", function(reply, to, from, node) |
|
27 local node, host = jid_split(to); |
|
28 if hosts[host] and rostermanager_is_contact_subscribed(node, host, jid_bare(from)) then |
|
29 reply:tag("identity", {category="account", type="registered"}):up(); |
|
30 return true; |
|
31 end |
|
32 end); |
|
33 helper:addDiscoItemsHandler("*host", function(reply, to, from, node) |
|
34 if hosts[to] and hosts[to].type == "local" then |
|
35 return true; |
|
36 end |
|
37 end); |
|
38 end |
|
39 |
|
40 module "discomanager" |
|
41 |
|
42 function handle(stanza) |
|
43 return helper:handle(stanza); |
|
44 end |
|
45 |
|
46 function addDiscoItemsHandler(jid, func) |
|
47 return helper:addDiscoItemsHandler(jid, func); |
|
48 end |
|
49 |
|
50 function addDiscoInfoHandler(jid, func) |
|
51 return helper:addDiscoInfoHandler(jid, func); |
|
52 end |
|
53 |
|
54 function set(plugin, var, origin) |
|
55 -- TODO handle origin and host based on plugin. |
|
56 local handler = function(reply, to, from, node) -- service discovery |
|
57 if #node == 0 then |
|
58 reply:tag("feature", {var = var}):up(); |
|
59 return true; |
|
60 end |
|
61 end |
|
62 addDiscoInfoHandler("*node", handler); |
|
63 addDiscoInfoHandler("*host", handler); |
|
64 end |
|
65 |
|
66 return _M; |
|