aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-07-16 20:49:33 +0200
committerKim Alvefur <zash@zash.se>2023-07-16 20:49:33 +0200
commit1987a7411f6aab1b0534ef23dc8797362eae1076 (patch)
tree47c52d7b27c3b76cb1356f1a512105f1df2e8592 /plugins
parent903e945d09ffd94ebf3f08b6c5092a56ad484348 (diff)
downloadprosody-1987a7411f6aab1b0534ef23dc8797362eae1076.tar.gz
prosody-1987a7411f6aab1b0534ef23dc8797362eae1076.zip
plugins: Switch to :get_option_period() for time range options
Improves readability ("1 day" vs 86400) and centralizes validation.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_bosh.lua6
-rw-r--r--plugins/mod_c2s.lua4
-rw-r--r--plugins/mod_csi_simple.lua2
-rw-r--r--plugins/mod_external_services.lua2
-rw-r--r--plugins/mod_http.lua2
-rw-r--r--plugins/mod_http_file_share.lua8
-rw-r--r--plugins/mod_invites.lua2
-rw-r--r--plugins/mod_limits.lua2
-rw-r--r--plugins/mod_mam/mod_mam.lua10
-rw-r--r--plugins/mod_register_limits.lua4
-rw-r--r--plugins/mod_s2s.lua4
-rw-r--r--plugins/mod_smacks.lua4
-rw-r--r--plugins/mod_tokenauth.lua2
-rw-r--r--plugins/mod_tombstones.lua2
-rw-r--r--plugins/mod_turn_external.lua2
-rw-r--r--plugins/mod_websocket.lua2
-rw-r--r--plugins/muc/lock.lib.lua2
-rw-r--r--plugins/muc/mod_muc.lua2
18 files changed, 24 insertions, 38 deletions
diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua
index 34d801d9..c505e152 100644
--- a/plugins/mod_bosh.lua
+++ b/plugins/mod_bosh.lua
@@ -36,12 +36,12 @@ local BOSH_HOLD = 1;
local BOSH_MAX_REQUESTS = 2;
-- The number of seconds a BOSH session should remain open with no requests
-local bosh_max_inactivity = module:get_option_number("bosh_max_inactivity", 60);
+local bosh_max_inactivity = module:get_option_period("bosh_max_inactivity", 60);
-- The minimum amount of time between requests with no payload
-local bosh_max_polling = module:get_option_number("bosh_max_polling", 5);
+local bosh_max_polling = module:get_option_period("bosh_max_polling", 5);
-- The maximum amount of time that the server will hold onto a request before replying
-- (the client can set this to a lower value when it connects, if it chooses)
-local bosh_max_wait = module:get_option_number("bosh_max_wait", 120);
+local bosh_max_wait = module:get_option_period("bosh_max_wait", 120);
local consider_bosh_secure = module:get_option_boolean("consider_bosh_secure");
local cross_domain = module:get_option("cross_domain_bosh");
diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua
index e189498c..54eea210 100644
--- a/plugins/mod_c2s.lua
+++ b/plugins/mod_c2s.lua
@@ -25,8 +25,8 @@ local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams";
local log = module._log;
-local c2s_timeout = module:get_option_number("c2s_timeout", 300);
-local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5);
+local c2s_timeout = module:get_option_period("c2s_timeout", "5 minutes");
+local stream_close_timeout = module:get_option_period("c2s_close_timeout", 5);
local opt_keepalives = module:get_option_boolean("c2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true));
local stanza_size_limit = module:get_option_number("c2s_stanza_size_limit", 1024*256);
diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua
index 7dcf0326..5a1c6e31 100644
--- a/plugins/mod_csi_simple.lua
+++ b/plugins/mod_csi_simple.lua
@@ -13,7 +13,7 @@ local filters = require "prosody.util.filters";
local timer = require "prosody.util.timer";
local queue_size = module:get_option_number("csi_queue_size", 256);
-local resume_delay = module:get_option_number("csi_resume_inactive_delay", 5);
+local resume_delay = module:get_option_period("csi_resume_inactive_delay", 5);
local important_payloads = module:get_option_set("csi_important_payloads", { });
diff --git a/plugins/mod_external_services.lua b/plugins/mod_external_services.lua
index 2d18fc99..21c6a9f3 100644
--- a/plugins/mod_external_services.lua
+++ b/plugins/mod_external_services.lua
@@ -10,7 +10,7 @@ local set = require "prosody.util.set";
local default_host = module:get_option_string("external_service_host", module.host);
local default_port = module:get_option_number("external_service_port");
local default_secret = module:get_option_string("external_service_secret");
-local default_ttl = module:get_option_number("external_service_ttl", 86400);
+local default_ttl = module:get_option_period("external_service_ttl", "1 day");
local configured_services = module:get_option_array("external_services", {});
diff --git a/plugins/mod_http.lua b/plugins/mod_http.lua
index 3889d62b..cf5dbe0f 100644
--- a/plugins/mod_http.lua
+++ b/plugins/mod_http.lua
@@ -38,7 +38,7 @@ local opt_methods = module:get_option_set("access_control_allow_methods", { "GET
local opt_headers = module:get_option_set("access_control_allow_headers", { "Content-Type" });
local opt_origins = module:get_option_set("access_control_allow_origins");
local opt_credentials = module:get_option_boolean("access_control_allow_credentials", false);
-local opt_max_age = module:get_option_number("access_control_max_age", 2 * 60 * 60);
+local opt_max_age = module:get_option_period("access_control_max_age", "2 hours");
local opt_default_cors = module:get_option_boolean("http_default_cors_enabled", true);
local function get_http_event(host, app_path, key)
diff --git a/plugins/mod_http_file_share.lua b/plugins/mod_http_file_share.lua
index f9f227cd..1f9f5b7b 100644
--- a/plugins/mod_http_file_share.lua
+++ b/plugins/mod_http_file_share.lua
@@ -19,7 +19,6 @@ local dt = require "prosody.util.datetime";
local hi = require "prosody.util.human.units";
local cache = require "prosody.util.cache";
local lfs = require "lfs";
-local parse_duration = require "prosody.util.human.io".parse_duration;
local unknown = math.abs(0/0);
local unlimited = math.huge;
@@ -40,12 +39,7 @@ local external_base_url = module:get_option_string(module.name .. "_base_url");
local file_size_limit = module:get_option_number(module.name .. "_size_limit", 10 * 1024 * 1024); -- 10 MB
local file_types = module:get_option_set(module.name .. "_allowed_file_types", {});
local safe_types = module:get_option_set(module.name .. "_safe_file_types", {"image/*","video/*","audio/*","text/plain"});
-local expiry_str = module:get_option_string(module.name .. "_expires_after", "1w");
-local expiry, parse_err = parse_duration(expiry_str);
-if expiry == nil then
- module:log("error", "Could not parse "..module.name.."_expire_after string %q: %s", expiry_str, parse_err);
- return false;
-end
+local expiry = module:get_option_period(module.name .. "_expires_after", "1w");
local daily_quota = module:get_option_number(module.name .. "_daily_quota", file_size_limit*10); -- 100 MB / day
local total_storage_limit = module:get_option_number(module.name.."_global_quota", unlimited);
diff --git a/plugins/mod_invites.lua b/plugins/mod_invites.lua
index 11f71544..14f710c7 100644
--- a/plugins/mod_invites.lua
+++ b/plugins/mod_invites.lua
@@ -5,7 +5,7 @@ local jid_node = require "prosody.util.jid".node;
local jid_split = require "prosody.util.jid".split;
local argparse = require "prosody.util.argparse";
-local default_ttl = module:get_option_number("invite_expiry", 86400 * 7);
+local default_ttl = module:get_option_period("invite_expiry", "1 week");
local token_storage;
if prosody.process_type == "prosody" or prosody.shutdown then
diff --git a/plugins/mod_limits.lua b/plugins/mod_limits.lua
index 73f92b34..407f681f 100644
--- a/plugins/mod_limits.lua
+++ b/plugins/mod_limits.lua
@@ -7,7 +7,7 @@ local timer = require "prosody.util.timer";
local ceil = math.ceil;
local limits_cfg = module:get_option("limits", {});
-local limits_resolution = module:get_option_number("limits_resolution", 1);
+local limits_resolution = module:get_option_period("limits_resolution", 1);
local default_bytes_per_second = 3000;
local default_burst = 2;
diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua
index 080eb283..d1e07de8 100644
--- a/plugins/mod_mam/mod_mam.lua
+++ b/plugins/mod_mam/mod_mam.lua
@@ -37,14 +37,13 @@ local tostring = tostring;
local time_now = require "prosody.util.time".now;
local m_min = math.min;
local timestamp, datestamp = import( "util.datetime", "datetime", "date");
-local parse_duration = require "prosody.util.human.io".parse_duration;
local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50);
local strip_tags = module:get_option_set("dont_archive_namespaces", { "http://jabber.org/protocol/chatstates" });
local archive_store = module:get_option_string("archive_store", "archive");
local archive = module:open_store(archive_store, "archive");
-local cleanup_after = module:get_option_string("archive_expires_after", "1w");
+local cleanup_after = module:get_option_period("archive_expires_after", "1w");
local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000);
local archive_truncate = math.floor(archive_item_limit * 0.99);
@@ -511,13 +510,6 @@ if cleanup_after ~= "never" then
local cleanup_storage = module:open_store("archive_cleanup");
local cleanup_map = module:open_store("archive_cleanup", "map");
- local cleanup_after_seconds, parse_err = parse_duration(cleanup_after);
- if parse_err ~= nil then
- module:log("error", "Could not parse archive_expires_after string %q: %s", cleanup_after, parse_err);
- return false;
- end
- cleanup_after = cleanup_after_seconds;
-
module:log("debug", "archive_expires_after = %d -- in seconds", cleanup_after);
if not archive.delete then
diff --git a/plugins/mod_register_limits.lua b/plugins/mod_register_limits.lua
index b3c6806c..dd78fc7c 100644
--- a/plugins/mod_register_limits.lua
+++ b/plugins/mod_register_limits.lua
@@ -16,13 +16,13 @@ local parse_cidr = ip_util.parse_cidr;
local errors = require "prosody.util.error";
-- COMPAT drop old option names
-local min_seconds_between_registrations = module:get_option_number("min_seconds_between_registrations");
+local min_seconds_between_registrations = module:get_option_period("min_seconds_between_registrations");
local allowlist_only = module:get_option_boolean("allowlist_registration_only", module:get_option_boolean("whitelist_registration_only"));
local allowlisted_ips = module:get_option_set("registration_allowlist", module:get_option("registration_whitelist", { "127.0.0.1", "::1" }))._items;
local blocklisted_ips = module:get_option_set("registration_blocklist", module:get_option_set("registration_blacklist", {}))._items;
local throttle_max = module:get_option_number("registration_throttle_max", min_seconds_between_registrations and 1);
-local throttle_period = module:get_option_number("registration_throttle_period", min_seconds_between_registrations);
+local throttle_period = module:get_option_period("registration_throttle_period", min_seconds_between_registrations);
local throttle_cache_size = module:get_option_number("registration_throttle_cache_size", 100);
local blocklist_overflow = module:get_option_boolean("blocklist_on_registration_throttle_overload",
module:get_option_boolean("blacklist_on_registration_throttle_overload", false));
diff --git a/plugins/mod_s2s.lua b/plugins/mod_s2s.lua
index 819e25d3..d2bb5037 100644
--- a/plugins/mod_s2s.lua
+++ b/plugins/mod_s2s.lua
@@ -34,8 +34,8 @@ local resolver_chain = require "prosody.net.resolvers.chain";
local errors = require "prosody.util.error";
local set = require "prosody.util.set";
-local connect_timeout = module:get_option_number("s2s_timeout", 90);
-local stream_close_timeout = module:get_option_number("s2s_close_timeout", 5);
+local connect_timeout = module:get_option_period("s2s_timeout", 90);
+local stream_close_timeout = module:get_option_period("s2s_close_timeout", 5);
local opt_keepalives = module:get_option_boolean("s2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true));
local secure_auth = module:get_option_boolean("s2s_secure_auth", false); -- One day...
local secure_domains, insecure_domains =
diff --git a/plugins/mod_smacks.lua b/plugins/mod_smacks.lua
index c432ebda..d4f2f546 100644
--- a/plugins/mod_smacks.lua
+++ b/plugins/mod_smacks.lua
@@ -67,12 +67,12 @@ local sm2_attr = { xmlns = xmlns_sm2 };
local sm3_attr = { xmlns = xmlns_sm3 };
local queue_size = module:get_option_number("smacks_max_queue_size", 500);
-local resume_timeout = module:get_option_number("smacks_hibernation_time", 600);
+local resume_timeout = module:get_option_period("smacks_hibernation_time", "10 minutes");
local s2s_smacks = module:get_option_boolean("smacks_enabled_s2s", true);
local s2s_resend = module:get_option_boolean("smacks_s2s_resend", false);
local max_unacked_stanzas = module:get_option_number("smacks_max_unacked_stanzas", 0);
local max_inactive_unacked_stanzas = module:get_option_number("smacks_max_inactive_unacked_stanzas", 256);
-local delayed_ack_timeout = module:get_option_number("smacks_max_ack_delay", 30);
+local delayed_ack_timeout = module:get_option_period("smacks_max_ack_delay", 30);
local max_old_sessions = module:get_option_number("smacks_max_old_sessions", 10);
local c2s_sessions = module:shared("/*/c2s/sessions");
diff --git a/plugins/mod_tokenauth.lua b/plugins/mod_tokenauth.lua
index 4364c2c8..89b2a81e 100644
--- a/plugins/mod_tokenauth.lua
+++ b/plugins/mod_tokenauth.lua
@@ -8,7 +8,7 @@ local generate_identifier = require "prosody.util.id".short;
local token_store = module:open_store("auth_tokens", "keyval+");
-local access_time_granularity = module:get_option_number("token_auth_access_time_granularity", 60);
+local access_time_granularity = module:get_option_period("token_auth_access_time_granularity", 60);
local function select_role(username, host, role_name)
if not role_name then return end
diff --git a/plugins/mod_tombstones.lua b/plugins/mod_tombstones.lua
index 275c5d15..4f3b167a 100644
--- a/plugins/mod_tombstones.lua
+++ b/plugins/mod_tombstones.lua
@@ -10,7 +10,7 @@ local st = require "prosody.util.stanza";
local graveyard = module:open_store(nil, "map");
local graveyard_cache = require "prosody.util.cache".new(module:get_option_number("tombstone_cache_size", 1024));
-local ttl = module:get_option_number("user_tombstone_expiry", nil);
+local ttl = module:get_option_period("user_tombstone_expiry", nil);
-- Keep tombstones forever by default
--
-- Rationale:
diff --git a/plugins/mod_turn_external.lua b/plugins/mod_turn_external.lua
index 2009002a..8d1d4662 100644
--- a/plugins/mod_turn_external.lua
+++ b/plugins/mod_turn_external.lua
@@ -4,7 +4,7 @@ local secret = module:get_option_string("turn_external_secret");
local host = module:get_option_string("turn_external_host", module.host);
local user = module:get_option_string("turn_external_user");
local port = module:get_option_number("turn_external_port", 3478);
-local ttl = module:get_option_number("turn_external_ttl", 86400);
+local ttl = module:get_option_period("turn_external_ttl", "1 day");
local tcp = module:get_option_boolean("turn_external_tcp", false);
local tls_port = module:get_option_number("turn_external_tls_port");
diff --git a/plugins/mod_websocket.lua b/plugins/mod_websocket.lua
index d03a4110..b94ee92d 100644
--- a/plugins/mod_websocket.lua
+++ b/plugins/mod_websocket.lua
@@ -31,7 +31,7 @@ local t_concat = table.concat;
local stanza_size_limit = module:get_option_number("c2s_stanza_size_limit", 1024 * 256);
local frame_buffer_limit = module:get_option_number("websocket_frame_buffer_limit", 2 * stanza_size_limit);
local frame_fragment_limit = module:get_option_number("websocket_frame_fragment_limit", 8);
-local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5);
+local stream_close_timeout = module:get_option_period("c2s_close_timeout", 5);
local consider_websocket_secure = module:get_option_boolean("consider_websocket_secure");
local cross_domain = module:get_option("cross_domain_websocket");
if cross_domain ~= nil then
diff --git a/plugins/muc/lock.lib.lua b/plugins/muc/lock.lib.lua
index 27264816..bb5bf82b 100644
--- a/plugins/muc/lock.lib.lua
+++ b/plugins/muc/lock.lib.lua
@@ -10,7 +10,7 @@
local st = require "prosody.util.stanza";
local lock_rooms = module:get_option_boolean("muc_room_locking", true);
-local lock_room_timeout = module:get_option_number("muc_room_lock_timeout", 300);
+local lock_room_timeout = module:get_option_period("muc_room_lock_timeout", "5 minutes");
local function lock(room)
module:fire_event("muc-room-locked", {room = room;});
diff --git a/plugins/muc/mod_muc.lua b/plugins/muc/mod_muc.lua
index f26934be..b8a0d480 100644
--- a/plugins/muc/mod_muc.lua
+++ b/plugins/muc/mod_muc.lua
@@ -389,7 +389,7 @@ end);
if module:get_option_boolean("muc_tombstones", true) then
- local ttl = module:get_option_number("muc_tombstone_expiry", 86400 * 31);
+ local ttl = module:get_option_period("muc_tombstone_expiry", "31 days");
module:hook("muc-room-destroyed",function(event)
local room = event.room;