From: Marcin Siodelski Date: Mon, 9 Sep 2013 10:49:51 +0000 (+0200) Subject: [3035] Added a function to return the number of labels in the FQDN. X-Git-Tag: bind10-1.2.0beta1-release~102^2~21^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fc2b2f8fa482e56c2c6f7e1e49db4129e9c5e7e6;p=thirdparty%2Fkea.git [3035] Added a function to return the number of labels in the FQDN. --- diff --git a/src/lib/dhcp/option_custom.h b/src/lib/dhcp/option_custom.h index a7d2b95b02..6ae0b1837c 100644 --- a/src/lib/dhcp/option_custom.h +++ b/src/lib/dhcp/option_custom.h @@ -105,7 +105,6 @@ public: template void addArrayDataField(const T value) { checkArrayType(); - OptionDataType data_type = definition_.getType(); if (OptionDataTypeTraits::type != data_type) { isc_throw(isc::dhcp::InvalidDataType, diff --git a/src/lib/dhcp/option_data_types.cc b/src/lib/dhcp/option_data_types.cc index 3c55ada3af..b2e84a33cb 100644 --- a/src/lib/dhcp/option_data_types.cc +++ b/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& buf) { std::string value; diff --git a/src/lib/dhcp/option_data_types.h b/src/lib/dhcp/option_data_types.h index 35d6a1f8b8..253776f29a 100644 --- a/src/lib/dhcp/option_data_types.h +++ b/src/lib/dhcp/option_data_types.h @@ -375,6 +375,14 @@ public: std::vector& 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.