]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#571,!306] Modified MySQL CB to use factory functions to allocate objects.
authorMarcin Siodelski <marcin@isc.org>
Wed, 17 Apr 2019 17:13:24 +0000 (19:13 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 18 Apr 2019 19:02:07 +0000 (21:02 +0200)
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc

index 3a88328ea776c5615aa6f2c0363166c56c53550c..901df2542dad7086c210b515e72e6c05623907e6 100644 (file)
@@ -323,9 +323,9 @@ public:
                 auto valid_lifetime = createTriplet(out_bindings[19]);
 
                 // Create subnet with basic settings.
-                last_subnet.reset(new Subnet4(prefix_pair.first, prefix_pair.second,
+                last_subnet = Subnet4::create(prefix_pair.first, prefix_pair.second,
                                               renew_timer, rebind_timer,
-                                              valid_lifetime, subnet_id));
+                                              valid_lifetime, subnet_id);
 
                 // 4o6_interface
                 if (!out_bindings[2]->amNull()) {
@@ -336,8 +336,8 @@ public:
                     std::string dhcp4o6_interface_id = out_bindings[3]->getString();
                     OptionBuffer dhcp4o6_interface_id_buf(dhcp4o6_interface_id.begin(),
                                                           dhcp4o6_interface_id.end());
-                    OptionPtr option_dhcp4o6_interface_id(new Option(Option::V6, D6O_INTERFACE_ID,
-                                                                     dhcp4o6_interface_id_buf));
+                    OptionPtr option_dhcp4o6_interface_id =
+                        Option::create(Option::V6, D6O_INTERFACE_ID, dhcp4o6_interface_id_buf);
                     last_subnet->get4o6().setInterfaceId(option_dhcp4o6_interface_id);
                 }
                 // 4o6_subnet
@@ -459,8 +459,8 @@ public:
                 (out_bindings[22]->getInteger<uint32_t>() != 0) &&
                 (out_bindings[20]->getInteger<uint64_t>() > last_pool_id)) {
                 last_pool_id = out_bindings[20]->getInteger<uint64_t>();
-                last_pool.reset(new Pool4(IOAddress(out_bindings[21]->getInteger<uint32_t>()),
-                                          IOAddress(out_bindings[22]->getInteger<uint32_t>())));
+                last_pool = Pool4::create(IOAddress(out_bindings[21]->getInteger<uint32_t>()),
+                                          IOAddress(out_bindings[22]->getInteger<uint32_t>()));
                 last_subnet->addPool(last_pool);
             }
 
@@ -649,8 +649,8 @@ public:
 
                 last_pool_id = out_bindings[0]->getInteger<uint64_t>();
 
-                last_pool.reset(new Pool4(IOAddress(out_bindings[1]->getInteger<uint32_t>()),
-                                          IOAddress(out_bindings[2]->getInteger<uint32_t>())));
+                last_pool = Pool4::create(IOAddress(out_bindings[1]->getInteger<uint32_t>()),
+                                          IOAddress(out_bindings[2]->getInteger<uint32_t>()));
                 pools.push_back(last_pool);
                 pool_ids.push_back(last_pool_id);
             }
