11#include <boost/foreach.hpp>
12#include <boost/lexical_cast.hpp>
27 for (
auto name : required) {
28 if (scope->contains(name)) {
39 for (
auto entry : scope->mapValue()) {
40 if (keywords.count(entry.first) == 0) {
41 if (spurious.empty()) {
42 spurious = entry.first;
48 (entry.second->getType() == expected)) {
55 if (!spurious.empty()) {
65 "missing parameter '" << name <<
"' ("
66 << scope->getPosition() <<
")");
70 "invalid type specified for parameter '" << name
71 <<
"' (" << x->getPosition() <<
")");
74 return (x->stringValue());
82 "missing parameter '" << name <<
"' ("
83 << scope->getPosition() <<
")");
87 "invalid type specified for parameter '" << name
88 <<
"' (" << x->getPosition() <<
")");
91 return (x->intValue());
96 int64_t min, int64_t max) {
98 if (tmp < min || tmp > max) {
100 "The '" << name <<
"' value (" << tmp
101 <<
") is not within expected range: (" << min <<
" - " << max
113 "missing parameter '" << name <<
"' ("
114 << scope->getPosition() <<
")");
118 "invalid type specified for parameter '" << name
119 <<
"' (" << x->getPosition() <<
")");
122 return (x->boolValue());
127 const std::string& name) {
128 std::string str =
getString(scope, name);
131 }
catch (
const std::exception& e) {
133 <<
"' to address: " << e.
what() <<
"("
140 const std::string& name) {
144 "missing parameter '" << name <<
"' ("
145 << scope->getPosition() <<
")");
150 "invalid type specified for parameter '" << name
151 <<
"' (" << x->getPosition() <<
")");
154 return (x->doubleValue());
165 return (parent->getPosition());
168 return (elem->getPosition());
193 switch (def_value.
type_) {
200 int int_value = boost::lexical_cast<int>(def_value.
value_);
203 catch (
const std::exception& ex) {
205 << def_value.
name_ <<
", value is: "
213 if (def_value.
value_ ==
string(
"true")) {
215 }
else if (def_value.
value_ ==
string(
"false")) {
219 "Internal error. Boolean value specified as "
220 << def_value.
value_ <<
", expected true or false");
226 double dbl_value = boost::lexical_cast<double>(def_value.
value_);
233 "Internal error. Incorrect default value type.");
237 scope->set(def_value.
name_, x);
248 BOOST_FOREACH(
ElementPtr entry, list->listValue()) {
264 BOOST_FOREACH(
string param, params) {
272 if (child->get(param)) {
279 child->set(param, x);
288 const std::string& name) {
291 bool has_value =
false;
292 uint32_t min_value = 0;
293 bool has_min =
false;
294 uint32_t max_value = 0;
295 bool has_max =
false;
296 if (scope->contains(name)) {
300 if (scope->contains(
"min-" + name)) {
304 if (scope->contains(
"max-" + name)) {
308 if (!has_value && !has_min && !has_max) {
312 if (!has_min && !has_max) {
316 }
else if (!has_min) {
319 }
else if (!has_max) {
323 }
else if (has_min) {
327 max_value = min_value;
331 << name <<
" but no " << name <<
" (default) in "
332 << scope->getPosition());
336 min_value = max_value;
340 if (min_value > max_value) {
341 if (has_min && has_max) {
343 << min_value <<
") is not less than max-" << name <<
" ("
344 << max_value <<
")");
345 }
else if (has_min) {
348 << min_value <<
") is not less than (default) " << name
349 <<
" (" << value <<
")");
353 <<
" (" << value <<
") is not less than max-" << name
354 <<
" (" << max_value <<
")");
358 if ((value < min_value) || (value > max_value)) {
360 << value <<
") is not between min-" << name <<
" ("
361 << min_value <<
") and max-" << name <<
" ("
362 << max_value <<
")");
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
The IOAddress class represents an IP addresses (version agnostic)
types
The types that an Element can hold.
static std::string typeToName(Element::types type)
Returns the name of the given type as a string.
static const Position & ZERO_POSITION()
Returns Position object with line_ and pos_ set to 0, and with an empty file name.
Notes: IntElement type is changed to int64_t.
static void checkKeywords(const SimpleKeywords &keywords, isc::data::ConstElementPtr scope)
Checks acceptable keywords with their expected type.
static size_t setListDefaults(isc::data::ConstElementPtr list, const SimpleDefaults &default_values)
Sets the default values for all entries in a list.
static const data::Element::Position & getPosition(const std::string &name, const data::ConstElementPtr parent)
Utility method that returns position of an element.
static double getDouble(const ConstElementPtr &scope, const std::string &name)
Returns a floating point parameter from a scope.
static void checkRequired(const SimpleRequiredKeywords &required, isc::data::ConstElementPtr scope)
Checks that all required keywords are present.
static isc::asiolink::IOAddress getAddress(const ConstElementPtr &scope, const std::string &name)
Returns a IOAddress parameter from a scope.
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
const isc::util::Triplet< uint32_t > parseIntTriplet(const data::ConstElementPtr &scope, const std::string &name)
Parses an integer triplet.
static bool getBoolean(isc::data::ConstElementPtr scope, const std::string &name)
Returns a boolean parameter from a scope.
static size_t deriveParams(isc::data::ConstElementPtr parent, isc::data::ElementPtr child, const ParamsList ¶ms)
Derives (inherits) parameters from parent scope to a child.
static int64_t getInteger(isc::data::ConstElementPtr scope, const std::string &name)
Returns an integer parameter from a scope.
static size_t setDefaults(isc::data::ElementPtr scope, const SimpleDefaults &default_values)
Sets the default values.
To be removed. Please use ConfigError instead.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::vector< std::string > SimpleRequiredKeywords
This specifies all required keywords.
std::vector< std::string > ParamsList
This defines a list of all parameters that are derived (or inherited) between contexts.
boost::shared_ptr< const Element > ConstElementPtr
std::vector< SimpleDefault > SimpleDefaults
This specifies all default values in a given scope (e.g. a subnet).
boost::shared_ptr< Element > ElementPtr
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
Defines the logger used by the top-level component of kea-lfc.
Represents the position of the data element within a configuration string.
This array defines a single entry of default values.
const isc::data::Element::types type_