Merge 0.10->trunk
authorKim Alvefur <zash@zash.se>
Thu, 20 Aug 2015 11:05:22 +0000 (13:05 +0200)
committerKim Alvefur <zash@zash.se>
Thu, 20 Aug 2015 11:05:22 +0000 (13:05 +0200)
65 files changed:
.luacheckrc
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
net/adns.lua
net/connlisteners.lua
net/dns.lua
net/http.lua
net/httpserver.lua
net/server_event.lua
plugins/mod_admin_adhoc.lua
plugins/mod_admin_telnet.lua
prosodyctl
util-src/encodings.c
util-src/hashes.c
util-src/net.c
util-src/pposix.c
util-src/signal.c
util-src/windows.c
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/json.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/scram.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

index 7ebc7af429d529fcc904d2cd12f4116e311bdda8..bcce11552a84e912d3e8a75c6a75dada9d406195 100644 (file)
@@ -5,7 +5,7 @@ allow_defined_top = true
 module = true
 unused_secondaries = false
 codes = true
-ignore = { "411/err", "421/err", "411/ok", "421/ok" }
+ignore = { "411/err", "421/err", "411/ok", "421/ok", "211/_ENV" }
 
 files["plugins/"] = {
        ignore = { "122/module" };
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 3d581418fd2017bb121eab1f7e063b67d1adc375..c04e9e85b83f3074ed15f29550f9f843f3cab9fe 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;
@@ -157,8 +159,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 bb8021958219bc74537864336d86ed26e207f8a7..114a97a787727c695e7ec3e6d813106eb85e9459 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";
@@ -147,6 +146,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)
@@ -328,6 +328,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
@@ -437,9 +438,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..9f95077a483ca76f157ffe8abd29bfe7c24a2186 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,9 @@ function activate(service_name)
        return true;
 end
 
-function deactivate(service_name, service_info)
+local close; -- forward declaration
+
+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 +154,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 +169,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,6 +184,8 @@ function unregister_service(service_name, service_info)
        fire_event("service-removed", { name = service_name, service = service_info });
 end
 
+local get_service_at -- forward declaration
+
 function close(interface, port)
        local service, service_server = get_service_at(interface, port);
        if not service then
@@ -207,16 +202,37 @@ function get_service_at(interface, port)
        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..f196ccf3a1ef043ab78606d388265b36ce953da4 100644 (file)
@@ -22,9 +22,11 @@ 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 save_roster; -- forward declaration
+
+local function add_to_roster(session, jid, item)
        if session.roster then
                local old_item = session.roster[jid];
                session.roster[jid] = item;
@@ -39,7 +41,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 +56,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 +97,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];
@@ -147,7 +149,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 +163,9 @@ function process_inbound_subscription_approval(username, host, jid)
        end
 end
 
-function process_inbound_subscription_cancellation(username, host, jid)
+local is_contact_pending_out -- forward declaration
+
+local function process_inbound_subscription_cancellation(username, host, jid)
        local roster = load_roster(username, host);
        local item = roster[jid];
        local changed = nil;
@@ -183,7 +187,9 @@ function process_inbound_subscription_cancellation(username, host, jid)
        end
 end
 
-function process_inbound_unsubscribe(username, host, jid)
+local is_contact_pending_in -- forward declaration
+
+local function process_inbound_unsubscribe(username, host, jid)
        local roster = load_roster(username, host);
        local item = roster[jid];
        local changed = nil;
@@ -210,7 +216,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);
@@ -227,7 +233,7 @@ 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
@@ -241,7 +247,7 @@ function is_contact_pending_out(username, host, jid)
        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 +261,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 +276,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 +293,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 +314,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 +334,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 a01623ddd5b9d6d3f720165f911e333aa4ca67e1..a28d147c3bdfbb9d71aa329208d74710970af706 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);
@@ -109,7 +108,7 @@ local function create_map_shim(host, store)
        }, map_shim_mt);
 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
@@ -127,7 +126,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
@@ -165,4 +164,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 87f2876b1f84b5102425b1d896e5718dbe1ce117..d3da2065526e7218afdffce097d2319d5523cd87 100644 (file)
@@ -16,9 +16,9 @@ local coroutine, tostring, pcall = coroutine, tostring, pcall;
 
 local function dummy_send(sock, data, i, j) return (j-i)+1; end
 
-module "adns"
+local _ENV = nil;
 
-function lookup(handler, qname, qtype, qclass)
+local function lookup(handler, qname, qtype, qclass)
        return coroutine.wrap(function (peek)
                                if peek then
                                        log("debug", "Records for %s already cached, using those...", qname);
@@ -43,12 +43,12 @@ function lookup(handler, qname, qtype, qclass)
                        end)(dns.peek(qname, qtype, qclass));
 end
 
-function cancel(handle, call_handler, reason)
+local function cancel(handle, call_handler, reason)
        log("warn", "Cancelling DNS lookup for %s", tostring(handle[3]));
        dns.cancel(handle[1], handle[2], handle[3], handle[4], call_handler);
 end
 
-function new_async_socket(sock, resolver)
+local function new_async_socket(sock, resolver)
        local peername = "<unknown>";
        local listener = {};
        local handler = {};
@@ -88,4 +88,8 @@ end
 
 dns.socket_wrapper_set(new_async_socket);
 
