Browse Source

[5035] Moved to SimpleParser

Francis Dupont 8 years ago
parent
commit
3f07550f07

+ 7 - 2
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)

+ 7 - 2
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)

+ 3 - 11
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 <dhcpsrv/cfg_expiration.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/parsers/expiration_config_parser.h>
+#include <dhcpsrv/parsers/dhcp_parsers.h>
 #include <boost/foreach.hpp>
 
 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

+ 9 - 11
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 <dhcpsrv/parsers/dhcp_config_parser.h>
+#include <cc/data.h>
+#include <cc/simple_parser.h>
 
 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);
 
 };
 

+ 4 - 3
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 <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/cfg_expiration.h>
 #include <dhcpsrv/parsers/expiration_config_parser.h>
+#include <dhcpsrv/parsers/dhcp_parsers.h>
 #include <gtest/gtest.h>
 #include <sstream>
 #include <stdint.h>
@@ -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