Annotate

core/discomanager.lua @ 758:b1885732e979

GPL->MIT!
author Matthew Wild <mwild1@gmail.com>
date Fri, 30 Jan 2009 17:22:56 +0000
parent 648:3f34b83771eb
child 759:5cccfb5da6cb
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 --
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
388
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 local helper = require "util.discohelper".new();
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 local hosts = hosts;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 local jid_split = require "util.jid".split;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 local jid_bare = require "util.jid".bare;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 local usermanager_user_exists = require "core.usermanager".user_exists;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 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
17 local print = print;
388
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 do
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 helper:addDiscoInfoHandler("*host", function(reply, to, from, node)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 if hosts[to] then
517
afd9f6590fd0 lxmppd -> Prosody
Matthew Wild <mwild1@gmail.com>
parents: 420
diff changeset
22 reply:tag("identity", {category="server", type="im", name="Prosody"}):up();
388
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 return true;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 end);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 helper:addDiscoInfoHandler("*node", function(reply, to, from, node)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 local node, host = jid_split(to);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 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
29 reply:tag("identity", {category="account", type="registered"}):up();
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 return true;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
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);
388
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 module "discomanager"
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 function handle(stanza)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 return helper:handle(stanza);
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 function addDiscoItemsHandler(jid, func)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 return helper:addDiscoItemsHandler(jid, func);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50 function addDiscoInfoHandler(jid, func)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 return helper:addDiscoInfoHandler(jid, func);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53
420
aa1db0a80089 Minor bug fix
Waqas Hussain <waqas20@gmail.com>
parents: 419
diff changeset
54 function set(plugin, var, origin)
419
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
55 -- TODO handle origin and host based on plugin.
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
56 local handler = function(reply, to, from, node) -- service discovery
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
57 if #node == 0 then
420
aa1db0a80089 Minor bug fix
Waqas Hussain <waqas20@gmail.com>
parents: 419
diff changeset
58 reply:tag("feature", {var = var}):up();
419
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
59 return true;
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
60 end
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
61 end
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
62 addDiscoInfoHandler("*node", handler);
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
63 addDiscoInfoHandler("*host", handler);
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
64 end
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
65
388
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 return _M;