diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/events.lua | 8 | ||||
-rw-r--r-- | util/sasl_cyrus.lua | 23 |
2 files changed, 22 insertions, 9 deletions
diff --git a/util/events.lua b/util/events.lua index a1edd496..ef8fc30a 100644 --- a/util/events.lua +++ b/util/events.lua @@ -47,13 +47,13 @@ function new() _rebuild_index(event); end end; - local function add_plugin(plugin) - for event, handler in pairs(plugin) do + local function add_handlers(handlers) + for event, handler in pairs(handlers) do add_handler(event, handler); end end; - local function remove_plugin(plugin) - for event, handler in pairs(plugin) do + local function remove_handlers(handlers) + for event, handler in pairs(handlers) do remove_handler(event, handler); end end; diff --git a/util/sasl_cyrus.lua b/util/sasl_cyrus.lua index 7e689f62..b42bee07 100644 --- a/util/sasl_cyrus.lua +++ b/util/sasl_cyrus.lua @@ -31,12 +31,25 @@ module "sasl_cyrus" local method = {}; method.__index = method; - -pcall(cyrussasl.server_init, "prosody") +local initialized = false; + +local function init(service_name) + if not initialized then + local st, errmsg = pcall(cyrussasl.server_init, service_name); + if st then + initialized = true; + else + log("error", "Failed to initialize CyrusSASL: %s", errmsg); + end + end +end -- create a new SASL object which can be used to authenticate clients function new(realm, service_name) local sasl_i = {}; + + init(service_name); + sasl_i.realm = realm; sasl_i.service_name = service_name; sasl_i.cyrus = cyrussasl.server_new(service_name, nil, nil, nil, nil) @@ -64,17 +77,17 @@ end function method:mechanisms() local mechanisms = {} local cyrus_mechs = cyrussasl.listmech(self.cyrus, nil, "", " ", "") - for w in s_gmatch(cyrus_mechs, "%a+") do + for w in s_gmatch(cyrus_mechs, "[^ ]+") do mechanisms[w] = true; end - self.mechanisms = mechanisms + self.mechs = mechanisms return array.collect(keys(mechanisms)); end -- select a mechanism to use function method:select(mechanism) self.mechanism = mechanism; - return self.mechanisms[mechanism]; + return self.mechs[mechanism]; end -- feed new messages to process into the library |