From: Marcin Siodelski Date: Wed, 17 Apr 2019 17:13:24 +0000 (+0200) Subject: [#571,!306] Modified MySQL CB to use factory functions to allocate objects. X-Git-Tag: Kea-1.6.0-beta~229 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51aa6f6f4c6d7436be40df1b07171dac82385419;p=thirdparty%2Fkea.git [#571,!306] Modified MySQL CB to use factory functions to allocate objects. --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index 3a88328ea7..901df2542d 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -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() != 0) && (out_bindings[20]->getInteger() > last_pool_id)) { last_pool_id = out_bindings[20]->getInteger(); - last_pool.reset(new Pool4(IOAddress(out_bindings[21]->getInteger()), - IOAddress(out_bindings[22]->getInteger()))); + last_pool = Pool4::create(IOAddress(out_bindings[21]->getInteger()), + IOAddress(out_bindings[22]->getInteger())); last_subnet->addPool(last_pool); } @@ -649,8 +649,8 @@ public: last_pool_id = out_bindings[0]->getInteger(); - last_pool.reset(new Pool4(IOAddress(out_bindings[1]->getInteger()), - IOAddress(out_bindings[2]->getInteger()))); + last_pool = Pool4::create(IOAddress(out_bindings[1]->getInteger()), + IOAddress(out_bindings[2]->getInteger())); 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()) { last_network_id = out_bindings[0]->getInteger(); - 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); diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc index d6de23e390..daf6115cfa 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc @@ -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(), - mod_type, - out_bindings[4]->getTimestamp(), - out_bindings[5]->getStringOrDefault(""))); + AuditEntryPtr audit_entry = + AuditEntry::create(out_bindings[1]->getString(), + out_bindings[2]->getInteger(), + 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(out_bindings[6]->getInteger()); 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(), static_cast (out_bindings[4]->getInteger()), - 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(), static_cast (out_bindings[4]->getInteger()), - 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());