Wed, 03 Dec 2008 19:43:59 +0100
Using new LFLAGS variable.
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
517
diff
changeset
|
1 | -- Prosody IM v0.1 |
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); | |
44 | end | |
45 | ||
46 | module "discomanager" | |
47 | ||
48 | function handle(stanza) | |
49 | return helper:handle(stanza); | |
50 | end | |
51 | ||
52 | function addDiscoItemsHandler(jid, func) | |
53 | return helper:addDiscoItemsHandler(jid, func); | |
54 | end | |
55 | ||
56 | function addDiscoInfoHandler(jid, func) | |
57 | return helper:addDiscoInfoHandler(jid, func); | |
58 | end | |
59 | ||
420 | 60 | function set(plugin, var, origin) |
419
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
61 | -- TODO handle origin and host based on plugin. |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
62 | local handler = function(reply, to, from, node) -- service discovery |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
63 | if #node == 0 then |
420 | 64 | reply:tag("feature", {var = var}):up(); |
419
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
65 | return true; |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
66 | end |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
67 | end |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
68 | addDiscoInfoHandler("*node", handler); |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
69 | addDiscoInfoHandler("*host", handler); |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
70 | end |
af362df8e6fd
Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
393
diff
changeset
|
71 | |
388 | 72 | return _M; |