# HG changeset patch # User Matthew Wild # Date 1227019365 0 # Node ID d9d4c1de16ceee63d14aacd22a99a4cb101c2842 # Parent 3be63719428e103445aa827e8c6606d82306adf2 s2s sessions can now be disconnected, with or without a stream error. Fixes #8 diff -r 3be63719428e -r d9d4c1de16ce net/xmppclient_listener.lua --- a/net/xmppclient_listener.lua Tue Nov 18 05:13:29 2008 +0000 +++ b/net/xmppclient_listener.lua Tue Nov 18 14:42:45 2008 +0000 @@ -98,9 +98,6 @@ -- Debug version -- local function handleerr(err) print("Traceback:", err, debug.traceback()); end session.stanza_dispatch = function (stanza) return select(2, xpcall(function () return core_process_stanza(session, stanza); end, handleerr)); end - --- session.stanza_dispatch = function (stanza) return core_process_stanza(session, stanza); end - end if data then session.data(conn, data); diff -r 3be63719428e -r d9d4c1de16ce net/xmppserver_listener.lua --- a/net/xmppserver_listener.lua Tue Nov 18 05:13:29 2008 +0000 +++ b/net/xmppserver_listener.lua Tue Nov 18 14:42:45 2008 +0000 @@ -35,6 +35,39 @@ return true; end + +local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; +local function session_disconnect(session, reason) + local log = session.log or log; + if session.conn then + if reason then + if type(reason) == "string" then -- assume stream error + log("info", "Disconnecting %s[%s], is: %s", session.host or "(unknown host)", session.type, reason); + session.send(st.stanza("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(); + if reason.text then + stanza:tag("text", stream_xmlns_attr):text(reason.text):up(); + end + if reason.extra then + stanza:add_child(reason.extra); + end + log("info", "Disconnecting %s[%s], is: %s", session.host or "(unknown host)", session.type, tostring(stanza)); + session.send(stanza); + elseif reason.name then -- a stanza + log("info", "Disconnecting %s[%s], is: %s", session.host or "(unknown host)", session.type, tostring(reason)); + session.send(reason); + end + end + end + session.send(""); + session.conn.close(); + xmppserver.disconnect(session.conn, "stream error"); + end +end + + -- End of session methods -- function xmppserver.listener(conn, data) @@ -56,6 +89,7 @@ print("Incoming s2s connection"); session.reset_stream = session_reset_stream; + session.disconnect = session_disconnect; session_reset_stream(session); -- Initialise, ready for use