Commit 3328fb38 authored by Marcin Siodelski's avatar Marcin Siodelski

[2940] Addressed review comments.

parent 672d4907
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
// //
// Permission to use, copy, modify, and/or distribute this software for any // Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above // purpose with or without fee is hereby granted, provided that the above
...@@ -104,7 +104,7 @@ ClientId::ClientId(const uint8_t *clientid, size_t len) ...@@ -104,7 +104,7 @@ ClientId::ClientId(const uint8_t *clientid, size_t len)
} }
// Returns a copy of client-id data // Returns a copy of client-id data
std::vector<uint8_t> ClientId::getClientId() const { const std::vector<uint8_t>& ClientId::getClientId() const {
return (duid_); return (duid_);
} }
......
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
// //
// Permission to use, copy, modify, and/or distribute this software for any // Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above // purpose with or without fee is hereby granted, provided that the above
...@@ -116,8 +116,13 @@ public: ...@@ -116,8 +116,13 @@ public:
/// @brief Constructor based on array and array size /// @brief Constructor based on array and array size
ClientId(const uint8_t* clientid, size_t len); ClientId(const uint8_t* clientid, size_t len);
/// @brief Returns reference to the client-id data /// @brief Returns reference to the client-id data.
std::vector<uint8_t> getClientId() const; ///
/// @warning Since this function returns a reference to the vector (not a
/// copy) the returned object must be used with caution because it remains
/// valid only for the time period when the object which returned it is
/// valid.
const std::vector<uint8_t>& getClientId() const;
/// @brief Returns textual representation of a DUID (e.g. 00:01:02:03:ff) /// @brief Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
std::string toText() const; std::string toText() const;
......
...@@ -74,10 +74,11 @@ Lease4::Lease4(const Lease4& other) ...@@ -74,10 +74,11 @@ Lease4::Lease4(const Lease4& other)
} }
} }
std::vector<uint8_t> const std::vector<uint8_t>&
Lease4::getClientIdVector() const { Lease4::getClientIdVector() const {
if(!client_id_) { if(!client_id_) {
return std::vector<uint8_t>(); static std::vector<uint8_t> empty_vec;
return (empty_vec);
} }
return (client_id_->getClientId()); return (client_id_->getClientId());
......
...@@ -211,9 +211,14 @@ struct Lease4 : public Lease { ...@@ -211,9 +211,14 @@ struct Lease4 : public Lease {
/// @brief Returns a client identifier. /// @brief Returns a client identifier.
/// ///
/// @return A client identifier as vector, or an empty vector if client /// @warning Since the function returns the reference to a vector (not a
/// identifier is NULL. /// copy), the returned object should be used with caution because it will
std::vector<uint8_t> getClientIdVector() const; /// remain valid only for the period of time when an object which returned
/// it exists.
///
/// @return A reference to a vector holding client identifier,
/// or an empty vector if client identifier is NULL.
const std::vector<uint8_t>& getClientIdVector() const;
/// @brief Assignment operator. /// @brief Assignment operator.
/// ///
......
...@@ -80,7 +80,7 @@ Memfile_LeaseMgr::getLease4(const HWAddr& hwaddr) const { ...@@ -80,7 +80,7 @@ Memfile_LeaseMgr::getLease4(const HWAddr& hwaddr) const {
lease != idx.end(); ++lease) { lease != idx.end(); ++lease) {
// Every Lease4 has a hardware address, so we can compare it // Every Lease4 has a hardware address, so we can compare it
if((*lease)->hwaddr_ == hwaddr.hwaddr_) { if ((*lease)->hwaddr_ == hwaddr.hwaddr_) {
collection.push_back((*lease)); collection.push_back((*lease));
} }
} }
......
...@@ -330,7 +330,7 @@ protected: ...@@ -330,7 +330,7 @@ protected:
// lease: client id and subnet id. // lease: client id and subnet id.
boost::multi_index::composite_key< boost::multi_index::composite_key<
Lease4, Lease4,
boost::multi_index::const_mem_fun<Lease4, std::vector<uint8_t>, boost::multi_index::const_mem_fun<Lease4, const std::vector<uint8_t>&,
&Lease4::getClientIdVector>, &Lease4::getClientIdVector>,
// The subnet id is accessed through the subnet_id_ member. // The subnet id is accessed through the subnet_id_ member.
boost::multi_index::member<Lease, uint32_t, &Lease::subnet_id_> boost::multi_index::member<Lease, uint32_t, &Lease::subnet_id_>
...@@ -343,7 +343,7 @@ protected: ...@@ -343,7 +343,7 @@ protected:
// lease: client id and subnet id. // lease: client id and subnet id.
boost::multi_index::composite_key< boost::multi_index::composite_key<
Lease4, Lease4,
boost::multi_index::const_mem_fun<Lease4, std::vector<uint8_t>, boost::multi_index::const_mem_fun<Lease4, const std::vector<uint8_t>&,
&Lease4::getClientIdVector>, &Lease4::getClientIdVector>,
// The hardware address is held in the hwaddr_ member of the // The hardware address is held in the hwaddr_ member of the
// Lease4 object. // Lease4 object.
......
...@@ -545,7 +545,7 @@ GenericLeaseMgrTest::testGetLease4HWAddr() { ...@@ -545,7 +545,7 @@ GenericLeaseMgrTest::testGetLease4HWAddr() {
} }
void void
GenericLeaseMgrTest::testLease4ClientIdHWAddrSubnetId() { GenericLeaseMgrTest::testGetLease4ClientIdHWAddrSubnetId() {
Lease4Ptr leaseA = initializeLease4(straddress4_[4]); Lease4Ptr leaseA = initializeLease4(straddress4_[4]);
Lease4Ptr leaseB = initializeLease4(straddress4_[5]); Lease4Ptr leaseB = initializeLease4(straddress4_[5]);
Lease4Ptr leaseC = initializeLease4(straddress4_[6]); Lease4Ptr leaseC = initializeLease4(straddress4_[6]);
......
...@@ -116,7 +116,7 @@ public: ...@@ -116,7 +116,7 @@ public:
void testGetLease4HWAddr(); void testGetLease4HWAddr();
/// @brief Test lease retrieval using client id, HW address and subnet id. /// @brief Test lease retrieval using client id, HW address and subnet id.
void testLease4ClientIdHWAddrSubnetId(); void testGetLease4ClientIdHWAddrSubnetId();
// Member variables // Member variables
std::vector<std::string> straddress4_; ///< String forms of IPv4 addresses std::vector<std::string> straddress4_; ///< String forms of IPv4 addresses
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment