util.sasl: Cache the calculated mechanisms set for SASL profiles (profile.mechanisms...
authorWaqas Hussain <waqas20@gmail.com>
Wed, 29 Dec 2010 13:45:31 +0000 (18:45 +0500)
committerWaqas Hussain <waqas20@gmail.com>
Wed, 29 Dec 2010 13:45:31 +0000 (18:45 +0500)
util/sasl.lua

index 93b79a86a63de48333bc482b0a0de155c3db3aa3..17d10b804b7b9188a434d2dfe669db078912b905 100644 (file)
@@ -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