]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3035] Added a function to return the number of labels in the FQDN.
authorMarcin Siodelski <marcin@isc.org>
Mon, 9 Sep 2013 10:49:51 +0000 (12:49 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 9 Sep 2013 10:49:51 +0000 (12:49 +0200)
src/lib/dhcp/option_custom.h
src/lib/dhcp/option_data_types.cc
src/lib/dhcp/option_data_types.h

index a7d2b95b02800658f88a9319ab9b31324e1fa936..6ae0b1837ccdddc4a2348fbcd9e38f49ad989155 100644 (file)
@@ -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,
index 3c55ada3af8b6d375ff55cbc77b411e8f2db793d..b2e84a33cb96f1b9cfb6a9d8fbb2b4d5ce021032 100644 (file)
@@ -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;
index 35d6a1f8b8326eb26bd19edb6bedb4b278a8f07c..253776f29ac4f0c23db0489c231be0ae8dbfc86a 100644 (file)
@@ -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.