Changeset

3147:bc8c31399520

xmppserver_listener: Add filters for incoming bytes and stanzas
author Matthew Wild <mwild1@gmail.com>
date Wed, 02 Jun 2010 18:23:39 +0100
parents 3146:aaaea4cdbf10
children 3148:a83a995fe5db
files net/xmppserver_listener.lua
diffstat 1 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/net/xmppserver_listener.lua	Wed Jun 02 18:23:15 2010 +0100
+++ b/net/xmppserver_listener.lua	Wed Jun 02 18:23:39 2010 +0100
@@ -125,16 +125,26 @@
 		session.stream:reset();
 	end
 	
+	local filter = session.filter;
 	function session.data(data)
-		local ok, err = stream:feed(data);
-		if ok then return; end
-		(session.log or log)("warn", "Received invalid XML: %s", data);
-		(session.log or log)("warn", "Problem was: %s", err);
-		session:close("xml-not-well-formed");
+		data = filter("bytes/in", data);
+		if data then
+			local ok, err = stream:feed(data);
+			if ok then return; end
+			(session.log or log)("warn", "Received invalid XML: %s", data);
+			(session.log or log)("warn", "Problem was: %s", err);
+			session:close("xml-not-well-formed");
+		end
 	end
 
 	session.close = session_close;
-	session.dispatch_stanza = stream_callbacks.handlestanza;
+	local handlestanza = stream_callbacks.handlestanza;
+	function session.dispatch_stanza(session, stanza)
+		stanza = filters("stanzas/in", stanza);
+		if stanza then
+			return handlestanza(session, stanza);
+		end
+	end
 end
 
 function xmppserver.onconnect(conn)