From 80de22c29bae5672eae6b8a96a4f0a92dca7a28c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 6 Mar 2010 18:45:09 +0000 Subject: net.xmppserver_listener: Clarify log message (for nil/false) --- net/xmppserver_listener.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'net') diff --git a/net/xmppserver_listener.lua b/net/xmppserver_listener.lua index c9746ee1..8a3886ad 100644 --- a/net/xmppserver_listener.lua +++ b/net/xmppserver_listener.lua @@ -176,7 +176,7 @@ function xmppserver.ondisconnect(conn, err) 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)); + (session.log or log)("info", "s2s disconnected: %s->%s (%s)", tostring(session.from_host), tostring(session.to_host), tostring(err or "closed")); s2s_destroy_session(session, err); sessions[conn] = nil; session = nil; -- cgit v1.2.3 From ada4f197bba33b040746ab40fc64b50fe4523087 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:01:00 +0000 Subject: net.xmppclient_listener: Fix to correctly handle stream errors from clients --- net/xmppclient_listener.lua | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'net') diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua index 3a0c65be..0d0e92ce 100644 --- a/net/xmppclient_listener.lua +++ b/net/xmppclient_listener.lua @@ -33,13 +33,32 @@ local opt_keepalives = config.get("*", "core", "tcp_keepalives"); local stream_callbacks = { default_ns = "jabber:client", streamopened = sm_streamopened, streamclosed = sm_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.log("debug", "Invalid opening stream header"); session:close("invalid-namespace"); - elseif session.close then - (session.log or log)("debug", "Client XML parse error: %s", tostring(error)); + elseif error == "parse-error" then + (session.log or log)("debug", "Client XML parse error: %s", tostring(data)); 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 -- cgit v1.2.3 From 4481ea54a304192f483ad704ba75ffd4398ec541 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:03:02 +0000 Subject: net.xmppcomponent_listener: Fix to correctly handle stream errors from components --- net/xmppcomponent_listener.lua | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'net') diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index 0b98b6bc..2483d48a 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -34,16 +34,32 @@ local xmlns_component = 'jabber:component:accept'; local stream_callbacks = { default_ns = xmlns_component }; +local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; + function stream_callbacks.error(session, error, data, data2) log("warn", "Error processing component stream: "..tostring(error)); if error == "no-stream" then session:close("invalid-namespace"); - elseif error == "xml-parse-error" and data == "unexpected-element-close" then - session.log("warn", "Unexpected close of '%s' tag", data2); - session:close("xml-not-well-formed"); - else - session.log("warn", "External component %s XML parse error: %s", tostring(session.host), tostring(error)); + elseif error == "parse-error" then + session.log("warn", "External component %s XML parse error: %s", tostring(session.host), tostring(data)); 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 -- cgit v1.2.3 From 6550edee36ee362d2373d8c98e0b40d4635e1f14 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:04:04 +0000 Subject: net.xmppcomponent_listener: Don't handle stream errors from component sessions that have already been destroyed --- net/xmppcomponent_listener.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'net') diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index 2483d48a..056eb0a2 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -37,6 +37,7 @@ local stream_callbacks = { default_ns = xmlns_component }; local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; function stream_callbacks.error(session, error, data, data2) + if session.destroyed then return; end log("warn", "Error processing component stream: "..tostring(error)); if error == "no-stream" then session:close("invalid-namespace"); -- cgit v1.2.3 From ef9204bca17420748f0757806d5942f8948a1450 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:04:51 +0000 Subject: net.xmppcomponent_listener: Close component sessions on receiving a --- net/xmppcomponent_listener.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'net') diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index 056eb0a2..9d7988cb 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -88,8 +88,8 @@ function stream_callbacks.streamopened(session, attr) end function stream_callbacks.streamclosed(session) - session.send(""); - session.notopen = true; + session.log("Received "); + session:close(); end local core_process_stanza = core_process_stanza; -- cgit v1.2.3 From c1cb6b9e9b87dfb2f068aa01ab1fb955852c5360 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:05:43 +0000 Subject: net.xmppcomponent_listener: Don't allow closing a session that has already been destroyed --- net/xmppcomponent_listener.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'net') diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index 9d7988cb..c9a0d70b 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -106,6 +106,7 @@ end local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; 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) + if session.destroyed then return; end local log = session.log or log; if session.conn then if session.notopen then -- cgit v1.2.3 From a81dc4028b418c0374bbdb56583b40472dbe8693 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:06:19 +0000 Subject: net.xmppcomponent_listener: Log invalid XML received from components (as we already do for c2s/s2s) --- net/xmppcomponent_listener.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'net') diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index c9a0d70b..7b8ab95a 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -164,6 +164,7 @@ function component_listener.onincoming(conn, data) function session.data(conn, data) local ok, err = parser:parse(data); if ok then return; end + log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")); session:close("xml-not-well-formed"); end -- cgit v1.2.3 From 30e384b6f629033b49c3d304f31079b508a9ef27 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:07:05 +0000 Subject: net.xmppcomponent_listener: Don't remove 'log' and 'close' from sessions when destroying, and set destroyed = true --- net/xmppcomponent_listener.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'net') diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index 7b8ab95a..568d947c 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -186,7 +186,12 @@ function component_listener.ondisconnect(conn, err) hosts[session.host].connected = nil; end sessions[conn] = nil; - for k in pairs(session) do session[k] = nil; end + for k in pairs(session) do + if k ~= "log" and k ~= "close" then + session[k] = nil; + end + end + session.destroyed = true; session = nil; end end -- cgit v1.2.3