Comparison

plugins/mod_bosh.lua @ 684:b7d85c6a0002

Implement session:close() for BOSH, and add checking for attempts to connect to hosts we don't serve
author Matthew Wild <mwild1@gmail.com>
date Fri, 09 Jan 2009 19:18:46 +0000
parent 683:7428244a82a6
child 692:4a218377f4e3
comparison
equal deleted inserted replaced
683:7428244a82a6 684:b7d85c6a0002
82 log("debug", "Had nothing to say, so leaving request unanswered for now"); 82 log("debug", "Had nothing to say, so leaving request unanswered for now");
83 return true; 83 return true;
84 end 84 end
85 end 85 end
86 86
87 local session_close_reply = tostring(st.stanza("body", { xmlns = xmlns_bosh, type = "terminate" })); 87
88 local function bosh_reset_stream(session) session.notopen = true; end 88 local function bosh_reset_stream(session) session.notopen = true; end
89 local function bosh_close_stream(session, reason) end 89
90 local session_close_reply = st.stanza("body", { xmlns = xmlns_bosh, type = "terminate" });
91 local function bosh_close_stream(session, reason)
92 (session.log or log)("info", "BOSH client disconnected");
93 session_close_reply.attr.condition = reason;
94 local session_close_reply = tostring(session_close_reply);
95 for _, held_request in ipairs(session.requests) do
96 held_request:send(session_close_reply);
97 held_request:destroy();
98 end
99 sessions[session.sid] = nil;
100 sm_destroy_session(session);
101 end
90 102
91 function stream_callbacks.streamopened(request, attr) 103 function stream_callbacks.streamopened(request, attr)
92 print("Attr:") 104 print("Attr:")
93 for k,v in pairs(attr) do print("", k, v); end 105 for k,v in pairs(attr) do print("", k, v); end
94 log("debug", "BOSH body open (sid: %s)", attr.sid); 106 log("debug", "BOSH body open (sid: %s)", attr.sid);
95 local sid = attr.sid 107 local sid = attr.sid
96 if not sid then 108 if not sid then
97 -- New session request 109 -- New session request
110 request.notopen = nil; -- Signals that we accept this opening tag
111
98 -- TODO: Sanity checks here (rid, to, known host, etc.) 112 -- TODO: Sanity checks here (rid, to, known host, etc.)
99 request.notopen = nil; -- Signals that we accept this opening tag 113 if not hosts[attr.to] then
114 -- Unknown host
115 session_close_reply.attr.condition = "host-unknown";
116 request:send(tostring(session_close_reply));
117 request.notopen = nil
118 return;
119 end
100 120
101 -- New session 121 -- New session
102 sid = tostring(new_uuid()); 122 sid = tostring(new_uuid());
103 local session = { type = "c2s_unauthed", conn = {}, sid = sid, rid = attr.rid, host = attr.to, bosh_version = attr.ver, bosh_wait = attr.wait, streamid = sid, 123 local session = { type = "c2s_unauthed", conn = {}, sid = sid, rid = attr.rid, host = attr.to, bosh_version = attr.ver, bosh_wait = attr.wait, streamid = sid,
104 bosh_hold = BOSH_DEFAULT_HOLD, bosh_max_inactive = BOSH_DEFAULT_INACTIVITY, 124 bosh_hold = BOSH_DEFAULT_HOLD, bosh_max_inactive = BOSH_DEFAULT_INACTIVITY,
167 return; 187 return;
168 end 188 end
169 189
170 if attr.type == "terminate" then 190 if attr.type == "terminate" then
171 -- Client wants to end this session 191 -- Client wants to end this session
172 (session.log or log)("info", "BOSH client disconnected"); 192 session:close();
173 for _, held_request in ipairs(session.requests) do
174 held_request:send(session_close_reply);
175 held_request:destroy();
176 end
177 sm_destroy_session(session);
178 sessions[sid] = nil;
179 request.notopen = nil; 193 request.notopen = nil;
180 return; 194 return;
181 end 195 end
182 196
183 -- If session was inactive, make sure it is now marked as not 197 -- If session was inactive, make sure it is now marked as not