-return _M;
+return {
+       lookup = lookup;
+       cancel = cancel;
+       new_async_socket = new_async_socket;
+};
index 99ddc720aa570fb02765191ca6b1c47eaddaaee0..000bfa63effa2d85598ca02eb72652240bbc4928 100644 (file)
@@ -2,14 +2,17 @@
 local log = require "util.logger".init("net.connlisteners");
 local traceback = debug.traceback;
 
-module "httpserver"
+local _ENV = nil;
 
-function fail()
+local function fail()
        log("error", "Attempt to use legacy connlisteners API. For more info see http://prosody.im/doc/developers/network");
        log("error", "Legacy connlisteners API usage, %s", traceback("", 2));
 end
 
-register, deregister = fail, fail;
-get, start = fail, fail, epic_fail;
-
-return _M;
+return {
+       register = fail;
+       register = fail;
+       get = fail;
+       start = fail;
+       -- epic fail
+};
index 992f398602346ddc5c7f0e86d29d3a92fd1b657a..acc1556c400fe0086637fcab3cf972d54810ea65 100644 (file)
@@ -71,8 +71,8 @@ local get, set = ztact.get, ztact.set;
 local default_timeout = 15;
 
 -------------------------------------------------- module dns
-module('dns')
-local dns = _M;
+local _ENV = nil;
+local dns = {};
 
 
 -- dns type & class codes ------------------------------ dns type & class codes
index 357b74520a4700e67d6d49b839327fe8bbc32361..b78f84382b40137484b3261ce541ded64c153d27 100644 (file)
@@ -23,7 +23,7 @@ local assert, error = assert, error
 
 local log = require "util.logger".init("http");
 
-module "http"
+local _ENV = nil;
 
 local requests = {}; -- Open requests
 
@@ -75,6 +75,13 @@ function listener.ondetach(conn)
        requests[conn] = nil;
 end
 
+local function destroy_request(request)
+       if request.conn then
+               request.conn = nil;
+               request.handler:close()
+       end
+end
+
 local function request_reader(request, data, err)
        if not request.parser then
                local function error_cb(reason)
@@ -106,7 +113,7 @@ local function request_reader(request, data, err)
 end
 
 local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); end
-function request(u, ex, callback)
+local function request(u, ex, callback)
        local req = url.parse(u);
 
        if not (req and req.host) then
@@ -184,17 +191,12 @@ function request(u, ex, callback)
        return req;
 end
 
-function destroy_request(request)
-       if request.conn then
-               request.conn = nil;
-               request.handler:close()
-       end
-end
-
-local urlencode, urldecode = util_http.urlencode, util_http.urldecode;
-local formencode, formdecode = util_http.formencode, util_http.formdecode;
-
-_M.urlencode, _M.urldecode = urlencode, urldecode;
-_M.formencode, _M.formdecode = formencode, formdecode;
-
-return _M;
+return {
+       request = request;
+       
+       -- COMPAT
+       urlencode = util_http.urlencode;
+       urldecode = util_http.urldecode;
+       formencode = util_http.formencode;
+       formdecode = util_http.formdecode;
+};
index 7d574788253ea25a6f67bf20f0e426e0449c34ce..6e2e31b9b3f1102794ca12d4e5397a4897826fdc 100644 (file)
@@ -2,14 +2,15 @@
 local log = require "util.logger".init("net.httpserver");
 local traceback = debug.traceback;
 
-module "httpserver"
+local _ENV = nil;
 
 function fail()
        log("error", "Attempt to use legacy HTTP API. For more info see http://prosody.im/doc/developers/legacy_http");
        log("error", "Legacy HTTP API usage, %s", traceback("", 2));
 end
 
-new, new_from_config = fail, fail;
-set_default_handler = fail;
-
-return _M;
+return {
+       new = fail;
+       new_from_config = fail;
+       set_default_handler = fail;
+};
index fa6dda19fe552f5807a6caa7464fb90d57040bc2..a4cf11461bb9c1f6ab5c1e0a8204f24a5ecb1613 100644 (file)
@@ -758,18 +758,18 @@ do
                local create = socket[typ or "tcp"]
                if type( create ) ~= "function"  then
                        return nil, "invalid socket type"
-               end
+                       end
                local client, err = create()  -- creating new socket
                if not client then
                        debug( "cannot create socket:", err )
-                       return nil, err
-               end
+                               return nil, err
+                       end
                client:settimeout( 0 )  -- set nonblocking
                local res, err = client:connect( addr, serverport )  -- connect
                if res or ( err == "timeout" or err == "Operation already in progress" ) then
                        if client.getsockname then
                                addr = client:getsockname( )
-                       end
+               end
                        local interface = wrapclient( client, addr, serverport, listener, pattern, sslctx )
                        debug( "new connection id:", interface.id )
                        return interface, err
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;
index ee8a43dc7fa13482897a7bc3d10f52951b0e06d6..7523ec524353d66214392856cd926c2b68c446c3 100644 (file)
@@ -346,10 +346,9 @@ local function get_hosts_set(hosts, module)
        elseif type(hosts) == "string" then
                return set.new { hosts };
        elseif hosts == nil then
-               local mm = require "modulemanager";
                local hosts_set = set.new(array.collect(keys(prosody.hosts)))
