25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

mod_pubsub: Allow for limiting item_expire value

If mod_pubsub's 'max_item_expire_node' option is specified, reject node
configurations with an 'item_expire' value that exceeds the specified
limit.
This commit is contained in:
Holger Weiss 2022-01-17 19:08:36 +01:00
parent 8e88fa3884
commit 0f2d36dc53

View File

@ -3512,17 +3512,24 @@ decode_node_config(undefined, _, _) ->
decode_node_config(#xdata{fields = Fs}, Host, Lang) ->
try
Config = pubsub_node_config:decode(Fs),
Max = get_max_items_node(Host),
case {check_opt_range(max_items, Config, Max),
MaxItems = get_max_items_node(Host),
MaxExpiry = get_max_item_expire_node(Host),
case {check_opt_range(max_items, Config, MaxItems),
check_opt_range(item_expire, Config, MaxExpiry),
check_opt_range(max_payload_size, Config, ?MAX_PAYLOAD_SIZE)} of
{true, true} ->
{true, true, true} ->
Config;
{true, false} ->
{true, true, false} ->
erlang:error(
{pubsub_node_config,
{bad_var_value, <<"pubsub#max_payload_size">>,
?NS_PUBSUB_NODE_CONFIG}});
{false, _} ->
{true, false, _} ->
erlang:error(
{pubsub_node_config,
{bad_var_value, <<"pubsub#item_expire">>,
?NS_PUBSUB_NODE_CONFIG}});
{false, _, _} ->
erlang:error(
{pubsub_node_config,
{bad_var_value, <<"pubsub#max_items">>,
@ -3568,9 +3575,11 @@ decode_get_pending(#xdata{fields = Fs}, Lang) ->
end.
-spec check_opt_range(atom(), [proplists:property()],
non_neg_integer() | unlimited) -> boolean().
non_neg_integer() | unlimited | infinity) -> boolean().
check_opt_range(_Opt, _Opts, unlimited) ->
true;
check_opt_range(_Opt, _Opts, infinity) ->
true;
check_opt_range(Opt, Opts, Max) ->
case proplists:get_value(Opt, Opts, Max) of
max -> true;