From: JINMEI Tatuya Date: Tue, 4 Dec 2012 07:21:06 +0000 (-0800) Subject: [2442] unified from std::string and with lexer ctro for text-like rdata. X-Git-Tag: bind10-1.0.0-beta-release~39^2~3^2~1^2~2^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4036de3cb6229d38270225eff7a00f5c07a4573;p=thirdparty%2Fkea.git [2442] unified from std::string and with lexer ctro for text-like rdata. 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. --- diff --git a/src/bin/auth/tests/auth_srv_unittest.cc b/src/bin/auth/tests/auth_srv_unittest.cc index 8015043bf1..7f89fda23a 100644 --- a/src/bin/auth/tests/auth_srv_unittest.cc +++ b/src/bin/auth/tests/auth_srv_unittest.cc @@ -225,7 +225,7 @@ createBuiltinVersionResponse(const qid_t qid, vector& 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(), diff --git a/src/lib/dns/python/tests/rdata_python_test.py b/src/lib/dns/python/tests/rdata_python_test.py index 81dea5f6dc..3b8f9ad312 100644 --- a/src/lib/dns/python/tests/rdata_python_test.py +++ b/src/lib/dns/python/tests/rdata_python_test.py @@ -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"), diff --git a/src/lib/dns/rdata/generic/detail/txt_like.h b/src/lib/dns/rdata/generic/detail/txt_like.h index 24a4e0fe9b..fecf1b0860 100644 --- a/src/lib/dns/rdata/generic/detail/txt_like.h +++ b/src/lib/dns/rdata/generic/detail/txt_like.h @@ -23,6 +23,7 @@ #include #include +#include #include 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 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. diff --git a/src/lib/dns/tests/rdata_txt_like_unittest.cc b/src/lib/dns/tests/rdata_txt_like_unittest.cc index 7ce0aec308..6c980f84a3 100644 --- a/src/lib/dns/tests/rdata_txt_like_unittest.cc +++ b/src/lib/dns/tests/rdata_txt_like_unittest.cc @@ -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