util.iterators: Add skip() to skip the first n items of an iterator
[prosody.git] / util / sasl.lua
index c9225f0d776436ab1ad0d44b456318392fc43d71..5d1b9f17f3d5e2e8e76f517b522bf45ebfee20c7 100644 (file)
@@ -88,18 +88,21 @@ end
 
 -- get a list of possible SASL mechanims to use
 function method:mechanisms()
-       local mechanisms = {}
-       for backend, f in pairs(self.profile) do
-               if backend_mechanism[backend] then
-                       for _, mechanism in ipairs(backend_mechanism[backend]) do
-                               if not self.restrict:contains(mechanism) then
-                                       mechanisms[mechanism] = true;
+       local mechanisms = self.mechs;
+       if not mechanisms then
+               mechanisms = {}
+               for backend, f in pairs(self.profile) do
+                       if backend_mechanism[backend] then
+                               for _, mechanism in ipairs(backend_mechanism[backend]) do
+                                       if not self.restrict:contains(mechanism) then
+                                               mechanisms[mechanism] = true;
+                                       end
                                end
                        end
                end
+               self.mechs = mechanisms;
        end
-       self["possible_mechanisms"] = mechanisms;
-       return array.collect(keys(mechanisms));
+       return mechanisms;
 end
 
 -- select a mechanism to use
@@ -108,7 +111,7 @@ function method:select(mechanism)
                return false;
        end
        
-       self.mech_i = mechanisms[mechanism];
+       self.mech_i = mechanisms[self:mechanisms()[mechanism] and mechanism];
        return (self.mech_i ~= nil);
 end