-                       / function (host) return (prosody.hosts[host].type == "local" or module and mm.is_loaded(host, module)) and host or nil; end;
-               if module and mm.get_module("*", module) then
+                       / function (host) return (prosody.hosts[host].type == "local" or module and modulemanager.is_loaded(host, module)) and host or nil; end;
+               if module and modulemanager.get_module("*", module) then
                        hosts_set:add("*");
                end
                return hosts_set;
@@ -357,15 +356,13 @@ local function get_hosts_set(hosts, module)
 end
 
 function def_env.module:load(name, hosts, config)
-       local mm = require "modulemanager";
-
        hosts = get_hosts_set(hosts);
 
        -- Load the module for each host
        local ok, err, count, mod = true, nil, 0, nil;
        for host in hosts do
-               if (not mm.is_loaded(host, name)) then
-                       mod, err = mm.load(host, name, config);
+               if (not modulemanager.is_loaded(host, name)) then
+                       mod, err = modulemanager.load(host, name, config);
                        if not mod then
                                ok = false;
                                if err == "global-module-already-loaded" then
@@ -386,15 +383,13 @@ function def_env.module:load(name, hosts, config)
 end
 
 function def_env.module:unload(name, hosts)
-       local mm = require "modulemanager";
-
        hosts = get_hosts_set(hosts, name);
 
        -- Unload the module for each host
        local ok, err, count = true, nil, 0;
        for host in hosts do
-               if mm.is_loaded(host, name) then
-                       ok, err = mm.unload(host, name);
+               if modulemanager.is_loaded(host, name) then
+                       ok, err = modulemanager.unload(host, name);
                        if not ok then
                                ok = false;
                                self.session.print(err or "Unknown error unloading module");
@@ -408,8 +403,6 @@ function def_env.module:unload(name, hosts)
 end
 
 function def_env.module:reload(name, hosts)
