From: JINMEI Tatuya Date: Wed, 9 Jan 2013 21:37:14 +0000 (-0800) Subject: [2500] extracted createName() from soa.cc so it can be commonly used. X-Git-Tag: bind10-1.0.0-rc-release~95^2~16^2~1^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a8e4e8678710187bbd044689a0ed603f5182fda8;p=thirdparty%2Fkea.git [2500] extracted createName() from soa.cc so it can be commonly used. --- diff --git a/src/lib/dns/Makefile.am b/src/lib/dns/Makefile.am index 8525842ff1..d84327213b 100644 --- a/src/lib/dns/Makefile.am +++ b/src/lib/dns/Makefile.am @@ -23,6 +23,7 @@ EXTRA_DIST += rdata/generic/cname_5.cc EXTRA_DIST += rdata/generic/cname_5.h EXTRA_DIST += rdata/generic/detail/char_string.cc EXTRA_DIST += rdata/generic/detail/char_string.h +EXTRA_DIST += rdata/generic/detail/lexer_util.h EXTRA_DIST += rdata/generic/detail/nsec_bitmap.cc EXTRA_DIST += rdata/generic/detail/nsec_bitmap.h EXTRA_DIST += rdata/generic/detail/nsec3param_common.cc diff --git a/src/lib/dns/rdata/generic/detail/lexer_util.h b/src/lib/dns/rdata/generic/detail/lexer_util.h new file mode 100644 index 0000000000..89df5a0e17 --- /dev/null +++ b/src/lib/dns/rdata/generic/detail/lexer_util.h @@ -0,0 +1,70 @@ +// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#ifndef DNS_RDATA_LEXER_UTIL_H +#define DNS_RDATA_LEXER_UTIL_H 1 + +#include +#include + +/// \file lexer_util.h +/// \brief Utilities for extracting RDATA fields from lexer. +/// +/// This file intends to define convenient small routines that can be +/// commonly used in the RDATA implementation to build RDATA fields from +/// a \c MasterLexer. + +namespace isc { +namespace dns { +namespace rdata { +namespace generic { +namespace detail { + +/// \brief Construct a Name object using a master lexer and optional origin. +/// +/// This is a convenient shortcut of commonly used code pattern that would +/// be used to build RDATA that contain a domain name field. +/// +/// Note that this function throws an exception against invalid input. +/// The (direct or indirect) caller's responsibility needs to expect and +/// handle exceptions appropriately. +/// +/// \throw MasterLexer::LexerError The next token from lexer is not string. +/// \throw Other Exceptions from the \c Name class constructor if the next +/// string token from the lexer does not represent a valid name. +/// +/// \param lexer A \c MasterLexer object. Its next token is expected to be +/// a string that represent a domain name. +/// \param origin If non NULL, specifies the origin of the name to be +/// constructed. +/// +/// \return A new Name object that corresponds to the next string token of +/// the \c lexer. +inline Name +createNameFromLexer(MasterLexer& lexer, const Name* origin) { + const MasterToken::StringRegion& str_region = + lexer.getNextToken(MasterToken::STRING).getStringRegion(); + return (Name(str_region.beg, str_region.len, origin)); +} + +} // namespace detail +} // namespace generic +} // namespace rdata +} // namespace dns +} // namespace isc +#endif // DNS_RDATA_LEXER_UTIL_H + +// Local Variables: +// mode: c++ +// End: diff --git a/src/lib/dns/rdata/generic/soa_6.cc b/src/lib/dns/rdata/generic/soa_6.cc index 4c95c51b1b..1a37b7c3f1 100644 --- a/src/lib/dns/rdata/generic/soa_6.cc +++ b/src/lib/dns/rdata/generic/soa_6.cc @@ -25,6 +25,8 @@ #include #include +#include + #include #include @@ -34,6 +36,7 @@ using namespace std; using boost::lexical_cast; using namespace isc::util; +using isc::dns::rdata::generic::detail::createNameFromLexer; // BEGIN_ISC_NAMESPACE // BEGIN_RDATA_NAMESPACE @@ -47,13 +50,6 @@ SOA::SOA(InputBuffer& buffer, size_t) : } namespace { -Name -createName(MasterLexer& lexer, const Name* origin) { - const MasterToken::StringRegion& str_region = - lexer.getNextToken(MasterToken::STRING).getStringRegion(); - return (Name(str_region.beg, str_region.len, origin)); -} - void fillParameters(MasterLexer& lexer, uint8_t numdata[20]) { // Copy serial, refresh, retry, expire, minimum. We accept the extended @@ -84,6 +80,7 @@ fillParameters(MasterLexer& lexer, uint8_t numdata[20]) { /// \throw Others Exception from the Name and RRTTL constructors. /// \throw InvalidRdataText Other general syntax errors. SOA::SOA(const std::string& soastr) : + // Fill in dummy name and replace them soon below. mname_(Name::ROOT_NAME()), rname_(Name::ROOT_NAME()) { try { @@ -91,8 +88,8 @@ SOA::SOA(const std::string& soastr) : MasterLexer lexer; lexer.pushSource(ss); - mname_ = createName(lexer, NULL); - rname_ = createName(lexer, NULL); + mname_ = createNameFromLexer(lexer, NULL); + rname_ = createNameFromLexer(lexer, NULL); fillParameters(lexer, numdata_); if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) { @@ -126,7 +123,8 @@ SOA::SOA(const std::string& soastr) : /// they are non absolute. SOA::SOA(MasterLexer& lexer, const Name* origin, MasterLoader::Options, MasterLoaderCallbacks&) : - mname_(createName(lexer, origin)), rname_(createName(lexer, origin)) + mname_(createNameFromLexer(lexer, origin)), + rname_(createNameFromLexer(lexer, origin)) { fillParameters(lexer, numdata_); } diff --git a/src/lib/dns/tests/rdata_soa_unittest.cc b/src/lib/dns/tests/rdata_soa_unittest.cc index dedb1f9b7b..ed1c29f2ae 100644 --- a/src/lib/dns/tests/rdata_soa_unittest.cc +++ b/src/lib/dns/tests/rdata_soa_unittest.cc @@ -106,6 +106,13 @@ TEST_F(Rdata_SOA_Test, createFromText) { checkFromBadTexxt( ". bad..example. 2010012601 1H 5M 1000H 20M"); + // Names shouldn't be quoted. (Note: on completion of #2534, the resulting + // exception will be different). + checkFromBadTexxt( + "\".\" . 0 0 0 0 0"); + checkFromBadTexxt( + ". \".\" 0 0 0 0 0"); + // Missing MAME or RNAME: for the string version, the serial would be // tried as RNAME and result in "not absolute". For the lexer version, // it reaches the end-of-line, missing min TTL.