Annotate

core/discomanager.lua @ 1563:c5078fab0978

Tagging 0.5.0
author Matthew Wild <mwild1@gmail.com>
date Mon, 20 Jul 2009 14:59:51 +0100
parent 1523:841d61be198f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1523
841d61be198f Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents: 1512
diff changeset
1 -- Prosody IM
760
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
2 -- Copyright (C) 2008-2009 Matthew Wild
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
3 -- Copyright (C) 2008-2009 Waqas Hussain
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 517
diff changeset
4 --
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 648
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 648
diff changeset
6 -- COPYING file in the source package for more information.
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 517
diff changeset
7 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 517
diff changeset
8
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 517
diff changeset
9
1512
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
10
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
11 local helper = require "util.discohelper".new();
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
12 local hosts = hosts;
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
13 local jid_split = require "util.jid".split;
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
14 local jid_bare = require "util.jid".bare;
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
15 local usermanager_user_exists = require "core.usermanager".user_exists;
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
16 local rostermanager_is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
17 local print = print;
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
18
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
19 do
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
20 helper:addDiscoInfoHandler("*host", function(reply, to, from, node)
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
21 if hosts[to] then
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
22 reply:tag("identity", {category="server", type="im", name="Prosody"}):up();
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
23 return true;
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
24 end
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
25 end);
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
26 helper:addDiscoInfoHandler("*node", function(reply, to, from, node)
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
27 local node, host = jid_split(to);
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
28 if hosts[host] and rostermanager_is_contact_subscribed(node, host, jid_bare(from)) then
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
29 reply:tag("identity", {category="account", type="registered"}):up();
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
30 return true;
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
31 end
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
32 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
33 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
34 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
35 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
36 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
37 end);
1512
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
38 end
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
39
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
40 module "discomanager"
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
41
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
42 function handle(stanza)
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
43 return helper:handle(stanza);
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
44 end
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
45
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
46 function addDiscoItemsHandler(jid, func)
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
47 return helper:addDiscoItemsHandler(jid, func);
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
48 end
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
49
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
50 function addDiscoInfoHandler(jid, func)
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
51 return helper:addDiscoInfoHandler(jid, func);
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
52 end
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
53
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
54 function set(plugin, var, origin)
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
55 -- TODO handle origin and host based on plugin.
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
56 local handler = function(reply, to, from, node) -- service discovery
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
57 if #node == 0 then
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
58 reply:tag("feature", {var = var}):up();
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
59 return true;
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
60 end
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
61 end
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
62 addDiscoInfoHandler("*node", handler);
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
63 addDiscoInfoHandler("*host", handler);
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
64 end
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
65
81628dfcc4ee discomanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
66 return _M;