Parcourir la source

[2940] Addressed review comments.

Marcin Siodelski il y a 11 ans
Parent
commit
3328fb3879

+ 2 - 2
src/lib/dhcp/duid.cc

@@ -1,4 +1,4 @@
-// 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
 // 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)
 }
 
 // Returns a copy of client-id data
-std::vector<uint8_t> ClientId::getClientId() const {
+const std::vector<uint8_t>& ClientId::getClientId() const {
     return (duid_);
 }
 

+ 8 - 3
src/lib/dhcp/duid.h

@@ -1,4 +1,4 @@
-// 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
 // purpose with or without fee is hereby granted, provided that the above
@@ -116,8 +116,13 @@ public:
     /// @brief Constructor based on array and array size
     ClientId(const uint8_t* clientid, size_t len);
 
-    /// @brief Returns reference to the client-id data
-    std::vector<uint8_t> getClientId() const;
+    /// @brief Returns reference to the client-id data.
+    ///
+    /// @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)
     std::string toText() const;

+ 3 - 2
src/lib/dhcpsrv/lease.cc

@@ -74,10 +74,11 @@ Lease4::Lease4(const Lease4& other)
     }
 }
 
-std::vector<uint8_t>
+const std::vector<uint8_t>&
 Lease4::getClientIdVector() const {
     if(!client_id_) {
-        return std::vector<uint8_t>();
+        static std::vector<uint8_t> empty_vec;
+        return (empty_vec);
     }
 
     return (client_id_->getClientId());

+ 8 - 3
src/lib/dhcpsrv/lease.h

@@ -211,9 +211,14 @@ struct Lease4 : public Lease {
 
     /// @brief Returns a client identifier.
     ///
-    /// @return A client identifier as vector, or an empty vector if client
-    /// identifier is NULL.
-    std::vector<uint8_t> getClientIdVector() const;
+    /// @warning Since the function returns the reference to a vector (not a
+    /// copy), the returned object should be used with caution because it will
+    /// 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.
     ///

+ 1 - 1
src/lib/dhcpsrv/memfile_lease_mgr.cc

@@ -80,7 +80,7 @@ Memfile_LeaseMgr::getLease4(const HWAddr& hwaddr) const {
         lease != idx.end(); ++lease) {
 
         // 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));
         }
     }

+ 2 - 2
src/lib/dhcpsrv/memfile_lease_mgr.h

@@ -330,7 +330,7 @@ protected:
                 // lease: client id and subnet id.
                 boost::multi_index::composite_key<
                     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>,
                     // The subnet id is accessed through the subnet_id_ member.
                     boost::multi_index::member<Lease, uint32_t, &Lease::subnet_id_>
@@ -343,7 +343,7 @@ protected:
                 // lease: client id and subnet id.
                 boost::multi_index::composite_key<
                     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>,
                     // The hardware address is held in the hwaddr_ member of the
                     // Lease4 object.

+ 1 - 1
src/lib/dhcpsrv/tests/test_utils.cc

@@ -545,7 +545,7 @@ GenericLeaseMgrTest::testGetLease4HWAddr() {
 }
 
 void
-GenericLeaseMgrTest::testLease4ClientIdHWAddrSubnetId() {
+GenericLeaseMgrTest::testGetLease4ClientIdHWAddrSubnetId() {
     Lease4Ptr leaseA = initializeLease4(straddress4_[4]);
     Lease4Ptr leaseB = initializeLease4(straddress4_[5]);
     Lease4Ptr leaseC = initializeLease4(straddress4_[6]);

+ 1 - 1
src/lib/dhcpsrv/tests/test_utils.h

@@ -116,7 +116,7 @@ public:
     void testGetLease4HWAddr();
 
     /// @brief Test lease retrieval using client id, HW address and subnet id.
-    void testLease4ClientIdHWAddrSubnetId();
+    void testGetLease4ClientIdHWAddrSubnetId();
 
     // Member variables
     std::vector<std::string>  straddress4_;   ///< String forms of IPv4 addresses