From f4620596bd798f3c0e1d4b7738a5c4ca1730cf89 Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Mon, 1 Aug 2011 12:29:05 -0400 Subject: [PATCH 01/20] [trac1144] DS reworked and DLV added --- src/lib/dns/rdata/generic/detail/ds_like.h | 169 +++++++++++++++++++++ src/lib/dns/rdata/generic/dlv_32769.cc | 19 +++ src/lib/dns/rdata/generic/dlv_32769.h | 97 ++++++++++++ src/lib/dns/rdata/generic/ds_43.cc | 155 ------------------- src/lib/dns/rdata/generic/ds_43.h | 79 +++++++--- 5 files changed, 345 insertions(+), 174 deletions(-) create mode 100644 src/lib/dns/rdata/generic/detail/ds_like.h create mode 100644 src/lib/dns/rdata/generic/dlv_32769.cc create mode 100644 src/lib/dns/rdata/generic/dlv_32769.h diff --git a/src/lib/dns/rdata/generic/detail/ds_like.h b/src/lib/dns/rdata/generic/detail/ds_like.h new file mode 100644 index 0000000000..20cf09469d --- /dev/null +++ b/src/lib/dns/rdata/generic/detail/ds_like.h @@ -0,0 +1,169 @@ +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#ifndef __DS_LIKE_H +#define __DS_LIKE_H 1 + +#include + +#include +#include + +using namespace std; +using namespace isc::util; + +struct DSImpl { + // straightforward representation of DS RDATA fields + DSImpl(uint16_t tag, uint8_t algorithm, uint8_t digest_type, + const vector& digest) : + tag_(tag), algorithm_(algorithm), digest_type_(digest_type), + digest_(digest) + {} + + uint16_t tag_; + uint8_t algorithm_; + uint8_t digest_type_; + const vector digest_; +}; + +templateclass DS_LIKE : public Rdata { +public: + DS_LIKE(const string& ds_str) : + impl_(NULL) + { + istringstream iss(ds_str); + unsigned int tag, algorithm, digest_type; + stringbuf digestbuf; + + iss >> tag >> algorithm >> digest_type >> &digestbuf; + if (iss.bad() || iss.fail()) { + isc_throw(InvalidRdataText, "Invalid DS text"); + } + if (tag > 0xffff) { + isc_throw(InvalidRdataText, "DS tag out of range"); + } + if (algorithm > 0xff) { + isc_throw(InvalidRdataText, "DS algorithm out of range"); + } + if (digest_type > 0xff) { + isc_throw(InvalidRdataText, "DS digest type out of range"); + } + + vector digest; + decodeHex(digestbuf.str(), digest); + + impl_ = new DSImpl(tag, algorithm, digest_type, digest); + } + + DS_LIKE(InputBuffer& buffer, size_t rdata_len) { + if (rdata_len < 4) { + isc_throw(InvalidRdataLength, "DS too short"); + } + + uint16_t tag = buffer.readUint16(); + uint16_t algorithm = buffer.readUint8(); + uint16_t digest_type = buffer.readUint8(); + + rdata_len -= 4; + vector digest(rdata_len); + buffer.readData(&digest[0], rdata_len); + + impl_ = new DSImpl(tag, algorithm, digest_type, digest); + } + + DS_LIKE(const DS_LIKE& source) : + Rdata(), impl_(new DSImpl(*source.impl_)) + {} + + DS_LIKE& + operator=(const DS_LIKE& source) { + if (impl_ == source.impl_) { + return (*this); + } + + DSImpl* newimpl = new DSImpl(*source.impl_); + delete impl_; + impl_ = newimpl; + + return (*this); + } + + ~DS_LIKE() { + delete impl_; + } + + string + toText() const { + using namespace boost; + return (lexical_cast(static_cast(impl_->tag_)) + + " " + lexical_cast(static_cast(impl_->algorithm_)) + + " " + lexical_cast(static_cast(impl_->digest_type_)) + + " " + encodeHex(impl_->digest_)); + } + + void + toWire(OutputBuffer& buffer) const { + buffer.writeUint16(impl_->tag_); + buffer.writeUint8(impl_->algorithm_); + buffer.writeUint8(impl_->digest_type_); + buffer.writeData(&impl_->digest_[0], impl_->digest_.size()); + } + + void + toWire(AbstractMessageRenderer& renderer) const { + renderer.writeUint16(impl_->tag_); + renderer.writeUint8(impl_->algorithm_); + renderer.writeUint8(impl_->digest_type_); + renderer.writeData(&impl_->digest_[0], impl_->digest_.size()); + } + + int + compare(const Rdata& other) const { + const RTYPE& other_ds = dynamic_cast(other); + + if (impl_->tag_ != other_ds.impl_->tag_) { + return (impl_->tag_ < other_ds.impl_->tag_ ? -1 : 1); + } + if (impl_->algorithm_ != other_ds.impl_->algorithm_) { + return (impl_->algorithm_ < other_ds.impl_->algorithm_ ? -1 : 1); + } + if (impl_->digest_type_ != other_ds.impl_->digest_type_) { + return (impl_->digest_type_ < other_ds.impl_->digest_type_ ? -1 : 1); + } + + size_t this_len = impl_->digest_.size(); + size_t other_len = other_ds.impl_->digest_.size(); + size_t cmplen = min(this_len, other_len); + int cmp = memcmp(&impl_->digest_[0], &other_ds.impl_->digest_[0], cmplen); + if (cmp != 0) { + return (cmp); + } else { + return ((this_len == other_len) ? 0 : (this_len < other_len) ? -1 : 1); + } + } + + uint16_t + getTag() const { + return (impl_->tag_); + } + +private: + DSImpl* impl_; +}; + +#endif // __DS_LIKE_H + +// Local Variables: +// mode: c++ +// End: diff --git a/src/lib/dns/rdata/generic/dlv_32769.cc b/src/lib/dns/rdata/generic/dlv_32769.cc new file mode 100644 index 0000000000..cf72d76882 --- /dev/null +++ b/src/lib/dns/rdata/generic/dlv_32769.cc @@ -0,0 +1,19 @@ +// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +// BEGIN_ISC_NAMESPACE +// BEGIN_RDATA_NAMESPACE + +// END_RDATA_NAMESPACE +// END_ISC_NAMESPACE diff --git a/src/lib/dns/rdata/generic/dlv_32769.h b/src/lib/dns/rdata/generic/dlv_32769.h new file mode 100644 index 0000000000..1a8e7a3766 --- /dev/null +++ b/src/lib/dns/rdata/generic/dlv_32769.h @@ -0,0 +1,97 @@ +// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +// BEGIN_HEADER_GUARD + +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include + +using namespace std; +using namespace isc::util; +using namespace isc::util::encode; + +// BEGIN_ISC_NAMESPACE + +// BEGIN_COMMON_DECLARATIONS +// END_COMMON_DECLARATIONS + +// BEGIN_RDATA_NAMESPACE + +#include + +class DLV : public DS_LIKE { + friend class DS_LIKE; + static string const id; + +public: + // BEGIN_COMMON_MEMBERS + // END_COMMON_MEMBERS + +}; + +/// explicit DLV(const std::string& type_str); +inline DLV::DLV(const std::string& type_str) : DS_LIKE(type_str) {} + +/// DLV(isc::util::InputBuffer& buffer, size_t rdata_len); +inline DLV::DLV(isc::util::InputBuffer& buffer, size_t rdata_len) : DS_LIKE(buffer, rdata_len) {} + +/// DLV(const DLV& other); +inline DLV::DLV(const DLV& other) : DS_LIKE(other) {} + +/// virtual std::string toText() const; +inline std::string DLV::toText() const +{ + return DS_LIKE::toText(); +} + +/// virtual void toWire(isc::util::OutputBuffer& buffer) const; +inline void DLV::toWire(isc::util::OutputBuffer& buffer) const +{ + DS_LIKE::toWire(buffer); +} + +/// virtual void toWire(AbstractMessageRenderer& renderer) const; +inline void DLV::toWire(AbstractMessageRenderer& renderer) const +{ + DS_LIKE::toWire(renderer); +} + +/// virtual int compare(const Rdata& other) const; +inline int DLV::compare(const Rdata& other) const +{ + return DS_LIKE::compare(other); +} + +// END_RDATA_NAMESPACE +// END_ISC_NAMESPACE +// END_HEADER_GUARD + +// Local Variables: +// mode: c++ +// End: diff --git a/src/lib/dns/rdata/generic/ds_43.cc b/src/lib/dns/rdata/generic/ds_43.cc index 1b48456d8b..cf72d76882 100644 --- a/src/lib/dns/rdata/generic/ds_43.cc +++ b/src/lib/dns/rdata/generic/ds_43.cc @@ -12,163 +12,8 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include -#include -#include - -#include -#include - -using namespace std; -using namespace isc::util; -using namespace isc::util::encode; - // BEGIN_ISC_NAMESPACE // BEGIN_RDATA_NAMESPACE -struct DSImpl { - // straightforward representation of DS RDATA fields - DSImpl(uint16_t tag, uint8_t algorithm, uint8_t digest_type, - const vector& digest) : - tag_(tag), algorithm_(algorithm), digest_type_(digest_type), - digest_(digest) - {} - - uint16_t tag_; - uint8_t algorithm_; - uint8_t digest_type_; - const vector digest_; -}; - -DS::DS(const string& ds_str) : - impl_(NULL) -{ - istringstream iss(ds_str); - unsigned int tag, algorithm, digest_type; - stringbuf digestbuf; - - iss >> tag >> algorithm >> digest_type >> &digestbuf; - if (iss.bad() || iss.fail()) { - isc_throw(InvalidRdataText, "Invalid DS text"); - } - if (tag > 0xffff) { - isc_throw(InvalidRdataText, "DS tag out of range"); - } - if (algorithm > 0xff) { - isc_throw(InvalidRdataText, "DS algorithm out of range"); - } - if (digest_type > 0xff) { - isc_throw(InvalidRdataText, "DS digest type out of range"); - } - - vector digest; - decodeHex(digestbuf.str(), digest); - - impl_ = new DSImpl(tag, algorithm, digest_type, digest); -} - -DS::DS(InputBuffer& buffer, size_t rdata_len) { - if (rdata_len < 4) { - isc_throw(InvalidRdataLength, "DS too short"); - } - - uint16_t tag = buffer.readUint16(); - uint16_t algorithm = buffer.readUint8(); - uint16_t digest_type = buffer.readUint8(); - - rdata_len -= 4; - vector digest(rdata_len); - buffer.readData(&digest[0], rdata_len); - - impl_ = new DSImpl(tag, algorithm, digest_type, digest); -} - -DS::DS(const DS& source) : - Rdata(), impl_(new DSImpl(*source.impl_)) -{} - -DS& -DS::operator=(const DS& source) { - if (impl_ == source.impl_) { - return (*this); - } - - DSImpl* newimpl = new DSImpl(*source.impl_); - delete impl_; - impl_ = newimpl; - - return (*this); -} - -DS::~DS() { - delete impl_; -} - -string -DS::toText() const { - using namespace boost; - return (lexical_cast(static_cast(impl_->tag_)) + - " " + lexical_cast(static_cast(impl_->algorithm_)) + - " " + lexical_cast(static_cast(impl_->digest_type_)) + - " " + encodeHex(impl_->digest_)); -} - -void -DS::toWire(OutputBuffer& buffer) const { - buffer.writeUint16(impl_->tag_); - buffer.writeUint8(impl_->algorithm_); - buffer.writeUint8(impl_->digest_type_); - buffer.writeData(&impl_->digest_[0], impl_->digest_.size()); -} - -void -DS::toWire(AbstractMessageRenderer& renderer) const { - renderer.writeUint16(impl_->tag_); - renderer.writeUint8(impl_->algorithm_); - renderer.writeUint8(impl_->digest_type_); - renderer.writeData(&impl_->digest_[0], impl_->digest_.size()); -} - -int -DS::compare(const Rdata& other) const { - const DS& other_ds = dynamic_cast(other); - - if (impl_->tag_ != other_ds.impl_->tag_) { - return (impl_->tag_ < other_ds.impl_->tag_ ? -1 : 1); - } - if (impl_->algorithm_ != other_ds.impl_->algorithm_) { - return (impl_->algorithm_ < other_ds.impl_->algorithm_ ? -1 : 1); - } - if (impl_->digest_type_ != other_ds.impl_->digest_type_) { - return (impl_->digest_type_ < other_ds.impl_->digest_type_ ? -1 : 1); - } - - size_t this_len = impl_->digest_.size(); - size_t other_len = other_ds.impl_->digest_.size(); - size_t cmplen = min(this_len, other_len); - int cmp = memcmp(&impl_->digest_[0], &other_ds.impl_->digest_[0], cmplen); - if (cmp != 0) { - return (cmp); - } else { - return ((this_len == other_len) ? 0 : (this_len < other_len) ? -1 : 1); - } -} - -uint16_t -DS::getTag() const { - return (impl_->tag_); -} - // END_RDATA_NAMESPACE // END_ISC_NAMESPACE diff --git a/src/lib/dns/rdata/generic/ds_43.h b/src/lib/dns/rdata/generic/ds_43.h index 03b19a0903..0bb813587e 100644 --- a/src/lib/dns/rdata/generic/ds_43.h +++ b/src/lib/dns/rdata/generic/ds_43.h @@ -12,17 +12,30 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -#include - -#include - -#include -#include -#include -#include - // BEGIN_HEADER_GUARD +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include + +using namespace std; +using namespace isc::util; +using namespace isc::util::encode; + // BEGIN_ISC_NAMESPACE // BEGIN_COMMON_DECLARATIONS @@ -30,23 +43,51 @@ // BEGIN_RDATA_NAMESPACE -struct DSImpl; +#include + +class DS : public DS_LIKE { + friend class DS_LIKE; + static string const id; -class DS : public Rdata { public: // BEGIN_COMMON_MEMBERS // END_COMMON_MEMBERS - DS& operator=(const DS& source); - ~DS(); - /// - /// Specialized methods - /// - uint16_t getTag() const; -private: - DSImpl* impl_; }; +/// explicit DS(const std::string& type_str); +inline DS::DS(const std::string& type_str) : DS_LIKE(type_str) {} + +/// DS(isc::util::InputBuffer& buffer, size_t rdata_len); +inline DS::DS(isc::util::InputBuffer& buffer, size_t rdata_len) : DS_LIKE(buffer, rdata_len) {} + +/// DS(const DS& other); +inline DS::DS(const DS& other) : DS_LIKE(other) {} + +/// virtual std::string toText() const; +inline std::string DS::toText() const +{ + return DS_LIKE::toText(); +} + +/// virtual void toWire(isc::util::OutputBuffer& buffer) const; +inline void DS::toWire(isc::util::OutputBuffer& buffer) const +{ + DS_LIKE::toWire(buffer); +} + +/// virtual void toWire(AbstractMessageRenderer& renderer) const; +inline void DS::toWire(AbstractMessageRenderer& renderer) const +{ + DS_LIKE::toWire(renderer); +} + +/// virtual int compare(const Rdata& other) const; +inline int DS::compare(const Rdata& other) const +{ + return DS_LIKE::compare(other); +} + // END_RDATA_NAMESPACE // END_ISC_NAMESPACE // END_HEADER_GUARD From 8975d286a6de827a02b073de32570602cd9cffbc Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Tue, 9 Aug 2011 05:23:41 -0400 Subject: [PATCH 02/20] [1144] fixes to Makefile.am --- src/lib/dns/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/dns/Makefile.am b/src/lib/dns/Makefile.am index 887ac09fee..09c6e1961c 100644 --- a/src/lib/dns/Makefile.am +++ b/src/lib/dns/Makefile.am @@ -23,6 +23,7 @@ EXTRA_DIST += rdata/generic/cname_5.cc EXTRA_DIST += rdata/generic/cname_5.h EXTRA_DIST += rdata/generic/detail/nsec_bitmap.cc EXTRA_DIST += rdata/generic/detail/nsec_bitmap.h +EXTRA_DIST += rdata/generic/detail/ds_like.h EXTRA_DIST += rdata/generic/dname_39.cc EXTRA_DIST += rdata/generic/dname_39.h EXTRA_DIST += rdata/generic/dnskey_48.cc @@ -90,6 +91,7 @@ libdns___la_SOURCES += tsigkey.h tsigkey.cc libdns___la_SOURCES += tsigrecord.h tsigrecord.cc libdns___la_SOURCES += rdata/generic/detail/nsec_bitmap.h libdns___la_SOURCES += rdata/generic/detail/nsec_bitmap.cc +libdns___la_SOURCES += rdata/generic/detail/ds_like.h libdns___la_CPPFLAGS = $(AM_CPPFLAGS) # Most applications of libdns++ will only implicitly rely on libcryptolink, From eb5023d2a38e0862e2d9a5f1ca4a3788fc131405 Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Tue, 9 Aug 2011 15:54:42 -0400 Subject: [PATCH 03/20] [1144] fixes to address jinmei's review notes --- src/lib/dns/rdata/generic/detail/ds_like.h | 23 +++++++++----- src/lib/dns/rdata/generic/dlv_32769.cc | 32 +++++++++++++++++++ src/lib/dns/rdata/generic/dlv_32769.h | 37 +--------------------- src/lib/dns/rdata/generic/ds_43.cc | 32 +++++++++++++++++++ src/lib/dns/rdata/generic/ds_43.h | 37 +--------------------- 5 files changed, 81 insertions(+), 80 deletions(-) diff --git a/src/lib/dns/rdata/generic/detail/ds_like.h b/src/lib/dns/rdata/generic/detail/ds_like.h index 20cf09469d..8d4c5b2492 100644 --- a/src/lib/dns/rdata/generic/detail/ds_like.h +++ b/src/lib/dns/rdata/generic/detail/ds_like.h @@ -20,9 +20,6 @@ #include #include -using namespace std; -using namespace isc::util; - struct DSImpl { // straightforward representation of DS RDATA fields DSImpl(uint16_t tag, uint8_t algorithm, uint8_t digest_type, @@ -48,16 +45,24 @@ public: iss >> tag >> algorithm >> digest_type >> &digestbuf; if (iss.bad() || iss.fail()) { - isc_throw(InvalidRdataText, "Invalid DS text"); + isc_throw(InvalidRdataText, "Invalid " + + RRParamRegistry::getRegistry().codeToTypeText(typeCode) + + " text"); } if (tag > 0xffff) { - isc_throw(InvalidRdataText, "DS tag out of range"); + isc_throw(InvalidRdataText, + RRParamRegistry::getRegistry().codeToTypeText(typeCode) + + " tag out of range"); } if (algorithm > 0xff) { - isc_throw(InvalidRdataText, "DS algorithm out of range"); + isc_throw(InvalidRdataText, + RRParamRegistry::getRegistry().codeToTypeText(typeCode) + + " algorithm out of range"); } if (digest_type > 0xff) { - isc_throw(InvalidRdataText, "DS digest type out of range"); + isc_throw(InvalidRdataText, + RRParamRegistry::getRegistry().codeToTypeText(typeCode) + + " digest type out of range"); } vector digest; @@ -68,7 +73,9 @@ public: DS_LIKE(InputBuffer& buffer, size_t rdata_len) { if (rdata_len < 4) { - isc_throw(InvalidRdataLength, "DS too short"); + isc_throw(InvalidRdataLength, + RRParamRegistry::getRegistry().codeToTypeText(typeCode) + + " too short"); } uint16_t tag = buffer.readUint16(); diff --git a/src/lib/dns/rdata/generic/dlv_32769.cc b/src/lib/dns/rdata/generic/dlv_32769.cc index cf72d76882..d00282f739 100644 --- a/src/lib/dns/rdata/generic/dlv_32769.cc +++ b/src/lib/dns/rdata/generic/dlv_32769.cc @@ -15,5 +15,37 @@ // BEGIN_ISC_NAMESPACE // BEGIN_RDATA_NAMESPACE +DLV::DLV(const std::string& type_str) : + DS_LIKE(type_str) +{} + +DLV::DLV(isc::util::InputBuffer& buffer, size_t rdata_len) : + DS_LIKE(buffer, rdata_len) +{} + +DLV::DLV(const DLV& other) : + DS_LIKE(other) +{} + +std::string DLV::toText() const +{ + return DS_LIKE::toText(); +} + +void DLV::toWire(isc::util::OutputBuffer& buffer) const +{ + DS_LIKE::toWire(buffer); +} + +void DLV::toWire(AbstractMessageRenderer& renderer) const +{ + DS_LIKE::toWire(renderer); +} + +int DLV::compare(const Rdata& other) const +{ + return DS_LIKE::compare(other); +} + // END_RDATA_NAMESPACE // END_ISC_NAMESPACE diff --git a/src/lib/dns/rdata/generic/dlv_32769.h b/src/lib/dns/rdata/generic/dlv_32769.h index 1a8e7a3766..cf86234347 100644 --- a/src/lib/dns/rdata/generic/dlv_32769.h +++ b/src/lib/dns/rdata/generic/dlv_32769.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -46,48 +47,12 @@ using namespace isc::util::encode; #include class DLV : public DS_LIKE { - friend class DS_LIKE; - static string const id; - public: // BEGIN_COMMON_MEMBERS // END_COMMON_MEMBERS }; -/// explicit DLV(const std::string& type_str); -inline DLV::DLV(const std::string& type_str) : DS_LIKE(type_str) {} - -/// DLV(isc::util::InputBuffer& buffer, size_t rdata_len); -inline DLV::DLV(isc::util::InputBuffer& buffer, size_t rdata_len) : DS_LIKE(buffer, rdata_len) {} - -/// DLV(const DLV& other); -inline DLV::DLV(const DLV& other) : DS_LIKE(other) {} - -/// virtual std::string toText() const; -inline std::string DLV::toText() const -{ - return DS_LIKE::toText(); -} - -/// virtual void toWire(isc::util::OutputBuffer& buffer) const; -inline void DLV::toWire(isc::util::OutputBuffer& buffer) const -{ - DS_LIKE::toWire(buffer); -} - -/// virtual void toWire(AbstractMessageRenderer& renderer) const; -inline void DLV::toWire(AbstractMessageRenderer& renderer) const -{ - DS_LIKE::toWire(renderer); -} - -/// virtual int compare(const Rdata& other) const; -inline int DLV::compare(const Rdata& other) const -{ - return DS_LIKE::compare(other); -} - // END_RDATA_NAMESPACE // END_ISC_NAMESPACE // END_HEADER_GUARD diff --git a/src/lib/dns/rdata/generic/ds_43.cc b/src/lib/dns/rdata/generic/ds_43.cc index cf72d76882..fe73e52630 100644 --- a/src/lib/dns/rdata/generic/ds_43.cc +++ b/src/lib/dns/rdata/generic/ds_43.cc @@ -15,5 +15,37 @@ // BEGIN_ISC_NAMESPACE // BEGIN_RDATA_NAMESPACE +DS::DS(const std::string& type_str) : + DS_LIKE(type_str) +{} + +DS::DS(isc::util::InputBuffer& buffer, size_t rdata_len) : + DS_LIKE(buffer, rdata_len) +{} + +DS::DS(const DS& other) : + DS_LIKE(other) +{} + +std::string DS::toText() const +{ + return DS_LIKE::toText(); +} + +void DS::toWire(isc::util::OutputBuffer& buffer) const +{ + DS_LIKE::toWire(buffer); +} + +void DS::toWire(AbstractMessageRenderer& renderer) const +{ + DS_LIKE::toWire(renderer); +} + +int DS::compare(const Rdata& other) const +{ + return DS_LIKE::compare(other); +} + // END_RDATA_NAMESPACE // END_ISC_NAMESPACE diff --git a/src/lib/dns/rdata/generic/ds_43.h b/src/lib/dns/rdata/generic/ds_43.h index 0bb813587e..24715d997f 100644 --- a/src/lib/dns/rdata/generic/ds_43.h +++ b/src/lib/dns/rdata/generic/ds_43.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -46,48 +47,12 @@ using namespace isc::util::encode; #include class DS : public DS_LIKE { - friend class DS_LIKE; - static string const id; - public: // BEGIN_COMMON_MEMBERS // END_COMMON_MEMBERS }; -/// explicit DS(const std::string& type_str); -inline DS::DS(const std::string& type_str) : DS_LIKE(type_str) {} - -/// DS(isc::util::InputBuffer& buffer, size_t rdata_len); -inline DS::DS(isc::util::InputBuffer& buffer, size_t rdata_len) : DS_LIKE(buffer, rdata_len) {} - -/// DS(const DS& other); -inline DS::DS(const DS& other) : DS_LIKE(other) {} - -/// virtual std::string toText() const; -inline std::string DS::toText() const -{ - return DS_LIKE::toText(); -} - -/// virtual void toWire(isc::util::OutputBuffer& buffer) const; -inline void DS::toWire(isc::util::OutputBuffer& buffer) const -{ - DS_LIKE::toWire(buffer); -} - -/// virtual void toWire(AbstractMessageRenderer& renderer) const; -inline void DS::toWire(AbstractMessageRenderer& renderer) const -{ - DS_LIKE::toWire(renderer); -} - -/// virtual int compare(const Rdata& other) const; -inline int DS::compare(const Rdata& other) const -{ - return DS_LIKE::compare(other); -} - // END_RDATA_NAMESPACE // END_ISC_NAMESPACE // END_HEADER_GUARD From a03d7d9aae8ac258d266c66c62c63e03ff5d2558 Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Tue, 9 Aug 2011 21:26:24 -0400 Subject: [PATCH 04/20] [1144] DS and DLV cleaned up --- src/lib/dns/Makefile.am | 2 +- src/lib/dns/rdata/generic/detail/ds_like.h | 4 +- src/lib/dns/rdata/generic/dlv_32769.cc | 51 ---------------------- src/lib/dns/rdata/generic/dlv_32769.h | 7 +-- src/lib/dns/rdata/generic/ds_43.cc | 51 ---------------------- src/lib/dns/rdata/generic/ds_43.h | 7 +-- 6 files changed, 5 insertions(+), 117 deletions(-) delete mode 100644 src/lib/dns/rdata/generic/dlv_32769.cc delete mode 100644 src/lib/dns/rdata/generic/ds_43.cc diff --git a/src/lib/dns/Makefile.am b/src/lib/dns/Makefile.am index 88242bc707..a8bcb72f48 100644 --- a/src/lib/dns/Makefile.am +++ b/src/lib/dns/Makefile.am @@ -24,11 +24,11 @@ EXTRA_DIST += rdata/generic/cname_5.h EXTRA_DIST += rdata/generic/detail/nsec_bitmap.cc EXTRA_DIST += rdata/generic/detail/nsec_bitmap.h EXTRA_DIST += rdata/generic/detail/ds_like.h +EXTRA_DIST += rdata/generic/dlv_32769.h EXTRA_DIST += rdata/generic/dname_39.cc EXTRA_DIST += rdata/generic/dname_39.h EXTRA_DIST += rdata/generic/dnskey_48.cc EXTRA_DIST += rdata/generic/dnskey_48.h -EXTRA_DIST += rdata/generic/ds_43.cc EXTRA_DIST += rdata/generic/ds_43.h EXTRA_DIST += rdata/generic/mx_15.cc EXTRA_DIST += rdata/generic/mx_15.h diff --git a/src/lib/dns/rdata/generic/detail/ds_like.h b/src/lib/dns/rdata/generic/detail/ds_like.h index 8d4c5b2492..3ed190f3d2 100644 --- a/src/lib/dns/rdata/generic/detail/ds_like.h +++ b/src/lib/dns/rdata/generic/detail/ds_like.h @@ -34,7 +34,7 @@ struct DSImpl { const vector digest_; }; -templateclass DS_LIKE : public Rdata { +templateclass DS_LIKE : public Rdata { public: DS_LIKE(const string& ds_str) : impl_(NULL) @@ -137,7 +137,7 @@ public: int compare(const Rdata& other) const { - const RTYPE& other_ds = dynamic_cast(other); + const DS_LIKE& other_ds = dynamic_cast(other); if (impl_->tag_ != other_ds.impl_->tag_) { return (impl_->tag_ < other_ds.impl_->tag_ ? -1 : 1); diff --git a/src/lib/dns/rdata/generic/dlv_32769.cc b/src/lib/dns/rdata/generic/dlv_32769.cc deleted file mode 100644 index d00282f739..0000000000 --- a/src/lib/dns/rdata/generic/dlv_32769.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -// BEGIN_ISC_NAMESPACE -// BEGIN_RDATA_NAMESPACE - -DLV::DLV(const std::string& type_str) : - DS_LIKE(type_str) -{} - -DLV::DLV(isc::util::InputBuffer& buffer, size_t rdata_len) : - DS_LIKE(buffer, rdata_len) -{} - -DLV::DLV(const DLV& other) : - DS_LIKE(other) -{} - -std::string DLV::toText() const -{ - return DS_LIKE::toText(); -} - -void DLV::toWire(isc::util::OutputBuffer& buffer) const -{ - DS_LIKE::toWire(buffer); -} - -void DLV::toWire(AbstractMessageRenderer& renderer) const -{ - DS_LIKE::toWire(renderer); -} - -int DLV::compare(const Rdata& other) const -{ - return DS_LIKE::compare(other); -} - -// END_RDATA_NAMESPACE -// END_ISC_NAMESPACE diff --git a/src/lib/dns/rdata/generic/dlv_32769.h b/src/lib/dns/rdata/generic/dlv_32769.h index cf86234347..f1d27618de 100644 --- a/src/lib/dns/rdata/generic/dlv_32769.h +++ b/src/lib/dns/rdata/generic/dlv_32769.h @@ -46,12 +46,7 @@ using namespace isc::util::encode; #include -class DLV : public DS_LIKE { -public: - // BEGIN_COMMON_MEMBERS - // END_COMMON_MEMBERS - -}; +typedef DS_LIKE<32769> DLV; // END_RDATA_NAMESPACE // END_ISC_NAMESPACE diff --git a/src/lib/dns/rdata/generic/ds_43.cc b/src/lib/dns/rdata/generic/ds_43.cc deleted file mode 100644 index fe73e52630..0000000000 --- a/src/lib/dns/rdata/generic/ds_43.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -// BEGIN_ISC_NAMESPACE -// BEGIN_RDATA_NAMESPACE - -DS::DS(const std::string& type_str) : - DS_LIKE(type_str) -{} - -DS::DS(isc::util::InputBuffer& buffer, size_t rdata_len) : - DS_LIKE(buffer, rdata_len) -{} - -DS::DS(const DS& other) : - DS_LIKE(other) -{} - -std::string DS::toText() const -{ - return DS_LIKE::toText(); -} - -void DS::toWire(isc::util::OutputBuffer& buffer) const -{ - DS_LIKE::toWire(buffer); -} - -void DS::toWire(AbstractMessageRenderer& renderer) const -{ - DS_LIKE::toWire(renderer); -} - -int DS::compare(const Rdata& other) const -{ - return DS_LIKE::compare(other); -} - -// END_RDATA_NAMESPACE -// END_ISC_NAMESPACE diff --git a/src/lib/dns/rdata/generic/ds_43.h b/src/lib/dns/rdata/generic/ds_43.h index 24715d997f..eae22cbd41 100644 --- a/src/lib/dns/rdata/generic/ds_43.h +++ b/src/lib/dns/rdata/generic/ds_43.h @@ -46,12 +46,7 @@ using namespace isc::util::encode; #include -class DS : public DS_LIKE { -public: - // BEGIN_COMMON_MEMBERS - // END_COMMON_MEMBERS - -}; +typedef DS_LIKE<43> DS; // END_RDATA_NAMESPACE // END_ISC_NAMESPACE From 04749187843604f51ddcab4f53811dac9a9ed8a0 Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Thu, 11 Aug 2011 16:35:03 -0400 Subject: [PATCH 05/20] [1144] DS and DLV common implementation hidden behind private pointers so that the implementation weren't seen in rdataclass.h --- src/lib/dns/Makefile.am | 2 + src/lib/dns/rdata/generic/detail/ds_like.h | 138 ++++++++------------- src/lib/dns/rdata/generic/dlv_32769.h | 40 +++--- src/lib/dns/rdata/generic/ds_43.h | 40 +++--- 4 files changed, 94 insertions(+), 126 deletions(-) diff --git a/src/lib/dns/Makefile.am b/src/lib/dns/Makefile.am index a8bcb72f48..45525c353b 100644 --- a/src/lib/dns/Makefile.am +++ b/src/lib/dns/Makefile.am @@ -24,11 +24,13 @@ EXTRA_DIST += rdata/generic/cname_5.h EXTRA_DIST += rdata/generic/detail/nsec_bitmap.cc EXTRA_DIST += rdata/generic/detail/nsec_bitmap.h EXTRA_DIST += rdata/generic/detail/ds_like.h +EXTRA_DIST += rdata/generic/dlv_32769.cc EXTRA_DIST += rdata/generic/dlv_32769.h EXTRA_DIST += rdata/generic/dname_39.cc EXTRA_DIST += rdata/generic/dname_39.h EXTRA_DIST += rdata/generic/dnskey_48.cc EXTRA_DIST += rdata/generic/dnskey_48.h +EXTRA_DIST += rdata/generic/ds_43.cc EXTRA_DIST += rdata/generic/ds_43.h EXTRA_DIST += rdata/generic/mx_15.cc EXTRA_DIST += rdata/generic/mx_15.h diff --git a/src/lib/dns/rdata/generic/detail/ds_like.h b/src/lib/dns/rdata/generic/detail/ds_like.h index 3ed190f3d2..5249abf1c8 100644 --- a/src/lib/dns/rdata/generic/detail/ds_like.h +++ b/src/lib/dns/rdata/generic/detail/ds_like.h @@ -20,62 +20,37 @@ #include #include -struct DSImpl { - // straightforward representation of DS RDATA fields - DSImpl(uint16_t tag, uint8_t algorithm, uint8_t digest_type, - const vector& digest) : - tag_(tag), algorithm_(algorithm), digest_type_(digest_type), - digest_(digest) - {} - - uint16_t tag_; - uint8_t algorithm_; - uint8_t digest_type_; - const vector digest_; -}; - -templateclass DS_LIKE : public Rdata { +templateclass DSLikeImpl { public: - DS_LIKE(const string& ds_str) : - impl_(NULL) + DSLikeImpl(const string& ds_str) { istringstream iss(ds_str); - unsigned int tag, algorithm, digest_type; stringbuf digestbuf; + uint32_t tag, algorithm, digest_type; iss >> tag >> algorithm >> digest_type >> &digestbuf; if (iss.bad() || iss.fail()) { - isc_throw(InvalidRdataText, "Invalid " + - RRParamRegistry::getRegistry().codeToTypeText(typeCode) + - " text"); + isc_throw(InvalidRdataText, "Invalid " << RRType(typeCode) << " text"); } if (tag > 0xffff) { - isc_throw(InvalidRdataText, - RRParamRegistry::getRegistry().codeToTypeText(typeCode) + - " tag out of range"); + isc_throw(InvalidRdataText, RRType(typeCode) << " tag out of range"); } if (algorithm > 0xff) { - isc_throw(InvalidRdataText, - RRParamRegistry::getRegistry().codeToTypeText(typeCode) + - " algorithm out of range"); + isc_throw(InvalidRdataText, RRType(typeCode) << " algorithm out of range"); } if (digest_type > 0xff) { - isc_throw(InvalidRdataText, - RRParamRegistry::getRegistry().codeToTypeText(typeCode) + - " digest type out of range"); + isc_throw(InvalidRdataText, RRType(typeCode) << " digest type out of range"); } - vector digest; - decodeHex(digestbuf.str(), digest); - - impl_ = new DSImpl(tag, algorithm, digest_type, digest); + tag_ = tag; + algorithm_ = algorithm; + digest_type_ = digest_type; + decodeHex(digestbuf.str(), digest_); } - DS_LIKE(InputBuffer& buffer, size_t rdata_len) { + DSLikeImpl(InputBuffer& buffer, size_t rdata_len) { if (rdata_len < 4) { - isc_throw(InvalidRdataLength, - RRParamRegistry::getRegistry().codeToTypeText(typeCode) + - " too short"); + isc_throw(InvalidRdataLength, RRType(typeCode) << " too short"); } uint16_t tag = buffer.readUint16(); @@ -83,76 +58,63 @@ public: uint16_t digest_type = buffer.readUint8(); rdata_len -= 4; - vector digest(rdata_len); - buffer.readData(&digest[0], rdata_len); + digest_.resize(rdata_len); + buffer.readData(&digest_[0], rdata_len); - impl_ = new DSImpl(tag, algorithm, digest_type, digest); + tag_ = tag; + algorithm_ = algorithm; + digest_type_ = digest_type; } - DS_LIKE(const DS_LIKE& source) : - Rdata(), impl_(new DSImpl(*source.impl_)) - {} - - DS_LIKE& - operator=(const DS_LIKE& source) { - if (impl_ == source.impl_) { - return (*this); - } - - DSImpl* newimpl = new DSImpl(*source.impl_); - delete impl_; - impl_ = newimpl; - - return (*this); - } - - ~DS_LIKE() { - delete impl_; + DSLikeImpl(const DSLikeImpl& source) + { + digest_ = source.digest_; + tag_ = source.tag_; + algorithm_ = source.algorithm_; + digest_type_ = source.digest_type_; } string toText() const { using namespace boost; - return (lexical_cast(static_cast(impl_->tag_)) + - " " + lexical_cast(static_cast(impl_->algorithm_)) + - " " + lexical_cast(static_cast(impl_->digest_type_)) + - " " + encodeHex(impl_->digest_)); + return (lexical_cast(static_cast(tag_)) + + " " + lexical_cast(static_cast(algorithm_)) + + " " + lexical_cast(static_cast(digest_type_)) + + " " + encodeHex(digest_)); } void toWire(OutputBuffer& buffer) const { - buffer.writeUint16(impl_->tag_); - buffer.writeUint8(impl_->algorithm_); - buffer.writeUint8(impl_->digest_type_); - buffer.writeData(&impl_->digest_[0], impl_->digest_.size()); + buffer.writeUint16(tag_); + buffer.writeUint8(algorithm_); + buffer.writeUint8(digest_type_); + buffer.writeData(&digest_[0], digest_.size()); } void toWire(AbstractMessageRenderer& renderer) const { - renderer.writeUint16(impl_->tag_); - renderer.writeUint8(impl_->algorithm_); - renderer.writeUint8(impl_->digest_type_); - renderer.writeData(&impl_->digest_[0], impl_->digest_.size()); + renderer.writeUint16(tag_); + renderer.writeUint8(algorithm_); + renderer.writeUint8(digest_type_); + renderer.writeData(&digest_[0], digest_.size()); } int - compare(const Rdata& other) const { - const DS_LIKE& other_ds = dynamic_cast(other); - - if (impl_->tag_ != other_ds.impl_->tag_) { - return (impl_->tag_ < other_ds.impl_->tag_ ? -1 : 1); + compare(const DSLikeImpl& other_ds) const { + if (tag_ != other_ds.tag_) { + return (tag_ < other_ds.tag_ ? -1 : 1); } - if (impl_->algorithm_ != other_ds.impl_->algorithm_) { - return (impl_->algorithm_ < other_ds.impl_->algorithm_ ? -1 : 1); + if (algorithm_ != other_ds.algorithm_) { + return (algorithm_ < other_ds.algorithm_ ? -1 : 1); } - if (impl_->digest_type_ != other_ds.impl_->digest_type_) { - return (impl_->digest_type_ < other_ds.impl_->digest_type_ ? -1 : 1); + if (digest_type_ != other_ds.digest_type_) { + return (digest_type_ < other_ds.digest_type_ ? -1 : 1); } - size_t this_len = impl_->digest_.size(); - size_t other_len = other_ds.impl_->digest_.size(); + size_t this_len = digest_.size(); + size_t other_len = other_ds.digest_.size(); size_t cmplen = min(this_len, other_len); - int cmp = memcmp(&impl_->digest_[0], &other_ds.impl_->digest_[0], cmplen); + int cmp = memcmp(&digest_[0], &other_ds.digest_[0], cmplen); if (cmp != 0) { return (cmp); } else { @@ -162,11 +124,15 @@ public: uint16_t getTag() const { - return (impl_->tag_); + return (tag_); } private: - DSImpl* impl_; + // straightforward representation of DS RDATA fields + uint16_t tag_; + uint8_t algorithm_; + uint8_t digest_type_; + vector digest_; }; #endif // __DS_LIKE_H diff --git a/src/lib/dns/rdata/generic/dlv_32769.h b/src/lib/dns/rdata/generic/dlv_32769.h index f1d27618de..84b1d1c4ee 100644 --- a/src/lib/dns/rdata/generic/dlv_32769.h +++ b/src/lib/dns/rdata/generic/dlv_32769.h @@ -14,28 +14,14 @@ // BEGIN_HEADER_GUARD -#include +#include + #include -#include -#include -#include - -#include -#include - -#include #include +#include +#include #include -#include -#include - -#include -#include - -using namespace std; -using namespace isc::util; -using namespace isc::util::encode; // BEGIN_ISC_NAMESPACE @@ -44,9 +30,23 @@ using namespace isc::util::encode; // BEGIN_RDATA_NAMESPACE -#include +template class DSLikeImpl; -typedef DS_LIKE<32769> DLV; +class DLV : public Rdata { +public: + // BEGIN_COMMON_MEMBERS + // END_COMMON_MEMBERS + DLV& operator=(const DLV& source); + ~DLV(); + + /// + /// Specialized methods + /// + uint16_t getTag() const; +private: + typedef DSLikeImpl DLVImpl; + DLVImpl* impl_; +}; // END_RDATA_NAMESPACE // END_ISC_NAMESPACE diff --git a/src/lib/dns/rdata/generic/ds_43.h b/src/lib/dns/rdata/generic/ds_43.h index eae22cbd41..ef441b6ef6 100644 --- a/src/lib/dns/rdata/generic/ds_43.h +++ b/src/lib/dns/rdata/generic/ds_43.h @@ -14,28 +14,14 @@ // BEGIN_HEADER_GUARD -#include +#include + #include -#include -#include -#include - -#include -#include - -#include #include +#include +#include #include -#include -#include - -#include -#include - -using namespace std; -using namespace isc::util; -using namespace isc::util::encode; // BEGIN_ISC_NAMESPACE @@ -44,9 +30,23 @@ using namespace isc::util::encode; // BEGIN_RDATA_NAMESPACE -#include +template class DSLikeImpl; -typedef DS_LIKE<43> DS; +class DS : public Rdata { +public: + // BEGIN_COMMON_MEMBERS + // END_COMMON_MEMBERS + DS& operator=(const DS& source); + ~DS(); + + /// + /// Specialized methods + /// + uint16_t getTag() const; +private: + typedef DSLikeImpl DSImpl; + DSImpl* impl_; +}; // END_RDATA_NAMESPACE // END_ISC_NAMESPACE From a9ddfa91f81e00400f04548e71ab9519892a6dea Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Thu, 11 Aug 2011 16:46:50 -0400 Subject: [PATCH 06/20] [1144] cleanall.sh re-done w/o non-POSIX find options --- tests/system/cleanall.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/system/cleanall.sh b/tests/system/cleanall.sh index 17c3d4a6eb..d23d103882 100755 --- a/tests/system/cleanall.sh +++ b/tests/system/cleanall.sh @@ -27,7 +27,10 @@ find . -type f \( \ status=0 -for d in `find . -type d -maxdepth 1 -mindepth 1 -print` +for d in ./.* ./* do + case $d in ./.|./..) continue ;; esac + test -d $d || continue + test ! -f $d/clean.sh || ( cd $d && sh clean.sh ) done From 8c84a6865c4b09eccf41c9d2e91a030c941bffab Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Thu, 11 Aug 2011 17:49:12 -0400 Subject: [PATCH 07/20] [1144] DS and DLV common implementation hidden behind private pointers so that the implementation details weren't seen in rdataclass.h --- src/lib/dns/rdata/generic/ds_43.cc | 99 ++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/lib/dns/rdata/generic/ds_43.cc diff --git a/src/lib/dns/rdata/generic/ds_43.cc b/src/lib/dns/rdata/generic/ds_43.cc new file mode 100644 index 0000000000..0883616f69 --- /dev/null +++ b/src/lib/dns/rdata/generic/ds_43.cc @@ -0,0 +1,99 @@ +// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include + +using namespace std; +using namespace isc::util; +using namespace isc::util::encode; + +// BEGIN_ISC_NAMESPACE +// BEGIN_RDATA_NAMESPACE + +#include + +DS::DS(const string& ds_str) : + impl_(new DSImpl(ds_str)) +{} + +DS::DS(InputBuffer& buffer, size_t rdata_len) : + impl_(new DSImpl(buffer, rdata_len)) +{} + +DS::DS(const DS& source) : + Rdata(), impl_(new DSImpl(*source.impl_)) +{} + +DS& +DS::operator=(const DS& source) { + if (impl_ == source.impl_) { + return (*this); + } + + DSImpl* newimpl = new DSImpl(*source.impl_); + delete impl_; + impl_ = newimpl; + + return (*this); +} + +DS::~DS() { + delete impl_; +} + +string +DS::toText() const { + return (impl_->toText()); +} + +void +DS::toWire(OutputBuffer& buffer) const { + impl_->toWire(buffer); +} + +void +DS::toWire(AbstractMessageRenderer& renderer) const { + impl_->toWire(renderer); +} + +int +DS::compare(const Rdata& other) const { + const DS& other_ds = dynamic_cast(other); + + return (impl_->compare(*other_ds.impl_)); +} + +uint16_t +DS::getTag() const { + return (impl_->getTag()); +} + +// END_RDATA_NAMESPACE +// END_ISC_NAMESPACE From b51f0cfcedc2499aa1c0b85aaebf2fecf244c291 Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Fri, 12 Aug 2011 09:13:11 -0400 Subject: [PATCH 08/20] [1144] dlv_32769.cc added --- src/lib/dns/rdata/generic/dlv_32769.cc | 99 ++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/lib/dns/rdata/generic/dlv_32769.cc diff --git a/src/lib/dns/rdata/generic/dlv_32769.cc b/src/lib/dns/rdata/generic/dlv_32769.cc new file mode 100644 index 0000000000..70a52fc648 --- /dev/null +++ b/src/lib/dns/rdata/generic/dlv_32769.cc @@ -0,0 +1,99 @@ +// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include + +using namespace std; +using namespace isc::util; +using namespace isc::util::encode; + +// BEGIN_ISC_NAMESPACE +// BEGIN_RDATA_NAMESPACE + +#include + +DLV::DLV(const string& ds_str) : + impl_(new DLVImpl(ds_str)) +{} + +DLV::DLV(InputBuffer& buffer, size_t rdata_len) : + impl_(new DLVImpl(buffer, rdata_len)) +{} + +DLV::DLV(const DLV& source) : + Rdata(), impl_(new DLVImpl(*source.impl_)) +{} + +DLV& +DLV::operator=(const DLV& source) { + if (impl_ == source.impl_) { + return (*this); + } + + DLVImpl* newimpl = new DLVImpl(*source.impl_); + delete impl_; + impl_ = newimpl; + + return (*this); +} + +DLV::~DLV() { + delete impl_; +} + +string +DLV::toText() const { + return (impl_->toText()); +} + +void +DLV::toWire(OutputBuffer& buffer) const { + impl_->toWire(buffer); +} + +void +DLV::toWire(AbstractMessageRenderer& renderer) const { + impl_->toWire(renderer); +} + +int +DLV::compare(const Rdata& other) const { + const DLV& other_ds = dynamic_cast(other); + + return (impl_->compare(*other_ds.impl_)); +} + +uint16_t +DLV::getTag() const { + return (impl_->getTag()); +} + +// END_RDATA_NAMESPACE +// END_ISC_NAMESPACE From d63056e7cff35f58898a9bdc8d5cad589689590c Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Wed, 17 Aug 2011 09:55:35 -0400 Subject: [PATCH 09/20] [1144] style fixes in src/lib/dns/rdata/generic/detail/ds_like.h --- src/lib/dns/rdata/generic/detail/ds_like.h | 141 +++++++++++---------- 1 file changed, 73 insertions(+), 68 deletions(-) diff --git a/src/lib/dns/rdata/generic/detail/ds_like.h b/src/lib/dns/rdata/generic/detail/ds_like.h index 5249abf1c8..7e26d275b1 100644 --- a/src/lib/dns/rdata/generic/detail/ds_like.h +++ b/src/lib/dns/rdata/generic/detail/ds_like.h @@ -24,107 +24,112 @@ templateclass DSLikeImpl { public: DSLikeImpl(const string& ds_str) { - istringstream iss(ds_str); - stringbuf digestbuf; - uint32_t tag, algorithm, digest_type; + istringstream iss(ds_str); + stringbuf digestbuf; + uint32_t tag, algorithm, digest_type; - iss >> tag >> algorithm >> digest_type >> &digestbuf; - if (iss.bad() || iss.fail()) { - isc_throw(InvalidRdataText, "Invalid " << RRType(typeCode) << " text"); - } - if (tag > 0xffff) { - isc_throw(InvalidRdataText, RRType(typeCode) << " tag out of range"); - } - if (algorithm > 0xff) { - isc_throw(InvalidRdataText, RRType(typeCode) << " algorithm out of range"); - } - if (digest_type > 0xff) { - isc_throw(InvalidRdataText, RRType(typeCode) << " digest type out of range"); - } + iss >> tag >> algorithm >> digest_type >> &digestbuf; + if (iss.bad() || iss.fail()) { + isc_throw(InvalidRdataText, + "Invalid " << RRType(typeCode) << " text"); + } + if (tag > 0xffff) { + isc_throw(InvalidRdataText, + RRType(typeCode) << " tag out of range"); + } + if (algorithm > 0xff) { + isc_throw(InvalidRdataText, + RRType(typeCode) << " algorithm out of range"); + } + if (digest_type > 0xff) { + isc_throw(InvalidRdataText, + RRType(typeCode) << " digest type out of range"); + } - tag_ = tag; - algorithm_ = algorithm; - digest_type_ = digest_type; - decodeHex(digestbuf.str(), digest_); + tag_ = tag; + algorithm_ = algorithm; + digest_type_ = digest_type; + decodeHex(digestbuf.str(), digest_); } DSLikeImpl(InputBuffer& buffer, size_t rdata_len) { - if (rdata_len < 4) { - isc_throw(InvalidRdataLength, RRType(typeCode) << " too short"); - } + if (rdata_len < 4) { + isc_throw(InvalidRdataLength, RRType(typeCode) << " too short"); + } - uint16_t tag = buffer.readUint16(); - uint16_t algorithm = buffer.readUint8(); - uint16_t digest_type = buffer.readUint8(); + uint16_t tag = buffer.readUint16(); + uint16_t algorithm = buffer.readUint8(); + uint16_t digest_type = buffer.readUint8(); - rdata_len -= 4; - digest_.resize(rdata_len); - buffer.readData(&digest_[0], rdata_len); + rdata_len -= 4; + digest_.resize(rdata_len); + buffer.readData(&digest_[0], rdata_len); - tag_ = tag; - algorithm_ = algorithm; - digest_type_ = digest_type; + tag_ = tag; + algorithm_ = algorithm; + digest_type_ = digest_type; } DSLikeImpl(const DSLikeImpl& source) { - digest_ = source.digest_; - tag_ = source.tag_; - algorithm_ = source.algorithm_; - digest_type_ = source.digest_type_; + digest_ = source.digest_; + tag_ = source.tag_; + algorithm_ = source.algorithm_; + digest_type_ = source.digest_type_; } string toText() const { - using namespace boost; - return (lexical_cast(static_cast(tag_)) + - " " + lexical_cast(static_cast(algorithm_)) + - " " + lexical_cast(static_cast(digest_type_)) + - " " + encodeHex(digest_)); + using namespace boost; + return (lexical_cast(static_cast(tag_)) + + " " + lexical_cast(static_cast(algorithm_)) + + " " + lexical_cast(static_cast(digest_type_)) + + " " + encodeHex(digest_)); } void toWire(OutputBuffer& buffer) const { - buffer.writeUint16(tag_); - buffer.writeUint8(algorithm_); - buffer.writeUint8(digest_type_); - buffer.writeData(&digest_[0], digest_.size()); + buffer.writeUint16(tag_); + buffer.writeUint8(algorithm_); + buffer.writeUint8(digest_type_); + buffer.writeData(&digest_[0], digest_.size()); } void toWire(AbstractMessageRenderer& renderer) const { - renderer.writeUint16(tag_); - renderer.writeUint8(algorithm_); - renderer.writeUint8(digest_type_); - renderer.writeData(&digest_[0], digest_.size()); + renderer.writeUint16(tag_); + renderer.writeUint8(algorithm_); + renderer.writeUint8(digest_type_); + renderer.writeData(&digest_[0], digest_.size()); } int compare(const DSLikeImpl& other_ds) const { - if (tag_ != other_ds.tag_) { - return (tag_ < other_ds.tag_ ? -1 : 1); - } - if (algorithm_ != other_ds.algorithm_) { - return (algorithm_ < other_ds.algorithm_ ? -1 : 1); - } - if (digest_type_ != other_ds.digest_type_) { - return (digest_type_ < other_ds.digest_type_ ? -1 : 1); - } + if (tag_ != other_ds.tag_) { + return (tag_ < other_ds.tag_ ? -1 : 1); + } + if (algorithm_ != other_ds.algorithm_) { + return (algorithm_ < other_ds.algorithm_ ? -1 : 1); + } + if (digest_type_ != other_ds.digest_type_) { + return (digest_type_ < other_ds.digest_type_ ? -1 : 1); + } - size_t this_len = digest_.size(); - size_t other_len = other_ds.digest_.size(); - size_t cmplen = min(this_len, other_len); - int cmp = memcmp(&digest_[0], &other_ds.digest_[0], cmplen); - if (cmp != 0) { - return (cmp); - } else { - return ((this_len == other_len) ? 0 : (this_len < other_len) ? -1 : 1); - } + size_t this_len = digest_.size(); + size_t other_len = other_ds.digest_.size(); + size_t cmplen = min(this_len, other_len); + int cmp = memcmp(&digest_[0], &other_ds.digest_[0], cmplen); + if (cmp != 0) { + return (cmp); + } else { + return ((this_len == other_len) + ? 0 : (this_len < other_len) ? -1 : 1); + } } uint16_t getTag() const { - return (tag_); + return (tag_); } private: From fb3d0e1146e9e5a36a9402690a09e7629408c677 Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Wed, 24 Aug 2011 07:35:03 -0400 Subject: [PATCH 10/20] [1144] docs for DLV --- src/lib/dns/rdata/generic/detail/ds_like.h | 68 +++++++++++++++++++--- src/lib/dns/rdata/generic/dlv_32769.cc | 30 ++++++++++ src/lib/dns/rdata/generic/dlv_32769.h | 22 ++++++- 3 files changed, 110 insertions(+), 10 deletions(-) diff --git a/src/lib/dns/rdata/generic/detail/ds_like.h b/src/lib/dns/rdata/generic/detail/ds_like.h index 7e26d275b1..40157e63f6 100644 --- a/src/lib/dns/rdata/generic/detail/ds_like.h +++ b/src/lib/dns/rdata/generic/detail/ds_like.h @@ -20,8 +20,31 @@ #include #include +/// \brief \c rdata::DSLikeImpl class represents the DS-like RDATA for DS +/// and DLV types. +/// +/// This class implements the basic interfaces inherited by the DS and DLV +/// classes from the abstract \c rdata::Rdata class, and provides trivial +/// accessors to DS-like RDATA. templateclass DSLikeImpl { + // Common sequence of toWire() operations used for the two versions of + // toWire(). + template + void + toWireCommon(Output& output) const { + output.writeUint16(tag_); + output.writeUint8(algorithm_); + output.writeUint8(digest_type_); + output.writeData(&digest_[0], digest_.size()); + } + public: + /// \brief Constructor from string. + /// + /// Exceptions + /// + /// \c InvalidRdataText is thrown if the method cannot process the + /// parameter data for any of the number of reasons. DSLikeImpl(const string& ds_str) { istringstream iss(ds_str); @@ -52,6 +75,16 @@ public: decodeHex(digestbuf.str(), digest_); } + /// \brief Constructor from wire-format data. + /// + /// \param buffer A buffer storing the wire format data. + /// \param rdata_len The length of the RDATA in bytes, normally expected + /// to be the value of the RDLENGTH field of the corresponding RR. + /// + /// Exceptions + /// + /// \c InvalidRdataLength is thrown if the input data is too short for the + /// type. DSLikeImpl(InputBuffer& buffer, size_t rdata_len) { if (rdata_len < 4) { isc_throw(InvalidRdataLength, RRType(typeCode) << " too short"); @@ -70,6 +103,9 @@ public: digest_type_ = digest_type; } + /// \brief The copy constructor. + /// + /// Trivial for now, we could've used the default one. DSLikeImpl(const DSLikeImpl& source) { digest_ = source.digest_; @@ -78,6 +114,9 @@ public: digest_type_ = source.digest_type_; } + /// \brief Convert the DS-like data to a string. + /// + /// \return A \c string object that represents the DS-like data. string toText() const { using namespace boost; @@ -87,22 +126,34 @@ public: " " + encodeHex(digest_)); } + /// \brief Render the DS-like data in the wire format to an OutputBuffer + /// object. + /// + /// \param buffer An output buffer to store the wire data. void toWire(OutputBuffer& buffer) const { - buffer.writeUint16(tag_); - buffer.writeUint8(algorithm_); - buffer.writeUint8(digest_type_); - buffer.writeData(&digest_[0], digest_.size()); + toWireCommon(buffer); } + /// \brief Render the DS-like data in the wire format to an + /// AbstractMessageRenderer object. + /// + /// \param renderer A renderer object to send the wire data to. void toWire(AbstractMessageRenderer& renderer) const { - renderer.writeUint16(tag_); - renderer.writeUint8(algorithm_); - renderer.writeUint8(digest_type_); - renderer.writeData(&digest_[0], digest_.size()); + toWireCommon(renderer); } + /// \brief Compare two instances of DS-like RDATA. + /// + /// It is up to the caller to make sure that \c other is an object of the + /// same \c DSLikeImpl class. + /// + /// \param other the right-hand operand to compare against. + /// \return < 0 if \c this would be sorted before \c other. + /// \return 0 if \c this is identical to \c other in terms of sorting + /// order. + /// \return > 0 if \c this would be sorted after \c other. int compare(const DSLikeImpl& other_ds) const { if (tag_ != other_ds.tag_) { @@ -127,6 +178,7 @@ public: } } + /// \brief Accessors uint16_t getTag() const { return (tag_); diff --git a/src/lib/dns/rdata/generic/dlv_32769.cc b/src/lib/dns/rdata/generic/dlv_32769.cc index 70a52fc648..84a0d1603b 100644 --- a/src/lib/dns/rdata/generic/dlv_32769.cc +++ b/src/lib/dns/rdata/generic/dlv_32769.cc @@ -39,18 +39,30 @@ using namespace isc::util::encode; #include +/// \brief Constructor from string. +/// +/// A copy of the implementation object is allocated and constructed. DLV::DLV(const string& ds_str) : impl_(new DLVImpl(ds_str)) {} +/// \brief Constructor from wire-format data. +/// +/// A copy of the implementation object is allocated and constructed. DLV::DLV(InputBuffer& buffer, size_t rdata_len) : impl_(new DLVImpl(buffer, rdata_len)) {} +/// \brief Copy constructor +/// +/// A copy of the implementation object is allocated and constructed. DLV::DLV(const DLV& source) : Rdata(), impl_(new DLVImpl(*source.impl_)) {} +/// \brief Assignment operator +/// +/// PIMPL-induced logic DLV& DLV::operator=(const DLV& source) { if (impl_ == source.impl_) { @@ -64,25 +76,42 @@ DLV::operator=(const DLV& source) { return (*this); } +/// \brief Destructor +/// +/// Deallocates an internal resource. DLV::~DLV() { delete impl_; } +/// \brief Convert the \c DLV to a string. +/// +/// A pass-thru to the corresponding implementation method. string DLV::toText() const { return (impl_->toText()); } +/// \brief Render the \c DLV in the wire format to a OutputBuffer object +/// +/// A pass-thru to the corresponding implementation method. void DLV::toWire(OutputBuffer& buffer) const { impl_->toWire(buffer); } +/// \brief Render the \c DLV in the wire format to a AbstractMessageRenderer +/// object +/// +/// A pass-thru to the corresponding implementation method. void DLV::toWire(AbstractMessageRenderer& renderer) const { impl_->toWire(renderer); } +/// \brief Compare two instances of \c DLV RDATA. +/// +/// The type check is performed here. Otherwise, a pass-thru to the +/// corresponding implementation method. int DLV::compare(const Rdata& other) const { const DLV& other_ds = dynamic_cast(other); @@ -90,6 +119,7 @@ DLV::compare(const Rdata& other) const { return (impl_->compare(*other_ds.impl_)); } +/// \brief Tag accessor uint16_t DLV::getTag() const { return (impl_->getTag()); diff --git a/src/lib/dns/rdata/generic/dlv_32769.h b/src/lib/dns/rdata/generic/dlv_32769.h index 84b1d1c4ee..cdc22ec46f 100644 --- a/src/lib/dns/rdata/generic/dlv_32769.h +++ b/src/lib/dns/rdata/generic/dlv_32769.h @@ -32,16 +32,34 @@ template class DSLikeImpl; +/// \brief \c rdata::DLV class represents the DLV RDATA as defined %in +/// RFC4431. +/// +/// This class implements the basic interfaces inherited from the abstract +/// \c rdata::Rdata class, and provides trivial accessors specific to the +/// DLV RDATA. class DLV : public Rdata { public: // BEGIN_COMMON_MEMBERS // END_COMMON_MEMBERS + + /// \brief Assignment operator. + /// + /// It internally allocates a resource, and if it fails a corresponding + /// standard exception will be thrown. + /// This operator never throws an exception otherwise. + /// + /// This operator provides the strong exception guarantee: When an + /// exception is thrown the content of the assignment target will be + /// intact. DLV& operator=(const DLV& source); + + /// \brief The destructor. ~DLV(); + /// \brief Return the value of the Tag field. /// - /// Specialized methods - /// + /// This method never throws an exception. uint16_t getTag() const; private: typedef DSLikeImpl DLVImpl; From 06341cb6cdbd5ff57c376f7b0b25aba4a35bab86 Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Mon, 12 Sep 2011 11:32:00 -0400 Subject: [PATCH 11/20] [1144] tests for DS and DLV combined into a single parameterized test --- src/lib/dns/tests/Makefile.am | 2 +- src/lib/dns/tests/rdata_ds_like_unittest.cc | 125 ++++++++++++++++++++ src/lib/dns/tests/rdata_ds_unittest.cc | 99 ---------------- 3 files changed, 126 insertions(+), 100 deletions(-) create mode 100644 src/lib/dns/tests/rdata_ds_like_unittest.cc delete mode 100644 src/lib/dns/tests/rdata_ds_unittest.cc diff --git a/src/lib/dns/tests/Makefile.am b/src/lib/dns/tests/Makefile.am index bd6fbe2a6e..6d60bee53b 100644 --- a/src/lib/dns/tests/Makefile.am +++ b/src/lib/dns/tests/Makefile.am @@ -34,7 +34,7 @@ run_unittests_SOURCES += rdata_ptr_unittest.cc rdata_cname_unittest.cc run_unittests_SOURCES += rdata_dname_unittest.cc run_unittests_SOURCES += rdata_opt_unittest.cc run_unittests_SOURCES += rdata_dnskey_unittest.cc -run_unittests_SOURCES += rdata_ds_unittest.cc +run_unittests_SOURCES += rdata_ds_like_unittest.cc run_unittests_SOURCES += rdata_nsec_unittest.cc run_unittests_SOURCES += rdata_nsec3_unittest.cc run_unittests_SOURCES += rdata_nsecbitmap_unittest.cc diff --git a/src/lib/dns/tests/rdata_ds_like_unittest.cc b/src/lib/dns/tests/rdata_ds_like_unittest.cc new file mode 100644 index 0000000000..444d41f0d3 --- /dev/null +++ b/src/lib/dns/tests/rdata_ds_like_unittest.cc @@ -0,0 +1,125 @@ +// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +using isc::UnitTestUtil; +using namespace std; +using namespace isc::dns; +using namespace isc::util; +using namespace isc::dns::rdata; + +// hacks to make templates work +template +class RRTYPE : public RRType { +public: + RRTYPE(); +}; + +template<> RRTYPE::RRTYPE() : RRType(RRType::DS()) {} +template<> RRTYPE::RRTYPE() : RRType(RRType::DLV()) {} + +namespace { +template +class Rdata_DS_LIKE_Test : public RdataTest { +protected: + static DS_LIKE const rdata_ds_like; +}; + +string ds_like_txt("12892 5 2 F1E184C0E1D615D20EB3C223ACED3B03C773DD952D" + "5F0EB5C777586DE18DA6B5"); + +template +DS_LIKE const Rdata_DS_LIKE_Test::rdata_ds_like(ds_like_txt); + +// The list of types we want to test. +typedef testing::Types Implementations; + +TYPED_TEST_CASE(Rdata_DS_LIKE_Test, Implementations); + +TYPED_TEST(Rdata_DS_LIKE_Test, toText_DS_LIKE) { + EXPECT_EQ(ds_like_txt, + Rdata_DS_LIKE_Test::rdata_ds_like.toText()); +} + +TYPED_TEST(Rdata_DS_LIKE_Test, badText_DS_LIKE) { + EXPECT_THROW(const TypeParam ds_like2("99999 5 2 BEEF"), InvalidRdataText); + EXPECT_THROW(const TypeParam ds_like2("11111 555 2 BEEF"), + InvalidRdataText); + EXPECT_THROW(const TypeParam ds_like2("11111 5 22222 BEEF"), + InvalidRdataText); + EXPECT_THROW(const TypeParam ds_like2("11111 5 2"), InvalidRdataText); + EXPECT_THROW(const TypeParam ds_like2("GARBAGE IN"), InvalidRdataText); +} + +// this test currently fails; we must fix it, and then migrate the test to +// badText_DS_LIKE +TYPED_TEST(Rdata_DS_LIKE_Test, DISABLED_badText_DS_LIKE) { + // no space between the digest type and the digest. + EXPECT_THROW(const TypeParam ds_like2( + "12892 5 2F1E184C0E1D615D20EB3C223ACED3B03C773DD952D" + "5F0EB5C777586DE18DA6B5"), InvalidRdataText); +} + +TYPED_TEST(Rdata_DS_LIKE_Test, createFromWire_DS_LIKE) { + EXPECT_EQ(0, Rdata_DS_LIKE_Test::rdata_ds_like.compare( + *rdataFactoryFromFile(RRTYPE(), RRClass::IN(), + "rdata_ds_fromWire"))); +} + +TYPED_TEST(Rdata_DS_LIKE_Test, getTag_DS_LIKE) { + EXPECT_EQ(12892, Rdata_DS_LIKE_Test::rdata_ds_like.getTag()); +} + +TYPED_TEST(Rdata_DS_LIKE_Test, toWireRenderer) { + Rdata_DS_LIKE_Test::renderer.skip(2); + TypeParam rdata_ds_like(ds_like_txt); + rdata_ds_like.toWire(Rdata_DS_LIKE_Test::renderer); + + vector data; + UnitTestUtil::readWireData("rdata_ds_fromWire", data); + EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, + static_cast + (Rdata_DS_LIKE_Test::obuffer.getData()) + 2, + Rdata_DS_LIKE_Test::obuffer.getLength() - 2, + &data[2], data.size() - 2); +} + +TYPED_TEST(Rdata_DS_LIKE_Test, toWireBuffer) { + TypeParam rdata_ds_like(ds_like_txt); + rdata_ds_like.toWire(Rdata_DS_LIKE_Test::obuffer); +} + +TYPED_TEST(Rdata_DS_LIKE_Test, compare) { + // trivial case: self equivalence + EXPECT_EQ(0, + TypeParam(ds_like_txt).compare(TypeParam(ds_like_txt))); + + // TODO: need more tests +} + +} diff --git a/src/lib/dns/tests/rdata_ds_unittest.cc b/src/lib/dns/tests/rdata_ds_unittest.cc deleted file mode 100644 index 59886208cf..0000000000 --- a/src/lib/dns/tests/rdata_ds_unittest.cc +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -using isc::UnitTestUtil; -using namespace std; -using namespace isc::dns; -using namespace isc::util; -using namespace isc::dns::rdata; - -namespace { -class Rdata_DS_Test : public RdataTest { - // there's nothing to specialize -}; - -string ds_txt("12892 5 2 F1E184C0E1D615D20EB3C223ACED3B03C773DD952D" - "5F0EB5C777586DE18DA6B5"); -const generic::DS rdata_ds(ds_txt); - -TEST_F(Rdata_DS_Test, toText_DS) { - EXPECT_EQ(ds_txt, rdata_ds.toText()); -} - -TEST_F(Rdata_DS_Test, badText_DS) { - EXPECT_THROW(const generic::DS ds2("99999 5 2 BEEF"), InvalidRdataText); - EXPECT_THROW(const generic::DS ds2("11111 555 2 BEEF"), InvalidRdataText); - EXPECT_THROW(const generic::DS ds2("11111 5 22222 BEEF"), InvalidRdataText); - EXPECT_THROW(const generic::DS ds2("11111 5 2"), InvalidRdataText); - EXPECT_THROW(const generic::DS ds2("GARBAGE IN"), InvalidRdataText); -} - -// this test currently fails; we must fix it, and then migrate the test to -// badText_DS -TEST_F(Rdata_DS_Test, DISABLED_badText_DS) { - // no space between the digest type and the digest. - EXPECT_THROW(const generic::DS ds2( - "12892 5 2F1E184C0E1D615D20EB3C223ACED3B03C773DD952D" - "5F0EB5C777586DE18DA6B5"), InvalidRdataText); -} - -TEST_F(Rdata_DS_Test, createFromWire_DS) { - EXPECT_EQ(0, rdata_ds.compare( - *rdataFactoryFromFile(RRType::DS(), RRClass::IN(), - "rdata_ds_fromWire"))); -} - -TEST_F(Rdata_DS_Test, getTag_DS) { - EXPECT_EQ(12892, rdata_ds.getTag()); -} - -TEST_F(Rdata_DS_Test, toWireRenderer) { - renderer.skip(2); - generic::DS rdata_ds(ds_txt); - rdata_ds.toWire(renderer); - - vector data; - UnitTestUtil::readWireData("rdata_ds_fromWire", data); - EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, - static_cast(obuffer.getData()) + 2, - obuffer.getLength() - 2, &data[2], data.size() - 2); -} - -TEST_F(Rdata_DS_Test, toWireBuffer) { - generic::DS rdata_ds(ds_txt); - rdata_ds.toWire(obuffer); -} - -TEST_F(Rdata_DS_Test, compare) { - // trivial case: self equivalence - EXPECT_EQ(0, generic::DS(ds_txt).compare(generic::DS(ds_txt))); - - // TODO: need more tests -} - -} From f8b10842465d60483e3bc9827e06115ea8081bfc Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Mon, 12 Sep 2011 14:36:10 -0700 Subject: [PATCH 12/20] [1144] missing 'this->' for TYPED_TEST --- src/lib/dns/tests/rdata_ds_like_unittest.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/dns/tests/rdata_ds_like_unittest.cc b/src/lib/dns/tests/rdata_ds_like_unittest.cc index 444d41f0d3..62937df23e 100644 --- a/src/lib/dns/tests/rdata_ds_like_unittest.cc +++ b/src/lib/dns/tests/rdata_ds_like_unittest.cc @@ -87,8 +87,8 @@ TYPED_TEST(Rdata_DS_LIKE_Test, DISABLED_badText_DS_LIKE) { TYPED_TEST(Rdata_DS_LIKE_Test, createFromWire_DS_LIKE) { EXPECT_EQ(0, Rdata_DS_LIKE_Test::rdata_ds_like.compare( - *rdataFactoryFromFile(RRTYPE(), RRClass::IN(), - "rdata_ds_fromWire"))); + *this->rdataFactoryFromFile(RRTYPE(), RRClass::IN(), + "rdata_ds_fromWire"))); } TYPED_TEST(Rdata_DS_LIKE_Test, getTag_DS_LIKE) { From 31e010330189f489c624b7cdb812ef3f33f8e280 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Fri, 23 Sep 2011 14:34:30 -0700 Subject: [PATCH 13/20] [1144] some suggested (mostly) editorial cleanups: - style guideline adjustment (position of opening braces, indentation, etc) - avoid 'using namespace' before including a header file and (as a result of it) in ds_like.h - move standard header files from dlv/ds implementation files to ds_link.h as much as possible - trivial documentation updates --- src/lib/dns/rdata/generic/detail/ds_like.h | 50 ++++++++++++++------- src/lib/dns/rdata/generic/dlv_32769.cc | 11 ++--- src/lib/dns/rdata/generic/dlv_32769.h | 8 ++-- src/lib/dns/rdata/generic/ds_43.cc | 11 ++--- src/lib/dns/rdata/generic/ds_43.h | 28 ++++++++++-- src/lib/dns/tests/rdata_ds_like_unittest.cc | 11 +++-- 6 files changed, 73 insertions(+), 46 deletions(-) diff --git a/src/lib/dns/rdata/generic/detail/ds_like.h b/src/lib/dns/rdata/generic/detail/ds_like.h index 40157e63f6..da3ade4338 100644 --- a/src/lib/dns/rdata/generic/detail/ds_like.h +++ b/src/lib/dns/rdata/generic/detail/ds_like.h @@ -17,19 +17,36 @@ #include +#include +#include #include #include +#include + +#include + +#include +#include +#include +#include + +namespace isc { +namespace dns { +namespace rdata { +namespace generic { +namespace detail { + /// \brief \c rdata::DSLikeImpl class represents the DS-like RDATA for DS /// and DLV types. /// /// This class implements the basic interfaces inherited by the DS and DLV /// classes from the abstract \c rdata::Rdata class, and provides trivial /// accessors to DS-like RDATA. -templateclass DSLikeImpl { +template class DSLikeImpl { // Common sequence of toWire() operations used for the two versions of // toWire(). - template + template void toWireCommon(Output& output) const { output.writeUint16(tag_); @@ -45,10 +62,9 @@ public: /// /// \c InvalidRdataText is thrown if the method cannot process the /// parameter data for any of the number of reasons. - DSLikeImpl(const string& ds_str) - { - istringstream iss(ds_str); - stringbuf digestbuf; + DSLikeImpl(const std::string& ds_str) { + std::istringstream iss(ds_str); + std::stringbuf digestbuf; uint32_t tag, algorithm, digest_type; iss >> tag >> algorithm >> digest_type >> &digestbuf; @@ -90,24 +106,19 @@ public: isc_throw(InvalidRdataLength, RRType(typeCode) << " too short"); } - uint16_t tag = buffer.readUint16(); - uint16_t algorithm = buffer.readUint8(); - uint16_t digest_type = buffer.readUint8(); + tag_ = buffer.readUint16(); + algorithm_ = buffer.readUint8(); + digest_type_ = buffer.readUint8(); rdata_len -= 4; digest_.resize(rdata_len); buffer.readData(&digest_[0], rdata_len); - - tag_ = tag; - algorithm_ = algorithm; - digest_type_ = digest_type; } /// \brief The copy constructor. /// /// Trivial for now, we could've used the default one. - DSLikeImpl(const DSLikeImpl& source) - { + DSLikeImpl(const DSLikeImpl& source) { digest_ = source.digest_; tag_ = source.tag_; algorithm_ = source.algorithm_; @@ -117,7 +128,7 @@ public: /// \brief Convert the DS-like data to a string. /// /// \return A \c string object that represents the DS-like data. - string + std::string toText() const { using namespace boost; return (lexical_cast(static_cast(tag_)) + @@ -189,9 +200,14 @@ private: uint16_t tag_; uint8_t algorithm_; uint8_t digest_type_; - vector digest_; + std::vector digest_; }; +} +} +} +} +} #endif // __DS_LIKE_H // Local Variables: diff --git a/src/lib/dns/rdata/generic/dlv_32769.cc b/src/lib/dns/rdata/generic/dlv_32769.cc index 84a0d1603b..4e2d780397 100644 --- a/src/lib/dns/rdata/generic/dlv_32769.cc +++ b/src/lib/dns/rdata/generic/dlv_32769.cc @@ -12,33 +12,28 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -#include #include -#include -#include - -#include #include #include #include -#include #include #include #include #include +#include + using namespace std; using namespace isc::util; using namespace isc::util::encode; +using namespace isc::dns::rdata::generic::detail; // BEGIN_ISC_NAMESPACE // BEGIN_RDATA_NAMESPACE -#include - /// \brief Constructor from string. /// /// A copy of the implementation object is allocated and constructed. diff --git a/src/lib/dns/rdata/generic/dlv_32769.h b/src/lib/dns/rdata/generic/dlv_32769.h index cdc22ec46f..30128fb241 100644 --- a/src/lib/dns/rdata/generic/dlv_32769.h +++ b/src/lib/dns/rdata/generic/dlv_32769.h @@ -30,9 +30,11 @@ // BEGIN_RDATA_NAMESPACE -template class DSLikeImpl; +namespace detail { +template class DSLikeImpl; +} -/// \brief \c rdata::DLV class represents the DLV RDATA as defined %in +/// \brief \c rdata::generic::DLV class represents the DLV RDATA as defined in /// RFC4431. /// /// This class implements the basic interfaces inherited from the abstract @@ -62,7 +64,7 @@ public: /// This method never throws an exception. uint16_t getTag() const; private: - typedef DSLikeImpl DLVImpl; + typedef detail::DSLikeImpl DLVImpl; DLVImpl* impl_; }; diff --git a/src/lib/dns/rdata/generic/ds_43.cc b/src/lib/dns/rdata/generic/ds_43.cc index 0883616f69..5535d9d279 100644 --- a/src/lib/dns/rdata/generic/ds_43.cc +++ b/src/lib/dns/rdata/generic/ds_43.cc @@ -12,33 +12,28 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -#include #include -#include -#include - -#include #include #include #include -#include #include #include +#include + #include #include using namespace std; using namespace isc::util; using namespace isc::util::encode; +using namespace isc::dns::rdata::generic::detail; // BEGIN_ISC_NAMESPACE // BEGIN_RDATA_NAMESPACE -#include - DS::DS(const string& ds_str) : impl_(new DSImpl(ds_str)) {} diff --git a/src/lib/dns/rdata/generic/ds_43.h b/src/lib/dns/rdata/generic/ds_43.h index ef441b6ef6..52f2f0b3cd 100644 --- a/src/lib/dns/rdata/generic/ds_43.h +++ b/src/lib/dns/rdata/generic/ds_43.h @@ -30,21 +30,41 @@ // BEGIN_RDATA_NAMESPACE -template class DSLikeImpl; +namespace detail { +template class DSLikeImpl; +} +/// \brief \c rdata::generic::DS class represents the DS RDATA as defined in +/// RFC3658. +/// +/// This class implements the basic interfaces inherited from the abstract +/// \c rdata::Rdata class, and provides trivial accessors specific to the +/// DS RDATA. class DS : public Rdata { public: // BEGIN_COMMON_MEMBERS // END_COMMON_MEMBERS + + /// \brief Assignment operator. + /// + /// It internally allocates a resource, and if it fails a corresponding + /// standard exception will be thrown. + /// This operator never throws an exception otherwise. + /// + /// This operator provides the strong exception guarantee: When an + /// exception is thrown the content of the assignment target will be + /// intact. DS& operator=(const DS& source); + + /// \brief The destructor. ~DS(); + /// \brief Return the value of the Tag field. /// - /// Specialized methods - /// + /// This method never throws an exception. uint16_t getTag() const; private: - typedef DSLikeImpl DSImpl; + typedef detail::DSLikeImpl DSImpl; DSImpl* impl_; }; diff --git a/src/lib/dns/tests/rdata_ds_like_unittest.cc b/src/lib/dns/tests/rdata_ds_like_unittest.cc index 62937df23e..354dfe7522 100644 --- a/src/lib/dns/tests/rdata_ds_like_unittest.cc +++ b/src/lib/dns/tests/rdata_ds_like_unittest.cc @@ -33,8 +33,9 @@ using namespace isc::dns; using namespace isc::util; using namespace isc::dns::rdata; +namespace { // hacks to make templates work -template +template class RRTYPE : public RRType { public: RRTYPE(); @@ -43,7 +44,6 @@ public: template<> RRTYPE::RRTYPE() : RRType(RRType::DS()) {} template<> RRTYPE::RRTYPE() : RRType(RRType::DLV()) {} -namespace { template class Rdata_DS_LIKE_Test : public RdataTest { protected: @@ -51,7 +51,7 @@ protected: }; string ds_like_txt("12892 5 2 F1E184C0E1D615D20EB3C223ACED3B03C773DD952D" - "5F0EB5C777586DE18DA6B5"); + "5F0EB5C777586DE18DA6B5"); template DS_LIKE const Rdata_DS_LIKE_Test::rdata_ds_like(ds_like_txt); @@ -103,7 +103,7 @@ TYPED_TEST(Rdata_DS_LIKE_Test, toWireRenderer) { vector data; UnitTestUtil::readWireData("rdata_ds_fromWire", data); EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, - static_cast + static_cast (Rdata_DS_LIKE_Test::obuffer.getData()) + 2, Rdata_DS_LIKE_Test::obuffer.getLength() - 2, &data[2], data.size() - 2); @@ -116,8 +116,7 @@ TYPED_TEST(Rdata_DS_LIKE_Test, toWireBuffer) { TYPED_TEST(Rdata_DS_LIKE_Test, compare) { // trivial case: self equivalence - EXPECT_EQ(0, - TypeParam(ds_like_txt).compare(TypeParam(ds_like_txt))); + EXPECT_EQ(0, TypeParam(ds_like_txt).compare(TypeParam(ds_like_txt))); // TODO: need more tests } From b6dd72042939ca62d9ceeb80385eedc7c5f0560d Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Fri, 23 Sep 2011 14:55:49 -0700 Subject: [PATCH 14/20] [1144] added simple assignment tests mainly only for covering the code. --- src/lib/dns/tests/rdata_ds_like_unittest.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lib/dns/tests/rdata_ds_like_unittest.cc b/src/lib/dns/tests/rdata_ds_like_unittest.cc index 354dfe7522..daf0dd48c8 100644 --- a/src/lib/dns/tests/rdata_ds_like_unittest.cc +++ b/src/lib/dns/tests/rdata_ds_like_unittest.cc @@ -91,6 +91,23 @@ TYPED_TEST(Rdata_DS_LIKE_Test, createFromWire_DS_LIKE) { "rdata_ds_fromWire"))); } +TYPED_TEST(Rdata_DS_LIKE_Test, assignment_DS_LIKE) { + TypeParam copy((string(ds_like_txt))); + copy = this->rdata_ds_like; + EXPECT_EQ(0, copy.compare(this->rdata_ds_like)); + + // Check if the copied data is valid even after the original is deleted + TypeParam* copy2 = new TypeParam(this->rdata_ds_like); + TypeParam copy3((string(ds_like_txt))); + copy3 = *copy2; + delete copy2; + EXPECT_EQ(0, copy3.compare(this->rdata_ds_like)); + + // Self assignment + copy = copy; + EXPECT_EQ(0, copy.compare(this->rdata_ds_like)); +} + TYPED_TEST(Rdata_DS_LIKE_Test, getTag_DS_LIKE) { EXPECT_EQ(12892, Rdata_DS_LIKE_Test::rdata_ds_like.getTag()); } From 9c95bf79406ae791e2f8c7263ff4fddb19d0eda4 Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Tue, 27 Sep 2011 11:24:43 -0400 Subject: [PATCH 15/20] [1144] style/cosmetic changes in ds_43.{h,cc} and dlv_32769.{h,cc} --- src/lib/dns/rdata/generic/dlv_32769.cc | 5 +---- src/lib/dns/rdata/generic/dlv_32769.h | 2 +- src/lib/dns/rdata/generic/ds_43.cc | 5 +---- src/lib/dns/rdata/generic/ds_43.h | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/lib/dns/rdata/generic/dlv_32769.cc b/src/lib/dns/rdata/generic/dlv_32769.cc index 4e2d780397..9887aa88bd 100644 --- a/src/lib/dns/rdata/generic/dlv_32769.cc +++ b/src/lib/dns/rdata/generic/dlv_32769.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -21,9 +21,6 @@ #include #include -#include -#include - #include using namespace std; diff --git a/src/lib/dns/rdata/generic/dlv_32769.h b/src/lib/dns/rdata/generic/dlv_32769.h index 30128fb241..86cd98ce05 100644 --- a/src/lib/dns/rdata/generic/dlv_32769.h +++ b/src/lib/dns/rdata/generic/dlv_32769.h @@ -1,4 +1,4 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/lib/dns/rdata/generic/ds_43.cc b/src/lib/dns/rdata/generic/ds_43.cc index 5535d9d279..20b62dca83 100644 --- a/src/lib/dns/rdata/generic/ds_43.cc +++ b/src/lib/dns/rdata/generic/ds_43.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -23,9 +23,6 @@ #include -#include -#include - using namespace std; using namespace isc::util; using namespace isc::util::encode; diff --git a/src/lib/dns/rdata/generic/ds_43.h b/src/lib/dns/rdata/generic/ds_43.h index 52f2f0b3cd..2697f513be 100644 --- a/src/lib/dns/rdata/generic/ds_43.h +++ b/src/lib/dns/rdata/generic/ds_43.h @@ -1,4 +1,4 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above From 5e5743ecb40da81c4e8ad27ac8b158c9a7aaff87 Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Tue, 27 Sep 2011 11:26:10 -0400 Subject: [PATCH 16/20] [1144] proposed new DLV entry in ChangeLog --- ChangeLog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5a145584ce..f2c3edc736 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +278. [func] dvv + Implement the DLV rrtype according to RFC4431. + (Trac #1144, git TBD) + 277. [func] jerry Implement the SRV rrtype according to RFC2782. (Trac #1128, git 5fd94aa027828c50e63ae1073d9d6708e0a9c223) From 0b46c391a973bb8d3f0a1681eb0a79e8a196f0f0 Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Tue, 27 Sep 2011 11:28:18 -0400 Subject: [PATCH 17/20] [1144] src/lib/dns/rdata/generic/detail/ds_like.h: bug fixed for a faling unittest case + cosmetic/style change src/lib/dns/tests/rdata_ds_like_unittest.cc: a previously failing test case enabled --- src/lib/dns/rdata/generic/detail/ds_like.h | 12 ++++++++++- src/lib/dns/tests/rdata_ds_like_unittest.cc | 22 ++++++++------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/lib/dns/rdata/generic/detail/ds_like.h b/src/lib/dns/rdata/generic/detail/ds_like.h index da3ade4338..1061ece2f1 100644 --- a/src/lib/dns/rdata/generic/detail/ds_like.h +++ b/src/lib/dns/rdata/generic/detail/ds_like.h @@ -64,10 +64,12 @@ public: /// parameter data for any of the number of reasons. DSLikeImpl(const std::string& ds_str) { std::istringstream iss(ds_str); + // peekc should be of iss's char_type for isspace to work + std::istringstream::char_type peekc; std::stringbuf digestbuf; uint32_t tag, algorithm, digest_type; - iss >> tag >> algorithm >> digest_type >> &digestbuf; + iss >> tag >> algorithm >> digest_type; if (iss.bad() || iss.fail()) { isc_throw(InvalidRdataText, "Invalid " << RRType(typeCode) << " text"); @@ -85,6 +87,14 @@ public: RRType(typeCode) << " digest type out of range"); } + peekc = iss.peek(); + if (!iss.good() || !isspace(peekc, iss.getloc())) { + isc_throw(InvalidRdataText, + RRType(typeCode) << " presentation format error"); + } + + iss >> &digestbuf; + tag_ = tag; algorithm_ = algorithm; digest_type_ = digest_type; diff --git a/src/lib/dns/tests/rdata_ds_like_unittest.cc b/src/lib/dns/tests/rdata_ds_like_unittest.cc index daf0dd48c8..95610e1edc 100644 --- a/src/lib/dns/tests/rdata_ds_like_unittest.cc +++ b/src/lib/dns/tests/rdata_ds_like_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -62,8 +62,7 @@ typedef testing::Types Implementations; TYPED_TEST_CASE(Rdata_DS_LIKE_Test, Implementations); TYPED_TEST(Rdata_DS_LIKE_Test, toText_DS_LIKE) { - EXPECT_EQ(ds_like_txt, - Rdata_DS_LIKE_Test::rdata_ds_like.toText()); + EXPECT_EQ(ds_like_txt, this->rdata_ds_like.toText()); } TYPED_TEST(Rdata_DS_LIKE_Test, badText_DS_LIKE) { @@ -74,11 +73,6 @@ TYPED_TEST(Rdata_DS_LIKE_Test, badText_DS_LIKE) { InvalidRdataText); EXPECT_THROW(const TypeParam ds_like2("11111 5 2"), InvalidRdataText); EXPECT_THROW(const TypeParam ds_like2("GARBAGE IN"), InvalidRdataText); -} - -// this test currently fails; we must fix it, and then migrate the test to -// badText_DS_LIKE -TYPED_TEST(Rdata_DS_LIKE_Test, DISABLED_badText_DS_LIKE) { // no space between the digest type and the digest. EXPECT_THROW(const TypeParam ds_like2( "12892 5 2F1E184C0E1D615D20EB3C223ACED3B03C773DD952D" @@ -86,7 +80,7 @@ TYPED_TEST(Rdata_DS_LIKE_Test, DISABLED_badText_DS_LIKE) { } TYPED_TEST(Rdata_DS_LIKE_Test, createFromWire_DS_LIKE) { - EXPECT_EQ(0, Rdata_DS_LIKE_Test::rdata_ds_like.compare( + EXPECT_EQ(0, this->rdata_ds_like.compare( *this->rdataFactoryFromFile(RRTYPE(), RRClass::IN(), "rdata_ds_fromWire"))); } @@ -109,26 +103,26 @@ TYPED_TEST(Rdata_DS_LIKE_Test, assignment_DS_LIKE) { } TYPED_TEST(Rdata_DS_LIKE_Test, getTag_DS_LIKE) { - EXPECT_EQ(12892, Rdata_DS_LIKE_Test::rdata_ds_like.getTag()); + EXPECT_EQ(12892, this->rdata_ds_like.getTag()); } TYPED_TEST(Rdata_DS_LIKE_Test, toWireRenderer) { Rdata_DS_LIKE_Test::renderer.skip(2); TypeParam rdata_ds_like(ds_like_txt); - rdata_ds_like.toWire(Rdata_DS_LIKE_Test::renderer); + rdata_ds_like.toWire(this->renderer); vector data; UnitTestUtil::readWireData("rdata_ds_fromWire", data); EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, static_cast - (Rdata_DS_LIKE_Test::obuffer.getData()) + 2, - Rdata_DS_LIKE_Test::obuffer.getLength() - 2, + (this->obuffer.getData()) + 2, + this->obuffer.getLength() - 2, &data[2], data.size() - 2); } TYPED_TEST(Rdata_DS_LIKE_Test, toWireBuffer) { TypeParam rdata_ds_like(ds_like_txt); - rdata_ds_like.toWire(Rdata_DS_LIKE_Test::obuffer); + rdata_ds_like.toWire(this->obuffer); } TYPED_TEST(Rdata_DS_LIKE_Test, compare) { From fe76209cd8ad96144f0e2fc9522f5fda1d52d9c3 Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Tue, 4 Oct 2011 07:33:05 -0400 Subject: [PATCH 18/20] [1144] read instead of peek in rdata/generic/detail/ds_like.h --- src/lib/dns/rdata/generic/detail/ds_like.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/dns/rdata/generic/detail/ds_like.h b/src/lib/dns/rdata/generic/detail/ds_like.h index 1061ece2f1..b5a35cd967 100644 --- a/src/lib/dns/rdata/generic/detail/ds_like.h +++ b/src/lib/dns/rdata/generic/detail/ds_like.h @@ -87,7 +87,7 @@ public: RRType(typeCode) << " digest type out of range"); } - peekc = iss.peek(); + iss.read(&peekc, 1); if (!iss.good() || !isspace(peekc, iss.getloc())) { isc_throw(InvalidRdataText, RRType(typeCode) << " presentation format error"); From 956e210239d46bebe4574c5ca38b3b51b1bb7c65 Mon Sep 17 00:00:00 2001 From: Dima Volodin Date: Tue, 4 Oct 2011 07:33:55 -0400 Subject: [PATCH 19/20] [1144] more comparison tests in tests/rdata_ds_like_unittest.cc --- src/lib/dns/tests/rdata_ds_like_unittest.cc | 34 ++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/lib/dns/tests/rdata_ds_like_unittest.cc b/src/lib/dns/tests/rdata_ds_like_unittest.cc index 95610e1edc..db25aead80 100644 --- a/src/lib/dns/tests/rdata_ds_like_unittest.cc +++ b/src/lib/dns/tests/rdata_ds_like_unittest.cc @@ -125,11 +125,43 @@ TYPED_TEST(Rdata_DS_LIKE_Test, toWireBuffer) { rdata_ds_like.toWire(this->obuffer); } +string ds_like_txt1("12892 5 2 F1E184C0E1D615D20EB3C223ACED3B03C773DD952D" + "5F0EB5C777586DE18DA6B5"); +// different tag +string ds_like_txt2("12893 5 2 F1E184C0E1D615D20EB3C223ACED3B03C773DD952D" + "5F0EB5C777586DE18DA6B5"); +// different algorithm +string ds_like_txt3("12892 6 2 F1E184C0E1D615D20EB3C223ACED3B03C773DD952D" + "5F0EB5C777586DE18DA6B5"); +// different digest type +string ds_like_txt4("12892 5 3 F1E184C0E1D615D20EB3C223ACED3B03C773DD952D" + "5F0EB5C777586DE18DA6B5"); +// different digest +string ds_like_txt5("12892 5 2 F2E184C0E1D615D20EB3C223ACED3B03C773DD952D" + "5F0EB5C777586DE18DA6B5"); +// different digest length +string ds_like_txt6("12892 5 2 F2E184C0E1D615D20EB3C223ACED3B03C773DD952D" + "5F0EB5C777586DE18DA6B555"); + TYPED_TEST(Rdata_DS_LIKE_Test, compare) { // trivial case: self equivalence EXPECT_EQ(0, TypeParam(ds_like_txt).compare(TypeParam(ds_like_txt))); - // TODO: need more tests + // non-equivalence tests + EXPECT_LT(TypeParam(ds_like_txt1).compare(TypeParam(ds_like_txt2)), 0); + EXPECT_GT(TypeParam(ds_like_txt2).compare(TypeParam(ds_like_txt1)), 0); + + EXPECT_LT(TypeParam(ds_like_txt1).compare(TypeParam(ds_like_txt3)), 0); + EXPECT_GT(TypeParam(ds_like_txt3).compare(TypeParam(ds_like_txt1)), 0); + + EXPECT_LT(TypeParam(ds_like_txt1).compare(TypeParam(ds_like_txt4)), 0); + EXPECT_GT(TypeParam(ds_like_txt4).compare(TypeParam(ds_like_txt1)), 0); + + EXPECT_LT(TypeParam(ds_like_txt1).compare(TypeParam(ds_like_txt5)), 0); + EXPECT_GT(TypeParam(ds_like_txt5).compare(TypeParam(ds_like_txt1)), 0); + + EXPECT_LT(TypeParam(ds_like_txt1).compare(TypeParam(ds_like_txt6)), 0); + EXPECT_GT(TypeParam(ds_like_txt6).compare(TypeParam(ds_like_txt1)), 0); } } From 33c0d21361655c08b274c75736b7bcbe99dd3d2d Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Tue, 4 Oct 2011 10:30:31 -0700 Subject: [PATCH 20/20] [1144] added one more test case: comparing incompatible types of RDATAs --- src/lib/dns/tests/rdata_ds_like_unittest.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/dns/tests/rdata_ds_like_unittest.cc b/src/lib/dns/tests/rdata_ds_like_unittest.cc index db25aead80..d49e22987e 100644 --- a/src/lib/dns/tests/rdata_ds_like_unittest.cc +++ b/src/lib/dns/tests/rdata_ds_like_unittest.cc @@ -162,6 +162,10 @@ TYPED_TEST(Rdata_DS_LIKE_Test, compare) { EXPECT_LT(TypeParam(ds_like_txt1).compare(TypeParam(ds_like_txt6)), 0); EXPECT_GT(TypeParam(ds_like_txt6).compare(TypeParam(ds_like_txt1)), 0); + + // comparison attempt between incompatible RR types should be rejected + EXPECT_THROW(this->rdata_ds_like.compare(*RdataTest::rdata_nomatch), + bad_cast); } }