Kea 3.3.4
isc::cb::ConfigCmdsParser Class Reference

This parser class contains the common logic for various callouts to parse and validate the contents of the received command. More...

#include <cb_cmds_impl.h>

Public Types

enum  ServerTagsParse : uint16_t { TAGS_OPTIONAL , TAGS_REQUIRED , TAGS_FORBIDDEN }
 Server selector parsing. More...
enum  SubnetsAction : uint16_t { ACTION_KEEP , ACTION_DELETE }
 Subnets actions for shared network delete. More...
enum  SubnetsInclude : uint16_t { INCLUDE_NO , INCLUDE_FULL }
 Subnets actions for shared network get command. More...

Public Member Functions

db::BackendSelector getBackendSelector (const data::ConstElementPtr &args) const
 Creates backend selector from the command's arguments.
db::ServerSelector getServerSelector (const data::ConstElementPtr &args, ServerTagsParse tags_parse) const
 Creates server selector from the command's arguments.
template<typename SubnetPtrType, typename KeyType>
void getSubnetCommon (hooks::CalloutHandle &callout_handle, const SubnetPtrType &subnet, const uint16_t address_family, const KeyType &key)
 Common routine invoked when getting a subnet.
SubnetsAction getSubnetsAction (const data::ConstElementPtr &args) const
 Creates subnets action from the command's arguments.
SubnetsInclude getSubnetsInclude (const data::ConstElementPtr &args) const
 Creates SubnetsInclude from the command's arguments.
template<typename ParserType, typename... ParserArgs, typename ElementType>
data::ConstElementPtr parseInputListElement (hooks::CalloutHandle &callout_handle, const std::string &list_name, ParserArgs... parser_args, ElementType &parsed_element, data::Element::types sub_type=data::Element::map) const
 Parses a command containing a list of elements (second call).
template<typename ParserType, typename... ParserArgs, typename ElementType>
data::ConstElementPtr parseInputListElement (hooks::CalloutHandle &callout_handle, const std::string &list_name, ParserArgs... parser_args, ElementType &parsed_element, db::BackendSelector &backend_selector, db::ServerSelector &server_selector, ServerTagsParse tags_parse, data::Element::types sub_type=data::Element::map) const
 Parses a command containing a list of elements.
template<typename ParserType, typename... ParserArgs, typename ElementType>
void parseInputMapElement (hooks::CalloutHandle &callout_handle, const std::string &map_name, ParserArgs... parser_args, ElementType &parsed_element, db::BackendSelector &backend_selector, db::ServerSelector &server_selector, ServerTagsParse tags_parse) const
 Parses a command containing a map of elements.

Detailed Description

This parser class contains the common logic for various callouts to parse and validate the contents of the received command.

Definition at line 39 of file cb_cmds_impl.h.

Member Enumeration Documentation

◆ ServerTagsParse

Server selector parsing.

It determines the expected server tags specified for the command parsed by the parseInputListElement and parseInputMapElement.

Note
We currently don't support the case of the optional server-tags list, but it may be useful in the future and makes the progressive implementation of the server tags easier.
Enumerator
TAGS_OPTIONAL 

server-tags entry is optional

TAGS_REQUIRED 

server-tags is required

TAGS_FORBIDDEN 

server-tags is not allowed

Definition at line 50 of file cb_cmds_impl.h.

◆ SubnetsAction

Subnets actions for shared network delete.

Enumerator
ACTION_KEEP 

keep subnets (default)

ACTION_DELETE 

delete subnets

Definition at line 57 of file cb_cmds_impl.h.

◆ SubnetsInclude

Subnets actions for shared network get command.

Enumerator
INCLUDE_NO 
INCLUDE_FULL 

Definition at line 63 of file cb_cmds_impl.h.

Member Function Documentation

◆ getBackendSelector()

BackendSelector isc::cb::ConfigCmdsParser::getBackendSelector ( const data::ConstElementPtr & args) const

Creates backend selector from the command's arguments.

If the command arguments include "remote" parameter we will use the contents of this parameter to create backend selector. Otherwise, we will return the default selector (unspecified).

Parameters
argsPointer to the command arguments.

