Kea 2.7.0
isc::data::SimpleParser Class Reference

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.
 
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 &params)
 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::PositiongetPosition (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.
 

Detailed Description

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:

  • no build/commit nonsense. There's a single step: CfgStorage parse(ConstElementPtr json) that converts JSON configuration into an object and returns it.
  • no state kept. This greatly simplifies the parsers (no contexts, no child parsers list, no separate storage for uint32, strings etc. In fact, this base class is purely static. However, some derived classes may store some state. Implementors are advised to store as little state as possible.
  • no optional parameters (all are mandatory). This simplifies the parser, but introduces a new step before parsing where we insert the default values into client configuration before parsing. This is actually a good thing, because we now have a clear picture of the default parameters as they're defined in a single place (the DhcpConfigParser had the defaults spread out in multiple files in multiple directories).

Definition at line 68 of file lib/cc/simple_parser.h.

Member Function Documentation

◆ checkKeywords()

void isc::data::SimpleParser::checkKeywords ( const SimpleKeywords & keywords,
isc::data::ConstElementPtr scope )
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.

Parameters
keywordsThe SimpleKeywords keywords and types map.
scopeSpecified parameters which are checked.
Exceptions
DhcpConfigErrorif a not acceptable keyword is found.
DhcpConfigErrorif 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().

+ Here is the call graph for this function:

◆ checkRequired()

void isc::data::SimpleParser::checkRequired ( const SimpleRequiredKeywords & required,
isc::data::ConstElementPtr scope )
static

Checks that all required keywords are present.

This method throws an exception when a required entry is not present in the given scope.

Parameters
requiredRequired keywords.
scopeSpecified parameters which are checked.
Exceptions
DhcpConfigErrorif a required parameter is not present.

Definition at line 24 of file lib/cc/simple_parser.cc.

References isc_throw.

◆ deriveParams()

size_t isc::data::SimpleParser::deriveParams ( isc::data::ConstElementPtr parent,
isc::data::ElementPtr child,
const ParamsList & params )
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.

Parameters
parentscope to copy from (e.g. global)
childscope to copy from (e.g. subnet)
paramsnames of the parameters to copy
Returns
number of parameters copied

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().

◆ getAddress()

IOAddress isc::data::SimpleParser::getAddress ( const ConstElementPtr & scope,
const std::string & name )
static

Returns a IOAddress parameter from a scope.

Unconditionally returns a parameter.

Parameters
scopespecified parameter will be extracted from this scope
namename of the parameter
Returns
an IOAddress representing the value of the parameter
Exceptions
DhcpConfigErrorif 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().

+ Here is the call graph for this function:

◆ getAndConvert()

template<typename target_type , target_type convert>
target_type isc::data::SimpleParser::getAndConvert ( isc::data::ConstElementPtr scope,
const std::string & name,
const std::string & type_name )
inlineprotected

Returns a converted value from a scope.

This template should be instantiated in parsers when useful

Template Parameters
target_typethe type of the result
convertthe conversion function std::string -> target_type
Parameters
scopespecified parameter will be extracted from this scope
namename of the parameter for error report
type_namename of target_type for error report
Returns
a converted value of target_type
Exceptions
DhcpConfigErrorif 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().

+ Here is the call graph for this function:

◆ getBoolean()

bool isc::data::SimpleParser::getBoolean ( isc::data::ConstElementPtr scope,
const std::string & name )
static

◆ getDouble()

double isc::data::SimpleParser::getDouble ( const ConstElementPtr & scope,
const std::string & name )
static

Returns a floating point parameter from a scope.

Unconditionally returns a parameter.

Parameters
scopespecified parameter will be extracted from this scope
namename of the parameter
Returns
a double value of the parameter
Exceptions
DhcpConfigErrorif 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().

◆ getInteger() [1/2]

◆ getInteger() [2/2]

int64_t isc::data::SimpleParser::getInteger ( isc::data::ConstElementPtr scope,
const std::string & name,
int64_t min,
int64_t max )
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.

Parameters
scopespecified parameter will be extracted from this scope
namename of the parameter
minminimum allowed value
maxmaximum allowed value
Returns
an integer value of the parameter
Exceptions
DhcpConfigErrorif the parameter is not there or is not of appropriate type.
OutOfRangeif the parameter is out of range

Definition at line 94 of file lib/cc/simple_parser.cc.

References getInteger(), and isc_throw.

+ Here is the call graph for this function:

◆ getIntType()

template<typename int_type >
int_type isc::data::SimpleParser::getIntType ( isc::data::ConstElementPtr scope,
const std::string & name )
inlineprotected

Returns an integer value with range checking from a scope.

This template should be instantiated in parsers when useful

Template Parameters
int_typethe integer type e.g. uint32_t
Parameters
scopespecified parameter will be extracted from this scope
namename of the parameter for error report
Returns
a value of int_type
Exceptions
DhcpConfigErrorif 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.

+ Here is the call graph for this function:

◆ getPosition()

◆ getString()

std::string isc::data::SimpleParser::getString ( isc::data::ConstElementPtr scope,
const std::string & name )
static

Returns a string parameter from a scope.

Unconditionally returns a parameter.

Parameters
scopespecified parameter will be extracted from this scope
namename of the parameter
Returns
a string value of the parameter
Exceptions
DhcpConfigErrorif 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().

◆ getUint16()

uint16_t isc::data::SimpleParser::getUint16 ( isc::data::ConstElementPtr scope,
const std::string & name )
inline

Returns a value converted to uint16_t.

Instantiation of getIntType() to uint16_t

Parameters
scopespecified parameter will be extracted from this scope
namename of the parameter
Returns
an uint16_t value
Exceptions
isc::dhcp::DhcpConfigErrorwhen it is not an uint16_t

Definition at line 305 of file lib/cc/simple_parser.h.

Referenced by isc::dhcp::DUIDConfigParser::parse().

◆ getUint32()

uint32_t isc::data::SimpleParser::getUint32 ( isc::data::ConstElementPtr scope,
const std::string & name )
inline

Returns a value converted to uint32_t.

Instantiation of getIntType() to uint32_t

Parameters
scopespecified parameter will be extracted from this scope
namename of the parameter
Returns
an uint32_t value
Exceptions
isc::dhcp::DhcpConfigErrorwhen 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().

◆ getUint8()

uint8_t isc::data::SimpleParser::getUint8 ( ConstElementPtr scope,
const std::string & name )
inline

Get an uint8_t value.

Instantiation of getIntType() to uint8_t

Parameters
scopespecified parameter will be extracted from this scope
namename of the parameter
Returns
uint8_t value
Exceptions
isc::dhcp::DhcpConfigErrorwhen 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().

◆ parseIntTriplet()

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}

Parameters
scopeData element holding e.g. shared network configuration to be parsed.
nameBase name of the parameter.
Returns
A triplet with the parsed value.

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().

+ Here is the call graph for this function:

◆ setDefaults()

size_t isc::data::SimpleParser::setDefaults ( isc::data::ElementPtr scope,
const SimpleDefaults & default_values )
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.

Parameters
scopedefault values will be inserted here
default_valueslist of default values
Returns
number of parameters inserted

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().

◆ setListDefaults()

size_t isc::data::SimpleParser::setListDefaults ( isc::data::ConstElementPtr list,
const SimpleDefaults & default_values )
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.

Parameters
listlist to be iterated over
default_valueslist of default values
Returns
number of parameters inserted

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().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: