Software /
code /
prosody
Annotate
core/discomanager.lua @ 1003:afae75e37ceb
core.xmlhandlers: expat is the XML parser, not us. Don't reject valid XML.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 18 Apr 2009 04:06:41 +0100 |
parent | 896:2c0b9e3c11c3 |
child | 1512:81628dfcc4ee |
rev | line source |
---|---|
896 | 1 -- Prosody IM v0.4 |
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 | 5 -- This project is MIT/X11 licensed. Please see the |
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 | 10 |
11 local helper = require "util.discohelper".new(); | |
12 local hosts = hosts; | |
13 local jid_split = require "util.jid".split; | |
14 local jid_bare = require "util.jid".bare; | |
15 local usermanager_user_exists = require "core.usermanager".user_exists; | |
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 | 18 |
19 do | |
20 helper:addDiscoInfoHandler("*host", function(reply, to, from, node) | |
21 if hosts[to] then | |
517 | 22 reply:tag("identity", {category="server", type="im", name="Prosody"}):up(); |
388 | 23 return true; |
24 end | |
25 end); | |
26 helper:addDiscoInfoHandler("*node", function(reply, to, from, node) | |
27 local node, host = jid_split(to); | |
28 if hosts[host] and rostermanager_is_contact_subscribed(node, host, jid_bare(from)) then | |
29 reply:tag("identity", {category="account", type="registered"}):up(); | |
30 return true; | |
31 end | |
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 | 38 end |
39 | |
40 module "discomanager" | |
41 | |
42 function handle(stanza) | |
43 return helper:handle(stanza); | |
44 end | |
45 | |
46 function addDiscoItemsHandler(jid, func) | |
47 return helper:addDiscoItemsHandler(jid, func); | |
48 end | |
49 | |
50 function addDiscoInfoHandler(jid, func) | |
51 return helper:addDiscoInfoHandler(jid, func); | |
52 end | |
53 | |
420 | 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 | 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 | 66 return _M; |