X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=net%2Fxmppserver_listener.lua;h=c9746ee1281fe91c4921c7c88646b5576738a14c;hb=3704ffb23b6ffd8d248f9c7ad26d7f19a0cc6824;hp=797ef183fe78ce47664b3c60e0ec1825aae56fd0;hpb=4e9ad86f42f78e32d5a983b62277a0552c853a9c;p=prosody.git diff --git a/net/xmppserver_listener.lua b/net/xmppserver_listener.lua index 797ef183..c9746ee1 100644 --- a/net/xmppserver_listener.lua +++ b/net/xmppserver_listener.lua @@ -17,16 +17,34 @@ local s2s_streamopened = require "core.s2smanager".streamopened; local s2s_streamclosed = require "core.s2smanager".streamclosed; local s2s_destroy_session = require "core.s2smanager".destroy_session; local s2s_attempt_connect = require "core.s2smanager".attempt_connection; -local stream_callbacks = { stream_tag = "http://etherx.jabber.org/streams\1stream", - default_ns = "jabber:server", +local stream_callbacks = { default_ns = "jabber:server", streamopened = s2s_streamopened, streamclosed = s2s_streamclosed, handlestanza = core_process_stanza }; +local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; + function stream_callbacks.error(session, error, data) if error == "no-stream" then session:close("invalid-namespace"); - else + elseif error == "parse-error" then session.log("debug", "Server-to-server XML parse error: %s", tostring(error)); session:close("xml-not-well-formed"); + elseif error == "stream-error" then + local condition, text = "undefined-condition"; + for child in data:children() do + if child.attr.xmlns == xmlns_xmpp_streams then + if child.name ~= "text" then + condition = child.name; + else + text = child:get_text(); + end + if condition ~= "undefined-condition" and text then + break; + end + end + end + text = condition .. (text and (" ("..text..")") or ""); + session.log("info", "Session closed by remote with error: %s", text); + session:close(nil, text); end end @@ -70,8 +88,8 @@ local function session_reset_stream(session) end local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; -local default_stream_attr = { ["xmlns:stream"] = stream_callbacks.stream_tag:match("[^\1]*"), xmlns = stream_callbacks.default_ns, version = "1.0", id = "" }; -local function session_close(session, reason) +local default_stream_attr = { ["xmlns:stream"] = "http://etherx.jabber.org/streams", xmlns = stream_callbacks.default_ns, version = "1.0", id = "" }; +local function session_close(session, reason, remote_reason) local log = session.log or log; if session.conn then if session.notopen then @@ -100,11 +118,11 @@ local function session_close(session, reason) end end session.sends2s(""); - if session.notopen or not session.conn.close() then - session.conn.close(true); -- Force FIXME: timer? + if session.notopen or not session.conn:close() then + session.conn:close(true); -- Force FIXME: timer? end - session.conn.close(); - xmppserver.ondisconnect(session.conn, "stream error"); + session.conn:close(); + xmppserver.ondisconnect(session.conn, remote_reason or (reason and (reason.text or reason.condition)) or reason or "stream closed"); end end @@ -137,7 +155,7 @@ function xmppserver.onincoming(conn, data) end end -function xmppserver.status(conn, status) +function xmppserver.onstatus(conn, status) if status == "ssl-handshake-complete" then local session = sessions[conn]; if session and session.direction == "outgoing" then @@ -152,17 +170,16 @@ function xmppserver.ondisconnect(conn, err) local session = sessions[conn]; if session then if err and err ~= "closed" and session.srv_hosts then - (session.log or log)("debug", "s2s connection closed unexpectedly"); + (session.log or log)("debug", "s2s connection attempt failed: %s", err); if s2s_attempt_connect(session, err) then - (session.log or log)("debug", "...so we're going to try again"); + (session.log or log)("debug", "...so we're going to try another target"); return; -- Session lives for now end end (session.log or log)("info", "s2s disconnected: %s->%s (%s)", tostring(session.from_host), tostring(session.to_host), tostring(err)); - s2s_destroy_session(session); + s2s_destroy_session(session, err); sessions[conn] = nil; session = nil; - collectgarbage("collect"); end end