Commit acb5dff4 authored by Dima Volodin's avatar Dima Volodin
Browse files

[1140] TXT&SPF re-done to isolate the implementation details in

       txt_like.h from rdataclass.h using private pointers
parent 69eb1a25
......@@ -50,7 +50,9 @@ EXTRA_DIST += rdata/generic/rrsig_46.cc
EXTRA_DIST += rdata/generic/rrsig_46.h
EXTRA_DIST += rdata/generic/soa_6.cc
EXTRA_DIST += rdata/generic/soa_6.h
EXTRA_DIST += rdata/generic/spf_99.cc
EXTRA_DIST += rdata/generic/spf_99.h
EXTRA_DIST += rdata/generic/txt_16.cc
EXTRA_DIST += rdata/generic/txt_16.h
EXTRA_DIST += rdata/hs_4/a_1.cc
EXTRA_DIST += rdata/hs_4/a_1.h
......
......@@ -23,24 +23,22 @@
using namespace std;
using namespace isc::util;
template<uint16_t typeCode>class TXT_LIKE : public Rdata {
template<class Type, uint16_t typeCode>class TXTLikeImpl {
public:
TXT_LIKE(InputBuffer& buffer, size_t rdata_len) {
TXTLikeImpl(InputBuffer& buffer, size_t rdata_len) {
if (rdata_len > MAX_RDLENGTH) {
isc_throw(InvalidRdataLength, "RDLENGTH too large: " << rdata_len);
}
if (rdata_len == 0) { // note that this couldn't happen in the loop.
isc_throw(DNSMessageFORMERR, "Error in parsing " +
RRParamRegistry::getRegistry().codeToTypeText(typeCode) +
isc_throw(DNSMessageFORMERR, "Error in parsing " << RRType(typeCode) <<
" RDATA: 0-length character string");
}
do {
const uint8_t len = buffer.readUint8();
if (rdata_len < len + 1) {
isc_throw(DNSMessageFORMERR, "Error in parsing " +
RRParamRegistry::getRegistry().codeToTypeText(typeCode) +
isc_throw(DNSMessageFORMERR, "Error in parsing " << RRType(typeCode) <<
" RDATA: character string length is too large: " << static_cast<int>(len));
}
vector<uint8_t> data(len + 1);
......@@ -52,7 +50,7 @@ public:
} while (rdata_len > 0);
}
explicit TXT_LIKE(const std::string& txtstr) {
explicit TXTLikeImpl(const std::string& txtstr) {
// TBD: this is a simple, incomplete implementation that only supports
// a single character-string.
......@@ -65,13 +63,13 @@ public:
}
if (length > MAX_CHARSTRING_LEN) {
isc_throw(CharStringTooLong, RRParamRegistry::getRegistry().codeToTypeText(typeCode)
+ " RDATA construction from text: string length is too long: " << length);
isc_throw(CharStringTooLong, RRType(typeCode) <<
" RDATA construction from text: string length is too long: " << length);
}
// TBD: right now, we don't support escaped characters
if (txtstr.find('\\') != string::npos) {
isc_throw(InvalidRdataText, RRParamRegistry::getRegistry().codeToTypeText(typeCode) +
isc_throw(InvalidRdataText, RRType(typeCode) <<
" RDATA from text: escaped character is currently not supported: " << txtstr);
}
......@@ -83,8 +81,8 @@ public:
string_list_.push_back(data);
}
TXT_LIKE(const TXT_LIKE& other) :
Rdata(), string_list_(other.string_list_)
TXTLikeImpl(const TXTLikeImpl& other) :
string_list_(other.string_list_)
{}
void
......@@ -129,16 +127,14 @@ public:
}
int
compare(const Rdata& other) const {
const TXT_LIKE& other_txt = dynamic_cast<const TXT_LIKE&>(other);
compare(const TXTLikeImpl& other) const {
// This implementation is not efficient. Revisit this (TBD).
OutputBuffer this_buffer(0);
toWire(this_buffer);
size_t this_len = this_buffer.getLength();
OutputBuffer other_buffer(0);
other_txt.toWire(other_buffer);
other.toWire(other_buffer);
const size_t other_len = other_buffer.getLength();
const size_t cmplen = min(this_len, other_len);
......
// 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 <stdint.h>
#include <string.h>
#include <string>
#include <vector>
#include <util/buffer.h>
#include <dns/exceptions.h>
#include <dns/messagerenderer.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
using namespace std;
using namespace isc::util;
// BEGIN_ISC_NAMESPACE
// BEGIN_RDATA_NAMESPACE
#include <dns/rdata/generic/detail/txt_like.h>
SPF&
SPF::operator=(const SPF& source) {
if (impl_ == source.impl_) {
return (*this);
}
SPFImpl* newimpl = new SPFImpl(*source.impl_);
delete impl_;
impl_ = newimpl;
return (*this);
}
SPF::~SPF() {
delete impl_;
}
SPF::SPF(InputBuffer& buffer, size_t rdata_len) :
impl_(new SPFImpl(buffer, rdata_len))
{}
SPF::SPF(const std::string& txtstr) :
impl_(new SPFImpl(txtstr))
{}
SPF::SPF(const SPF& other) :
Rdata(), impl_(new SPFImpl(*other.impl_))
{}
void
SPF::toWire(OutputBuffer& buffer) const {
impl_->toWire(buffer);
}
void
SPF::toWire(AbstractMessageRenderer& renderer) const {
impl_->toWire(renderer);
}
string
SPF::toText() const {
return (impl_->toText());
}
int
SPF::compare(const Rdata& other) const {
const SPF& other_txt = dynamic_cast<const SPF&>(other);
return (impl_->compare(*other_txt.impl_));
}
// END_RDATA_NAMESPACE
// END_ISC_NAMESPACE
......@@ -14,16 +14,13 @@
// BEGIN_HEADER_GUARD
#include <stdint.h>
#include <string>
#include <vector>
#include <dns/name.h>
#include <dns/rdata.h>
#include <util/buffer.h>
#include <dns/exceptions.h>
#include <dns/messagerenderer.h>
#include <dns/rrparamregistry.h>
// BEGIN_ISC_NAMESPACE
// BEGIN_COMMON_DECLARATIONS
......@@ -31,9 +28,20 @@
// BEGIN_RDATA_NAMESPACE
#include <dns/rdata/generic/detail/txt_like.h>
template<class Type, uint16_t typeCode> class TXTLikeImpl;
class SPF : public Rdata {
public:
// BEGIN_COMMON_MEMBERS
// END_COMMON_MEMBERS
SPF& operator=(const SPF& source);
~SPF();
typedef TXT_LIKE<99> SPF;
private:
typedef TXTLikeImpl<SPF, 16> SPFImpl;
SPFImpl* impl_;
};
// END_RDATA_NAMESPACE
// END_ISC_NAMESPACE
......
// 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 <stdint.h>
#include <string.h>
#include <string>
#include <vector>
#include <util/buffer.h>
#include <dns/exceptions.h>
#include <dns/messagerenderer.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
using namespace std;
using namespace isc::util;
// BEGIN_ISC_NAMESPACE
// BEGIN_RDATA_NAMESPACE
#include <dns/rdata/generic/detail/txt_like.h>
TXT&
TXT::operator=(const TXT& source) {
if (impl_ == source.impl_) {
return (*this);
}
TXTImpl* newimpl = new TXTImpl(*source.impl_);
delete impl_;
impl_ = newimpl;
return (*this);
}
TXT::~TXT() {
delete impl_;
}
TXT::TXT(InputBuffer& buffer, size_t rdata_len) :
impl_(new TXTImpl(buffer, rdata_len))
{}
TXT::TXT(const std::string& txtstr) :
impl_(new TXTImpl(txtstr))
{}
TXT::TXT(const TXT& other) :
Rdata(), impl_(new TXTImpl(*other.impl_))
{}
void
TXT::toWire(OutputBuffer& buffer) const {
impl_->toWire(buffer);
}
void
TXT::toWire(AbstractMessageRenderer& renderer) const {
impl_->toWire(renderer);
}
string
TXT::toText() const {
return (impl_->toText());
}
int
TXT::compare(const Rdata& other) const {
const TXT& other_txt = dynamic_cast<const TXT&>(other);
return (impl_->compare(*other_txt.impl_));
}
// END_RDATA_NAMESPACE
// END_ISC_NAMESPACE
......@@ -14,16 +14,13 @@
// BEGIN_HEADER_GUARD
#include <stdint.h>
#include <string>
#include <vector>
#include <dns/name.h>
#include <dns/rdata.h>
#include <util/buffer.h>
#include <dns/exceptions.h>
#include <dns/messagerenderer.h>
#include <dns/rrparamregistry.h>
// BEGIN_ISC_NAMESPACE
// BEGIN_COMMON_DECLARATIONS
......@@ -31,9 +28,20 @@
// BEGIN_RDATA_NAMESPACE
#include <dns/rdata/generic/detail/txt_like.h>
template<class Type, uint16_t typeCode> class TXTLikeImpl;
class TXT : public Rdata {
public:
// BEGIN_COMMON_MEMBERS
// END_COMMON_MEMBERS
TXT& operator=(const TXT& source);
~TXT();
typedef TXT_LIKE<16> TXT;
private:
typedef TXTLikeImpl<TXT, 16> TXTImpl;
TXTImpl* impl_;
};
// END_RDATA_NAMESPACE
// END_ISC_NAMESPACE
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment