mod_*: Fix a load of global accesses

Wed, 22 Apr 2009 21:32:23 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 22 Apr 2009 21:32:23 +0100
changeset 1042
a3d77353c18a
parent 1041
07835534d996
child 1043
ad87f555b484

mod_*: Fix a load of global accesses

plugins/mod_bosh.lua file | annotate | diff | comparison | revisions
plugins/mod_component.lua file | annotate | diff | comparison | revisions
plugins/mod_console.lua file | annotate | diff | comparison | revisions
plugins/mod_dialback.lua file | annotate | diff | comparison | revisions
plugins/mod_legacyauth.lua file | annotate | diff | comparison | revisions
plugins/mod_muc.lua file | annotate | diff | comparison | revisions
plugins/mod_posix.lua file | annotate | diff | comparison | revisions
plugins/mod_register.lua file | annotate | diff | comparison | revisions
plugins/mod_saslauth.lua file | annotate | diff | comparison | revisions
plugins/mod_vcard.lua file | annotate | diff | comparison | revisions
--- a/plugins/mod_bosh.lua	Wed Apr 22 20:52:27 2009 +0100
+++ b/plugins/mod_bosh.lua	Wed Apr 22 21:32:23 2009 +0100
@@ -1,6 +1,7 @@
 
 module.host = "*" -- Global module
 
+local hosts = _G.hosts;
 local lxp = require "lxp";
 local init_xmlhandlers = require "core.xmlhandlers"
 local server = require "net.server";
--- a/plugins/mod_component.lua	Wed Apr 22 20:52:27 2009 +0100
+++ b/plugins/mod_component.lua	Wed Apr 22 21:32:23 2009 +0100
@@ -10,14 +10,19 @@
 	error("Don't load mod_component manually, it should be for a component, please see http://prosody.im/doc/components", 0);
 end
 
+local hosts = _G.hosts;
+
 local t_concat = table.concat;
 
+local lxp = require "lxp";
+local logger = require "util.logger";
+local config = require "core.configmanager";
 local connlisteners = require "net.connlisteners";
 local cm_register_component = require "core.componentmanager".register_component;
 local cm_deregister_component = require "core.componentmanager".deregister_component;
 local uuid_gen = require "util.uuid".generate;
 local sha1 = require "util.hashes".sha1;
-local st = stanza;
+local st = require "util.stanza";
 local init_xmlhandlers = require "core.xmlhandlers";
 
 local sessions = {};
