BIND 10 master, updated. 83d31781cfeb717a84e916b1a08522664dd7b590 Merge branch 'master' into trac1774
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jun 28 03:27:16 UTC 2012
The branch, master has been updated
via 83d31781cfeb717a84e916b1a08522664dd7b590 (commit)
via 3dab9ab4947300e8d5b9cf8d4544d9491c65038c (commit)
via 8acfde4201f10d86ee53d2c60701b222896fe088 (commit)
via b574c191d04f51d21c97979546c5641582d1bdf5 (commit)
via 24c9af463a1087f54918f6e1206f72b50b43d9bf (commit)
via bf0f1e06d99d7f4fc36a0eb53e1bf8420e86bb35 (commit)
via 846dbfde91d54302568407175b54bc3cfb0f6bae (commit)
via 31ee75a034bad0d43d30368fa1ed7a3643aea402 (commit)
via de9c0a0b8ce9eb7b7aa7319aef68a209f27f1421 (commit)
from 2498f05b7afa17431e9f3f4d6109e995fbec6514 (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 83d31781cfeb717a84e916b1a08522664dd7b590
Merge: 3dab9ab 2498f05
Author: Mukund Sivaraman <muks at isc.org>
Date: Thu Jun 28 08:40:31 2012 +0530
Merge branch 'master' into trac1774
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/labelsequence.cc | 16 +++++-----
src/lib/dns/labelsequence.h | 2 +-
src/lib/dns/messagerenderer.cc | 6 ++--
src/lib/dns/name.cc | 32 +++++++++----------
src/lib/dns/name.h | 9 ++++--
src/lib/dns/name_internal.h | 2 +-
src/lib/dns/tests/labelsequence_unittest.cc | 46 +++++++++++++++++++++------
7 files changed, 73 insertions(+), 40 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/labelsequence.cc b/src/lib/dns/labelsequence.cc
index 71e0f82..d6521e0 100644
--- a/src/lib/dns/labelsequence.cc
+++ b/src/lib/dns/labelsequence.cc
@@ -23,7 +23,7 @@
namespace isc {
namespace dns {
-const char*
+const uint8_t*
LabelSequence::getData(size_t *len) const {
*len = getDataLength();
return (&name_.ndata_[name_.offsets_[first_label_]]);
@@ -47,22 +47,22 @@ LabelSequence::getDataLength() const {
bool
LabelSequence::equals(const LabelSequence& other, bool case_sensitive) const {
size_t len, other_len;
- const char* data = getData(&len);
- const char* other_data = other.getData(&other_len);
+ const uint8_t* data = getData(&len);
+ const uint8_t* other_data = other.getData(&other_len);
if (len != other_len) {
return (false);
}
if (case_sensitive) {
- return (std::strncmp(data, other_data, len) == 0);
+ return (std::memcmp(data, other_data, len) == 0);
}
// As long as the data was originally validated as (part of) a name,
// label length must never be a capital ascii character, so we can
// simply compare them after converting to lower characters.
for (size_t i = 0; i < len; ++i) {
- const unsigned char ch = data[i];
- const unsigned char other_ch = other_data[i];
+ const uint8_t ch = data[i];
+ const uint8_t other_ch = other_data[i];
if (isc::dns::name::internal::maptolower[ch] !=
isc::dns::name::internal::maptolower[other_ch]) {
return (false);
@@ -97,14 +97,14 @@ LabelSequence::isAbsolute() const {
size_t
LabelSequence::getHash(bool case_sensitive) const {
size_t length;
- const char* s = getData(&length);
+ const uint8_t* s = getData(&length);
if (length > 16) {
length = 16;
}
size_t hash_val = 0;
while (length > 0) {
- const unsigned char c = *s++;
+ const uint8_t c = *s++;
boost::hash_combine(hash_val, case_sensitive ? c :
isc::dns::name::internal::maptolower[c]);
--length;
diff --git a/src/lib/dns/labelsequence.h b/src/lib/dns/labelsequence.h
index b17eeb4..12fb4f4 100644
--- a/src/lib/dns/labelsequence.h
+++ b/src/lib/dns/labelsequence.h
@@ -67,7 +67,7 @@ public:
/// \param len Pointer to a size_t where the length of the data
/// will be stored (in number of octets)
/// \return Pointer to the wire-format data of this label sequence
- const char* getData(size_t* len) const;
+ const uint8_t* getData(size_t* len) const;
/// \brief Return the length of the wire-format data of this LabelSequence
///
diff --git a/src/lib/dns/messagerenderer.cc b/src/lib/dns/messagerenderer.cc
index d5c7c69..ca4ea54 100644
--- a/src/lib/dns/messagerenderer.cc
+++ b/src/lib/dns/messagerenderer.cc
@@ -100,8 +100,8 @@ struct NameCompare {
uint16_t item_label_len = 0;
for (size_t i = 0; i < item.len_; ++i, ++item_pos) {
item_pos = nextPosition(*buffer_, item_pos, item_label_len);
- const unsigned char ch1 = (*buffer_)[item_pos];
- const unsigned char ch2 = name_buf_->readUint8();
+ const uint8_t ch1 = (*buffer_)[item_pos];
+ const uint8_t ch2 = name_buf_->readUint8();
if (CASE_SENSITIVE) {
if (ch1 != ch2) {
return (false);
@@ -293,7 +293,7 @@ MessageRenderer::writeName(const Name& name, const bool compress) {
LabelSequence sequence(name);
const size_t nlabels = sequence.getLabelCount();
size_t data_len;
- const char* data;
+ const uint8_t* data;
// Find the offset in the offset table whose name gives the longest
// match against the name to be rendered.
diff --git a/src/lib/dns/name.cc b/src/lib/dns/name.cc
index d642e97..5630435 100644
--- a/src/lib/dns/name.cc
+++ b/src/lib/dns/name.cc
@@ -75,7 +75,7 @@ const char digitvalue[256] = {
namespace name {
namespace internal {
-const unsigned char maptolower[] = {
+const uint8_t maptolower[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
@@ -147,11 +147,11 @@ Name::Name(const std::string &namestring, bool downcase) {
bool is_root = false;
ft_state state = ft_init;
- std::vector<unsigned char> offsets;
+ NameOffsets offsets;
offsets.reserve(Name::MAX_LABELS);
offsets.push_back(0);
- std::string ndata;
+ NameString ndata;
ndata.reserve(Name::MAX_WIRE);
// should we refactor this code using, e.g, the state pattern? Probably
@@ -310,7 +310,7 @@ typedef enum {
}
Name::Name(InputBuffer& buffer, bool downcase) {
- std::vector<unsigned char> offsets;
+ NameOffsets offsets;
offsets.reserve(Name::MAX_LABELS);
/*
@@ -436,8 +436,8 @@ Name::toText(bool omit_final_dot) const {
return (".");
}
- std::string::const_iterator np = ndata_.begin();
- std::string::const_iterator np_end = ndata_.end();
+ NameString::const_iterator np = ndata_.begin();
+ NameString::const_iterator np_end = ndata_.end();
unsigned int labels = labelcount_; // use for integrity check
// init with an impossible value to catch error cases in the end:
unsigned int count = MAX_LABELLEN + 1;
@@ -467,7 +467,7 @@ Name::toText(bool omit_final_dot) const {
}
while (count-- > 0) {
- unsigned char c = *np++;
+ uint8_t c = *np++;
switch (c) {
case 0x22: // '"'
case 0x28: // '('
@@ -534,8 +534,8 @@ Name::compare(const Name& other) const {
unsigned int count = (cdiff < 0) ? count1 : count2;
while (count > 0) {
- unsigned char label1 = ndata_[pos1];
- unsigned char label2 = other.ndata_[pos2];
+ uint8_t label1 = ndata_[pos1];
+ uint8_t label2 = other.ndata_[pos2];
int chdiff = (int)maptolower[label1] - (int)maptolower[label2];
if (chdiff != 0) {
@@ -571,15 +571,15 @@ Name::equals(const Name& other) const {
}
for (unsigned int l = labelcount_, pos = 0; l > 0; --l) {
- unsigned char count = ndata_[pos];
+ uint8_t count = ndata_[pos];
if (count != other.ndata_[pos]) {
return (false);
}
++pos;
while (count-- > 0) {
- unsigned char label1 = ndata_[pos];
- unsigned char label2 = other.ndata_[pos];
+ uint8_t label1 = ndata_[pos];
+ uint8_t label2 = other.ndata_[pos];
if (maptolower[label1] != maptolower[label2]) {
return (false);
@@ -663,9 +663,9 @@ Name::reverse() const {
retname.ndata_.reserve(length_);
// Copy the original name, label by label, from tail to head.
- vector<unsigned char>::const_reverse_iterator rit0 = offsets_.rbegin();
- vector<unsigned char>::const_reverse_iterator rit1 = rit0 + 1;
- string::const_iterator n0 = ndata_.begin();
+ NameOffsets::const_reverse_iterator rit0 = offsets_.rbegin();
+ NameOffsets::const_reverse_iterator rit1 = rit0 + 1;
+ NameString::const_iterator n0 = ndata_.begin();
retname.offsets_.push_back(0);
while (rit1 != offsets_.rend()) {
retname.ndata_.append(n0 + *rit1, n0 + *rit0);
@@ -746,7 +746,7 @@ Name::downcase() {
while (count > 0) {
ndata_.at(pos) =
- maptolower[static_cast<unsigned char>(ndata_.at(pos))];
+ maptolower[ndata_.at(pos)];
++pos;
--nlen;
--count;
diff --git a/src/lib/dns/name.h b/src/lib/dns/name.h
index ef32f90..41024fc 100644
--- a/src/lib/dns/name.h
+++ b/src/lib/dns/name.h
@@ -229,6 +229,11 @@ class Name {
///
//@{
private:
+ /// \brief Name data string
+ typedef std::basic_string<uint8_t> NameString;
+ /// \brief Name offsets type
+ typedef std::vector<uint8_t> NameOffsets;
+
/// The default constructor
///
/// This is used internally in the class implementation, but at least at
@@ -679,8 +684,8 @@ public:
//@}
private:
- std::string ndata_;
- std::vector<unsigned char> offsets_;
+ NameString ndata_;
+ NameOffsets offsets_;
unsigned int length_;
unsigned int labelcount_;
};
diff --git a/src/lib/dns/name_internal.h b/src/lib/dns/name_internal.h
index e1eab8c..8595df1 100644
--- a/src/lib/dns/name_internal.h
+++ b/src/lib/dns/name_internal.h
@@ -31,7 +31,7 @@ namespace isc {
namespace dns {
namespace name {
namespace internal {
-extern const unsigned char maptolower[];
+extern const uint8_t maptolower[];
} // end of internal
} // end of name
} // end of dns
diff --git a/src/lib/dns/tests/labelsequence_unittest.cc b/src/lib/dns/tests/labelsequence_unittest.cc
index 98bb99c..0e1fd5e 100644
--- a/src/lib/dns/tests/labelsequence_unittest.cc
+++ b/src/lib/dns/tests/labelsequence_unittest.cc
@@ -34,14 +34,21 @@ public:
n3("example.org"), n4("foo.bar.test.example"),
n5("example.ORG"), n6("ExAmPlE.org"),
n7("."), n8("foo.example.org.bar"),
+ n9("\\000xample.org"),
+ n10("\\000xample.org"),
+ n11("\\000xample.com"),
+ n12("\\000xamplE.com"),
ls1(n1), ls2(n2), ls3(n3), ls4(n4), ls5(n5),
- ls6(n6), ls7(n7), ls8(n8)
+ ls6(n6), ls7(n7), ls8(n8),
+ ls9(n9), ls10(n10), ls11(n11), ls12(n12)
{};
// Need to keep names in scope for at least the lifetime of
// the labelsequences
Name n1, n2, n3, n4, n5, n6, n7, n8;
+ Name n9, n10, n11, n12;
LabelSequence ls1, ls2, ls3, ls4, ls5, ls6, ls7, ls8;
+ LabelSequence ls9, ls10, ls11, ls12;
};
// Basic equality tests
@@ -81,6 +88,11 @@ TEST_F(LabelSequenceTest, equals_sensitive) {
EXPECT_FALSE(ls5.equals(ls6, true));
EXPECT_FALSE(ls5.equals(ls7, true));
EXPECT_FALSE(ls5.equals(ls8, true));
+
+ EXPECT_TRUE(ls9.equals(ls10, true));
+ EXPECT_FALSE(ls9.equals(ls11, true));
+ EXPECT_FALSE(ls9.equals(ls12, true));
+ EXPECT_FALSE(ls11.equals(ls12, true));
}
TEST_F(LabelSequenceTest, equals_insensitive) {
@@ -123,28 +135,44 @@ TEST_F(LabelSequenceTest, equals_insensitive) {
EXPECT_TRUE(ls5.equals(ls5));
EXPECT_TRUE(ls5.equals(ls6));
EXPECT_FALSE(ls5.equals(ls7));
+
+ EXPECT_TRUE(ls9.equals(ls10));
+ EXPECT_FALSE(ls9.equals(ls11));
+ EXPECT_FALSE(ls9.equals(ls12));
+ EXPECT_TRUE(ls11.equals(ls12));
}
void
-getDataCheck(const char* expected_data, size_t expected_len,
+getDataCheck(const uint8_t* expected_data, size_t expected_len,
const LabelSequence& ls)
{
size_t len;
- const char* data = ls.getData(&len);
+ const uint8_t* data = ls.getData(&len);
ASSERT_EQ(expected_len, len) << "Expected data: " << expected_data <<
" name: " << ls.getName().toText();
EXPECT_EQ(expected_len, ls.getDataLength()) <<
"Expected data: " << expected_data <<
" name: " << ls.getName().toText();
for (size_t i = 0; i < len; ++i) {
- EXPECT_EQ(expected_data[i], data[i]) << "Difference at pos " << i <<
- ": Expected data: " <<
- expected_data <<
- " name: " <<
- ls.getName().toText();;
+ EXPECT_EQ(expected_data[i], data[i]) <<
+ "Difference at pos " << i << ": Expected data: " << expected_data <<
+ " name: " << ls.getName().toText();;
}
}
+// Convenient data converter for expected data. Label data must be of
+// uint8_t*, while it's convenient if we can specify some test data in
+// plain string (which is of char*). This wrapper converts the latter to
+// the former in a safer way.
+void
+getDataCheck(const char* expected_char_data, size_t expected_len,
+ const LabelSequence& ls)
+{
+ const vector<uint8_t> expected_data(expected_char_data,
+ expected_char_data + expected_len);
+ getDataCheck(&expected_data[0], expected_len, ls);
+}
+
TEST_F(LabelSequenceTest, getData) {
getDataCheck("\007example\003org\000", 13, ls1);
getDataCheck("\007example\003com\000", 13, ls2);
@@ -243,7 +271,7 @@ TEST_F(LabelSequenceTest, comparePart) {
// Data comparison
size_t len;
- const char* data = ls1.getData(&len);
+ const uint8_t* data = ls1.getData(&len);
getDataCheck(data, len, ls8);
}
More information about the bind10-changes
mailing list