Software /
code /
prosody-modules
Comparison
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 |
parent | 2011:1831c7b23286 |
child | 2457:17539a5d73f4 |
comparison
equal
deleted
inserted
replaced
2455:dc30ca5ce315 | 2456:f3fc2b672df3 |
---|---|
12 | 12 |
13 -- Imports | 13 -- Imports |
14 local new_sasl = require "core.usermanager".get_sasl_handler; | 14 local new_sasl = require "core.usermanager".get_sasl_handler; |
15 local user_exists = require "core.usermanager".user_exists; | 15 local user_exists = require "core.usermanager".user_exists; |
16 local base64 = require"util.encodings".base64; | 16 local base64 = require"util.encodings".base64; |
17 local new_buffer = module:require"buffer".new; | |
18 local dump = require"util.serialization".serialize; | 17 local dump = require"util.serialization".serialize; |
19 | 18 |
20 -- Config | 19 -- Config |
21 local default_vhost = module:get_option_string("dovecotauth_host", (next(hosts))); -- TODO Is there a better solution? | 20 local default_vhost = module:get_option_string("dovecotauth_host", (next(hosts))); -- TODO Is there a better solution? |
22 local allow_master = module:get_option_boolean("dovecotauth_allow_master", false); | 21 local allow_master = module:get_option_boolean("dovecotauth_allow_master", false); |
29 do | 28 do |
30 local sess = { }; | 29 local sess = { }; |
31 local sess_mt = { __index = sess }; | 30 local sess_mt = { __index = sess }; |
32 | 31 |
33 function new_session(conn) | 32 function new_session(conn) |
34 local sess = { type = "?", conn = conn, buf = assert(new_buffer()), sasl = {} } | 33 local sess = { type = "?", conn = conn, buf = "", sasl = {} } |
35 function sess:log(l, m, ...) | 34 function sess:log(l, m, ...) |
36 return module:log(l, self.type..tonumber(tostring(self):match("%x+$"), 16)..": "..m, ...); | 35 return module:log(l, self.type..tonumber(tostring(self):match("%x+$"), 16)..": "..m, ...); |
37 end | 36 end |
38 return setmetatable(sess, sess_mt); | 37 return setmetatable(sess, sess_mt); |
39 end | 38 end |
64 | 63 |
65 function sess:feed(data) | 64 function sess:feed(data) |
66 -- TODO break this up a bit | 65 -- TODO break this up a bit |
67 -- module:log("debug", "sess = %s", dump(self)); | 66 -- module:log("debug", "sess = %s", dump(self)); |
68 local buf = self.buf; | 67 local buf = self.buf; |
69 buf:write(data); | 68 buf = buf .. data; |
70 local line = buf:read("*l") | 69 local line, eol = buf:match("(.-)\r?\n()") |
71 while line and line ~= "" do | 70 while line and line ~= "" do |
71 buf = buf:sub(eol); | |
72 self.buf = buf; | |
72 local part = line:gmatch("[^\t]+"); | 73 local part = line:gmatch("[^\t]+"); |
73 local command = part(); | 74 local command = part(); |
74 if command == "VERSION" then | 75 if command == "VERSION" then |
75 local major = tonumber(part()); | 76 local major = tonumber(part()); |
76 local minor = tonumber(part()); | 77 local minor = tonumber(part()); |
136 else | 137 else |
137 self:log("warn", "Unhandled command %s", tostring(command)); | 138 self:log("warn", "Unhandled command %s", tostring(command)); |
138 self.conn:close(); | 139 self.conn:close(); |
139 break; | 140 break; |
140 end | 141 end |
141 line = buf:read("*l"); | 142 line, eol = buf:match("(.-)\r?\n()") |
142 end | 143 end |
143 end | 144 end |
144 | 145 |
145 end | 146 end |
146 | 147 |