Skip to content

Commit

Permalink
Merge branch 'sze/snmp_generic-split_index' into pu
Browse files Browse the repository at this point in the history
  • Loading branch information
proxyles committed Oct 3, 2012
2 parents ba305e2 + 8f1a00e commit 16b51d5
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/snmp/src/agent/snmp_generic.erl
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,12 @@ collect_keys([#asn1_type{lo = X, hi = X} | _Indexes], Keys)
%% Otherwise, its a dynamic-length type => its a list
%% OBJECT IDENTIFIER, OCTET STRING or BITS (or derivatives)
%% Check if it is IMPLIED (only last element can be IMPLIED)
collect_keys([#asn1_type{implied = true}], Keys) ->
[Keys];
collect_keys([_Type | Indexes], [Length | Keys]) when length(Keys) >= Length ->
%% and also check lo/hi constraints...
collect_keys([#asn1_type{implied = true} = Type], Keys) ->
[collect_check_length(Type, Keys)];
collect_keys([Type | Indexes], [Length | Keys]) when length(Keys) >= Length ->
{StrKey, Rest} = collect_length(Length, Keys, []),
[StrKey | collect_keys(Indexes, Rest)];
[collect_check_length(Type, StrKey) | collect_keys(Indexes, Rest)];
collect_keys([_Type | _Indexes], [Length | Keys]) ->
exit({error, {size_mismatch, Length, Keys}});
collect_keys([], []) -> [];
Expand All @@ -657,6 +658,17 @@ collect_length(0, Rest, Rts) ->
collect_length(N, [El | Rest], Rts) ->
collect_length(N-1, Rest, [El | Rts]).

collect_check_length(#asn1_type{lo = Lo, hi = Hi}, ListVal) ->
Length = length(ListVal),
if
is_integer(Lo) andalso Length < Lo ->
exit({error, {size_mismatch, Lo, ListVal}});
is_integer(Hi) andalso Length > Hi ->
exit({error, {size_mismatch, Hi, ListVal}});
true ->
ListVal
end.

%%------------------------------------------------------------------
%% Checks if a certain row exists.
%% Returns true or false.
Expand Down

0 comments on commit 16b51d5

Please sign in to comment.