# HG changeset patch # User Kim Alvefur # Date 1689533373 -7200 # Node ID c8d949cf6b09127031420c0b5f9ec420bd44afd4 # Parent a7c6ea1c5308b4498923cc8ebaf006f61f0fd8a6 plugins: Switch to :get_option_period() for time range options Improves readability ("1 day" vs 86400) and centralizes validation. diff -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_bosh.lua --- a/plugins/mod_bosh.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_bosh.lua Sun Jul 16 20:49:33 2023 +0200 @@ -36,12 +36,12 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_c2s.lua --- a/plugins/mod_c2s.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_c2s.lua Sun Jul 16 20:49:33 2023 +0200 @@ -25,8 +25,8 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_csi_simple.lua --- a/plugins/mod_csi_simple.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_csi_simple.lua Sun Jul 16 20:49:33 2023 +0200 @@ -13,7 +13,7 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_external_services.lua --- a/plugins/mod_external_services.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_external_services.lua Sun Jul 16 20:49:33 2023 +0200 @@ -10,7 +10,7 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_http.lua --- a/plugins/mod_http.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_http.lua Sun Jul 16 20:49:33 2023 +0200 @@ -38,7 +38,7 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_http_file_share.lua --- a/plugins/mod_http_file_share.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_http_file_share.lua Sun Jul 16 20:49:33 2023 +0200 @@ -19,7 +19,6 @@ 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 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_invites.lua --- a/plugins/mod_invites.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_invites.lua Sun Jul 16 20:49:33 2023 +0200 @@ -5,7 +5,7 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_limits.lua --- a/plugins/mod_limits.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_limits.lua Sun Jul 16 20:49:33 2023 +0200 @@ -7,7 +7,7 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_mam/mod_mam.lua --- a/plugins/mod_mam/mod_mam.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_mam/mod_mam.lua Sun Jul 16 20:49:33 2023 +0200 @@ -37,14 +37,13 @@ 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 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_register_limits.lua --- a/plugins/mod_register_limits.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_register_limits.lua Sun Jul 16 20:49:33 2023 +0200 @@ -16,13 +16,13 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_s2s.lua --- a/plugins/mod_s2s.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_s2s.lua Sun Jul 16 20:49:33 2023 +0200 @@ -34,8 +34,8 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_smacks.lua --- a/plugins/mod_smacks.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_smacks.lua Sun Jul 16 20:49:33 2023 +0200 @@ -67,12 +67,12 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_tokenauth.lua --- a/plugins/mod_tokenauth.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_tokenauth.lua Sun Jul 16 20:49:33 2023 +0200 @@ -8,7 +8,7 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_tombstones.lua --- a/plugins/mod_tombstones.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_tombstones.lua Sun Jul 16 20:49:33 2023 +0200 @@ -10,7 +10,7 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_turn_external.lua --- a/plugins/mod_turn_external.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_turn_external.lua Sun Jul 16 20:49:33 2023 +0200 @@ -4,7 +4,7 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/mod_websocket.lua --- a/plugins/mod_websocket.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/mod_websocket.lua Sun Jul 16 20:49:33 2023 +0200 @@ -31,7 +31,7 @@ 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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/muc/lock.lib.lua --- a/plugins/muc/lock.lib.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/muc/lock.lib.lua Sun Jul 16 20:49:33 2023 +0200 @@ -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 -r a7c6ea1c5308 -r c8d949cf6b09 plugins/muc/mod_muc.lua --- a/plugins/muc/mod_muc.lua Sun Jul 16 21:04:42 2023 +0200 +++ b/plugins/muc/mod_muc.lua Sun Jul 16 20:49:33 2023 +0200 @@ -389,7 +389,7 @@ 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;