aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/src/base
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2017-08-31 08:57:57 +0200
committerAnders Svensson <[email protected]>2017-09-01 17:22:36 +0200
commit99db256e992591ab5cd03d77adcd4ad8d8a16a7e (patch)
treed53fe461180dfcd056f86bbbaac10d2f924681ca /lib/diameter/src/base
parenta1b2f90096a70e521fdbcb2176aacf1dcc7c7f0e (diff)
downloadotp-99db256e992591ab5cd03d77adcd4ad8d8a16a7e.tar.gz
otp-99db256e992591ab5cd03d77adcd4ad8d8a16a7e.tar.bz2
otp-99db256e992591ab5cd03d77adcd4ad8d8a16a7e.zip
Tweak {decode_format, false} semantics
Represent the decoded message by its atom-valued name in diameter_packet.msg, which makes trace much more readable. A diameter_avp.value is untouched (ie. undefined): the AVP name is already in the name field.
Diffstat (limited to 'lib/diameter/src/base')
-rw-r--r--lib/diameter/src/base/diameter_gen.erl45
-rw-r--r--lib/diameter/src/base/diameter_traffic.erl4
2 files changed, 31 insertions, 18 deletions
diff --git a/lib/diameter/src/base/diameter_gen.erl b/lib/diameter/src/base/diameter_gen.erl
index 763f70d877..e8f637dd53 100644
--- a/lib/diameter/src/base/diameter_gen.erl
+++ b/lib/diameter/src/base/diameter_gen.erl
@@ -230,7 +230,7 @@ enc(AvpName, Value, Opts, Mod) ->
%% ---------------------------------------------------------------------------
-spec decode_avps(parent_name(), binary(), map())
- -> {parent_record() | false, [avp()], Failed}
+ -> {parent_record() | parent_name(), [avp()], Failed}
when Failed :: [{5000..5999, #diameter_avp{}}].
decode_avps(Name, Bin, #{module := Mod, decode_format := Fmt} = Opts) ->
@@ -301,7 +301,7 @@ decode(Bin, Code, Vid, DataLen, Pad, M, P, Name, Mod, Fmt, Strict, Opts0,
type = type(NameT),
index = Idx},
- Dec = decode(Data, Name, NameT, Mod, Opts, Avp), %% decode
+ Dec = decode1(Data, Name, NameT, Mod, Fmt, Opts, Avp),
Acc = decode(T, Name, Mod, Fmt, Strict, Opts, Idx+1, AM),%% recurse
acc(Acc, Dec, I, Name, Field, Arity, Strict, Mod, Opts);
_ ->
@@ -449,10 +449,10 @@ field({AvpName, _}) ->
field(_) ->
'AVP'.
-%% decode/6
+%% decode1/7
%% AVP not in dictionary.
-decode(_Data, _Name, 'AVP', _Mod, _Opts, Avp) ->
+decode1(_Data, _Name, 'AVP', _Mod, _Fmt, _Opts, Avp) ->
Avp;
%% 6733, 4.4:
@@ -502,7 +502,7 @@ decode(_Data, _Name, 'AVP', _Mod, _Opts, Avp) ->
%% defined the RFC's "unrecognized", which is slightly stronger than
%% "not defined".)
-decode(Data, Name, {AvpName, Type}, Mod, Opts, Avp) ->
+decode1(Data, Name, {AvpName, Type}, Mod, Fmt, Opts, Avp) ->
#{dictionary := AppMod, failed_avp := Failed}
= Opts,
@@ -516,26 +516,39 @@ decode(Data, Name, {AvpName, Type}, Mod, Opts, Avp) ->
%% list of component AVPs.
try avp_decode(Data, AvpName, Opts, DecMod, Mod) of
- {Rec, As} when Type == 'Grouped' ->
- A = Avp#diameter_avp{value = Rec},
- [A | As];
- V when Type /= 'Grouped' ->
- Avp#diameter_avp{value = V}
+ V ->
+ set(Type, Fmt, Avp, V)
catch
throw: {?MODULE, T} ->
- decode_error(Failed, T, Avp);
+ decode_error(Failed, Fmt, T, Avp);
error: Reason ->
decode_error(Failed, Reason, Name, Mod, Opts, Avp)
end.
-%% decode_error/3
+%% set/4
+
+set('Grouped', false, Avp, V) ->
+ {_Rec, As} = V,
+ [Avp | As];
+
+set('Grouped', _, Avp, V) ->
+ {Rec, As} = V,
+ [Avp#diameter_avp{value = Rec} | As];
+
+set(_, _, Avp, V) ->
+ Avp#diameter_avp{value = V}.
+
+%% decode_error/4
%%
%% Error when decoding a grouped AVP.
-decode_error(true, {Rec, _, _}, Avp) ->
+decode_error(true, false, _, Avp) ->
+ Avp;
+
+decode_error(true, _, {Rec, _, _}, Avp) ->
Avp#diameter_avp{value = Rec};
-decode_error(false, {_, ComponentAvps, [{RC,A} | _]}, Avp) ->
+decode_error(false, _, {_, ComponentAvps, [{RC,A} | _]}, Avp) ->
{RC, [Avp | ComponentAvps], Avp#diameter_avp{data = [A]}}.
%% decode_error/6
@@ -817,8 +830,8 @@ empty(Name, #{module := Mod} = Opts) ->
%% newrec/4
-newrec(false = No, _, _, _) ->
- No;
+newrec(false, _, Name, _) ->
+ Name;
newrec(record, Mod, Name, T)
when T /= decode ->
diff --git a/lib/diameter/src/base/diameter_traffic.erl b/lib/diameter/src/base/diameter_traffic.erl
index 5ee598f513..3cc1c7cce5 100644
--- a/lib/diameter/src/base/diameter_traffic.erl
+++ b/lib/diameter/src/base/diameter_traffic.erl
@@ -1992,10 +1992,10 @@ avp_decode(Dict, 'Experimental-Result' = N, #diameter_avp{data = Bin}
{V,_} = Dict:avp(decode, Bin, N, decode_opts(Dict)),
Avp#diameter_avp{name = N, value = V};
-avp_decode(Dict, Name, #diameter_avp{value = X,
+avp_decode(Dict, Name, #diameter_avp{value = undefined,
data = Bin}
= Avp)
- when is_binary(Bin), X == undefined orelse X == false ->
+ when is_binary(Bin) ->
V = Dict:avp(decode, Bin, Name, decode_opts(Dict)),
Avp#diameter_avp{name = Name, value = V};