Skip to content

Commit

Permalink
Parse VSAs in reply messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Bryars committed Nov 3, 2011
1 parent 0bbbabe commit ba83df5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/radiustar/packet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def pack
def unpack
@code, @id, len, @authenticator, attribute_data = @packed.unpack(P_HDR)
@code = CODES.key(@code)
vendor = nil

unset_all_attributes

Expand All @@ -149,7 +150,15 @@ def unpack
attribute_type, attribute_value = attribute_data.unpack("Cxa#{length-2}")
attribute_type = attribute_type.to_i

attribute = @dict.find_attribute_by_id(attribute_type)
if attribute_type == 26 # Vendor Specific Attribute
vid, attribute_type, attribute_value = attribute_data.unpack("xxNCxa#{length-6}")
vendor = @dict.vendors.find_by_id(vid)
attribute = vendor.find_attribute_by_id(attribute_type)
else
vendor = nil
attribute = @dict.find_attribute_by_id(attribute_type)
end

attribute_value = case attribute.type
when 'string'
attribute_value
Expand All @@ -163,7 +172,12 @@ def unpack
attribute_value.unpack("N")[0]
end

set_attribute(attribute.name, attribute_value) if attribute
if vendor
set_attribute(vendor.name+"/"+attribute.name, attribute_value) if attribute
else
set_attribute(attribute.name, attribute_value) if attribute
end

attribute_data[0, length] = ""
end
end
Expand Down

0 comments on commit ba83df5

Please sign in to comment.