util.*: Remove use of module() function, make all module functions local and return them in a table at the end
authorKim Alvefur <zash@zash.se>
Sat, 21 Feb 2015 10:36:37 +0100
changeset 6780 5de6b93d0190
parent 6777 3965662ae091
child 6781 4009ae66e0f0
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
util/array.lua
util/caps.lua
util/dataforms.lua
util/datamanager.lua
util/datetime.lua
util/debug.lua
util/dependencies.lua
util/events.lua
util/filters.lua
util/helpers.lua
util/jid.lua
util/logger.lua
util/multitable.lua
util/pluginloader.lua
util/prosodyctl.lua
util/pubsub.lua
util/sasl.lua
util/sasl/anonymous.lua
util/sasl/digest-md5.lua
util/sasl/external.lua
util/sasl/plain.lua
util/sasl_cyrus.lua
util/serialization.lua
util/set.lua
util/sql.lua
util/sslconfig.lua
util/stanza.lua
util/template.lua
util/termcolours.lua
util/throttle.lua
util/timer.lua
util/watchdog.lua
util/x509.lua
util/xml.lua
util/xmppstream.lua
--- a/util/array.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/array.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -169,7 +169,4 @@
 	end
 end
 
-_G.array = array;
-module("array");
-
 return array;
--- a/util/caps.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/caps.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -12,9 +12,9 @@
 local t_insert, t_sort, t_concat = table.insert, table.sort, table.concat;
 local ipairs = ipairs;
 
-module "caps"
+local _ENV = nil;
 
-function calculate_hash(disco_info)
+local function calculate_hash(disco_info)
 	local identities, features, extensions = {}, {}, {};
 	for _, tag in ipairs(disco_info) do
 		if tag.name == "identity" then
@@ -58,4 +58,6 @@
 	return ver, S;
 end
 
-return _M;
+return {
+	calculate_hash = calculate_hash;
+};
--- a/util/dataforms.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/dataforms.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -13,14 +13,14 @@
 local st = require "util.stanza";
 local jid_prep = require "util.jid".prep;
 
-module "dataforms"
+local _ENV = nil;
 
 local xmlns_forms = 'jabber:x:data';
 
 local form_t = {};
 local form_mt = { __index = form_t };
 
-function new(layout)
+local function new(layout)
 	return setmetatable(layout, form_mt);
 end
 
@@ -238,7 +238,9 @@
 		return field_tag:get_child_text("value");
 	end
 
