Changeset

3551:4fba723ab235

mod_saslauth: Moved SASL mechanism selection and CDATA handling into separate functions.
author Waqas Hussain <waqas20@gmail.com>
date Tue, 02 Nov 2010 21:19:50 +0500
parents 3550:5e5d136d9de0
children 3552:8ad09efc19cc
files plugins/mod_saslauth.lua
diffstat 1 files changed, 20 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_saslauth.lua	Tue Nov 02 18:58:11 2010 +0500
+++ b/plugins/mod_saslauth.lua	Tue Nov 02 21:19:50 2010 +0500
@@ -72,6 +72,25 @@
 	return status, ret, err_msg;
 end
 
+local function sasl_process_cdata(session, stanza)
+	local text = stanza[1];
+	if text then
+		text = base64.decode(text);
+		--log("debug", "AUTH: %s", text:gsub("[%z\001-\008\011\012\014-\031]", " "));
+		if not text then
+			session.sasl_handler = nil;
+			session.send(build_reply("failure", "incorrect-encoding"));
+			return true;
+		end
+	end
+	local status, ret, err_msg = session.sasl_handler:process(text);
+	status, ret, err_msg = handle_status(session, status, ret, err_msg);
+	local s = build_reply(status, ret, err_msg);
+	log("debug", "sasl reply: %s", tostring(s));
+	session.send(s);
+	return true;
+end
+
 local function sasl_handler(event)
 	local session, stanza = event.origin, event.stanza;
 	if session.type ~= "c2s_unauthed" then return; end
@@ -100,22 +119,7 @@
 	elseif not session.sasl_handler then
 		return true; -- FIXME ignoring out of order stanzas because ejabberd does
 	end
-	local text = stanza[1];
-	if text then
-		text = base64.decode(text);
-		--log("debug", "AUTH: %s", text:gsub("[%z\001-\008\011\012\014-\031]", " "));
-		if not text then
-			session.sasl_handler = nil;
-			session.send(build_reply("failure", "incorrect-encoding"));
-			return true;
-		end
-	end
-	local status, ret, err_msg = session.sasl_handler:process(text);
-	status, ret, err_msg = handle_status(session, status, ret, err_msg);
-	local s = build_reply(status, ret, err_msg);
-	log("debug", "sasl reply: %s", tostring(s));
-	session.send(s);
-	return true;
+	return sasl_process_cdata(session, stanza);
 end
 
 module:hook("stanza/urn:ietf:params:xml:ns:xmpp-sasl:auth", sasl_handler);