Software /
code /
prosody
Annotate
core/discomanager.lua @ 455:2eeae9c314b0
main.lua -> prosody
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 29 Nov 2008 01:00:04 +0000 |
parent | 420:aa1db0a80089 |
child | 517:afd9f6590fd0 |
rev | line source |
---|---|
388 | 1 |
2 local helper = require "util.discohelper".new(); | |
3 local hosts = hosts; | |
4 local jid_split = require "util.jid".split; | |
5 local jid_bare = require "util.jid".bare; | |
6 local usermanager_user_exists = require "core.usermanager".user_exists; | |
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 | 9 |
10 do | |
11 helper:addDiscoInfoHandler("*host", function(reply, to, from, node) | |
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 | 14 return true; |
15 end | |
16 end); | |
17 helper:addDiscoInfoHandler("*node", function(reply, to, from, node) | |
18 local node, host = jid_split(to); | |
19 if hosts[host] and rostermanager_is_contact_subscribed(node, host, jid_bare(from)) then | |
20 reply:tag("identity", {category="account", type="registered"}):up(); | |
21 return true; | |
22 end | |
23 end); | |
24 end | |
25 | |
26 module "discomanager" | |
27 | |
28 function handle(stanza) | |
29 return helper:handle(stanza); | |
30 end | |
31 | |
32 function addDiscoItemsHandler(jid, func) | |
33 return helper:addDiscoItemsHandler(jid, func); | |
34 end | |
35 | |
36 function addDiscoInfoHandler(jid, func) | |
37 return helper:addDiscoInfoHandler(jid, func); | |
38 end | |
39 | |
420 | 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 | 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 | 52 return _M; |