Commit 01eba32f authored by Razvan Becheriu's avatar Razvan Becheriu

[1040] separated delete functions

parent 5f9937b1
......@@ -126,7 +126,7 @@ private:
/// @brief Callback that will be called from iface_mgr when data
/// is received over control socket.
///
/// This static callback method is called from IfaceMgr::receive6() method,
/// This static callback method is called from IfaceMgr::receive4() method,
/// when there is a new command or configuration sent over control socket
/// (that was sent from some yet unspecified sender).
static void sessionReader(void);
......
......@@ -2894,7 +2894,7 @@ Dhcpv4Srv::processRelease(Pkt4Ptr& release, AllocEngine::ClientContext4Ptr& cont
// Callout didn't indicate to skip the release process. Let's release
// the lease.
if (!skip) {
bool success = LeaseMgrFactory::instance().deleteLease(lease->addr_);
bool success = LeaseMgrFactory::instance().deleteLease(lease);
if (success) {
......@@ -3785,5 +3785,5 @@ void Dhcpv4Srv::discardPackets() {
HooksManager::clearParkingLots();
}
} // namespace dhcp
} // namespace isc
} // namespace dhcp
} // namespace isc
......@@ -1647,7 +1647,9 @@ TEST_F(Dhcpv4SrvTest, RenewBasic) {
// Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr));
Lease4Ptr lease(new Lease4());
lease->addr_ = addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
}
// Renew*Lifetime common code.
......@@ -1768,7 +1770,9 @@ TEST_F(Dhcpv4SrvTest, RenewDefaultLifetime) {
// Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(c.addr));
Lease4Ptr lease(new Lease4());
lease->addr_ = c.addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
}
// This test verifies that renewal returns the specified valid lifetime
......@@ -1813,7 +1817,9 @@ TEST_F(Dhcpv4SrvTest, RenewHintLifetime) {
// Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(c.addr));
Lease4Ptr lease(new Lease4());
lease->addr_ = c.addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
}
// This test verifies that renewal returns the min valid lifetime
......@@ -1858,7 +1864,9 @@ TEST_F(Dhcpv4SrvTest, RenewMinLifetime) {
// Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(c.addr));
Lease4Ptr lease(new Lease4());
lease->addr_ = c.addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
}
// This test verifies that renewal returns the max valid lifetime
......@@ -1902,7 +1910,9 @@ TEST_F(Dhcpv4SrvTest, RenewMaxLifetime) {
// Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(c.addr));
Lease4Ptr lease(new Lease4());
lease->addr_ = c.addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
}
} // end of Renew*Lifetime
......@@ -3903,4 +3913,4 @@ TEST_F(Dhcpv4SrvTest, userContext) {
/// @todo: Implement proper tests for MySQL lease/host database,
/// see ticket #4214.
}; // end of anonymous namespace
} // namespace
......@@ -735,7 +735,7 @@ public:
std::vector<uint8_t> id_test;
handle.getArgument("id_value", id_test);
std::vector<uint8_t> id = { 0x66, 0x6f, 0x6f }; // foo
std::vector<uint8_t> id = { 0x66, 0x6f, 0x6f }; // foo
handle.setArgument("id_value", id);
handle.setArgument("id_type", Host::IDENT_FLEX);
......@@ -1827,7 +1827,9 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSimple) {
sort(expected_argument_names.begin(), expected_argument_names.end());
EXPECT_TRUE(callback_argument_names_ == expected_argument_names);
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr));
Lease4Ptr lease(new Lease4());
lease->addr_ = addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
// Pkt passed to a callout must be configured to copy retrieved options.
EXPECT_TRUE(callback_qry_options_copy_);
......@@ -1896,7 +1898,9 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSkip) {
EXPECT_EQ(temp_valid, l->valid_lft_);
EXPECT_EQ(temp_timestamp, l->cltt_);
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr));
Lease4Ptr lease(new Lease4());
lease->addr_ = addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
// Check if the callout handle state was reset after the callout.
checkCalloutHandleReset(req);
......
......@@ -198,7 +198,7 @@ std::set<std::string> dhcp6_statistics = {
"pkt6-receive-drop"
};
}; // anonymous namespace
} // namespace
namespace isc {
namespace dhcp {
......@@ -1364,7 +1364,7 @@ Dhcpv6Srv::sanityCheck(const Pkt6Ptr& pkt) {
switch (pkt->getType()) {
case DHCPV6_SOLICIT:
case DHCPV6_REBIND:
case DHCPV6_CONFIRM:
case DHCPV6_CONFIRM:
sanityCheck(pkt, MANDATORY, FORBIDDEN);
return (true);
......@@ -1587,6 +1587,7 @@ Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
if (answer_opt) {
answer->addOption(answer_opt);
}
break;
}
default:
break;
......@@ -2677,7 +2678,7 @@ Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
bool success = false; // was the removal operation successful?
if (!skip) {
success = LeaseMgrFactory::instance().deleteLease(lease->addr_);
success = LeaseMgrFactory::instance().deleteLease(lease);
}
// Here the success should be true if we removed lease successfully
......@@ -2835,7 +2836,7 @@ Dhcpv6Srv::releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
bool success = false; // was the removal operation successful?
if (!skip) {
success = LeaseMgrFactory::instance().deleteLease(lease->addr_);
success = LeaseMgrFactory::instance().deleteLease(lease);
} else {
// Callouts decided to skip the next processing step. The next
// processing step would to send the packet, so skip at this
......@@ -4035,5 +4036,5 @@ Dhcpv6Srv::setTeeTimes(uint32_t preferred_lft, const Subnet6Ptr& subnet, Option6
}
}
};
};
} // namespace dhcp
} // namespace isc
......@@ -1046,7 +1046,9 @@ TEST_F(Dhcpv6SrvTest, RequestBasic) {
// check that the lease is really in the database
Lease6Ptr l = checkLease(duid_, reply->getOption(D6O_IA_NA), addr);
EXPECT_TRUE(l);
LeaseMgrFactory::instance().deleteLease(addr->getAddress());
Lease6Ptr lease(new Lease6());
lease->addr_ = addr->getAddress();
LeaseMgrFactory::instance().deleteLease(lease);
}
// This test verifies that incoming REQUEST can be handled properly, that a
......@@ -1112,7 +1114,9 @@ TEST_F(Dhcpv6SrvTest, pdRequestBasic) {
// check that the lease is really in the database
Lease6Ptr l = checkPdLease(duid_, reply->getOption(D6O_IA_PD), prf);
EXPECT_TRUE(l);
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(prf->getAddress()));
Lease6Ptr lease(new Lease6());
lease->addr_ = prf->getAddress();
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
}
// This test checks that the server is offering different addresses to different
......@@ -2975,4 +2979,4 @@ TEST_F(Dhcpv6SrvTest, calculateTeeTimers) {
/// @todo: Implement proper tests for MySQL lease/host database,
/// see ticket #4214.
} // end of anonymous namespace
} // namespace
......@@ -433,7 +433,9 @@ Dhcpv6SrvTest::testRenewBasic(Lease::Type type,
// equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(renew_addr));
Lease6Ptr lease(new Lease6());
lease->addr_ = renew_addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
}
void
......@@ -755,7 +757,9 @@ Dhcpv6SrvTest::testReleaseReject(Lease::Type type, const IOAddress& addr) {
EXPECT_EQ(1, stat->getInteger().first);
// Finally, let's cleanup the database
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr));
lease.reset(new Lease6());
lease->addr_ = addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
}
void
......@@ -964,6 +968,6 @@ NakedDhcpv6SrvTest::checkIA_NAStatusCode(
}
}
}; // end of isc::dhcp::test namespace
}; // end of isc::dhcp namespace
}; // end of isc namespace
} // namespace test
} // namespace dhcp
} // namespace isc
......@@ -838,7 +838,7 @@ public:
handle.getArgument("id_value", id_test);
// Ok, now set the identifier.
std::vector<uint8_t> id = { 0x66, 0x6f, 0x6f }; // foo
std::vector<uint8_t> id = { 0x66, 0x6f, 0x6f }; // foo
handle.setArgument("id_value", id);
handle.setArgument("id_type", Host::IDENT_FLEX);
......@@ -2857,7 +2857,9 @@ TEST_F(HooksDhcpv6SrvTest, leaseUpdateLease6Renew) {
// Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr_opt->getAddress()));
Lease6Ptr deleted_lease(new Lease6());
deleted_lease->addr_ = addr_opt->getAddress();
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(deleted_lease));
// Check if the callout handle state was reset after the callout.
checkCalloutHandleReset(req);
......@@ -3976,7 +3978,9 @@ TEST_F(HooksDhcpv6SrvTest, leaseUpdateLease6Rebind) {
// Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr_opt->getAddress()));
lease.reset(new Lease6());
lease->addr_ = addr_opt->getAddress();
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
// Check if the callout handle state was reset after the callout.
checkCalloutHandleReset(req);
......@@ -4958,4 +4962,4 @@ TEST_F(LoadUnloadDhcpv6SrvTest, Dhcpv6SrvConfigured) {
"3io_contextjson_confignetwork_stateserver_config"));
}
} // end of anonymous namespace
} // namespace
......@@ -472,7 +472,10 @@ TEST_F(RebindTest, directClientLostLease) {
Lease6 lease_client = client.getLease(0);
// The lease has been acquired. Now, let's explicitly remove it from the
// lease database.
LeaseMgrFactory::instance().deleteLease(lease_client.addr_);
Lease6Ptr lease(new Lease6());
lease->addr_ = lease_client.addr_;
LeaseMgrFactory::instance().deleteLease(lease);
// Send Rebind.
ASSERT_NO_THROW(client.doRebind());
......@@ -604,7 +607,9 @@ TEST_F(RebindTest, relayedClientLostLease) {
Lease6 lease_client = client.getLease(0);
// The lease has been acquired. Now, let's explicitly remove it from the
// lease database.
LeaseMgrFactory::instance().deleteLease(lease_client.addr_);
Lease6Ptr lease(new Lease6());
lease->addr_ = lease_client.addr_;
LeaseMgrFactory::instance().deleteLease(lease);
// Send Rebind.
ASSERT_NO_THROW(client.doRebind());
......@@ -1146,5 +1151,4 @@ TEST_F(RebindTest, optionsInheritance) {
ASSERT_TRUE(client.hasOptionWithAddress(D6O_SNTP_SERVERS, "3000:2::2"));
}
} // end of anonymous namespace
} // namespace
......@@ -1074,7 +1074,10 @@ LeaseCmdsImpl::lease4DelHandler(CalloutHandle& handle) {
}
}
if (LeaseMgrFactory::instance().deleteLease(addr)) {
Lease4Ptr lease(new Lease4());
lease->addr_ = addr;
if (LeaseMgrFactory::instance().deleteLease(lease)) {
setSuccessResponse(handle, "IPv4 lease deleted.");
} else {
setErrorResponse (handle, "IPv4 lease not found.", CONTROL_RESULT_EMPTY);
......@@ -1172,7 +1175,10 @@ LeaseCmdsImpl::lease6BulkApplyHandler(CalloutHandle& handle) {
// This may throw if the lease couldn't be deleted for
// any reason, but we still want to proceed with other
// leases.
if (LeaseMgrFactory::instance().deleteLease(lease_addr)) {
Lease6Ptr lease(new Lease6());
lease->addr_ = lease_addr;
if (LeaseMgrFactory::instance().deleteLease(lease)) {
++success_count;
} else {
......@@ -1319,7 +1325,10 @@ LeaseCmdsImpl::lease6DelHandler(CalloutHandle& handle) {
}
}
if (LeaseMgrFactory::instance().deleteLease(addr)) {
Lease6Ptr lease(new Lease6());
lease->addr_ = addr;
if (LeaseMgrFactory::instance().deleteLease(lease)) {
setSuccessResponse(handle, "IPv6 lease deleted.");
} else {
setErrorResponse (handle, "IPv6 lease not found.", CONTROL_RESULT_EMPTY);
......
......@@ -232,6 +232,8 @@ CqlConnection::openDatabase() {
try {
port_number = boost::lexical_cast<int32_t>(port);
if (port_number < 1 || port_number > 65535) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError,
"CqlConnection::openDatabase(): "
"port outside of range, expected "
......@@ -239,6 +241,8 @@ CqlConnection::openDatabase() {
<< port);
}
} catch (const boost::bad_lexical_cast& ex) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError,
"CqlConnection::openDatabase(): invalid "
"port, expected castable to int, instead got "
......@@ -265,12 +269,16 @@ CqlConnection::openDatabase() {
reconnect_wait_time_number =
boost::lexical_cast<int32_t>(reconnect_wait_time);
if (reconnect_wait_time_number < 0) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError,
"CqlConnection::openDatabase(): invalid reconnect "
"wait time, expected positive number, instead got "
<< reconnect_wait_time);
}
} catch (const boost::bad_lexical_cast& ex) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError,
"CqlConnection::openDatabase(): "
"invalid reconnect wait time, expected "
......@@ -287,6 +295,8 @@ CqlConnection::openDatabase() {
connect_timeout_number =
boost::lexical_cast<int32_t>(connect_timeout);
if (connect_timeout_number < 0) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError,
"CqlConnection::openDatabase(): "
"invalid connect timeout, expected "
......@@ -294,6 +304,8 @@ CqlConnection::openDatabase() {
<< connect_timeout);
}
} catch (const boost::bad_lexical_cast& ex) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError,
"CqlConnection::openDatabase(): invalid connect timeout, "
"expected castable to int, instead got \""
......@@ -308,6 +320,8 @@ CqlConnection::openDatabase() {
request_timeout_number =
boost::lexical_cast<int32_t>(request_timeout);
if (request_timeout_number < 0) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError,
"CqlConnection::openDatabase(): "
"invalid request timeout, expected "
......@@ -315,6 +329,8 @@ CqlConnection::openDatabase() {
<< request_timeout);
}
} catch (const boost::bad_lexical_cast& ex) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError,
"CqlConnection::openDatabase(): invalid request timeout, "
"expected castable to int, instead got \""
......@@ -328,6 +344,8 @@ CqlConnection::openDatabase() {
try {
tcp_keepalive_number = boost::lexical_cast<int32_t>(tcp_keepalive);
if (tcp_keepalive_number < 0) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError,
"CqlConnection::openDatabase(): "
"invalid TCP keepalive, expected "
......@@ -335,6 +353,8 @@ CqlConnection::openDatabase() {
<< tcp_keepalive);
}
} catch (const boost::bad_lexical_cast& ex) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError,
"CqlConnection::openDatabase(): invalid TCP keepalive, "
"expected castable to int, instead got \""
......@@ -371,6 +391,10 @@ CqlConnection::openDatabase() {
schema_meta_ = cass_session_get_schema_meta(session_);
keyspace_meta_ = cass_schema_meta_keyspace_by_name(schema_meta_, keyspace);
if (!keyspace_meta_) {
cass_session_free(session_);
session_ = NULL;
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOpenError, "CqlConnection::openDatabase(): "
"!cass_schema_meta_keyspace_by_name()");
}
......
......@@ -80,7 +80,7 @@ struct AllocEngineHooks {
// module is called.
AllocEngineHooks Hooks;
}; // anonymous namespace
} // namespace
namespace isc {
namespace dhcp {
......@@ -1480,7 +1480,7 @@ AllocEngine::removeNonmatchingReservedLeases6(ClientContext6& ctx,
// Remove this lease from LeaseMgr as it is reserved to someone
// else or doesn't belong to a pool.
LeaseMgrFactory::instance().deleteLease(candidate->addr_);
LeaseMgrFactory::instance().deleteLease(candidate);
// Update DNS if needed.
queueNCR(CHG_REMOVE, candidate);
......@@ -1523,7 +1523,7 @@ AllocEngine::removeNonmatchingReservedNoHostLeases6(ClientContext6& ctx,
}
// Remove this lease from LeaseMgr as it doesn't belong to a pool.
LeaseMgrFactory::instance().deleteLease(candidate->addr_);
LeaseMgrFactory::instance().deleteLease(candidate);
// Update DNS if needed.
queueNCR(CHG_REMOVE, candidate);
......@@ -1590,7 +1590,7 @@ AllocEngine::removeNonreservedLeases6(ClientContext6& ctx,
// simply remove it from the list.
// We have reservations, but not for this lease. Release it.
// Remove this lease from LeaseMgr
LeaseMgrFactory::instance().deleteLease((*lease)->addr_);
LeaseMgrFactory::instance().deleteLease(*lease);
// Update DNS if required.
queueNCR(CHG_REMOVE, *lease);
......@@ -1991,7 +1991,7 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) {
// Oh dear, the lease is no longer valid. We need to get rid of it.
// Remove this lease from LeaseMgr
LeaseMgrFactory::instance().deleteLease(lease->addr_);
LeaseMgrFactory::instance().deleteLease(lease);
// Updated DNS if required.
queueNCR(CHG_REMOVE, lease);
......@@ -2781,8 +2781,7 @@ void AllocEngine::reclaimLeaseInDatabase(const LeasePtrType& lease,
// Reclaim the lease - depending on the configuration, set the
// expired-reclaimed state or simply remove it.
if (remove_lease) {
lease_mgr.deleteLease(lease->addr_);
lease_mgr.deleteLease(lease);
} else if (!lease_update_fun.empty()) {
// Clear FQDN information as we have already sent the
// name change request to remove the DNS record.
......@@ -2803,8 +2802,8 @@ void AllocEngine::reclaimLeaseInDatabase(const LeasePtrType& lease,
}
} // end of isc::dhcp namespace
} // end of isc namespace
} // namespace dhcp
} // namespace isc
// ##########################################################################
// # DHCPv4 lease allocation code starts here.
......@@ -3018,7 +3017,7 @@ inAllowedPool(AllocEngine::ClientContext4& ctx, const IOAddress& address) {
return (false);
}
} // end of anonymous namespace
} // namespace
namespace isc {
namespace dhcp {
......@@ -3526,7 +3525,7 @@ AllocEngine::requestLease4(AllocEngine::ClientContext4& ctx) {
.arg(ctx.query_->getLabel())
.arg(client_lease->addr_.toText());
lease_mgr.deleteLease(client_lease->addr_);
lease_mgr.deleteLease(client_lease);
// Need to decrease statistic for assigned addresses.
StatsMgr::instance().addValue(
......@@ -4015,5 +4014,5 @@ AllocEngine::conditionalExtendLifetime(Lease& lease) const {
return (true);
}
}; // end of isc::dhcp namespace
}; // end of isc namespace
} // namespace dhcp
} // namespace isc
......@@ -1757,7 +1757,7 @@ private:
/// @brief A pointer to the @c AllocEngine object.
typedef boost::shared_ptr<AllocEngine> AllocEnginePtr;
}; // namespace isc::dhcp
}; // namespace isc
} // namespace dhcp
} // namespace isc
#endif // ALLOC_ENGINE_H
......@@ -26,6 +26,7 @@
#include <dhcp/hwaddr.h>
#include <asiolink/io_address.h>
#include <boost/make_shared.hpp>
using namespace isc::data;
using namespace isc::db;
......@@ -157,7 +158,7 @@ public:
/// @param address address of the lease to be deleted
/// @param data lease info in CQL format will be stored here
/// @param statement_tag tag identifying the query (optional)
void createBindForDelete(const IOAddress &address,
void createBindForDelete(const Lease4Ptr &lease,
AnyArray &data,
StatementTag statement_tag = NULL);
......@@ -621,14 +622,20 @@ CqlLease4Exchange::createBindForUpdate(const Lease4Ptr &lease, AnyArray &data,
}
void
CqlLease4Exchange::createBindForDelete(const IOAddress &address, AnyArray &data,
CqlLease4Exchange::createBindForDelete(const Lease4Ptr &lease, AnyArray &data,
StatementTag /* unused */) {
if (!lease) {
isc_throw(BadValue, "CqlLease4Exchange::createBindForDelete(): "
"Lease4 object is NULL");
}
// Store lease object to ensure it remains valid.
lease_ = lease;
// Set up the structures for the various components of the lease4
// structure.
try {
// address: int
address_ = static_cast<cass_int32_t>(address.toUint32());
address_ = static_cast<cass_int32_t>(lease_->addr_.toUint32());
// Start with a fresh array.
data.clear();
......@@ -637,8 +644,8 @@ CqlLease4Exchange::createBindForDelete(const IOAddress &address, AnyArray &data,
} catch (const Exception &ex) {
isc_throw(DbOperationError,
"CqlLease4Exchange::createBindForDelete(): "
"could not create bind array with address: "
<< address_ << ", reason: " << ex.what());
"could not create bind array from Lease4: "
<< lease_->addr_.toText() << ", reason: " << ex.what());
}
}
......@@ -712,7 +719,7 @@ CqlLease4Exchange::retrieve() {
time_t cltt = 0;
CqlExchange::convertFromDatabaseTime(expire_, valid_lifetime_, cltt);
HWAddrPtr hwaddr(new HWAddr(hwaddr_, HTYPE_ETHER));
HWAddrPtr hwaddr = boost::make_shared<HWAddr>(hwaddr_, HTYPE_ETHER);
uint32_t addr4 = static_cast<uint32_t>(address_);
......@@ -725,10 +732,10 @@ CqlLease4Exchange::retrieve() {
}
}
Lease4Ptr result(new Lease4(addr4, hwaddr, client_id_.data(),
client_id_.size(), valid_lifetime_,
cltt, subnet_id_, fqdn_fwd_, fqdn_rev_,
hostname_));
Lease4Ptr result(boost::make_shared<Lease4>(addr4, hwaddr, client_id_.data(),
client_id_.size(), valid_lifetime_,
cltt, subnet_id_, fqdn_fwd_, fqdn_rev_,
hostname_));
result->state_ = state_;
......@@ -787,12 +794,11 @@ CqlLease4Exchange::getExpiredLeases(const size_t &max_leases,
// If the number of leases is 0, we will return all leases. This is
// achieved by setting the limit to a very high value.
cass_int32_t limit = max_leases > 0u ?
static_cast<cass_int32_t>(max_leases) :
std::numeric_limits<cass_int32_t>::max();
cass_int32_t limit = max_leases > 0u ? static_cast<cass_int32_t>(max_leases) :
std::numeric_limits<cass_int32_t>::max();
for (cass_int32_t state = Lease::STATE_DEFAULT;
state <= Lease::STATE_EXPIRED_RECLAIMED; state++) {
for (cass_int32_t state = Lease::STATE_DEFAULT; state <= Lease::STATE_EXPIRED_RECLAIMED;
state++) {
if (state == keep_state) {
continue;
}
......@@ -804,8 +810,7 @@ CqlLease4Exchange::getExpiredLeases(const size_t &max_leases,
// Retrieve leases from the database.
Lease4Collection temp_collection;
getLeaseCollection(CqlLease4Exchange::GET_LEASE4_EXPIRE, data,
temp_collection);
getLeaseCollection(CqlLease4Exchange::GET_LEASE4_EXPIRE, data, temp_collection);
for (Lease4Ptr &lease : temp_collection) {
expired_leases.push_back(lease);
......@@ -861,10 +866,10 @@ public:
/// Fills in the CQL_BIND array for sending data in the Lease6 object to
/// the database. Used for DELETE statements.
///
/// @param address address of the lease to be deleted
/// @param lease address of the lease to be deleted
/// @param data lease info in CQL format will be stored here
/// @param statement_tag tag identifying the query (optional)
void createBindForDelete(const IOAddress &address,
void createBindForDelete(const Lease6Ptr &lease,
AnyArray &data,
StatementTag statement_tag = NULL);
......@@ -1390,14 +1395,26 @@ CqlLease6Exchange::createBindForUpdate(const Lease6Ptr &lease, AnyArray &data,
}
void
CqlLease6Exchange::createBindForDelete(const IOAddress &address, AnyArray &data,
CqlLease6Exchange::createBindForDelete(const Lease6Ptr &lease, AnyArray &data,
StatementTag /* unused */) {