25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +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) -> decode_node_config(#xdata{fields = Fs}, Host, Lang) ->
try try
Config = pubsub_node_config:decode(Fs), Config = pubsub_node_config:decode(Fs),
Max = get_max_items_node(Host), MaxItems = get_max_items_node(Host),
case {check_opt_range(max_items, Config, Max), 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 check_opt_range(max_payload_size, Config, ?MAX_PAYLOAD_SIZE)} of
{true, true} -> {true, true, true} ->
Config; Config;
{true, false} -> {true, true, false} ->
erlang:error( erlang:error(
{pubsub_node_config, {pubsub_node_config,
{bad_var_value, <<"pubsub#max_payload_size">>, {bad_var_value, <<"pubsub#max_payload_size">>,
?NS_PUBSUB_NODE_CONFIG}}); ?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( erlang:error(
{pubsub_node_config, {pubsub_node_config,
{bad_var_value, <<"pubsub#max_items">>, {bad_var_value, <<"pubsub#max_items">>,
@ -3568,9 +3575,11 @@ decode_get_pending(#xdata{fields = Fs}, Lang) ->
end. end.
-spec check_opt_range(atom(), [proplists:property()], -spec check_opt_range(atom(), [proplists:property()],
non_neg_integer() | unlimited) -> boolean(). non_neg_integer() | unlimited | infinity) -> boolean().
check_opt_range(_Opt, _Opts, unlimited) -> check_opt_range(_Opt, _Opts, unlimited) ->
true; true;
check_opt_range(_Opt, _Opts, infinity) ->
true;
check_opt_range(Opt, Opts, Max) -> check_opt_range(Opt, Opts, Max) ->
case proplists:get_value(Opt, Opts, Max) of case proplists:get_value(Opt, Opts, Max) of
max -> true; max -> true;