Mercurial > prosody-hg
comparison plugins/mod_bosh.lua @ 4313:42d7d09fdda0
Backout commit d6366294f618 which I was testing and didn't mean to push to 0.8
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 05 Jun 2011 12:28:49 +0100 |
| parents | d6366294f618 |
| children | 2478698bdc52 |
comparison
equal
deleted
inserted
replaced
| 4312:bcdff2b1d3ec | 4313:42d7d09fdda0 |
|---|---|
| 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 if session.bosh_terminate then | 165 return true; -- Inform httpserver we shall reply later |
| 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 | |
| 172 end | 166 end |
| 173 end | 167 end |
| 174 | 168 |
| 175 | 169 |
| 176 local function bosh_reset_stream(session) session.notopen = true; end | 170 local function bosh_reset_stream(session) session.notopen = true; end |
| 206 log("info", "Disconnecting client, <stream:error> is: %s", tostring(close_reply)); | 200 log("info", "Disconnecting client, <stream:error> is: %s", tostring(close_reply)); |
| 207 end | 201 end |
| 208 | 202 |
| 209 local session_close_response = { headers = default_headers, body = tostring(close_reply) }; | 203 local session_close_response = { headers = default_headers, body = tostring(close_reply) }; |
| 210 | 204 |
| 205 --FIXME: Quite sure we shouldn't reply to all requests with the error | |
| 211 for _, held_request in ipairs(session.requests) do | 206 for _, held_request in ipairs(session.requests) do |
| 212 held_request:send(session_close_response); | 207 held_request:send(session_close_response); |
| 213 held_request:destroy(); | 208 held_request:destroy(); |
| 214 end | 209 end |
| 215 sessions[session.sid] = nil; | 210 sessions[session.sid] = nil; |
| 258 end | 253 end |
| 259 --log("debug", "Sending BOSH data: %s", tostring(s)); | 254 --log("debug", "Sending BOSH data: %s", tostring(s)); |
| 260 local oldest_request = r[1]; | 255 local oldest_request = r[1]; |
| 261 if oldest_request then | 256 if oldest_request then |
| 262 log("debug", "We have an open request, so sending on that"); | 257 log("debug", "We have an open request, so sending on that"); |
| 263 response.body = t_concat({ | 258 response.body = t_concat{"<body xmlns='http://jabber.org/protocol/httpbind' sid='", sid, "' xmlns:stream = 'http://etherx.jabber.org/streams'>", tostring(s), "</body>" }; |
| 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 }); | |
| 270 oldest_request:send(response); | 259 oldest_request:send(response); |
| 271 --log("debug", "Sent"); | 260 --log("debug", "Sent"); |
| 272 if oldest_request.stayopen then | 261 if oldest_request.stayopen then |
| 273 if #r>1 then | 262 if #r>1 then |
| 274 -- Move front request to back | 263 -- Move front request to back |
| 336 return; | 325 return; |
| 337 end | 326 end |
| 338 session.rid = rid; | 327 session.rid = rid; |
| 339 end | 328 end |
| 340 | 329 |
| 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 | |
| 341 if session.notopen then | 337 if session.notopen then |
| 342 local features = st.stanza("stream:features"); | 338 local features = st.stanza("stream:features"); |
| 343 hosts[session.host].events.fire_event("stream-features", { origin = session, features = features }); | 339 hosts[session.host].events.fire_event("stream-features", { origin = session, features = features }); |
| 344 fire_event("stream-features", session, features); | 340 fire_event("stream-features", session, features); |
| 345 session.send(features); | 341 session.send(features); |
| 346 session.notopen = nil; | 342 session.notopen = nil; |
| 347 end | 343 end |
| 348 | 344 |
| 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 | |
| 355 request.notopen = nil; -- Signals that we accept this opening tag | 345 request.notopen = nil; -- Signals that we accept this opening tag |
| 356 t_insert(session.requests, request); | 346 t_insert(session.requests, request); |
| 357 request.sid = sid; | 347 request.sid = sid; |
| 358 end | 348 end |
| 359 | 349 |
