Software /
code /
prosody
Comparison
plugins/mod_s2s/mod_s2s.lua @ 10477:28755107c2f4
mod_s2s: Refactor stream error handling on close
Deduplicates the 3 log calls that log the same thing but subtly
differently. The first one would say "Disconnecting localhost" and the
last one didn't log the IP.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 01 Dec 2019 12:21:26 +0100 |
parent | 10476:035027a868bc |
child | 10482:c7864f970969 |
comparison
equal
deleted
inserted
replaced
10476:035027a868bc | 10477:28755107c2f4 |
---|---|
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 if type(reason) == "string" then -- assume stream error | 509 if type(reason) == "string" then -- assume stream error |
510 log("debug", "Disconnecting %s[%s], <stream:error> is: %s", session.host or session.ip or "(unknown host)", session.type, reason); | 510 reason = st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }); |
511 session.sends2s(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" then | 512 local stanza = st.stanza("stream:error"):tag(reason.condition or "undefined-condition", stream_xmlns_attr):up(); |
513 if reason.condition then | 513 if reason.text then |
514 local stanza = st.stanza("stream:error"):tag(reason.condition, stream_xmlns_attr):up(); | 514 stanza:tag("text", stream_xmlns_attr):text(reason.text):up(); |
515 if reason.text then | |
516 stanza:tag("text", stream_xmlns_attr):text(reason.text):up(); | |
517 end | |
518 if reason.extra then | |
519 stanza:add_child(reason.extra); | |
520 end | |
521 log("debug", "Disconnecting %s[%s], <stream:error> is: %s", | |
522 session.host or session.ip or "(unknown host)", session.type, stanza); | |
523 session.sends2s(stanza); | |
524 elseif st.is_stanza(reason) then | |
525 log("debug", "Disconnecting %s->%s[%s], <stream:error> is: %s", | |
526 session.from_host or "(unknown host)", session.to_host or "(unknown host)", | |
527 session.type, reason); | |
528 session.sends2s(reason); | |
529 end | 515 end |
516 if reason.extra then | |
517 stanza:add_child(reason.extra); | |
518 end | |
519 end | |
520 if st.is_stanza(reason) then | |
521 -- to and from are never unknown on outgoing connections | |
522 log("debug", "Disconnecting %s->%s[%s], <stream:error> is: %s", | |
523 session.from_host or "(unknown host)" or session.ip, session.to_host or "(unknown host)", session.type, reason); | |
524 session.sends2s(reason); | |
530 end | 525 end |
531 end | 526 end |
532 | 527 |
533 session.sends2s("</stream:stream>"); | 528 session.sends2s("</stream:stream>"); |
534 function session.sends2s() return false; end | 529 function session.sends2s() return false; end |