Software /
code /
prosody
Annotate
core/discomanager.lua @ 734:cfb4ec5cba5e
Fix for pposix version detection
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 16 Jan 2009 05:40:40 +0000 |
parent | 648:3f34b83771eb |
child | 758:b1885732e979 |
rev | line source |
---|---|
615 | 1 -- Prosody IM v0.2 |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
2 -- Copyright (C) 2008 Matthew Wild |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
3 -- Copyright (C) 2008 Waqas Hussain |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
4 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
5 -- This program is free software; you can redistribute it and/or |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
6 -- modify it under the terms of the GNU General Public License |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
7 -- as published by the Free Software Foundation; either version 2 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
8 -- of the License, or (at your option) any later version. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
9 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
10 -- This program is distributed in the hope that it will be useful, |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
13 -- GNU General Public License for more details. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
14 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
15 -- You should have received a copy of the GNU General Public License |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
16 -- along with this program; if not, write to the Free Software |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
18 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
19 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
20 |
388 | 21 |
22 local helper = require "util.discohelper".new(); | |
23 local hosts = hosts; | |
24 local jid_split = require "util.jid".split; | |
25 local jid_bare = require "util.jid".bare; | |
26 local usermanager_user_exists = require "core.usermanager".user_exists; | |
27 local rostermanager_is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; | |
419
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
28 local print = print; |
388 | 29 |
30 do | |
31 helper:addDiscoInfoHandler("*host", function(reply, to, from, node) | |
32 if hosts[to] then | |
517 | 33 reply:tag("identity", {category="server", type="im", name="Prosody"}):up(); |
388 | 34 return true; |
35 end | |
36 end); | |
37 helper:addDiscoInfoHandler("*node", function(reply, to, from, node) | |
38 local node, host = jid_split(to); | |
39 if hosts[host] and rostermanager_is_contact_subscribed(node, host, jid_bare(from)) then | |
40 reply:tag("identity", {category="account", type="registered"}):up(); | |
41 return true; | |
42 end | |
43 end); | |
648
3f34b83771eb
Return an empty set intead of an error when no disco items are available for a host
Waqas Hussain <waqas20@gmail.com>
parents:
615
diff
changeset
|
44 helper:addDiscoItemsHandler("*host", function(reply, to, from, node) |
3f34b83771eb
Return an empty set intead of an error when no disco items are available for a host
Waqas Hussain <waqas20@gmail.com>
parents:
615
diff
changeset
|
45 if hosts[to] and hosts[to].type == "local" then |
3f34b83771eb
Return an empty set intead of an error when no disco items are available for a host
Waqas Hussain <waqas20@gmail.com>
parents:
615
diff
changeset
|
46 return true; |
3f34b83771eb
Return an empty set intead of an error when no disco items are available for a host
Waqas Hussain <waqas20@gmail.com>
parents:
615
diff
changeset
|
47 end |
3f34b83771eb
Return an empty set intead of an error when no disco items are available for a host
Waqas Hussain <waqas20@gmail.com>
parents:
615
diff
changeset
|
48 end); |
388 | 49 end |
50 | |
51 module "discomanager" | |
52 | |
53 function handle(stanza) | |
54 return helper:handle(stanza); | |
55 end | |
56 | |
57 function addDiscoItemsHandler(jid, func) | |
58 return helper:addDiscoItemsHandler(jid, func); | |
59 end | |
60 | |
61 function addDiscoInfoHandler(jid, func) | |
62 return helper:addDiscoInfoHandler(jid, func); | |
63 end | |
64 | |
420 | 65 function set(plugin, var, origin) |
419
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
66 -- TODO handle origin and host based on plugin. |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
67 local handler = function(reply, to, from, node) -- service discovery |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
68 if #node == 0 then |
420 | 69 reply:tag("feature", {var = var}):up(); |
419
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
70 return true; |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
71 end |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
72 end |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
73 addDiscoInfoHandler("*node", handler); |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
74 addDiscoInfoHandler("*host", handler); |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
75 end |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
76 |
388 | 77 return _M; |