configure: Replaces tabs with spaces in --help
[prosody.git] / util / sasl.lua
index 93b79a86a63de48333bc482b0a0de155c3db3aa3..afb3861b08f90d70db33d9657da4df77efe43036 100644 (file)
@@ -35,7 +35,7 @@ local mechanisms = {};
 local backend_mechanism = {};
 
 -- register a new SASL mechanims
-local function registerMechanism(name, backends, f)
+function registerMechanism(name, backends, f)
        assert(type(name) == "string", "Parameter name MUST be a string.");
        assert(type(backends) == "string" or type(backends) == "table", "Parameter backends MUST be either a string or a table.");
        assert(type(f) == "function", "Parameter f MUST be a function.");
@@ -48,13 +48,17 @@ end
 
 -- create a new SASL object which can be used to authenticate clients
 function new(realm, profile)
-       local mechanisms = {};
-       for backend, f in pairs(profile) do
-               if backend_mechanism[backend] then
-                       for _, mechanism in ipairs(backend_mechanism[backend]) do
-                               mechanisms[mechanism] = true;
+       local mechanisms = profile.mechanisms;
+       if not mechanisms then
+               mechanisms = {};
+               for backend, f in pairs(profile) do
+                       if backend_mechanism[backend] then
+                               for _, mechanism in ipairs(backend_mechanism[backend]) do
+                                       mechanisms[mechanism] = true;
+                               end
                        end
                end
+               profile.mechanisms = mechanisms;
        end
        return setmetatable({ profile = profile, realm = realm, mechs = mechanisms }, method);
 end