]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3536] addressed review comments
authorRazvan Becheriu <razvan@isc.org>
Mon, 9 Sep 2024 13:17:59 +0000 (16:17 +0300)
committerRazvan Becheriu <razvan@isc.org>
Wed, 11 Sep 2024 08:36:40 +0000 (11:36 +0300)
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp6/json_config_parser.cc
src/lib/dhcpsrv/host_data_source_factory.cc
src/lib/dhcpsrv/host_data_source_factory.h
src/lib/dhcpsrv/lease_mgr_factory.cc
src/lib/dhcpsrv/lease_mgr_factory.h
src/lib/dhcpsrv/tests/host_data_source_factory_unittest.cc
src/lib/dhcpsrv/tests/lease_mgr_factory_unittest.cc
src/lib/dhcpsrv/tracking_lease_mgr.h

index 68fa6db7395edba42ac48ba1531666a7ae452739..85b6f5c6e338c18d2dcfe699ad8aba343b7edc64 100644 (file)
@@ -900,15 +900,14 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
         }
     }
 
-    // Print the list of known backends.
-    LeaseMgrFactory::printRegistered();
+    // Log the list of known backends.
+    LeaseMgrFactory::logRegistered();
 
-    // Print the list of known backends.
-    HostDataSourceFactory::printRegistered();
+    // Log the list of known backends.
+    HostDataSourceFactory::logRegistered();
 
     // Moved from the commit block to add the config backend indication.
     if (status_code == CONTROL_RESULT_SUCCESS && (!check_only || extra_checks)) {
-
         try {
             // If there are config backends, fetch and merge into staging config
             server.getCBControl()->databaseConfigFetch(srv_config,
index 74c4f9087d145135a2409dcd650cff10dc74482b..c4c506bc9b2bd603a1c107248b6f087dd2467d90 100644 (file)
@@ -1036,11 +1036,11 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
         }
     }
 
-    // Print the list of known backends.
-    LeaseMgrFactory::printRegistered();
+    // Log the list of known backends.
+    LeaseMgrFactory::logRegistered();
 
-    // Print the list of known backends.
-    HostDataSourceFactory::printRegistered();
+    // Log the list of known backends.
+    HostDataSourceFactory::logRegistered();
 
     // Moved from the commit block to add the config backend indication.
     if (status_code == CONTROL_RESULT_SUCCESS && (!check_only || extra_checks)) {
index b8064ee7932063fcd0eeaa1f0b05c3d230f0f616..bb2e388bdd0ae047a60dec42fd413bc6de1627b3 100644 (file)
@@ -43,7 +43,7 @@ HostDataSourceFactory::add(HostDataSourceList& sources,
     DatabaseConnection::ParameterMap parameters =
             DatabaseConnection::parse(dbaccess);
 
-    // Get the database type and open the corresponding database
+    // Get the database type and open the corresponding database.
     DatabaseConnection::ParameterMap::iterator it = parameters.find("type");
     if (it == parameters.end()) {
         isc_throw(InvalidParameter, "Host database configuration does not "
@@ -55,8 +55,7 @@ HostDataSourceFactory::add(HostDataSourceList& sources,
 
     // No match?
     if (index == map_.end()) {
-        if ((db_type == "mysql") ||
-            (db_type == "postgresql")) {
+        if ((db_type == "mysql") || (db_type == "postgresql")) {
             string with = (db_type == "postgresql" ? "pgsql" : db_type);
             isc_throw(InvalidType, "The type of host backend: '" << db_type
                       << "' is not compiled in. Did you forget to use --with-"
@@ -69,11 +68,11 @@ HostDataSourceFactory::add(HostDataSourceList& sources,
     // Call the factory and push the pointer on sources.
     sources.push_back(index->second(parameters));
 
-    // Check the factory did not return NULL.
+    // Check the factory did not return null.
     if (!sources.back()) {
         sources.pop_back();
         isc_throw(Unexpected, "Hosts database " << db_type <<
-                  " factory returned NULL");
+                  " factory returned null");
     }
 }
 
@@ -163,14 +162,18 @@ HostDataSourceFactory::registeredFactory(const std::string& db_type) {
 }
 
 void
-HostDataSourceFactory::printRegistered() {
+HostDataSourceFactory::logRegistered() {
     std::stringstream txt;
 
     for (auto const& x : map_) {
-        txt << x.first << " ";
+        if (!txt.str().empty()) {
+            txt << " ";
+        }
+        txt << x.first;
     }
 
-    LOG_INFO(hosts_logger, HOSTS_BACKENDS_REGISTERED).arg(txt.str());
+    LOG_INFO(hosts_logger, HOSTS_BACKENDS_REGISTERED)
+        .arg(txt.str());
 }
 
 }  // namespace dhcp
index c4e833600dcb508f40de7e234f41f48edbae264a..0600064dffaa8a38e26f9282dd90e2f30fd90c5a 100644 (file)
@@ -96,7 +96,7 @@ public:
     /// @brief Type of host data source factory
     ///
     /// A factory takes a parameter map and returns a pointer to a host
-    /// data source. In case of failure it must throw and not return NULL.
+    /// data source. In case of failure it must throw and not return null.
     typedef std::function<HostDataSourcePtr (const db::DatabaseConnection::ParameterMap&)> Factory;
 
     /// @brief Register a host data source factory
@@ -131,12 +131,12 @@ public:
     /// @return true if a factory was registered for db_type, false if not.
     static bool registeredFactory(const std::string& db_type);
 
-    /// @brief Prints out all registered backends.
+    /// @brief Logs out all registered backends.
     ///
     /// We need a dedicated method for this, because we sometimes can't log
     /// the backend type when doing early initialization for backends
     /// initialized statically.
-    static void printRegistered();
+    static void logRegistered();
 
 private:
     /// @brief Factory map
index ed2cb862c79fd018683908fb75ac744c675222a0..1d293d8f9a83a40c152af18bfe4c6c4ef3e84039 100644 (file)
@@ -47,7 +47,7 @@ LeaseMgrFactory::create(const std::string& dbaccess) {
     DatabaseConnection::ParameterMap parameters = DatabaseConnection::parse(dbaccess);
     std::string redacted = DatabaseConnection::redactedAccessString(parameters);
 
-    // Get the database type and open the corresponding database
+    // Get the database type and open the corresponding database.
     DatabaseConnection::ParameterMap::iterator it = parameters.find(type);
     if (it == parameters.end()) {
         LOG_ERROR(dhcpsrv_logger, DHCPSRV_NOTYPE_DB).arg(dbaccess);
@@ -88,8 +88,7 @@ LeaseMgrFactory::create(const std::string& dbaccess) {
 
     // No match?
     if (index == map_.end()) {
-        if ((db_type == "mysql") ||
-            (db_type == "postgresql")) {
+        if ((db_type == "mysql") || (db_type == "postgresql")) {
             LOG_ERROR(dhcpsrv_logger, DHCPSRV_UNKNOWN_DB).arg(db_type);
             string with = (db_type == "postgresql" ? "pgsql" : db_type);
             isc_throw(InvalidType, "The Kea server has not been compiled with "
@@ -106,10 +105,10 @@ LeaseMgrFactory::create(const std::string& dbaccess) {
     // Call the factory.
     getLeaseMgrPtr() = index->second(parameters);
 
-    // Check the factory did not return NULL.
+    // Check the factory did not return null.
     if (!getLeaseMgrPtr()) {
         isc_throw(Unexpected, "Lease database " << db_type <<
-                  " factory returned NULL");
+                  " factory returned null");
     }
 }
 
@@ -159,7 +158,7 @@ LeaseMgrFactory::haveInstance() {
 TrackingLeaseMgr&
 LeaseMgrFactory::instance() {
     TrackingLeaseMgr* lmptr = getLeaseMgrPtr().get();
-    if (lmptr == NULL) {
+    if (!lmptr) {
         isc_throw(NoLeaseManager, "no current lease manager is available");
     }
     return (*lmptr);
@@ -208,14 +207,18 @@ LeaseMgrFactory::registeredFactory(const std::string& db_type) {
 }
 
 void
-LeaseMgrFactory::printRegistered() {
+LeaseMgrFactory::logRegistered() {
     std::stringstream txt;
 
     for (auto const& x : map_) {
-        txt << x.first << " ";
+        if (!txt.str().empty()) {
+            txt << " ";
+        }
+        txt << x.first;
     }
 
-    LOG_INFO(dhcpsrv_logger, DHCPSRV_LEASE_MGR_BACKENDS_REGISTERED).arg(txt.str());
+    LOG_INFO(dhcpsrv_logger, DHCPSRV_LEASE_MGR_BACKENDS_REGISTERED)
+        .arg(txt.str());
 }
 
 } // namespace dhcp
index 7e0cc7f420d3e74b402baa1dd78fae1530caa2d3..a08a926a4bedb2525b1fffaa6d631abab9abd00c 100644 (file)
@@ -18,7 +18,6 @@
 namespace isc {
 namespace dhcp {
 
-
 /// @brief No lease manager exception
 ///
 /// Thrown if an attempt is made to get a reference to the current lease
@@ -106,7 +105,7 @@ public:
     /// @brief Type of lease mgr factory
     ///
     /// A factory takes a parameter map and returns a pointer to a lease mgr.
-    /// In case of failure it must throw and not return NULL.
+    /// In case of failure it must throw and not return null.
     typedef std::function<TrackingLeaseMgrPtr (const db::DatabaseConnection::ParameterMap&)> Factory;
 
     /// @brief Register a lease mgr factory
@@ -121,7 +120,8 @@ public:
     /// @return true if the factory was successfully added to the map, false
     /// if it already exists.
     static bool registerFactory(const std::string& db_type,
-                                const Factory& factory, bool no_log = false);
+                                const Factory& factory,
+                                bool no_log = false);
 
     /// @brief Deregister a lease mgr factory
     ///
@@ -141,12 +141,12 @@ public:
     /// @return true if a factory was registered for db_type, false if not.
     static bool registeredFactory(const std::string& db_type);
 
-    /// @brief Prints out all registered backends.
+    /// @brief Logs out all registered backends.
     ///
     /// We need a dedicated method for this, because we sometimes can't log
     /// the backend type when doing early initialization for backends
     /// initialized statically.
-    static void printRegistered();
+    static void logRegistered();
 
 private:
     /// @brief Hold pointer to lease manager
index 35ef6ee2f9d4adba51b08c17e32a81cc8f32f3a2..1d058960493076db5109f198ffd43f29871b2541 100644 (file)
@@ -149,7 +149,7 @@ TEST_F(HostDataSourceFactoryTest, notype) {
                  InvalidType);
 }
 
-// Verify that factory must not return NULL
+// Verify that factory must not return null
 TEST_F(HostDataSourceFactoryTest, null) {
     EXPECT_TRUE(HostDataSourceFactory::registerFactory("mem", factory0));
     EXPECT_THROW(HostDataSourceFactory::add(sources_, "type=mem"),
index aa781c4741a6be7c8cf341d97e29bcef038c2b01..babf53abdb5acff88a31d2a45a5c4b5dcdd944d6 100644 (file)
@@ -173,7 +173,7 @@ TEST_F(LeaseMgrFactoryTest, notype) {
     EXPECT_FALSE(LeaseMgrFactory::haveInstance());
 }
 
-// Verify that factory must not return NULL
+// Verify that factory must not return null
 TEST_F(LeaseMgrFactoryTest, null) {
     EXPECT_TRUE(LeaseMgrFactory::registerFactory("mem", factory0));
     EXPECT_THROW(LeaseMgrFactory::create("type=mem"),
index 96b1d0b9648f68e5d80cead6db4600db1cb139ff..13f2a67dd6bce494dc2ce45938251d0483377918 100644 (file)
@@ -303,7 +303,7 @@ protected:
 };
 
 /// @brief TrackingLeaseMgr pointer
-typedef boost::shared_ptr<TrackingLeaseMgr> TrackingLeaseMgrPtr;
+typedef std::unique_ptr<TrackingLeaseMgr> TrackingLeaseMgrPtr;
 
 } // end of namespace isc::dhcp
 } // end of namespace isc