BIND 10 trac2390, updated. 92dd5c1dce7ba5c1f7be1200cec6ee3ce7fdfaa0 [2390] Update std::string PTR constructor to use the MasterLexer

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Jan 28 10:05:58 UTC 2013


The branch, trac2390 has been updated
       via  92dd5c1dce7ba5c1f7be1200cec6ee3ce7fdfaa0 (commit)
      from  59d0a053de50c8e86a465f7b63a1a11b8f7744f5 (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 92dd5c1dce7ba5c1f7be1200cec6ee3ce7fdfaa0
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon Jan 28 15:35:39 2013 +0530

    [2390] Update std::string PTR constructor to use the MasterLexer
    
    Also adjust tests.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dns/rdata/generic/ptr_12.cc     |   21 +++++++++++++++++++--
 src/lib/dns/tests/rdata_ptr_unittest.cc |   16 ++++++++--------
 2 files changed, 27 insertions(+), 10 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/rdata/generic/ptr_12.cc b/src/lib/dns/rdata/generic/ptr_12.cc
index 6a3cefa..3aadb6e 100644
--- a/src/lib/dns/rdata/generic/ptr_12.cc
+++ b/src/lib/dns/rdata/generic/ptr_12.cc
@@ -29,8 +29,25 @@ using namespace isc::util;
 // BEGIN_RDATA_NAMESPACE
 
 PTR::PTR(const std::string& type_str) :
-    ptr_name_(type_str)
-{}
+    // Fill in dummy name and replace them soon below.
+    ptr_name_(Name::ROOT_NAME())
+{
+    try {
+        std::istringstream ss(type_str);
+        MasterLexer lexer;
+        lexer.pushSource(ss);
+
+        ptr_name_ = createNameFromLexer(lexer, NULL);
+
+        if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
+            isc_throw(InvalidRdataText, "extra input text for PTR: "
+                      << type_str);
+        }
+    } catch (const MasterLexer::LexerError& ex) {
+        isc_throw(InvalidRdataText, "Failed to construct PTR from '" <<
+                  type_str << "': " << ex.what());
+    }
+}
 
 PTR::PTR(InputBuffer& buffer, size_t) :
     ptr_name_(buffer)
diff --git a/src/lib/dns/tests/rdata_ptr_unittest.cc b/src/lib/dns/tests/rdata_ptr_unittest.cc
index cecbdd3..0297bf0 100644
--- a/src/lib/dns/tests/rdata_ptr_unittest.cc
+++ b/src/lib/dns/tests/rdata_ptr_unittest.cc
@@ -40,8 +40,8 @@ class Rdata_PTR_Test : public RdataTest {
     // there's nothing to specialize
 };
 
-const generic::PTR rdata_ptr("ns.example.com");
-const generic::PTR rdata_ptr2("ns2.example.com");
+const generic::PTR rdata_ptr("ns.example.com.");
+const generic::PTR rdata_ptr2("ns2.example.com.");
 const uint8_t wiredata_ptr[] = {
     0x02, 0x6e, 0x73, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x03,
     0x63, 0x6f, 0x6d, 0x00 };
@@ -54,15 +54,15 @@ const uint8_t wiredata_ptr2[] = {
     0x03, 0x6e, 0x73, 0x32, 0xc0, 0x03 };
 
 TEST_F(Rdata_PTR_Test, createFromText) {
-    EXPECT_EQ(0, rdata_ptr.compare(generic::PTR("ns.example.com")));
+    EXPECT_EQ(0, rdata_ptr.compare(generic::PTR("ns.example.com.")));
     // explicitly add a trailing dot.  should be the same RDATA.
     EXPECT_EQ(0, rdata_ptr.compare(generic::PTR("ns.example.com.")));
     // should be case sensitive.
-    EXPECT_EQ(0, rdata_ptr.compare(generic::PTR("NS.EXAMPLE.COM")));
+    EXPECT_EQ(0, rdata_ptr.compare(generic::PTR("NS.EXAMPLE.COM.")));
     // RDATA of a class-independent type should be recognized for any
     // "unknown" class.
     EXPECT_EQ(0, rdata_ptr.compare(*createRdata(RRType("PTR"), RRClass(65000),
-                                               "ns.example.com")));
+                                               "ns.example.com.")));
 }
 
 TEST_F(Rdata_PTR_Test, createFromWire) {
@@ -82,7 +82,7 @@ TEST_F(Rdata_PTR_Test, createFromWire) {
                                       "rdata_ns_fromWire", 71),
                  DNSMessageFORMERR);
 
-    EXPECT_EQ(0, generic::PTR("ns2.example.com").compare(
+    EXPECT_EQ(0, generic::PTR("ns2.example.com.").compare(
                   *rdataFactoryFromFile(RRType("PTR"), RRClass("IN"),
                                         "rdata_ns_fromWire", 55)));
     EXPECT_THROW(*rdataFactoryFromFile(RRType("PTR"), RRClass("IN"),
@@ -119,8 +119,8 @@ TEST_F(Rdata_PTR_Test, toText) {
 }
 
 TEST_F(Rdata_PTR_Test, compare) {
-    generic::PTR small("a.example");
-    generic::PTR large("example");
+    generic::PTR small("a.example.");
+    generic::PTR large("example.");
     EXPECT_TRUE(Name("a.example") > Name("example"));
     EXPECT_GT(0, small.compare(large));
 }



More information about the bind10-changes mailing list