Changeset

8153:c22d5680ca68

configmanager: Remove support for multiple parsers, fixes #852.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 27 May 2017 15:32:28 +0100
parents 8150:4720f5ec4171
children 8157:4947e84f2e5b
files core/configmanager.lua prosody prosodyctl
diffstat 3 files changed, 8 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/core/configmanager.lua	Sat May 20 15:00:50 2017 +0200
+++ b/core/configmanager.lua	Sat May 27 15:32:28 2017 +0100
@@ -27,7 +27,7 @@
 
 _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,11 +77,11 @@
 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;
@@ -103,26 +103,11 @@
 	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({
@@ -211,7 +196,7 @@
 			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
--- a/prosody	Sat May 20 15:00:50 2017 +0200
+++ b/prosody	Sat May 27 15:32:28 2017 +0100
@@ -76,9 +76,7 @@
 	elseif os.getenv("PROSODY_CONFIG") then -- Passed by prosodyctl
 			table.insert(filenames, os.getenv("PROSODY_CONFIG"));
 	else
-		for _, format in ipairs(config.parsers()) do
-			table.insert(filenames, (CFG_CONFIGDIR or ".").."/prosody.cfg."..format);
-		end
+		table.insert(filenames, (CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
 	end
 	for _,_filename in ipairs(filenames) do
 		filename = _filename;
--- a/prosodyctl	Sat May 20 15:00:50 2017 +0200
+++ b/prosodyctl	Sat May 27 15:32:28 2017 +0100
@@ -74,9 +74,7 @@
 		end
 		table.remove(arg, 1); table.remove(arg, 1);
 	else
-		for _, format in ipairs(config.parsers()) do
-			table.insert(filenames, (CFG_CONFIGDIR or ".").."/prosody.cfg."..format);
-		end
+		table.insert(filenames, (CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
 	end
 	for _,_filename in ipairs(filenames) do
 		filename = _filename;