From bf3bb39ea3ebf1faff066579a2647e31aa031ace Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 4 Dec 2008 16:41:32 +0000 Subject: Fix logger ids for c2s and s2sout --- core/s2smanager.lua | 2 +- net/xmppclient_listener.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 0afb8805..9c7a6008 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -108,7 +108,7 @@ function new_outgoing(from_host, to_host) local log; do - local conn_name = "s2sout"..tostring(conn):match("[a-f0-9]*$"); + local conn_name = "s2sout"..tostring(host_session):match("[a-f0-9]*$"); log = logger_init(conn_name); host_session.log = log; end diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua index 8ab3008c..a0d7ea57 100644 --- a/net/xmppclient_listener.lua +++ b/net/xmppclient_listener.lua @@ -101,7 +101,7 @@ function xmppclient.listener(conn, data) local mainlog, log = log; do - local conn_name = tostring(conn):match("[a-f0-9]+$"); + local conn_name = "c2s"..tostring(conn):match("[a-f0-9]+$"); log = logger.init(conn_name); end local print = function (...) log("info", t_concatall({...}, "\t")); end -- cgit v1.2.3 From 533449b6d26621a0e410e84003f1902e319bbfb6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 4 Dec 2008 17:10:02 +0000 Subject: Don't send stream:features to incoming s2s connections --- core/s2smanager.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 9c7a6008..df877767 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -180,7 +180,9 @@ end function streamopened(session, attr) local send = session.sends2s; - session.version = tonumber(attr.version) or 0; + -- TODO: #29: SASL/TLS on s2s streams + session.version = 0; --tonumber(attr.version) or 0; + if session.version >= 1.0 and not (attr.to and attr.from) then --print("to: "..tostring(attr.to).." from: "..tostring(attr.from)); log("warn", (session.to_host or "(unknown)").." failed to specify 'to' or 'from' hostname as per RFC"); -- cgit v1.2.3 From 327c81737eb11a340005c7078015c46fdfea6390 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 4 Dec 2008 18:47:26 +0000 Subject: Abstract xmlhandlers a bit more, also add error callbacks --- core/xmlhandlers.lua | 20 +++++++++++--------- net/xmppclient_listener.lua | 7 ++++--- net/xmppserver_listener.lua | 6 +++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index ec3051b4..2872a036 100644 --- a/core/xmlhandlers.lua +++ b/core/xmlhandlers.lua @@ -52,12 +52,13 @@ function init_xmlhandlers(session, stream_callbacks) local chardata = {}; local xml_handlers = {}; local log = session.log or default_log; - --local print = function (...) log("info", "xmlhandlers", t_concatall({...}, "\t")); end - + local send = session.send; local cb_streamopened = stream_callbacks.streamopened; local cb_streamclosed = stream_callbacks.streamclosed; + local cb_error = stream_callbacks.error or function (e) error("XML stream error: "..tostring(e)); end; + local cb_handlestanza = stream_callbacks.handlestanza; local stanza function xml_handlers:StartElement(name, attr) @@ -92,12 +93,14 @@ function init_xmlhandlers(session, stream_callbacks) if cb_streamopened then cb_streamopened(session, attr); end - return; + else + -- Garbage before stream? + cb_error("no-stream"); end - error("Client failed to open stream successfully"); + return; end if curr_ns == "jabber:client" and name ~= "iq" and name ~= "presence" and name ~= "message" then - error("Client sent invalid top-level stanza"); + cb_error("invalid-top-level-element"); end stanza = st.stanza(name, attr); @@ -119,15 +122,14 @@ function init_xmlhandlers(session, stream_callbacks) curr_ns,name = name:match("^(.+)|([%w%-]+)$"); if (not stanza) or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then if name == "stream" then - log("debug", "Stream closed"); if cb_streamclosed then cb_streamclosed(session); end return; elseif name == "error" then - error("Stream error: "..tostring(name)..": "..tostring(stanza)); + cb_error("stream-error", stanza); else - error("XML parse error in client stream with element: "..name); + cb_error("parse-error", "unexpected-element-close", name); end end if stanza and #chardata > 0 then @@ -137,7 +139,7 @@ function init_xmlhandlers(session, stream_callbacks) end -- Complete stanza if #stanza.last_add == 0 then - session.stanza_dispatch(stanza); + cb_handlestanza(session, stanza); stanza = nil; else stanza:up(); diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua index a0d7ea57..470c23d2 100644 --- a/net/xmppclient_listener.lua +++ b/net/xmppclient_listener.lua @@ -36,7 +36,7 @@ local sm_streamopened = sessionmanager.streamopened; local sm_streamclosed = sessionmanager.streamclosed; local st = stanza; -local stream_callbacks = { streamopened = sm_streamopened, streamclosed = sm_streamclosed }; +local stream_callbacks = { streamopened = sm_streamopened, streamclosed = sm_streamclosed, handlestanza = core_process_stanza }; local sessions = {}; local xmppclient = { default_port = 5222, default_mode = "*a" }; @@ -119,8 +119,9 @@ function xmppclient.listener(conn, data) -- (I'm on a mission, no time to fix now) -- 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 + --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 + end if data then session.data(conn, data); diff --git a/net/xmppserver_listener.lua b/net/xmppserver_listener.lua index 20641998..4b41afbd 100644 --- a/net/xmppserver_listener.lua +++ b/net/xmppserver_listener.lua @@ -28,7 +28,7 @@ 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 = { streamopened = s2s_streamopened, streamclosed = s2s_streamclosed }; +local stream_callbacks = { streamopened = s2s_streamopened, streamclosed = s2s_streamclosed, handlestanza = core_process_stanza }; local connlisteners_register = require "net.connlisteners".register; @@ -121,8 +121,8 @@ function xmppserver.listener(conn, data) -- (I'm on a mission, no time to fix now) -- 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 +-- 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 end if data then session.data(conn, data); -- cgit v1.2.3