Browse Source

[3035] Added a function to return the number of labels in the FQDN.

Marcin Siodelski 11 years ago
parent
commit
fc2b2f8fa4

+ 0 - 1
src/lib/dhcp/option_custom.h

@@ -105,7 +105,6 @@ public:
     template<typename T>
     void addArrayDataField(const T value) {
         checkArrayType();
-
         OptionDataType data_type = definition_.getType();
         if (OptionDataTypeTraits<T>::type != data_type) {
             isc_throw(isc::dhcp::InvalidDataType,

+ 10 - 0
src/lib/dhcp/option_data_types.cc

@@ -227,6 +227,16 @@ OptionDataTypeUtil::writeFqdn(const std::string& fqdn,
     }
 }
 
+unsigned int
+OptionDataTypeUtil::getLabelCount(const std::string& text_name) {
+    try {
+        isc::dns::Name name(text_name);
+        return (name.getLabelCount());
+    } catch (const isc::Exception& ex) {
+        isc_throw(BadDataTypeCast, ex.what());
+    }
+}
+
 std::string
 OptionDataTypeUtil::readString(const std::vector<uint8_t>& buf) {
     std::string value;

+ 8 - 0
src/lib/dhcp/option_data_types.h

@@ -375,6 +375,14 @@ public:
                           std::vector<uint8_t>& buf,
                           const bool downcase = false);
 
+    /// @brief Return the number of labels in the Name.
+    ///
+    /// @param text_name A text representation of the name.
+    ///
+    /// @return A number of labels in the provided name.
+    /// @throw isc::BadCast if provided name is malformed.
+    static unsigned int getLabelCount(const std::string& text_name);
+
     /// @brief Read string value from a buffer.
     ///
     /// @param buf input buffer.