aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/src/base/diameter_codec.erl
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2017-07-30 01:27:42 +0200
committerAnders Svensson <[email protected]>2017-08-03 17:17:37 +0200
commit96cd627acfde682875149effda4611dc778622fd (patch)
treeda67ee6f943407b025d80a8ae2b332d5dd063b8a /lib/diameter/src/base/diameter_codec.erl
parent43b84071754a27894a44ffb0f34d4a03157ebeb5 (diff)
downloadotp-96cd627acfde682875149effda4611dc778622fd.tar.gz
otp-96cd627acfde682875149effda4611dc778622fd.tar.bz2
otp-96cd627acfde682875149effda4611dc778622fd.zip
Count AVPs in #diameter_avp.index
The index field in record diameter_avp was previously used to enumerate AVPs so that the list could be returned in some cases, since diameter_codec:collect_avps/2 (now /1) reversed the order. That's no longer the case as of the grandparent commit, so use the field to enumerate instances of the same AVP instead, and only when arities are being checked, to save having to look them up in the map when checking for 5009 errors, or counting AVPs at all in diameter_codec:collect_avps/1.
Diffstat (limited to 'lib/diameter/src/base/diameter_codec.erl')
-rw-r--r--lib/diameter/src/base/diameter_codec.erl18
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/diameter/src/base/diameter_codec.erl b/lib/diameter/src/base/diameter_codec.erl
index c179c4b362..81c21fb8f2 100644
--- a/lib/diameter/src/base/diameter_codec.erl
+++ b/lib/diameter/src/base/diameter_codec.erl
@@ -489,9 +489,9 @@ collect_avps(#diameter_packet{bin = Bin} = Pkt) ->
Pkt#diameter_packet{avps = collect_avps(Bin)};
collect_avps(<<_:20/binary, Avps/binary>>) ->
- collect(Avps, 0).
+ collect(Avps).
-%% collect/2
+%% collect/1
%% 0 1 2 3
%% 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@@ -505,7 +505,7 @@ collect_avps(<<_:20/binary, Avps/binary>>) ->
%% | Data ...
%% +-+-+-+-+-+-+-+-+
-collect(<<Code:32, V:1, M:1, P:1, _:5, Len:24, I:V/unit:32, Rest/binary>>, N)->
+collect(<<Code:32, V:1, M:1, P:1, _:5, Len:24, I:V/unit:32, Rest/binary>>) ->
Vid = if 1 == V -> I; 0 == V -> undefined end,
DataLen = Len - 8 - V*4, %% Might be negative, which ensures
Pad = ?PAD(Len), %% failure of the match below.
@@ -518,9 +518,8 @@ collect(<<Code:32, V:1, M:1, P:1, _:5, Len:24, I:V/unit:32, Rest/binary>>, N)->
vendor_id = Vid,
is_mandatory = MB,
need_encryption = PB,
- data = Data,
- index = N},
- [Avp | collect(T, N+1)];
+ data = Data},
+ [Avp | collect(T)];
_ ->
%% Length in header points past the end of the message, or
%% doesn't span the header. Note that an length error can
@@ -532,16 +531,15 @@ collect(<<Code:32, V:1, M:1, P:1, _:5, Len:24, I:V/unit:32, Rest/binary>>, N)->
vendor_id = Vid,
is_mandatory = MB,
need_encryption = PB,
- data = {5014, Rest},
- index = N}]
+ data = {5014, Rest}}]
end;
-collect(<<>>, _) ->
+collect(<<>>) ->
[];
%% Header is truncated. pack_avp/1 will pad this at encode if sent in
%% a Failed-AVP.
-collect(Bin, _) ->
+collect(Bin) ->
[#diameter_avp{data = {5014, Bin}}].
%% 3588: