diff options
Diffstat (limited to 'lib/diameter/src')
-rw-r--r-- | lib/diameter/src/base/diameter.erl | 2 | ||||
-rw-r--r-- | lib/diameter/src/base/diameter_config.erl | 4 | ||||
-rw-r--r-- | lib/diameter/src/base/diameter_gen.erl | 56 | ||||
-rw-r--r-- | lib/diameter/src/base/diameter_traffic.erl | 4 | ||||
-rw-r--r-- | lib/diameter/src/base/diameter_watchdog.erl | 4 |
5 files changed, 41 insertions, 29 deletions
diff --git a/lib/diameter/src/base/diameter.erl b/lib/diameter/src/base/diameter.erl index 3b41feac0d..69ef6f4ec0 100644 --- a/lib/diameter/src/base/diameter.erl +++ b/lib/diameter/src/base/diameter.erl @@ -340,7 +340,7 @@ call(SvcName, App, Message) -> :: record | list | map - | false + | none | record_from_map. -type strict_arities() diff --git a/lib/diameter/src/base/diameter_config.erl b/lib/diameter/src/base/diameter_config.erl index 6fc4277ac8..284f885884 100644 --- a/lib/diameter/src/base/diameter_config.erl +++ b/lib/diameter/src/base/diameter_config.erl @@ -588,8 +588,7 @@ opt(service, {K, false}) K == use_shared_peers; K == monitor; K == restrict_connections; - K == strict_arities; - K == decode_format -> + K == strict_arities -> true; opt(service, {K, true}) @@ -602,6 +601,7 @@ opt(service, {decode_format, T}) when T == record; T == list; T == map; + T == none; T == record_from_map -> true; diff --git a/lib/diameter/src/base/diameter_gen.erl b/lib/diameter/src/base/diameter_gen.erl index f9172ec59d..0aea982a54 100644 --- a/lib/diameter/src/base/diameter_gen.erl +++ b/lib/diameter/src/base/diameter_gen.erl @@ -45,7 +45,7 @@ -define(THROW(T), throw({?MODULE, T})). -type parent_name() :: atom(). %% parent = Message or AVP --type parent_record() :: tuple(). %% +-type parent_record() :: tuple() | avp_values() | map(). -type avp_name() :: atom(). -type avp_record() :: tuple(). -type avp_values() :: [{avp_name(), term()}]. @@ -61,9 +61,7 @@ %% # encode_avps/3 %% --------------------------------------------------------------------------- --spec encode_avps(parent_name(), - parent_record() | avp_values() | map(), - map()) +-spec encode_avps(parent_name(), parent_record(), map()) -> iolist() | no_return(). @@ -232,7 +230,7 @@ enc(AvpName, Value, Opts, Mod) -> %% --------------------------------------------------------------------------- -spec decode_avps(parent_name(), binary(), map()) - -> {parent_record(), [avp()], Failed} + -> {parent_record() | parent_name(), [avp()], Failed} when Failed :: [{5000..5999, #diameter_avp{}}]. decode_avps(Name, Bin, #{module := Mod, decode_format := Fmt} = Opts) -> @@ -303,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); _ -> @@ -451,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: @@ -504,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, @@ -518,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', none, 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, none, _, 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 @@ -724,8 +735,9 @@ pack(Arity, F, Avp, Mod, [Failed | Rec]) -> %% set/5 -set(_, _, _, _, false = No) -> - No; +set(_, _, _, _, None) + when is_atom(None) -> + None; set(1, F, Value, _, Map) when is_map(Map) -> @@ -819,8 +831,8 @@ empty(Name, #{module := Mod} = Opts) -> %% newrec/4 -newrec(false = No, _, _, _) -> - No; +newrec(none, _, 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 c719ef4739..1a4bb4d0bf 100644 --- a/lib/diameter/src/base/diameter_traffic.erl +++ b/lib/diameter/src/base/diameter_traffic.erl @@ -1993,10 +1993,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}; diff --git a/lib/diameter/src/base/diameter_watchdog.erl b/lib/diameter/src/base/diameter_watchdog.erl index bb671e9860..c08e2da672 100644 --- a/lib/diameter/src/base/diameter_watchdog.erl +++ b/lib/diameter/src/base/diameter_watchdog.erl @@ -72,7 +72,7 @@ restrict := boolean(), suspect := non_neg_integer(), %% OKAY -> SUSPECT okay := non_neg_integer()}, %% REOPEN -> OKAY - codec :: #{decode_format := false, + codec :: #{decode_format := none, string_decode := false, strict_arities => diameter:strict_arities(), strict_mbit := boolean(), @@ -157,7 +157,7 @@ i({Ack, T, Pid, {Opts, string_decode, rfc, ordered_encode], - SvcOpts#{decode_format := false, + SvcOpts#{decode_format := none, string_decode := false, ordered_encode => false})}. |