]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3770] Clean up
authorThomas Markwalder <tmark@isc.org>
Thu, 10 Jul 2025 20:17:38 +0000 (16:17 -0400)
committerThomas Markwalder <tmark@isc.org>
Tue, 15 Jul 2025 14:02:03 +0000 (14:02 +0000)
/src/hooks/dhcp/pgsql/pgsql_cb_impl.cc
    PgSqlConfigBackendImpl::addClientClassesBinding()
    - use ClientClasses::toElement()

/src/lib/dhcpsrv/cfg_option.*
    ClientClassesPtr OptionDescriptor::copyClientClasses()
    - new convenience function

/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc
    Use new convenience function

src/hooks/dhcp/pgsql/pgsql_cb_impl.cc
src/lib/dhcpsrv/cfg_option.cc
src/lib/dhcpsrv/cfg_option.h
src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc

index b386cf40e478250a14db8df35e30ffb754f2550b..a80540914c01e2c020a3baee124ac7c571a224c1 100644 (file)
@@ -1159,12 +1159,7 @@ void
 PgSqlConfigBackendImpl::addClientClassesBinding(db::PsqlBindArray& bindings,
                                                 const ClientClasses& client_classes) {
     // Create JSON list of client classes.
-    data::ElementPtr client_classes_element = data::Element::createList();
-    for (auto const& client_class : client_classes) {
-        client_classes_element->add(data::Element::create(client_class));
-    }
-
-    bindings.add(client_classes_element);
+    bindings.add(client_classes.toElement());
 }
 
 void
index 8f18c135e86aa8f58e6a8f80a723f505f46efa96..76bc6b01c75da1b77540a597bf65995e6b96d109 100644 (file)
@@ -61,6 +61,11 @@ OptionDescriptor::addClientClass(const std::string& class_name) {
     }
 }
 
