plugins: Use integer config API with interval specification where sensible

Many of these fall into a few categories:
- util.cache size, must be >= 1
- byte or item counts that logically can't be negative
- port numbers that should be in 1..0xffff
This commit is contained in:
Kim Alvefur 2023-07-17 01:38:54 +02:00
parent 55768509a3
commit 71ad48095d
26 changed files with 48 additions and 47 deletions

View file

@ -27,7 +27,7 @@ local get_auth_db = assert(scram_hashers[hash_name], "SCRAM-"..hash_name.." not
local scram_name = "scram_"..hash_name:gsub("%-","_"):lower();
-- Default; can be set per-user
local default_iteration_count = module:get_option_number("default_iteration_count", 10000);
local default_iteration_count = module:get_option_integer("default_iteration_count", 10000, 4096);
local tokenauth = module:depends("tokenauth");

View file

@ -35,7 +35,7 @@ local cache = setmetatable({}, { __mode = "v" });
-- disk, which we want to avoid during routing. On the other hand, we don't
-- want to use too much memory either, so this can be tuned by advanced
-- users. TODO use science to figure out a better default, 64 is just a guess.
local cache_size = module:get_option_number("blocklist_cache_size", 64);
local cache_size = module:get_option_integer("blocklist_cache_size", 64, 1);
local cache2 = require"prosody.util.cache".new(cache_size);
local null_blocklist = {};

View file

@ -45,7 +45,7 @@ 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");
local stanza_size_limit = module:get_option_number("c2s_stanza_size_limit", 1024*256);
local stanza_size_limit = module:get_option_integer("c2s_stanza_size_limit", 1024*256, 10000);
if cross_domain ~= nil then
module:log("info", "The 'cross_domain_bosh' option has been deprecated");

View file

@ -28,7 +28,7 @@ local log = module._log;
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);
local stanza_size_limit = module:get_option_integer("c2s_stanza_size_limit", 1024*256,10000);
local measure_connections = module:metric("gauge", "connections", "", "Established c2s connections", {"host", "type", "ip_family"});

View file

@ -27,7 +27,8 @@ local hosts = prosody.hosts;
local log = module._log;
local opt_keepalives = module:get_option_boolean("component_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true));
local stanza_size_limit = module:get_option_number("component_stanza_size_limit", module:get_option_number("s2s_stanza_size_limit", 1024*512));
local stanza_size_limit = module:get_option_integer("component_stanza_size_limit",
module:get_option_integer("s2s_stanza_size_limit", 1024 * 512, 10000), 10000);
local sessions = module:shared("sessions");

View file

@ -12,7 +12,7 @@ local dt = require "prosody.util.datetime";
local filters = require "prosody.util.filters";
local timer = require "prosody.util.timer";
local queue_size = module:get_option_number("csi_queue_size", 256);
local queue_size = module:get_option_integer("csi_queue_size", 256, 1);
local resume_delay = module:get_option_period("csi_resume_inactive_delay", 5);
local important_payloads = module:get_option_set("csi_important_payloads", { });

View file

@ -8,7 +8,7 @@ local array = require "prosody.util.array";
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_port = module:get_option_integer("external_service_port", nil, 1, 65535);
local default_secret = module:get_option_string("external_service_secret");
local default_ttl = module:get_option_period("external_service_ttl", "1 day");

View file

@ -29,8 +29,8 @@ local server = require "prosody.net.http.server";
server.set_default_host(module:get_option_string("http_default_host"));
server.set_option("body_size_limit", module:get_option_number("http_max_content_size"));
server.set_option("buffer_size_limit", module:get_option_number("http_max_buffer_size"));
server.set_option("body_size_limit", module:get_option_number("http_max_content_size", 0));
server.set_option("buffer_size_limit", module:get_option_number("http_max_buffer_size", 0));
-- CORS settings
local cors_overrides = module:get_option("http_cors_override", {});

View file

@ -36,12 +36,12 @@ local persist_stats = module:open_store("upload_stats", "map");
local secret = module:get_option_string(module.name.."_secret", require"prosody.util.id".long());
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_size_limit = module:get_option_integer(module.name .. "_size_limit", 10 * 1024 * 1024, 0); -- 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 = 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);
local daily_quota = module:get_option_integer(module.name .. "_daily_quota", file_size_limit*10, 0); -- 100 MB / day
local total_storage_limit = module:get_option_integer(module.name.."_global_quota", unlimited, 0);
local create_jwt, verify_jwt = require"prosody.util.jwt".init("HS256", secret, secret, { default_ttl = 600 });

