# HG changeset patch # User Kim Alvefur # Date 1366905022 -7200 # Node ID 0220093e34fad59b61d810a678af68d64d5e06b7 # Parent 9d7349bbe4d2b992ac665da27238f66283b191eb mod_c2s: Refactor building to allways tostring() it and only call send once diff -r 9d7349bbe4d2 -r 0220093e34fa plugins/mod_c2s.lua --- a/plugins/mod_c2s.lua Tue Apr 23 15:55:49 2013 -0400 +++ b/plugins/mod_c2s.lua Thu Apr 25 17:50:22 2013 +0200 @@ -133,25 +133,25 @@ session.send(st.stanza("stream:stream", default_stream_attr):top_tag()); end if reason then -- nil == no err, initiated by us, false == initiated by client + local stream_error = st.stanza("stream:error"); if type(reason) == "string" then -- assume stream error - log("debug", "Disconnecting client, is: %s", reason); - session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' })); + stream_error:tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }); elseif type(reason) == "table" then if reason.condition then - local stanza = st.stanza("stream:error"):tag(reason.condition, stream_xmlns_attr):up(); + stream_error:tag(reason.condition, stream_xmlns_attr):up(); if reason.text then - stanza:tag("text", stream_xmlns_attr):text(reason.text):up(); + stream_error:tag("text", stream_xmlns_attr):text(reason.text):up(); end if reason.extra then - stanza:add_child(reason.extra); + stream_error:add_child(reason.extra); end - log("debug", "Disconnecting client, is: %s", tostring(stanza)); - session.send(stanza); elseif reason.name then -- a stanza - log("debug", "Disconnecting client, is: %s", tostring(reason)); - session.send(reason); + stream_error = reason; end end + stream_error = tostring(stream_error); + log("debug", "Disconnecting client, is: %s", stream_error); + session.send(stream_error); end session.send("");