12#include <boost/lexical_cast.hpp>
26 switch (
static_cast<uint8_t
>(value)) {
36 return (
"ipv6prefix");
47 if (name ==
"string") {
49 }
else if ((name ==
"integer") || (name ==
"date")) {
51 }
else if (name ==
"ipaddr") {
53 }
else if (name ==
"ipv6addr") {
55 }
else if (name ==
"ipv6prefix") {
57 }
else if (name ==
"vsa") {
73 auto it = idx.find(boost::make_tuple(vendor, type));
74 if (it != idx.end()) {
83 auto it = idx.find(boost::make_tuple(vendor, name));
84 if (it != idx.end()) {
87 auto alias =
aliases_.find(boost::make_tuple(vendor, name));
89 auto ita = idx.find(boost::make_tuple(vendor, alias->name_));
90 if (ita != idx.end()) {
103 auto it1 = idx1.find(boost::make_tuple(def->vendor_, def->name_));
104 if (it1 != idx1.end()) {
105 if ((def->type_ == (*it1)->type_) &&
106 (def->value_type_ == (*it1)->value_type_)) {
111 msg <<
"Illegal attribute redefinition of '" << def->name_ <<
"'";
112 if (def->vendor_ != 0) {
113 msg <<
" vendor " << def->vendor_;
115 msg <<
" type " <<
static_cast<unsigned>((*it1)->type_)
117 <<
" by " <<
static_cast<unsigned>(def->type_)
122 auto it0 = idx0.find(boost::make_tuple(def->vendor_, def->type_));
123 if (it0 != idx0.end()) {
124 if (def->value_type_ == (*it0)->value_type_) {
126 AttrDefAlias alias(def->name_, (*it0)->name_, def->vendor_);
127 static_cast<void>(
aliases_.insert(alias));
131 msg <<
"Illegal attribute redefinition of '" << (*it0)->name_ <<
"'";
132 if (def->vendor_ != 0) {
133 msg <<
" vendor " << def->vendor_;
135 msg <<
" type " <<
static_cast<unsigned>((*it0)->type_)
137 <<
" by '" << def->name_ <<
"' "
138 <<
static_cast<unsigned>(def->type_) <<
" "
152 oss <<
"Attribute-" <<
static_cast<unsigned>(type);
158 const uint32_t vendor)
const {
160 auto it = idx.find(boost::make_tuple(vendor, type, name));
161 if (it != idx.end()) {
169 const uint32_t vendor)
const {
171 auto it = idx.find(boost::make_tuple(vendor, type, value));
172 if (it != idx.end()) {
184 auto it = idx.find(boost::make_tuple(def->vendor_, def->type_, def->name_));
185 if (it != idx.end()) {
186 if (def->value_ == (*it)->value_) {
193 << def->name_ <<
"' value " << (*it)->value_
194 <<
" by " << def->value_);
197 msg <<
"Illegal integer constant redefinition of '"
198 << def->name_ <<
"' for attribute '"
199 <<
getName(def->type_, def->vendor_) <<
"'";
200 if (def->vendor_ != 0) {
201 msg <<
" in vendor " << def->vendor_;
203 msg <<
" value " << (*it)->value_ <<
" by " << def->value_;
217 if (line[0] ==
'#') {
223 if (tokens.empty()) {
227 if (tokens[0] ==
"$INCLUDE") {
228 if (tokens.size() != 2) {
235 if (tokens[0] ==
"ATTRIBUTE") {
236 if (tokens.size() != 4) {
239 const string& name = tokens[1];
240 const string& type_str = tokens[2];
243 int64_t type64 = boost::lexical_cast<int64_t>(type_str);
245 if ((type64 < numeric_limits<uint8_t>::min()) ||
246 (type64 > numeric_limits<uint8_t>::max())) {
249 type =
static_cast<uint8_t
>(type64);
257 <<
"have the vsa data type");
264 if (tokens[0] ==
"VALUE") {
265 if (tokens.size() != 4) {
268 const string& attr_str = tokens[1];
272 msg <<
"unknown attribute '" << attr_str <<
"'";
274 msg <<
" in vendor " << vendor;
280 msg <<
"attribute '" << attr_str <<
"'";
282 msg <<
" in vendor " << vendor;
284 msg <<
" is not an integer attribute";
287 const string& name = tokens[2];
288 const string& value_str = tokens[3];
291 int64_t val = boost::lexical_cast<int64_t>(value_str);
292 if ((val < numeric_limits<int32_t>::min()) ||
293 (val > numeric_limits<uint32_t>::max())) {
296 value =
static_cast<uint32_t
>(val);
305 if (tokens[0] ==
"VENDOR") {
306 if (tokens.size() != 3) {
309 const string& name = tokens[1];
310 const string& value_str = tokens[2];
313 int64_t val = boost::lexical_cast<int64_t>(value_str);
314 if ((val < numeric_limits<int32_t>::min()) ||
315 (val > numeric_limits<uint32_t>::max())) {
318 value =
static_cast<uint32_t
>(val);
330 if (tokens[0] ==
"BEGIN-VENDOR") {
333 << vendor <<
" is still open");
335 if (tokens.size() != 2) {
338 const string& vendor_str = tokens[1];
341 vendor = vendor_cst->value_;
345 int64_t val = boost::lexical_cast<int64_t>(vendor_str);
346 if ((val < numeric_limits<int32_t>::min()) ||
347 (val > numeric_limits<uint32_t>::max())) {
350 vendor =
static_cast<uint32_t
>(val);
360 if (tokens[0] ==
"END-VENDOR") {
364 if (tokens.size() != 2) {
367 const string& vendor_str = tokens[1];
370 if (vendor_cst->value_ == vendor) {
375 <<
" and end vendor " << vendor_cst->value_
381 int64_t val = boost::lexical_cast<int64_t>(vendor_str);
382 if ((val < numeric_limits<int32_t>::min()) ||
383 (val > numeric_limits<uint32_t>::max())) {
386 value =
static_cast<uint32_t
>(val);
390 if (vendor == value) {
395 <<
" and end vendor " << value <<
" do not match");
406 if (!ifs.is_open()) {
416 }
catch (
const exception& ex) {
418 isc_throw(BadValue, ex.what() <<
" in dictionary '" << path <<
"'"
419 << (depth > 0 ?
"," :
""));
436 }
catch (
const exception& ex) {
443 for (
auto const& it : defs) {
450 if (def->type_ != it.type_) {
452 <<
"for '" << it.name_ <<
"': type is "
453 <<
static_cast<unsigned>(def->type_) <<
", must be "
454 <<
static_cast<unsigned>(it.type_));
456 if (def->value_type_ != it.value_type_) {
458 <<
"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.
AttrValueType
Attribute value types.
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.
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.