Annotate

core/discomanager.lua @ 661:59c3f9a49969 0.2.0

Small fix for logging in connlisteners (warning != warn)
author Matthew Wild <mwild1@gmail.com>
date Sat, 27 Dec 2008 21:25:08 +0000
parent 648:3f34b83771eb
child 758:b1885732e979
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
615
4ae3e81513f3 0.1 -> 0.2
Matthew Wild <mwild1@gmail.com>
parents: 519
diff changeset
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
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);
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
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 module "discomanager"
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 function handle(stanza)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 return helper:handle(stanza);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 function addDiscoItemsHandler(jid, func)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
58 return helper:addDiscoItemsHandler(jid, func);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
59 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
60
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
61 function addDiscoInfoHandler(jid, func)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62 return helper:addDiscoInfoHandler(jid, func);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64
420
aa1db0a80089 Minor bug fix
Waqas Hussain <waqas20@gmail.com>
parents: 419
diff changeset
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
aa1db0a80089 Minor bug fix
Waqas Hussain <waqas20@gmail.com>
parents: 419
diff changeset
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
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
77 return _M;