20 #include <boost/foreach.hpp> 21 #include <boost/make_shared.hpp> 33 OptionDataParser::OptionDataParser(
const uint16_t address_family,
35 : address_family_(address_family), cfg_option_def_(cfg_option_def) {
38 std::pair<OptionDescriptor, std::string>
49 std::pair<OptionDescriptor, std::string> opt =
createOption(single_option);
51 if (!opt.first.option_) {
54 "parser logic error: no option has been configured and" 55 " thus there is nothing to commit. Has build() been called?");
67 }
catch (
const std::exception&) {
74 code > std::numeric_limits<uint8_t>::max()) {
76 <<
"', it must not be greater than '" 77 << static_cast<int>(std::numeric_limits<uint8_t>::max())
82 code > std::numeric_limits<uint16_t>::max()) {
84 <<
"', it must not exceed '" 85 << std::numeric_limits<uint16_t>::max()
104 if (name.find(
" ") != std::string::npos) {
106 <<
"', space character is not allowed (" 129 bool csv_format =
true;
131 csv_format =
getBoolean(parent,
"csv-format");
159 <<
"' option space name is reserved for DHCPv4 server");
164 <<
"' option space name is reserved for DHCPv6 server");
167 }
catch (
const std::exception& ex) {
178 bool persist =
false;
256 std::pair<OptionDescriptor, std::string>
272 " 'code' or 'name' parameters to be specified" 273 <<
" (" << option_data->getPosition() <<
")");
285 if (!csv_format_param.
unspecified() && csv_format_param) {
287 << space_param <<
"." << name_param
288 <<
"' having code '" << code_param
289 <<
"' does not exist (" 297 << space_param <<
"." << name_param
298 <<
"' does not exist (" 305 std::vector<uint8_t> binary;
306 std::vector<std::string> data_tokens;
310 if (def && (csv_format_param.
unspecified() || csv_format_param)) {
327 if (binary.empty()) {
332 <<
" string of hexadecimal digits: " << data_param
347 OptionPtr option(
new Option(universe, static_cast<uint16_t>(code_param),
355 if (!name_param.
unspecified() && (def->getName() != name_param.
get())) {
357 << name_param <<
"' does not match the " 358 <<
"option definition: '" << space_param
359 <<
"." << def->getName() <<
"' (" 367 bool use_csv = csv_format_param.
unspecified() || csv_format_param;
369 def->optionFactory(universe, def->getCode(), data_tokens) :
370 def->optionFactory(universe, def->getCode(), binary);
378 <<
" option definition (space: " << space_param
379 <<
", code: " << def->getCode() <<
"): " 390 <<
"reserved for PAD (" 391 << option_data->getPosition() <<
")");
394 <<
"reserved for END (" 395 << option_data->getPosition() <<
")");
401 if (desc.
option_->getType() == 0) {
403 <<
"reserved value (" 404 << option_data->getPosition() <<
")");
415 return make_pair(desc, space_param);
421 const uint16_t address_family,
431 std::pair<OptionDescriptor, std::string> option =
432 option_parser->parse(data);
434 cfg->add(option.first, option.second);
439 boost::shared_ptr<OptionDataParser>
util::Optional< uint32_t > extractCode(data::ConstElementPtr parent) const
Retrieves parsed option code as an optional value.
static bool getBoolean(isc::data::ConstElementPtr scope, const std::string &name)
Returns a boolean parameter from a scope.
static OptionDefinitionPtr getRuntimeOptionDef(const std::string &space, const uint16_t code)
Returns runtime (non-standard) option definition by space and option code.
void unspecified(bool unspecified)
Modifies the flag that indicates whether the value is specified or unspecified.
void setContext(const data::ConstElementPtr &ctx)
Sets user context.
static int64_t getInteger(isc::data::ConstElementPtr scope, const std::string &name)
Returns an integer parameter from a scope.
void parse(const CfgOptionPtr &cfg, isc::data::ConstElementPtr option_data_list)
Parses a list of options, instantiates them and stores in cfg.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
std::pair< OptionDescriptor, std::string > parse(isc::data::ConstElementPtr single_option)
Parses ElementPtr containing option definition.
std::pair< OptionDescriptor, std::string > createOption(isc::data::ConstElementPtr option_data)
Create option instance.
static bool validateName(const std::string &name)
Checks that the provided option space name is valid.
util::Optional< std::string > extractName(data::ConstElementPtr parent) const
Retrieves parsed option name as an optional value.
boost::shared_ptr< Option > OptionPtr
Universe
defines option universe DHCPv4 or DHCPv6
T get() const
Retrieves the encapsulated value.
std::string extractData(data::ConstElementPtr parent) const
Retrieves option data as a string.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
uint16_t address_family_
Address family: AF_INET or AF_INET6.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void decodeFormattedHexString(const std::string &hex_string, std::vector< uint8_t > &binary)
Converts a formatted string of hexadecimal digits into a vector.
uint16_t address_family_
Address family: AF_INET or AF_INET6.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::string formatted_value_
Option value in textual (CSV) format.
vector< string > tokens(const std::string &text, const std::string &delim, bool escape)
Split String into Tokens.
To be removed. Please use ConfigError instead.
virtual boost::shared_ptr< OptionDataParser > createOptionDataParser() const
Returns an instance of the OptionDataListParser to be used in parsing options.
bool persistent_
Persistence flag.
util::Optional< bool > extractPersistent(data::ConstElementPtr parent) const
Retrieves persistent/always-send parameter as an optional value.
CfgOptionDefPtr cfg_option_def_
Config option definitions.
std::string extractSpace(data::ConstElementPtr parent) const
Retrieves option space name.
boost::shared_ptr< const Element > ConstElementPtr
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
static OptionDefinitionPtr getOptionDef(const std::string &space, const uint16_t code)
Return the first option definition matching a particular option code.
static const isc::data::SimpleKeywords OPTION6_PARAMETERS
This table defines all option parameters.
std::vector< uint8_t > quotedStringToBinary(const std::string "ed_string)
Converts a string in quotes into vector.
OptionPtr option_
Option instance.
static const data::Element::Position & getPosition(const std::string &name, const data::ConstElementPtr parent)
Utility method that returns position of an element.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
util::Optional< bool > extractCSVFormat(data::ConstElementPtr parent) const
Retrieves csv-format parameter as an optional value.
#define DHCP6_OPTION_SPACE
CfgOptionDefPtr cfg_option_def_
Config option definitions.
A generic exception that is thrown if a function is called in a prohibited way.
#define DHCP4_OPTION_SPACE
global std option spaces
static void checkKeywords(const SimpleKeywords &keywords, isc::data::ConstElementPtr scope)
Checks acceptable keywords with their expected type.
static OptionDefinitionPtr getLastResortOptionDef(const std::string &space, const uint16_t code)
Returns last resort option definition by space and option code.
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
virtual OptionDefinitionPtr findOptionDefinition(const std::string &option_space, const util::Optional< uint32_t > &option_code, const util::Optional< std::string > &option_name) const
Finds an option definition within an option space.
OptionDataListParser(const uint16_t address_family, CfgOptionDefPtr cfg_option_def=CfgOptionDefPtr())
Constructor.
static uint32_t optionSpaceToVendorId(const std::string &option_space)
Converts option space name to vendor id.
static const isc::data::SimpleKeywords OPTION4_PARAMETERS
This table defines all option parameters.
static OptionDefinitionPtr getVendorOptionDef(const Option::Universe u, const uint32_t vendor_id, const uint16_t code)
Returns vendor option definition for a given vendor-id and code.