diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2022-01-17 19:08:36 +0100 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2022-01-17 19:08:36 +0100 |
commit | 0f2d36dc533b03dca55b9dfda78956f7d4a2de37 (patch) | |
tree | 5ce253cdd24e11f0f2bd90babbbf0bc38e38c575 /src/mod_pubsub.erl | |
parent | mod_shared_roster: Normalize JID on unset_presence (diff) |
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.
Diffstat (limited to '')
-rw-r--r-- | src/mod_pubsub.erl | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/mod_pubsub.erl b/src/mod_pubsub.erl index 76092f1c6..d161ec10c 100644 --- a/src/mod_pubsub.erl +++ b/src/mod_pubsub.erl @@ -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; |