Definition at line 34 of file cb_cmds_impl.cc.

Referenced by parseInputListElement(), and parseInputMapElement().

◆ getServerSelector()

ServerSelector isc::cb::ConfigCmdsParser::getServerSelector ( const data::ConstElementPtr & args,
ServerTagsParse tags_parse ) const

Creates server selector from the command's arguments.

If the parsing choice is TAGS_REQUIRED:

  • no "server-tags" or empty parameter give an error.
  • "server-tags" parameter contents is used to create server selector.

If the parsing choice is TAGS_FORBIDDEN:

  • a "server-tags" parameter gives an error.
  • no "server-tags" gives the ANY server selector.

If the parsing choice is TAGS_OPTIONAL:

  • no "server-tags" parameter gives the ANY server selector.
  • empty "server-tags" parameter gives an error.
  • "server-tags" parameter contents is used to create server selector.
Parameters
argsPointer to the command arguments.
tags_parseParsing choice for server-tags entry.
Exceptions
BadValueif server selector cannot be parsed following tags_parse.

Definition at line 44 of file cb_cmds_impl.cc.

References isc::db::ServerSelector::ANY(), isc::data::ServerTag::get(), isc_throw, Element::list, isc::db::ServerSelector::MULTIPLE(), Element::null, isc::db::ServerSelector::ONE(), Element::string, TAGS_FORBIDDEN, TAGS_REQUIRED, and isc::db::ServerSelector::UNASSIGNED().

Referenced by parseInputListElement(), and parseInputMapElement().

Here is the call graph for this function:

◆ getSubnetCommon()

template<typename SubnetPtrType, typename KeyType>
void isc::cb::ConfigCmdsParser::getSubnetCommon ( hooks::CalloutHandle & callout_handle,
const SubnetPtrType & subnet,
const uint16_t address_family,
const KeyType & key )
inline

Common routine invoked when getting a subnet.

Creates a response to the caller which includes the fetched subnet and appropriate control result.

Template Parameters
SubnetPtrTypeType of the pointer to the retrieved subnet.
KeyTypeType of the key used to fetch the subnet.
Parameters
callout_handleCallout handle where response will be stored.
subnetInstance of the fetched subnet or null if no subnet was found.
address_familyAddress family.
keySubnet property used for locating the subnet, e.g. subnet identifier or prefix.

Definition at line 426 of file cb_cmds_impl.h.

References isc::config::CONTROL_RESULT_EMPTY, isc::config::CONTROL_RESULT_SUCCESS, isc::data::Element::create(), isc::config::createAnswer(), isc::data::Element::createList(), isc::data::Element::createMap(), isc::db::info, and isc::hooks::CalloutHandle::setArgument().

Here is the call graph for this function:

◆ getSubnetsAction()

ConfigCmdsParser::SubnetsAction isc::cb::ConfigCmdsParser::getSubnetsAction ( const data::ConstElementPtr & args) const

Creates subnets action from the command's arguments.

If the command arguments include "subnets-action" parameter we will use the contents of this parameter to create subnets action. Otherwise, we will return the default action (keep).

Parameters
argsPointer to the command arguments.

Definition at line 93 of file cb_cmds_impl.cc.

References ACTION_DELETE, ACTION_KEEP, isc_throw, and Element::string.

◆ getSubnetsInclude()

ConfigCmdsParser::SubnetsInclude isc::cb::ConfigCmdsParser::getSubnetsInclude ( const data::ConstElementPtr & args) const

Creates SubnetsInclude from the command's arguments.

If teh command arguments include "subnets-include" parameter we will use the contents of this parameter we will use it to determine whether the subnets should be included in the response to the remote-network[46]-get command.

Parameters
argsPointer to the command arguments.

Definition at line 114 of file cb_cmds_impl.cc.

References INCLUDE_FULL, INCLUDE_NO, isc_throw, and Element::string.

◆ parseInputListElement() [1/2]

template<typename ParserType, typename... ParserArgs, typename ElementType>
data::ConstElementPtr isc::cb::ConfigCmdsParser::parseInputListElement ( hooks::CalloutHandle & callout_handle,
const std::string & list_name,
ParserArgs... parser_args,
ElementType & parsed_element,
data::Element::types sub_type = data::Element::map ) const
inline

