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;
47 if ((expected == Element::any) ||
48 (entry.second->getType() == expected)) {
52 << (expected == Element::integer ?
"an " :
"a ")
53 << Element::typeToName(expected));
55 if (!spurious.empty()) {
65 "missing parameter '" << name <<
"' ("
66 << scope->getPosition() <<
")");
68 if (x->getType() != Element::string) {
70 "invalid type specified for parameter '" << name
71 <<
"' (" << x->getPosition() <<
")");
74 return (x->stringValue());
82 "missing parameter '" << name <<
"' ("
83 << scope->getPosition() <<
")");
85 if (x->getType() != Element::integer) {
87 "invalid type specified for parameter '" << name
88 <<
"' (" << x->getPosition() <<
")");
91 return (x->intValue());
96 int64_t min, int64_t max) {
97 int64_t tmp = getInteger(scope, name);
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() <<
")");
115 if (x->getType() != Element::boolean) {
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() <<
"("
133 << getPosition(name, scope) <<
")");
139 const std::string& name) {
143 "missing parameter '" << name <<
"' ("
144 << scope->getPosition() <<
")");
147 if (x->getType() != Element::real) {
149 "invalid type specified for parameter '" << name
150 <<
"' (" << x->getPosition() <<
")");
153 return (x->doubleValue());
160 return (data::Element::ZERO_POSITION());
164 return (parent->getPosition());
166 return (elem->getPosition());
191 switch (def_value.
type_) {
192 case Element::string: {
196 case Element::integer: {
198 int int_value = boost::lexical_cast<
int>(def_value.
value_);
201 catch (
const std::exception& ex) {
203 << def_value.
name_ <<
", value is: "
209 case Element::boolean: {
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");
223 case Element::real: {
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()) {
247 cnt += setDefaults(entry, default_values);
256 if ( (parent->getType() != Element::map) ||
257 (child->getType() != Element::map)) {
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)) {
295 value = getInteger(scope, name);
298 if (scope->contains(
"min-" + name)) {
299 min_value = getInteger(scope,
"min-" + name);
302 if (scope->contains(
"max-" + name)) {
303 max_value = getInteger(scope,
"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 <<
")");
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
std::vector< SimpleDefault > SimpleDefaults
This specifies all default values in a given scope (e.g. a subnet).
boost::shared_ptr< Element > ElementPtr
const isc::data::Element::types type_
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
To be removed. Please use ConfigError instead.
Notes: IntElement type is changed to int64_t.
boost::shared_ptr< const Element > ConstElementPtr
std::vector< std::string > SimpleRequiredKeywords
This specifies all required keywords.
This array defines a single entry of default values.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Represents the position of the data element within a configuration string.
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::vector< std::string > ParamsList
This defines a list of all parameters that are derived (or inherited) between contexts.
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)