Skip to content

Commit

Permalink
mod_pubsub: Allow for limiting item_expire value
Browse files Browse the repository at this point in the history
If mod_pubsub's 'max_item_expire_node' option is specified, reject node
configurations with an 'item_expire' value that exceeds the specified
limit.
  • Loading branch information
weiss committed Jan 17, 2022
1 parent 8e88fa3 commit 0f2d36d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/mod_pubsub.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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">>,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0f2d36d

Please sign in to comment.