diff mod_net_dovecotauth/mod_net_dovecotauth.lua @ 2456:f3fc2b672df3

mod_net_dovecotauth: Replace missing buffer lib with simpler string based buffering
author Kim Alvefur <zash@zash.se>
date Sun, 22 Jan 2017 04:41:04 +0100
parents 1831c7b23286
children 17539a5d73f4
line wrap: on
line diff
--- a/mod_net_dovecotauth/mod_net_dovecotauth.lua	Sun Jan 22 00:41:11 2017 +0100
+++ b/mod_net_dovecotauth/mod_net_dovecotauth.lua	Sun Jan 22 04:41:04 2017 +0100
@@ -14,7 +14,6 @@
 local new_sasl = require "core.usermanager".get_sasl_handler;
 local user_exists = require "core.usermanager".user_exists;
 local base64 = require"util.encodings".base64;
-local new_buffer = module:require"buffer".new;
 local dump = require"util.serialization".serialize;
 
 -- Config
@@ -31,7 +30,7 @@
 local sess_mt = { __index = sess };
 
 function new_session(conn)
-	local sess = { type = "?", conn = conn, buf = assert(new_buffer()), sasl = {} }
+	local sess = { type = "?", conn = conn, buf = "", sasl = {} }
 	function sess:log(l, m, ...)
 		return module:log(l, self.type..tonumber(tostring(self):match("%x+$"), 16)..": "..m, ...);
 	end
@@ -66,9 +65,11 @@
 	-- TODO break this up a bit
 	-- module:log("debug", "sess = %s", dump(self));
 	local buf = self.buf;
-	buf:write(data);
-	local line = buf:read("*l")
+	buf = buf .. data;
+	local line, eol = buf:match("(.-)\r?\n()")
 	while line and line ~= "" do
+		buf = buf:sub(eol);
+		self.buf = buf;
 		local part = line:gmatch("[^\t]+");
 		local command = part();
 		if command == "VERSION" then
@@ -138,7 +139,7 @@
 			self.conn:close();
 			break;
 		end
-		line = buf:read("*l");
+		line, eol = buf:match("(.-)\r?\n()")
 	end
 end