Diff

net/xmppclient_listener.lua @ 557:c9b3ffb08fe3

Disconnect with stream errors on bad XML, or invalid stream namespace
author Matthew Wild <mwild1@gmail.com>
date Fri, 05 Dec 2008 02:02:57 +0000
parent 545:60002993be04
child 559:fa4a51fe6442
line wrap: on
line diff
--- a/net/xmppclient_listener.lua	Fri Dec 05 02:02:40 2008 +0000
+++ b/net/xmppclient_listener.lua	Fri Dec 05 02:02:57 2008 +0000
@@ -36,7 +36,16 @@
 local sm_streamclosed = sessionmanager.streamclosed;
 local st = stanza;
 
-local stream_callbacks = { streamopened = sm_streamopened, streamclosed = sm_streamclosed, handlestanza = core_process_stanza };
+local stream_callbacks = { ns = "http://etherx.jabber.org/streams", streamopened = sm_streamopened, streamclosed = sm_streamclosed, handlestanza = core_process_stanza };
+
+function stream_callbacks.error(session, error, data)
+	if error == "no-stream" then
+		session:close("invalid-namespace");
+	else
+		session.log("debug", "Client XML parse error: %s", tostring(error));
+		session:close("xml-not-well-formed");
+	end
+end
 
 local sessions = {};
 local xmppclient = { default_port = 5222, default_mode = "*a" };
@@ -51,8 +60,11 @@
 		session.notopen = true;
 		
 		function session.data(conn, data)
-			parser:parse(data);
+			local ok, err = parser:parse(data);
+			if ok then return; end
+			session:close("xml-not-well-formed");
 		end
+		
 		return true;
 end