diff options
author | Anders Svensson <[email protected]> | 2015-06-17 13:27:55 +0200 |
---|---|---|
committer | Anders Svensson <[email protected]> | 2015-06-17 21:14:51 +0200 |
commit | 596848c0b7b752ebf1ed31873de39ad729dc54b4 (patch) | |
tree | f662c6ee10bf0f78bdf83dd2c6f5c7678fa163a2 /lib | |
parent | f3fefbae24a2569a13b538d80d0e99129963ebef (diff) | |
download | otp-596848c0b7b752ebf1ed31873de39ad729dc54b4.tar.gz otp-596848c0b7b752ebf1ed31873de39ad729dc54b4.tar.bz2 otp-596848c0b7b752ebf1ed31873de39ad729dc54b4.zip |
Simplify logic
Failed == undefined implies is_failed() == true. This was true even when
the code was written, in commit c2c00fdd.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/diameter/include/diameter_gen.hrl | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/diameter/include/diameter_gen.hrl b/lib/diameter/include/diameter_gen.hrl index e8ffe7f92c..6e2af0f8f7 100644 --- a/lib/diameter/include/diameter_gen.hrl +++ b/lib/diameter/include/diameter_gen.hrl @@ -338,11 +338,7 @@ d(Name, Avp, Acc) -> A = trim(Avp), {[[A | trim(ComponentAvps)] | Avps], {Rec, [{RC, A} | Errors]}}; error: Reason -> - d(undefined == Failed orelse is_failed(), - Reason, - Name, - trim(Avp), - Acc) + d(is_failed(), Reason, Name, trim(Avp), Acc) after reset(?STRICT_KEY, Strict), reset(?FAILED_KEY, Failed) @@ -428,10 +424,22 @@ relax('Failed-AVP') -> relax(_) -> is_failed(). - + +%% is_failed/0 +%% +%% Is the AVP currently being decoded nested within Failed-AVP? Note +%% that this is only true when Failed-AVP is the parent. In +%% particular, it's not true when Failed-AVP itself is being decoded +%% (unless nested). + is_failed() -> true == getr(?FAILED_KEY). +%% is_failed/1 + +is_failed(Name) -> + 'Failed-AVP' == Name orelse is_failed(). + %% reset/2 reset(Key, undefined) -> @@ -528,17 +536,16 @@ pack_AVP(Name, #diameter_avp{is_mandatory = M, name = AvpName} = Avp, Acc) -> %% allow for Failed-AVP in an answer-message. pack_arity(Name, AvpName, M) -> - IsFailed = Name == 'Failed-AVP' orelse is_failed(), %% Not testing just Name /= 'Failed-AVP' means we're changing the %% packing of AVPs nested within Failed-AVP, but the point of %% ignoring errors within Failed-AVP is to decode as much as %% possible, and failing because a mandatory AVP couldn't be - %% packed into a dedicated field defeats that point. Note that we - %% can't just test not is_failed() since this will be 'true' when - %% packing an unknown AVP directly within Failed-AVP. + %% packed into a dedicated field defeats that point. Note + %% is_failed/1 since is_failed/0 will return false when packing + %% 'AVP' within Failed-AVP. - pack_arity(IsFailed + pack_arity(is_failed(Name) orelse {Name, AvpName} == {'answer-message', 'Failed-AVP'} orelse not M orelse not is_strict(), |