Software /
code /
prosody
Changeset
4438:7f51186ed28b
mod_bosh: Move stream:features sending until after the current request has been added to session.requests. Ensures correct inactivity logic.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 07 Dec 2011 04:57:51 +0000 |
parents | 4437:916681a9a7be |
children | 4439:1c8d2c0d02db |
files | plugins/mod_bosh.lua |
diffstat | 1 files changed, 16 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_bosh.lua Wed Dec 07 03:54:28 2011 +0000 +++ b/plugins/mod_bosh.lua Wed Dec 07 04:57:51 2011 +0000 @@ -120,10 +120,17 @@ request.on_destroy = on_destroy_request; local stream = new_xmpp_stream(request, stream_callbacks); + -- stream:feed() calls the stream_callbacks, so all stanzas in -- the body are processed in this next line before it returns. + -- In particular, the streamopened() stream callback is where + -- much of the session logic happens, because it's where we first + -- get to see the 'sid' of this request. stream:feed(body); + -- Stanzas (if any) in the request have now been processed, and + -- we take care of the high-level BOSH logic here, including + -- giving a response or putting the request "on hold". local session = sessions[request.sid]; if session then -- Session was marked as inactive, since we have @@ -218,6 +225,7 @@ sm_destroy_session(session); end +-- Handle the <body> tag in the request payload. function stream_callbacks.streamopened(request, attr) local sid = attr.sid; log("debug", "BOSH body open (sid: %s)", sid or "<none>"); @@ -340,14 +348,6 @@ session.rid = rid; end - if session.notopen then - local features = st.stanza("stream:features"); - hosts[session.host].events.fire_event("stream-features", { origin = session, features = features }); - fire_event("stream-features", session, features); - session.send(features); - 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 @@ -357,6 +357,14 @@ request.notopen = nil; -- Signals that we accept this opening tag t_insert(session.requests, request); request.sid = sid; + + if session.notopen then + local features = st.stanza("stream:features"); + hosts[session.host].events.fire_event("stream-features", { origin = session, features = features }); + fire_event("stream-features", session, features); + session.send(features); + session.notopen = nil; + end end function stream_callbacks.handlestanza(request, stanza)