Software /
code /
prosody
Comparison
plugins/mod_s2s/mod_s2s.lua @ 4988:29bdf68ad142
mod_s2s: Adjust session:close() in line with mod_c2s's - fixes waiting for </stream:stream> if it has already been sent by the peer
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 23 Jul 2012 13:31:26 +0100 |
parent | 4969:15183193c6a6 |
child | 4993:5243b74a4cbb |
comparison
equal
deleted
inserted
replaced
4987:d37f2abac72c | 4988:29bdf68ad142 |
---|---|
288 session.notopen = nil; | 288 session.notopen = nil; |
289 end | 289 end |
290 | 290 |
291 function stream_callbacks.streamclosed(session) | 291 function stream_callbacks.streamclosed(session) |
292 (session.log or log)("debug", "Received </stream:stream>"); | 292 (session.log or log)("debug", "Received </stream:stream>"); |
293 session:close(); | 293 session:close(false); |
294 end | 294 end |
295 | 295 |
296 function stream_callbacks.error(session, error, data) | 296 function stream_callbacks.error(session, error, data) |
297 if error == "no-stream" then | 297 if error == "no-stream" then |
298 session:close("invalid-namespace"); | 298 session:close("invalid-namespace"); |
340 if session.conn then | 340 if session.conn then |
341 if session.notopen then | 341 if session.notopen then |
342 session.sends2s("<?xml version='1.0'?>"); | 342 session.sends2s("<?xml version='1.0'?>"); |
343 session.sends2s(st.stanza("stream:stream", default_stream_attr):top_tag()); | 343 session.sends2s(st.stanza("stream:stream", default_stream_attr):top_tag()); |
344 end | 344 end |
345 if reason then | 345 if reason then -- nil == no err, initiated by us, false == initiated by remote |
346 if type(reason) == "string" then -- assume stream error | 346 if type(reason) == "string" then -- assume stream error |
347 log("info", "Disconnecting %s[%s], <stream:error> is: %s", session.host or "(unknown host)", session.type, reason); | 347 log("info", "Disconnecting %s[%s], <stream:error> is: %s", session.host or "(unknown host)", session.type, reason); |
348 session.sends2s(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' })); | 348 session.sends2s(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' })); |
349 elseif type(reason) == "table" then | 349 elseif type(reason) == "table" then |
350 if reason.condition then | 350 if reason.condition then |
361 log("info", "Disconnecting %s->%s[%s], <stream:error> is: %s", session.from_host or "(unknown host)", session.to_host or "(unknown host)", session.type, tostring(reason)); | 361 log("info", "Disconnecting %s->%s[%s], <stream:error> is: %s", session.from_host or "(unknown host)", session.to_host or "(unknown host)", session.type, tostring(reason)); |
362 session.sends2s(reason); | 362 session.sends2s(reason); |
363 end | 363 end |
364 end | 364 end |
365 end | 365 end |
366 | |
366 session.sends2s("</stream:stream>"); | 367 session.sends2s("</stream:stream>"); |
367 | |
368 function session.sends2s() return false; end | 368 function session.sends2s() return false; end |
369 | 369 |
370 local reason = remote_reason or (reason and (reason.text or reason.condition)) or reason or "stream closed"; | 370 local reason = remote_reason or (reason and (reason.text or reason.condition)) or reason; |
371 session.log("info", "%s s2s stream %s->%s closed: %s", session.direction, session.from_host or "(unknown host)", session.to_host or "(unknown host)", reason); | 371 session.log("info", "%s s2s stream %s->%s closed: %s", session.direction, session.from_host or "(unknown host)", session.to_host or "(unknown host)", reason or "stream closed"); |
372 | 372 |
373 -- Authenticated incoming stream may still be sending us stanzas, so wait for </stream:stream> from remote | 373 -- Authenticated incoming stream may still be sending us stanzas, so wait for </stream:stream> from remote |
374 local conn = session.conn; | 374 local conn = session.conn; |
375 if not session.notopen and session.type == "s2sin" then | 375 if reason == nil and not session.notopen and session.type == "s2sin" then |
376 add_task(stream_close_timeout, function () | 376 add_task(stream_close_timeout, function () |
377 if not session.destroyed then | 377 if not session.destroyed then |
378 session.log("warn", "Failed to receive a stream close response, closing connection anyway..."); | 378 session.log("warn", "Failed to receive a stream close response, closing connection anyway..."); |
379 s2s_destroy_session(session, reason); | 379 s2s_destroy_session(session, reason); |
380 conn:close(); | 380 conn:close(); |