+ClientClassesPtr
+OptionDescriptor::copyClientClasses() const {
+    return (ClientClassesPtr(new ClientClasses(client_classes_)));
+}
+
 bool
 OptionDescriptor::allowedForClientClasses(const ClientClasses& cclasses) const {
     if (client_classes_.empty()) {
index e5d0930f947f7f66a302ba5270c3084e9984ce55..9c8ef0f75a6c69bf6954fe226a9394cca5664e92 100644 (file)
@@ -219,6 +219,11 @@ public:
     /// @return True if descriptor's client-classes is empty or at least
     /// one of its members is found in the validation list.
     bool allowedForClientClasses(const ClientClasses& cclasses) const;
+
+    /// @brief Get a copy of client classes
+    ///
+    /// @return Pointer to a copy of descriptor's client classes
+    ClientClassesPtr copyClientClasses() const;
 };
 
 /// @brief Multi index container for DHCP option descriptors.
index 03ae354f1fc3049aebf1727354e49e418d850a44..5fff7a62f7a612fa9ad788ab8138d1dc396ffeaa 100644 (file)
@@ -3714,11 +3714,10 @@ GenericConfigBackendDHCPv4Test::globalOption4WithClientClassesTest() {
     OptionDescriptorPtr found_option;
     for (auto const& ref_option : ref_options) {
         // Find the option by code and client_classes.
-        ClientClassesPtr cclasses(new ClientClasses(ref_option->client_classes_));
         found_option = cbptr_->getOption4(ServerSelector::ALL(),
                                           ref_option->option_->getType(),
                                           DHCP4_OPTION_SPACE,
-                                          cclasses);
+                                          ref_option->copyClientClasses());
         ASSERT_TRUE(found_option);
         SCOPED_OPT_COMPARE((*ref_option), (*found_option));
     }
@@ -3728,8 +3727,6 @@ GenericConfigBackendDHCPv4Test::globalOption4WithClientClassesTest() {
 
     // Update each option in the backend.
     for (auto const& ref_option : ref_options) {
-        ClientClassesPtr cclasses(new ClientClasses(ref_option->client_classes_));
-
         // Update option in the config back end.
         cbptr_->createUpdateOption4(ServerSelector::ALL(), ref_option);
 
@@ -3737,14 +3734,14 @@ GenericConfigBackendDHCPv4Test::globalOption4WithClientClassesTest() {
         found_option = cbptr_->getOption4(ServerSelector::ALL(),
                                           ref_option->option_->getType(),
                                           DHCP4_OPTION_SPACE,
-                                          cclasses);
+                                          ref_option->copyClientClasses());
         ASSERT_TRUE(found_option);
         SCOPED_OPT_COMPARE((*ref_option), (*found_option));
     }
 
     // Delete each option from the backend.
     for (auto const& ref_option : ref_options) {
-        ClientClassesPtr cclasses(new ClientClasses(ref_option->client_classes_));
+        ClientClassesPtr cclasses = ref_option->copyClientClasses();
 
         // Delete the option by code and client_classes.
         ASSERT_EQ(1, cbptr_->deleteOption4(ServerSelector::ALL(),
@@ -4175,7 +4172,8 @@ GenericConfigBackendDHCPv4Test::createUpdateDeleteSharedNetworkOption4Test() {
     EXPECT_EQ(1, cbptr_->deleteOption4(ServerSelector::ANY(),
                                        shared_network->getName(),
                                        opt_boot_file_name->option_->getType(),
-                                       opt_boot_file_name->space_name_));
+                                       opt_boot_file_name->space_name_,
+                                       opt_boot_file_name->copyClientClasses()));
     returned_network = cbptr_->getSharedNetwork4(ServerSelector::ALL(),
                                                  shared_network->getName());
     ASSERT_TRUE(returned_network);
@@ -4983,13 +4981,11 @@ GenericConfigBackendDHCPv4Test::sharedNetworkOption4WithClientClassesTest() {
     // Now make sure that we can delete the options individually.
     updateClassTaggedOptions(ref_options);
     for (auto const& ref_option : ref_options) {
-        ClientClassesPtr cclasses(new ClientClasses(ref_option->client_classes_));
         ASSERT_EQ(1, cbptr_->deleteOption4(ServerSelector::ANY(),
                                            network->getName(),
                                            ref_option->option_->getType(),
                                            DHCP4_OPTION_SPACE,
-                                           cclasses)) << "code:" << ref_option->option_->getType() 
-                                                      <<  " classes: " << cclasses->toText();
+                                           ref_option->copyClientClasses()));
     }
 
     // Re-fetch the network.
@@ -5049,12 +5045,11 @@ GenericConfigBackendDHCPv4Test::subnetOption4WithClientClassesTest() {
     // Now make sure that we can delete the options individually.
     updateClassTaggedOptions(ref_options);
     for (auto const& ref_option : ref_options) {
-        ClientClassesPtr cclasses(new ClientClasses(ref_option->client_classes_));
         ASSERT_EQ(1, cbptr_->deleteOption4(ServerSelector::ANY(),
                                            subnet->getID(),
                                            ref_option->option_->getType(),
                                            DHCP4_OPTION_SPACE,
-                                           cclasses));
+                                           ref_option->copyClientClasses()));
     }
 
     // Re-fetch the subnet.
@@ -5128,13 +5123,12 @@ GenericConfigBackendDHCPv4Test::poolOption4WithClientClassesTest() {
 
     // Now make sure that we can delete the options individually.
     for (auto const& ref_option : ref_options) {
-        ClientClassesPtr cclasses(new ClientClasses(ref_option->client_classes_));
         ASSERT_EQ(1, cbptr_->deleteOption4(ServerSelector::ANY(),
                                            pool->getFirstAddress(),
                                            pool->getLastAddress(),
                                            ref_option->option_->getType(),
                                            DHCP4_OPTION_SPACE,
-                                           cclasses));
+                                           ref_option->copyClientClasses()));
     }
 
     // Re-fetch the subnet.