BIND 10 master, updated. f7b5370a9bf82b0b480b75275349d8570ee83c4c [master] Merge trac1112 and update the ChangeLog
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Sep 21 03:07:56 UTC 2011
The branch, master has been updated
via f7b5370a9bf82b0b480b75275349d8570ee83c4c (commit)
via 12d62d54d33fbb1572a1aa3089b0d547d02924aa (commit)
via ee468e8f02f1cd1bcf09da75170ed62dc230b70e (commit)
via f0274b7451761b2dc48c0be148ecd8563c9800da (commit)
via 9f441d72a245e3ccce2ee014adaa0ad62e7b0d29 (commit)
via 88095bed9cbc3e39c61eb0ea7dee1646ff13ac7e (commit)
via b557ab47f3355f5fc7d4f87dfa9e4a15e7e9f3e3 (commit)
via 4e12574323ca3db3e985acee0540c603b2b33124 (commit)
via 3fc53ba91b92ad40ebbf46272f57a45e3d2e3a27 (commit)
via 5157876271e945703ee699f07442ee1a72bba362 (commit)
from c38112d8b59bfb6e73b5fbc637fa9eaaae42c52d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit f7b5370a9bf82b0b480b75275349d8570ee83c4c
Author: Ocean Wang <wanghaidong at cnnic.cn>
Date: Wed Sep 21 11:05:30 2011 +0800
[master] Merge trac1112 and update the ChangeLog
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 5 +
src/lib/dns/Makefile.am | 1 +
src/lib/dns/character_string.cc | 140 ++++++++++++++++++++
src/lib/dns/character_string.h | 57 ++++++++
src/lib/dns/rdata/generic/hinfo_13.cc | 129 ++++++++++++++++++
.../dns/rdata/generic/{naptr_35.h => hinfo_13.h} | 48 +++++---
src/lib/dns/rdata/generic/naptr_35.cc | 104 +--------------
src/lib/dns/rdata/generic/naptr_35.h | 20 +++
src/lib/dns/tests/Makefile.am | 2 +
src/lib/dns/tests/character_string_unittest.cc | 92 +++++++++++++
src/lib/dns/tests/rdata_hinfo_unittest.cc | 115 ++++++++++++++++
11 files changed, 597 insertions(+), 116 deletions(-)
create mode 100644 src/lib/dns/character_string.cc
create mode 100644 src/lib/dns/character_string.h
create mode 100644 src/lib/dns/rdata/generic/hinfo_13.cc
copy src/lib/dns/rdata/generic/{naptr_35.h => hinfo_13.h} (57%)
create mode 100644 src/lib/dns/tests/character_string_unittest.cc
create mode 100644 src/lib/dns/tests/rdata_hinfo_unittest.cc
-----------------------------------------------------------------------
diff --git a/ChangeLog b/ChangeLog
index a71c8a8..6f84a07 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+286. [func] ocean
+ libdns++: Implement the HINFO rrtype support according to RFC1034,
+ and RFC1035.
+ (Trac #1112, git 12d62d54d33fbb1572a1aa3089b0d547d02924aa)
+
285. [bug] jelte
sqlite3 data source: fixed a race condition on initial startup,
when the database has not been initialized yet, and multiple
diff --git a/src/lib/dns/Makefile.am b/src/lib/dns/Makefile.am
index 3a23e23..1827b70 100644
--- a/src/lib/dns/Makefile.am
+++ b/src/lib/dns/Makefile.am
@@ -101,6 +101,7 @@ libdns___la_SOURCES += tsig.h tsig.cc
libdns___la_SOURCES += tsigerror.h tsigerror.cc
libdns___la_SOURCES += tsigkey.h tsigkey.cc
libdns___la_SOURCES += tsigrecord.h tsigrecord.cc
+libdns___la_SOURCES += character_string.h character_string.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/txt_like.h
diff --git a/src/lib/dns/character_string.cc b/src/lib/dns/character_string.cc
new file mode 100644
index 0000000..3a289ac
--- /dev/null
+++ b/src/lib/dns/character_string.cc
@@ -0,0 +1,140 @@
+// 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.
+
+#include "character_string.h"
+#include "rdata.h"
+
+using namespace std;
+using namespace isc::dns::rdata;
+
+namespace isc {
+namespace dns {
+
+namespace {
+bool isDigit(char c) {
+ return (('0' <= c) && (c <= '9'));
+}
+}
+
+std::string
+characterstr::getNextCharacterString(const std::string& input_str,
+ std::string::const_iterator& input_iterator)
+{
+ string result;
+
+ // If the input string only contains white-spaces, it is an invalid
+ // <character-string>
+ if (input_iterator >= input_str.end()) {
+ isc_throw(InvalidRdataText, "Invalid text format, \
+ <character-string> field is missing.");
+ }
+
+ // Whether the <character-string> is separated with double quotes (")
+ bool quotes_separated = (*input_iterator == '"');
+ // Whether the quotes are pared if the string is quotes separated
+ bool quotes_paired = false;
+
+ if (quotes_separated) {
+ ++input_iterator;
+ }
+
+ while(input_iterator < input_str.end()){
+ // Escaped characters processing
+ if (*input_iterator == '\\') {
+ if (input_iterator + 1 == input_str.end()) {
+ isc_throw(InvalidRdataText, "<character-string> ended \
+ prematurely.");
+ } else {
+ if (isDigit(*(input_iterator + 1))) {
+ // \DDD where each D is a digit. It its the octet
+ // corresponding to the decimal number described by DDD
+ if (input_iterator + 3 >= input_str.end()) {
+ isc_throw(InvalidRdataText, "<character-string> ended \
+ prematurely.");
+ } else {
+ int n = 0;
+ ++input_iterator;
+ for (int i = 0; i < 3; ++i) {
+ if (isDigit(*input_iterator)) {
+ n = n*10 + (*input_iterator - '0');
+ ++input_iterator;
+ } else {
+ isc_throw(InvalidRdataText, "Illegal decimal \
+ escaping series");
+ }
+ }
+ if (n > 255) {
+ isc_throw(InvalidRdataText, "Illegal octet \
+ number");
+ }
+ result.push_back(n);
+ continue;
+ }
+ } else {
+ ++input_iterator;
+ result.push_back(*input_iterator);
+ ++input_iterator;
+ continue;
+ }
+ }
+ }
+
+ if (quotes_separated) {
+ // If the <character-string> is seperated with quotes symbol and
+ // another quotes symbol is encountered, it is the end of the
+ // <character-string>
+ if (*input_iterator == '"') {
+ quotes_paired = true;
+ ++input_iterator;
+ // Reach the end of character string
+ break;
+ }
+ } else if (*input_iterator == ' ') {
+ // If the <character-string> is not seperated with quotes symbol,
+ // it is seperated with <space> char
+ break;
+ }
+
+ result.push_back(*input_iterator);
+
+ ++input_iterator;
+ }
+
+ if (result.size() > MAX_CHARSTRING_LEN) {
+ isc_throw(CharStringTooLong, "<character-string> is too long");
+ }
+
+ if (quotes_separated && !quotes_paired) {
+ isc_throw(InvalidRdataText, "The quotes are not paired");
+ }
+
+ return (result);
+}
+
+std::string
+characterstr::getNextCharacterString(util::InputBuffer& buffer, size_t len) {
+ uint8_t str_len = buffer.readUint8();
+
+ size_t pos = buffer.getPosition();
+ if (len - pos < str_len) {
+ isc_throw(InvalidRdataLength, "Invalid string length");
+ }
+
+ uint8_t buf[MAX_CHARSTRING_LEN];
+ buffer.readData(buf, str_len);
+ return (string(buf, buf + str_len));
+}
+
+} // end of namespace dns
+} // end of namespace isc
diff --git a/src/lib/dns/character_string.h b/src/lib/dns/character_string.h
new file mode 100644
index 0000000..7961274
--- /dev/null
+++ b/src/lib/dns/character_string.h
@@ -0,0 +1,57 @@
+// 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 __CHARACTER_STRING_H
+#define __CHARACTER_STRING_H
+
+#include <string>
+#include <exceptions/exceptions.h>
+#include <util/buffer.h>
+
+namespace isc {
+namespace dns {
+
+// \brief Some utility functions to extract <character-string> from string
+// or InputBuffer
+//
+// <character-string> is expressed in one or two ways: as a contiguous set
+// of characters without interior spaces, or as a string beginning with a "
+// and ending with a ". Inside a " delimited string any character can
+// occur, except for a " itself, which must be quoted using \ (back slash).
+// Ref. RFC1035
+
+
+namespace characterstr {
+ /// Get a <character-string> from a string
+ ///
+ /// \param input_str The input string
+ /// \param input_iterator The iterator from which to start extracting,
+ /// the iterator will be updated to new position after the function
+ /// is returned
+ /// \return A std::string that contains the extracted <character-string>
+ std::string getNextCharacterString(const std::string& input_str,
+ std::string::const_iterator& input_iterator);
+
+ /// Get a <character-string> from a input buffer
+ ///
+ /// \param buffer The input buffer
+ /// \param len The input buffer total length
+ /// \return A std::string that contains the extracted <character-string>
+ std::string getNextCharacterString(util::InputBuffer& buffer, size_t len);
+
+} // namespace characterstr
+} // namespace dns
+} // namespace isc
+
+#endif // __CHARACTER_STRING_H
diff --git a/src/lib/dns/rdata/generic/hinfo_13.cc b/src/lib/dns/rdata/generic/hinfo_13.cc
new file mode 100644
index 0000000..45f4209
--- /dev/null
+++ b/src/lib/dns/rdata/generic/hinfo_13.cc
@@ -0,0 +1,129 @@
+// 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.
+
+#include <config.h>
+
+#include <string>
+
+#include <boost/lexical_cast.hpp>
+
+#include <exceptions/exceptions.h>
+
+#include <dns/name.h>
+#include <dns/messagerenderer.h>
+#include <dns/rdata.h>
+#include <dns/rdataclass.h>
+#include <dns/character_string.h>
+#include <util/strutil.h>
+
+using namespace std;
+using namespace boost;
+using namespace isc::util;
+using namespace isc::dns;
+using namespace isc::dns::characterstr;
+
+// BEGIN_ISC_NAMESPACE
+// BEGIN_RDATA_NAMESPACE
+
+
+HINFO::HINFO(const string& hinfo_str) {
+ string::const_iterator input_iterator = hinfo_str.begin();
+ cpu_ = getNextCharacterString(hinfo_str, input_iterator);
+
+ skipLeftSpaces(hinfo_str, input_iterator);
+
+ os_ = getNextCharacterString(hinfo_str, input_iterator);
+}
+
+HINFO::HINFO(InputBuffer& buffer, size_t rdata_len) {
+ cpu_ = getNextCharacterString(buffer, rdata_len);
+ os_ = getNextCharacterString(buffer, rdata_len);
+}
+
+HINFO::HINFO(const HINFO& source):
+ Rdata(), cpu_(source.cpu_), os_(source.os_)
+{
+}
+
+std::string
+HINFO::toText() const {
+ string result;
+ result += "\"";
+ result += cpu_;
+ result += "\" \"";
+ result += os_;
+ result += "\"";
+ return (result);
+}
+
+void
+HINFO::toWire(OutputBuffer& buffer) const {
+ toWireHelper(buffer);
+}
+
+void
+HINFO::toWire(AbstractMessageRenderer& renderer) const {
+ toWireHelper(renderer);
+}
+
+int
+HINFO::compare(const Rdata& other) const {
+ const HINFO& other_hinfo = dynamic_cast<const HINFO&>(other);
+
+ if (cpu_ < other_hinfo.cpu_) {
+ return (-1);
+ } else if (cpu_ > other_hinfo.cpu_) {
+ return (1);
+ }
+
+ if (os_ < other_hinfo.os_) {
+ return (-1);
+ } else if (os_ > other_hinfo.os_) {
+ return (1);
+ }
+
+ return (0);
+}
+
+const std::string&
+HINFO::getCPU() const {
+ return (cpu_);
+}
+
+const std::string&
+HINFO::getOS() const {
+ return (os_);
+}
+
+void
+HINFO::skipLeftSpaces(const std::string& input_str,
+ std::string::const_iterator& input_iterator)
+{
+ if (input_iterator >= input_str.end()) {
+ isc_throw(InvalidRdataText,
+ "Invalid HINFO text format, field is missing.");
+ }
+
+ if (!isspace(*input_iterator)) {
+ isc_throw(InvalidRdataText,
+ "Invalid HINFO text format, fields are not separated by space.");
+ }
+ // Skip white spaces
+ while (input_iterator < input_str.end() && isspace(*input_iterator)) {
+ ++input_iterator;
+ }
+}
+
+// END_RDATA_NAMESPACE
+// END_ISC_NAMESPACE
diff --git a/src/lib/dns/rdata/generic/hinfo_13.h b/src/lib/dns/rdata/generic/hinfo_13.h
new file mode 100644
index 0000000..8513419
--- /dev/null
+++ b/src/lib/dns/rdata/generic/hinfo_13.h
@@ -0,0 +1,77 @@
+// 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.
+
+// BEGIN_HEADER_GUARD
+#include <stdint.h>
+
+#include <string>
+
+#include <dns/name.h>
+#include <dns/rdata.h>
+#include <util/buffer.h>
+
+// BEGIN_ISC_NAMESPACE
+
+// BEGIN_COMMON_DECLARATIONS
+// END_COMMON_DECLARATIONS
+
+// BEGIN_RDATA_NAMESPACE
+
+/// \brief \c HINFO class represents the HINFO rdata defined in
+/// RFC1034, RFC1035
+///
+/// This class implements the basic interfaces inherited from the
+/// \c rdata::Rdata class, and provides accessors specific to the
+/// HINFO rdata.
+class HINFO : public Rdata {
+public:
+ // BEGIN_COMMON_MEMBERS
+ // END_COMMON_MEMBERS
+
+ // HINFO specific methods
+ const std::string& getCPU() const;
+ const std::string& getOS() const;
+
+private:
+ /// Skip the left whitespaces of the input string
+ ///
+ /// \param input_str The input string
+ /// \param input_iterator From which the skipping started
+ void skipLeftSpaces(const std::string& input_str,
+ std::string::const_iterator& input_iterator);
+
+ /// Helper template function for toWire()
+ ///
+ /// \param outputer Where to write data in
+ template <typename T>
+ void toWireHelper(T& outputer) const {
+ outputer.writeUint8(cpu_.size());
+ outputer.writeData(cpu_.c_str(), cpu_.size());
+
+ outputer.writeUint8(os_.size());
+ outputer.writeData(os_.c_str(), os_.size());
+ }
+
+ std::string cpu_;
+ std::string os_;
+};
+
+
+// END_RDATA_NAMESPACE
+// END_ISC_NAMESPACE
+// END_HEADER_GUARD
+
+// Local Variables:
+// mode: c++
+// End:
diff --git a/src/lib/dns/rdata/generic/naptr_35.cc b/src/lib/dns/rdata/generic/naptr_35.cc
index 5268331..129bf6c 100644
--- a/src/lib/dns/rdata/generic/naptr_35.cc
+++ b/src/lib/dns/rdata/generic/naptr_35.cc
@@ -20,6 +20,7 @@
#include <exceptions/exceptions.h>
+#include <dns/character_string.h>
#include <dns/name.h>
#include <dns/messagerenderer.h>
#include <dns/rdata.h>
@@ -28,6 +29,8 @@
using namespace std;
using namespace boost;
using namespace isc::util;
+using namespace isc::dns;
+using namespace isc::dns::characterstr;
// BEGIN_ISC_NAMESPACE
// BEGIN_RDATA_NAMESPACE
@@ -56,79 +59,6 @@ skipLeftSpaces(const std::string& input_str,
}
}
-/// Get a <character-string> from a string
-///
-/// \param input_str The input string
-/// \param input_iterator The iterator from which to start extracting,
-/// the iterator will be updated to new position after the function
-/// is returned
-/// \return A std::string that contains the extracted <character-string>
-std::string
-getNextCharacterString(const std::string& input_str,
- std::string::const_iterator& input_iterator)
-{
- string result;
-
- // If the input string only contains white-spaces, it is an invalid
- // <character-string>
- if (input_iterator >= input_str.end()) {
- isc_throw(InvalidRdataText, "Invalid NAPTR text format, \
- <character-string> field is missing.");
- }
-
- // Whether the <character-string> is separated with double quotes (")
- bool quotes_separated = (*input_iterator == '"');
-
- if (quotes_separated) {
- ++input_iterator;
- }
-
- while(input_iterator < input_str.end()){
- if (quotes_separated) {
- // If the <character-string> is seperated with quotes symbol and
- // another quotes symbol is encountered, it is the end of the
- // <character-string>
- if (*input_iterator == '"') {
- ++input_iterator;
- break;
- }
- } else if (*input_iterator == ' ') {
- // If the <character-string> is not seperated with quotes symbol,
- // it is seperated with <space> char
- break;
- }
-
- result.push_back(*input_iterator);
-
- ++input_iterator;
- }
-
- if (result.size() > MAX_CHARSTRING_LEN) {
- isc_throw(CharStringTooLong, "NAPTR <character-string> is too long");
- }
-
- return (result);
-}
-
-/// Get a <character-string> from a input buffer
-///
-/// \param buffer The input buffer
-/// \param len The input buffer total length
-/// \return A std::string that contains the extracted <character-string>
-std::string
-getNextCharacterString(InputBuffer& buffer, size_t len) {
- uint8_t str_len = buffer.readUint8();
-
- size_t pos = buffer.getPosition();
- if (len - pos < str_len) {
- isc_throw(InvalidRdataLength, "Invalid NAPTR string length");
- }
-
- uint8_t buf[MAX_CHARSTRING_LEN];
- buffer.readData(buf, str_len);
- return (string(buf, buf + str_len));
-}
-
} // Anonymous namespace
NAPTR::NAPTR(InputBuffer& buffer, size_t len):
@@ -194,36 +124,12 @@ NAPTR::NAPTR(const NAPTR& naptr):
void
NAPTR::toWire(OutputBuffer& buffer) const {
- buffer.writeUint16(order_);
- buffer.writeUint16(preference_);
-
- buffer.writeUint8(flags_.size());
- buffer.writeData(flags_.c_str(), flags_.size());
-
- buffer.writeUint8(services_.size());
- buffer.writeData(services_.c_str(), services_.size());
-
- buffer.writeUint8(regexp_.size());
- buffer.writeData(regexp_.c_str(), regexp_.size());
-
- replacement_.toWire(buffer);
+ toWireHelper(buffer);
}
void
NAPTR::toWire(AbstractMessageRenderer& renderer) const {
- renderer.writeUint16(order_);
- renderer.writeUint16(preference_);
-
- renderer.writeUint8(flags_.size());
- renderer.writeData(flags_.c_str(), flags_.size());
-
- renderer.writeUint8(services_.size());
- renderer.writeData(services_.c_str(), services_.size());
-
- renderer.writeUint8(regexp_.size());
- renderer.writeData(regexp_.c_str(), regexp_.size());
-
- replacement_.toWire(renderer);
+ toWireHelper(renderer);
}
string
diff --git a/src/lib/dns/rdata/generic/naptr_35.h b/src/lib/dns/rdata/generic/naptr_35.h
index b3015ae..ca16b3c 100644
--- a/src/lib/dns/rdata/generic/naptr_35.h
+++ b/src/lib/dns/rdata/generic/naptr_35.h
@@ -46,6 +46,26 @@ public:
const std::string& getRegexp() const;
const Name& getReplacement() const;
private:
+ /// Helper template function for toWire()
+ ///
+ /// \param outputer Where to write data in
+ template <typename T>
+ void toWireHelper(T& outputer) const {
+ outputer.writeUint16(order_);
+ outputer.writeUint16(preference_);
+
+ outputer.writeUint8(flags_.size());
+ outputer.writeData(flags_.c_str(), flags_.size());
+
+ outputer.writeUint8(services_.size());
+ outputer.writeData(services_.c_str(), services_.size());
+
+ outputer.writeUint8(regexp_.size());
+ outputer.writeData(regexp_.c_str(), regexp_.size());
+
+ replacement_.toWire(outputer);
+ }
+
uint16_t order_;
uint16_t preference_;
std::string flags_;
diff --git a/src/lib/dns/tests/Makefile.am b/src/lib/dns/tests/Makefile.am
index 48bce85..5f90cea 100644
--- a/src/lib/dns/tests/Makefile.am
+++ b/src/lib/dns/tests/Makefile.am
@@ -46,6 +46,7 @@ run_unittests_SOURCES += rdata_srv_unittest.cc
run_unittests_SOURCES += rdata_minfo_unittest.cc
run_unittests_SOURCES += rdata_tsig_unittest.cc
run_unittests_SOURCES += rdata_naptr_unittest.cc
+run_unittests_SOURCES += rdata_hinfo_unittest.cc
run_unittests_SOURCES += rrset_unittest.cc rrsetlist_unittest.cc
run_unittests_SOURCES += question_unittest.cc
run_unittests_SOURCES += rrparamregistry_unittest.cc
@@ -55,6 +56,7 @@ run_unittests_SOURCES += tsig_unittest.cc
run_unittests_SOURCES += tsigerror_unittest.cc
run_unittests_SOURCES += tsigkey_unittest.cc
run_unittests_SOURCES += tsigrecord_unittest.cc
+run_unittests_SOURCES += character_string_unittest.cc
run_unittests_SOURCES += run_unittests.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
# We shouldn't need to include BOTAN_LDFLAGS here, but there
diff --git a/src/lib/dns/tests/character_string_unittest.cc b/src/lib/dns/tests/character_string_unittest.cc
new file mode 100644
index 0000000..5fed9eb
--- /dev/null
+++ b/src/lib/dns/tests/character_string_unittest.cc
@@ -0,0 +1,92 @@
+// 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.
+
+
+#include <gtest/gtest.h>
+
+#include <dns/rdata.h>
+#include <dns/tests/unittest_util.h>
+#include <dns/character_string.h>
+
+using isc::UnitTestUtil;
+
+using namespace std;
+using namespace isc;
+using namespace isc::dns;
+using namespace isc::dns::characterstr;
+using namespace isc::dns::rdata;
+
+namespace {
+
+class CharacterString {
+public:
+ CharacterString(const string& str){
+ string::const_iterator it = str.begin();
+ characterStr_ = getNextCharacterString(str, it);
+ }
+ const string& str() const { return characterStr_; }
+private:
+ string characterStr_;
+};
+
+TEST(CharacterStringTest, testNormalCase) {
+ CharacterString cstr1("foo");
+ EXPECT_EQ(string("foo"), cstr1.str());
+
+ // Test <character-string> that separated by space
+ CharacterString cstr2("foo bar");
+ EXPECT_EQ(string("foo"), cstr2.str());
+
+ // Test <character-string> that separated by quotes
+ CharacterString cstr3("\"foo bar\"");
+ EXPECT_EQ(string("foo bar"), cstr3.str());
+
+ // Test <character-string> that not separate by quotes but ended with quotes
+ CharacterString cstr4("foo\"");
+ EXPECT_EQ(string("foo\""), cstr4.str());
+}
+
+TEST(CharacterStringTest, testBadCase) {
+ // The <character-string> that started with quotes should also be ended
+ // with quotes
+ EXPECT_THROW(CharacterString cstr("\"foo"), InvalidRdataText);
+
+ // The string length cannot exceed 255 characters
+ string str;
+ for (int i = 0; i < 257; ++i) {
+ str += 'A';
+ }
+ EXPECT_THROW(CharacterString cstr(str), CharStringTooLong);
+}
+
+TEST(CharacterStringTest, testEscapeCharacter) {
+ CharacterString cstr1("foo\\bar");
+ EXPECT_EQ(string("foobar"), cstr1.str());
+
+ CharacterString cstr2("foo\\\\bar");
+ EXPECT_EQ(string("foo\\bar"), cstr2.str());
+
+ CharacterString cstr3("fo\\111bar");
+ EXPECT_EQ(string("foobar"), cstr3.str());
+
+ CharacterString cstr4("fo\\1112bar");
+ EXPECT_EQ(string("foo2bar"), cstr4.str());
+
+ // There must be at least 3 digits followed by '\'
+ EXPECT_THROW(CharacterString cstr("foo\\98ar"), InvalidRdataText);
+ EXPECT_THROW(CharacterString cstr("foo\\9ar"), InvalidRdataText);
+ EXPECT_THROW(CharacterString cstr("foo\\98"), InvalidRdataText);
+}
+
+} // namespace
diff --git a/src/lib/dns/tests/rdata_hinfo_unittest.cc b/src/lib/dns/tests/rdata_hinfo_unittest.cc
new file mode 100644
index 0000000..c52b2a0
--- /dev/null
+++ b/src/lib/dns/tests/rdata_hinfo_unittest.cc
@@ -0,0 +1,115 @@
+// 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.
+
+#include <util/buffer.h>
+#include <dns/exceptions.h>
+#include <dns/messagerenderer.h>
+#include <dns/rdata.h>
+#include <dns/rdataclass.h>
+#include <dns/rrclass.h>
+#include <dns/rrtype.h>
+
+#include <gtest/gtest.h>
+
+#include <dns/tests/unittest_util.h>
+#include <dns/tests/rdata_unittest.h>
+
+using isc::UnitTestUtil;
+using namespace std;
+using namespace isc::dns;
+using namespace isc::util;
+using namespace isc::dns::rdata;
+using namespace isc::dns::rdata::generic;
+
+namespace {
+class Rdata_HINFO_Test : public RdataTest {
+};
+
+static uint8_t hinfo_rdata[] = {0x07,0x50,0x65,0x6e,0x74,0x69,0x75,0x6d,0x05,
+ 0x4c,0x69,0x6e,0x75,0x78};
+static const char *hinfo_str = "\"Pentium\" \"Linux\"";
+static const char *hinfo_str1 = "\"Pen\\\"tium\" \"Linux\"";
+
+static const char *hinfo_str_small1 = "\"Lentium\" \"Linux\"";
+static const char *hinfo_str_small2 = "\"Pentium\" \"Kinux\"";
+static const char *hinfo_str_large1 = "\"Qentium\" \"Linux\"";
+static const char *hinfo_str_large2 = "\"Pentium\" \"UNIX\"";
+
+TEST_F(Rdata_HINFO_Test, createFromText) {
+ HINFO hinfo(hinfo_str);
+ EXPECT_EQ(string("Pentium"), hinfo.getCPU());
+ EXPECT_EQ(string("Linux"), hinfo.getOS());
+
+ // Test the text with double quotes in the middle of string
+ HINFO hinfo1(hinfo_str1);
+ EXPECT_EQ(string("Pen\"tium"), hinfo1.getCPU());
+}
+
+TEST_F(Rdata_HINFO_Test, badText) {
+ // Fields must be seperated by spaces
+ EXPECT_THROW(const HINFO hinfo("\"Pentium\"\"Linux\""), InvalidRdataText);
+ // Field cannot be missing
+ EXPECT_THROW(const HINFO hinfo("Pentium"), InvalidRdataText);
+ // The <character-string> cannot exceed 255 characters
+ string hinfo_str;
+ for (int i = 0; i < 257; ++i) {
+ hinfo_str += 'A';
+ }
+ hinfo_str += " Linux";
+ EXPECT_THROW(const HINFO hinfo(hinfo_str), CharStringTooLong);
+}
+
+TEST_F(Rdata_HINFO_Test, createFromWire) {
+ InputBuffer input_buffer(hinfo_rdata, sizeof(hinfo_rdata));
+ HINFO hinfo(input_buffer, sizeof(hinfo_rdata));
+ EXPECT_EQ(string("Pentium"), hinfo.getCPU());
+ EXPECT_EQ(string("Linux"), hinfo.getOS());
+}
+
+TEST_F(Rdata_HINFO_Test, toText) {
+ HINFO hinfo(hinfo_str);
+ EXPECT_EQ(hinfo_str, hinfo.toText());
+}
+
+TEST_F(Rdata_HINFO_Test, toWire) {
+ HINFO hinfo(hinfo_str);
+ hinfo.toWire(obuffer);
+
+ EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, obuffer.getData(),
+ obuffer.getLength(), hinfo_rdata, sizeof(hinfo_rdata));
+}
+
+TEST_F(Rdata_HINFO_Test, toWireRenderer) {
+ HINFO hinfo(hinfo_str);
+
+ hinfo.toWire(renderer);
+ EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, obuffer.getData(),
+ obuffer.getLength(), hinfo_rdata, sizeof(hinfo_rdata));
+}
+
+TEST_F(Rdata_HINFO_Test, compare) {
+ HINFO hinfo(hinfo_str);
+ HINFO hinfo_small1(hinfo_str_small1);
+ HINFO hinfo_small2(hinfo_str_small2);
+ HINFO hinfo_large1(hinfo_str_large1);
+ HINFO hinfo_large2(hinfo_str_large2);
+
+ EXPECT_EQ(0, hinfo.compare(HINFO(hinfo_str)));
+ EXPECT_EQ(1, hinfo.compare(HINFO(hinfo_str_small1)));
+ EXPECT_EQ(1, hinfo.compare(HINFO(hinfo_str_small2)));
+ EXPECT_EQ(-1, hinfo.compare(HINFO(hinfo_str_large1)));
+ EXPECT_EQ(-1, hinfo.compare(HINFO(hinfo_str_large2)));
+}
+
+}
More information about the bind10-changes
mailing list