Kea: isc::data::SimpleParser Class Reference

| Kea 2.2.0

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
isc::data::SimpleParser Class Reference

A simple parser. More...

`#include <simple_parser.h>`

Inheritance diagram for isc::data::SimpleParser:
[legend]

## 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...
const isc::util::Triplet< uint32_t > | parseIntTriplet (const data::ConstElementPtr &scope, const std::string &name)
| Parses an integer triplet. More...

## Static Public Member Functions
static void | checkKeywords (const SimpleKeywords &keywords, isc::data::ConstElementPtr scope)
| Checks acceptable keywords with their expected type. More...
static void | checkRequired (const SimpleRequiredKeywords &required, isc::data::ConstElementPtr scope)
| Checks that all required keywords are present. More...
static size_t | deriveParams (isc::data::ConstElementPtr parent, isc::data::ElementPtr child, const ParamsList &params)
| 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 double | getDouble (const ConstElementPtr &scope, const std::string &name)
| Returns a floating point 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 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. 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...

## 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

  keywords | The `SimpleKeywords` keywords and types map.
  scope | Specified parameters which are checked.

Exceptions

  DhcpConfigError | if a not acceptable keyword is found.
  DhcpConfigError | if an acceptable entry does not have the expected type.

Definition at line 36 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::dhcp::Subnet4ConfigParser::parse(), isc::dhcp::Subnet6ConfigParser::parse(), isc::dhcp::OptionDefParser::parse(), isc::dhcp::OptionDataParser::parse(), isc::dhcp::PdPoolParser::parse(), and isc::dhcp::PoolParser::parse().

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

  required | Required keywords.
  scope | Specified parameters which are checked.

Exceptions

  DhcpConfigError | if a required parameter is not present.

Definition at line 25 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

  parent | scope to copy from (e.g. global)
  child | scope to copy from (e.g. subnet)
  params | names of the parameters to copy

Returns
  number of parameters copied

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

References isc::data::Element::map.

Referenced by 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

  scope | specified parameter will be extracted from this scope
  name | name of the parameter

Returns
  an IOAddress representing the value of the parameter

Exceptions

  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 126 of file lib/cc/simple_parser.cc.

References getPosition(), getString(), isc_throw, and isc::Exception::what().

Referenced by 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_type | the type of the result
  convert | the conversion function std::string -> target_type

Parameters

  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

Returns
  a converted value of target_type

Exceptions

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

Here is the call graph for this function:

## ◆ getBoolean()

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

Returns a boolean parameter from a scope.

Unconditionally returns a parameter.

Parameters

  scope | specified parameter will be extracted from this scope
  name | name of the parameter

Returns
  a boolean value of the parameter

Exceptions

  DhcpConfigError | if the parameter is not there or is not of appropriate type

Definition at line 109 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::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::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().

## ◆ 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

  scope | specified parameter will be extracted from this scope
  name | name of the parameter

Returns
  a double value of the parameter

Exceptions

  DhcpConfigError | if the parameter is not there or is not an Element::real

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

References isc_throw, and isc::data::Element::real.

Referenced by isc::dhcp::BaseNetworkParser::parseCacheParams(), and isc::dhcp::BaseNetworkParser::parseTeePercents().

## ◆ getInteger() [1/2]

int64_t isc::data::SimpleParser::getInteger | ( | isc::data::ConstElementPtr | scope,
|  | const std::string & | name
| ) |  |
| static

Returns an integer parameter from a scope.

Unconditionally returns a parameter.

Parameters

  scope | specified parameter will be extracted from this scope
  name | name of the parameter

Returns
  an integer value of the parameter

Exceptions

  DhcpConfigError | if the parameter is not there or is not of appropriate type

Definition at line 78 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::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(), and parseIntTriplet().

## ◆ 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

  scope | specified parameter will be extracted from this scope
  name | name of the parameter
  min | minimum allowed value
  max | maximum allowed value

Returns
  an integer value of the parameter

Exceptions

  DhcpConfigError | if the parameter is not there or is not of appropriate type.
  OutOfRange | if the parameter is out of range

Definition at line 95 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_type | the integer type e.g. uint32_t

Parameters

  scope | specified parameter will be extracted from this scope
  name | name of the parameter for error report

Returns
  a value of int_type

Exceptions

  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.

Here is the call graph for this function:

## ◆ getPosition()

const data::Element::Position & isc::data::SimpleParser::getPosition | ( | const std::string & | name,
|  | const data::ConstElementPtr | parent
| ) |  |
| 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.

Parameters

  name | position of that element will be returned
  parent | parent element (optional)

Returns
  position of the element specified.

Definition at line 159 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::BaseNetworkParser::moveReservationMode(), 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(), and isc::dhcp::MultiThreadingConfigParser::parse().

Here is the call graph for this function:

## ◆ 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

  scope | specified parameter will be extracted from this scope
  name | name of the parameter

Returns
  a string value of the parameter

Exceptions

  DhcpConfigError | if the parameter is not there or is not of appropriate type

Definition at line 61 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::BaseNetworkParser::moveReservationMode(), isc::dhcp::ClientClassDefParser::parse(), isc::dhcp::DUIDConfigParser::parse(), isc::dhcp::SharedNetwork4Parser::parse(), isc::dhcp::SharedNetwork6Parser::parse(), isc::dhcp::RelayInfoParser::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(), and isc::dhcp::BaseNetworkParser::parseDdnsParams().

## ◆ 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

  scope | specified parameter will be extracted from this scope
  name | name of the parameter

Returns
  an uint16_t value

Exceptions

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

## ◆ 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

  scope | specified parameter will be extracted from this scope
  name | name of the parameter

Returns
  an uint32_t value

Exceptions

  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::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

  scope | specified parameter will be extracted from this scope
  name | name of the parameter

Returns
  uint8_t value

Exceptions

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

## ◆ 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

  scope | Data element holding e.g. shared network configuration to be parsed.
  name | Base name of the parameter.

Returns
  A triplet with the parsed value.

Definition at line 287 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

  scope | default values will be inserted here
  default_values | list of default values

Returns
  number of parameters inserted

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

References isc::data::Element::boolean, isc::data::Element::integer, isc_throw, isc::data::SimpleDefault::name_, isc::data::Element::real, isc::data::Element::string, isc::data::SimpleDefault::type_, and isc::data::SimpleDefault::value_.

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

  list | list to be iterated over
  default_values | list of default values

Returns
  number of parameters inserted

Definition at line 245 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:

- lib/cc/simple_parser.h
- lib/cc/simple_parser.cc