aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.luacheckrc1
-rw-r--r--core/moduleapi.lua23
-rw-r--r--plugins/mod_admin_telnet.lua4
-rw-r--r--plugins/mod_disco.lua2
-rw-r--r--plugins/mod_http_files.lua4
-rw-r--r--plugins/mod_mam/mamprefs.lib.lua5
-rw-r--r--plugins/mod_mam/mod_mam.lua2
-rw-r--r--plugins/mod_pubsub/mod_pubsub.lua3
-rw-r--r--plugins/mod_version.lua4
-rw-r--r--util/array.lua13
10 files changed, 35 insertions, 26 deletions
diff --git a/.luacheckrc b/.luacheckrc
index d931da66..8b1afa42 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -48,6 +48,7 @@ files["plugins/"] = {
"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",
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index 62c34031..e39fd026 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -214,7 +214,7 @@ function api:get_option(name, default_value)
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 @@ function api:get_option_string(name, default_value)
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 @@ function api:get_option_string(name, default_value)
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 @@ function api:get_option_number(name, ...)
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
diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua
index 0913eb6d..2f5d9f63 100644
--- a/plugins/mod_admin_telnet.lua
+++ b/plugins/mod_admin_telnet.lua
@@ -1148,7 +1148,7 @@ function def_env.http:list()
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 @@ function def_env.http:list()
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
diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua
index c9d4a9df..517fcaec 100644
--- a/plugins/mod_disco.lua
+++ b/plugins/mod_disco.lua
@@ -13,7 +13,7 @@ local jid_bare = require "util.jid".bare;
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;
diff --git a/plugins/mod_http_files.lua b/plugins/mod_http_files.lua
index ab2f3966..e396df60 100644
--- a/plugins/mod_http_files.lua
+++ b/plugins/mod_http_files.lua
@@ -19,7 +19,7 @@ local path_sep = package.config:sub(1,1);
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 @@ if not mime_map then
};
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();
diff --git a/plugins/mod_mam/mamprefs.lib.lua b/plugins/mod_mam/mamprefs.lib.lua
index a561b9d5..72c08886 100644
--- a/plugins/mod_mam/mamprefs.lib.lua
+++ b/plugins/mod_mam/mamprefs.lib.lua
@@ -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
diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua
index 6e6d6383..7ea14502 100644
--- a/plugins/mod_mam/mod_mam.lua
+++ b/plugins/mod_mam/mod_mam.lua
@@ -35,7 +35,7 @@ local time_now = os.time;
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
diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua
index 2b878ed8..18d85c52 100644
--- a/plugins/mod_pubsub/mod_pubsub.lua
+++ b/plugins/mod_pubsub/mod_pubsub.lua
@@ -9,8 +9,7 @@ local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
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;
diff --git a/plugins/mod_version.lua b/plugins/mod_version.lua
index be244beb..7f045415 100644
--- a/plugins/mod_version.lua
+++ b/plugins/mod_version.lua
@@ -16,11 +16,11 @@ local query = st.stanza("query", {xmlns = "jabber:iq:version"})
: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;
diff --git a/util/array.lua b/util/array.lua
index ea520f6b..05fa97ca 100644
--- a/util/array.lua
+++ b/util/array.lua
@@ -33,6 +33,19 @@ function array_mt.__add(a1, a2)
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