Annotate

core/discomanager.lua @ 535:74f32ac6db40

Automated merge with http://84.46.7.57:1234
author Matthew Wild <mwild1@gmail.com>
date Wed, 03 Dec 2008 19:34:41 +0000
parent 519:cccd610a0ef9
child 615:4ae3e81513f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 local helper = require "util.discohelper".new();
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 local hosts = hosts;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 local jid_split = require "util.jid".split;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 local jid_bare = require "util.jid".bare;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 local usermanager_user_exists = require "core.usermanager".user_exists;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
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
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 do
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 helper:addDiscoInfoHandler("*host", function(reply, to, from, node)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32 if hosts[to] then
517
afd9f6590fd0 lxmppd -> Prosody
Matthew Wild <mwild1@gmail.com>
parents: 420
diff changeset
33 reply:tag("identity", {category="server", type="im", name="Prosody"}):up();
388
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 return true;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 end);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 helper:addDiscoInfoHandler("*node", function(reply, to, from, node)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 local node, host = jid_split(to);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 if hosts[host] and rostermanager_is_contact_subscribed(node, host, jid_bare(from)) then
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 reply:tag("identity", {category="account", type="registered"}):up();
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 return true;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 end);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 module "discomanager"
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 function handle(stanza)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 return helper:handle(stanza);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 function addDiscoItemsHandler(jid, func)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 return helper:addDiscoItemsHandler(jid, func);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 function addDiscoInfoHandler(jid, func)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 return helper:addDiscoInfoHandler(jid, func);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
58 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
59
420
aa1db0a80089 Minor bug fix
Waqas Hussain <waqas20@gmail.com>
parents: 419
diff changeset
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
aa1db0a80089 Minor bug fix
Waqas Hussain <waqas20@gmail.com>
parents: 419
diff changeset
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
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
72 return _M;