Browse Source

[trac1144] DS reworked and DLV added

Dima Volodin 13 years ago
parent
commit
f4620596bd

+ 169 - 0
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 <stdint.h>
+
+#include <string>
+#include <vector>
+
+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<uint8_t>& digest) :
+        tag_(tag), algorithm_(algorithm), digest_type_(digest_type),
+        digest_(digest)
+    {}
+
+    uint16_t tag_;
+    uint8_t algorithm_;
+    uint8_t digest_type_;
+    const vector<uint8_t> digest_;
+};
+
+template<class RTYPE, uint16_t typeCode>class 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<uint8_t> 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<uint8_t> 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<string>(static_cast<int>(impl_->tag_)) +
+	    " " + lexical_cast<string>(static_cast<int>(impl_->algorithm_)) +
+	    " " + lexical_cast<string>(static_cast<int>(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<const RTYPE&>(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: 

+ 19 - 0
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

+ 97 - 0
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 <iostream>
+#include <string>
+#include <sstream>
+#include <vector>
+
+#include <boost/lexical_cast.hpp>
+
+#include <util/buffer.h>
+#include <util/encode/hex.h>
+
+#include <dns/messagerenderer.h>
+#include <dns/name.h>
+#include <dns/rdata.h>
+#include <dns/rdataclass.h>
+
+#include <stdio.h>
+#include <time.h>
+
+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 <dns/rdata/generic/detail/ds_like.h>
+
+class DLV : public DS_LIKE<DLV, 32769> {
+    friend class DS_LIKE<DLV, 32769>;
+    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<DLV, 32769>(type_str) {}
+
+///    DLV(isc::util::InputBuffer& buffer, size_t rdata_len);
+inline DLV::DLV(isc::util::InputBuffer& buffer, size_t rdata_len) : DS_LIKE<DLV, 32769>(buffer, rdata_len) {}
+
+///    DLV(const DLV& other);
+inline DLV::DLV(const DLV& other) : DS_LIKE<DLV, 32769>(other) {}
+
+///    virtual std::string toText() const;
+inline std::string DLV::toText() const
+{
+    return DS_LIKE<DLV, 32769>::toText();
+}
+
+///    virtual void toWire(isc::util::OutputBuffer& buffer) const;
+inline void DLV::toWire(isc::util::OutputBuffer& buffer) const
+{
+    DS_LIKE<DLV, 32769>::toWire(buffer);
+}
+
+///    virtual void toWire(AbstractMessageRenderer& renderer) const;
+inline void DLV::toWire(AbstractMessageRenderer& renderer) const
+{
+    DS_LIKE<DLV, 32769>::toWire(renderer);
+}
+
+///    virtual int compare(const Rdata& other) const;
+inline int DLV::compare(const Rdata& other) const
+{
+    return DS_LIKE<DLV, 32769>::compare(other);
+}
+
+// END_RDATA_NAMESPACE
+// END_ISC_NAMESPACE
+// END_HEADER_GUARD
+
+// Local Variables: 
+// mode: c++
+// End: 

+ 0 - 155
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 <iostream>
-#include <string>
-#include <sstream>
-#include <vector>
-
-#include <boost/lexical_cast.hpp>
-
-#include <util/buffer.h>
-#include <util/encode/hex.h>
-
-#include <dns/messagerenderer.h>
-#include <dns/name.h>
-#include <dns/rdata.h>
-#include <dns/rdataclass.h>
-
-#include <stdio.h>
-#include <time.h>
-
-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<uint8_t>& digest) :
-        tag_(tag), algorithm_(algorithm), digest_type_(digest_type),
-        digest_(digest)
-    {}
-
-    uint16_t tag_;
-    uint8_t algorithm_;
-    uint8_t digest_type_;
-    const vector<uint8_t> 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<uint8_t> 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<uint8_t> 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<string>(static_cast<int>(impl_->tag_)) +
-        " " + lexical_cast<string>(static_cast<int>(impl_->algorithm_)) +
-        " " + lexical_cast<string>(static_cast<int>(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<const DS&>(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

+ 56 - 15
src/lib/dns/rdata/generic/ds_43.h

@@ -12,16 +12,29 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include <stdint.h>
+// BEGIN_HEADER_GUARD
 
+#include <iostream>
 #include <string>
+#include <sstream>
+#include <vector>
+
+#include <boost/lexical_cast.hpp>
 
+#include <util/buffer.h>
+#include <util/encode/hex.h>
+
+#include <dns/messagerenderer.h>
 #include <dns/name.h>
-#include <dns/rrtype.h>
-#include <dns/rrttl.h>
 #include <dns/rdata.h>
+#include <dns/rdataclass.h>
 
-// BEGIN_HEADER_GUARD
+#include <stdio.h>
+#include <time.h>
+
+using namespace std;
+using namespace isc::util;
+using namespace isc::util::encode;
 
 // BEGIN_ISC_NAMESPACE
 
@@ -30,23 +43,51 @@
 
 // BEGIN_RDATA_NAMESPACE
 
-struct DSImpl;
+#include <dns/rdata/generic/detail/ds_like.h>
+
+class DS : public DS_LIKE<DS, 43> {
+    friend class DS_LIKE<DS, 43>;
+    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<DS, 43>(type_str) {}
+
+///    DS(isc::util::InputBuffer& buffer, size_t rdata_len);
+inline DS::DS(isc::util::InputBuffer& buffer, size_t rdata_len) : DS_LIKE<DS, 43>(buffer, rdata_len) {}
+
+///    DS(const DS& other);
+inline DS::DS(const DS& other) : DS_LIKE<DS, 43>(other) {}
+
+///    virtual std::string toText() const;
+inline std::string DS::toText() const
+{
+    return DS_LIKE<DS, 43>::toText();
+}
+
+///    virtual void toWire(isc::util::OutputBuffer& buffer) const;
+inline void DS::toWire(isc::util::OutputBuffer& buffer) const
+{
+    DS_LIKE<DS, 43>::toWire(buffer);
+}
+
+///    virtual void toWire(AbstractMessageRenderer& renderer) const;
+inline void DS::toWire(AbstractMessageRenderer& renderer) const
+{
+    DS_LIKE<DS, 43>::toWire(renderer);
+}
+
+///    virtual int compare(const Rdata& other) const;
+inline int DS::compare(const Rdata& other) const
+{
+    return DS_LIKE<DS, 43>::compare(other);
+}
+
 // END_RDATA_NAMESPACE
 // END_ISC_NAMESPACE
 // END_HEADER_GUARD