Kea 2.7.4
|
A simple parser. More...
#include <simple_parser.h>
Public Member Functions | |
uint16_t | getUint16 (isc::data::ConstElementPtr scope, const std::string &name) |
Returns a value converted to uint16_t. | |
uint32_t | getUint32 (isc::data::ConstElementPtr scope, const std::string &name) |
Returns a value converted to uint32_t. | |
uint8_t | getUint8 (ConstElementPtr scope, const std::string &name) |
Get an uint8_t value. | |
const isc::util::Triplet< uint32_t > | parseIntTriplet (const data::ConstElementPtr &scope, const std::string &name) |
Parses an integer triplet. | |
Static Public Member Functions | |
static void | checkKeywords (const SimpleKeywords &keywords, isc::data::ConstElementPtr scope) |
Checks acceptable keywords with their expected type. | |
static void | checkRequired (const SimpleRequiredKeywords &required, isc::data::ConstElementPtr scope) |
Checks that all required keywords are present. | |
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 isc::asiolink::IOAddress | getAddress (const ConstElementPtr &scope, const std::string &name) |
Returns a IOAddress parameter from a scope. | |
static bool | getBoolean (isc::data::ConstElementPtr scope, const std::string &name) |
Returns a boolean parameter from a scope. | |
static double | getDouble (const ConstElementPtr &scope, const std::string &name) |
Returns a floating point parameter from a scope. | |
static int64_t | getInteger (isc::data::ConstElementPtr scope, const std::string &name) |
Returns an integer parameter from a scope. | |
static int64_t | getInteger (isc::data::ConstElementPtr scope, const std::string &name, int64_t min, int64_t max) |
Returns an integer parameter from a scope and checks its range. | |
static const data::Element::Position & | getPosition (const std::string &name, const data::ConstElementPtr parent) |
Utility method that returns position of an element. | |
static std::string | getString (isc::data::ConstElementPtr scope, const std::string &name) |
Returns a string parameter from a scope. | |
static size_t | setDefaults (isc::data::ElementPtr scope, const SimpleDefaults &default_values) |
Sets the default values. | |
static size_t | setListDefaults (isc::data::ConstElementPtr list, const SimpleDefaults &default_values) |
Sets the default values for all entries in a list. | |
Protected Member Functions | |
template<typename target_type , target_type convert> | |
target_type | getAndConvert (isc::data::ConstElementPtr scope, const std::string &name, const std::string &type_name) |
Returns a converted value from a scope. | |
template<typename int_type > | |
int_type | getIntType (isc::data::ConstElementPtr scope, const std::string &name) |
Returns an integer value with range checking from a scope. | |
A simple parser.
This class is intended to be a simpler replacement for DhcpConfigParser. This class has been initially created to facilitate DHCPv4 and DHCPv6 servers' configuration parsing. Thus examples provided herein are related to DHCP configuration. Nevertheless, this is a generic class to be used in other modules too.
The simplification comes from several factors:
Definition at line 68 of file lib/cc/simple_parser.h.
|
static |
Checks acceptable keywords with their expected type.
This methods throws an exception when a not acceptable keyword is found or when an acceptable entry does not have the expected type.
keywords | The SimpleKeywords keywords and types map. |
scope | Specified parameters which are checked. |
DhcpConfigError | if a not acceptable keyword is found. |
DhcpConfigError | if an acceptable entry does not have the expected type. |
Definition at line 35 of file lib/cc/simple_parser.cc.
References isc::data::Element::any, isc::data::Element::integer, isc_throw, and isc::data::Element::typeToName().
Referenced by isc::dhcp::SharedNetwork4Parser::parse(), isc::dhcp::SharedNetwork6Parser::parse(), isc::perfmon::PerfMonConfig::parse(), isc::perfmon::DurationKeyParser::parse(), isc::perfmon::AlarmParser::parse(), isc::dhcp::Subnet4ConfigParser::parse(), isc::dhcp::Subnet6ConfigParser::parse(), isc::dhcp::OptionDefParser::parse(), isc::dhcp::OptionDataParser::parse(), isc::dhcp::PdPoolParser::parse(), isc::dhcp::PoolParser::parse(), isc::perfmon::PerfMonMgr::perfmonControlHandler(), and isc::perfmon::PerfMonMgr::perfmonGetAllDurationsHandler().
|
static |
Checks that all required keywords are present.
This method throws an exception when a required entry is not present in the given scope.
required | Required keywords. |
scope | Specified parameters which are checked. |
DhcpConfigError | if a required parameter is not present. |
Definition at line 24 of file lib/cc/simple_parser.cc.
References isc_throw.
|
static |
Derives (inherits) parameters from parent scope to a child.
This method derives parameters from the parent scope to the child, if there are no values specified in the child scope. For example, this method can be used to derive timers from global scope (e.g. for the whole DHCPv6 server) to a subnet scope. This method checks if the child scope doesn't have more specific values defined. If it doesn't, then the value from parent scope is copied over.
parent | scope to copy from (e.g. global) |
child | scope to copy from (e.g. subnet) |
params | names of the parameters to copy |
Definition at line 254 of file lib/cc/simple_parser.cc.
References isc::data::Element::map.
Referenced by isc::netconf::NetconfSimpleParser::deriveParameters(), isc::dhcp::SimpleParser4::deriveParameters(), and isc::dhcp::SimpleParser6::deriveParameters().
|
static |
Returns a IOAddress parameter from a scope.
Unconditionally returns a parameter.
scope | specified parameter will be extracted from this scope |
name | name of the parameter |
DhcpConfigError | if the parameter is not there or is not of appropriate type (or its conversion to IOAddress fails due to not being a proper address). |
Definition at line 125 of file lib/cc/simple_parser.cc.
References getPosition(), getString(), and isc_throw.
Referenced by isc::d2::D2SimpleParser::parse(), isc::dhcp::D2ClientConfigParser::parse(), isc::lease_cmds::Lease4Parser::parse(), and isc::lease_cmds::Lease6Parser::parse().
|
inlineprotected |
Returns a converted value from a scope.
This template should be instantiated in parsers when useful
target_type | the type of the result |
convert | the conversion function std::string -> target_type |
scope | specified parameter will be extracted from this scope |
name | name of the parameter for error report |
type_name | name of target_type for error report |
DhcpConfigError | if the parameter is not there, is not of appropriate type or can not be converted |
Definition at line 269 of file lib/cc/simple_parser.h.
References getPosition(), getString(), and isc_throw.
Referenced by isc::dhcp::BaseNetworkParser::parseDdnsParams().
|
static |
Returns a boolean parameter from a scope.
Unconditionally returns a parameter.
scope | specified parameter will be extracted from this scope |
name | name of the parameter |
DhcpConfigError | if the parameter is not there or is not of appropriate type |
Definition at line 108 of file lib/cc/simple_parser.cc.
References isc::data::Element::boolean, and isc_throw.
Referenced by isc::dhcp::IfaceMgr::configureDHCPPacketQueue(), isc::dhcp::CfgMultiThreading::extract(), isc::dhcp::OptionDataParser::extractCancelled(), isc::dhcp::OptionDataParser::extractCSVFormat(), isc::dhcp::OptionDataParser::extractPersistent(), isc::dhcp::Subnet4ConfigParser::initSubnet(), isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::dhcp::ClientClassDefParser::parse(), isc::dhcp::DUIDConfigParser::parse(), isc::dhcp::IfacesConfigParser::parse(), isc::agent::AgentSimpleParser::parse(), isc::dhcp::SharedNetwork4Parser::parse(), isc::dhcp::SharedNetwork6Parser::parse(), isc::dhcp::DHCPQueueControlParser::parse(), isc::netconf::ServerConfigParser::parse(), isc::dhcp::D2ClientConfigParser::parse(), isc::dhcp::OptionDefParser::parse(), isc::lease_cmds::Lease4Parser::parse(), isc::lease_cmds::Lease6Parser::parse(), isc::dhcp::MultiThreadingConfigParser::parse(), isc::dhcp::BaseNetworkParser::parseCommon(), isc::dhcp::BaseNetworkParser::parseDdnsParams(), and isc::dhcp::BaseNetworkParser::parseTeePercents().
|
static |
Returns a floating point parameter from a scope.
Unconditionally returns a parameter.
scope | specified parameter will be extracted from this scope |
name | name of the parameter |
DhcpConfigError | if the parameter is not there or is not an Element::real |
Definition at line 138 of file lib/cc/simple_parser.cc.
References isc_throw, and isc::data::Element::real.
Referenced by isc::dhcp::BaseNetworkParser::parseCacheParams(), isc::dhcp::BaseNetworkParser::parseDdnsParams(), and isc::dhcp::BaseNetworkParser::parseTeePercents().
|
static |
Returns an integer parameter from a scope.
Unconditionally returns a parameter.
scope | specified parameter will be extracted from this scope |
name | name of the parameter |
DhcpConfigError | if the parameter is not there or is not of appropriate type |
Definition at line 77 of file lib/cc/simple_parser.cc.
References isc::data::Element::integer, and isc_throw.
Referenced by isc::dhcp::PacketQueueMgr4::PacketQueueMgr4(), isc::dhcp::PacketQueueMgr6::PacketQueueMgr6(), isc::dhcp::CfgMultiThreading::extract(), isc::dhcp::OptionDataParser::extractCode(), getInteger(), getIntType(), isc::dhcp::Subnet4ConfigParser::initSubnet(), isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::dhcp::ClientClassDefParser::parse(), isc::process::ConfigControlParser::parse(), isc::d2::TSIGKeyInfoParser::parse(), isc::d2::DnsServerInfoParser::parse(), isc::dhcp::ExpirationConfigParser::parse(), isc::dhcp::OptionDefParser::parse(), isc::lease_cmds::Lease4Parser::parse(), isc::lease_cmds::Lease6Parser::parse(), isc::dhcp::MultiThreadingConfigParser::parse(), isc::dhcp::BaseNetworkParser::parseCacheParams(), isc::dhcp::BaseNetworkParser::parseCommon(), parseIntTriplet(), and isc::dhcp::BaseNetworkParser::parseOfferLft().
|
static |
Returns an integer parameter from a scope and checks its range.
Unconditionally returns a parameter. Checks that the value specified is in min =< X =< max range.
scope | specified parameter will be extracted from this scope |
name | name of the parameter |
min | minimum allowed value |
max | maximum allowed value |
DhcpConfigError | if the parameter is not there or is not of appropriate type. |
OutOfRange | if the parameter is out of range |
Definition at line 94 of file lib/cc/simple_parser.cc.
References getInteger(), and isc_throw.
|
inlineprotected |
Returns an integer value with range checking from a scope.
This template should be instantiated in parsers when useful
int_type | the integer type e.g. uint32_t |
scope | specified parameter will be extracted from this scope |
name | name of the parameter for error report |
DhcpConfigError | if the parameter is not there, is not of appropriate type or is out of type value range |
Definition at line 242 of file lib/cc/simple_parser.h.
References getInteger(), getPosition(), and isc_throw.
|
static |
Utility method that returns position of an element.
It's mostly useful for logging. If the element is missing the parent position is returned or ZERO_POSITION if parent is null.
name | position of that element will be returned |
parent | parent element (optional) |
Definition at line 158 of file lib/cc/simple_parser.cc.
References isc::data::Element::ZERO_POSITION().
Referenced by isc::dhcp::RelayInfoParser::addAddress(), isc::dhcp::OptionDataParser::createOption(), isc::dhcp::OptionDataParser::extractCode(), isc::dhcp::OptionDataParser::extractName(), isc::dhcp::OptionDataParser::extractSpace(), getAddress(), getAndConvert(), getIntType(), isc::dhcp::ClientClassDefParser::parse(), isc::dhcp::DUIDConfigParser::parse(), isc::dhcp::RelayInfoParser::parse(), isc::netconf::ControlSocketConfigParser::parse(), isc::d2::DdnsDomainListParser::parse(), isc::d2::TSIGKeyInfoParser::parse(), isc::d2::TSIGKeyInfoListParser::parse(), isc::d2::DnsServerInfoParser::parse(), isc::dhcp::D2ClientConfigParser::parse(), isc::dhcp::ExpirationConfigParser::parse(), isc::dhcp::OptionDefParser::parse(), isc::dhcp::MultiThreadingConfigParser::parse(), and isc::dhcp::BaseNetworkParser::parseOfferLft().
|
static |
Returns a string parameter from a scope.
Unconditionally returns a parameter.
scope | specified parameter will be extracted from this scope |
name | name of the parameter |
DhcpConfigError | if the parameter is not there or is not of appropriate type |
Definition at line 60 of file lib/cc/simple_parser.cc.
References isc_throw, and isc::data::Element::string.
Referenced by isc::dhcp::PacketQueueMgr< PacketQueueTypePtr >::createPacketQueue(), isc::dhcp::SubnetConfigParser::createSubnet(), isc::dhcp::OptionDataParser::extractData(), isc::dhcp::OptionDataParser::extractName(), isc::dhcp::OptionDataParser::extractSpace(), getAddress(), getAndConvert(), isc::dhcp::Subnet4ConfigParser::initSubnet(), isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::dhcp::ClientClassDefParser::parse(), isc::dhcp::DUIDConfigParser::parse(), isc::agent::AgentSimpleParser::parse(), isc::dhcp::SharedNetwork4Parser::parse(), isc::dhcp::SharedNetwork6Parser::parse(), isc::netconf::ControlSocketConfigParser::parse(), isc::d2::DdnsDomainParser::parse(), isc::d2::TSIGKeyInfoParser::parse(), isc::netconf::ServerConfigParser::parse(), isc::d2::DnsServerInfoParser::parse(), isc::dhcp::D2ClientConfigParser::parse(), isc::dhcp::OptionDefParser::parse(), isc::lease_cmds::Lease4Parser::parse(), isc::lease_cmds::Lease6Parser::parse(), isc::dhcp::PdPoolParser::parse(), isc::dhcp::BaseNetworkParser::parseAllocatorParams(), isc::dhcp::BaseNetworkParser::parseDdnsParams(), and isc::dhcp::BaseNetworkParser::parsePdAllocatorParams().
|
inline |
Returns a value converted to uint16_t.
Instantiation of getIntType() to uint16_t
scope | specified parameter will be extracted from this scope |
name | name of the parameter |
isc::dhcp::DhcpConfigError | when it is not an uint16_t |
Definition at line 305 of file lib/cc/simple_parser.h.
Referenced by isc::dhcp::DUIDConfigParser::parse().
|
inline |
Returns a value converted to uint32_t.
Instantiation of getIntType() to uint32_t
scope | specified parameter will be extracted from this scope |
name | name of the parameter |
isc::dhcp::DhcpConfigError | when it is not an uint32_t |
Definition at line 292 of file lib/cc/simple_parser.h.
Referenced by isc::lease_cmds::LeaseCmdsImpl::lease4WipeHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6WipeHandler(), isc::dhcp::DUIDConfigParser::parse(), isc::d2::D2SimpleParser::parse(), isc::dhcp::D2ClientConfigParser::parse(), isc::lease_cmds::Lease4Parser::parse(), and isc::lease_cmds::Lease6Parser::parse().
|
inline |
Get an uint8_t value.
Instantiation of getIntType() to uint8_t
scope | specified parameter will be extracted from this scope |
name | name of the parameter |
isc::dhcp::DhcpConfigError | when it is not an uint8_t |
Definition at line 318 of file lib/cc/simple_parser.h.
Referenced by isc::lease_cmds::Lease4Parser::parse(), isc::lease_cmds::Lease6Parser::parse(), and isc::dhcp::PdPoolParser::parse().
const util::Triplet< uint32_t > isc::data::SimpleParser::parseIntTriplet | ( | const data::ConstElementPtr & | scope, |
const std::string & | name ) |
Parses an integer triplet.
Parses an integer triplet parameter of the form:
min-{name}, {name}, max-{name}
scope | Data element holding e.g. shared network configuration to be parsed. |
name | Base name of the parameter. |
Definition at line 286 of file lib/cc/simple_parser.cc.
References getInteger(), and isc_throw.
Referenced by isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::dhcp::ClientClassDefParser::parse(), isc::dhcp::SharedNetwork6Parser::parse(), and isc::dhcp::BaseNetworkParser::parseCommon().
|
static |
Sets the default values.
This method sets the default values for parameters that are not defined. The list of default values is specified by default_values. If not present, those will be inserted into the scope. If a parameter is already present, the default value will not be inserted.
scope | default values will be inserted here |
default_values | list of default values |
Definition at line 170 of file lib/cc/simple_parser.cc.
References isc::data::Element::boolean, isc::data::Element::integer, isc_throw, isc::data::Element::real, and isc::data::Element::string.
Referenced by isc::agent::AgentSimpleParser::setAllDefaults(), isc::netconf::NetconfSimpleParser::setAllDefaults(), isc::d2::D2SimpleParser::setAllDefaults(), isc::dhcp::D2ClientConfigParser::setAllDefaults(), isc::dhcp::SimpleParser4::setAllDefaults(), isc::dhcp::SimpleParser6::setAllDefaults(), isc::d2::D2SimpleParser::setDdnsDomainDefaults(), setListDefaults(), isc::d2::D2SimpleParser::setManagerDefaults(), and isc::netconf::NetconfSimpleParser::setServerDefaults().
|
static |
Sets the default values for all entries in a list.
This is a simple utility method that iterates over all parameters in a list and calls setDefaults for each entry.
list | list to be iterated over |
default_values | list of default values |
Definition at line 244 of file lib/cc/simple_parser.cc.
References setDefaults().
Referenced by isc::dhcp::ClientClassDefParser::parse(), isc::d2::D2SimpleParser::setAllDefaults(), isc::dhcp::SimpleParser4::setAllDefaults(), isc::dhcp::SimpleParser6::setAllDefaults(), and isc::d2::D2SimpleParser::setDdnsDomainDefaults().