]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2442] unified from std::string and with lexer ctro for text-like rdata.
authorJINMEI Tatuya <jinmei@isc.org>
Tue, 4 Dec 2012 07:21:06 +0000 (23:21 -0800)
committerJINMEI Tatuya <jinmei@isc.org>
Tue, 4 Dec 2012 07:21:06 +0000 (23:21 -0800)
some tests needed to be adjusted:
- ' ' * 256 (in python) now doesn't work as intended; they are considered
  space
- in auth tests, make sure txt RDATA containing a space is explicitly double
  quoted
- in Rdata_TXT_LIKE_Test::createFromText, removed the last test case because
  it's actually a valid representation as commented.  now the implementation
  correctly accepts it.

src/bin/auth/tests/auth_srv_unittest.cc
src/lib/dns/python/tests/rdata_python_test.py
src/lib/dns/rdata/generic/detail/txt_like.h
src/lib/dns/tests/rdata_txt_like_unittest.cc

index 8015043bf137e9f419c0a5178d83c00b64fdef8f..7f89fda23add8f691f00985fa6f2d1b7d91050a2 100644 (file)
@@ -225,7 +225,7 @@ createBuiltinVersionResponse(const qid_t qid, vector<uint8_t>& data) {
     message.setHeaderFlag(Message::HEADERFLAG_AA);
     RRsetPtr rrset_version = RRsetPtr(new RRset(version_name, RRClass::CH(),
                                                 RRType::TXT(), RRTTL(0)));
-    rrset_version->addRdata(generic::TXT(PACKAGE_STRING));
+    rrset_version->addRdata(generic::TXT("\"" PACKAGE_STRING "\""));
     message.addRRset(Message::SECTION_ANSWER, rrset_version);
 
     RRsetPtr rrset_version_ns = RRsetPtr(new RRset(apex_name, RRClass::CH(),
index 81dea5f6dc3afd1741060084604aab98cd500811..3b8f9ad312d0450a5a07d9274ab0e2d026c5e620 100644 (file)
@@ -38,7 +38,7 @@ class RdataTest(unittest.TestCase):
         self.assertRaises(InvalidRdataText, Rdata, RRType("A"), RRClass("IN"),
                           "Invalid Rdata Text")
         self.assertRaises(CharStringTooLong, Rdata, RRType("TXT"),
-                          RRClass("IN"), ' ' * 256)
+                          RRClass("IN"), 'x' * 256)
         self.assertRaises(InvalidRdataLength, Rdata, RRType("TXT"),
                           RRClass("IN"), bytes(65536))
         self.assertRaises(DNSMessageFORMERR, Rdata, RRType("TXT"),
index 24a4e0fe9bd262c887b47728f793c991c5be0519..fecf1b0860ed0bdfafd53427d7f1c521cd136c2d 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdint.h>
 
 #include <string>
+#include <sstream>
 #include <vector>
 
 namespace isc {
@@ -85,43 +86,20 @@ public:
     /// \c InvalidRdataText is thrown if the method cannot process the
     /// parameter data.
     explicit TXTLikeImpl(const std::string& txtstr) {
-        // TBD: this is a simple, incomplete implementation that only supports
-        // a single character-string.
-
-        size_t length = txtstr.size();
-        size_t pos_begin = 0;
-
-        if (length > 1 && txtstr[0] == '"' && txtstr[length - 1] == '"') {
-            pos_begin = 1;
-            length -= 2;
-        }
-
-        if (length > MAX_CHARSTRING_LEN) {
-            isc_throw(CharStringTooLong, RRType(typeCode) <<
-                      " RDATA construction from text:"
-                      " string length is too long: " << length);
-        }
-
-        // TBD: right now, we don't support escaped characters
-        if (txtstr.find('\\') != string::npos) {
-            isc_throw(InvalidRdataText, RRType(typeCode) <<
-                      " RDATA from text:"
-                      " escaped character is currently not supported: " <<
-                      txtstr);
-        }
-
-        std::vector<uint8_t> data;
-        data.reserve(length + 1);
-        data.push_back(length);
-        data.insert(data.end(), txtstr.begin() + pos_begin,
-                    txtstr.begin() + pos_begin + length);
-        string_list_.push_back(data);
+        std::istringstream ss(txtstr);
+        MasterLexer lexer;
+        lexer.pushSource(ss);
+        buildFromTextHelper(lexer);
     }
 
-    TXTLikeImpl(MasterLexer& lexer, const Name*,
-                MasterLoader::Options,
+    TXTLikeImpl(MasterLexer& lexer, const Name*, MasterLoader::Options,
                 MasterLoaderCallbacks&)
     {
+        buildFromTextHelper(lexer);
+    }
+
+private:
+    void buildFromTextHelper(MasterLexer& lexer) {
         while (true) {
             const MasterToken& token = lexer.getNextToken(
                 MasterToken::QSTRING, true);
@@ -135,6 +113,7 @@ public:
         lexer.ungetToken();
     }
 
+public:
     /// \brief The copy constructor.
     ///
     /// Trivial for now, we could've used the default one.
index 7ce0aec3081165be97026bf8d51a261e24d516ef..6c980f84a3967475208a6833000c9252311bce75 100644 (file)
@@ -154,16 +154,10 @@ TYPED_TEST(Rdata_TXT_LIKE_Test, createFromText) {
 
     // The escape character makes the double quote a part of character-string,
     // so this is invalid input and should be rejected.
-    EXPECT_THROW(TypeParam("\"Test-String\\\""), InvalidRdataText);
+    EXPECT_THROW(TypeParam("\"Test-String\\\""), MasterLexer::LexerError);
     EXPECT_THROW(TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS,
                            this->loader_cb), MasterLexer::LexerError);
     EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType());
-
-    // Terminating double-quote is provided, so this is valid, but in this
-    // version of implementation we reject escaped characters.
-    EXPECT_THROW(TypeParam("\"Test-String\\\"\""), InvalidRdataText);
-    TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS,
-              this->loader_cb);
 }
 
 void