comparison plugins/mod_bosh.lua @ 13960:b1e9942ce471

mod_bosh: Move all namespaces to variables at the top Consistency. Having `xmlns_bosh` hard-coded wasn't needed after 16c7b510694b
author Kim Alvefur <zash@zash.se>
date Sun, 22 Jun 2025 21:31:37 +0200
parents 08c2b7accd94
children ab7be38146bc
comparison
equal deleted inserted replaced
13959:1b95d50cfa18 13960:b1e9942ce471
24 local nameprep = require "prosody.util.encodings".stringprep.nameprep; 24 local nameprep = require "prosody.util.encodings".stringprep.nameprep;
25 local cache = require "prosody.util.cache"; 25 local cache = require "prosody.util.cache";
26 26
27 local xmlns_streams = "http://etherx.jabber.org/streams"; 27 local xmlns_streams = "http://etherx.jabber.org/streams";
28 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; 28 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams";
29 local xmlns_bosh = "http://jabber.org/protocol/httpbind"; -- (hard-coded into a literal in session.send) 29 local xmlns_bosh = "http://jabber.org/protocol/httpbind";
30 local xmlns_xbosh = "urn:xmpp:xbosh";
30 31
31 local stream_callbacks = { 32 local stream_callbacks = {
32 stream_ns = xmlns_bosh, stream_tag = "body", default_ns = "jabber:client" }; 33 stream_ns = xmlns_bosh, stream_tag = "body", default_ns = "jabber:client" };
33 34
34 -- These constants are implicitly assumed within the code, and cannot be changed 35 -- These constants are implicitly assumed within the code, and cannot be changed
221 end 222 end
222 end 223 end
223 224
224 local function bosh_reset_stream(session) session.notopen = true; end 225 local function bosh_reset_stream(session) session.notopen = true; end
225 226
226 local stream_xmlns_attr = { xmlns = "urn:ietf:params:xml:ns:xmpp-streams" }; 227 local stream_xmlns_attr = { xmlns = xmlns_xmpp_streams };
227 local function bosh_close_stream(session, reason) 228 local function bosh_close_stream(session, reason)
228 (session.log or log)("info", "BOSH client disconnected: %s", (reason and reason.condition or reason) or "session close"); 229 (session.log or log)("info", "BOSH client disconnected: %s", (reason and reason.condition or reason) or "session close");
229 230
230 local close_reply = st.stanza("body", { xmlns = xmlns_bosh, type = "terminate", 231 local close_reply = st.stanza("body", { xmlns = xmlns_bosh, type = "terminate",
231 ["xmlns:stream"] = xmlns_streams }); 232 ["xmlns:stream"] = xmlns_streams });
364 t_insert(session.send_buffer, tostring(s)); 365 t_insert(session.send_buffer, tostring(s));
365 366
366 local oldest_request = r[1]; 367 local oldest_request = r[1];
367 if oldest_request and not session.bosh_processing then 368 if oldest_request and not session.bosh_processing then
368 log("debug", "We have an open request, so sending on that"); 369 log("debug", "We have an open request, so sending on that");
369 local body_attr = { xmlns = "http://jabber.org/protocol/httpbind", 370 local body_attr = { xmlns = xmlns_bosh,
370 ["xmlns:stream"] = "http://etherx.jabber.org/streams"; 371 ["xmlns:stream"] = xmlns_streams;
371 type = session.bosh_terminate and "terminate" or nil; 372 type = session.bosh_terminate and "terminate" or nil;
372 sid = sid; 373 sid = sid;
373 }; 374 };
374 if creating_session then 375 if creating_session then
375 creating_session = nil; 376 creating_session = nil;
380 body_attr.wait = tostring(session.bosh_wait); 381 body_attr.wait = tostring(session.bosh_wait);
381 body_attr.authid = sid; 382 body_attr.authid = sid;
382 body_attr.secure = "true"; 383 body_attr.secure = "true";
383 body_attr.ver = '1.6'; 384 body_attr.ver = '1.6';
384 body_attr.from = session.host; 385 body_attr.from = session.host;
385 body_attr["xmlns:xmpp"] = "urn:xmpp:xbosh"; 386 body_attr["xmlns:xmpp"] = xmlns_xbosh;
386 body_attr["xmpp:version"] = "1.0"; 387 body_attr["xmpp:version"] = "1.0";
387 end 388 end
388 local response_xml = st.stanza("body", body_attr):top_tag()..t_concat(session.send_buffer).."</body>"; 389 local response_xml = st.stanza("body", body_attr):top_tag()..t_concat(session.send_buffer).."</body>";
389 session.bosh_responses[oldest_request.context.rid] = response_xml; 390 session.bosh_responses[oldest_request.context.rid] = response_xml;
390 oldest_request:send(response_xml); 391 oldest_request:send(response_xml);