diff options
author | Matthew Wild <mwild1@gmail.com> | 2009-01-09 19:18:46 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2009-01-09 19:18:46 +0000 |
commit | bd17ed3f7d3a20cd94ccadbe98bb057f8b8675fc (patch) | |
tree | 5eb34e280fee927105425ddcd75e86523c4d2a49 | |
parent | bc31c214d8c650e506676e620b52720f6df8eb1a (diff) | |
download | prosody-bd17ed3f7d3a20cd94ccadbe98bb057f8b8675fc.tar.gz prosody-bd17ed3f7d3a20cd94ccadbe98bb057f8b8675fc.zip |
Implement session:close() for BOSH, and add checking for attempts to connect to hosts we don't serve
-rw-r--r-- | plugins/mod_bosh.lua | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua index c0a2ada5..d41cc02e 100644 --- a/plugins/mod_bosh.lua +++ b/plugins/mod_bosh.lua @@ -84,9 +84,21 @@ function handle_request(method, body, request) end end -local session_close_reply = tostring(st.stanza("body", { xmlns = xmlns_bosh, type = "terminate" })); + local function bosh_reset_stream(session) session.notopen = true; end -local function bosh_close_stream(session, reason) end + +local session_close_reply = st.stanza("body", { xmlns = xmlns_bosh, type = "terminate" }); +local function bosh_close_stream(session, reason) + (session.log or log)("info", "BOSH client disconnected"); + session_close_reply.attr.condition = reason; + local session_close_reply = tostring(session_close_reply); + for _, held_request in ipairs(session.requests) do + held_request:send(session_close_reply); + held_request:destroy(); + end + sessions[session.sid] = nil; + sm_destroy_session(session); +end function stream_callbacks.streamopened(request, attr) print("Attr:") @@ -95,9 +107,17 @@ function stream_callbacks.streamopened(request, attr) local sid = attr.sid if not sid then -- New session request - -- TODO: Sanity checks here (rid, to, known host, etc.) request.notopen = nil; -- Signals that we accept this opening tag + -- TODO: Sanity checks here (rid, to, known host, etc.) + if not hosts[attr.to] then + -- Unknown host + session_close_reply.attr.condition = "host-unknown"; + request:send(tostring(session_close_reply)); + request.notopen = nil + return; + end + -- New session sid = tostring(new_uuid()); local session = { type = "c2s_unauthed", conn = {}, sid = sid, rid = attr.rid, host = attr.to, bosh_version = attr.ver, bosh_wait = attr.wait, streamid = sid, @@ -169,13 +189,7 @@ function stream_callbacks.streamopened(request, attr) if attr.type == "terminate" then -- Client wants to end this session - (session.log or log)("info", "BOSH client disconnected"); - for _, held_request in ipairs(session.requests) do - held_request:send(session_close_reply); - held_request:destroy(); - end - sm_destroy_session(session); - sessions[sid] = nil; + session:close(); request.notopen = nil; return; end |