comparison plugins/mod_bosh.lua @ 13963:44f859531df7

mod_bosh: Tweak logging Tries to use logger from session or request for easier correlation. Why were we even logging the whole <body> there? Inconsistent with mod_c2s.
author Kim Alvefur <zash@zash.se>
date Sat, 27 Sep 2025 18:26:18 +0200
parents c5a2846c9cba
children c1469296190d
comparison
equal deleted inserted replaced
13962:c5a2846c9cba 13963:44f859531df7
77 measure_inactive(inactive); 77 measure_inactive(inactive);
78 end); 78 end);
79 79
80 -- Used to respond to idle sessions (those with waiting requests) 80 -- Used to respond to idle sessions (those with waiting requests)
81 function on_destroy_request(request) 81 function on_destroy_request(request)
82 local log = request.log or log;
82 log("debug", "Request destroyed: %s", request); 83 log("debug", "Request destroyed: %s", request);
83 local session = sessions[request.context.sid]; 84 local session = sessions[request.context.sid];
84 if session then 85 if session then
86 log = session.log or log;
85 local requests = session.requests; 87 local requests = session.requests;
86 for i, r in ipairs(requests) do 88 for i, r in ipairs(requests) do
87 if r == request then 89 if r == request then
88 t_remove(requests, i); 90 t_remove(requests, i);
89 break; 91 break;
114 sm_destroy_session(session, reason); 116 sm_destroy_session(session, reason);
115 end 117 end
116 end 118 end
117 119
118 function handle_POST(event) 120 function handle_POST(event)
119 log("debug", "Handling new request %s: %s\n----------", event.request, event.request.body);
120
121 local request, response = event.request, event.response; 121 local request, response = event.request, event.response;
122 local log = request.log or log;
122 response.on_destroy = on_destroy_request; 123 response.on_destroy = on_destroy_request;
123 local body = request.body; 124 local body = request.body;
124 125
125 local context = { request = request, response = response, notopen = true }; 126 local context = { request = request, response = response, notopen = true };
126 local stream = new_xmpp_stream(context, stream_callbacks, stanza_size_limit); 127 local stream = new_xmpp_stream(context, stream_callbacks, stanza_size_limit);
264 local runner_callbacks = { }; 265 local runner_callbacks = { };
265 266
266 -- Handle the <body> tag in the request payload. 267 -- Handle the <body> tag in the request payload.
267 function stream_callbacks.streamopened(context, attr) 268 function stream_callbacks.streamopened(context, attr)
268 local request, response = context.request, context.response; 269 local request, response = context.request, context.response;
270 local log = request.log or log;
269 local sid, rid = attr.sid, tonumber(attr.rid); 271 local sid, rid = attr.sid, tonumber(attr.rid);
270 log("debug", "BOSH body open (sid: %s)", sid or "<none>"); 272 log("debug", "BOSH body open (sid: %s)", sid or "<none>");
271 context.rid = rid; 273 context.rid = rid;
272 if not sid then 274 if not sid then
273 -- New session request 275 -- New session request
381 body_attr.inactivity = tostring(bosh_max_inactivity); 383 body_attr.inactivity = tostring(bosh_max_inactivity);
382 body_attr.polling = tostring(bosh_max_polling); 384 body_attr.polling = tostring(bosh_max_polling);
383 body_attr.wait = tostring(session.bosh_wait); 385 body_attr.wait = tostring(session.bosh_wait);
384 body_attr.authid = sid; 386 body_attr.authid = sid;
385 body_attr.secure = "true"; 387 body_attr.secure = "true";
386 body_attr.ver = '1.6'; 388 body_attr.ver = '1.6';
387 body_attr.from = session.host; 389 body_attr.from = session.host;
388 body_attr["xmlns:xmpp"] = xmlns_xbosh; 390 body_attr["xmlns:xmpp"] = xmlns_xbosh;
389 body_attr["xmpp:version"] = "1.0"; 391 body_attr["xmpp:version"] = "1.0";
390 end 392 end
391 local response_xml = st.stanza("body", body_attr):top_tag()..t_concat(session.send_buffer).."</body>"; 393 local response_xml = st.stanza("body", body_attr):top_tag()..t_concat(session.send_buffer).."</body>";
471 return handleerr(err); 473 return handleerr(err);
472 end 474 end
473 475
474 function stream_callbacks.handlestanza(context, stanza) 476 function stream_callbacks.handlestanza(context, stanza)
475 if context.ignore then return; end 477 if context.ignore then return; end
476 log("debug", "BOSH stanza received: %s\n", stanza:top_tag());
477 local session = sessions[context.sid]; 478 local session = sessions[context.sid];
478 if session then 479 if session then
479 if stanza.attr.xmlns == xmlns_bosh then 480 if stanza.attr.xmlns == xmlns_bosh then
480 stanza.attr.xmlns = nil; 481 stanza.attr.xmlns = nil;
481 end 482 end