core.*: Remove use of module() function
authorKim Alvefur <zash@zash.se>
Sat, 21 Feb 2015 09:42:19 +0000 (10:42 +0100)
committerKim Alvefur <zash@zash.se>
Sat, 21 Feb 2015 09:42:19 +0000 (10:42 +0100)
13 files changed:
core/certmanager.lua
core/configmanager.lua
core/hostmanager.lua
core/loggingmanager.lua
core/moduleapi.lua
core/modulemanager.lua
core/portmanager.lua
core/rostermanager.lua
core/s2smanager.lua
core/sessionmanager.lua
core/storagemanager.lua
core/usermanager.lua
plugins/mod_admin_adhoc.lua

index b40c13c1c8951f906c353cef524cb50ca680cdab..958ad3a3b78b5920f1b0c43b873e87672633f7a8 100644 (file)
@@ -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;
+};
index 5ee131ad772e921baac1fdb055cce9e3f1b6c94d..16d4b8e2f4a0ecb2841600bc01973c6c83d00b60 100644 (file)
@@ -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
index 046722b1a0ff3ca80c40f4a5225e06354ba6e566..53c1cd4eeaa4cd72b54507952ad1401738f60553 100644 (file)
@@ -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;
+}
index 57ed868775e45fdd1a620b9c6f893f505ea4e104..e21e3901647a7da25a627718d798be2811f98386 100644 (file)
@@ -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;
+}
index 0cb1f1e7f13a552bb532a6d82cfc1ad761101432..5817894f938e8d88dcad88f085107973ac6244fe 100644 (file)
@@ -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;
index e629b00571c49dee40e96183f443aca2f2e67693..41c9b2fe97eacebb02a8322aee0728c4a2674386 100644 (file)
@@ -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;
+};
index e800cf36dcb03612abc63766e60e066fa840f207..47ec10c7fddccd0455939e1177b0e4c9b1e5ea4f 100644 (file)
@@ -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;
+};
index a9b26f23892d5b5b1079b309e149fc980992feb0..08a507ab14bb07e3c640afd3449b383ebf65ed2e 100644 (file)
@@ -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;
+};
index b65163930563c2fcfb0079b914c5afa0e53a20d3..a8d399d2761307a27c1d3893750238feb2ddbf1f 100644 (file)
@@ -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;
+};
index 33cc3d21f6ec4c11d55e8e2198288f78e43fcdb4..616f38a8d891dee85edd85f12c787fcce97348f9 100644 (file)
@@ -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;
+};
index 0b6679d87c8acd237dcfcd2f92091e3f5c39bd06..b72b84db138967a7280dbcb10733242959848006 100644 (file)
@@ -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;
+};
index 3a2b23a252a1b78e09463a791888e28154e5e8c0..d874447d9dc64f59d853e6217c6057976374bdbc 100644 (file)
@@ -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;
+};
index 4fab84bca1fb36c68fe921f2d8afcb823e533c7b..c21a2060823305d12e5162ec08b3973cae50eb6f 100644 (file)
@@ -26,7 +26,7 @@ local st, jid = require "util.stanza", require "util.jid";
 local timer_add_task = require "util.timer".add_task;
 local dataforms_new = require "util.dataforms".new;
 local array = require "util.array";
-local modulemanager = require "modulemanager";
+local modulemanager = require "core.modulemanager";
 local core_post_stanza = prosody.core_post_stanza;
 local adhoc_simple = require "util.adhoc".new_simple_form;
 local adhoc_initial = require "util.adhoc".new_initial_data_form;