Changeset

7982:e30b0cbed472

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Thu, 16 Mar 2017 23:49:27 +0100
parents 7974:547f000941cf (current diff) 7981:bbb900cfcfa5 (diff)
children 7984:ae3c5abb3336
files core/moduleapi.lua plugins/mod_admin_telnet.lua plugins/mod_pubsub/mod_pubsub.lua
diffstat 10 files changed, 35 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/.luacheckrc	Sun Mar 12 12:52:55 2017 +0100
+++ b/.luacheckrc	Thu Mar 16 23:49:27 2017 +0100
@@ -48,6 +48,7 @@
 		"module.get_option_inherited_set",
 		"module.get_option_number",
 		"module.get_option_path",
+		"module.get_option_scalar",
 		"module.get_option_set",
 		"module.get_option_string",
 		"module.handle_items",
--- a/core/moduleapi.lua	Sun Mar 12 12:52:55 2017 +0100
+++ b/core/moduleapi.lua	Thu Mar 16 23:49:27 2017 +0100
@@ -214,7 +214,7 @@
 	return value;
 end
 
-function api:get_option_string(name, default_value)
+function api:get_option_scalar(name, default_value)
 	local value = self:get_option(name, default_value);
 	if type(value) == "table" then
 		if #value > 1 then
@@ -222,6 +222,11 @@
 		end
 		value = value[1];
 	end
+	return value;
+end
+
+function api:get_option_string(name, default_value)
+	local value = self:get_option_scalar(name, default_value);
 	if value == nil then
 		return nil;
 	end
@@ -229,13 +234,7 @@
 end
 
 function api:get_option_number(name, ...)
-	local value = self:get_option(name, ...);
-	if type(value) == "table" then
-		if #value > 1 then
-			self:log("error", "Config option '%s' does not take a list, using just the first item", name);
-		end
-		value = value[1];
-	end
+	local value = self:get_option_scalar(name, ...);
 	local ret = tonumber(value);
 	if value ~= nil and ret == nil then
 		self:log("error", "Config option '%s' not understood, expecting a number", name);
@@ -244,13 +243,7 @@
 end
 
 function api:get_option_boolean(name, ...)
-	local value = self:get_option(name, ...);
-	if type(value) == "table" then
-		if #value > 1 then
-			self:log("error", "Config option '%s' does not take a list, using just the first item", name);
-		end
-		value = value[1];
-	end
+	local value = self:get_option_scalar(name, ...);
 	if value == nil then
 		return nil;
 	end
--- a/plugins/mod_admin_telnet.lua	Sun Mar 12 12:52:55 2017 +0100
+++ b/plugins/mod_admin_telnet.lua	Thu Mar 16 23:49:27 2017 +0100
@@ -1148,7 +1148,7 @@
 	for host in pairs(prosody.hosts) do
 		local http_apps = modulemanager.get_items("http-provider", host);
 		if #http_apps > 0 then
-			local http_host = module:context(host):get_option("http_host");
+			local http_host = module:context(host):get_option_string("http_host");
 			print("HTTP endpoints on "..host..(http_host and (" (using "..http_host.."):") or ":"));
 			for _, provider in ipairs(http_apps) do
 				local url = module:context(host):http_url(provider.name);
@@ -1158,7 +1158,7 @@
 		end
 	end
 
-	local default_host = module:get_option("http_default_host");
+	local default_host = module:get_option_string("http_default_host");
 	if not default_host then
 		print("HTTP requests to unknown hosts will return 404 Not Found");
 	else
--- a/plugins/mod_disco.lua	Sun Mar 12 12:52:55 2017 +0100
+++ b/plugins/mod_disco.lua	Thu Mar 16 23:49:27 2017 +0100
@@ -13,7 +13,7 @@
 local st = require "util.stanza"
 local calculate_hash = require "util.caps".calculate_hash;
 
-local disco_items = module:get_option("disco_items") or {};
+local disco_items = module:get_option_array("disco_items", {})
 do -- validate disco_items
 	for _, item in ipairs(disco_items) do
 		local err;
--- a/plugins/mod_http_files.lua	Sun Mar 12 12:52:55 2017 +0100
+++ b/plugins/mod_http_files.lua	Thu Mar 16 23:49:27 2017 +0100
@@ -19,7 +19,7 @@
 local base_path = module:get_option_string("http_files_dir", module:get_option_string("http_path"));
 local cache_size = module:get_option_number("http_files_cache_size", 128);
 local cache_max_file_size = module:get_option_number("http_files_cache_max_file_size", 4096);
