Mercurial > prosody-modules
annotate mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua @ 5808:2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Prosody does not have s2s connections between vhosts. Multiple domains will therefor not show up as each-other 'remote domains'.
With this commit, the module considers vhosts permanently s2s-connected.
Additional debug logging has been added.
author | Guus der Kinderen <guus.der.kinderen@gmail.com> |
---|---|
date | Thu, 04 Jan 2024 15:14:19 +0100 |
parents | 55b99f593c3a |
children | a8cae8322b7c |
rev | line source |
---|---|
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
1 local st = require "util.stanza"; |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
2 local new_id = require"util.id".medium; |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
3 local dataform = require "util.dataforms".new; |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
4 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
5 local local_domain = module:get_host(); |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
6 local service = module:get_option(module.name .. "_service") or "pubsub." .. local_domain; |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
7 local node = module:get_option(module.name .. "_node") or "serverinfo"; |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
8 local actor = module.host .. "/modules/" .. module.name; |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
9 local publication_interval = module:get_option(module.name .. "_publication_interval") or 300; |
5805
55b99f593c3a
mod_pubsub_serverinfo: Disco/info cache TTL should be configurable
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5804
diff
changeset
|
10 local cache_ttl = module:get_option(module.name .. "_cache_ttl") or 3600; |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
11 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
12 local opt_in_reports |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
13 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
14 function module.load() |
5804
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
15 discover_node():next( |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
16 function(exists) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
17 if not exists then create_node() end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
18 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
19 ):catch( |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
20 function(error) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
21 module:log("warn", "Error prevented discovery or creation of pub/sub node at %s: %s", service, error) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
22 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
23 ) |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
24 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
25 module:add_feature("urn:xmpp:serverinfo:0"); |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
26 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
27 module:add_extension(dataform { |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
28 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/network/serverinfo" }, |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
29 { name = "serverinfo-pubsub-node", type = "text-single" }, |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
30 }:form({ ["serverinfo-pubsub-node"] = ("xmpp:%s?;node=%s"):format(service, node) }, "result")); |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
31 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
32 module:add_timer(10, publish_serverinfo); |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
33 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
34 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
35 function module.unload() |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
36 -- This removes all subscribers, which may or may not be desirable, depending on the reason for the unload. |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
37 delete_node(); -- Should this block, to delay unload() until the node is deleted? |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
38 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
39 |
5804
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
40 -- Returns a promise of a boolean |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
41 function discover_node() |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
42 local request = st.iq({ type = "get", to = service, from = actor, id = new_id() }) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
43 :tag("query", { xmlns = "http://jabber.org/protocol/disco#items" }) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
44 |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
45 module:log("debug", "Sending request to discover existence of pub/sub node '%s' at %s", node, service) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
46 return module:send_iq(request):next( |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
47 function(response) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
48 if response.stanza == nil or response.stanza.attr.type ~= "result" then |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
49 module:log("warn", "Unexpected response to service discovery items request at %s: %s", service, response.stanza) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
50 return false |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
51 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
52 |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
53 local query = response.stanza:get_child("query", "http://jabber.org/protocol/disco#items") |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
54 if query ~= nil then |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
55 for item in query:childtags("item") do |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
56 if item.attr.jid == service and item.attr.node == node then |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
57 module:log("debug", "pub/sub node '%s' at %s does exists.", node, service) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
58 return true |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
59 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
60 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
61 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
62 module:log("debug", "pub/sub node '%s' at %s does not exist.", node, service) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
63 return false; |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
64 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
65 ); |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
66 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
67 |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
68 -- Returns a promise of a boolean |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
69 function create_node() |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
70 local request = st.iq({ type = "set", to = service, from = actor, id = new_id() }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
71 :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
72 :tag("create", { node = node }):up() |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
73 :tag("configure") |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
74 :tag("x", { xmlns = "jabber:x:data", type = "submit" }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
75 :tag("field", { var = "FORM_TYPE", type = "hidden"}) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
76 :text_tag("value", "http://jabber.org/protocol/pubsub#node_config") |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
77 :up() |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
78 :tag("field", { var = "pubsub#max_items" }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
79 :text_tag("value", "1") |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
80 :up() |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
81 :tag("field", { var = "pubsub#persist_items" }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
82 :text_tag("value", "0") |
5804
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
83 |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
84 module:log("debug", "Sending request to create pub/sub node '%s' at %s", node, service) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
85 return module:send_iq(request):next( |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
86 function(response) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
87 if response.stanza == nil or response.stanza.attr.type ~= "result" then |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
88 module:log("warn", "Unexpected response to pub/sub node '%s' creation request at %s: %s", node, service, response.stanza) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
89 return false |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
90 else |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
91 module:log("debug", "Successfully created pub/sub node '%s' at %s", node, service) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
92 return true |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
93 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
94 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
95 ) |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
96 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
97 |
5804
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
98 -- Returns a promise of a boolean |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
99 function delete_node() |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
100 local request = st.iq({ type = "set", to = service, from = actor, id = new_id() }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
101 :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
102 :tag("delete", { node = node }); |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
103 |
5804
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
104 module:log("debug", "Sending request to delete pub/sub node '%s' at %s", node, service) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
105 return module:send_iq(request):next( |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
106 function(response) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
107 if response.stanza == nil or response.stanza.attr.type ~= "result" then |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
108 module:log("warn", "Unexpected response to pub/sub node '%s' deletion request at %s: %s", node, service, response.stanza) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
109 return false |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
110 else |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
111 module:log("debug", "Successfully deleted pub/sub node '%s' at %s", node, service) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
112 return true |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
113 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
114 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
115 ) |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
116 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
117 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
118 function publish_serverinfo() |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
119 -- Iterate over s2s sessions, adding them to a multimap, where the key is the local domain name, |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
120 -- mapped to a collection of remote domain names. De-duplicate all remote domain names by using |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
121 -- them as an index in a table. |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
122 local domains_by_host = {} |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
123 for session, _ in pairs(prosody.incoming_s2s) do |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
124 if session ~= nil and session.from_host ~= nil and local_domain == session.to_host then |
5808
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
125 module:log("debug", "Local host '%s' has remote '%s' (inbound)", session.to_host, session.from_host); |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
126 local sessions = domains_by_host[session.to_host] |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
127 if sessions == nil then sessions = {} end; -- instantiate a new entry if none existed |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
128 sessions[session.from_host] = true |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
129 domains_by_host[session.to_host] = sessions |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
130 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
131 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
132 |
5808
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
133 -- At an earlier stage, the code iterated over all prosody.hosts, trying to generate one pubsub item for all local hosts. That turned out to be |
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
134 -- to noisy. Instead, this code now creates an item that includes the local vhost only. It is assumed that this module will also be loaded for |
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
135 -- other vhosts. Their data should then be published to distinct pub/sub services and nodes. |
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
136 |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
137 -- for host, data in pairs(prosody.hosts) do |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
138 local host = local_domain |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
139 local data = prosody.hosts[host] |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
140 if data ~= nil then |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
141 local sessions = domains_by_host[host] |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
142 if sessions == nil then sessions = {} end; -- instantiate a new entry if none existed |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
143 if data.s2sout ~= nil then |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
144 for _, session in pairs(data.s2sout) do |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
145 if session.to_host ~= nil then |
5808
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
146 module:log("debug", "Local host '%s' has remote '%s' (outbound)", host, session.to_host); |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
147 sessions[session.to_host] = true |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
148 domains_by_host[host] = sessions |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
149 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
150 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
151 end |
5808
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
152 |
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
153 -- When the instance of Prosody hosts more than one host, the other hosts can be thought of as having a 'permanent' s2s connection. |
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
154 for host_name, host_info in pairs(prosody.hosts) do |
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
155 if host ~= host_name and host_info.type ~= "component" then |
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
156 module:log("debug", "Local host '%s' has remote '%s' (vhost)", host, host_name); |
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
157 sessions[host_name] = true; |
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
158 domains_by_host[host] = sessions |
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
159 end |
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
160 end |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
161 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
162 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
163 -- Build the publication stanza. |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
164 local request = st.iq({ type = "set", to = service, from = actor, id = new_id() }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
165 :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
166 :tag("publish", { node = node, xmlns = "http://jabber.org/protocol/pubsub" }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
167 :tag("item", { id = "current", xmlns = "http://jabber.org/protocol/pubsub" }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
168 :tag("serverinfo", { xmlns = "urn:xmpp:serverinfo:0" }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
169 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
170 request:tag("domain", { name = local_domain }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
171 :tag("federation") |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
172 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
173 local remotes = domains_by_host[host] |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
174 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
175 if remotes ~= nil then |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
176 for remote, _ in pairs(remotes) do |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
177 -- include a domain name for remote domains, but only if they advertise support. |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
178 if does_opt_in(remote) then |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
179 request:tag("remote-domain", { name = remote }):up() |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
180 else |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
181 request:tag("remote-domain"):up() |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
182 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
183 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
184 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
185 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
186 request:up():up() |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
187 |
5804
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
188 module:send_iq(request):next( |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
189 function(response) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
190 if response.stanza == nil or response.stanza.attr.type ~= "result" then |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
191 module:log("warn", "Unexpected response to item publication at pub/sub node '%s' on %s: %s", node, service, response.stanza) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
192 return false |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
193 else |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
194 module:log("debug", "Successfully published item on pub/sub node '%s' at %s", node, service) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
195 return true |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
196 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
197 end, |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
198 function(error) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
199 module:log("warn", "Error prevented publication of item on pub/sub node at %s: %s", service, error) |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
200 end |
c3eeeb968403
mod_pubsub_serverinfo: Detect existence of pub/sub node
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5803
diff
changeset
|
201 ) |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
202 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
203 return publication_interval; |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
204 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
205 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
206 local opt_in_cache = {} |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
207 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
208 function does_opt_in(remoteDomain) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
209 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
210 -- try to read answer from cache. |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
211 local cached_value = opt_in_cache[remoteDomain] |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
212 if cached_value ~= nil and os.difftime(cached_value.expires, os.time()) > 0 then |
5808
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
213 module:log("debug", "Opt-in status (from cache) for '%s': %s", remoteDomain, cached_value.opt_in) |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
214 return cached_value.opt_in; |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
215 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
216 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
217 -- TODO worry about not having multiple requests in flight to the same domain.cached_value |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
218 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
219 -- Cache could not provide an answer. Perform service discovery. |
5808
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
220 module:log("debug", "No cached opt-in status for '%s': performing disco/info to determine opt-in.", remoteDomain) |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
221 local discoRequest = st.iq({ type = "get", to = remoteDomain, from = actor, id = new_id() }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
222 :tag("query", { xmlns = "http://jabber.org/protocol/disco#info" }) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
223 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
224 module:send_iq(discoRequest):next( |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
225 function(response) |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
226 if response.stanza ~= nil and response.stanza.attr.type == "result" then |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
227 local query = response.stanza:get_child("query", "http://jabber.org/protocol/disco#info") |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
228 if query ~= nil then |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
229 for feature in query:childtags("feature", "http://jabber.org/protocol/disco#info") do |
5808
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
230 module:log("debug", "Disco/info feature for '%s': %s", remoteDomain, feature) |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
231 if feature.attr.var == 'urn:xmpp:serverinfo:0' then |
5808
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
232 module:log("debug", "Disco/info response included opt-in for '%s'", remoteDomain) |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
233 opt_in_cache[remoteDomain] = { |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
234 opt_in = true; |
5805
55b99f593c3a
mod_pubsub_serverinfo: Disco/info cache TTL should be configurable
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5804
diff
changeset
|
235 expires = os.time() + cache_ttl; |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
236 } |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
237 return; -- prevent 'false' to be cached, down below. |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
238 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
239 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
240 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
241 end |
5808
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
242 module:log("debug", "Disco/info response did not include opt-in for '%s'", remoteDomain) |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
243 opt_in_cache[remoteDomain] = { |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
244 opt_in = false; |
5805
55b99f593c3a
mod_pubsub_serverinfo: Disco/info cache TTL should be configurable
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5804
diff
changeset
|
245 expires = os.time() + cache_ttl; |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
246 } |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
247 end, |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
248 function(response) |
5808
2465d5191ae9
mod_pubsub_serverinfo: Consider sibling vhosts 'connected'
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5805
diff
changeset
|
249 module:log("debug", "An error occurred while performing a disco/info request to determine opt-in for '%s'", remoteDomain, response) |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
250 opt_in_cache[remoteDomain] = { |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
251 opt_in = false; |
5805
55b99f593c3a
mod_pubsub_serverinfo: Disco/info cache TTL should be configurable
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5804
diff
changeset
|
252 expires = os.time() + cache_ttl; |
5803
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
253 } |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
254 end |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
255 ); |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
256 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
257 -- return 'false' for now. Better luck next time... |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
258 return false; |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
259 |
f55e65315ba0
mod_pubsub_serverinfo: implemented all basic features
Guus der Kinderen <guus.der.kinderen@gmail.com>
parents:
5801
diff
changeset
|
260 end |