16#include <boost/lexical_cast.hpp>
29 switch (
static_cast<uint8_t
>(value)) {
39 return (
"ipv6prefix");
50 if (name ==
"string") {
52 }
else if ((name ==
"integer") || (name ==
"date")) {
54 }
else if (name ==
"ipaddr") {
56 }
else if (name ==
"ipv6addr") {
58 }
else if (name ==
"ipv6prefix") {
60 }
else if (name ==
"vsa") {
76 auto it = idx.find(boost::make_tuple(vendor, type));
77 if (it != idx.end()) {
86 auto it = idx.find(boost::make_tuple(vendor, name));
87 if (it != idx.end()) {
90 auto alias =
aliases_.find(boost::make_tuple(vendor, name));
92 auto ita = idx.find(boost::make_tuple(vendor, alias->name_));
93 if (ita != idx.end()) {
106 auto it1 = idx1.find(boost::make_tuple(def->vendor_, def->name_));
107 if (it1 != idx1.end()) {
108 if ((def->type_ == (*it1)->type_) &&
109 (def->value_type_ == (*it1)->value_type_)) {
114 msg <<
"Illegal attribute redefinition of '" << def->name_ <<
"'";
115 if (def->vendor_ != 0) {
116 msg <<
" vendor " << def->vendor_;
118 msg <<
" type " <<
static_cast<unsigned>((*it1)->type_)
120 <<
" by " <<
static_cast<unsigned>(def->type_)
125 auto it0 = idx0.find(boost::make_tuple(def->vendor_, def->type_));
126 if (it0 != idx0.end()) {
127 if (def->value_type_ == (*it0)->value_type_) {
129 AttrDefAlias alias(def->name_, (*it0)->name_, def->vendor_);
130 static_cast<void>(
aliases_.insert(alias));
134 msg <<
"Illegal attribute redefinition of '" << (*it0)->name_ <<
"'";
135 if (def->vendor_ != 0) {
136 msg <<
" vendor " << def->vendor_;
138 msg <<
" type " <<
static_cast<unsigned>((*it0)->type_)
140 <<
" by '" << def->name_ <<
"' "
141 <<
static_cast<unsigned>(def->type_) <<
" "
155 oss <<
"Attribute-" <<
static_cast<unsigned>(type);
161 const uint32_t vendor)
const {
163 auto it = idx.find(boost::make_tuple(vendor, type, name));
164 if (it != idx.end()) {
172 const uint32_t vendor)
const {
174 auto it = idx.find(boost::make_tuple(vendor, type, value));
175 if (it != idx.end()) {
187 auto it = idx.find(boost::make_tuple(def->vendor_, def->type_, def->name_));
188 if (it != idx.end()) {
189 if (def->value_ == (*it)->value_) {
196 << def->name_ <<
"' value " << (*it)->value_
197 <<
" by " << def->value_);
200 msg <<
"Illegal integer constant redefinition of '"
201 << def->name_ <<
"' for attribute '"
202 <<
getName(def->type_, def->vendor_) <<
"'";
203 if (def->vendor_ != 0) {
204 msg <<
" in vendor " << def->vendor_;
206 msg <<
" value " << (*it)->value_ <<
" by " << def->value_;
220 if (line[0] ==
'#') {
226 if (tokens.empty()) {
230 if (tokens[0] ==
"$INCLUDE") {
231 if (tokens.size() != 2) {
238 if (tokens[0] ==
"ATTRIBUTE") {
239 if (tokens.size() != 4) {
242 const string& name = tokens[1];
243 const string& type_str = tokens[2];
246 int64_t type64 = boost::lexical_cast<int64_t>(type_str);
248 if ((type64 < numeric_limits<uint8_t>::min()) ||
249 (type64 > numeric_limits<uint8_t>::max())) {
252 type =
static_cast<uint8_t
>(type64);
260 <<
"have the vsa data type");
267 if (tokens[0] ==
"VALUE") {
268 if (tokens.size() != 4) {
271 const string& attr_str = tokens[1];
275 msg <<
"unknown attribute '" << attr_str <<
"'";
277 msg <<
" in vendor " << vendor;
283 msg <<
"attribute '" << attr_str <<
"'";
285 msg <<
" in vendor " << vendor;
287 msg <<
" is not an integer attribute";
290 const string& name = tokens[2];
291 const string& value_str = tokens[3];
294 int64_t val = boost::lexical_cast<int64_t>(value_str);
295 if ((val < numeric_limits<int32_t>::min()) ||
296 (val > numeric_limits<uint32_t>::max())) {
299 value =
static_cast<uint32_t
>(val);
308 if (tokens[0] ==
"VENDOR") {
309 if (tokens.size() != 3) {
312 const string& name = tokens[1];
313 const string& value_str = tokens[2];
316 int64_t val = boost::lexical_cast<int64_t>(value_str);
317 if ((val < numeric_limits<int32_t>::min()) ||
318 (val > numeric_limits<uint32_t>::max())) {
321 value =
static_cast<uint32_t
>(val);
333 if (tokens[0] ==
"BEGIN-VENDOR") {
336 << vendor <<
" is still open");
338 if (tokens.size() != 2) {
341 const string& vendor_str = tokens[1];
344 vendor = vendor_cst->value_;
348 int64_t val = boost::lexical_cast<int64_t>(vendor_str);
349 if ((val < numeric_limits<int32_t>::min()) ||
350 (val > numeric_limits<uint32_t>::max())) {
353 vendor =
static_cast<uint32_t
>(val);
363 if (tokens[0] ==
"END-VENDOR") {
367 if (tokens.size() != 2) {
370 const string& vendor_str = tokens[1];
373 if (vendor_cst->value_ == vendor) {
378 <<
" and end vendor " << vendor_cst->value_
384 int64_t val = boost::lexical_cast<int64_t>(vendor_str);
385 if ((val < numeric_limits<int32_t>::min()) ||
386 (val > numeric_limits<uint32_t>::max())) {
389 value =
static_cast<uint32_t
>(val);
393 if (vendor == value) {
398 <<
" and end vendor " << value <<
" do not match");
405 unsigned int depth) {
410 if (!ifs.is_open()) {
420 }
catch (
const exception& ex) {
423 << (depth > 0 ?
"," :
""));
440 }
catch (
const exception& ex) {
447 for (
auto const& it : defs) {
454 if (def->type_ != it.type_) {
456 <<
"for '" << it.name_ <<
"': type is "
457 <<
static_cast<unsigned>(def->type_) <<
", must be "
458 <<
static_cast<unsigned>(it.type_));
460 if (def->value_type_ != it.value_type_) {
462 <<
"for '" << it.name_ <<
"': value type is "
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
A generic exception that is thrown when an unexpected error condition occurs.
RADIUS attribute aliases.
RADIUS attribute definition.
void add(AttrDefPtr def)
Add (or replace) an attribute definition.
static AttrDefs & instance()
Returns a single instance.
AttrDefContainer container_
Attribute definition container.
IntCstDefContainer ic_container_
Integer constant definition container.
AttrDefAliases aliases_
Attribute aliases.
void readDictionary(const std::string &path, uint32_t &vendor, unsigned int depth=0)
Read a dictionary from a file.
IntCstDefPtr getByValue(const uint8_t type, const uint32_t value, const uint32_t vendor=0) const
Get integer constant definition by attribute type and value.
void parseLine(const std::string &line, uint32_t &vendor, unsigned int depth)
Parse a dictionary line.
std::string getName(const uint8_t type, const uint32_t vendor=0) const
Get attribute name.
AttrDefPtr getByName(const std::string &name, const uint32_t vendor=0) const
Get attribute definition by name and vendor.
void checkStandardDefs(const AttrDefList &defs) const
Check if a list of standard attribute definitions are available and correct.
AttrDefPtr getByType(const uint8_t type, const uint32_t vendor=0) const
Get attribute definition by type and vendor.
RADIUS integer constant definitions.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< IntCstDef > IntCstDefPtr
Shared pointers to Integer constant definition.
@ PW_VENDOR_SPECIFIC
string.
std::list< AttrDef > AttrDefList
List of Attribute definitions.
boost::shared_ptr< AttrDef > AttrDefPtr
Shared pointers to Attribute definition.
AttrValueType textToAttrValueType(const string &name)
AttrValueType name -> value function.
string attrValueTypeToText(const AttrValueType value)
AttrValueType value -> name function.
AttrValueType
Attribute value types.
vector< string > tokens(const string &text, const string &delim, bool escape)
Split string into tokens.
Defines the logger used by the top-level component of kea-lfc.