@@ -860,7 +860,7 @@ public:
         for (auto option_space : option_spaces) {
             OptionContainerPtr options = subnet->getCfgOption()->getAll(option_space);
             for (auto desc = options->begin(); desc != options->end(); ++desc) {
-                OptionDescriptorPtr desc_copy(new OptionDescriptor(*desc));
+                OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc);
                 desc_copy->space_name_ = option_space;
                 createUpdateOption4(server_selector, subnet->getID(), desc_copy,
                                     true);
@@ -892,7 +892,7 @@ public:
         for (auto option_space : option_spaces) {
             OptionContainerPtr options = pool->getCfgOption()->getAll(option_space);
             for (auto desc = options->begin(); desc != options->end(); ++desc) {
-                OptionDescriptorPtr desc_copy(new OptionDescriptor(*desc));
+                OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc);
                 desc_copy->space_name_ = option_space;
                 createUpdateOption4(server_selector, pool_id, desc_copy, true);
             }
@@ -1037,7 +1037,7 @@ public:
             if (last_network_id != out_bindings[0]->getInteger<uint64_t>()) {
 
                 last_network_id = out_bindings[0]->getInteger<uint64_t>();
-                last_network.reset(new SharedNetwork4(out_bindings[1]->getString()));
+                last_network = SharedNetwork4::create(out_bindings[1]->getString());
                 last_network->setId(last_network_id);
 
                 // client_class
@@ -1326,7 +1326,7 @@ public:
         for (auto option_space : option_spaces) {
             OptionContainerPtr options = shared_network->getCfgOption()->getAll(option_space);
             for (auto desc = options->begin(); desc != options->end(); ++desc) {
-                OptionDescriptorPtr desc_copy(new OptionDescriptor(*desc));
+                OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc);
                 desc_copy->space_name_ = option_space;
                 createUpdateOption4(server_selector, shared_network->getName(),
                                     desc_copy, true);
index d6de23e3902846c90949dcbdc53e2154d348094c..daf6115cfa8143eefc28810c3513cce6d133ed74 100644 (file)
@@ -168,11 +168,12 @@ MySqlConfigBackendImpl::getRecentAuditEntries(const int index,
 
             // Create new audit entry and add it to the collection of received
             // entries.
-            AuditEntryPtr audit_entry(new AuditEntry(out_bindings[1]->getString(),
-                                                     out_bindings[2]->getInteger<uint64_t>(),
-                                                     mod_type,
-                                                     out_bindings[4]->getTimestamp(),
-                                                     out_bindings[5]->getStringOrDefault("")));
+            AuditEntryPtr audit_entry =
+                AuditEntry::create(out_bindings[1]->getString(),
+                                   out_bindings[2]->getInteger<uint64_t>(),
+                                   mod_type,
+                                   out_bindings[4]->getTimestamp(),
+                                   out_bindings[5]->getStringOrDefault(""));
             audit_entries.insert(audit_entry);
         });
     }
@@ -317,18 +318,18 @@ MySqlConfigBackendImpl::getOptionDefs(const int index,
             bool array_type = static_cast<bool>(out_bindings[6]->getInteger<uint8_t>());
             if (array_type) {
                 // Create array option.
-                last_def.reset(new OptionDefinition(out_bindings[2]->getString(),
+                last_def = OptionDefinition::create(out_bindings[2]->getString(),
                                                     out_bindings[1]->getInteger<uint16_t>(),
                                                     static_cast<OptionDataType>
                                                     (out_bindings[4]->getInteger<uint8_t>()),
-                                                    array_type));
+                                                    array_type);
             } else {
                 // Create non-array option.
-                last_def.reset(new OptionDefinition(out_bindings[2]->getString(),
+                last_def = OptionDefinition::create(out_bindings[2]->getString(),
                                                     out_bindings[1]->getInteger<uint16_t>(),
                                                     static_cast<OptionDataType>
                                                     (out_bindings[4]->getInteger<uint8_t>()),
-                                                    out_bindings[7]->getStringOrDefault("").c_str()));
+                                                    out_bindings[7]->getStringOrDefault("").c_str());
             }
 
             // space
@@ -480,7 +481,7 @@ MySqlConfigBackendImpl::getOption(const int index,
     in_bindings.push_back(MySqlBinding::createString(space));
     getOptions(index, in_bindings, universe, options);
     return (options.empty() ? OptionDescriptorPtr() :
-            OptionDescriptorPtr(new OptionDescriptor(*options.begin())));
+            OptionDescriptor::create(*options.begin()));
 }
 
 OptionContainer
@@ -547,7 +548,7 @@ MySqlConfigBackendImpl::getOption(const int index,
     in_bindings.push_back(MySqlBinding::createString(space));
     getOptions(index, in_bindings, universe, options);
     return (options.empty() ? OptionDescriptorPtr() :
-            OptionDescriptorPtr(new OptionDescriptor(*options.begin())));
+            OptionDescriptor::create(*options.begin()));
 }
 
 OptionDescriptorPtr
@@ -586,7 +587,7 @@ MySqlConfigBackendImpl::getOption(const int index,
     in_bindings.push_back(MySqlBinding::createString(space));
     getOptions(index, in_bindings, universe, options);
     return (options.empty() ? OptionDescriptorPtr() :
-            OptionDescriptorPtr(new OptionDescriptor(*options.begin())));
+            OptionDescriptor::create(*options.begin()));
 }
 
 OptionDescriptorPtr
@@ -616,7 +617,7 @@ MySqlConfigBackendImpl::getOption(const int index,
     in_bindings.push_back(MySqlBinding::createString(space));
     getOptions(index, in_bindings, universe, options);
     return (options.empty() ? OptionDescriptorPtr() :
-            OptionDescriptorPtr(new OptionDescriptor(*options.begin())));
+            OptionDescriptor::create(*options.begin()));
 }
 
 void
@@ -699,7 +700,7 @@ MySqlConfigBackendImpl::processOptionRow(const Option::Universe& universe,
     // Get formatted value if available.
     std::string formatted_value = (*(first_binding + 3))->getStringOrDefault("");
 
-    OptionPtr option(new Option(universe, code));
+    OptionPtr option = Option::create(universe, code);
 
     // If we don't have a formatted value, check for a blob. Add it to the
     // option if it exists.
@@ -717,7 +718,7 @@ MySqlConfigBackendImpl::processOptionRow(const Option::Universe& universe,
     // Create option descriptor which encapsulates our option and adds
     // additional information, i.e. whether the option is persistent,
     // its option space and timestamp.
-    OptionDescriptorPtr desc(new OptionDescriptor(option, persistent, formatted_value));
+    OptionDescriptorPtr desc = OptionDescriptor::create(option, persistent, formatted_value);
     desc->space_name_ = space;
     desc->setModificationTime((*(first_binding + 11))->getTimestamp());