|
# File radius/dictionary.rb, line 63
def read(fp)
fp.each_line {
|line|
next if line =~ /^\#/ # discard comments
next if (sl = line.split(/\s+/)) == []
case sl[0].upcase
when "ATTRIBUTE"
@attr[sl[1]] = [sl[2].to_i, sl[3]] if (@attr[sl[1]] == nil)
@rattr[sl[2].to_i] = [sl[1], sl[3]] if (@rattr[sl[2].to_i] == nil)
when "VALUE"
if (@attr[sl[1]] == nil)
$stderr.print("Warning: value given for unknown attribute #{sl[1]}");
else
if (@val[@attr[sl[1]][0]] == nil)
@val[@attr[sl[1]][0]] = {}
end
if (@rval[@attr[sl[1]][0]] == nil)
@rval[@attr[sl[1]][0]] = []
end
if (@val[@attr[sl[1]][0]][sl[2]] == nil)
@val[@attr[sl[1]][0]][sl[2]] = sl[3].to_i
end
if (@rval[@attr[sl[1]][0]][sl[3].to_i] == nil)
@rval[@attr[sl[1]][0]][sl[3].to_i] = sl[2]
end
end
when "VENDORATTR"
sl[3] = Kernel::Integer(sl[3]) # this gets hex and octal
# values correctly
@vsattr[sl[1].to_i] = {} if (@vsattr[sl[1].to_i] == nil)
@rvsattr[sl[1].to_i] = {} if (@rvsattr[sl[1].to_i] == nil)
if (@vsattr[sl[1].to_i][sl[2]] == nil)
@vsattr[sl[1].to_i][sl[2]] = sl[3..4]
end
if (@rvsattr[sl[1].to_i][sl[3]] == nil)
@rvsattr[sl[1].to_i][sl[3]] = [sl[2], sl[4]]
end
when "VENDORVALUE"
sl[4] = Kernel::Integer(sl[4])
if (@vsattr[sl[1].to_i][sl[2]] == nil)
$stderr.print "Warning: vendor value for unknown vendor attribute #{sl[1]} found - ignored\n"
else
sl[1] = sl[1].to_i
@vsaval[sl[1]] = {} if @vsaval[sl[1].to_i] == nil
@rvsaval[sl[1]] = {} if @rvsaval[sl[1].to_i] == nil
if @vsaval[sl[1]][@vsattr[sl[1]][sl[2]][0]] == nil
@vsaval[sl[1]][@vsattr[sl[1]][sl[2]][0]] = {}
end
if @rvsaval[sl[1]][@vsattr[sl[1]][sl[2]][0]] == nil
@rvsaval[sl[1]][@vsattr[sl[1]][sl[2]][0]] = []
end
if @vsaval[sl[1]][@vsattr[sl[1]][sl[2]][0]][sl[3]] == nil
@vsaval[sl[1]][@vsattr[sl[1]][sl[2]][0]][sl[3]] = sl[4]
end
if @rvsaval[sl[1]][@vsattr[sl[1]][sl[2]][0]][sl[4]] == nil
@rvsaval[sl[1]][@vsattr[sl[1]][sl[2]][0]][sl[4]] = sl[3]
end
end
else
$stderr.print "Warning: Weird dictionary line: #{line}\n"
end
}
end
|