]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3316] Implemented function to check if specified tuple is in VC option.
authorMarcin Siodelski <marcin@isc.org>
Thu, 13 Feb 2014 13:33:02 +0000 (14:33 +0100)
committerMarcin Siodelski <marcin@isc.org>
Thu, 13 Feb 2014 13:33:02 +0000 (14:33 +0100)
src/lib/dhcp/opaque_data_tuple.cc
src/lib/dhcp/opaque_data_tuple.h
src/lib/dhcp/option_vendor_class.cc
src/lib/dhcp/option_vendor_class.h
src/lib/dhcp/tests/option_vendor_class_unittest.cc

index 42c04eb44a5b065210a18c55c2cafe8315b55ab3..f35721ad1fd4552f787fc1ad0f705670d8c83c78 100644 (file)
@@ -89,7 +89,7 @@ OpaqueDataTuple::operator=(const std::string& other) {
 }
 
 bool
-OpaqueDataTuple::operator==(const std::string& other) {
+OpaqueDataTuple::operator==(const std::string& other) const {
     return (equals(other));
 }
 
index ed1b25c659cb6878ecc3e355ed6ccc8a86045010..82ea1ad394ecfd64087022f812a65cdd055fe007 100644 (file)
@@ -261,7 +261,7 @@ public:
     ///
     /// @param other String to compare the tuple against.
     /// @return true if data carried in the tuple is equal to the string.
-    bool operator==(const std::string& other);
+    bool operator==(const std::string& other) const;
 
     /// @brief Inequality operator.
     ///
index 6f05d5212131b2cf2ab1bd558114585cc5c776a5..c211b2f0fc701d29f9955403c89230a3256a3181 100644 (file)
@@ -130,6 +130,20 @@ OptionVendorClass::getTuple(const size_t at) const {
     return (tuples_[at]);
 }
 
+bool
+OptionVendorClass::hasTuple(const std::string& tuple_str) const {
+    // Iterate over existing tuples (there shouldn't be many of them),
+    // and try to match the searched one.
+    for (TuplesCollection::const_iterator it = tuples_.begin();
+         it != tuples_.end(); ++it) {
+        if (*it == tuple_str) {
+            return (true);
+        }
+    }
+    return (false);
+}
+
+
 uint16_t
 OptionVendorClass::len() {
     // The option starts with the header and enterprise id.
index 35daff31a224cda1883ff6b0619e7badab1291a7..1d43078bcca78d191dd8bf59adb08a967a69a633 100644 (file)
@@ -128,6 +128,13 @@ public:
         return (tuples_);
     }
 
+    /// @brief Checks if the Vendor Class holds the opaque data tuple with the
+    /// specified string.
+    ///
+    /// @param tuple_str String representation of the tuple being searched.
+    /// @return true if the specified tuple exists for this option.
+    bool hasTuple(const std::string& tuple_str) const;
+
     /// @brief Returns the full length of the option, including option header.
     virtual uint16_t len();
 
index 402871035640e23efc864cf7e3505c3d89d20f16..2315e1e5867795f14c2ce17b1a360ba20f8fbc0c 100644 (file)
@@ -74,6 +74,11 @@ TEST(OptionVendorClass, addTuple) {
     EXPECT_EQ("xyz", vendor_class.getTuple(0).getText());
     EXPECT_EQ("abc", vendor_class.getTuple(1).getText());
 
+    // Check that hasTuple correctly identifies existing tuples.
+    EXPECT_TRUE(vendor_class.hasTuple("xyz"));
+    EXPECT_TRUE(vendor_class.hasTuple("abc"));
+    EXPECT_FALSE(vendor_class.hasTuple("other"));
+
     // Attempt to add the tuple with 1 byte long length field should fail
     // for DHCPv6 option.
     OpaqueDataTuple tuple2(OpaqueDataTuple::LENGTH_1_BYTE);