-return _M;
+return {
+	new = new;
+};
 
 
 --[=[
--- a/util/datamanager.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/datamanager.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -43,7 +43,7 @@
 	fallocate = pposix.fallocate or fallocate;
 end);
 
-module "datamanager"
+local _ENV = nil;
 
 ---- utils -----
 local encode, decode;
@@ -74,7 +74,7 @@
 
 ------- API -------------
 
-function set_data_path(path)
+local function set_data_path(path)
 	log("debug", "Setting data path to: %s", path);
 	data_path = path;
 end
@@ -87,14 +87,14 @@
 
 	return username, host, datastore, data;
 end
-function add_callback(func)
+local function add_callback(func)
 	if not callbacks[func] then -- Would you really want to set the same callback more than once?
 		callbacks[func] = true;
 		callbacks[#callbacks+1] = func;
 		return true;
 	end
 end
-function remove_callback(func)
+local function remove_callback(func)
 	if callbacks[func] then
 		for i, f in ipairs(callbacks) do
 			if f == func then
@@ -106,7 +106,7 @@
 	end
 end
 
-function getpath(username, host, datastore, ext, create)
+local function getpath(username, host, datastore, ext, create)
 	ext = ext or "dat";
 	host = (host and encode(host)) or "_global";
 	username = username and encode(username);
@@ -119,7 +119,7 @@
 	end
 end
 
-function load(username, host, datastore)
+local function load(username, host, datastore)
 	local data, ret = envloadfile(getpath(username, host, datastore), {});
 	if not data then
 		local mode = lfs.attributes(getpath(username, host, datastore), "mode");
@@ -175,7 +175,7 @@
 	end
 end
 
-function store(username, host, datastore, data)
+local function store(username, host, datastore, data)
 	if not data then
 		data = {};
 	end
@@ -209,7 +209,7 @@
 	return true;
 end
 
-function list_append(username, host, datastore, data)
+local function list_append(username, host, datastore, data)
 	if not data then return; end
 	if callback(username, host, datastore) == false then return true; end
 	-- save the datastore
@@ -235,7 +235,7 @@
 	return true;
 end
 
-function list_store(username, host, datastore, data)
+local function list_store(username, host, datastore, data)
 	if not data then
 		data = {};
 	end
@@ -259,7 +259,7 @@
 	return true;
 end
 
-function list_load(username, host, datastore)
+local function list_load(username, host, datastore)
 	local items = {};
 	local data, ret = envloadfile(getpath(username, host, datastore, "list"), {item = function(i) t_insert(items, i); end});
 	if not data then
@@ -287,7 +287,7 @@
 	list = "list";
 }
 
-function users(host, store, typ)
+local function users(host, store, typ)
 	typ = type_map[typ or "keyval"];
 	local store_dir = format("%s/%s/%s", data_path, encode(host), store);
 
@@ -306,7 +306,7 @@
 	end, state;
 end
 
-function stores(username, host, typ)
+local function stores(username, host, typ)
 	typ = type_map[typ or "keyval"];
 	local store_dir = format("%s/%s/", data_path, encode(host));
 
@@ -346,7 +346,7 @@
 	return true
 end
 
-function purge(username, host)
+local function purge(username, host)
 	local host_dir = format("%s/%s/", data_path, encode(host));
 	local ok, iter, state, var = pcall(lfs.dir, host_dir);
 	if not ok then
@@ -366,6 +366,19 @@
 	return #errs == 0, t_concat(errs, ", ");
 end
 
-_M.path_decode = decode;
-_M.path_encode = encode;
-return _M;
+return {
+	set_data_path = set_data_path;
+	add_callback = add_callback;
+	remove_callback = remove_callback;
+	getpath = getpath;
+	load = load;
+	store = store;
+	list_append = list_append;
+	list_store = list_store;
+	list_load = list_load;
+	users = users;
+	stores = stores;
+	purge = purge;
+	path_decode = decode;
+	path_encode = encode;
+};
--- a/util/datetime.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/datetime.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -15,25 +15,25 @@
 local error = error;
 local tonumber = tonumber;
 
-module "datetime"
+local _ENV = nil;
 
-function date(t)
+local function date(t)
 	return os_date("!%Y-%m-%d", t);
 end
 
-function datetime(t)
+local function datetime(t)
 	return os_date("!%Y-%m-%dT%H:%M:%SZ", t);
 end
 
-function time(t)
+local function time(t)
 	return os_date("!%H:%M:%S", t);
 end
 
-function legacy(t)
+local function legacy(t)
 	return os_date("!%Y%m%dT%H:%M:%S", t);
 end
 
-function parse(s)
+local function parse(s)
 	if s then
 		local year, month, day, hour, min, sec, tzd;
 		year, month, day, hour, min, sec, tzd = s:match("^(%d%d%d%d)%-?(%d%d)%-?(%d%d)T(%d%d):(%d%d):(%d%d)%.?%d*([Z+%-]?.*)$");
@@ -54,4 +54,10 @@
 	end
 end
 
-return _M;
+return {
+	date     = date;
+	datetime = datetime;
+	time     = time;
+	legacy   = legacy;
+	parse    = parse;
+};
--- a/util/debug.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/debug.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -13,7 +13,7 @@
 local getstring = termcolours.getstring;
 local styles;
 do
-	_ = termcolours.getstyle;
+	local _ = termcolours.getstyle;
 	styles = {
 		boundary_padding = _("bright");
 		filename         = _("bright", "blue");
@@ -22,9 +22,8 @@
 		location         = _("yellow");
 	};
 end
-module("debugx", package.seeall);
 
-function get_locals_table(thread, level)
+local function get_locals_table(thread, level)
 	local locals = {};
 	for local_num = 1, math.huge do
 		local name, value;
@@ -39,7 +38,7 @@
 	return locals;
 end
 
-function get_upvalues_table(func)
+local function get_upvalues_table(func)
 	local upvalues = {};
 	if func then
 		for upvalue_num = 1, math.huge do
@@ -51,7 +50,7 @@
 	return upvalues;
 end
 
-function string_from_var_table(var_table, max_line_len, indent_str)
+local function string_from_var_table(var_table, max_line_len, indent_str)
 	local var_string = {};
 	local col_pos = 0;
 	max_line_len = max_line_len or math.huge;
@@ -87,7 +86,7 @@
 	end
 end
 
-function get_traceback_table(thread, start_level)
+local function get_traceback_table(thread, start_level)
 	local levels = {};
 	for level = start_level, math.huge do
 		local info;
@@ -108,20 +107,12 @@
 	return levels;
 end
 
-function traceback(...)
-	local ok, ret = pcall(_traceback, ...);
-	if not ok then
-		return "Error in error handling: "..ret;
-	end
-	return ret;
-end
-
 local function build_source_boundary_marker(last_source_desc)
 	local padding = string.rep("-", math.floor(((optimal_line_length - 6) - #last_source_desc)/2));
 	return getstring(styles.boundary_padding, "v"..padding).." "..getstring(styles.filename, last_source_desc).." "..getstring(styles.boundary_padding, padding..(#last_source_desc%2==0 and "-v" or "v "));
 end
 
-function _traceback(thread, message, level)
+local function _traceback(thread, message, level)
 
 	-- Lua manual says: debug.traceback ([thread,] [message [, level]])
 	-- I fathom this to mean one of:
@@ -192,8 +183,23 @@
 	return message.."stack traceback:\n"..table.concat(lines, "\n");
 end
 
-function use()
+local function traceback(...)
+	local ok, ret = pcall(_traceback, ...);
+	if not ok then
+		return "Error in error handling: "..ret;
+	end
+	return ret;
+end
+
+local function use()
 	debug.traceback = traceback;
 end
 
-return _M;
+return {
+	get_locals_table = get_locals_table;
+	get_upvalues_table = get_upvalues_table;
+	string_from_var_table = string_from_var_table;
+	get_traceback_table = get_traceback_table;
+	traceback = traceback;
+	use = use;
+};
--- a/util/dependencies.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/dependencies.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -6,16 +6,14 @@
 -- COPYING file in the source package for more information.
 --
 
-module("dependencies", package.seeall)
-
-function softreq(...) local ok, lib =  pcall(require, ...); if ok then return lib; else return nil, lib; end end
+local function softreq(...) local ok, lib =  pcall(require, ...); if ok then return lib; else return nil, lib; end end
 
 -- Required to be able to find packages installed with luarocks
 if not softreq "luarocks.loader" then -- LuaRocks 2.x
 	softreq "luarocks.require"; -- LuaRocks <1.x
 end
 
-function missingdep(name, sources, msg)
+local function missingdep(name, sources, msg)
 	print("");
 	print("**************************");
 	print("Prosody was unable to find "..tostring(name));
@@ -48,7 +46,7 @@
 	end
 end;
 
-function check_dependencies()
+local function check_dependencies()
 	if _VERSION ~= "Lua 5.1" then
 		print "***********************************"
 		print("Unsupported Lua version: ".._VERSION);
@@ -137,13 +135,15 @@
 	return not fatal;
 end
 
-function log_warnings()
+local function log_warnings()
+	local ssl = softreq"ssl";
 	if ssl then
 		local major, minor, veryminor, patched = ssl._VERSION:match("(%d+)%.(%d+)%.?(%d*)(M?)");
 		if not major or ((tonumber(major) == 0 and (tonumber(minor) or 0) <= 3 and (tonumber(veryminor) or 0) <= 2) and patched ~= "M") then
 			log("error", "This version of LuaSec contains a known bug that causes disconnects, see http://prosody.im/doc/depends");
 		end
 	end
+	local lxp = softreq"lxp";
 	if lxp then
 		if not pcall(lxp.new, { StartDoctypeDecl = false }) then
 			log("error", "The version of LuaExpat on your system leaves Prosody "
@@ -162,4 +162,9 @@
 	end
 end
 
-return _M;
+return {
+	softreq = softreq;
+	missingdep = missingdep;
+	check_dependencies = check_dependencies;
+	log_warnings = log_warnings;
+};
--- a/util/events.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/events.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -14,9 +14,9 @@
 local setmetatable = setmetatable;
 local next = next;
 
-module "events"
+local _ENV = nil;
 
-function new()
+local function new()
 	local handlers = {};
 	local global_wrappers;
 	local wrappers = {};
@@ -151,4 +151,6 @@
 	};
 end
 
-return _M;
+return {
+	new = new;
+};
--- a/util/filters.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/filters.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -8,11 +8,11 @@
 
 local t_insert, t_remove = table.insert, table.remove;
 
-module "filters"
+local _ENV = nil;
 
 local new_filter_hooks = {};
 
-function initialize(session)
+local function initialize(session)
 	if not session.filters then
 		local filters = {};
 		session.filters = filters;
@@ -36,7 +36,7 @@
 	return session.filter;
 end
 
-function add_filter(session, type, callback, priority)
+local function add_filter(session, type, callback, priority)
 	if not session.filters then
 		initialize(session);
 	end
@@ -60,7 +60,7 @@
 	filter_list[callback] = priority;
 end
 
-function remove_filter(session, type, callback)
+local function remove_filter(session, type, callback)
 	if not session.filters then return; end
 	local filter_list = session.filters[type];
 	if filter_list and filter_list[callback] then
@@ -74,11 +74,11 @@
 	end
 end
 
-function add_filter_hook(callback)
+local function add_filter_hook(callback)
 	t_insert(new_filter_hooks, callback);
 end
 
-function remove_filter_hook(callback)
+local function remove_filter_hook(callback)
 	for i=1,#new_filter_hooks do
 		if new_filter_hooks[i] == callback then
 			t_remove(new_filter_hooks, i);
@@ -86,4 +86,10 @@
 	end
 end
 
-return _M;
+return {
+	initialize = initialize;
+	add_filter = add_filter;
+	remove_filter = remove_filter;
+	add_filter_hook = add_filter_hook;
+	remove_filter_hook = remove_filter_hook;
+};
--- a/util/helpers.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/helpers.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -8,21 +8,19 @@
 
 local debug = require "util.debug";
 
-module("helpers", package.seeall);
-
 -- Helper functions for debugging
 
 local log = require "util.logger".init("util.debug");
 
-function log_host_events(host)
+local function log_host_events(host)
 	return log_events(prosody.hosts[host].events, host);
 end
 
-function revert_log_host_events(host)
+local function revert_log_host_events(host)
 	return revert_log_events(prosody.hosts[host].events);
 end
 
-function log_events(events, name, logger)
+local function log_events(events, name, logger)
 	local f = events.fire_event;
 	if not f then
 		error("Object does not appear to be a util.events object");
@@ -37,11 +35,11 @@
 	return events;
 end
 
-function revert_log_events(events)
+local function revert_log_events(events)
 	events.fire_event, events[events.fire_event] = events[events.fire_event], nil; -- :))
 end
 
-function show_events(events, specific_event)
+local function show_events(events, specific_event)
 	local event_handlers = events._handlers;
 	local events_array = {};
 	local event_handler_arrays = {};
@@ -70,7 +68,7 @@
 	return table.concat(events_array, "\n");
 end
 
-function get_upvalue(f, get_name)
+local function get_upvalue(f, get_name)
 	local i, name, value = 0;
 	repeat
 		i = i + 1;
@@ -79,4 +77,11 @@
 	return value;
 end
 
-return _M;
+return {
+	log_host_events = log_host_events;
+	revert_log_host_events = revert_log_host_events;
+	log_events = log_events;
+	revert_log_events = revert_log_events;
+	show_events = show_events;
+	get_upvalue = get_upvalue;
+};
--- a/util/jid.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/jid.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -23,9 +23,9 @@
 local unescapes = {};
 for k,v in pairs(escapes) do unescapes[v] = k; end
 
-module "jid"
+local _ENV = nil;
 
-local function _split(jid)
+local function split(jid)
 	if not jid then return; end
 	local node, nodepos = match(jid, "^([^@/]+)@()");
 	local host, hostpos = match(jid, "^([^@/]+)()", nodepos)
@@ -34,14 +34,13 @@
 	if (not host) or ((not resource) and #jid >= hostpos) then return nil, nil, nil; end
 	return node, host, resource;
 end
-split = _split;
 
-function bare(jid)
+local function bare(jid)
 	return jid and match(jid, "^[^/]+");
 end
 
-local function _prepped_split(jid)
-	local node, host, resource = _split(jid);
+local function prepped_split(jid)
+	local node, host, resource = split(jid);
 	if host then
 		if sub(host, -1, -1) == "." then -- Strip empty root label
 			host = sub(host, 1, -2);
@@ -59,9 +58,8 @@
 		return node, host, resource;
 	end
 end
-prepped_split = _prepped_split;
 
-local function _join(node, host, resource)
+local function join(node, host, resource)
 	if not host then return end
 	if node and resource then
 		return node.."@"..host.."/"..resource;
@@ -72,18 +70,17 @@
 	end
 	return host;
 end
-join = _join;
 
-function prep(jid)
-	local node, host, resource = _prepped_split(jid);
-	return _join(node, host, resource);
+local function prep(jid)
+	local node, host, resource = prepped_split(jid);
+	return join(node, host, resource);
 end
 
-function compare(jid, acl)
+local function compare(jid, acl)
 	-- compare jid to single acl rule
 	-- TODO compare to table of rules?
-	local jid_node, jid_host, jid_resource = _split(jid);
-	local acl_node, acl_host, acl_resource = _split(acl);
+	local jid_node, jid_host, jid_resource = split(jid);
+	local acl_node, acl_host, acl_resource = split(acl);
 	if ((acl_node ~= nil and acl_node == jid_node) or acl_node == nil) and
 		((acl_host ~= nil and acl_host == jid_host) or acl_host == nil) and
 		((acl_resource ~= nil and acl_resource == jid_resource) or acl_resource == nil) then
@@ -92,7 +89,16 @@
 	return false
 end
 
-function escape(s) return s and (s:gsub(".", escapes)); end
-function unescape(s) return s and (s:gsub("\\%x%x", unescapes)); end
+local function escape(s) return s and (s:gsub(".", escapes)); end
+local function unescape(s) return s and (s:gsub("\\%x%x", unescapes)); end
 
-return _M;
+return {
+	split = split;
+	bare = bare;
+	prepped_split = prepped_split;
+	join = join;
+	prep = prep;
+	compare = compare;
+	escape = escape;
+	unescape = unescape;
+};
--- a/util/logger.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/logger.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -11,13 +11,13 @@
 local find = string.find;
 local ipairs, pairs, setmetatable = ipairs, pairs, setmetatable;
 
-module "logger"
+local _ENV = nil;
 
 local level_sinks = {};
 
 local make_logger;
 
-function init(name)
+local function init(name)
 	local log_debug = make_logger(name, "debug");
 	local log_info = make_logger(name, "info");
 	local log_warn = make_logger(name, "warn");
@@ -52,7 +52,7 @@
 	return logger;
 end
 
-function reset()
+local function reset()
 	for level, handler_list in pairs(level_sinks) do
 		-- Clear all handlers for this level
 		for i = 1, #handler_list do
@@ -61,7 +61,7 @@
 	end
 end
 
-function add_level_sink(level, sink_function)
+local function add_level_sink(level, sink_function)
 	if not level_sinks[level] then
 		level_sinks[level] = { sink_function };
 	else
@@ -69,6 +69,10 @@
 	end
 end
 
-_M.new = make_logger;
-
-return _M;
+return {
+	init = init;
+	make_logger = make_logger;
+	reset = reset;
+	add_level_sink = add_level_sink;
+	new = make_logger;
+};
--- a/util/multitable.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/multitable.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -10,7 +10,7 @@
 local t_insert = table.insert;
 local unpack, pairs, next, type = unpack, pairs, next, type;
 
-module "multitable"
+local _ENV = nil;
 
 local function get(self, ...)
 	local t = self.data;
@@ -126,7 +126,7 @@
 	return results;
 end
 
-function iter(self, ...)
+local function iter(self, ...)
 	local query = { ... };
 	local maxdepth = select("#", ...);
 	local stack = { self.data };
@@ -161,7 +161,7 @@
 	return it, self;
 end
 
-function new()
+local function new()
 	return {
 		data = {};
 		get = get;
@@ -174,4 +174,7 @@
 	};
 end
 
-return _M;
+return {
+	iter = iter;
+	new = new;
+};
--- a/util/pluginloader.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/pluginloader.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -17,9 +17,7 @@
 local io_open = io.open;
 local envload = require "util.envload".envload;
 
-module "pluginloader"
-
-function load_file(names)
+local function load_file(names)
 	local file, err, path;
 	for i=1,#plugin_dir do
 		for j=1,#names do
@@ -35,7 +33,7 @@
 	return file, err;
 end
 
-function load_resource(plugin, resource)
+local function load_resource(plugin, resource)
 	resource = resource or "mod_"..plugin..".lua";
 
 	local names = {
@@ -48,7 +46,7 @@
 	return load_file(names);
 end
 
-function load_code(plugin, resource, env)
+local function load_code(plugin, resource, env)
 	local content, err = load_resource(plugin, resource);
 	if not content then return content, err; end
 	local path = err;
@@ -57,4 +55,8 @@
 	return f, path;
 end
 
-return _M;
+return {
+	load_file = load_file;
+	load_resource = load_resource;
+	load_code = load_code;
+};
--- a/util/prosodyctl.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/prosodyctl.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -29,25 +29,19 @@
 local _G = _G;
 local prosody = prosody;
 
-module "prosodyctl"
-
 -- UI helpers
-function show_message(msg, ...)
+local function show_message(msg, ...)
 	print(msg:format(...));
 end
 
-function show_warning(msg, ...)
-	print(msg:format(...));
-end
-
-function show_usage(usage, desc)
+local function show_usage(usage, desc)
 	print("Usage: ".._G.arg[0].." "..usage);
 	if desc then
 		print(" "..desc);
 	end
 end
 
-function getchar(n)
+local function getchar(n)
 	local stty_ret = os.execute("stty raw -echo 2>/dev/null");
 	local ok, char;
 	if stty_ret == 0 then
@@ -64,14 +58,14 @@
 	end
 end
 
-function getline()
+local function getline()
 	local ok, line = pcall(io.read, "*l");
 	if ok then
 		return line;
 	end
 end
 
-function getpass()
+local function getpass()
 	local stty_ret = os.execute("stty -echo 2>/dev/null");
 	if stty_ret ~= 0 then
 		io.write("\027[08m"); -- ANSI 'hidden' text attribute
@@ -88,7 +82,7 @@
 	end
 end
 
-function show_yesno(prompt)
+local function show_yesno(prompt)
 	io.write(prompt, " ");
 	local choice = getchar():lower();
 	io.write("\n");
@@ -99,7 +93,7 @@
 	return (choice == "y");
 end
 
-function read_password()
+local function read_password()
 	local password;
 	while true do
 		io.write("Enter new password: ");
@@ -120,7 +114,7 @@
 	return password;
 end
 
-function show_prompt(prompt)
+local function show_prompt(prompt)
 	io.write(prompt, " ");
 	local line = getline();
 	line = line and line:gsub("\n$","");
@@ -128,7 +122,7 @@
 end
 
 -- Server control
-function adduser(params)
+local function adduser(params)
 	local user, host, password = nodeprep(params.user), nameprep(params.host), params.password;
 	if not user then
 		return false, "invalid-username";
@@ -149,12 +143,12 @@
 
 	local ok, errmsg = usermanager.create_user(user, password, host);
 	if not ok then
-		return false, errmsg;
+		return false, errmsg or "creating-user-failed";
 	end
 	return true;
 end
 
-function user_exists(params)
+local function user_exists(params)
 	local user, host, password = nodeprep(params.user), nameprep(params.host), params.password;
 
 	storagemanager.initialize_host(host);
@@ -166,16 +160,16 @@
 	return usermanager.user_exists(user, host);
 end
 
-function passwd(params)
-	if not _M.user_exists(params) then
+local function passwd(params)
+	if not user_exists(params) then
 		return false, "no-such-user";
 	end
 
-	return _M.adduser(params);
+	return adduser(params);
 end
 
-function deluser(params)
-	if not _M.user_exists(params) then
+local function deluser(params)
+	if not user_exists(params) then
 		return false, "no-such-user";
 	end
 	local user, host = nodeprep(params.user), nameprep(params.host);
@@ -183,7 +177,7 @@
 	return usermanager.delete_user(user, host);
 end
 
-function getpid()
+local function getpid()
 	local pidfile = config.get("*", "pidfile");
 	if not pidfile then
 		return false, "no-pidfile";
@@ -219,8 +213,8 @@
 	return true, pid;
 end
 
-function isrunning()
-	local ok, pid, err = _M.getpid();
+local function isrunning()
+	local ok, pid, err = getpid();
 	if not ok then
 		if pid == "pidfile-read-failed" or pid == "pidfile-not-locked" then
 			-- Report as not running, since we can't open the pidfile
@@ -232,8 +226,8 @@
 	return true, signal.kill(pid, 0) == 0;
 end
 
-function start()
-	local ok, ret = _M.isrunning();
+local function start()
+	local ok, ret = isrunning();
 	if not ok then
 		return ok, ret;
 	end
@@ -248,8 +242,24 @@
 	return true;
 end
 
-function stop()
-	local ok, ret = _M.isrunning();
+local function stop()
+	local ok, ret = isrunning();
+	if not ok then
+		return ok, ret;
+	end
+	if not ret then
+		return false, "not-running";
+	end
+
+	local ok, pid = getpid()
+	if not ok then return false, pid; end
+
+	signal.kill(pid, signal.SIGTERM);
+	return true;
+end
+
+local function reload()
+	local ok, ret = isrunning();
 	if not ok then
 		return ok, ret;
 	end
@@ -257,27 +267,30 @@
 		return false, "not-running";
 	end
 
-	local ok, pid = _M.getpid()
-	if not ok then return false, pid; end
-
-	signal.kill(pid, signal.SIGTERM);
-	return true;
-end
-
-function reload()
-	local ok, ret = _M.isrunning();
-	if not ok then
-		return ok, ret;
-	end
-	if not ret then
-		return false, "not-running";
-	end
-
-	local ok, pid = _M.getpid()
+	local ok, pid = getpid()
 	if not ok then return false, pid; end
 
 	signal.kill(pid, signal.SIGHUP);
 	return true;
 end
 
-return _M;
+return {
+	show_message = show_message;
+	show_warning = show_message;
+	show_usage = show_usage;
+	getchar = getchar;
+	getline = getline;
+	getpass = getpass;
+	show_yesno = show_yesno;
+	read_password = read_password;
+	show_prompt = show_prompt;
+	adduser = adduser;
+	user_exists = user_exists;
+	passwd = passwd;
+	deluser = deluser;
+	getpid = getpid;
+	isrunning = isrunning;
+	start = start;
+	stop = stop;
+	reload = reload;
+};
--- a/util/pubsub.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/pubsub.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -1,8 +1,6 @@
 local events = require "util.events";
 local t_remove = table.remove;
 
-module("pubsub", package.seeall);
-
 local service = {};
 local service_mt = { __index = service };
 
@@ -15,7 +13,7 @@
 	["pubsub#max_items"] = "20";
 } };
 
-function new(config)
+local function new(config)
 	config = config or {};
 	return setmetatable({
 		config = setmetatable(config, default_config);
@@ -442,4 +440,6 @@
 	return true;
 end
 
-return _M;
+return {
+	new = new;
+};
--- a/util/sasl.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/sasl.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -19,7 +19,7 @@
 local assert = assert;
 local require = require;
 
-module "sasl"
+local _ENV = nil;
 
 --[[
 Authentication Backend Prototypes:
@@ -47,7 +47,7 @@
 local mechanism_channelbindings = {};
 
 -- register a new SASL mechanims
-function registerMechanism(name, backends, f, cb_backends)
+local function registerMechanism(name, backends, f, cb_backends)
 	assert(type(name) == "string", "Parameter name MUST be a string.");
 	assert(type(backends) == "string" or type(backends) == "table", "Parameter backends MUST be either a string or a table.");
 	assert(type(f) == "function", "Parameter f MUST be a function.");
@@ -66,7 +66,7 @@
 end
 
 -- create a new SASL object which can be used to authenticate clients
-function new(realm, profile)
+local function new(realm, profile)
 	local mechanisms = profile.mechanisms;
 	if not mechanisms then
 		mechanisms = {};
@@ -138,4 +138,7 @@
 require "util.sasl.scram"     .init(registerMechanism);
 require "util.sasl.external"  .init(registerMechanism);
 
-return _M;
+return {
+	registerMechanism = registerMechanism;
+	new = new;
+};
--- a/util/sasl/anonymous.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/sasl/anonymous.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -16,7 +16,7 @@
 local log = require "util.logger".init("sasl");
 local generate_uuid = require "util.uuid".generate;
 
-module "sasl.anonymous"
+local _ENV = nil;
 
 --=========================
 --SASL ANONYMOUS according to RFC 4505
@@ -39,8 +39,10 @@
 	return "success"
 end
 
-function init(registerMechanism)
+local function init(registerMechanism)
 	registerMechanism("ANONYMOUS", {"anonymous"}, anonymous);
 end
 
-return _M;
+return {
+	init = init;
+}
--- a/util/sasl/digest-md5.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/sasl/digest-md5.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -25,7 +25,7 @@
 local generate_uuid = require "util.uuid".generate;
 local nodeprep = require "util.encodings".stringprep.nodeprep;
 
-module "sasl.digest-md5"
+local _ENV = nil;
 
 --=========================
 --SASL DIGEST-MD5 according to RFC 2831
@@ -241,8 +241,10 @@
 	end
 end
 
-function init(registerMechanism)
+local function init(registerMechanism)
 	registerMechanism("DIGEST-MD5", {"plain"}, digest);
 end
 
-return _M;
+return {
+	init = init;
+}
--- a/util/sasl/external.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/sasl/external.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -1,6 +1,6 @@
 local saslprep = require "util.encodings".stringprep.saslprep;
 
-module "sasl.external"
+local _ENV = nil;
 
 local function external(self, message)
 	message = saslprep(message);
@@ -18,8 +18,10 @@
 	return "success";
 end
 
-function init(registerMechanism)
+local function init(registerMechanism)
 	registerMechanism("EXTERNAL", {"external"}, external);
 end
 
-return _M;
+return {
+	init = init;
+}
--- a/util/sasl/plain.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/sasl/plain.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -16,7 +16,7 @@
 local nodeprep = require "util.encodings".stringprep.nodeprep;
 local log = require "util.logger".init("sasl");
 
-module "sasl.plain"
+local _ENV = nil;
 
 -- ================================
 -- SASL PLAIN according to RFC 4616
@@ -82,8 +82,10 @@
 	return "success";
 end
 
-function init(registerMechanism)
+local function init(registerMechanism)
 	registerMechanism("PLAIN", {"plain", "plain_test"}, plain);
 end
 
-return _M;
+return {
+	init = init;
+}
--- a/util/sasl_cyrus.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/sasl_cyrus.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -60,7 +60,7 @@
 };
 setmetatable(sasl_errstring, { __index = function() return "undefined error!" end });
 
-module "sasl_cyrus"
+local _ENV = nil;
 
 local method = {};
 method.__index = method;
@@ -82,7 +82,7 @@
 --      For GSSAPI, this determines the hostname in the service ticket (after
 --      reverse DNS canonicalization, only if [libdefaults] rdns = true which
 --      is the default).
-function new(realm, service_name, app_name, host_fqdn)
+local function new(realm, service_name, app_name, host_fqdn)
 
 	init(app_name or service_name);
 
@@ -163,4 +163,6 @@
 	end
 end
 
-return _M;
+return {
+	new = new;
+};
--- a/util/serialization.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/serialization.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -20,7 +20,7 @@
 local log = require "util.logger".init("serialization");
 local envload = require"util.envload".envload;
 
-module "serialization"
+local _ENV = nil;
 
 local indent = function(i)
 	return string_rep("\t", i);
@@ -71,16 +71,16 @@
 	end
 end
 
-function append(t, o)
+local function append(t, o)
 	_simplesave(o, 1, t, t.write or t_insert);
 	return t;
 end
 
-function serialize(o)
+local function serialize(o)
 	return t_concat(append({}, o));
 end
 
-function deserialize(str)
+local function deserialize(str)
 	if type(str) ~= "string" then return nil; end
 	str = "return "..str;
 	local f, err = envload(str, "@data", {});
@@ -90,4 +90,8 @@
 	return ret;
 end
 
-return _M;
+return {
+	append = append;
+	serialize = serialize;
+	deserialize = deserialize;
+};
--- a/util/set.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/set.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -10,59 +10,19 @@
       ipairs, pairs, setmetatable, next, tostring;
 local t_concat = table.concat;
 
-module "set"
+local _ENV = nil;
 
 local set_mt = {};
 function set_mt.__call(set, _, k)
 	return next(set._items, k);
 end
-function set_mt.__add(set1, set2)
-	return _M.union(set1, set2);
-end
-function set_mt.__sub(set1, set2)
-	return _M.difference(set1, set2);
-end
-function set_mt.__div(set, func)
-	local new_set = _M.new();
-	local items, new_items = set._items, new_set._items;
-	for item in pairs(items) do
-		local new_item = func(item);
-		if new_item ~= nil then
-			new_items[new_item] = true;
-		end
-	end
-	return new_set;
-end
-function set_mt.__eq(set1, set2)
-	set1, set2 = set1._items, set2._items;
-	for item in pairs(set1) do
-		if not set2[item] then
-			return false;
-		end
-	end
-
-	for item in pairs(set2) do
-		if not set1[item] then
-			return false;
-		end
-	end
-
-	return true;
-end
-function set_mt.__tostring(set)
-	local s, items = { }, set._items;
-	for item in pairs(items) do
-		s[#s+1] = tostring(item);
-	end
-	return t_concat(s, ", ");
-end
 
 local items_mt = {};
 function items_mt.__call(items, _, k)
 	return next(items, k);
 end
 
-function new(list)
+local function new(list)
 	local items = setmetatable({}, items_mt);
 	local set = { _items = items };
 
@@ -116,7 +76,7 @@
 	return setmetatable(set, set_mt);
 end
 
-function union(set1, set2)
+local function union(set1, set2)
 	local set = new();
 	local items = set._items;
 
@@ -131,7 +91,7 @@
 	return set;
 end
 
-function difference(set1, set2)
+local function difference(set1, set2)
 	local set = new();
 	local items = set._items;
 
@@ -142,7 +102,7 @@
 	return set;
 end
 
-function intersection(set1, set2)
+local function intersection(set1, set2)
 	local set = new();
 	local items = set._items;
 
@@ -155,8 +115,55 @@
 	return set;
 end
 
-function xor(set1, set2)
+local function xor(set1, set2)
 	return union(set1, set2) - intersection(set1, set2);
 end
 
-return _M;
+function set_mt.__add(set1, set2)
+	return union(set1, set2);
+end
+function set_mt.__sub(set1, set2)
+	return difference(set1, set2);
+end
+function set_mt.__div(set, func)
+	local new_set = new();
+	local items, new_items = set._items, new_set._items;
+	for item in pairs(items) do
+		local new_item = func(item);
+		if new_item ~= nil then
+			new_items[new_item] = true;
+		end
+	end
+	return new_set;
+end
+function set_mt.__eq(set1, set2)
+	set1, set2 = set1._items, set2._items;
+	for item in pairs(set1) do
+		if not set2[item] then
+			return false;
+		end
+	end
+
+	for item in pairs(set2) do
+		if not set1[item] then
+			return false;
+		end
+	end
+
+	return true;
+end
+function set_mt.__tostring(set)
+	local s, items = { }, set._items;
+	for item in pairs(items) do
+		s[#s+1] = tostring(item);
+	end
+	return t_concat(s, ", ");
+end
+
+return {
+	new = new;
+	union = union;
+	difference = difference;
+	intersection = intersection;
+	xor = xor;
+};
--- a/util/sql.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/sql.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -13,7 +13,7 @@
 DBI.Drivers();
 local build_url = require "socket.url".build;
 
-module("sql")
+local _ENV = nil;
 
 local column_mt = {};
 local table_mt = {};
@@ -21,17 +21,17 @@
 --local op_mt = {};
 local index_mt = {};
 
-function is_column(x) return getmetatable(x)==column_mt; end
-function is_index(x) return getmetatable(x)==index_mt; end
-function is_table(x) return getmetatable(x)==table_mt; end
-function is_query(x) return getmetatable(x)==query_mt; end
-function Integer(n) return "Integer()" end
-function String(n) return "String()" end
+local function is_column(x) return getmetatable(x)==column_mt; end
+local function is_index(x) return getmetatable(x)==index_mt; end
+local function is_table(x) return getmetatable(x)==table_mt; end
+local function is_query(x) return getmetatable(x)==query_mt; end
+local function Integer(n) return "Integer()" end
+local function String(n) return "String()" end
 
-function Column(definition)
+local function Column(definition)
 	return setmetatable(definition, column_mt);
 end
-function Table(definition)
+local function Table(definition)
 	local c = {}
 	for i,col in ipairs(definition) do
 		if is_column(col) then
@@ -42,7 +42,7 @@
 	end
 	return setmetatable({ __table__ = definition, c = c, name = definition.name }, table_mt);
 end
-function Index(definition)
+local function Index(definition)
 	return setmetatable(definition, index_mt);
 end
 
@@ -302,7 +302,7 @@
 end
 local engine_mt = { __index = engine };
 
-function db2uri(params)
+local function db2uri(params)
 	return build_url{
 		scheme = params.driver,
 		user = params.username,
@@ -313,8 +313,19 @@
 	};
 end
 
-function create_engine(self, params, onconnect)
+local function create_engine(self, params, onconnect)
 	return setmetatable({ url = db2uri(params), params = params, onconnect = onconnect }, engine_mt);
 end
 
-return _M;
+return {
+	is_column = is_column;
+	is_index = is_index;
+	is_table = is_table;
+	is_query = is_query;
+	Integer = Integer;
+	String = String;
+	Column = Column;
+	Table = Table;
+	Index = Index;
+	create_engine = create_engine;
+};
--- a/util/sslconfig.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/sslconfig.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -1,3 +1,11 @@
+local type = type;
+local pairs = pairs;
+local rawset = rawset;
+local t_concat = table.concat;
+local t_insert = table.insert;
+local setmetatable = setmetatable;
+
+local _ENV = nil;
 
 local handlers = { };
 local finalisers = { };
@@ -34,7 +42,7 @@
 
 function finalisers.ciphers(a)
 	if type(a) == "table" then
-		return table.concat(a, ":");
+		return t_concat(a, ":");
 	end
 	return a;
 end
@@ -47,7 +55,7 @@
 	if min_protocol then
 		a.protocol = "sslv23";
 		for i = 1, min_protocol do
-			table.insert(a.options, "no_"..protocols[i]);
+			t_insert(a.options, "no_"..protocols[i]);
 		end
 	end
 end
--- a/util/stanza.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/stanza.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -35,13 +35,12 @@
 
 local xmlns_stanzas = "urn:ietf:params:xml:ns:xmpp-stanzas";
 
-module "stanza"
+local _ENV = nil;
 
-stanza_mt = { __type = "stanza" };
+local stanza_mt = { __type = "stanza" };
 stanza_mt.__index = stanza_mt;
-local stanza_mt = stanza_mt;
 
-function stanza(name, attr)
+local function stanza(name, attr)
 	local stanza = { name = name, attr = attr or {}, tags = {} };
 	return setmetatable(stanza, stanza_mt);
 end
@@ -200,12 +199,8 @@
 end
 
 
-local xml_escape
-do
-	local escape_table = { ["'"] = "&apos;", ["\""] = "&quot;", ["<"] = "&lt;", [">"] = "&gt;", ["&"] = "&amp;" };
-	function xml_escape(str) return (s_gsub(str, "['&<>\"]", escape_table)); end
-	_M.xml_escape = xml_escape;
-end
+local escape_table = { ["'"] = "&apos;", ["\""] = "&quot;", ["<"] = "&lt;", [">"] = "&gt;", ["&"] = "&amp;" };
+local function xml_escape(str) return (s_gsub(str, "['&<>\"]", escape_table)); end
 
 local function _dostring(t, buf, self, xml_escape, parentns)
 	local nsid = 0;
@@ -280,15 +275,13 @@
 	return type, condition or "undefined-condition", text;
 end
 
-do
-	local id = 0;
-	function new_id()
-		id = id + 1;
-		return "lx"..id;
-	end
+local id = 0;
+local function new_id()
+	id = id + 1;
+	return "lx"..id;
 end
 
-function preserialize(stanza)
+local function preserialize(stanza)
 	local s = { name = stanza.name, attr = stanza.attr };
 	for _, child in ipairs(stanza) do
 		if type(child) == "table" then
@@ -300,7 +293,7 @@
 	return s;
 end
 
-function deserialize(stanza)
+local function deserialize(stanza)
 	-- Set metatable
 	if stanza then
 		local attr = stanza.attr;
@@ -337,51 +330,48 @@
 	return stanza;
 end
 
-local function _clone(stanza)
+local function clone(stanza)
 	local attr, tags = {}, {};
 	for k,v in pairs(stanza.attr) do attr[k] = v; end
 	local new = { name = stanza.name, attr = attr, tags = tags };
 	for i=1,#stanza do
 		local child = stanza[i];
 		if child.name then
-			child = _clone(child);
+			child = clone(child);
 			t_insert(tags, child);
 		end
 		t_insert(new, child);
 	end
 	return setmetatable(new, stanza_mt);
 end
-clone = _clone;
 
-function message(attr, body)
+local function message(attr, body)
 	if not body then
 		return stanza("message", attr);
 	else
 		return stanza("message", attr):tag("body"):text(body):up();
 	end
 end
-function iq(attr)
+local function iq(attr)
 	if attr and not attr.id then attr.id = new_id(); end
 	return stanza("iq", attr or { id = new_id() });
 end
 
-function reply(orig)
+local function reply(orig)
 	return stanza(orig.name, orig.attr and { to = orig.attr.from, from = orig.attr.to, id = orig.attr.id, type = ((orig.name == "iq" and "result") or orig.attr.type) });
 end
 
-do
-	local xmpp_stanzas_attr = { xmlns = xmlns_stanzas };
-	function error_reply(orig, type, condition, message)
-		local t = reply(orig);
-		t.attr.type = "error";
-		t:tag("error", {type = type}) --COMPAT: Some day xmlns:stanzas goes here
-			:tag(condition, xmpp_stanzas_attr):up();
-		if (message) then t:tag("text", xmpp_stanzas_attr):text(message):up(); end
-		return t; -- stanza ready for adding app-specific errors
-	end
+local xmpp_stanzas_attr = { xmlns = xmlns_stanzas };
+local function error_reply(orig, type, condition, message)
+	local t = reply(orig);
+	t.attr.type = "error";
+	t:tag("error", {type = type}) --COMPAT: Some day xmlns:stanzas goes here
+	:tag(condition, xmpp_stanzas_attr):up();
+	if (message) then t:tag("text", xmpp_stanzas_attr):text(message):up(); end
+	return t; -- stanza ready for adding app-specific errors
 end
 
-function presence(attr)
+local function presence(attr)
 	return stanza("presence", attr);
 end
 
@@ -425,4 +415,16 @@
 	stanza_mt.pretty_top_tag = stanza_mt.top_tag;
 end
 
-return _M;
+return {
+	stanza_mt = stanza_mt;
+	stanza = stanza;
+	new_id = new_id;
+	preserialize = preserialize;
+	deserialize = deserialize;
+	clone = clone;
+	message = message;
+	iq = iq;
+	reply = reply;
+	error_reply = error_reply;
+	presence = presence;
+};
--- a/util/template.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/template.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -9,7 +9,7 @@
 local t_remove = table.remove;
 local parse_xml = require "util.xml".parse;
 
-module("template")
+local _ENV = nil;
 
 local function trim_xml(stanza)
 	for i=#stanza,1,-1 do
--- a/util/termcolours.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/termcolours.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -19,7 +19,7 @@
 end
 local orig_color = windows and windows.get_consolecolor and windows.get_consolecolor();
 
-module "termcolours"
+local _ENV = nil;
 
 local stylemap = {
 			reset = 0; bright = 1, dim = 2, underscore = 4, blink = 5, reverse = 7, hidden = 8;
@@ -45,7 +45,7 @@
 };
 
 local fmt_string = char(0x1B).."[%sm%s"..char(0x1B).."[0m";
-function getstring(style, text)
+local function getstring(style, text)
 	if style then
 		return format(fmt_string, style, text);
 	else
@@ -53,7 +53,7 @@
 	end
 end
 
-function getstyle(...)
+local function getstyle(...)
 	local styles, result = { ... }, {};
 	for i, style in ipairs(styles) do
 		style = stylemap[style];
@@ -65,7 +65,7 @@
 end
 
 local last = "0";
-function setstyle(style)
+local function setstyle(style)
 	style = style or "0";
 	if style ~= last then
 		io_write("\27["..style.."m");
@@ -95,8 +95,13 @@
 	return "</span><span style='"..t_concat(css, ";").."'>";
 end
 
-function tohtml(input)
+local function tohtml(input)
 	return input:gsub("\027%[(.-)m", ansi2css);
 end
 
-return _M;
+return {
+	getstring = getstring;
+	getstyle = getstyle;
+	setstyle = setstyle;
+	tohtml = tohtml;
+};
--- a/util/throttle.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/throttle.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -3,7 +3,7 @@
 local setmetatable = setmetatable;
 local floor = math.floor;
 
-module "throttle"
+local _ENV = nil;
 
 local throttle = {};
 local throttle_mt = { __index = throttle };
@@ -39,8 +39,10 @@
 	end
 end
 
-function create(max, period)
+local function create(max, period)
 	return setmetatable({ rate = max / period, max = max, t = 0, balance = max }, throttle_mt);
 end
 
-return _M;
+return {
+	create = create;
+};
--- a/util/timer.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/timer.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -17,7 +17,7 @@
 local data = {};
 local new_data = {};
 
-module "timer"
+local _ENV = nil;
 
 local _add_task;
 if not server.event then
@@ -78,6 +78,6 @@
 	end
 end
 
-add_task = _add_task;
-
-return _M;
+return {
+	add_task = _add_task;
+};
--- a/util/watchdog.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/watchdog.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -2,12 +2,12 @@
 local setmetatable = setmetatable;
 local os_time = os.time;
 
-module "watchdog"
+local _ENV = nil;
 
 local watchdog_methods = {};
 local watchdog_mt = { __index = watchdog_methods };
 
-function new(timeout, callback)
+local function new(timeout, callback)
 	local watchdog = setmetatable({ timeout = timeout, last_reset = os_time(), callback = callback }, watchdog_mt);
 	timer.add_task(timeout+1, function (current_time)
 		local last_reset = watchdog.last_reset;
@@ -31,4 +31,6 @@
 	self.last_reset = nil;
 end
 
-return _M;
+return {
+	new = new;
+};
--- a/util/x509.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/x509.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -24,7 +24,7 @@
 local log = require "util.logger".init("x509");
 local s_format = string.format;
 
-module "x509"
+local _ENV = nil;
 
 local oid_commonname = "2.5.4.3"; -- [LDAP] 2.3
 local oid_subjectaltname = "2.5.29.17"; -- [PKIX] 4.2.1.6
@@ -147,7 +147,7 @@
 	return false
 end
 
-function verify_identity(host, service, cert)
+local function verify_identity(host, service, cert)
 	if cert.setencode then
 		cert:setencode("utf8");
 	end
@@ -218,7 +218,7 @@
 local pat = "%-%-%-%-%-BEGIN ([A-Z ]+)%-%-%-%-%-\r?\n"..
 "([0-9A-Za-z+/=\r\n]*)\r?\n%-%-%-%-%-END %1%-%-%-%-%-";
 
-function pem2der(pem)
+local function pem2der(pem)
 	local typ, data = pem:match(pat);
 	if typ and data then
 		return base64.decode(data), typ;
@@ -228,10 +228,14 @@
 local wrap = ('.'):rep(64);
 local envelope = "-----BEGIN %s-----\n%s\n-----END %s-----\n"
 
-function der2pem(data, typ)
+local function der2pem(data, typ)
 	typ = typ and typ:upper() or "CERTIFICATE";
 	data = base64.encode(data);
 	return s_format(envelope, typ, data:gsub(wrap, '%0\n', (#data-1)/64), typ);
 end
 
-return _M;
+return {
+	verify_identity = verify_identity;
+	pem2der = pem2der;
+	der2pem = der2pem;
+};
--- a/util/xml.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/xml.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -2,7 +2,7 @@
 local st = require "util.stanza";
 local lxp = require "lxp";
 
-module("xml")
+local _ENV = nil;
 
 local parse_xml = (function()
 	local ns_prefixes = {
@@ -54,5 +54,6 @@
 	end;
 end)();
 
-parse = parse_xml;
-return _M;
+return {
+	parse = parse_xml;
+};
--- a/util/xmppstream.lua	Mon Aug 10 22:16:05 2015 +0200
+++ b/util/xmppstream.lua	Sat Feb 21 10:36:37 2015 +0100
@@ -24,7 +24,7 @@
 
 local default_stanza_size_limit = 1024*1024*10; -- 10MB
 
-module "xmppstream"
+local _ENV = nil;
 
 local new_parser = lxp.new;
 
@@ -40,12 +40,9 @@
 local ns_separator = "\1";
 local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$";
 
-_M.ns_separator = ns_separator;
-_M.ns_pattern = ns_pattern;
-
 local function dummy_cb() end
 
-function new_sax_handlers(session, stream_callbacks, cb_handleprogress)
+local function new_sax_handlers(session, stream_callbacks, cb_handleprogress)
 	local xml_handlers = {};
 
 	local cb_streamopened = stream_callbacks.streamopened;
@@ -224,7 +221,7 @@
 	return xml_handlers, { reset = reset, set_session = set_session };
 end
 
-function new(session, stream_callbacks, stanza_size_limit)
+local function new(session, stream_callbacks, stanza_size_limit)
 	-- Used to track parser progress (e.g. to enforce size limits)
 	local n_outstanding_bytes = 0;
 	local handle_progress;
@@ -281,4 +278,9 @@
 	};
 end
 
-return _M;
+return {
+	ns_separator = ns_separator;
+	ns_pattern = ns_pattern;
+	new_sax_handlers = new_sax_handlers;
+	new = new;
+};