diff options
| author | Francesco Mazzoli <francesco@rabbitmq.com> | 2012-09-10 14:51:26 +0100 |
|---|---|---|
| committer | Francesco Mazzoli <francesco@rabbitmq.com> | 2012-09-10 14:51:26 +0100 |
| commit | 90c5cccca622e9dd256713d6e35338c1d878d7a8 (patch) | |
| tree | cfd5b5f80bb9c0a2fb1483799387e89eb47b8cf4 /src | |
| parent | 7b5c49fe977af08b37cb56d6f8c2b98a95ccff11 (diff) | |
| parent | 347ae507df6d28da169dbef65f1a7f356819e3f4 (diff) | |
| download | rabbitmq-server-git-90c5cccca622e9dd256713d6e35338c1d878d7a8.tar.gz | |
merge default
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_amqqueue.erl | 16 | ||||
| -rw-r--r-- | src/rabbit_parameter_validation.erl | 11 | ||||
| -rw-r--r-- | src/rabbit_policy.erl | 12 |
3 files changed, 26 insertions, 13 deletions
diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 461b25ebef..7628d1097d 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -40,6 +40,8 @@ -define(INTEGER_ARG_TYPES, [byte, short, signedint, long]). +-define(MAX_EXPIRY_TIMER, 4294967295). + -define(MORE_CONSUMER_CREDIT_AFTER, 50). -define(FAILOVER_WAIT_MILLIS, 100). @@ -397,16 +399,18 @@ check_int_arg({Type, _}, _) -> check_positive_int_arg({Type, Val}, Args) -> case check_int_arg({Type, Val}, Args) of - ok when Val > 0 -> ok; - ok -> {error, {value_zero_or_less, Val}}; - Error -> Error + ok when Val > ?MAX_EXPIRY_TIMER -> {error, {value_too_big, Val}}; + ok when Val > 0 -> ok; + ok -> {error, {value_zero_or_less, Val}}; + Error -> Error end. check_non_neg_int_arg({Type, Val}, Args) -> case check_int_arg({Type, Val}, Args) of - ok when Val >= 0 -> ok; - ok -> {error, {value_less_than_zero, Val}}; - Error -> Error + ok when Val > ?MAX_EXPIRY_TIMER -> {error, {value_too_big, Val}}; + ok when Val >= 0 -> ok; + ok -> {error, {value_less_than_zero, Val}}; + Error -> Error end. check_dlxrk_arg({longstr, _}, Args) -> diff --git a/src/rabbit_parameter_validation.erl b/src/rabbit_parameter_validation.erl index af940dde97..2235340f78 100644 --- a/src/rabbit_parameter_validation.erl +++ b/src/rabbit_parameter_validation.erl @@ -16,7 +16,7 @@ -module(rabbit_parameter_validation). --export([number/2, binary/2, list/2, proplist/3]). +-export([number/2, binary/2, list/2, regex/2, proplist/3]). number(_Name, Term) when is_number(Term) -> ok; @@ -36,6 +36,15 @@ list(_Name, Term) when is_list(Term) -> list(Name, Term) -> {error, "~s should be list, actually was ~p", [Name, Term]}. +regex(Name, Term) when is_binary(Term) -> + case re:compile(Term) of + {ok, _} -> ok; + {error, Reason} -> {error, "~s should be regular expression " + "but is invalid: ~p", [Name, Reason]} + end; +regex(Name, Term) -> + {error, "~s should be a binary but was ~p", [Name, Term]}. + proplist(Name, Constraints, Term) when is_list(Term) -> {Results, Remainder} = lists:foldl( diff --git a/src/rabbit_policy.erl b/src/rabbit_policy.erl index 05b43a2ee1..69480c9c11 100644 --- a/src/rabbit_policy.erl +++ b/src/rabbit_policy.erl @@ -22,7 +22,7 @@ -include("rabbit.hrl"). --import(rabbit_misc, [pget/2]). +-import(rabbit_misc, [pget/2, pget/3]). -export([register/0]). -export([name/1, get/2, set/1]). @@ -129,14 +129,14 @@ match(Name, Policies) -> end. matches(#resource{name = Name}, Policy) -> - lists:prefix(binary_to_list(pget(<<"prefix">>, Policy)), - binary_to_list(Name)). + match =:= re:run(Name, pget(<<"pattern">>, Policy), [{capture, none}]). sort_pred(A, B) -> - size(pget(<<"prefix">>, A)) >= size(pget(<<"prefix">>, B)). + pget(<<"priority">>, A, 0) >= pget(<<"priority">>, B, 0). %%---------------------------------------------------------------------------- policy_validation() -> - [{<<"prefix">>, fun rabbit_parameter_validation:binary/2, mandatory}, - {<<"policy">>, fun rabbit_parameter_validation:list/2, mandatory}]. + [{<<"priority">>, fun rabbit_parameter_validation:number/2, optional}, + {<<"pattern">>, fun rabbit_parameter_validation:regex/2, mandatory}, + {<<"policy">>, fun rabbit_parameter_validation:list/2, mandatory}]. |
