From: Mukund Sivaraman Date: Mon, 25 Mar 2013 10:40:08 +0000 (+0530) Subject: [2387] Support empty bitmaps in buildBitmapsFromLexer() X-Git-Tag: bind10-1.2.0beta1-release~481^2~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ecc1e01cde7133bfcb183ced46b011b4eb9558a;p=thirdparty%2Fkea.git [2387] Support empty bitmaps in buildBitmapsFromLexer() This avoids an extra ungetToken() and cuts down on some code too. --- diff --git a/src/lib/dns/rdata/generic/detail/nsec_bitmap.cc b/src/lib/dns/rdata/generic/detail/nsec_bitmap.cc index c8a84616f3..a95d6c7969 100644 --- a/src/lib/dns/rdata/generic/detail/nsec_bitmap.cc +++ b/src/lib/dns/rdata/generic/detail/nsec_bitmap.cc @@ -79,7 +79,8 @@ checkRRTypeBitmaps(const char* const rrtype_name, void buildBitmapsFromLexer(const char* const rrtype_name, - MasterLexer& lexer, vector& typebits) + MasterLexer& lexer, vector& typebits, + bool allow_empty) { uint8_t bitmap[8 * 1024]; // 64k bits memset(bitmap, 0, sizeof(bitmap)); @@ -112,6 +113,9 @@ buildBitmapsFromLexer(const char* const rrtype_name, lexer.ungetToken(); if (!have_rrtypes) { + if (allow_empty) { + return; + } isc_throw(InvalidRdataText, rrtype_name << " record does not end with RR type mnemonic"); } diff --git a/src/lib/dns/rdata/generic/detail/nsec_bitmap.h b/src/lib/dns/rdata/generic/detail/nsec_bitmap.h index 7468225f4d..552538442f 100644 --- a/src/lib/dns/rdata/generic/detail/nsec_bitmap.h +++ b/src/lib/dns/rdata/generic/detail/nsec_bitmap.h @@ -57,7 +57,8 @@ void checkRRTypeBitmaps(const char* const rrtype_name, /// \brief Convert textual sequence of RR types read from a lexer into /// type bitmaps. /// -/// See the other variant above for description. +/// See the other variant above for description. If \c allow_empty is +/// true and there are no mnemonics, \c typebits is left untouched. /// /// \exception InvalidRdataText Data read from the given lexer does not /// meet the assumption (e.g. including invalid form of RR type, not @@ -70,9 +71,13 @@ void checkRRTypeBitmaps(const char* const rrtype_name, /// bits are set. /// \param typebits A placeholder for the resulting bitmaps. Expected to be /// empty, but it's not checked. +/// \param allow_empty If true, the function simply returns if no RR +/// type mnemonics are found. Otherwise, it throws an exception if no RR +/// type mnemonics are found. void buildBitmapsFromLexer(const char* const rrtype_name, isc::dns::MasterLexer& lexer, - std::vector& typebits); + std::vector& typebits, + bool allow_empty = false); /// \brief Convert type bitmaps to textual sequence of RR types. /// diff --git a/src/lib/dns/rdata/generic/nsec3_50.cc b/src/lib/dns/rdata/generic/nsec3_50.cc index 6c65cd2802..51d72d8109 100644 --- a/src/lib/dns/rdata/generic/nsec3_50.cc +++ b/src/lib/dns/rdata/generic/nsec3_50.cc @@ -144,26 +144,9 @@ NSEC3::constructFromLexer(MasterLexer& lexer) { << next.size() << " bytes"); } - // For NSEC3 empty bitmap is possible and allowed. - bool empty_bitmap = false; - const MasterToken& token = lexer.getNextToken(); - if ((token.getType() == MasterToken::END_OF_LINE) || - (token.getType() == MasterToken::END_OF_FILE)) { - empty_bitmap = true; - } - - lexer.ungetToken(); - - if (empty_bitmap) { - impl_ = new NSEC3Impl(params.algorithm, params.flags, - params.iterations, salt, next, - vector()); - return; - } - vector typebits; - buildBitmapsFromLexer("NSEC3", lexer, typebits); - + // For NSEC3 empty bitmap is possible and allowed. + buildBitmapsFromLexer("NSEC3", lexer, typebits, true); impl_ = new NSEC3Impl(params.algorithm, params.flags, params.iterations, salt, next, typebits); }