diff options
author | Matthew Wild <mwild1@gmail.com> | 2011-03-04 20:27:57 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2011-03-04 20:27:57 +0000 |
commit | b7ab106c4877b8c756a1c742183e057a037a3b0e (patch) | |
tree | 9b9cc2e6f859505ebb2a03d2bdd216cdf80b80c8 | |
parent | 2c97611fedc6a28d47708dddcd3ee9a2e1ee69a4 (diff) | |
download | prosody-b7ab106c4877b8c756a1c742183e057a037a3b0e.tar.gz prosody-b7ab106c4877b8c756a1c742183e057a037a3b0e.zip |
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).
-rw-r--r-- | plugins/mod_bosh.lua | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua index 5ef6b18e..a6b84367 100644 --- a/plugins/mod_bosh.lua +++ b/plugins/mod_bosh.lua @@ -162,7 +162,13 @@ function handle_request(method, body, request) end end - return true; -- Inform httpserver we shall reply later + if session.bosh_terminate then + session.log("debug", "Closing session with %d requests open", #session.requests); + session:close(); + return nil; + else + return true; -- Inform httpserver we shall reply later + end end end @@ -202,7 +208,6 @@ local function bosh_close_stream(session, reason) local session_close_response = { headers = default_headers, body = tostring(close_reply) }; - --FIXME: Quite sure we shouldn't reply to all requests with the error for _, held_request in ipairs(session.requests) do held_request:send(session_close_response); held_request:destroy(); @@ -255,7 +260,13 @@ function stream_callbacks.streamopened(request, attr) local oldest_request = r[1]; if oldest_request then log("debug", "We have an open request, so sending on that"); - response.body = t_concat{"<body xmlns='http://jabber.org/protocol/httpbind' sid='", sid, "' xmlns:stream = 'http://etherx.jabber.org/streams'>", tostring(s), "</body>" }; + response.body = t_concat({ + "<body xmlns='http://jabber.org/protocol/httpbind' ", + session.bosh_terminate and "type='terminate' " or "", + "sid='", sid, "' xmlns:stream = 'http://etherx.jabber.org/streams'>", + tostring(s), + "</body>" + }); oldest_request:send(response); --log("debug", "Sent"); if oldest_request.stayopen then @@ -327,13 +338,6 @@ function stream_callbacks.streamopened(request, attr) session.rid = rid; end - if attr.type == "terminate" then - -- Client wants to end this session - session:close(); - request.notopen = nil; - return; - end - if session.notopen then local features = st.stanza("stream:features"); hosts[session.host].events.fire_event("stream-features", { origin = session, features = features }); @@ -342,6 +346,12 @@ function stream_callbacks.streamopened(request, attr) session.notopen = nil; end + if attr.type == "terminate" then + -- Client wants to end this session, which we'll do + -- after processing any stanzas in this request + session.bosh_terminate = true; + end + request.notopen = nil; -- Signals that we accept this opening tag t_insert(session.requests, request); request.sid = sid; |