Mercurial > prosody-modules
comparison mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua @ 5813:d38772479891
mod_pubsub_serverinfo: Some logging improvements
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 08 Jan 2024 15:51:52 +0000 |
parents | cf5f77491323 |
children | fa28fc2ee465 |
comparison
equal
deleted
inserted
replaced
5812:cf5f77491323 | 5813:d38772479891 |
---|---|
27 module:add_extension(dataform { | 27 module:add_extension(dataform { |
28 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/network/serverinfo" }, | 28 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/network/serverinfo" }, |
29 { name = "serverinfo-pubsub-node", type = "text-single" }, | 29 { name = "serverinfo-pubsub-node", type = "text-single" }, |
30 }:form({ ["serverinfo-pubsub-node"] = ("xmpp:%s?;node=%s"):format(service, node) }, "result")); | 30 }:form({ ["serverinfo-pubsub-node"] = ("xmpp:%s?;node=%s"):format(service, node) }, "result")); |
31 | 31 |
32 if cache_ttl < publication_interval then | |
33 module:log("warn", "It is recommended to have a cache interval higher than the publication interval"); | |
34 end | |
35 | |
32 cache_warm_up() | 36 cache_warm_up() |
33 module:add_timer(10, publish_serverinfo); | 37 module:add_timer(10, publish_serverinfo); |
34 end | 38 end |
35 | 39 |
36 function module.unload() | 40 function module.unload() |
53 | 57 |
54 local query = response.stanza:get_child("query", "http://jabber.org/protocol/disco#items") | 58 local query = response.stanza:get_child("query", "http://jabber.org/protocol/disco#items") |
55 if query ~= nil then | 59 if query ~= nil then |
56 for item in query:childtags("item") do | 60 for item in query:childtags("item") do |
57 if item.attr.jid == service and item.attr.node == node then | 61 if item.attr.jid == service and item.attr.node == node then |
58 module:log("debug", "pub/sub node '%s' at %s does exists.", node, service) | 62 module:log("debug", "pub/sub node '%s' at %s does exist.", node, service) |
59 return true | 63 return true |
60 end | 64 end |
61 end | 65 end |
62 end | 66 end |
63 module:log("debug", "pub/sub node '%s' at %s does not exist.", node, service) | 67 module:log("debug", "pub/sub node '%s' at %s does not exist.", node, service) |
163 | 167 |
164 return domains_by_host | 168 return domains_by_host |
165 end | 169 end |
166 | 170 |
167 function publish_serverinfo() | 171 function publish_serverinfo() |
172 module:log("debug", "Publishing server info..."); | |
168 local domains_by_host = get_remote_domain_names() | 173 local domains_by_host = get_remote_domain_names() |
169 | 174 |
170 -- Build the publication stanza. | 175 -- Build the publication stanza. |
171 local request = st.iq({ type = "set", to = service, from = actor, id = new_id() }) | 176 local request = st.iq({ type = "set", to = service, from = actor, id = new_id() }) |
172 :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" }) | 177 :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" }) |
234 end | 239 end |
235 | 240 |
236 -- We don't have a cached value, or it is nearing expiration - refresh it now | 241 -- We don't have a cached value, or it is nearing expiration - refresh it now |
237 -- TODO worry about not having multiple requests in flight to the same domain.cached_value | 242 -- TODO worry about not having multiple requests in flight to the same domain.cached_value |
238 | 243 |
239 module:log("debug", "No cached opt-in status for '%s': performing disco/info to determine opt-in.", remoteDomain) | 244 module:log("debug", "%s: performing disco/info to determine opt-in", remoteDomain) |
240 local discoRequest = st.iq({ type = "get", to = remoteDomain, from = actor, id = new_id() }) | 245 local discoRequest = st.iq({ type = "get", to = remoteDomain, from = actor, id = new_id() }) |
241 :tag("query", { xmlns = "http://jabber.org/protocol/disco#info" }) | 246 :tag("query", { xmlns = "http://jabber.org/protocol/disco#info" }) |
242 | 247 |
243 module:send_iq(discoRequest):next( | 248 module:send_iq(discoRequest):next( |
244 function(response) | 249 function(response) |
245 if response.stanza ~= nil and response.stanza.attr.type == "result" then | 250 if response.stanza ~= nil and response.stanza.attr.type == "result" then |
246 local query = response.stanza:get_child("query", "http://jabber.org/protocol/disco#info") | 251 local query = response.stanza:get_child("query", "http://jabber.org/protocol/disco#info") |
247 if query ~= nil then | 252 if query ~= nil then |
248 for feature in query:childtags("feature") do | 253 for feature in query:childtags("feature") do |
249 module:log("debug", "Disco/info feature for '%s': %s", remoteDomain, feature) | 254 --module:log("debug", "Disco/info feature for '%s': %s", remoteDomain, feature) |
250 if feature.attr.var == 'urn:xmpp:serverinfo:0' then | 255 if feature.attr.var == 'urn:xmpp:serverinfo:0' then |
251 module:log("debug", "Disco/info response included opt-in for '%s'", remoteDomain) | 256 module:log("debug", "Disco/info response included opt-in for '%s'", remoteDomain) |
252 opt_in_cache[remoteDomain] = { | 257 opt_in_cache[remoteDomain] = { |
253 opt_in = true; | 258 opt_in = true; |
254 expires = os.time() + cache_ttl; | 259 expires = os.time() + cache_ttl; |