util/startup.lua
changeset 8641 f8f45bbbd8ba
parent 8640 c8368c7c81a1
child 8642 070a77c15f63
equal deleted inserted replaced
8640:c8368c7c81a1 8641:f8f45bbbd8ba
       
     1 -- Ignore the CFG_* variables
       
     2 -- luacheck: ignore 113/CFG_CONFIGDIR 113/CFG_SOURCEDIR 113/CFG_DATADIR 113/CFG_PLUGINDIR
     1 local startup = {};
     3 local startup = {};
     2 
     4 
     3 local prosody = { events = require "util.events".new() };
     5 local prosody = { events = require "util.events".new() };
     4 
     6 
     5 local config = require "core.configmanager";
     7 local config = require "core.configmanager";
    25 		filename = _filename;
    27 		filename = _filename;
    26 		local file = io.open(filename);
    28 		local file = io.open(filename);
    27 		if file then
    29 		if file then
    28 			file:close();
    30 			file:close();
    29 			prosody.config_file = filename;
    31 			prosody.config_file = filename;
    30 			CFG_CONFIGDIR = filename:match("^(.*)[\\/][^\\/]*$");
    32 			CFG_CONFIGDIR = filename:match("^(.*)[\\/][^\\/]*$"); -- luacheck: ignore 111
    31 			break;
    33 			break;
    32 		end
    34 		end
    33 	end
    35 	end
    34 	prosody.config_file = filename
    36 	prosody.config_file = filename
    35 	local ok, level, err = config.load(filename);
    37 	local ok, level, err = config.load(filename);
   112 		local name, env = debug.getupvalue(debug.getinfo(f or 1).func, 1);
   114 		local name, env = debug.getupvalue(debug.getinfo(f or 1).func, 1);
   113 		if name == "_ENV" then
   115 		if name == "_ENV" then
   114 			return env;
   116 			return env;
   115 		end
   117 		end
   116 	end
   118 	end
   117 	function require(...)
   119 	function require(...) -- luacheck: ignore 121
   118 		local curr_env = getfenv(2);
   120 		local curr_env = getfenv(2);
   119 		local curr_env_mt = getmetatable(curr_env);
   121 		local curr_env_mt = getmetatable(curr_env);
   120 		local _realG_mt = getmetatable(_realG);
   122 		local _realG_mt = getmetatable(_realG);
   121 		if curr_env_mt and curr_env_mt.__index and not curr_env_mt.__newindex and _realG_mt then
   123 		if curr_env_mt and curr_env_mt.__index and not curr_env_mt.__newindex and _realG_mt then
   122 			local old_newindex, old_index;
   124 			local old_newindex, old_index;
   182 		require "lfs".chdir(data_path);
   184 		require "lfs".chdir(data_path);
   183 	end
   185 	end
   184 end
   186 end
   185 
   187 
   186 function startup.init_global_state()
   188 function startup.init_global_state()
       
   189 	-- luacheck: ignore 121
   187 	prosody.bare_sessions = {};
   190 	prosody.bare_sessions = {};
   188 	prosody.full_sessions = {};
   191 	prosody.full_sessions = {};
   189 	prosody.hosts = {};
   192 	prosody.hosts = {};
   190 
   193 
   191 	-- COMPAT: These globals are deprecated
   194 	-- COMPAT: These globals are deprecated
   197 	local data_path = config.get("*", "data_path") or CFG_DATADIR or "data";
   200 	local data_path = config.get("*", "data_path") or CFG_DATADIR or "data";
   198 	local custom_plugin_paths = config.get("*", "plugin_paths");
   201 	local custom_plugin_paths = config.get("*", "plugin_paths");
   199 	if custom_plugin_paths then
   202 	if custom_plugin_paths then
   200 		local path_sep = package.config:sub(3,3);
   203 		local path_sep = package.config:sub(3,3);
   201 		-- path1;path2;path3;defaultpath...
   204 		-- path1;path2;path3;defaultpath...
       
   205 		-- luacheck: ignore 111
   202 		CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins");
   206 		CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins");
   203 	end
   207 	end
   204 	prosody.paths = { source = CFG_SOURCEDIR, config = CFG_CONFIGDIR or ".",
   208 	prosody.paths = { source = CFG_SOURCEDIR, config = CFG_CONFIGDIR or ".",
   205 	                  plugins = CFG_PLUGINDIR or "plugins", data = data_path };
   209 	                  plugins = CFG_PLUGINDIR or "plugins", data = data_path };
   206 
   210 
   457 
   461 
   458 function startup.make_dummy_hosts()
   462 function startup.make_dummy_hosts()
   459 	-- When running under prosodyctl, we don't want to
   463 	-- When running under prosodyctl, we don't want to
   460 	-- fully initialize the server, so we populate prosody.hosts
   464 	-- fully initialize the server, so we populate prosody.hosts
   461 	-- with just enough things for most code to work correctly
   465 	-- with just enough things for most code to work correctly
       
   466 	-- luacheck: ignore 122/hosts
   462 	prosody.core_post_stanza = function () end; -- TODO: mod_router!
   467 	prosody.core_post_stanza = function () end; -- TODO: mod_router!
   463 	local function make_host(hostname)
   468 	local function make_host(hostname)
   464 		return {
   469 		return {
   465 			type = "local",
   470 			type = "local",
   466 			events = prosody.events,
   471 			events = prosody.events,