-local dir_indices = module:get_option("http_index_files", { "index.html", "index.htm" });
+local dir_indices = module:get_option_array("http_index_files", { "index.html", "index.htm" });
 local directory_index = module:get_option_boolean("http_dir_listing");
 
 local mime_map = module:shared("/*/http_files/mime").types;
@@ -37,7 +37,7 @@
 	};
 	module:shared("/*/http_files/mime").types = mime_map;
 
-	local mime_types, err = open(module:get_option_string("mime_types_file", "/etc/mime.types"),"r");
+	local mime_types, err = open(module:get_option_path("mime_types_file", "/etc/mime.types", prosody.paths.config), "r");
 	if mime_types then
 		local mime_data = mime_types:read("*a");
 		mime_types:close();
--- a/plugins/mod_mam/mamprefs.lib.lua	Sun Mar 12 12:52:55 2017 +0100
+++ b/plugins/mod_mam/mamprefs.lib.lua	Thu Mar 16 23:49:27 2017 +0100
@@ -10,7 +10,10 @@
 --
 -- luacheck: ignore 122/prosody
 
-local global_default_policy = module:get_option("default_archive_policy", true);
+local global_default_policy = module:get_option_string("default_archive_policy", true);
+if global_default_policy ~= "roster" then
+	global_default_policy = module:get_option_boolean("default_archive_policy", global_default_policy);
+end
 
 do
 	-- luacheck: ignore 211/prefs_format
--- a/plugins/mod_mam/mod_mam.lua	Sun Mar 12 12:52:55 2017 +0100
+++ b/plugins/mod_mam/mod_mam.lua	Thu Mar 16 23:49:27 2017 +0100
@@ -35,7 +35,7 @@
 local m_min = math.min;
 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse;
 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50);
-local global_default_policy = module:get_option("default_archive_policy", true);
+local global_default_policy = module:get_option_string("default_archive_policy", true);
 if global_default_policy ~= "roster" then
 	global_default_policy = module:get_option_boolean("default_archive_policy", global_default_policy);
 end
--- a/plugins/mod_pubsub/mod_pubsub.lua	Sun Mar 12 12:52:55 2017 +0100
+++ b/plugins/mod_pubsub/mod_pubsub.lua	Thu Mar 16 23:49:27 2017 +0100
@@ -9,8 +9,7 @@
 
 local autocreate_on_publish = module:get_option_boolean("autocreate_on_publish", false);
 local autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe", false);
-local pubsub_disco_name = module:get_option("name");
-if type(pubsub_disco_name) ~= "string" then pubsub_disco_name = "Prosody PubSub Service"; end
+local pubsub_disco_name = module:get_option_string("name" "Prosody PubSub Service");
 local expose_publisher = module:get_option_boolean("expose_publisher", false)
 
 local service;
--- a/plugins/mod_version.lua	Sun Mar 12 12:52:55 2017 +0100
+++ b/plugins/mod_version.lua	Thu Mar 16 23:49:27 2017 +0100
@@ -16,11 +16,11 @@
 	:tag("name"):text("Prosody"):up()
 	:tag("version"):text(prosody.version):up();
 
-if not module:get_option("hide_os_type") then
+if not module:get_option_boolean("hide_os_type") then
 	if os.getenv("WINDIR") then
 		version = "Windows";
 	else
-		local os_version_command = module:get_option("os_version_command");
+		local os_version_command = module:get_option_string("os_version_command");
 		local ok, pposix = pcall(require, "util.pposix");
 		if not os_version_command and (ok and pposix and pposix.uname) then
 			version = pposix.uname().sysname;
--- a/util/array.lua	Sun Mar 12 12:52:55 2017 +0100
+++ b/util/array.lua	Thu Mar 16 23:49:27 2017 +0100
@@ -33,6 +33,19 @@
 	return res:append(a1):append(a2);
 end
 
+function array_mt.__eq(a, b)
+	if #a == #b then
+		for i = 1, #a do
+			if a[i] ~= b[i] then
+				return false;
+			end
+		end
+	else
+		return false;
+	end
+	return true;
+end
+
 setmetatable(array, { __call = new_array });
 
 -- Read-only methods