-       local mm = require "modulemanager";
-
        hosts = array.collect(get_hosts_set(hosts, name)):sort(function (a, b)
                if a == "*" then return true
                elseif b == "*" then return false
@@ -419,8 +412,8 @@ function def_env.module:reload(name, hosts)
        -- Reload the module for each host
        local ok, err, count = true, nil, 0;
        for _, host in ipairs(hosts) do
-               if mm.is_loaded(host, name) then
-                       ok, err = mm.reload(host, name);
+               if modulemanager.is_loaded(host, name) then
+                       ok, err = modulemanager.reload(host, name);
                        if not ok then
                                ok = false;
                                self.session.print(err or "Unknown error reloading module");
index a67f3dbde964bb4a787a437327105bfaa0cb57a2..0a4491bff119a1fb824bfc8496d023e2dd3ebd57 100755 (executable)
@@ -244,7 +244,7 @@ end
 local modulemanager = require "core.modulemanager"
 
 local prosodyctl = require "util.prosodyctl"
-require "socket"
+local socket = require "socket"
 -----------------------
 
  -- FIXME: Duplicate code waiting for util.startup
index c00b2267e06bb5b53f69c6a9d64e68520227d008..35677095181fbf990c2c56a61527442e9009bcbf 100644 (file)
@@ -21,8 +21,8 @@
 #include "lua.h"
 #include "lauxlib.h"
 
-#if (LUA_VERSION_NUM == 502)
-#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0)
+#if (LUA_VERSION_NUM == 501)
+#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
 #endif
 
 /***************** BASE64 *****************/
@@ -530,19 +530,19 @@ LUALIB_API int luaopen_util_encodings(lua_State* L) {
        lua_newtable(L);
 
        lua_newtable(L);
-       luaL_register(L, NULL, Reg_base64);
+       luaL_setfuncs(L, Reg_base64, 0);
        lua_setfield(L, -2, "base64");
 
        lua_newtable(L);
-       luaL_register(L, NULL, Reg_stringprep);
+       luaL_setfuncs(L, Reg_stringprep, 0);
        lua_setfield(L, -2, "stringprep");
 
        lua_newtable(L);
-       luaL_register(L, NULL, Reg_idna);
+       luaL_setfuncs(L, Reg_idna, 0);
        lua_setfield(L, -2, "idna");
 
        lua_newtable(L);
-       luaL_register(L, NULL, Reg_utf8);
+       luaL_setfuncs(L, Reg_utf8, 0);
        lua_setfield(L, -2, "utf8");
 
        lua_pushliteral(L, "-3.14");
index a58a424d31a29f0e74b265db7391780e6422b07a..ecab2e328e892833d8d5780066e6afaf8c8f88c8 100644 (file)
@@ -27,8 +27,8 @@ typedef unsigned __int32 uint32_t;
 #include <openssl/sha.h>
 #include <openssl/md5.h>
 
-#if (LUA_VERSION_NUM == 502)
-#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0)
+#if (LUA_VERSION_NUM == 501)
+#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
 #endif
 
 #define HMAC_IPAD 0x36363636
@@ -213,7 +213,7 @@ static const luaL_Reg Reg[] = {
 
 LUALIB_API int luaopen_util_hashes(lua_State* L) {
        lua_newtable(L);
-       luaL_register(L, NULL, Reg);
+       luaL_setfuncs(L, Reg, 0);;
        lua_pushliteral(L, "-3.14");
        lua_setfield(L, -2, "version");
        return 1;
index ad09d04153d41d05bf5770a8b98dbe830d217517..3ccc7618e95dfbb1292f7f25e7b14a52cc1bc6cd 100644 (file)
@@ -26,8 +26,8 @@
 #include <lua.h>
 #include <lauxlib.h>
 
-#if (LUA_VERSION_NUM == 502)
-#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0)
+#if (LUA_VERSION_NUM == 501)
+#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
 #endif
 
 /* Enumerate all locally configured IP addresses */
@@ -131,6 +131,6 @@ int luaopen_util_net(lua_State* L) {
        };
 
        lua_newtable(L);
-       luaL_register(L, NULL,  exports);
+       luaL_setfuncs(L, exports, 0);
        return 1;
 }
index 5288b08cd03217e8c86db35cfa0c16a20027817c..02ea00871a7e2e3fea1c3df83bc01b8bff973c86 100644 (file)
@@ -35,8 +35,8 @@
 #include "lualib.h"
 #include "lauxlib.h"
 
-#if (LUA_VERSION_NUM == 502)
-#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0)
+#if (LUA_VERSION_NUM == 501)
+#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
 #endif
 
 #include <fcntl.h>
@@ -803,7 +803,7 @@ int luaopen_util_pposix(lua_State* L) {
        };
 
        lua_newtable(L);
-       luaL_register(L, NULL,  exports);
+       luaL_setfuncs(L, exports, 0);
 
        lua_pushliteral(L, "pposix");
        lua_setfield(L, -2, "_NAME");
index 1e988a2c59a606eab13f196322127473220dedc4..725555fa58ec7b79b9dd95f029871de2dc3b79dd 100644 (file)
@@ -32,8 +32,8 @@
 #include "lua.h"
 #include "lauxlib.h"
 
-#if (LUA_VERSION_NUM == 502)
-#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0)
+#if (LUA_VERSION_NUM == 501)
+#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
 #endif
 
 #ifndef lsig
@@ -388,7 +388,7 @@ int luaopen_util_signal(lua_State* L) {
 
        /* add the library */
        lua_newtable(L);
-       luaL_register(L, NULL, lsignal_lib);
+       luaL_setfuncs(L, lsignal_lib, 0);
 
        /* push lua_signals table into the registry */
        /* put the signals inside the library table too,
index aaa0740771098d62fa366579f8205db0b028356c..4fcbf21ea5bed5cfc72966584a24e3358d68c7ff 100644 (file)
@@ -19,8 +19,8 @@
 #include "lua.h"
 #include "lauxlib.h"
 
-#if (LUA_VERSION_NUM == 502)
-#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0)
+#if (LUA_VERSION_NUM == 501)
+#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
 #endif
 
 static int Lget_nameservers(lua_State* L) {
@@ -104,7 +104,7 @@ static const luaL_Reg Reg[] = {
 
 LUALIB_API int luaopen_util_windows(lua_State* L) {
        lua_newtable(L);
-       luaL_register(L, NULL, Reg);
+       luaL_setfuncs(L, Reg, 0);
        lua_pushliteral(L, "-3.14");
        lua_setfield(L, -2, "version");
        return 1;
index b10396b105e4613e329bcd621680ccfe2601a879..d4ab1771111cb543db105942892005177dbbd612 100644 (file)
@@ -169,7 +169,4 @@ for method, f in pairs(array_base) do
        end
 end
 
-_G.array = array;
-module("array");
-
 return array;
index 4723b912942e6606ccf59679e087c87c09b7597c..cd5ff9c0efdddfb6dd8fbb663a67e4464ec5acdd 100644 (file)
@@ -12,9 +12,9 @@ local sha1 = require "util.hashes".sha1;
 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 @@ function calculate_hash(disco_info)
        return ver, S;
 end
 
-return _M;
+return {
+       calculate_hash = calculate_hash;
+};
index 9f2693b1fc2eae20db3898a00520394391b91281..244fb3f31b3aff563c156012212058e53a4a1b59 100644 (file)
@@ -13,14 +13,14 @@ local t_concat = table.concat;
 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 @@ field_readers["hidden"] =
                return field_tag:get_child_text("value");
        end
 
-return _M;
+return {
+       new = new;
+};
 
 
 --[=[
index a107d95c26904a697a949157f8caa706ca46a696..4b722851233db27c4776469716a702e491e843bb 100644 (file)
@@ -43,7 +43,7 @@ pcall(function()
        fallocate = pposix.fallocate or fallocate;
 end);
 
-module "datamanager"
+local _ENV = nil;
 
 ---- utils -----
 local encode, decode;
@@ -74,7 +74,7 @@ local callbacks = {};
 
 ------- 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 @@ local function callback(username, host, datastore, data)
 
        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 @@ function remove_callback(func)
        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 @@ function getpath(username, host, datastore, ext, create)
        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 @@ if prosody and prosody.platform ~= "posix" then
        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 @@ function store(username, host, datastore, data)
        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 @@ function list_append(username, host, datastore, data)
        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 @@ function list_store(username, host, datastore, data)
        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 @@ local type_map = {
        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 @@ function users(host, store, typ)
        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 @@ local function do_remove(path)
        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 @@ function purge(username, host)
        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;
+};
index dd596527c4325c050d4d7c11eedb602cb3f272d3..27f28ace7eff560c5b3c7efc1caa0bbc880809e8 100644 (file)
@@ -15,25 +15,25 @@ local os_difftime = os.difftime;
 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 @@ function parse(s)
        end
 end
 
-return _M;
+return {
+       date     = date;
+       datetime = datetime;
+       time     = time;
+       legacy   = legacy;
+       parse    = parse;
+};
index 91f691e144b388d933b23126cf412f0ff7d8b2a4..a78524a9c1f148158d3f2cc85971f9ef96b5994c 100644 (file)
@@ -13,7 +13,7 @@ local termcolours = require "util.termcolours";
 local getstring = termcolours.getstring;
 local styles;
 do
-       _ = termcolours.getstyle;
+       local _ = termcolours.getstyle;
        styles = {
                boundary_padding = _("bright");
                filename         = _("bright", "blue");
@@ -22,9 +22,8 @@ do
                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 @@ function get_locals_table(thread, level)
        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 @@ function get_upvalues_table(func)
        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 @@ function string_from_var_table(var_table, max_line_len, indent_str)
        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 @@ function get_traceback_table(thread, start_level)
        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 @@ function _traceback(thread, message, level)
        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;
+};
index ea19d9a8b606b4f5cfa1d372b54d0f117035135c..5e3b03d833c63c8723b5853053a2cfed16439557 100644 (file)
@@ -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,11 +46,11 @@ package.preload["util.ztact"] = function ()
        end
 end;
 
-function check_dependencies()
-       if _VERSION ~= "Lua 5.1" then
+local function check_dependencies()
+       if _VERSION < "Lua 5.1" then
                print "***********************************"
                print("Unsupported Lua version: ".._VERSION);
-               print("Only Lua 5.1 is supported.");
+               print("At least Lua 5.1 is required.");
                print "***********************************"
                return false;
        end
@@ -137,13 +135,18 @@ function check_dependencies()
        return not fatal;
 end
 
-function log_warnings()
+local function log_warnings()
+       if _VERSION > "Lua 5.1" then
+               log("warn", "Support for %s is experimental, please report any issues", _VERSION);
+       end
+       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 +165,9 @@ function log_warnings()
        end
 end
 
-return _M;
+return {
+       softreq = softreq;
+       missingdep = missingdep;
+       check_dependencies = check_dependencies;
+       log_warnings = log_warnings;
+};
index d19da98b9165587659166ee2233b95f951fc9bf9..825ffb19b110f7e4d7e517d52fd34fbe6aaeb001 100644 (file)
@@ -14,9 +14,9 @@ local t_sort = table.sort;
 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 @@ function new()
        };
 end
 
-return _M;
+return {
+       new = new;
+};
index 427dcb7cafa14f8cf2f4818393ae9b8221ac6655..f405c0bdd91f70a47a51fa3e2a11d0cba8f93b97 100644 (file)
@@ -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 @@ function initialize(session)
        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 @@ function add_filter(session, type, callback, priority)
        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 @@ function remove_filter(session, type, callback)
        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 @@ function remove_filter_hook(callback)
        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;
+};
index 437a920c102371eb4130384e825af9a7fbabb25b..bf76d258d7237eaef4490f442bd490b69d2cafe9 100644 (file)
@@ -8,21 +8,11 @@
 
 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)
-       return log_events(prosody.hosts[host].events, host);
-end
-
-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 +27,19 @@ function log_events(events, name, logger)
        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 log_host_events(host)
+       return log_events(prosody.hosts[host].events, host);
+end
+
+local function revert_log_host_events(host)
+       return revert_log_events(prosody.hosts[host].events);
+end
+
+local function show_events(events, specific_event)
        local event_handlers = events._handlers;
        local events_array = {};
        local event_handler_arrays = {};
@@ -70,7 +68,7 @@ function show_events(events, specific_event)
        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 @@ function get_upvalue(f, get_name)
        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;
+};
index 27afab3e275e2de573e8b18f6211a7fbebfb5476..696f51d83ff5e2093f4f7b275ab1c1d70bb63e71 100644 (file)
@@ -23,9 +23,9 @@ local escapes = {
 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 @@ local function _split(jid)
        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 @@ local function _prepped_split(jid)
                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 @@ local function _join(node, host, resource)
        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 @@ function compare(jid, acl)
        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;
+};
index a8a58afcd12062267cf63414d905e9d6c75c75bc..becd295d55590e4757736c8a9cc1b4c16e7d834f 100644 (file)
@@ -13,7 +13,7 @@ local tostring, tonumber = tostring, tonumber;
 local pairs, ipairs = pairs, ipairs;
 local next = next;
 local error = error;
-local newproxy, getmetatable, setmetatable = newproxy, getmetatable, setmetatable;
+local getmetatable, setmetatable = getmetatable, setmetatable;
 local print = print;
 
 local has_array, array = pcall(require, "util.array");
@@ -22,10 +22,7 @@ local array_mt = has_array and getmetatable(array()) or {};
 --module("json")
 local json = {};
 
-local null = newproxy and newproxy(true) or {};
-if getmetatable and getmetatable(null) then
-       getmetatable(null).__tostring = function() return "null"; end;
-end
+local null = setmetatable({}, { __tostring = function() return "null"; end; });
 json.null = null;
 
 local escapes = {
index cd0769f9230fec3a7645088a5a1a959ad5470582..3d1f1c8bffc7c7aa971c63db10feda513819e5d2 100644 (file)
@@ -11,13 +11,13 @@ local pcall = pcall;
 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 @@ function make_logger(source_name, level)
        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 @@ function reset()
        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 @@ function add_level_sink(level, sink_function)
        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;
+};
index caf25118e3f622ecd66dbea06b5c24de7abba968..7a2d2b2a4224548977339e66fbb0c3cc4eca8631 100644 (file)
@@ -10,7 +10,7 @@ local select = select;
 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 @@ local function search_add(self, results, ...)
        return results;
 end
 
-function iter(self, ...)
+local function iter(self, ...)
        local query = { ... };
        local maxdepth = select("#", ...);
        local stack = { self.data };
@@ -161,7 +161,7 @@ function iter(self, ...)
        return it, self;
 end
 
-function new()
+local function new()
        return {
                data = {};
                get = get;
@@ -174,4 +174,7 @@ function new()
        };
 end
 
-return _M;
+return {
+       iter = iter;
+       new = new;
+};
index b9b3e207fa685ffbf38dbc4f474567fd7a81f6a8..0d7eafa7a154122d3af7242bac792349963794b6 100644 (file)
@@ -17,9 +17,7 @@ end
 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 @@ function load_file(names)
        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 @@ function load_resource(plugin, resource)
        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 @@ function load_code(plugin, resource, env)
        return f, path;
 end
 
-return _M;
+return {
+       load_file = load_file;
+       load_resource = load_resource;
+       load_code = load_code;
+};
index 9e30f8ea17094ac5cc5ddf04b28bb6985730d2a1..f8f2864412d48bd83dfd60b69c806e9cb287bfc5 100644 (file)
@@ -29,25 +29,19 @@ local CFG_SOURCEDIR = _G.CFG_SOURCEDIR;
 local _G = _G;
 local prosody = prosody;
 
-module "prosodyctl"
-
 -- UI helpers
-function show_message(msg, ...)
-       print(msg:format(...));
-end
-
-function show_warning(msg, ...)
+local function show_message(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 @@ function getchar(n)
        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 @@ function getpass()
        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 @@ function show_yesno(prompt)
        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 @@ function read_password()
        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 @@ function show_prompt(prompt)
 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 @@ function adduser(params)
 
        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 @@ function user_exists(params)
        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 @@ function deluser(params)
        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 @@ function getpid()
        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 @@ function isrunning()
        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,8 @@ function start()
        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
@@ -257,15 +251,15 @@ function stop()
                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.SIGTERM);
        return true;
 end
 
-function reload()
-       local ok, ret = _M.isrunning();
+local function reload()
+       local ok, ret = isrunning();
        if not ok then
                return ok, ret;
        end
@@ -273,11 +267,30 @@ function reload()
                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;
+};
index c15a41d7d059a8751485097253e913b56ff7f46f..6d12690aa8488ab4852a2ab12d5830e315012920 100644 (file)
@@ -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 @@ local default_node_config = { __index = {
        ["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 @@ function service:set_node_config(node, actor, new_config)
        return true;
 end
 
-return _M;
+return {
+       new = new;
+};
index b91e29a6cd51c4c8da4b54e8e4fec318f4c20488..5845f34a45e31cedfb20c07ec1592ef5ff833bdb 100644 (file)
@@ -19,7 +19,7 @@ local setmetatable = setmetatable;
 local assert = assert;
 local require = require;
 
-module "sasl"
+local _ENV = nil;
 
 --[[
 Authentication Backend Prototypes:
@@ -47,7 +47,7 @@ local backend_mechanism = {};
 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 @@ function registerMechanism(name, backends, f, cb_backends)
 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.anonymous" .init(registerMechanism);
 require "util.sasl.scram"     .init(registerMechanism);
 require "util.sasl.external"  .init(registerMechanism);
 
-return _M;
+return {
+       registerMechanism = registerMechanism;
+       new = new;
+};
index ca5fe4040d90f4350711c9e293c2c5ac8b7687ea..af05c0e738e4e16abde9df2c66bcffde2cba5c34 100644 (file)
@@ -16,7 +16,7 @@ local s_match = string.match;
 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 @@ local function anonymous(self, message)
        return "success"
 end
 
-function init(registerMechanism)
+local function init(registerMechanism)
        registerMechanism("ANONYMOUS", {"anonymous"}, anonymous);
 end
 
-return _M;
+return {
+       init = init;
+}
index 591d85371ace5db490cd90c5ab78b91d9f699709..695dd2a3ed3c2762fd6891f65b9f852d76492ab2 100644 (file)
@@ -25,7 +25,7 @@ local log = require "util.logger".init("sasl");
 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 @@ local function digest(self, message)
        end
 end
 
-function init(registerMechanism)
+local function init(registerMechanism)
        registerMechanism("DIGEST-MD5", {"plain"}, digest);
 end
 
-return _M;
+return {
+       init = init;
+}
index 4c5c4343b3b9c0aebf09ef102adf00e3d9e2455f..5ba90190eaff7a5072f7d0f1d6f97fe4b973cb53 100644 (file)
@@ -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 @@ local function external(self, message)
        return "success";
 end
 
-function init(registerMechanism)
+local function init(registerMechanism)
        registerMechanism("EXTERNAL", {"external"}, external);
 end
 
-return _M;
+return {
+       init = init;
+}
index c9ec2911797ecaacae50ac0e6f969adb062b5591..26e653354b479bc4e8b3c972ab770fff11e6bc63 100644 (file)
@@ -16,7 +16,7 @@ local saslprep = require "util.encodings".stringprep.saslprep;
 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 @@ local function plain(self, message)
        return "success";
 end
 
-function init(registerMechanism)
+local function init(registerMechanism)
        registerMechanism("PLAIN", {"plain", "plain_test"}, plain);
 end
 
-return _M;
+return {
+       init = init;
+}
index 0d2852bf8141d9d22c7fef8c38393378e5dfb487..a1b5117a7f2833d09d1427a5956b0c7f9f2efb9e 100644 (file)
@@ -25,7 +25,7 @@ local t_concat = table.concat;
 local char = string.char;
 local byte = string.byte;
 
-module "sasl.scram"
+local _ENV = nil;
 
 --=========================
 --SASL SCRAM-SHA-1 according to RFC 5802
@@ -87,7 +87,7 @@ local function hashprep(hashname)
        return hashname:lower():gsub("-", "_");
 end
 
-function getAuthenticationDatabaseSHA1(password, salt, iteration_count)
+local function getAuthenticationDatabaseSHA1(password, salt, iteration_count)
        if type(password) ~= "string" or type(salt) ~= "string" or type(iteration_count) ~= "number" then
                return false, "inappropriate argument types"
        end
@@ -235,7 +235,7 @@ local function scram_gen(hash_name, H_f, HMAC_f)
        return scram_hash;
 end
 
-function init(registerMechanism)
+local function init(registerMechanism)
        local function registerSCRAMMechanism(hash_name, hash, hmac_hash)
                registerMechanism("SCRAM-"..hash_name, {"plain", "scram_"..(hashprep(hash_name))}, scram_gen(hash_name:lower(), hash, hmac_hash));
 
@@ -246,4 +246,7 @@ function init(registerMechanism)
        registerSCRAMMechanism("SHA-1", sha1, hmac_sha1);
 end
 
-return _M;
+return {
+       getAuthenticationDatabaseSHA1 = getAuthenticationDatabaseSHA1;
+       init = init;
+}
index a0e8bd69d45c4dde830efd2881a3a55efcdaf1b1..4e9a4af5c72798db85b6f3bee69ed95e874a683f 100644 (file)
@@ -60,7 +60,7 @@ local sasl_errstring = {
 };
 setmetatable(sasl_errstring, { __index = function() return "undefined error!" end });
 
-module "sasl_cyrus"
+local _ENV = nil;
 
 local method = {};
 method.__index = method;
@@ -82,7 +82,7 @@ end
 --      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 @@ function method:process(message)
        end
 end
 
-return _M;
+return {
+       new = new;
+};
index 049011356cbbe0c9c892d89b9e79745df3d40a64..206f5fbbf59bda7766172dfb8cc6e3dceaf5c0a3 100644 (file)
@@ -20,7 +20,7 @@ local debug_traceback = debug.traceback;
 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 @@ local function _simplesave(o, ind, t, func)
        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 @@ function deserialize(str)
        return ret;
 end
 
-return _M;
+return {
+       append = append;
+       serialize = serialize;
+       deserialize = deserialize;
+};
index 4be39c1702da817cb2e2435c403233c9cad2240b..c136a522d3a272e1b7a08ec851708ad539a3ad89 100644 (file)
@@ -10,59 +10,19 @@ local ipairs, pairs, setmetatable, next, tostring =
       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 @@ function new(list)
        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 @@ function union(set1, set2)
        return set;
 end
 
-function difference(set1, set2)
+local function difference(set1, set2)
        local set = new();
        local items = set._items;
 
@@ -142,7 +102,7 @@ function difference(set1, set2)
        return set;
 end
 
-function intersection(set1, set2)
+local function intersection(set1, set2)
        local set = new();
        local items = set._items;
 
@@ -155,8 +115,55 @@ function intersection(set1, set2)
        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;
+};
index be34c3817d19bb299cb29c5b9a2584879e73f515..70e103dfb66d86e1077f31368b9265ce2da375e5 100644 (file)
@@ -13,7 +13,7 @@ local DBI = require "DBI";
 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 query_mt = {};
 --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 @@ function Table(definition)
        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 @@ function engine:set_encoding() -- to UTF-8
 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 @@ function db2uri(params)
        };
 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;
+};
index 42ce37d72045f94faad19af6c36851a3b9d77937..71f27c9460f6548ab816e843d8012ddef25425c1 100644 (file)
@@ -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 @@ finalisers.verifyext = finalisers.options;
 
 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 @@ local function protocol(a)
        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
index 82601e630986fc4376f22c714144bba267b27212..dc1600b02eb156d38475ebdc94db240f6b4487d3 100644 (file)
@@ -35,13 +35,12 @@ end
 
 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 @@ function stanza_mt:find(path)
 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 @@ function stanza_mt.get_error(stanza)
        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 @@ function preserialize(stanza)
        return s;
 end
 
-function deserialize(stanza)
+local function deserialize(stanza)
        -- Set metatable
        if stanza then
                local attr = stanza.attr;
@@ -337,51 +330,48 @@ function deserialize(stanza)
        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 @@ else
        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;
+};
index 66d4fca7ae9084b2a41a1d76c2dee4f662f82eb8..a26dd7ca6109eed096b4d307de5ef770a439bf48 100644 (file)
@@ -9,7 +9,7 @@ local debug = debug;
 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
index ef978364f93ff1ab35c1c348ed0d44d92d82188d..a1c01aa58517aa79f3cb685aa9b3480b3079fcd7 100644 (file)
@@ -19,7 +19,7 @@ if os.getenv("WINDIR") then
 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 cssmap = {
 };
 
 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 @@ function getstring(style, text)
        end
 end
 
-function getstyle(...)
+local function getstyle(...)
        local styles, result = { ... }, {};
        for i, style in ipairs(styles) do
                style = stylemap[style];
@@ -65,7 +65,7 @@ function getstyle(...)
 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 @@ local function ansi2css(ansi_codes)
        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;
+};
index 55e1d07b3f5a836b450fc65cf23a1c31b7363e49..3d3f5d2d8b029f9134de0276620411b06390abac 100644 (file)
@@ -3,7 +3,7 @@ local gettime = require "socket".gettime;
 local setmetatable = setmetatable;
 local floor = math.floor;
 
-module "throttle"
+local _ENV = nil;
 
 local throttle = {};
 local throttle_mt = { __index = throttle };
@@ -39,8 +39,10 @@ function throttle:poll(cost, split)
        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;
+};
index 0ec9758588560885364696fa4089a2a56fc1f013..7ac4b616dd4a1222c819e138537fad0903f53797 100644 (file)
@@ -15,10 +15,9 @@ local debug_traceback = debug.traceback;
 local tostring = tostring;
 local xpcall = xpcall;
 
-module "timer"
+local _ENV = nil;
 
 local _add_task = server.add_task;
---add_task = _add_task;
 
 local h = indexedbheap.create();
 local params = {};
@@ -41,15 +40,15 @@ local function _on_timer(now)
                if success and type(err) == "number" then
                        h:insert(_callback, err + now, _id); -- re-add
                        params[_id] = _param;
+                       end
                end
-       end
        next_time = peek;
        if peek ~= nil then
                return peek - now;
        end
 end
-function add_task(delay, callback, param)
-       local current_time = get_time();
+local function add_task(delay, callback, param)
+               local current_time = get_time();
        local event_time = current_time + delay;
 
        local id = h:insert(callback, event_time);
@@ -57,22 +56,27 @@ function add_task(delay, callback, param)
        if next_time == nil or event_time < next_time then
                next_time = event_time;
                _add_task(next_time - current_time, _on_timer);
-       end
+                               end
        return id;
-end
-function stop(id)
+                       end
+local function stop(id)
        params[id] = nil;
        return h:remove(id);
-end
-function reschedule(id, delay)
+               end
+local function reschedule(id, delay)
        local current_time = get_time();
        local event_time = current_time + delay;
        h:reprioritize(id, delay);
        if next_time == nil or event_time < next_time then
                next_time = event_time;
                _add_task(next_time - current_time, _on_timer);
-       end
+                       end
        return id;
 end
 
-return _M;
+return {
+       add_task = add_task;
+       stop = stop;
+       reschedule = reschedule;
+};
+
index bcb2e274dd609935b9613b4c63dbc7db352ea980..aa8c6486781a51de97f96b4a9c7bf7fd4018b0f0 100644 (file)
@@ -2,12 +2,12 @@ local timer = require "util.timer";
 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 @@ function watchdog_methods:cancel()
        self.last_reset = nil;
 end
 
-return _M;
+return {
+       new = new;
+};
index bf8d390661da35459434b16cee2b063b7849d8eb..f228b20130316e21e76f96b4e44d62dc9d2c0ebc 100644 (file)
@@ -24,7 +24,7 @@ local base64 = require "util.encodings".base64;
 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 @@ local function compare_srvname(host, service, asserted_names)
        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 @@ end
 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 @@ end
 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;
+};
index 88ccedde40ca4b8a44ab3048a2a60b4f199ccfba..733d821ad7c8b87dc93d7e4a0b3ab2cfa030fd85 100644 (file)
@@ -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 @@ local parse_xml = (function()
        end;
 end)();
 
-parse = parse_xml;
-return _M;
+return {
+       parse = parse_xml;
+};
index dede0da94d7b5b60e0d5185ad906c46a105286bf..7be63285dfdb48c8d219cab5190e930ffdaa6b9d 100644 (file)
@@ -24,7 +24,7 @@ local lxp_supports_bytecount = not not lxp.new({}).getcurrentbytecount;
 
 local default_stanza_size_limit = 1024*1024*10; -- 10MB
 
-module "xmppstream"
+local _ENV = nil;
 
 local new_parser = lxp.new;
 
@@ -40,12 +40,9 @@ local xmlns_streams = "http://etherx.jabber.org/streams";
 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 @@ function new_sax_handlers(session, stream_callbacks, cb_handleprogress)
        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 @@ function new(session, stream_callbacks, stanza_size_limit)
        };
 end
 
-return _M;
+return {
+       ns_separator = ns_separator;
+       ns_pattern = ns_pattern;
+       new_sax_handlers = new_sax_handlers;
+       new = new;
+};