diff options
author | Matthew Wild <mwild1@gmail.com> | 2008-11-18 05:13:29 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2008-11-18 05:13:29 +0000 |
commit | f21f55bb1e757f27cf9d2263469eb9ae6c63b91e (patch) | |
tree | 3ca7a7a8922903eed1b9522d7c2759043333ebcc | |
parent | 3ac3b3bc2dc01fea974472dbab1ba232b9ad776c (diff) | |
download | prosody-f21f55bb1e757f27cf9d2263469eb9ae6c63b91e.tar.gz prosody-f21f55bb1e757f27cf9d2263469eb9ae6c63b91e.zip |
Allow us to close client connections, with or without a stream error. Partially fixes #8, we still need the same for s2s (though it should be almost a straight copy of the code, I'm too tired atm)
-rw-r--r-- | core/sessionmanager.lua | 14 | ||||
-rw-r--r-- | net/xmppclient_listener.lua | 34 |
2 files changed, 46 insertions, 2 deletions
diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 0d65f6d6..33157567 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -96,13 +96,23 @@ function streamopened(session, attr) session.host = attr.to or error("Client failed to specify destination hostname"); session.version = tonumber(attr.version) or 0; session.streamid = m_random(1000000, 99999999); - print(session, session.host, "Client opened stream"); - send("<?xml version='1.0'?>"); + (session.log or session)("debug", "Client sent opening <stream:stream> to %s", session.host); + + + send("<?xml version='1.0'?>"); send(format("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='%s' from='%s' version='1.0'>", session.streamid, session.host)); + if not hosts[session.host] then + -- We don't serve this host... + session:disconnect{ condition = "host-unknown", text = "This server does not serve "..tostring(session.host)}; + return; + end + + local features = {}; modulemanager.fire_event("stream-features", session, features); + -- FIXME: Need to send() this all at once send("<stream:features>"); for _, feature in ipairs(features) do diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua index b5028db0..1f6691da 100644 --- a/net/xmppclient_listener.lua +++ b/net/xmppclient_listener.lua @@ -33,6 +33,39 @@ local function session_reset_stream(session) 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 client, <stream:error> is: %s", 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 client, <stream:error> is: %s", tostring(stanza)); + session.send(stanza); + elseif reason.name then -- a stanza + log("info", "Disconnecting client, <stream:error> is: %s", tostring(reason)); + session.send(reason); + end + end + end + session.send("</stream:stream>"); + session.conn.close(); + xmppclient.disconnect(session.conn, "stream error"); + end +end + + -- End of session methods -- function xmppclient.listener(conn, data) @@ -54,6 +87,7 @@ function xmppclient.listener(conn, data) print("Client connected"); session.reset_stream = session_reset_stream; + session.disconnect = session_disconnect; session_reset_stream(session); -- Initialise, ready for use |