# HG changeset patch
# User Tobias Markmann <tm@ayena.de>
# Date 1226777289 -3600
# Node ID dc53343af9aceadbc117a039f9c68ba30b9d0524
# Parent  7e4908d4bdf65d29b50c65b27bc605b50e41f3b2
Set username in a SASL object.

diff -r 7e4908d4bdf6 -r dc53343af9ac plugins/mod_saslauth.lua
--- a/plugins/mod_saslauth.lua	Sat Nov 15 19:25:51 2008 +0100
+++ b/plugins/mod_saslauth.lua	Sat Nov 15 20:28:09 2008 +0100
@@ -7,6 +7,7 @@
 local usermanager_validate_credentials = require "core.usermanager".validate_credentials;
 local t_concat, t_insert = table.concat, table.insert;
 local tostring = tostring;
+local jid_split = require "util.jid".split
 
 local log = require "util.logger".init("mod_saslauth");
 
@@ -65,7 +66,9 @@
 	end
 	local status, ret = session.sasl_handler:feed(text);
 	handle_status(session, status);
-	session.send(build_reply(status, ret));
+	local s = build_reply(status, ret); 
+	log("debug", "sasl reply: "..tostring(s));
+	session.send(s);
 end
 
 add_handler("c2s_unauthed", "auth", xmlns_sasl,
diff -r 7e4908d4bdf6 -r dc53343af9ac util/sasl.lua
--- a/util/sasl.lua	Sat Nov 15 19:25:51 2008 +0100
+++ b/util/sasl.lua	Sat Nov 15 20:28:09 2008 +0100
@@ -19,7 +19,9 @@
 local function new_plain(realm, password_handler)
 	local object = { mechanism = "PLAIN", realm = realm, password_handler = password_handler}
 	object.feed = 	function(self, message)
-						log("debug", "feed: "..message)
+						--print(message:gsub("%W", function (c) return string.format("\\%d", string.byte(c)) end));
+
+						if message == "" or message == nil then return "failure", "malformed-request" end
 						local response = message
 						local authorization = s_match(response, "([^&%z]+)")
 						local authentication = s_match(response, "%z([^&%z]+)%z")
@@ -31,9 +33,12 @@
 						if password_encoding == nil then claimed_password = password
 						else claimed_password = password_encoding(password) end
 						
+						self.username = authentication
 						if claimed_password == correct_password then
+							log("debug", "success")
 							return "success", nil
 						else
+							log("debug", "failure")
 							return "failure", "not-authorized"
 						end
 					end