Browse Source

[2377] Skeleton of the master loader

Michal 'vorner' Vaner 12 years ago
parent
commit
57fda3f1db

+ 47 - 4
src/lib/dns/master_loader.cc

@@ -13,6 +13,14 @@
 // PERFORMANCE OF THIS SOFTWARE.
 
 #include <dns/master_loader.h>
+#include <dns/master_lexer.h>
+#include <dns/name.h>
+#include <dns/rrttl.h>
+#include <dns/rrclass.h>
+#include <dns/rrtype.h>
+#include <dns/rrset.h>
+
+using std::string;
 
 namespace isc {
 namespace dns {
@@ -35,13 +43,48 @@ public:
         lexer_.pushSource(master_file);
     }
 
+    // Get a string token. Handle it as error if it is not string.
+    const string getString() {
+        return (lexer_.getNextToken(MasterToken::QSTRING).getString());
+    }
+
     bool loadIncremental(size_t count_limit) {
         size_t count = 0;
         bool done = false;
-        do {
-            // Code goes here
-        } while (!done && (count_limit != 0 && ++count < count_limit));
-        // add remaining rrset that was being built (TODO)
+        // TODO: Replace getNextToken with the wrapper version
+        while (!done && (count < count_limit)) {
+            // Skip all EOLNs and finish on EOF
+            bool empty = true;
+            do {
+                const MasterToken& empty_token(lexer_.getNextToken());
+                if (empty_token.getType() == MasterToken::END_OF_FILE) {
+                    // TODO: Check if this is the last source, possibly pop
+                    return (true);
+                }
+                empty = empty_token.getType() == MasterToken::END_OF_LINE;
+            } while (empty);
+            // Return the last token, as it was not empty
+            lexer_.ungetToken();
+
+            const string name_string(getString());
+            // TODO $ handling
+            const Name name(name_string); // TODO: Origin
+            // TODO: Some more flexibility. We don't allow omitting anything yet
+
+            // The parameters
+            const RRTTL ttl(getString());
+            const RRClass rrclass(getString());
+            const RRType rrtype(getString());
+
+            // Create the RRset. We don't need the RRSIG, so we are good
+            // with the basic one
+            RRsetPtr rrset(new BasicRRset(name, rrclass, rrtype, ttl));
+
+            // TODO: Create the RData
+
+            // OK now, so give the RRset with single RR to the caller
+            add_callback_(rrset);
+        }
         return (false);
     }
 

+ 4 - 3
src/lib/dns/master_loader.h

@@ -15,13 +15,14 @@
 #ifndef MASTER_LOADER_H
 #define MASTER_LOADER_H
 
-#include <dns/name.h>
-#include <dns/rrclass.h>
-#include <dns/master_lexer.h>
 #include <dns/master_loader_callbacks.h>
 
 namespace isc {
 namespace dns {
+
+class Name;
+class RRClass;
+
 class MasterLoader {
 public:
     enum Options {

+ 2 - 0
src/lib/dns/tests/master_loader_unittest.cc

@@ -16,6 +16,8 @@
 #include <dns/master_loader.h>
 #include <dns/rrtype.h>
 #include <dns/rrset.h>
+#include <dns/rrclass.h>
+#include <dns/name.h>
 
 #include <gtest/gtest.h>
 #include <boost/bind.hpp>