BIND 10 trac2535, updated. 27e7210b344cea5c7098bf233481d5f2bf7cac97 [2535] Use charStringToString() in TXTLike
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Dec 21 15:19:43 UTC 2012
The branch, trac2535 has been updated
via 27e7210b344cea5c7098bf233481d5f2bf7cac97 (commit)
via 230078e5f45f29fec72e35a77e2fd897fb6d3fb7 (commit)
via 77b42eabd7630b5ba7f5f9fa383de73e0e7fe49d (commit)
via 31a4bc5aacc85f79416c6c4da2e33e642077e9f9 (commit)
via 89f331dff577268f90d885dc871cd2a152940ef8 (commit)
via c6c569cae91e19aa6267081ef9926f52b87d903d (commit)
from 772ce4c2888583e2fe1e9959c705608f6d1b7e98 (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 27e7210b344cea5c7098bf233481d5f2bf7cac97
Author: Mukund Sivaraman <muks at isc.org>
Date: Fri Dec 21 11:57:04 2012 +0530
[2535] Use charStringToString() in TXTLike
commit 230078e5f45f29fec72e35a77e2fd897fb6d3fb7
Author: Mukund Sivaraman <muks at isc.org>
Date: Fri Dec 21 11:52:46 2012 +0530
[2535] Reindent code
commit 77b42eabd7630b5ba7f5f9fa383de73e0e7fe49d
Author: Mukund Sivaraman <muks at isc.org>
Date: Fri Dec 21 11:52:27 2012 +0530
[2535] Add charStringToString() to convert a CharString to a DNS textual representation
commit 31a4bc5aacc85f79416c6c4da2e33e642077e9f9
Author: Mukund Sivaraman <muks at isc.org>
Date: Fri Dec 21 10:40:07 2012 +0530
[2535] Add a ch variable to make code more readable
commit 89f331dff577268f90d885dc871cd2a152940ef8
Author: Mukund Sivaraman <muks at isc.org>
Date: Fri Dec 21 10:38:46 2012 +0530
[2535] Add comment about the \xxx escaped format
commit c6c569cae91e19aa6267081ef9926f52b87d903d
Author: Mukund Sivaraman <muks at isc.org>
Date: Fri Dec 21 10:37:18 2012 +0530
[2535] Replace 0x30 with '0' to make code more readable
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/rdata/generic/detail/char_string.cc | 23 +++++++++
src/lib/dns/rdata/generic/detail/char_string.h | 15 ++++++
src/lib/dns/rdata/generic/detail/txt_like.h | 21 +-------
src/lib/dns/tests/rdata_char_string_unittest.cc | 58 +++++++++++++++++++++++
4 files changed, 98 insertions(+), 19 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/rdata/generic/detail/char_string.cc b/src/lib/dns/rdata/generic/detail/char_string.cc
index fb4c9b4..dcee08a 100644
--- a/src/lib/dns/rdata/generic/detail/char_string.cc
+++ b/src/lib/dns/rdata/generic/detail/char_string.cc
@@ -91,6 +91,29 @@ strToCharString(const MasterToken::StringRegion& str_region,
result[0] = result.size() - 1;
}
+std::string
+charStringToString(const CharString& char_string) {
+ std::string s;
+ for (CharString::const_iterator it = char_string.begin() + 1;
+ it != char_string.end(); ++it) {
+ const uint8_t ch = *it;
+ if ((ch < 0x20) || (ch >= 0x7f)) {
+ // convert to escaped \xxx (decimal) format
+ s.push_back('\\');
+ s.push_back('0' + ((ch / 100) % 10));
+ s.push_back('0' + ((ch / 10) % 10));
+ s.push_back('0' + (ch % 10));
+ continue;
+ }
+ if ((ch == '"') || (ch == ';') || (ch == '\\')) {
+ s.push_back('\\');
+ }
+ s.push_back(ch);
+ }
+
+ return (s);
+}
+
} // end of detail
} // end of generic
} // end of rdata
diff --git a/src/lib/dns/rdata/generic/detail/char_string.h b/src/lib/dns/rdata/generic/detail/char_string.h
index 702af04..b369f40 100644
--- a/src/lib/dns/rdata/generic/detail/char_string.h
+++ b/src/lib/dns/rdata/generic/detail/char_string.h
@@ -17,6 +17,7 @@
#include <dns/master_lexer.h>
+#include <string>
#include <vector>
#include <stdint.h>
@@ -51,6 +52,20 @@ typedef std::vector<uint8_t> CharString;
void strToCharString(const MasterToken::StringRegion& str_region,
CharString& result);
+/// \brief Convert a CharString into a textual DNS character-string.
+///
+/// This method converts a binary 8-bit representation of a DNS
+/// character string into a textual string representation, escaping any
+/// special characters in the process. For example, characters like
+/// double-quotes, semi-colon and backspace are prefixed with backspace
+/// character, and characters not in the printable range of [0x20, 0x7e]
+/// (inclusive) are converted to the \xxx 3-digit decimal
+/// representation.
+///
+/// \param char_string The \c CharString to convert.
+/// \return A string representation of \c char_string.
+std::string charStringToString(const CharString& char_string);
+
} // namespace detail
} // namespace generic
} // namespace rdata
diff --git a/src/lib/dns/rdata/generic/detail/txt_like.h b/src/lib/dns/rdata/generic/detail/txt_like.h
index 5eac74f..12673ae 100644
--- a/src/lib/dns/rdata/generic/detail/txt_like.h
+++ b/src/lib/dns/rdata/generic/detail/txt_like.h
@@ -178,30 +178,13 @@ public:
std::string s;
for (std::vector<std::vector<uint8_t> >::const_iterator it =
- string_list_.begin();
- it != string_list_.end();
- ++it)
+ string_list_.begin(); it != string_list_.end(); ++it)
{
if (!s.empty()) {
s.push_back(' ');
}
s.push_back('"');
- for (std::vector<uint8_t>::const_iterator c_it =
- (*it).begin() + 1;
- c_it != (*it).end();
- ++c_it) {
- if ((*c_it < 0x20) || (*c_it >= 0x7f)) {
- s.push_back('\\');
- s.push_back(0x30 + ((*c_it / 100) % 10));
- s.push_back(0x30 + ((*c_it / 10) % 10));
- s.push_back(0x30 + (*c_it % 10));
- continue;
- }
- if ((*c_it == '"') || (*c_it == ';') || (*c_it == '\\')) {
- s.push_back('\\');
- }
- s.push_back(*c_it);
- }
+ s.append(charStringToString(*it));
s.push_back('"');
}
diff --git a/src/lib/dns/tests/rdata_char_string_unittest.cc b/src/lib/dns/tests/rdata_char_string_unittest.cc
index 9d23622..7526391 100644
--- a/src/lib/dns/tests/rdata_char_string_unittest.cc
+++ b/src/lib/dns/tests/rdata_char_string_unittest.cc
@@ -26,6 +26,7 @@ using namespace isc::dns;
using namespace isc::dns::rdata;
using isc::dns::rdata::generic::detail::CharString;
using isc::dns::rdata::generic::detail::strToCharString;
+using isc::dns::rdata::generic::detail::charStringToString;
using isc::util::unittests::matchWireData;
namespace {
@@ -144,4 +145,61 @@ TEST_F(CharStringTest, badDDD) {
InvalidRdataText);
}
+TEST_F(CharStringTest, charStringToString) {
+ const uint8_t double_quotes_buf[] = {
+ sizeof("Test\"Test\"") - 1,
+ 'T', 'e', 's', 't', '"', 'T', 'e', 's', 't', '"'
+ };
+ const CharString double_quotes
+ (double_quotes_buf, double_quotes_buf + sizeof(double_quotes_buf));
+ EXPECT_EQ("Test\\\"Test\\\"",
+ charStringToString(double_quotes));
+
+ const uint8_t semicolon_buf[] = {
+ sizeof("Test;Test") - 1,
+ 'T', 'e', 's', 't', ';', 'T', 'e', 's', 't'
+ };
+ const CharString semicolon
+ (semicolon_buf, semicolon_buf + sizeof(semicolon_buf));
+ EXPECT_EQ("Test\\;Test",
+ charStringToString(semicolon));
+
+ const uint8_t backslash_buf[] = {
+ sizeof("Test\\Test") - 1,
+ 'T', 'e', 's', 't', '\\', 'T', 'e', 's', 't'
+ };
+ const CharString backslash
+ (backslash_buf, backslash_buf + sizeof(backslash_buf));
+ EXPECT_EQ("Test\\\\Test",
+ charStringToString(backslash));
+
+ const uint8_t before_x20_buf[] = {
+ sizeof("Test\x1fTest") - 1,
+ 'T', 'e', 's', 't', 0x1f, 'T', 'e', 's', 't'
+ };
+ const CharString before_x20
+ (before_x20_buf, before_x20_buf + sizeof(before_x20_buf));
+ EXPECT_EQ("Test\\031Test",
+ charStringToString(before_x20));
+
+ const uint8_t from_x20_to_x7e_buf[] = {
+ sizeof("Test ~ Test") - 1,
+ 'T', 'e', 's', 't', ' ', '~', ' ', 'T', 'e', 's', 't'
+ };
+ const CharString from_x20_to_x7e
+ (from_x20_to_x7e_buf,
+ from_x20_to_x7e_buf + sizeof(from_x20_to_x7e_buf));
+ EXPECT_EQ("Test ~ Test",
+ charStringToString(from_x20_to_x7e));
+
+ const uint8_t after_0x7e_buf[] = {
+ sizeof("Test\x7fTest") - 1,
+ 'T', 'e', 's', 't', 0x7f, 'T', 'e', 's', 't'
+ };
+ const CharString after_0x7e
+ (after_0x7e_buf, after_0x7e_buf + sizeof(after_0x7e_buf));
+ EXPECT_EQ("Test\\127Test",
+ charStringToString(after_0x7e));
+}
+
} // unnamed namespace
More information about the bind10-changes
mailing list