From: Marcin Siodelski Date: Thu, 13 Feb 2014 13:33:02 +0000 (+0100) Subject: [3316] Implemented function to check if specified tuple is in VC option. X-Git-Tag: bind10-1.2.0beta1-release~35^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a0eb24bea3138ebb0d3d1543d7fa5e8c3a1ee676;p=thirdparty%2Fkea.git [3316] Implemented function to check if specified tuple is in VC option. --- diff --git a/src/lib/dhcp/opaque_data_tuple.cc b/src/lib/dhcp/opaque_data_tuple.cc index 42c04eb44a..f35721ad1f 100644 --- a/src/lib/dhcp/opaque_data_tuple.cc +++ b/src/lib/dhcp/opaque_data_tuple.cc @@ -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)); } diff --git a/src/lib/dhcp/opaque_data_tuple.h b/src/lib/dhcp/opaque_data_tuple.h index ed1b25c659..82ea1ad394 100644 --- a/src/lib/dhcp/opaque_data_tuple.h +++ b/src/lib/dhcp/opaque_data_tuple.h @@ -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. /// diff --git a/src/lib/dhcp/option_vendor_class.cc b/src/lib/dhcp/option_vendor_class.cc index 6f05d52121..c211b2f0fc 100644 --- a/src/lib/dhcp/option_vendor_class.cc +++ b/src/lib/dhcp/option_vendor_class.cc @@ -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. diff --git a/src/lib/dhcp/option_vendor_class.h b/src/lib/dhcp/option_vendor_class.h index 35daff31a2..1d43078bcc 100644 --- a/src/lib/dhcp/option_vendor_class.h +++ b/src/lib/dhcp/option_vendor_class.h @@ -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(); diff --git a/src/lib/dhcp/tests/option_vendor_class_unittest.cc b/src/lib/dhcp/tests/option_vendor_class_unittest.cc index 4028710356..2315e1e586 100644 --- a/src/lib/dhcp/tests/option_vendor_class_unittest.cc +++ b/src/lib/dhcp/tests/option_vendor_class_unittest.cc @@ -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);