]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#92,!13] Moved DbAccessParser to libkea-database.
authorMarcin Siodelski <marcin@isc.org>
Wed, 29 Aug 2018 08:52:41 +0000 (10:52 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 3 Sep 2018 07:31:33 +0000 (03:31 -0400)
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp6/json_config_parser.cc
src/lib/dhcpsrv/parsers/dbaccess_parser.cc
src/lib/dhcpsrv/parsers/dbaccess_parser.h
src/lib/dhcpsrv/tests/dbaccess_parser_unittest.cc

index d94e30916e206386a74dc48beca1e1f102d984ad..b8f479075437088bd7785549257ce63bcecadced 100644 (file)
@@ -429,25 +429,31 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
 
             // Please move at the end when migration will be finished.
             if (config_pair.first == "lease-database") {
-                DbAccessParser parser(DBType::LEASE_DB);
+                DbAccessParser parser;
+                std::string access_string;
+                parser.parse(access_string, config_pair.second);
                 CfgDbAccessPtr cfg_db_access = srv_cfg->getCfgDbAccess();
-                parser.parse(cfg_db_access, config_pair.second);
+                cfg_db_access->setLeaseDbAccessString(access_string);
                 continue;
             }
 
             if (config_pair.first == "hosts-database") {
-                DbAccessParser parser(DBType::HOSTS_DB);
+                DbAccessParser parser;
+                std::string access_string;
+                parser.parse(access_string, config_pair.second);
                 CfgDbAccessPtr cfg_db_access = srv_cfg->getCfgDbAccess();
-                parser.parse(cfg_db_access, config_pair.second);
+                cfg_db_access->setHostDbAccessString(access_string);
                 continue;
             }
 
             if (config_pair.first == "hosts-databases") {
                 CfgDbAccessPtr cfg_db_access = srv_cfg->getCfgDbAccess();
-                DbAccessParser parser(DBType::HOSTS_DB);
+                DbAccessParser parser;
                 auto list = config_pair.second->listValue();
                 for (auto it : list) {
-                    parser.parse(cfg_db_access, it);
+                    std::string access_string;
+                    parser.parse(access_string, it);
+                    cfg_db_access->setHostDbAccessString(access_string);
                 }
                 continue;
             }
index b6dbab69b1325eb9d13e51b3517f212a5666e3c8..261e5866609ec5bb4ebe07c563161011ae1a21ea 100644 (file)
@@ -542,25 +542,31 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
 
             // Please move at the end when migration will be finished.
             if (config_pair.first == "lease-database") {
-                DbAccessParser parser(DBType::LEASE_DB);
+                DbAccessParser parser;
+                std::string access_string;
+                parser.parse(access_string, config_pair.second);
                 CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
-                parser.parse(cfg_db_access, config_pair.second);
+                cfg_db_access->setLeaseDbAccessString(access_string);
                 continue;
             }
 
             if (config_pair.first == "hosts-database") {
-                DbAccessParser parser(DBType::HOSTS_DB);
+                DbAccessParser parser;
+                std::string access_string;
+                parser.parse(access_string, config_pair.second);
                 CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
-                parser.parse(cfg_db_access, config_pair.second);
+                cfg_db_access->setHostDbAccessString(access_string);
                 continue;
             }
 
             if (config_pair.first == "hosts-databases") {
                 CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
-                DbAccessParser parser(DBType::HOSTS_DB);
+                DbAccessParser parser;
                 auto list = config_pair.second->listValue();
                 for (auto it : list) {
-                    parser.parse(cfg_db_access, it);
+                    std::string access_string;
+                    parser.parse(access_string, it);
+                    cfg_db_access->setHostDbAccessString(access_string);
                 }
                 continue;
             }
index 1665b74f7c8f0a1365a174d14e76d75eae36fcc0..f87448d87b27fce2148e1b850183521060078571 100644 (file)
@@ -31,13 +31,13 @@ namespace dhcp {
 
 
 // Factory function to build the parser
-DbAccessParser::DbAccessParser(DBType db_type)
-    : values_(), type_(db_type) {
+DbAccessParser::DbAccessParser()
+    : values_() {
 }
 
 // Parse the configuration and check that the various keywords are consistent.
 void
-DbAccessParser::parse(CfgDbAccessPtr& cfg_db,
+DbAccessParser::parse(std::string& access_string,
                       ConstElementPtr database_config) {
 
     // To cope with incremental updates, the strategy is:
@@ -122,8 +122,7 @@ DbAccessParser::parse(CfgDbAccessPtr& cfg_db,
     StringPairMap::const_iterator type_ptr = values_copy.find("type");
     if (type_ptr == values_copy.end()) {
         isc_throw(DhcpConfigError,
-                  (type_ == DBType::LEASE_DB ? "lease" : "host")
-                  << " database access parameters must "
+                  "database access parameters must "
                   "include the keyword 'type' to determine type of database "
                   "to be accessed (" << database_config->getPosition() << ")");
     }
@@ -212,11 +211,7 @@ DbAccessParser::parse(CfgDbAccessPtr& cfg_db,
     values_.swap(values_copy);
 
     // 5. Save the database access string in the Configuration Manager.
-    if (type_ == DBType::LEASE_DB) {
-        cfg_db->setLeaseDbAccessString(getDbAccessString());
-    } else if (type_ == DBType::HOSTS_DB) {
-        cfg_db->setHostDbAccessString(getDbAccessString(), false);
-    }
+    access_string = getDbAccessString();
 }
 
 // Create the database access string
index e2013cc17e6a130268a41bfc8569653745d865fe..c6356893d00e3a84b231f88c84f801615c9eea3d 100644 (file)
 namespace isc {
 namespace dhcp {
 
-/// @brief Parse Lease Database Parameters
+/// @brief Parse Database Parameters
 ///
-/// This class is the parser for the lease database configuration.  This is a
-/// map under the top-level "lease-database" element, and comprises a map of
-/// strings.
+/// This class is the parser for the database configuration.  This is a
+/// map under the top-level "lease-database", "host-database" and
+/// "config-database" elements, and comprises a map of strings.
 ///
-/// Only the "type" sub-element is mandatory: the remaining sub-elements 
-/// depend on the database chosen.
 class DbAccessParser: public isc::data::SimpleParser {
 public:
 
@@ -35,9 +33,7 @@ public:
     typedef std::map<std::string, std::string> StringPairMap;
 
     /// @brief Constructor
-    ///
-    /// @param db_type Specifies database type (lease or hosts)
-    explicit DbAccessParser(DBType db_type);
+    DbAccessParser();
 
     /// The destructor.
     virtual ~DbAccessParser()
@@ -53,17 +49,16 @@ public:
     /// - "connect-timeout" is a number from the range of 0 to 4294967295.
     /// - "port" is a number from the range of 0 to 65535.
     ///
-    /// Once all has been validated, constructs the database access string
-    /// expected by the lease manager.
+    /// Once all has been validated, constructs the database access string.
     ///
-    /// @param cfg_db The configuration where the access string will be set
+    /// @param [out] access_string Generated database access string.
     /// @param database_config The configuration value for the "*-database"
     ///        identifier.
     ///
     /// @throw isc::dhcp::DhcpConfigError The 'type' keyword contains an
     ///        unknown database type or is missing from the list of
     ///        database access keywords.
-    void parse(isc::dhcp::CfgDbAccessPtr& cfg_db,
+    void parse(std::string& access_string,
                isc::data::ConstElementPtr database_config);
 
 
@@ -91,8 +86,6 @@ protected:
 private:
 
     std::map<std::string, std::string> values_; ///< Stored parameter values
-
-    DBType type_; ///< Database type (leases or hosts)
 };
 
 };  // namespace dhcp
index 0b8f833f16774431a4ce3582732e4baef5a36f5b..97d437a9d4cfba4d1e21fd01b8596e2f948d79d1 100644 (file)
@@ -198,7 +198,7 @@ public:
     ///
     /// @brief Keyword/value collection of database access parameters
     TestDbAccessParser(DBType type) 
-        : DbAccessParser(type)
+        : DbAccessParser(), type_(type)
     {}
 
     /// @brief Destructor
@@ -206,9 +206,18 @@ public:
     {}
 
     /// @brief Parse configuration value
+    ///
+    /// @param database_config Configuration to be parsed.
     void parse(ConstElementPtr database_config) {
         CfgDbAccessPtr cfg_db(new CfgDbAccess());
-        DbAccessParser::parse(cfg_db, database_config);
+        std::string db_access_string;
+        DbAccessParser::parse(db_access_string, database_config);
+
+        if (type_ == DBType::LEASE_DB) {
+            cfg_db->setLeaseDbAccessString(db_access_string);
+        } else {
+            cfg_db->setHostDbAccessString(db_access_string);
+        }
     }
 
     /// Allow use of superclass's protected functions.
@@ -234,6 +243,8 @@ public:
     std::string getDbAccessString() const {
         return (DbAccessParser::getDbAccessString());
     }
+
+    DBType type_;
 };
 
 // Check that the parser works with a simple configuration.