![]() |
Kea
1.5.0
|
A simple parser. More...
#include <simple_parser.h>
Inheritance diagram for isc::data::SimpleParser:Public Member Functions | |
| uint16_t | getUint16 (isc::data::ConstElementPtr scope, const std::string &name) |
| Returns a value converted to uint16_t. More... | |
| uint32_t | getUint32 (isc::data::ConstElementPtr scope, const std::string &name) |
| Returns a value converted to uint32_t. More... | |
| uint8_t | getUint8 (ConstElementPtr scope, const std::string &name) |
| Get an uint8_t value. More... | |
Static Public Member Functions | |
| static size_t | deriveParams (isc::data::ConstElementPtr parent, isc::data::ElementPtr child, const ParamsList ¶ms) |
| Derives (inherits) parameters from parent scope to a child. More... | |
| static isc::asiolink::IOAddress | getAddress (const ConstElementPtr &scope, const std::string &name) |
| Returns a IOAddress parameter from a scope. More... | |
| static bool | getBoolean (isc::data::ConstElementPtr scope, const std::string &name) |
| Returns a boolean parameter from a scope. More... | |
| static int64_t | getInteger (isc::data::ConstElementPtr scope, const std::string &name) |
| Returns an integer parameter from a scope. More... | |
| static const data::Element::Position & | getPosition (const std::string &name, const data::ConstElementPtr parent) |
| Utility method that returns position of an element. More... | |
| static std::string | getString (isc::data::ConstElementPtr scope, const std::string &name) |
| Returns a string parameter from a scope. More... | |
| static size_t | setDefaults (isc::data::ElementPtr scope, const SimpleDefaults &default_values) |
| Sets the default values. More... | |
| static size_t | setListDefaults (isc::data::ConstElementPtr list, const SimpleDefaults &default_values) |
| Sets the default values for all entries in a list. More... | |
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. More... | |
| 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. More... | |
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 60 of file lib/cc/simple_parser.h.
|
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 183 of file lib/cc/simple_parser.cc.
Referenced by isc::dhcp::SimpleParser4::deriveParameters(), isc::dhcp::SimpleParser6::deriveParameters(), and isc::netconf::NetconfSimpleParser::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 75 of file lib/cc/simple_parser.cc.
References isc_throw, and isc::Exception::what().
Referenced by isc::d2::D2SimpleParser::parse(), and isc::dhcp::D2ClientConfigParser::parse().
Here is the call graph for this function:
|
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 208 of file lib/cc/simple_parser.h.
References getPosition(), getString(), and isc_throw.
Here is the call graph for this function:
|
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 58 of file lib/cc/simple_parser.cc.
References isc_throw.
Referenced by isc::dhcp::IfaceMgr::configureDHCPPacketQueue(), isc::dhcp::Subnet4ConfigParser::initSubnet(), isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::dhcp::IfacesConfigParser::parse(), isc::netconf::ServerConfigParser::parse(), and isc::dhcp::D2ClientConfigParser::parse().
|
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 41 of file lib/cc/simple_parser.cc.
References isc_throw.
Referenced by getIntType(), isc::dhcp::Subnet4ConfigParser::initSubnet(), isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::dhcp::PacketQueueMgr4::PacketQueueMgr4(), isc::dhcp::PacketQueueMgr6::PacketQueueMgr6(), isc::d2::TSIGKeyInfoParser::parse(), and isc::d2::DnsServerInfoParser::parse().
|
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 181 of file lib/cc/simple_parser.h.
References getInteger(), getPosition(), and isc_throw.
Here is the call graph for this function:
|
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 88 of file lib/cc/simple_parser.cc.
Referenced by isc::dhcp::RelayInfoParser::addAddress(), getAndConvert(), getIntType(), isc::dhcp::Subnet4ConfigParser::initSubnet(), isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::netconf::ControlSocketConfigParser::parse(), isc::dhcp::RelayInfoParser::parse(), isc::d2::TSIGKeyInfoParser::parse(), isc::d2::TSIGKeyInfoListParser::parse(), isc::d2::DnsServerInfoParser::parse(), isc::dhcp::D2ClientConfigParser::parse(), isc::d2::DdnsDomainParser::parse(), and isc::d2::DdnsDomainListParser::parse().
|
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 24 of file lib/cc/simple_parser.cc.
References isc_throw.
Referenced by isc::dhcp::PacketQueueMgr< PacketQueue4Ptr >::createPacketQueue(), getAndConvert(), isc::dhcp::Subnet4ConfigParser::initSubnet(), isc::dhcp::Subnet6ConfigParser::initSubnet(), isc::agent::AgentSimpleParser::parse(), isc::netconf::ControlSocketConfigParser::parse(), isc::netconf::ServerConfigParser::parse(), isc::dhcp::RelayInfoParser::parse(), isc::dhcp::PdPoolParser::parse(), isc::d2::TSIGKeyInfoParser::parse(), isc::d2::DnsServerInfoParser::parse(), isc::dhcp::D2ClientConfigParser::parse(), and isc::d2::DdnsDomainParser::parse().
|
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 244 of file lib/cc/simple_parser.h.
|
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 231 of file lib/cc/simple_parser.h.
Referenced by isc::lease_cmds::LeaseCmdsImpl::lease4WipeHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6WipeHandler(), isc::d2::D2SimpleParser::parse(), and isc::dhcp::D2ClientConfigParser::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 257 of file lib/cc/simple_parser.h.
Referenced by isc::dhcp::PdPoolParser::parse().
|
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 99 of file lib/cc/simple_parser.cc.
References isc_throw, isc::data::SimpleDefault::name_, isc::data::SimpleDefault::type_, and isc::data::SimpleDefault::value_.
Referenced by isc::dhcp::SimpleParser4::setAllDefaults(), isc::dhcp::SimpleParser6::setAllDefaults(), and isc::agent::AgentSimpleParser::setAllDefaults().
|
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 173 of file lib/cc/simple_parser.cc.
Referenced by isc::dhcp::ClientClassDefParser::parse().