]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2387] Support empty bitmaps in buildBitmapsFromLexer()
authorMukund Sivaraman <muks@isc.org>
Mon, 25 Mar 2013 10:40:08 +0000 (16:10 +0530)
committerMukund Sivaraman <muks@isc.org>
Mon, 25 Mar 2013 10:40:13 +0000 (16:10 +0530)
This avoids an extra ungetToken() and cuts down on some code too.

src/lib/dns/rdata/generic/detail/nsec_bitmap.cc
src/lib/dns/rdata/generic/detail/nsec_bitmap.h
src/lib/dns/rdata/generic/nsec3_50.cc

index c8a84616f31766d9731e4b006163b7ec2739a0a5..a95d6c796967bd3b3d4fdbc4f7dc7d5c86a5c472 100644 (file)
@@ -79,7 +79,8 @@ checkRRTypeBitmaps(const char* const rrtype_name,
 
 void
 buildBitmapsFromLexer(const char* const rrtype_name,
-                      MasterLexer& lexer, vector<uint8_t>& typebits)
+                      MasterLexer& lexer, vector<uint8_t>& 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");
     }
index 7468225f4d270101c8eb312623d38c1ac25b0de0..552538442f3e22cff4dad68b5e5ecf6cdeca7391 100644 (file)
@@ -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<uint8_t>& typebits);
+                           std::vector<uint8_t>& typebits,
+                           bool allow_empty = false);
 
 /// \brief Convert type bitmaps to textual sequence of RR types.
 ///
index 6c65cd2802ff0b7041868a12450ff943bb0b9bce..51d72d81093a1b2e2b81b63f32fce588814ffc26 100644 (file)
@@ -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<uint8_t>());
-        return;
-    }
-
     vector<uint8_t> 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);
 }