---=========================
---SASL PLAIN
-local function sasl_mechanism_plain(self, message)
- local response = message
- local authorization = s_match(response, "([^%z]+)")
- local authentication = s_match(response, "%z([^%z]+)%z")
- local password = s_match(response, "%z[^%z]+%z([^%z]+)")
-
- if authentication == nil or password == nil then
- return "failure", "malformed-request";
- end
-
- local correct, state = false, false;
- if self.profile.plain then
- local correct_password;
- correct_password, state = self.profile.plain(authentication, self.realm);
- if correct_password == password then correct = true; else correct = false; end
- elseif self.profile.plain_test then
- correct, state = self.profile.plain_test(authentication, self.realm, password);
- end
-
- self.username = authentication
- if not state then
- return "failure", "account-disabled";
- end
-
- if correct then
- return "success";
- else
- return "failure", "not-authorized";
- end
-end
-registerMechanism("PLAIN", {"plain", "plain_test"}, sasl_mechanism_plain);
+-- load the mechanisms
+require "util.sasl.plain" .init(registerMechanism);
+require "util.sasl.digest-md5".init(registerMechanism);
+require "util.sasl.anonymous" .init(registerMechanism);
+require "util.sasl.scram" .init(registerMechanism);