Changeset

6779:6236668da30a

core.*: Remove use of module() function
author Kim Alvefur <zash@zash.se>
date Sat, 21 Feb 2015 10:42:19 +0100
parents 6778:4009ae66e0f0
children 6780:647adfd8f738
files 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
diffstat 13 files changed, 188 insertions(+), 104 deletions(-) [+]
line wrap: on
line diff
--- a/core/certmanager.lua	Sat Feb 21 10:38:44 2015 +0100
+++ b/core/certmanager.lua	Sat Feb 21 10:42:19 2015 +0100
@@ -45,7 +45,7 @@
 	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 @@
 	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 @@
 	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 @@
 
 prosody.events.add_handler("config-reloaded", reload_ssl_config);
 
-return _M;
+return {
+	create_context = create_context;
+	reload_ssl_config = reload_ssl_config;
+};
--- a/core/configmanager.lua	Sat Feb 21 10:38:44 2015 +0100
+++ b/core/configmanager.lua	Sat Feb 21 10:42:19 2015 +0100
@@ -19,10 +19,11 @@
 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 @@
 -- 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 @@
 	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 @@
 	end
 end
 
-function addparser(config_format, parser)
+function _M.addparser(config_format, parser)
 	if config_format and parser then
 		parsers[config_format] = parser;
 	end
--- a/core/hostmanager.lua	Sat Feb 21 10:38:44 2015 +0100
+++ b/core/hostmanager.lua	Sat Feb 21 10:42:19 2015 +0100
@@ -28,7 +28,7 @@
 local tostring, type = tostring, type;
 local setmetatable = setmetatable;
 
-module "hostmanager"
+local _ENV = nil;
 
 local host_mt = { }
 function host_mt:__tostring()
@@ -45,6 +45,8 @@
 
 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 @@
 	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;
+}
--- a/core/loggingmanager.lua	Sat Feb 21 10:38:44 2015 +0100
+++ b/core/loggingmanager.lua	Sat Feb 21 10:42:19 2015 +0100
@@ -27,7 +27,7 @@
 
 _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 @@
 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 @@
 	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;
+}
--- a/core/moduleapi.lua	Sat Feb 21 10:38:44 2015 +0100
+++ b/core/moduleapi.lua	Sat Feb 21 10:42:19 2015 +0100
@@ -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 @@
 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 @@
 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 @@
 	return self:measure_object_event(prosody.events.wrappers, event_name, stat_name);
 end
 
-function api.init(mm)
-	modulemanager = mm;
-	return api;
-end
-
 return api;
--- a/core/modulemanager.lua	Sat Feb 21 10:38:44 2015 +0100
+++ b/core/modulemanager.lua	Sat Feb 21 10:42:19 2015 +0100
@@ -13,6 +13,7 @@
 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 @@
 -- 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 @@
 	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;
+};
--- a/core/portmanager.lua	Sat Feb 21 10:38:44 2015 +0100
+++ b/core/portmanager.lua	Sat Feb 21 10:42:19 2015 +0100
@@ -14,7 +14,7 @@
 local prosody = prosody;
 local fire_event = prosody.events.fire_event;
 
-module "portmanager";
+local _ENV = nil;
 
 --- Config
 
@@ -63,18 +63,9 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	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;
+};
--- a/core/rostermanager.lua	Sat Feb 21 10:38:44 2015 +0100
+++ b/core/rostermanager.lua	Sat Feb 21 10:42:19 2015 +0100
@@ -22,9 +22,9 @@
 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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 		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 @@
 	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 @@
 
 
 
-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;
+};
--- a/core/s2smanager.lua	Sat Feb 21 10:38:44 2015 +0100
+++ b/core/s2smanager.lua	Sat Feb 21 10:42:19 2015 +0100
@@ -22,16 +22,16 @@
 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 @@
 		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 @@
 	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 @@
 	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;
+};
--- a/core/sessionmanager.lua	Sat Feb 21 10:38:44 2015 +0100
+++ b/core/sessionmanager.lua	Sat Feb 21 10:42:19 2015 +0100
@@ -24,9 +24,9 @@
 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 @@
 		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 @@
 	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 @@
 	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 @@
 
 -- 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 @@
 	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 @@
 	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 @@
 	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;
+};
--- a/core/storagemanager.lua	Sat Feb 21 10:38:44 2015 +0100
+++ b/core/storagemanager.lua	Sat Feb 21 10:42:19 2015 +0100
@@ -11,11 +11,10 @@
 
 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 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 @@
 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 @@
 	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 @@
 	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 @@
 	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 @@
 	return purge(username, host);
 end
 
-return _M;
+return {
+	initialize_host = initialize_host;
+	load_driver = load_driver;
+	get_driver = get_driver;
+	open = open;
+
+	olddm = olddm;
+};
--- a/core/usermanager.lua	Sat Feb 21 10:38:44 2015 +0100
+++ b/core/usermanager.lua	Sat Feb 21 10:42:19 2015 +0100
@@ -23,9 +23,9 @@
 
 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 @@
 
 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 @@
 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 @@
 	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;
+};
--- a/plugins/mod_admin_adhoc.lua	Sat Feb 21 10:38:44 2015 +0100
+++ b/plugins/mod_admin_adhoc.lua	Sat Feb 21 10:42:19 2015 +0100
@@ -26,7 +26,7 @@
 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;