diff options
author | Kim Alvefur <zash@zash.se> | 2015-02-21 10:42:19 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2015-02-21 10:42:19 +0100 |
commit | 27265c20e21d071bc96171da9b8707aec6ea669b (patch) | |
tree | 71be0c3f872550dc6849e4cde3afd5ebfa68c1b9 /core | |
parent | 359ca86e382251845aa294baac60d9f8f58e1fe1 (diff) | |
download | prosody-27265c20e21d071bc96171da9b8707aec6ea669b.tar.gz prosody-27265c20e21d071bc96171da9b8707aec6ea669b.zip |
core.*: Remove use of module() function
Diffstat (limited to 'core')
-rw-r--r-- | core/certmanager.lua | 11 | ||||
-rw-r--r-- | core/configmanager.lua | 15 | ||||
-rw-r--r-- | core/hostmanager.lua | 12 | ||||
-rw-r--r-- | core/loggingmanager.lua | 11 | ||||
-rw-r--r-- | core/moduleapi.lua | 8 | ||||
-rw-r--r-- | core/modulemanager.lua | 18 | ||||
-rw-r--r-- | core/portmanager.lua | 52 | ||||
-rw-r--r-- | core/rostermanager.lua | 56 | ||||
-rw-r--r-- | core/s2smanager.lua | 18 | ||||
-rw-r--r-- | core/sessionmanager.lua | 26 | ||||
-rw-r--r-- | core/storagemanager.lua | 22 | ||||
-rw-r--r-- | core/usermanager.lua | 41 |
12 files changed, 187 insertions, 103 deletions
diff --git a/core/certmanager.lua b/core/certmanager.lua index b40c13c1..958ad3a3 100644 --- a/core/certmanager.lua +++ b/core/certmanager.lua @@ -45,7 +45,7 @@ local luasec_has = { single_ecdh_use = luasec_version >= 2; }; -module "certmanager" +local _ENV = nil; -- Global SSL options if not overridden per-host local global_ssl_config = configmanager.get("*", "ssl"); @@ -78,7 +78,7 @@ if luasec_version < 5 and ssl_x509 then end end -function create_context(host, mode, ...) +local function create_context(host, mode, ...) local cfg = new_config(); cfg:apply(core_defaults); cfg:apply(global_ssl_config); @@ -154,7 +154,7 @@ function create_context(host, mode, ...) return ctx, err, user_ssl_config; end -function reload_ssl_config() +local function reload_ssl_config() global_ssl_config = configmanager.get("*", "ssl"); if luasec_has.no_compression then core_defaults.options.no_compression = configmanager.get("*", "ssl_compression") ~= true; @@ -163,4 +163,7 @@ end prosody.events.add_handler("config-reloaded", reload_ssl_config); -return _M; +return { + create_context = create_context; + reload_ssl_config = reload_ssl_config; +}; diff --git a/core/configmanager.lua b/core/configmanager.lua index 5ee131ad..16d4b8e2 100644 --- a/core/configmanager.lua +++ b/core/configmanager.lua @@ -19,10 +19,11 @@ local resolve_relative_path = require"util.paths".resolve_relative_path; local glob_to_pattern = require"util.paths".glob_to_pattern; local path_sep = package.config:sub(1,1); -local have_encodings, encodings = pcall(require, "util.encodings"); -local nameprep = have_encodings and encodings.stringprep.nameprep or function (host) return host:lower(); end +local encodings = deps.softreq"util.encodings"; +local nameprep = encodings and encodings.stringprep.nameprep or function (host) return host:lower(); end -module "configmanager" +local _M = {}; +local _ENV = nil; _M.resolve_relative_path = resolve_relative_path; -- COMPAT @@ -34,11 +35,11 @@ local config = setmetatable({ ["*"] = { } }, config_mt); -- When host not found, use global local host_mt = { __index = function(_, k) return config["*"][k] end } -function getconfig() +function _M.getconfig() return config; end -function get(host, key, _oldkey) +function _M.get(host, key, _oldkey) if key == "core" then key = _oldkey; -- COMPAT with code that still uses "core" end @@ -73,7 +74,7 @@ function _M.set(host, key, value, _oldvalue) return set(config, host, key, value); end -function load(filename, config_format) +function _M.load(filename, config_format) config_format = config_format or filename:match("%w+$"); if parsers[config_format] and parsers[config_format].load then @@ -102,7 +103,7 @@ function load(filename, config_format) end end -function addparser(config_format, parser) +function _M.addparser(config_format, parser) if config_format and parser then parsers[config_format] = parser; end diff --git a/core/hostmanager.lua b/core/hostmanager.lua index 046722b1..53c1cd4e 100644 --- a/core/hostmanager.lua +++ b/core/hostmanager.lua @@ -28,7 +28,7 @@ local pairs, select, rawget = pairs, select, rawget; local tostring, type = tostring, type; local setmetatable = setmetatable; -module "hostmanager" +local _ENV = nil; local host_mt = { } function host_mt:__tostring() @@ -45,6 +45,8 @@ end local hosts_loaded_once; +local activate, deactivate; + local function load_enabled_hosts(config) local defined_hosts = config or configmanager.getconfig(); local activated_any_host; @@ -164,8 +166,12 @@ function deactivate(host, reason) return true; end -function get_children(host) +local function get_children(host) return disco_items:get(host) or NULL; end -return _M; +return { + activate = activate; + deactivate = deactivate; + get_children = get_children; +} diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua index 57ed8687..e21e3901 100644 --- a/core/loggingmanager.lua +++ b/core/loggingmanager.lua @@ -27,7 +27,7 @@ local prosody = prosody; _G.log = logger.init("general"); -module "loggingmanager" +local _ENV = nil; -- The log config used if none specified in the config file (see reload_logging for initialization) local default_logging; @@ -136,7 +136,7 @@ function get_levels(criteria, set) end -- Initialize config, etc. -- -function reload_logging() +local function reload_logging() local old_sink_types = {}; for name, sink_maker in pairs(log_sink_types) do @@ -267,10 +267,13 @@ function log_sink_types.file(sink_config) end; end -function register_sink_type(name, sink_maker) +local function register_sink_type(name, sink_maker) local old_sink_maker = log_sink_types[name]; log_sink_types[name] = sink_maker; return old_sink_maker; end -return _M; +return { + reload_logging = reload_logging; + register_sink_type = register_sink_type; +} diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 0cb1f1e7..5817894f 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -7,7 +7,6 @@ -- local config = require "core.configmanager"; -local modulemanager; -- This gets set from modulemanager local array = require "util.array"; local set = require "util.set"; local it = require "util.iterators"; @@ -145,6 +144,7 @@ function api:require(lib) end function api:depends(name) + local modulemanager = require"core.modulemanager"; if not self.dependencies then self.dependencies = {}; self:hook("module-reloaded", function (event) @@ -326,6 +326,7 @@ function api:remove_item(key, value) end function api:get_host_items(key) + local modulemanager = require"core.modulemanager"; local result = modulemanager.get_items(key, self.host) or {}; return result; end @@ -417,9 +418,4 @@ function api:measure_global_event(event_name, stat_name) return self:measure_object_event(prosody.events.wrappers, event_name, stat_name); end -function api.init(mm) - modulemanager = mm; - return api; -end - return api; diff --git a/core/modulemanager.lua b/core/modulemanager.lua index e629b005..41c9b2fe 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -13,6 +13,7 @@ local pluginloader = require "util.pluginloader"; local set = require "util.set"; local new_multitable = require "util.multitable".new; +local api = require "core.moduleapi"; -- Module API container local hosts = hosts; local prosody = prosody; @@ -35,9 +36,9 @@ local component_inheritable_modules = {"tls", "saslauth", "dialback", "iq", "s2s -- We need this to let modules access the real global namespace local _G = _G; -module "modulemanager" +local _ENV = nil; -local api = _G.require "core.moduleapi".init(_M); -- Module API container +local load_modules_for_host, load, unload, reload, get_module, get_items, get_modules, is_loaded, module_has_method, call_module_method; -- [host] = { [module] = module_env } local modulemap = { ["*"] = {} }; @@ -317,4 +318,15 @@ function call_module_method(module, method, ...) end end -return _M; +return { + load_modules_for_host = load_modules_for_host; + load = load; + unload = unload; + reload = reload; + get_module = get_module; + get_items = get_items; + get_modules = get_modules; + is_loaded = is_loaded; + module_has_method = module_has_method; + call_module_method = call_module_method; +}; diff --git a/core/portmanager.lua b/core/portmanager.lua index e800cf36..47ec10c7 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -14,7 +14,7 @@ local type, tonumber, tostring, ipairs = type, tonumber, tostring, ipairs; local prosody = prosody; local fire_event = prosody.events.fire_event; -module "portmanager"; +local _ENV = nil; --- Config @@ -63,18 +63,9 @@ local function error_to_friendly_message(service_name, port, err) --luacheck: ig return friendly_message; end -prosody.events.add_handler("item-added/net-provider", function (event) - local item = event.item; - register_service(item.name, item); -end); -prosody.events.add_handler("item-removed/net-provider", function (event) - local item = event.item; - unregister_service(item.name, item); -end); - --- Public API -function activate(service_name) +local function activate(service_name) local service_info = services[service_name][1]; if not service_info then return nil, "Unknown service: "..service_name; @@ -151,7 +142,7 @@ function activate(service_name) return true; end -function deactivate(service_name, service_info) +local function deactivate(service_name, service_info) for name, interface, port, n, active_service --luacheck: ignore 213/name 213/n in active_services:iter(service_name or service_info and service_info.name, nil, nil, nil) do if service_info == nil or active_service.service == service_info then @@ -161,7 +152,7 @@ function deactivate(service_name, service_info) log("info", "Deactivated service '%s'", service_name or service_info.name); end -function register_service(service_name, service_info) +local function register_service(service_name, service_info) table.insert(services[service_name], service_info); if not active_services:get(service_name) then @@ -176,7 +167,7 @@ function register_service(service_name, service_info) return true; end -function unregister_service(service_name, service_info) +local function unregister_service(service_name, service_info) log("debug", "Unregistering service: %s", service_name); local service_info_list = services[service_name]; for i, service in ipairs(service_info_list) do @@ -191,7 +182,7 @@ function unregister_service(service_name, service_info) fire_event("service-removed", { name = service_name, service = service_info }); end -function close(interface, port) +local function close(interface, port) local service, service_server = get_service_at(interface, port); if not service then return false, "port-not-open"; @@ -202,21 +193,42 @@ function close(interface, port) return true; end -function get_service_at(interface, port) +local function get_service_at(interface, port) local data = active_services:search(nil, interface, port)[1][1]; return data.service, data.server; end -function get_service(service_name) +local function get_service(service_name) return (services[service_name] or {})[1]; end -function get_active_services() +local function get_active_services() return active_services; end -function get_registered_services() +local function get_registered_services() return services; end -return _M; +-- Event handlers + +prosody.events.add_handler("item-added/net-provider", function (event) + local item = event.item; + register_service(item.name, item); +end); +prosody.events.add_handler("item-removed/net-provider", function (event) + local item = event.item; + unregister_service(item.name, item); +end); + +return { + activate = activate; + deactivate = deactivate; + register_service = register_service; + unregister_service = unregister_service; + close = close; + get_service_at = get_service_at; + get_service = get_service; + get_active_services = get_active_services; + get_registered_services = get_registered_services; +}; diff --git a/core/rostermanager.lua b/core/rostermanager.lua index a9b26f23..08a507ab 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -22,9 +22,9 @@ local datamanager = require "util.datamanager" local um_user_exists = require "core.usermanager".user_exists; local st = require "util.stanza"; -module "rostermanager" +local _ENV = nil; -function add_to_roster(session, jid, item) +local function add_to_roster(session, jid, item) if session.roster then local old_item = session.roster[jid]; session.roster[jid] = item; @@ -39,7 +39,7 @@ function add_to_roster(session, jid, item) end end -function remove_from_roster(session, jid) +local function remove_from_roster(session, jid) if session.roster then local old_item = session.roster[jid]; session.roster[jid] = nil; @@ -54,7 +54,7 @@ function remove_from_roster(session, jid) end end -function roster_push(username, host, jid) +local function roster_push(username, host, jid) local roster = jid and hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster; if roster then local item = hosts[host].sessions[username].roster[jid]; @@ -95,7 +95,7 @@ local function roster_metadata(roster, err) return metadata; end -function load_roster(username, host) +local function load_roster(username, host) local jid = username.."@"..host; log("debug", "load_roster: asked for: %s", jid); local user = bare_sessions[jid]; @@ -121,7 +121,7 @@ function load_roster(username, host) return roster, err; end -function save_roster(username, host, roster) +local function save_roster(username, host, roster) if not um_user_exists(username, host) then log("debug", "not saving roster for %s@%s: the user doesn't exist", username, host); return nil; @@ -147,7 +147,7 @@ function save_roster(username, host, roster) return nil; end -function process_inbound_subscription_approval(username, host, jid) +local function process_inbound_subscription_approval(username, host, jid) local roster = load_roster(username, host); local item = roster[jid]; if item and item.ask then @@ -161,7 +161,7 @@ function process_inbound_subscription_approval(username, host, jid) end end -function process_inbound_subscription_cancellation(username, host, jid) +local function process_inbound_subscription_cancellation(username, host, jid) local roster = load_roster(username, host); local item = roster[jid]; local changed = nil; @@ -183,7 +183,7 @@ function process_inbound_subscription_cancellation(username, host, jid) end end -function process_inbound_unsubscribe(username, host, jid) +local function process_inbound_unsubscribe(username, host, jid) local roster = load_roster(username, host); local item = roster[jid]; local changed = nil; @@ -210,7 +210,7 @@ local function _get_online_roster_subscription(jidA, jidB) local item = user and (user.roster[jidB] or { subscription = "none" }); return item and item.subscription; end -function is_contact_subscribed(username, host, jid) +local function is_contact_subscribed(username, host, jid) do local selfjid = username.."@"..host; local user_subscription = _get_online_roster_subscription(selfjid, jid); @@ -223,11 +223,11 @@ function is_contact_subscribed(username, host, jid) return item and (item.subscription == "from" or item.subscription == "both"), err; end -function is_contact_pending_in(username, host, jid) +local function is_contact_pending_in(username, host, jid) local roster = load_roster(username, host); return roster[false].pending[jid]; end -function set_contact_pending_in(username, host, jid) +local function set_contact_pending_in(username, host, jid) local roster = load_roster(username, host); local item = roster[jid]; if item and (item.subscription == "from" or item.subscription == "both") then @@ -236,12 +236,12 @@ function set_contact_pending_in(username, host, jid) roster[false].pending[jid] = true; return save_roster(username, host, roster); end -function is_contact_pending_out(username, host, jid) +local function is_contact_pending_out(username, host, jid) local roster = load_roster(username, host); local item = roster[jid]; return item and item.ask; end -function set_contact_pending_out(username, host, jid) -- subscribe +local function set_contact_pending_out(username, host, jid) -- subscribe local roster = load_roster(username, host); local item = roster[jid]; if item and (item.ask or item.subscription == "to" or item.subscription == "both") then @@ -255,7 +255,7 @@ function set_contact_pending_out(username, host, jid) -- subscribe log("debug", "set_contact_pending_out: saving roster; set %s@%s.roster[%q].ask=subscribe", username, host, jid); return save_roster(username, host, roster); end -function unsubscribe(username, host, jid) +local function unsubscribe(username, host, jid) local roster = load_roster(username, host); local item = roster[jid]; if not item then return false; end @@ -270,7 +270,7 @@ function unsubscribe(username, host, jid) end return save_roster(username, host, roster); end -function subscribed(username, host, jid) +local function subscribed(username, host, jid) if is_contact_pending_in(username, host, jid) then local roster = load_roster(username, host); local item = roster[jid]; @@ -287,7 +287,7 @@ function subscribed(username, host, jid) return save_roster(username, host, roster); end -- TODO else implement optional feature pre-approval (ask = subscribed) end -function unsubscribed(username, host, jid) +local function unsubscribed(username, host, jid) local roster = load_roster(username, host); local item = roster[jid]; local pending = is_contact_pending_in(username, host, jid); @@ -308,7 +308,7 @@ function unsubscribed(username, host, jid) return success, pending, subscribed; end -function process_outbound_subscription_request(username, host, jid) +local function process_outbound_subscription_request(username, host, jid) local roster = load_roster(username, host); local item = roster[jid]; if item and (item.subscription == "none" or item.subscription == "from") then @@ -328,4 +328,22 @@ end]] -return _M; +return { + add_to_roster = add_to_roster; + remove_from_roster = remove_from_roster; + roster_push = roster_push; + load_roster = load_roster; + save_roster = save_roster; + process_inbound_subscription_approval = process_inbound_subscription_approval; + process_inbound_subscription_cancellation = process_inbound_subscription_cancellation; + process_inbound_unsubscribe = process_inbound_unsubscribe; + is_contact_subscribed = is_contact_subscribed; + is_contact_pending_in = is_contact_pending_in; + set_contact_pending_in = set_contact_pending_in; + is_contact_pending_out = is_contact_pending_out; + set_contact_pending_out = set_contact_pending_out; + unsubscribe = unsubscribe; + subscribed = subscribed; + unsubscribed = unsubscribed; + process_outbound_subscription_request = process_outbound_subscription_request; +}; diff --git a/core/s2smanager.lua b/core/s2smanager.lua index b6516393..a8d399d2 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -22,16 +22,16 @@ prosody.incoming_s2s = incoming_s2s; local incoming_s2s = incoming_s2s; local fire_event = prosody.events.fire_event; -module "s2smanager" +local _ENV = nil; -function new_incoming(conn) +local function new_incoming(conn) local session = { conn = conn, type = "s2sin_unauthed", direction = "incoming", hosts = {} }; session.log = logger_init("s2sin"..tostring(session):match("[a-f0-9]+$")); incoming_s2s[session] = true; return session; end -function new_outgoing(from_host, to_host) +local function new_outgoing(from_host, to_host) local host_session = { to_host = to_host, from_host = from_host, host = from_host, notopen = true, type = "s2sout_unauthed", direction = "outgoing" }; hosts[from_host].s2sout[to_host] = host_session; @@ -52,7 +52,7 @@ local resting_session = { -- Resting, not dead filter = function (type, data) return data; end; --luacheck: ignore 212/type }; resting_session.__index = resting_session; -function retire_session(session, reason) +local function retire_session(session, reason) local log = session.log or log; --luacheck: ignore 431/log for k in pairs(session) do if k ~= "log" and k ~= "id" and k ~= "conn" then @@ -68,7 +68,7 @@ function retire_session(session, reason) return setmetatable(session, resting_session); end -function destroy_session(session, reason) +local function destroy_session(session, reason) if session.destroyed then return; end (session.log or log)("debug", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)..(reason and (": "..reason) or "")); @@ -96,4 +96,10 @@ function destroy_session(session, reason) return true; end -return _M; +return { + incoming_s2s = incoming_s2s; + new_incoming = new_incoming; + new_outgoing = new_outgoing; + retire_session = retire_session; + destroy_session = destroy_session; +}; diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 33cc3d21..616f38a8 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -24,9 +24,9 @@ local uuid_generate = require "util.uuid".generate; local initialize_filters = require "util.filters".initialize; local gettime = require "socket".gettime; -module "sessionmanager" +local _ENV = nil; -function new_session(conn) +local function new_session(conn) local session = { conn = conn, type = "c2s_unauthed", conntime = gettime() }; local filter = initialize_filters(session); local w = conn.write; @@ -57,7 +57,7 @@ local resting_session = { -- Resting, not dead filter = function (type, data) return data; end; --luacheck: ignore 212/type }; resting_session.__index = resting_session; -function retire_session(session) +local function retire_session(session) local log = session.log or log; --luacheck: ignore 431/log for k in pairs(session) do if k ~= "log" and k ~= "id" then @@ -71,7 +71,7 @@ function retire_session(session) return setmetatable(session, resting_session); end -function destroy_session(session, err) +local function destroy_session(session, err) (session.log or log)("debug", "Destroying session for %s (%s@%s)%s", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)", err and (": "..err) or ""); if session.destroyed then return; end @@ -99,7 +99,7 @@ function destroy_session(session, err) retire_session(session); end -function make_authenticated(session, username) +local function make_authenticated(session, username) username = nodeprep(username); if not username or #username == 0 then return nil, "Invalid username"; end session.username = username; @@ -112,7 +112,7 @@ end -- returns true, nil on success -- returns nil, err_type, err, err_message on failure -function bind_resource(session, resource) +local function bind_resource(session, resource) if not session.username then return nil, "auth", "not-authorized", "Cannot bind resource before authentication"; end if session.resource then return nil, "cancel", "not-allowed", "Cannot bind multiple resources on a single connection"; end -- We don't support binding multiple resources @@ -193,7 +193,7 @@ function bind_resource(session, resource) return true; end -function send_to_available_resources(username, host, stanza) +local function send_to_available_resources(username, host, stanza) local jid = username.."@"..host; local count = 0; local user = bare_sessions[jid]; @@ -208,7 +208,7 @@ function send_to_available_resources(username, host, stanza) return count; end -function send_to_interested_resources(username, host, stanza) +local function send_to_interested_resources(username, host, stanza) local jid = username.."@"..host; local count = 0; local user = bare_sessions[jid]; @@ -223,4 +223,12 @@ function send_to_interested_resources(username, host, stanza) return count; end -return _M; +return { + new_session = new_session; + retire_session = retire_session; + destroy_session = destroy_session; + make_authenticated = make_authenticated; + bind_resource = bind_resource; + send_to_available_resources = send_to_available_resources; + send_to_interested_resources = send_to_interested_resources; +}; diff --git a/core/storagemanager.lua b/core/storagemanager.lua index 0b6679d8..b72b84db 100644 --- a/core/storagemanager.lua +++ b/core/storagemanager.lua @@ -11,11 +11,10 @@ local log = require "util.logger".init("storagemanager"); local prosody = prosody; -module("storagemanager") +local _ENV = nil; local olddm = {}; -- maintain old datamanager, for backwards compatibility for k,v in pairs(datamanager) do olddm[k] = v; end -_M.olddm = olddm; local null_storage_method = function () return false, "no data storage active"; end local null_storage_driver = setmetatable( @@ -31,7 +30,7 @@ local null_storage_driver = setmetatable( local stores_available = multitable.new(); -function initialize_host(host) +local function initialize_host(host) local host_session = hosts[host]; host_session.events.add_handler("item-added/storage-provider", function (event) local item = event.item; @@ -45,7 +44,7 @@ function initialize_host(host) end prosody.events.add_handler("host-activated", initialize_host, 101); -function load_driver(host, driver_name) +local function load_driver(host, driver_name) if driver_name == "null" then return null_storage_driver; end @@ -58,7 +57,7 @@ function load_driver(host, driver_name) return stores_available:get(host, driver_name); end -function get_driver(host, store) +local function get_driver(host, store) local storage = config.get(host, "storage"); local driver_name; local option_type = type(storage); @@ -80,7 +79,7 @@ function get_driver(host, store) return driver, driver_name; end -function open(host, store, typ) +local function open(host, store, typ) local driver, driver_name = get_driver(host, store); local ret, err = driver:open(store, typ); if not ret then @@ -94,7 +93,7 @@ function open(host, store, typ) return ret, err; end -function purge(user, host) +local function purge(user, host) local storage = config.get(host, "storage"); if type(storage) == "table" then -- multiple storage backends in use that we need to purge @@ -132,4 +131,11 @@ function datamanager.purge(username, host) return purge(username, host); end -return _M; +return { + initialize_host = initialize_host; + load_driver = load_driver; + get_driver = get_driver; + open = open; + + olddm = olddm; +}; diff --git a/core/usermanager.lua b/core/usermanager.lua index 3a2b23a2..d874447d 100644 --- a/core/usermanager.lua +++ b/core/usermanager.lua @@ -23,9 +23,9 @@ local setmetatable = setmetatable; local default_provider = "internal_plain"; -module "usermanager" +local _ENV = nil; -function new_null_provider() +local function new_null_provider() local function dummy() return nil, "method not implemented"; end; local function dummy_get_sasl_handler() return sasl_new(nil, {}); end return setmetatable({name = "null", get_sasl_handler = dummy_get_sasl_handler}, { @@ -35,7 +35,7 @@ end local provider_mt = { __index = new_null_provider() }; -function initialize_host(host) +local function initialize_host(host) local host_session = hosts[host]; if host_session.type ~= "local" then return; end @@ -68,46 +68,46 @@ function initialize_host(host) end; prosody.events.add_handler("host-activated", initialize_host, 100); -function test_password(username, host, password) +local function test_password(username, host, password) return hosts[host].users.test_password(username, password); end -function get_password(username, host) +local function get_password(username, host) return hosts[host].users.get_password(username); end -function set_password(username, password, host) +local function set_password(username, password, host) return hosts[host].users.set_password(username, password); end -function user_exists(username, host) +local function user_exists(username, host) return hosts[host].users.user_exists(username); end -function create_user(username, password, host) +local function create_user(username, password, host) return hosts[host].users.create_user(username, password); end -function delete_user(username, host) +local function delete_user(username, host) local ok, err = hosts[host].users.delete_user(username); if not ok then return nil, err; end prosody.events.fire_event("user-deleted", { username = username, host = host }); return storagemanager.purge(username, host); end -function users(host) +local function users(host) return hosts[host].users.users(); end -function get_sasl_handler(host, session) +local function get_sasl_handler(host, session) return hosts[host].users.get_sasl_handler(session); end -function get_provider(host) +local function get_provider(host) return hosts[host].users; end -function is_admin(jid, host) +local function is_admin(jid, host) if host and not hosts[host] then return false; end if type(jid) ~= "string" then return false; end @@ -151,4 +151,17 @@ function is_admin(jid, host) return is_admin or false; end -return _M; +return { + new_null_provider = new_null_provider; + initialize_host = initialize_host; + test_password = test_password; + get_password = get_password; + set_password = set_password; + user_exists = user_exists; + create_user = create_user; + delete_user = delete_user; + users = users; + get_sasl_handler = get_sasl_handler; + get_provider = get_provider; + is_admin = is_admin; +}; |