aboutsummaryrefslogtreecommitdiffstats
path: root/core/configmanager.lua
diff options
context:
space:
mode:
Diffstat (limited to 'core/configmanager.lua')
-rw-r--r--core/configmanager.lua42
1 files changed, 12 insertions, 30 deletions
diff --git a/core/configmanager.lua b/core/configmanager.lua
index 5a544375..1e67da9b 100644
--- a/core/configmanager.lua
+++ b/core/configmanager.lua
@@ -7,12 +7,10 @@
--
local _G = _G;
-local setmetatable, rawget, rawset, io, error, dofile, type, pairs, table =
- setmetatable, rawget, rawset, io, error, dofile, type, pairs, table;
+local setmetatable, rawget, rawset, io, os, error, dofile, type, pairs =
+ setmetatable, rawget, rawset, io, os, error, dofile, type, pairs;
local format, math_max = string.format, math.max;
-local fire_event = prosody and prosody.events.fire_event or function () end;
-
local envload = require"util.envload".envload;
local deps = require"util.dependencies";
local resolve_relative_path = require"util.paths".resolve_relative_path;
@@ -24,10 +22,11 @@ local nameprep = encodings and encodings.stringprep.nameprep or function (host)
local _M = {};
local _ENV = nil;
+-- luacheck: std none
_M.resolve_relative_path = resolve_relative_path; -- COMPAT
-local parsers = {};
+local parser = nil;
local config_mt = { __index = function (t, _) return rawget(t, "*"); end};
local config = setmetatable({ ["*"] = { } }, config_mt);
@@ -77,19 +76,14 @@ end
function _M.load(filename, config_format)
config_format = config_format or filename:match("%w+$");
- if parsers[config_format] and parsers[config_format].load then
+ if config_format == "lua" then
local f, err = io.open(filename);
if f then
local new_config = setmetatable({ ["*"] = { } }, config_mt);
- local ok, err = parsers[config_format].load(f:read("*a"), filename, new_config);
+ local ok, err = parser.load(f:read("*a"), filename, new_config);
f:close();
if ok then
config = new_config;
- fire_event("config-reloaded", {
- filename = filename,
- format = config_format,
- config = config
- });
end
return ok, "parser", err;
end
@@ -103,26 +97,11 @@ function _M.load(filename, config_format)
end
end
-function _M.addparser(config_format, parser)
- if config_format and parser then
- parsers[config_format] = parser;
- end
-end
-
--- _M needed to avoid name clash with local 'parsers'
-function _M.parsers()
- local p = {};
- for config_format in pairs(parsers) do
- table.insert(p, config_format);
- end
- return p;
-end
-
-- Built-in Lua parser
do
local pcall = _G.pcall;
- parsers.lua = {};
- function parsers.lua.load(data, config_file, config_table)
+ parser = {};
+ function parser.load(data, config_file, config_table)
local env;
-- The ' = true' are needed so as not to set off __newindex when we assign the functions below
env = setmetatable({
@@ -130,6 +109,9 @@ do
Component = true, component = true,
Include = true, include = true, RunScript = true }, {
__index = function (_, k)
+ if k:match("^ENV_") then
+ return os.getenv(k:sub(5));
+ end
return rawget(_G, k);
end,
__newindex = function (_, k, v)
@@ -211,7 +193,7 @@ do
file = resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), file);
local f, err = io.open(file);
if f then
- local ret, err = parsers.lua.load(f:read("*a"), file, config_table);
+ local ret, err = parser.load(f:read("*a"), file, config_table);
if not ret then error(err:gsub("%[string.-%]", file), 0); end
end
if not f then error("Error loading included "..file..": "..err, 0); end