@@ -211,8 +216,8 @@
 
 module:add_event_hook("server-started", 
 	function ()
-		if net_activate_ports then
-			net_activate_ports("component", "component", {5437}, "tcp");
+		if _G.net_activate_ports then
+			_G.net_activate_ports("component", "component", {5437}, "tcp");
 		else
 			error("No net_activate_ports: Using an incompatible version of Prosody?");
 		end
--- a/plugins/mod_console.lua	Wed Apr 22 20:52:27 2009 +0100
+++ b/plugins/mod_console.lua	Wed Apr 22 21:32:23 2009 +0100
@@ -8,6 +8,7 @@
 
 module.host = "*";
 
+local hosts = _G.hosts;
 local connlisteners_register = require "net.connlisteners".register;
 
 local console_listener = { default_port = 5582; default_mode = "*l"; };
--- a/plugins/mod_dialback.lua	Wed Apr 22 20:52:27 2009 +0100
+++ b/plugins/mod_dialback.lua	Wed Apr 22 21:32:23 2009 +0100
@@ -7,7 +7,7 @@
 --
 
 
-
+local hosts = _G.hosts;
 local send_s2s = require "core.s2smanager".send_to_host;
 local s2s_make_authenticated = require "core.s2smanager".make_authenticated;
 local s2s_verify_dialback = require "core.s2smanager".verify_dialback;
--- a/plugins/mod_legacyauth.lua	Wed Apr 22 20:52:27 2009 +0100
+++ b/plugins/mod_legacyauth.lua	Wed Apr 22 21:32:23 2009 +0100
@@ -11,6 +11,9 @@
 local st = require "util.stanza";
 local t_concat = table.concat;
 
+local sessionmanager = require "core.sessionmanager";
+local usermanager = require "core.usermanager";
+
 module:add_feature("jabber:iq:auth");
 module:add_event_hook("stream-features", function (session, features)
 	if not session.username then features:tag("auth", {xmlns='http://jabber.org/features/iq-auth'}):up(); end
--- a/plugins/mod_muc.lua	Wed Apr 22 20:52:27 2009 +0100
+++ b/plugins/mod_muc.lua	Wed Apr 22 21:32:23 2009 +0100
@@ -6,6 +6,8 @@
 -- COPYING file in the source package for more information.
 --
 
+local datamanager = require "util.datamanager";
+local datetime = require "util.datetime";
 
 local register_component = require "core.componentmanager".register_component;
 local deregister_component = require "core.componentmanager".deregister_component;
--- a/plugins/mod_posix.lua	Wed Apr 22 20:52:27 2009 +0100
+++ b/plugins/mod_posix.lua	Wed Apr 22 21:32:23 2009 +0100
@@ -6,7 +6,7 @@
 
 local signal = select(2, pcall(require, "util.signal"));
 if type(signal) == "string" then
-	log("warn", "Couldn't load signal library, won't respond to SIGTERM");
+	module:log("warn", "Couldn't load signal library, won't respond to SIGTERM");
 end
 
 local config_get = require "core.configmanager".get;
@@ -18,7 +18,7 @@
 
 local function remove_pidfile()
 	if pidfile_written then
-		os.remove(pidfile);
+		os.remove(pidfile_written);
 		pidfile_written = nil;
 	end
 end
@@ -27,11 +27,11 @@
 	if pidfile_written then
 		remove_pidfile();
 	end
-	local pidfile = config.get("*", "core", "pidfile");
+	local pidfile = config_get("*", "core", "pidfile");
 	if pidfile then
 		local pf, err = io.open(pidfile, "w+");
 		if not pf then
-			log("error", "Couldn't write pidfile; %s", err);
+			module:log("error", "Couldn't write pidfile; %s", err);
 		else
 			pf:write(tostring(pposix.getpid()));
 			pf:close();
@@ -62,11 +62,11 @@
 	local function daemonize_server()
 		local ok, ret = pposix.daemonize();
 		if not ok then
-			log("error", "Failed to daemonize: %s", ret);
+			module:log("error", "Failed to daemonize: %s", ret);
 		elseif ret and ret > 0 then
 			os.exit(0);
 		else
-			log("info", "Successfully daemonized to PID %d", pposix.getpid());
+			module:log("info", "Successfully daemonized to PID %d", pposix.getpid());
 			write_pidfile();
 		end
 	end
@@ -81,13 +81,13 @@
 -- Set signal handler
 if signal.signal then
 	signal.signal("SIGTERM", function ()
-		log("warn", "Received SIGTERM...");
-		unlock_globals();
-		if prosody_shutdown then
-			prosody_shutdown("Received SIGTERM");
+		module:log("warn", "Received SIGTERM...");
+		_G.unlock_globals();
+		if _G.prosody_shutdown then
+			_G.prosody_shutdown("Received SIGTERM");
 		else
-			log("warn", "...no prosody_shutdown(), ignoring.");
+			module:log("warn", "...no prosody_shutdown(), ignoring.");
 		end
-		lock_globals();
+		_G.lock_globals();
 	end);
 end
--- a/plugins/mod_register.lua	Wed Apr 22 20:52:27 2009 +0100
+++ b/plugins/mod_register.lua	Wed Apr 22 21:32:23 2009 +0100
@@ -7,8 +7,10 @@
 --
 
 
-
+local hosts = _G.hosts;
 local st = require "util.stanza";
+local config = require "core.configmanager";
+local datamanager = require "util.datamanager";
 local usermanager_user_exists = require "core.usermanager".user_exists;
 local usermanager_create_user = require "core.usermanager".create_user;
 local datamanager_store = require "util.datamanager".store;
--- a/plugins/mod_saslauth.lua	Wed Apr 22 20:52:27 2009 +0100
+++ b/plugins/mod_saslauth.lua	Wed Apr 22 21:32:23 2009 +0100
@@ -10,8 +10,10 @@
 
 local st = require "util.stanza";
 local sm_bind_resource = require "core.sessionmanager".bind_resource;
+local sm_make_authenticated = require "core.sessionmanager".make_authenticated;
 local base64 = require "util.encodings".base64;
 
+local datamanager_load = require "util.datamanager".load;
 local usermanager_validate_credentials = require "core.usermanager".validate_credentials;
 local t_concat, t_insert = table.concat, table.insert;
 local tostring = tostring;
@@ -49,14 +51,14 @@
 		session.sasl_handler = nil;
 	elseif status == "success" then
 		if not session.sasl_handler.username then error("SASL succeeded but we didn't get a username!"); end -- TODO move this to sessionmanager
-		sessionmanager.make_authenticated(session, session.sasl_handler.username);
+		sm_make_authenticated(session, session.sasl_handler.username);
 		session.sasl_handler = nil;
 		session:reset_stream();
 	end
 end
 
 local function password_callback(node, host, mechanism, decoder)
-	local password = (datamanager.load(node, host, "accounts") or {}).password; -- FIXME handle hashed passwords
+	local password = (datamanager_load(node, host, "accounts") or {}).password; -- FIXME handle hashed passwords
 	local func = function(x) return x; end;
 	if password then
 		if mechanism == "PLAIN" then
--- a/plugins/mod_vcard.lua	Wed Apr 22 20:52:27 2009 +0100
+++ b/plugins/mod_vcard.lua	Wed Apr 22 21:32:23 2009 +0100
@@ -8,13 +8,13 @@
 
 
 
-require "util.datamanager"
-local datamanager = datamanager;
+local hosts = _G.hosts;
+local datamanager = require "util.datamanager"
 
 local st = require "util.stanza"
 local t_concat, t_insert = table.concat, table.insert;
 
-require "util.jid"
+local jid = require "util.jid"
 local jid_split = jid.split;
 
 module:add_feature("vcard-temp");

mercurial