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
112 "missing parameter '" << name <<
"' ("
113 << scope->getPosition() <<
")");
117 "invalid type specified for parameter '" << name
118 <<
"' (" << x->getPosition() <<
")");
121 return (x->boolValue());
126 const std::string& name) {
127 std::string str =
getString(scope, name);
130 }
catch (
const std::exception& e) {
132 <<
"' to address: " << e.
what() <<
"("
139 const std::string& name) {
143 "missing parameter '" << name <<
"' ("
144 << scope->getPosition() <<
")");
149 "invalid type specified for parameter '" << name
150 <<
"' (" << x->getPosition() <<
")");
153 return (x->doubleValue());
164 return (parent->getPosition());
166 return (elem->getPosition());
191 switch (def_value.
type_) {
198 int int_value = boost::lexical_cast<int>(def_value.
value_);
201 catch (
const std::exception& ex) {
203 << def_value.
name_ <<
", value is: "
211 if (def_value.
value_ ==
string(
"true")) {
213 }
else if (def_value.
value_ ==
string(
"false")) {
217 "Internal error. Boolean value specified as "
218 << def_value.
value_ <<
", expected true or false");
224 double dbl_value = boost::lexical_cast<double>(def_value.
value_);
231 "Internal error. Incorrect default value type.");
235 scope->set(def_value.
name_, x);
246 BOOST_FOREACH(
ElementPtr entry, list->listValue()) {
262 BOOST_FOREACH(
string param, params) {
270 if (child->get(param)) {
277 child->set(param, x);
286 const std::string& name) {
289 bool has_value =
false;
290 uint32_t min_value = 0;
291 bool has_min =
false;
292 uint32_t max_value = 0;
293 bool has_max =
false;
294 if (scope->contains(name)) {
298 if (scope->contains(
"min-" + name)) {
302 if (scope->contains(
"max-" + name)) {
306 if (!has_value && !has_min && !has_max) {
310 if (!has_min && !has_max) {
314 }
else if (!has_min) {
317 }
else if (!has_max) {
321 }
else if (has_min) {
325 max_value = min_value;
329 << name <<
" but no " << name <<
" (default) in "
330 << scope->getPosition());
334 min_value = max_value;
338 if (min_value > max_value) {
339 if (has_min && has_max) {
341 << min_value <<
") is not less than max-" << name <<
" ("
342 << max_value <<
")");
343 }
else if (has_min) {
346 << min_value <<
") is not less than (default) " << name
347 <<
" (" << value <<
")");
351 <<
" (" << value <<
") is not less than max-" << name
352 <<
" (" << max_value <<
")");
356 if ((value < min_value) || (value > max_value)) {
358 << value <<
") is not between min-" << name <<
" ("
359 << min_value <<
") and max-" << name <<
" ("
360 << 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)
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.
const dhcp::Triplet< uint32_t > parseIntTriplet(const data::ConstElementPtr &scope, const std::string &name)
Parses an integer triplet.
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.
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.
This template specifies a parameter value.
#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_