summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMukund Sivaraman <muks@isc.org>2014-01-08 06:14:05 +0100
committerMukund Sivaraman <muks@isc.org>2014-01-08 06:26:14 +0100
commit9d6d5822fe89f485b1f7319e63c7e4572daf0b44 (patch)
tree316e10d6bb54c470a5ff4a9c6368b4e4567484f0
parent[master] Add ChangeLog for #3227 (diff)
downloadkea-9d6d5822fe89f485b1f7319e63c7e4572daf0b44.tar.xz
kea-9d6d5822fe89f485b1f7319e63c7e4572daf0b44.zip
[571] Don't print trailing newlines in Question::toText() output by default
It is possible to get the old behavior by passing toText(true). Message::toText() output is unchanged.
-rw-r--r--src/lib/dns/message.cc5
-rw-r--r--src/lib/dns/python/tests/question_python_test.py6
-rw-r--r--src/lib/dns/question.cc13
-rw-r--r--src/lib/dns/question.h12
-rw-r--r--src/lib/dns/tests/question_unittest.cc10
5 files changed, 32 insertions, 14 deletions
diff --git a/src/lib/dns/message.cc b/src/lib/dns/message.cc
index 89da4979ff..bb8e176c0a 100644
--- a/src/lib/dns/message.cc
+++ b/src/lib/dns/message.cc
@@ -869,8 +869,11 @@ struct SectionFormatter {
void operator()(const T& entry) {
if (section_ == Message::SECTION_QUESTION) {
output_ += ";";
+ output_ += entry->toText();
+ output_ += "\n";
+ } else {
+ output_ += entry->toText();
}
- output_ += entry->toText();
}
const Message::Section section_;
string& output_;
diff --git a/src/lib/dns/python/tests/question_python_test.py b/src/lib/dns/python/tests/question_python_test.py
index 8c8c81580e..43b80d3604 100644
--- a/src/lib/dns/python/tests/question_python_test.py
+++ b/src/lib/dns/python/tests/question_python_test.py
@@ -70,9 +70,9 @@ class QuestionTest(unittest.TestCase):
def test_to_text(self):
- self.assertEqual("foo.example.com. IN NS\n", self.test_question1.to_text())
- self.assertEqual("foo.example.com. IN NS\n", str(self.test_question1))
- self.assertEqual("bar.example.com. CH A\n", self.test_question2.to_text())
+ self.assertEqual("foo.example.com. IN NS", self.test_question1.to_text())
+ self.assertEqual("foo.example.com. IN NS", str(self.test_question1))
+ self.assertEqual("bar.example.com. CH A", self.test_question2.to_text())
def test_to_wire_buffer(self):
obuffer = bytes()
diff --git a/src/lib/dns/question.cc b/src/lib/dns/question.cc
index 6ccb164ed1..bf39174c32 100644
--- a/src/lib/dns/question.cc
+++ b/src/lib/dns/question.cc
@@ -40,10 +40,15 @@ Question::Question(InputBuffer& buffer) :
rrclass_ = RRClass(buffer);
}
-string
-Question::toText() const {
- return (name_.toText() + " " + rrclass_.toText() + " " +
- rrtype_.toText() + "\n");
+std::string
+Question::toText(bool newline) const {
+ std::string r(name_.toText() + " " + rrclass_.toText() + " " +
+ rrtype_.toText());
+ if (newline) {
+ r.append("\n");
+ }
+
+ return (r);
}
unsigned int
diff --git a/src/lib/dns/question.h b/src/lib/dns/question.h
index 4b5b23356c..388cf490ef 100644
--- a/src/lib/dns/question.h
+++ b/src/lib/dns/question.h
@@ -173,9 +173,9 @@ public:
//@{
/// \brief Convert the Question to a string.
///
- /// Unlike other similar methods of this library, this method terminates
- /// the resulting string with a trailing newline character
- /// (following the BIND9 convention).
+ /// When \c newline argument is \c true, this method terminates the
+ /// resulting string with a trailing newline character (following
+ /// the BIND9 convention).
///
/// This method simply calls the \c %toText() methods of the corresponding
/// \c Name, \c RRType and \c RRClass classes for this \c Question, and
@@ -183,8 +183,12 @@ public:
/// In particular, if resource allocation fails, a corresponding standard
/// exception will be thrown.
///
+ /// \param newline Whether to add a trailing newline. If true, a
+ /// trailing newline is added. If false, no trailing newline is
+ /// added.
+ ///
/// \return A string representation of the \c Question.
- std::string toText() const;
+ std::string toText(bool newline = false) const;
/// \brief Render the Question in the wire format with name compression.
///
diff --git a/src/lib/dns/tests/question_unittest.cc b/src/lib/dns/tests/question_unittest.cc
index 54d0942de1..d1214a1238 100644
--- a/src/lib/dns/tests/question_unittest.cc
+++ b/src/lib/dns/tests/question_unittest.cc
@@ -86,8 +86,14 @@ TEST_F(QuestionTest, fromWire) {
}
TEST_F(QuestionTest, toText) {
- EXPECT_EQ("foo.example.com. IN NS\n", test_question1.toText());
- EXPECT_EQ("bar.example.com. CH A\n", test_question2.toText());
+ EXPECT_EQ("foo.example.com. IN NS", test_question1.toText());
+ EXPECT_EQ("bar.example.com. CH A", test_question2.toText());
+
+ EXPECT_EQ("foo.example.com. IN NS", test_question1.toText(false));
+ EXPECT_EQ("bar.example.com. CH A", test_question2.toText(false));
+
+ EXPECT_EQ("foo.example.com. IN NS\n", test_question1.toText(true));
+ EXPECT_EQ("bar.example.com. CH A\n", test_question2.toText(true));
}
TEST_F(QuestionTest, toWireBuffer) {