From 3f07550f07a6417a34545c3977d2c5d52fd80a0d Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Sat, 7 Jan 2017 07:18:40 +0100 Subject: [PATCH] [5035] Moved to SimpleParser --- src/bin/dhcp4/json_config_parser.cc | 9 +++++++-- src/bin/dhcp6/json_config_parser.cc | 9 +++++++-- .../parsers/expiration_config_parser.cc | 14 +++---------- .../parsers/expiration_config_parser.h | 20 +++++++++---------- .../expiration_config_parser_unittest.cc | 7 ++++--- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc index 8a5d6a1212..48ea993b12 100644 --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@ -439,8 +439,7 @@ DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id, } else if (config_id.compare("match-client-id") == 0) { parser = new BooleanParser(config_id, globalContext()->boolean_values_); // control-socket has been converted to SimpleParser already. - } else if (config_id.compare("expired-leases-processing") == 0) { - parser = new ExpirationConfigParser(); + // expired-leases-processing has been converted to SimpleParser already. } else if (config_id.compare("client-classes") == 0) { parser = new ClientClassDefListParser(config_id, globalContext()); // host-reservation-identifiers have been converted to SimpleParser already. @@ -646,6 +645,12 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) { continue; } + if (config_pair.first == "expired-leases-processing") { + ExpirationConfigParser parser; + parser.parse(config_pair.second); + continue; + } + ParserPtr parser(createGlobalDhcp4ConfigParser(config_pair.first, config_pair.second)); LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, DHCP4_PARSER_CREATED) diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index bea936afde..c713fa62a5 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -720,8 +720,7 @@ DhcpConfigParser* createGlobal6DhcpConfigParser(const std::string& config_id, } else if (config_id.compare("relay-supplied-options") == 0) { parser = new RSOOListConfigParser(config_id); // control-socket has been converted to SimpleParser. - } else if (config_id.compare("expired-leases-processing") == 0) { - parser = new ExpirationConfigParser(); + // expired-leases-processing has been converted to SimpleParser. } else if (config_id.compare("client-classes") == 0) { parser = new ClientClassDefListParser(config_id, globalContext()); } else if (config_id.compare("server-id") == 0) { @@ -925,6 +924,12 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) { continue; } + if (config_pair.first == "expired-leases-processing") { + ExpirationConfigParser parser; + parser.parse(config_pair.second); + continue; + } + ParserPtr parser(createGlobal6DhcpConfigParser(config_pair.first, config_pair.second)); LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PARSER_CREATED) diff --git a/src/lib/dhcpsrv/parsers/expiration_config_parser.cc b/src/lib/dhcpsrv/parsers/expiration_config_parser.cc index 4bd8bfe4e6..170e95abba 100644 --- a/src/lib/dhcpsrv/parsers/expiration_config_parser.cc +++ b/src/lib/dhcpsrv/parsers/expiration_config_parser.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015,2017 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -8,6 +8,7 @@ #include #include #include +#include #include using namespace isc::data; @@ -15,12 +16,8 @@ using namespace isc::data; namespace isc { namespace dhcp { -ExpirationConfigParser::ExpirationConfigParser() - : DhcpConfigParser() { -} - void -ExpirationConfigParser::build(ConstElementPtr expiration_config) { +ExpirationConfigParser::parse(ConstElementPtr expiration_config) { CfgExpirationPtr cfg = CfgMgr::instance().getStagingCfg()->getCfgExpiration(); BOOST_FOREACH(ConfigPair config_element, expiration_config->mapValue()) { @@ -63,10 +60,5 @@ ExpirationConfigParser::build(ConstElementPtr expiration_config) { } } -void -ExpirationConfigParser::commit() { - // Nothing to do. -} - } // end of namespace isc::dhcp } // end of namespace isc diff --git a/src/lib/dhcpsrv/parsers/expiration_config_parser.h b/src/lib/dhcpsrv/parsers/expiration_config_parser.h index cf3f2ac3f4..44ba77d6e0 100644 --- a/src/lib/dhcpsrv/parsers/expiration_config_parser.h +++ b/src/lib/dhcpsrv/parsers/expiration_config_parser.h @@ -1,4 +1,4 @@ -// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015,2017 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -7,7 +7,8 @@ #ifndef EXPIRATION_CONFIG_PARSER_H #define EXPIRATION_CONFIG_PARSER_H -#include +#include +#include namespace isc { namespace dhcp { @@ -32,26 +33,23 @@ namespace dhcp { /// those that aren't specified. /// /// The parser checks if the values of the specified parameters are within -/// the allowed ranges and throws exception if they are. Each parameter +/// the allowed ranges and throws exception if they aren't. Each parameter /// has a corresponding maximum value defined in the @c CfgExpiration class. /// None of them may be negative. -class ExpirationConfigParser : public DhcpConfigParser { +class ExpirationConfigParser : public isc::data::SimpleParser { public: - /// @brief Constructor - ExpirationConfigParser(); + /// @brief Destructor. + virtual ~ExpirationConfigParser() { } /// @brief Parses parameters in the JSON map, pertaining to the processing /// of the expired leases. /// - /// @param value pointer to the content of parsed values + /// @param expiration_config pointer to the content of parsed values /// /// @throw DhcpConfigError if unknown parameter specified or the /// parameter contains invalid value.. - virtual void build(isc::data::ConstElementPtr value); - - /// @brief Does nothing. - virtual void commit(); + void parse(isc::data::ConstElementPtr expiration_config); }; diff --git a/src/lib/dhcpsrv/tests/expiration_config_parser_unittest.cc b/src/lib/dhcpsrv/tests/expiration_config_parser_unittest.cc index da2bee8e79..53c5953b42 100644 --- a/src/lib/dhcpsrv/tests/expiration_config_parser_unittest.cc +++ b/src/lib/dhcpsrv/tests/expiration_config_parser_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015,2017 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -105,7 +106,7 @@ ExpirationConfigParserTest::renderConfig() const { // Parse the configuration. This may emit exceptions. ExpirationConfigParser parser; - parser.build(config_element); + parser.parse(config_element); // No exception so return configuration. return (CfgMgr::instance().getStagingCfg()->getCfgExpiration()); @@ -254,7 +255,7 @@ TEST_F(ExpirationConfigParserTest, notNumberValue) { // Parse the configuration. It should throw exception. ExpirationConfigParser parser; - EXPECT_THROW(parser.build(config_element), DhcpConfigError); + EXPECT_THROW(parser.parse(config_element), DhcpConfigError); } } // end of anonymous namespace