Annotate

core/discomanager.lua @ 484:af499a5ee32f

Make ejabberd2prosody.lua eecutable
author Matthew Wild <mwild1@gmail.com>
date Sat, 29 Nov 2008 19:14:54 +0000
parent 420:aa1db0a80089
child 517:afd9f6590fd0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
388
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2 local helper = require "util.discohelper".new();
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 local hosts = hosts;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4 local jid_split = require "util.jid".split;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 local jid_bare = require "util.jid".bare;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6 local usermanager_user_exists = require "core.usermanager".user_exists;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7 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
8 local print = print;
388
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10 do
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 helper:addDiscoInfoHandler("*host", function(reply, to, from, node)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 if hosts[to] then
393
885a1864cd97 Ahem, a bit of an identity crisis..
Waqas Hussain <waqas20@gmail.com>
parents: 388
diff changeset
13 reply:tag("identity", {category="server", type="im", name="lxmppd"}):up();
388
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 return true;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 end);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 helper:addDiscoInfoHandler("*node", function(reply, to, from, node)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 local node, host = jid_split(to);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 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
20 reply:tag("identity", {category="account", type="registered"}):up();
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 return true;
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 end);
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
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 module "discomanager"
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 function handle(stanza)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 return helper:handle(stanza);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32 function addDiscoItemsHandler(jid, func)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 return helper:addDiscoItemsHandler(jid, func);
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 end
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 function addDiscoInfoHandler(jid, func)
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 return helper:addDiscoInfoHandler(jid, func);
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
420
aa1db0a80089 Minor bug fix
Waqas Hussain <waqas20@gmail.com>
parents: 419
diff changeset
40 function set(plugin, var, origin)
419
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
41 -- TODO handle origin and host based on plugin.
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
42 local handler = function(reply, to, from, node) -- service discovery
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
43 if #node == 0 then
420
aa1db0a80089 Minor bug fix
Waqas Hussain <waqas20@gmail.com>
parents: 419
diff changeset
44 reply:tag("feature", {var = var}):up();
419
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
45 return true;
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
46 end
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
47 end
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
48 addDiscoInfoHandler("*node", handler);
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
49 addDiscoInfoHandler("*host", handler);
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
50 end
af362df8e6fd Added helper method to discomanager
Waqas Hussain <waqas20@gmail.com>
parents: 393
diff changeset
51
388
9f520efc89ba Added discomanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 return _M;