View file

@ -12,8 +12,8 @@ local open = io.open;
local fileserver = require"prosody.net.http.files";
local base_path = module:get_option_path("http_files_dir", module:get_option_path("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 cache_size = module:get_option_integer("http_files_cache_size", 128, 1);
local cache_max_file_size = module:get_option_integer("http_files_cache_max_file_size", 4096, 1);
local dir_indices = module:get_option_array("http_index_files", { "index.html", "index.htm" });
local directory_index = module:get_option_boolean("http_dir_listing");

View file

@ -37,14 +37,14 @@ 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 default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50);
local default_max_items, max_max_items = 20, module:get_option_integer("max_archive_query_results", 50, 0);
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_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_item_limit = module:get_option_integer("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000, 0);
local archive_truncate = math.floor(archive_item_limit * 0.99);
if not archive.find then
@ -522,7 +522,7 @@ if cleanup_after ~= "never" then
-- outside the cleanup range.
if not (archive.caps and archive.caps.wildcard_delete) then
local last_date = require "prosody.util.cache".new(module:get_option_number("archive_cleanup_date_cache_size", 1000));
local last_date = require "prosody.util.cache".new(module:get_option_integer("archive_cleanup_date_cache_size", 1000, 1));
function schedule_cleanup(username, date)
date = date or datestamp();
if last_date:get(username) == date then return end

View file

@ -32,12 +32,12 @@ local tostring = tostring;
local time_now = require "prosody.util.time".now;
local m_min = math.min;
local timestamp, datestamp = import("prosody.util.datetime", "datetime", "date");
local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50);
local default_max_items, max_max_items = 20, module:get_option_integer("max_archive_query_results", 50, 0);
local cleanup_after = module:get_option_string("muc_log_expires_after", "1w");
local default_history_length = 20;
local max_history_length = module:get_option_number("max_history_messages", math.huge);
local max_history_length = module:get_option_integer("max_history_messages", math.huge, 0);
local function get_historylength(room)
return math.min(room._data.history_length or default_history_length, max_history_length);
@ -53,7 +53,7 @@ local log_by_default = module:get_option_boolean("muc_log_by_default", true);
local archive_store = "muc_log";
local archive = module:open_store(archive_store, "archive");
local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000);
local archive_item_limit = module:get_option_integer("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000, 0);
local archive_truncate = math.floor(archive_item_limit * 0.99);
if archive.name == "null" or not archive.find then
@ -492,7 +492,7 @@ if cleanup_after ~= "never" then
-- messages, we collect the union of sets of rooms from dates that fall
-- outside the cleanup range.
local last_date = require "prosody.util.cache".new(module:get_option_number("muc_log_cleanup_date_cache_size", 1000));
local last_date = require "prosody.util.cache".new(module:get_option_integer("muc_log_cleanup_date_cache_size", 1000, 1));
if not ( archive.caps and archive.caps.wildcard_delete ) then
function schedule_cleanup(roomname, date)
date = date or datestamp();

View file

@ -1,8 +1,8 @@
module:set_global();
local array = require "prosody.util.array";
local max_buffer_len = module:get_option_number("multiplex_buffer_size", 1024);
local default_mode = module:get_option_number("network_default_read_size", 4096);
local max_buffer_len = module:get_option_integer("multiplex_buffer_size", 1024, 1);
local default_mode = module:get_option_integer("network_default_read_size", 4096, 0);
local portmanager = require "prosody.core.portmanager";

View file

@ -24,7 +24,7 @@ local empty_set = set_new();
local pep_service_items = {};
-- size of caches with full pubsub service objects
local service_cache_size = module:get_option_number("pep_service_cache_size", 1000);
local service_cache_size = module:get_option_integer("pep_service_cache_size", 1000, 1);
-- username -> util.pubsub service object
local services = cache.new(service_cache_size, function (username, _)
@ -36,7 +36,7 @@ local services = cache.new(service_cache_size, function (username, _)
end):table();
-- size of caches with smaller objects
local info_cache_size = module:get_option_number("pep_info_cache_size", 10000);
local info_cache_size = module:get_option_integer("pep_info_cache_size", 10000, 1);
-- username -> recipient -> set of nodes
local recipients = cache.new(info_cache_size):table();
@ -49,7 +49,7 @@ local host = module.host;
local node_config = module:open_store("pep", "map");
local known_nodes = module:open_store("pep");
local max_max_items = module:get_option_number("pep_max_items", 256);
local max_max_items = module:get_option_number("pep_max_items", 256, 0);
local function tonumber_max_items(n)
if n == "max" then

View file

@ -39,7 +39,7 @@ end
-- get(node_name)
-- users(): iterator over (node_name)
local max_max_items = module:get_option_number("pubsub_max_items", 256);
local max_max_items = module:get_option_integer("pubsub_max_items", 256, 1);
local function tonumber_max_items(n)
if n == "max" then

View file

@ -21,9 +21,9 @@ local allowlist_only = module:get_option_boolean("allowlist_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_max = module:get_option_number("registration_throttle_max", min_seconds_between_registrations and 1, 0);
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 throttle_cache_size = module:get_option_integer("registration_throttle_cache_size", 100, 1);
local blocklist_overflow = module:get_option_boolean("blocklist_on_registration_throttle_overload",
module:get_option_boolean("blacklist_on_registration_throttle_overload", false));

View file

@ -41,7 +41,7 @@ local secure_auth = module:get_option_boolean("s2s_secure_auth", false); -- One
local secure_domains, insecure_domains =
module:get_option_set("s2s_secure_domains", {})._items, module:get_option_set("s2s_insecure_domains", {})._items;
local require_encryption = module:get_option_boolean("s2s_require_encryption", true);
local stanza_size_limit = module:get_option_number("s2s_stanza_size_limit", 1024*512);
local stanza_size_limit = module:get_option_integer("s2s_stanza_size_limit", 1024*512, 10000);
local measure_connections_inbound = module:metric(
"gauge", "connections_inbound", "",

View file

@ -66,14 +66,14 @@ local xmlns_sm3 = "urn:xmpp:sm:3";
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 queue_size = module:get_option_integer("smacks_max_queue_size", 500, 1);
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 max_unacked_stanzas = module:get_option_integer("smacks_max_unacked_stanzas", 0, 0);
local max_inactive_unacked_stanzas = module:get_option_integer("smacks_max_inactive_unacked_stanzas", 256, 0);
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 max_old_sessions = module:get_option_integer("smacks_max_old_sessions", 10, 0);
local c2s_sessions = module:shared("/*/c2s/sessions");
local local_sessions = prosody.hosts[module.host].sessions;

View file

@ -11,7 +11,7 @@ local it = require "prosody.util.iterators";
local host = module.host;
local archive_item_limit = module:get_option_number("storage_archive_item_limit", 10000);
local archive_item_limit = module:get_option_integer("storage_archive_item_limit", 10000, 0);
local archive_item_count_cache = cache.new(module:get_option("storage_archive_item_limit_cache_size", 1000));
local use_shift = module:get_option_boolean("storage_archive_experimental_fast_delete", false);

View file

@ -9,7 +9,7 @@ local set = require "prosody.util.set";
local auto_purge_enabled = module:get_option_boolean("storage_memory_temporary", false);
local auto_purge_stores = module:get_option_set("storage_memory_temporary_stores", {});
local archive_item_limit = module:get_option_number("storage_archive_item_limit", 1000);
local archive_item_limit = module:get_option_integer("storage_archive_item_limit", 1000, 0);
local memory = setmetatable({}, {
__index = function(t, k)

View file

@ -152,7 +152,7 @@ end
--- Archive store API
local archive_item_limit = module:get_option_number("storage_archive_item_limit");
local archive_item_limit = module:get_option_integer("storage_archive_item_limit", nil, 0);
local archive_item_count_cache = cache.new(module:get_option("storage_archive_item_limit_cache_size", 1000));
local item_count_cache_hit = module:measure("item_count_cache_hit", "rate");

View file

@ -8,7 +8,7 @@ local st = require "prosody.util.stanza";
-- Using a map store as key-value store so that removal of all user data
-- does not also remove the tombstone, which would defeat the point
local graveyard = module:open_store(nil, "map");
local graveyard_cache = require "prosody.util.cache".new(module:get_option_number("tombstone_cache_size", 1024));
local graveyard_cache = require "prosody.util.cache".new(module:get_option_integer("tombstone_cache_size", 1024, 1));
local ttl = module:get_option_period("user_tombstone_expiry", nil);
-- Keep tombstones forever by default

View file

@ -3,10 +3,10 @@ local set = require "prosody.util.set";
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 port = module:get_option_integer("turn_external_port", 3478, 1, 65535);
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");
local tls_port = module:get_option_integer("turn_external_tls_port", nil, 1, 65535);
if not secret then
module:log_status("error", "Failed to initialize: the 'turn_external_secret' option is not set in your configuration");

View file

@ -28,9 +28,9 @@ local parse_close = websocket_frames.parse_close;
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 stanza_size_limit = module:get_option_integer("c2s_stanza_size_limit", 1024 * 256, 10000);
local frame_buffer_limit = module:get_option_integer("websocket_frame_buffer_limit", 2 * stanza_size_limit, 0);
local frame_fragment_limit = module:get_option_integer("websocket_frame_fragment_limit", 8, 0);
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");

View file

@ -12,7 +12,7 @@ local datetime = require "prosody.util.datetime";
local st = require "prosody.util.stanza";
local default_history_length = 20;
local max_history_length = module:get_option_number("max_history_messages", math.huge);
local max_history_length = module:get_option_integer("max_history_messages", math.huge, 0);
local function set_max_history_length(_max_history_length)
max_history_length = _max_history_length or math.huge;

View file

@ -159,8 +159,8 @@ local function room_save(room, forced, savestate)
end
end
local max_rooms = module:get_option_number("muc_max_rooms");
local max_live_rooms = module:get_option_number("muc_room_cache_size", 100);
local max_rooms = module:get_option_integer("muc_max_rooms", nil, 0);
local max_live_rooms = module:get_option_integer("muc_room_cache_size", 100, 1);
local room_hit = module:measure("room_hit", "rate");
local room_miss = module:measure("room_miss", "rate")
@ -288,7 +288,7 @@ local function set_room_defaults(room, lang)
room:set_whois(module:get_option_boolean("muc_room_default_public_jids",
room:get_whois() == "anyone") and "anyone" or "moderators");
room:set_changesubject(module:get_option_boolean("muc_room_default_change_subject", room:get_changesubject()));
room:set_historylength(module:get_option_number("muc_room_default_history_length", room:get_historylength()));
room:set_historylength(module:get_option_integer("muc_room_default_history_length", room:get_historylength(), 0));
room:set_language(lang or module:get_option_string("muc_room_default_language"));
room:set_presence_broadcast(module:get_option("muc_room_default_presence_broadcast", room:get_presence_broadcast()));
end