diff options
| -rw-r--r-- | src/rabbit_exchange_type_headers.erl | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/rabbit_exchange_type_headers.erl b/src/rabbit_exchange_type_headers.erl index 60825086f5..444d507c7e 100644 --- a/src/rabbit_exchange_type_headers.erl +++ b/src/rabbit_exchange_type_headers.erl @@ -85,31 +85,52 @@ headers_match(Args, Data) -> MK = parse_x_match(rabbit_misc:table_lookup(Args, <<"x-match">>)), headers_match(Args, Data, true, false, MK). -headers_match([], _Data, AllMatch, _AnyMatch, all) -> - AllMatch; -headers_match([], _Data, _AllMatch, AnyMatch, any) -> - AnyMatch; +% A bit less horrendous algorithm :) +headers_match(_, _, false, _, all) -> false; +headers_match(_, _, _, true, any) -> true; + +% No more bindings, return current state +headers_match([], _Data, AllMatch, _AnyMatch, all) -> AllMatch; +headers_match([], _Data, _AllMatch, AnyMatch, any) -> AnyMatch; + +% Delete bindings starting with x- headers_match([{<<"x-", _/binary>>, _PT, _PV} | PRest], Data, AllMatch, AnyMatch, MatchKind) -> headers_match(PRest, Data, AllMatch, AnyMatch, MatchKind); + +% No more data, but still bindings, false with all headers_match(_Pattern, [], _AllMatch, AnyMatch, MatchKind) -> headers_match([], [], false, AnyMatch, MatchKind); + +% Data key header not in binding, go next data headers_match(Pattern = [{PK, _PT, _PV} | _], [{DK, _DT, _DV} | DRest], AllMatch, AnyMatch, MatchKind) when PK > DK -> headers_match(Pattern, DRest, AllMatch, AnyMatch, MatchKind); + +% Binding key header not in data, false with all, go next binding headers_match([{PK, _PT, _PV} | PRest], Data = [{DK, _DT, _DV} | _], _AllMatch, AnyMatch, MatchKind) when PK < DK -> headers_match(PRest, Data, false, AnyMatch, MatchKind); + +%% It's not properly specified, but a "no value" in a +%% pattern field is supposed to mean simple presence of +%% the corresponding data field. I've interpreted that to +%% mean a type of "void" for the pattern field. headers_match([{PK, void, _PV} | PRest], [{DK, _DT, _DV} | DRest], AllMatch, _AnyMatch, MatchKind) when PK == DK -> headers_match(PRest, DRest, AllMatch, true, MatchKind); + +% Complete match, true with any, go next headers_match([{PK, _PT, PV} | PRest], [{DK, _DT, DV} | DRest], AllMatch, _AnyMatch, MatchKind) when PK == DK andalso PV == DV -> headers_match(PRest, DRest, AllMatch, true, MatchKind); + +% Value does not match, false with all, go next headers_match([{PK, _PT, _PV} | PRest], [{DK, _DT, _DV} | DRest], _AllMatch, AnyMatch, MatchKind) when PK == DK -> headers_match(PRest, DRest, false, AnyMatch, MatchKind). + validate(_X) -> ok. create(_Tx, _X) -> ok. delete(_Tx, _X, _Bs) -> ok. |
