Software /
code /
prosody
Comparison
plugins/mod_bosh.lua @ 4223:9fb6e8ec15ed
mod_bosh: Fix terminate logic - process any stanzas in a terminating request, and add type='terminate' to any responses generated by those stanzas. Finally, close all remaining open requests with type='terminate' and close the session. Fixes #211 (thanks Maranda + waqas).
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 04 Mar 2011 20:27:57 +0000 |
parent | 4102:9df4e61c260b |
child | 4316:2478698bdc52 |
comparison
equal
deleted
inserted
replaced
4222:2805ebd57d7d | 4223:9fb6e8ec15ed |
---|---|
160 request.reply_before = os_time() + session.bosh_wait; | 160 request.reply_before = os_time() + session.bosh_wait; |
161 waiting_requests[request] = true; | 161 waiting_requests[request] = true; |
162 end | 162 end |
163 end | 163 end |
164 | 164 |
165 return true; -- Inform httpserver we shall reply later | 165 if session.bosh_terminate then |
166 session.log("debug", "Closing session with %d requests open", #session.requests); | |
167 session:close(); | |
168 return nil; | |
169 else | |
170 return true; -- Inform httpserver we shall reply later | |
171 end | |
166 end | 172 end |
167 end | 173 end |
168 | 174 |
169 | 175 |
170 local function bosh_reset_stream(session) session.notopen = true; end | 176 local function bosh_reset_stream(session) session.notopen = true; end |
200 log("info", "Disconnecting client, <stream:error> is: %s", tostring(close_reply)); | 206 log("info", "Disconnecting client, <stream:error> is: %s", tostring(close_reply)); |
201 end | 207 end |
202 | 208 |
203 local session_close_response = { headers = default_headers, body = tostring(close_reply) }; | 209 local session_close_response = { headers = default_headers, body = tostring(close_reply) }; |
204 | 210 |
205 --FIXME: Quite sure we shouldn't reply to all requests with the error | |
206 for _, held_request in ipairs(session.requests) do | 211 for _, held_request in ipairs(session.requests) do |
207 held_request:send(session_close_response); | 212 held_request:send(session_close_response); |
208 held_request:destroy(); | 213 held_request:destroy(); |
209 end | 214 end |
210 sessions[session.sid] = nil; | 215 sessions[session.sid] = nil; |
253 end | 258 end |
254 --log("debug", "Sending BOSH data: %s", tostring(s)); | 259 --log("debug", "Sending BOSH data: %s", tostring(s)); |
255 local oldest_request = r[1]; | 260 local oldest_request = r[1]; |
256 if oldest_request then | 261 if oldest_request then |
257 log("debug", "We have an open request, so sending on that"); | 262 log("debug", "We have an open request, so sending on that"); |
258 response.body = t_concat{"<body xmlns='http://jabber.org/protocol/httpbind' sid='", sid, "' xmlns:stream = 'http://etherx.jabber.org/streams'>", tostring(s), "</body>" }; | 263 response.body = t_concat({ |
264 "<body xmlns='http://jabber.org/protocol/httpbind' ", | |
265 session.bosh_terminate and "type='terminate' " or "", | |
266 "sid='", sid, "' xmlns:stream = 'http://etherx.jabber.org/streams'>", | |
267 tostring(s), | |
268 "</body>" | |
269 }); | |
259 oldest_request:send(response); | 270 oldest_request:send(response); |
260 --log("debug", "Sent"); | 271 --log("debug", "Sent"); |
261 if oldest_request.stayopen then | 272 if oldest_request.stayopen then |
262 if #r>1 then | 273 if #r>1 then |
263 -- Move front request to back | 274 -- Move front request to back |
325 return; | 336 return; |
326 end | 337 end |
327 session.rid = rid; | 338 session.rid = rid; |
328 end | 339 end |
329 | 340 |
330 if attr.type == "terminate" then | |
331 -- Client wants to end this session | |
332 session:close(); | |
333 request.notopen = nil; | |
334 return; | |
335 end | |
336 | |
337 if session.notopen then | 341 if session.notopen then |
338 local features = st.stanza("stream:features"); | 342 local features = st.stanza("stream:features"); |
339 hosts[session.host].events.fire_event("stream-features", { origin = session, features = features }); | 343 hosts[session.host].events.fire_event("stream-features", { origin = session, features = features }); |
340 fire_event("stream-features", session, features); | 344 fire_event("stream-features", session, features); |
341 session.send(features); | 345 session.send(features); |
342 session.notopen = nil; | 346 session.notopen = nil; |
343 end | 347 end |
344 | 348 |
349 if attr.type == "terminate" then | |
350 -- Client wants to end this session, which we'll do | |
351 -- after processing any stanzas in this request | |
352 session.bosh_terminate = true; | |
353 end | |
354 | |
345 request.notopen = nil; -- Signals that we accept this opening tag | 355 request.notopen = nil; -- Signals that we accept this opening tag |
346 t_insert(session.requests, request); | 356 t_insert(session.requests, request); |
347 request.sid = sid; | 357 request.sid = sid; |
348 end | 358 end |
349 | 359 |