]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2390] Update std::string PTR constructor to use the MasterLexer
authorMukund Sivaraman <muks@isc.org>
Mon, 28 Jan 2013 10:05:39 +0000 (15:35 +0530)
committerMukund Sivaraman <muks@isc.org>
Tue, 29 Jan 2013 04:59:00 +0000 (10:29 +0530)
Also adjust tests.

src/lib/dns/rdata/generic/ptr_12.cc
src/lib/dns/tests/rdata_ptr_unittest.cc

index 6a3cefacefc08622acc51bb9b02398afb4a32397..3aadb6e33def7f32bfd9630b5f82a37a84bfdfee 100644 (file)
@@ -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)
index cecbdd341a19c41f2a7572e8a59ff8418affa038..0297bf0deca93372bbad4e5193b4b36fcc5cb6f9 100644 (file)
@@ -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));
 }