504 else |
504 else |
505 session:open_stream(session.from_host, session.to_host); |
505 session:open_stream(session.from_host, session.to_host); |
506 end |
506 end |
507 end |
507 end |
508 if reason then -- nil == no err, initiated by us, false == initiated by remote |
508 if reason then -- nil == no err, initiated by us, false == initiated by remote |
|
509 local stream_error; |
509 if type(reason) == "string" then -- assume stream error |
510 if type(reason) == "string" then -- assume stream error |
510 reason = st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }); |
511 stream_error = st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }); |
511 elseif type(reason) == "table" and not st.is_stanza(reason) then |
512 elseif type(reason) == "table" and not st.is_stanza(reason) then |
512 local stanza = st.stanza("stream:error"):tag(reason.condition or "undefined-condition", stream_xmlns_attr):up(); |
513 stream_error = st.stanza("stream:error"):tag(reason.condition or "undefined-condition", stream_xmlns_attr):up(); |
513 if reason.text then |
514 if reason.text then |
514 stanza:tag("text", stream_xmlns_attr):text(reason.text):up(); |
515 stream_error:tag("text", stream_xmlns_attr):text(reason.text):up(); |
515 end |
516 end |
516 if reason.extra then |
517 if reason.extra then |
517 stanza:add_child(reason.extra); |
518 stream_error:add_child(reason.extra); |
518 end |
519 end |
519 reason = stanza; |
520 end |
520 end |
521 if st.is_stanza(stream_error) then |
521 if st.is_stanza(reason) then |
|
522 -- to and from are never unknown on outgoing connections |
522 -- to and from are never unknown on outgoing connections |
523 log("debug", "Disconnecting %s->%s[%s], <stream:error> is: %s", |
523 log("debug", "Disconnecting %s->%s[%s], <stream:error> is: %s", |
524 session.from_host or "(unknown host)" or session.ip, session.to_host or "(unknown host)", session.type, reason); |
524 session.from_host or "(unknown host)" or session.ip, session.to_host or "(unknown host)", session.type, reason); |
525 session.sends2s(reason); |
525 session.sends2s(stream_error); |
526 end |
526 end |
527 end |
527 end |
528 |
528 |
529 session.sends2s("</stream:stream>"); |
529 session.sends2s("</stream:stream>"); |
530 function session.sends2s() return false; end |
530 function session.sends2s() return false; end |