Diff

net/xmppclient_listener.lua @ 2879:94299e640ed0

Merge with 0.7 (and indirectly 0.6.2)
author Matthew Wild <mwild1@gmail.com>
date Mon, 15 Mar 2010 03:18:33 +0000
parent 2753:305428b14f76
child 2925:692b3c6c5bd2
line wrap: on
line diff
--- a/net/xmppclient_listener.lua	Fri Mar 05 18:35:23 2010 +0000
+++ b/net/xmppclient_listener.lua	Mon Mar 15 03:18:33 2010 +0000
@@ -33,13 +33,32 @@
 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