Parses a command containing a list of elements (second call).

This method is used for processing control commands which contain a list of maps. The map contains a configuration data structure such as subnet, shared network, global parameter, option etc. The parser to be used to parse the command arguments into the respective C++ objects is provided via the template parameters.

This is a stripped down version which is intended to be called a second time after "full" parseInputListElement.

Template Parameters
ParserTypeType of the parser to be used for parsing the data.
ParserArgsArguments to be passed to the parser specified via ParserType.
ElementTypeType of the object which holds parsed data.
Parameters
callout_handleReference to the callout handle holding the command to be parsed.
list_nameName of the list within command's arguments that holds the data, e.g. "subnets", "shared-networks" etc.
parser_argsArguments to be passed to the parser.
[out]parsed_elementReference to the object where the parsed data should be stored.
sub_typetype of the element of the list.
Returns
Pointer to the command arguments.
Exceptions
BadValueif the command is malformed.

Definition at line 233 of file cb_cmds_impl.h.

References isc::hooks::CalloutHandle::getArgument(), isc_throw, isc::data::Element::list, isc::data::Element::map, isc::config::parseCommandWithArgs(), and isc::data::Element::typeToName().

Here is the call graph for this function:

◆ parseInputListElement() [2/2]

template<typename ParserType, typename... ParserArgs, typename ElementType>
data::ConstElementPtr isc::cb::ConfigCmdsParser::parseInputListElement ( hooks::CalloutHandle & callout_handle,
const std::string & list_name,
ParserArgs... parser_args,
ElementType & parsed_element,
db::BackendSelector & backend_selector,
db::ServerSelector & server_selector,
ServerTagsParse tags_parse,
data::Element::types sub_type = data::Element::map ) const
inline

Parses a command containing a list of elements.

This method is used for processing control commands which contain a list of maps. The map contains a configuration data structure such as subnet, shared network, global parameter, option etc. The parser to be used to parse the command arguments into the respective C++ objects is provided via the template parameters.

The second template argument, i.e. ParserArgs, is a variadic template parameter pack which can contain no parameters, one parameter or multiple parameters. This parameter pack is passed to the configuration parser's (ParserType) constructor. For example:

auto option_pair = std::make_pair(OptionDescriptor(false, false), "");
BackendSelector backend_selector;
(callout_handle, "options", AF_INET,
CfgMgr::instance().getCurrentCfg()->getCfgOptionDef(),
option_pair, backend_selector, server_selector,
@ TAGS_REQUIRED
server-tags is required
data::ConstElementPtr parseInputListElement(hooks::CalloutHandle &callout_handle, const std::string &list_name, ParserArgs... parser_args, ElementType &parsed_element, db::BackendSelector &backend_selector, db::ServerSelector &server_selector, ServerTagsParse tags_parse, data::Element::types sub_type=data::Element::map) const
Parses a command containing a list of elements.
Config Backend selector.
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:29
Option descriptor.
Definition cfg_option.h:50

The first template argument specifies that OptionDataParser must be used to parse the data. Its constructor takes two parameters:

The second and third template parameter belong to the aforementioned parameter pack and they indicate that the uint16_t and the CfgOptionDefPtr parameters must be passed to the parser's constructor. These parameters are provided as the second and third parameter in the invocation. The last template parameter ElementType is not specified in the example above, because it is inferred by the compiler from the function arguments.

Another example demonstrates how to call this method when the parser's constructor takes no arguments:

Subnet4Ptr subnet;
BackendSelector backend_selector;
"subnets",
subnet,
backend_selector,
server_selector,
Server selector for associating objects in a database with specific servers.
static ServerSelector UNASSIGNED()
Factory returning "unassigned" server selector.
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
Definition subnet.h:458

In this case, the sole template parameter is the one that specifies the parser type. Neither the parameter pack is provided nor parser specific arguments.

Currently, the number of maps allowed in the list is restricted to 1. That means that only one subnet, shared network, global parameter etc. can be sent in a single command.

Template Parameters
ParserTypeType of the parser to be used for parsing the data.
ParserArgsArguments to be passed to the parser specified via ParserType.
ElementTypeType of the object which holds parsed data.
Parameters
callout_handleReference to the callout handle holding the command to be parsed.
list_nameName of the list within command's arguments that holds the data, e.g. "subnets", "shared-networks" etc.
parser_argsArguments to be passed to the parser.
[out]parsed_elementReference to the object where the parsed data should be stored.
[out]backend_selectorReference to the backend selector retrieved from the command.
[out]server_selectorReference to the server selector retrieved from the command.
tags_parseParsing choice for server-tags entry.
sub_typetype of the element of the list.
Returns
Pointer to the command arguments.
Exceptions
BadValueif the command is malformed.

Definition at line 151 of file cb_cmds_impl.h.

References isc::hooks::CalloutHandle::getArgument(), getBackendSelector(), getServerSelector(), isc_throw, isc::data::Element::list, isc::data::Element::map, isc::config::parseCommandWithArgs(), and isc::data::Element::typeToName().

Here is the call graph for this function:

◆ parseInputMapElement()

template<typename ParserType, typename... ParserArgs, typename ElementType>
void isc::cb::ConfigCmdsParser::parseInputMapElement ( hooks::CalloutHandle & callout_handle,
const std::string & map_name,
ParserArgs... parser_args,
ElementType & parsed_element,
db::BackendSelector & backend_selector,
db::ServerSelector & server_selector,
ServerTagsParse tags_parse ) const
inline

Parses a command containing a map of elements.

This method is used for processing control commands which contain a non-empty map. For example, it is used to parse a map of global configuration parameters for the DHCP servers. The parser to be used to parse the command arguments into the respective C++ objects is provided via the template parameters.

The second template argument, i.e. ParserArgs, is a variadic template parameter pack which can contain no parameters, one parameter or multiple parameters. This parameter pack is passed to the configuration parser's (ParserType) constructor. For example:

StampedValueCollection stamped_values;
BackendSelector backend_selector;
parser_->parseInputMapElement<GlobalParameterParser, const SimpleKeywords&>
(callout_handle, "parameters", keywords,
stamped_values, backend_selector, server_selector,
Implements a parser for global parameters.
Definition cb_parsers.h:60
static const isc::data::SimpleKeywords GLOBAL4_PARAMETERS
This table defines all global parameters in DHCPv4.
boost::multi_index_container< StampedValuePtr, boost::multi_index::indexed_by< boost::multi_index::hashed_non_unique< boost::multi_index::tag< StampedValueNameIndexTag >, boost::multi_index::const_mem_fun< StampedValue, std::string, &StampedValue::getName > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< StampedValueModificationTimeIndexTag >, boost::multi_index::const_mem_fun< BaseStampedElement, boost::posix_time::ptime, &BaseStampedElement::getModificationTime > > > > StampedValueCollection
Multi index container for StampedValue.
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.

The first template argument specifies that GlobalParameterParser must be used to parse the map. Its constructor takes one argument, i.e. const SimpleKeywords&.

The second template parameter belongs to the aforementioned parameter pack and it indicates that const SimpleKeywords& parameters must be passed to the parser's constructor.

The last template parameter ElementType is not specified in the example above, because it is inferred by the compiler from the function arguments.

Template Parameters
ParserTypeType of the parser to be used for parsing the data.
ParserArgsArguments to be passed to the parser specified via ParserType.
ElementTypeType of the object which holds parsed data.
Parameters
callout_handleReference to the callout handle holding the command to be parsed.
map_nameName of the map within command's arguments that holds the data.
parser_argsArguments to be passed to the parser.
[out]parsed_elementReference to the object where the parsed data should be stored.
[out]backend_selectorReference to the backend selector retrieved from the command.
[out]server_selectorReference to the server selector retrieved from the command.
tags_parseParsing choice for server-tags entry.

Definition at line 330 of file cb_cmds_impl.h.

References isc::hooks::CalloutHandle::getArgument(), getBackendSelector(), getServerSelector(), isc_throw, isc::data::Element::map, and isc::config::parseCommandWithArgs().

Here is the call graph for this function:

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