comparison mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua @ 6357:f24ff3e6e180

mod_pubsub_serverinfo: Some minor style/code tidying
author Matthew Wild <mwild1@gmail.com>
date Wed, 14 Jan 2026 13:55:36 +0000
parents a115f6a68d33
children de2651ba8bae
comparison
equal deleted inserted replaced
6356:a115f6a68d33 6357:f24ff3e6e180
37 function(exists) 37 function(exists)
38 if not exists then create_node() end 38 if not exists then create_node() end
39 end 39 end
40 ):catch( 40 ):catch(
41 function(error) 41 function(error)
42 module:log("warn", "Error prevented discovery or creation of pub/sub node at %s: %s", service, error) 42 module:log("warn", "Error prevented discovery or creation of pubsub node at %s: %s", service, error)
43 end 43 end
44 ) 44 )
45 45
46 module:add_feature("urn:xmpp:serverinfo:0"); 46 module:add_feature("urn:xmpp:serverinfo:0");
47 47
67 -- Returns a promise of a boolean 67 -- Returns a promise of a boolean
68 function discover_node() 68 function discover_node()
69 local request = st.iq({ type = "get", to = service, from = actor, id = new_id() }) 69 local request = st.iq({ type = "get", to = service, from = actor, id = new_id() })
70 :tag("query", { xmlns = "http://jabber.org/protocol/disco#items" }) 70 :tag("query", { xmlns = "http://jabber.org/protocol/disco#items" })
71 71
72 module:log("debug", "Sending request to discover existence of pub/sub node '%s' at %s", node, service) 72 module:log("debug", "Sending request to discover existence of pubsub node '%s' at %s", node, service)
73 return module:send_iq(request):next( 73 return module:send_iq(request):next(
74 function(response) 74 function(response)
75 if response.stanza == nil or response.stanza.attr.type ~= "result" then 75 if response.stanza == nil or response.stanza.attr.type ~= "result" then
76 module:log("warn", "Unexpected response to service discovery items request at %s: %s", service, response.stanza) 76 module:log("warn", "Unexpected response to service discovery items request at %s: %s", service, response.stanza)
77 return false 77 return false
79 79
80 local query = response.stanza:get_child("query", "http://jabber.org/protocol/disco#items") 80 local query = response.stanza:get_child("query", "http://jabber.org/protocol/disco#items")
81 if query ~= nil then 81 if query ~= nil then
82 for item in query:childtags("item") do 82 for item in query:childtags("item") do
83 if item.attr.jid == service and item.attr.node == node then 83 if item.attr.jid == service and item.attr.node == node then
84 module:log("debug", "pub/sub node '%s' at %s does exist.", node, service) 84 module:log("debug", "pubsub node '%s' at %s does exist.", node, service)
85 return true 85 return true
86 end 86 end
87 end 87 end
88 end 88 end
89 module:log("debug", "pub/sub node '%s' at %s does not exist.", node, service) 89 module:log("debug", "pubsub node '%s' at %s does not exist.", node, service)
90 return false; 90 return false;
91 end 91 end
92 ); 92 );
93 end 93 end
94 94
106 :text_tag("value", "1") 106 :text_tag("value", "1")
107 :up() 107 :up()
108 :tag("field", { var = "pubsub#persist_items" }) 108 :tag("field", { var = "pubsub#persist_items" })
109 :text_tag("value", persist_items and "1" or "0") 109 :text_tag("value", persist_items and "1" or "0")
110 110
111 module:log("debug", "Sending request to create pub/sub node '%s' at %s", node, service) 111 module:log("debug", "Sending request to create pubsub node '%s' at %s", node, service)
112 return module:send_iq(request):next( 112 return module:send_iq(request):next(
113 function(response) 113 function(response)
114 if response.stanza == nil or response.stanza.attr.type ~= "result" then 114 if response.stanza == nil or response.stanza.attr.type ~= "result" then
115 module:log("warn", "Unexpected response to pub/sub node '%s' creation request at %s: %s", node, service, response.stanza) 115 module:log("warn", "Unexpected response to pubsub node '%s' creation request at %s: %s", node, service, response.stanza)
116 return false 116 return false
117 else 117 else
118 module:log("debug", "Successfully created pub/sub node '%s' at %s", node, service) 118 module:log("debug", "Successfully created pubsub node '%s' at %s", node, service)
119 return true 119 return true
120 end 120 end
121 end 121 end
122 ) 122 )
123 end 123 end
126 function delete_node() 126 function delete_node()
127 local request = st.iq({ type = "set", to = service, from = actor, id = new_id() }) 127 local request = st.iq({ type = "set", to = service, from = actor, id = new_id() })
128 :tag("pubsub", { xmlns = xmlns_pubsub }) 128 :tag("pubsub", { xmlns = xmlns_pubsub })
129 :tag("delete", { node = node, xmlns = xmlns_pubsub }); 129 :tag("delete", { node = node, xmlns = xmlns_pubsub });
130 130
131 module:log("debug", "Sending request to delete pub/sub node '%s' at %s", node, service) 131 module:log("debug", "Sending request to delete pubsub node '%s' at %s", node, service)
132 return module:send_iq(request):next( 132 return module:send_iq(request):next(
133 function(response) 133 function(response)
134 if response.stanza == nil or response.stanza.attr.type ~= "result" then 134 if response.stanza == nil or response.stanza.attr.type ~= "result" then
135 module:log("warn", "Unexpected response to pub/sub node '%s' deletion request at %s: %s", node, service, response.stanza) 135 module:log("warn", "Unexpected response to pubsub node '%s' deletion request at %s: %s", node, service, response.stanza)
136 return false 136 return false
137 else 137 else
138 module:log("debug", "Successfully deleted pub/sub node '%s' at %s", node, service) 138 module:log("debug", "Successfully deleted pubsub node '%s' at %s", node, service)
139 return true 139 return true
140 end 140 end
141 end 141 end
142 ) 142 )
143 end 143 end
155 domains_by_host[session.to_host] = sessions 155 domains_by_host[session.to_host] = sessions
156 end 156 end
157 end 157 end
158 158
159 -- 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 159 -- 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
160 -- 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 160 -- too 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
161 -- other vhosts. Their data should then be published to distinct pub/sub services and nodes. 161 -- other vhosts. Their data should then be published to distinct pubsub services and nodes.
162 162
163 -- for host, data in pairs(prosody.hosts) do
164 local host = local_domain 163 local host = local_domain
165 local data = prosody.hosts[host] 164 local data = prosody.hosts[host]
166 if data ~= nil then 165 if data ~= nil then
167 local sessions = domains_by_host[host] 166 local sessions = domains_by_host[host]
168 if sessions == nil then sessions = {} end; -- instantiate a new entry if none existed 167 if sessions == nil then sessions = {} end; -- instantiate a new entry if none existed
240 module:log("debug", "Successfully published item on pub/sub node '%s' at %s", node, service) 239 module:log("debug", "Successfully published item on pub/sub node '%s' at %s", node, service)
241 return true 240 return true
242 end 241 end
243 end, 242 end,
244 function(error) 243 function(error)
245 module:log("warn", "Error prevented publication of item on pub/sub node at %s: %s", service, error) 244 module:log("warn", "Error prevented publication of item on pubsub node at %s: %s", service, error)
246 end 245 end
247 ) 246 )
248 247
249 return publication_interval; 248 return publication_interval;
250 end 249 end