Browse Source

[2428] Implement basic inclusion

Michal 'vorner' Vaner 12 years ago
parent
commit
c9bd919bd9
2 changed files with 26 additions and 7 deletions
  1. 23 4
      src/lib/dns/master_loader.cc
  2. 3 3
      src/lib/dns/tests/master_loader_unittest.cc

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

@@ -105,19 +105,38 @@ public:
 
 
     bool loadIncremental(size_t count_limit);
     bool loadIncremental(size_t count_limit);
 
 
+    void doInclude() {
+        // First, get the filename to include
+        const MasterToken::StringRegion
+            filename(lexer_.getNextToken(MasterLexer::QSTRING).
+                     getStringRegion());
+
+        // TODO: Handle the case where there's Name after the
+        // filename, meaning origin. Once $ORIGIN handling is
+        // done, it should be interconnected somehow.
+
+        // Push the filename. We abuse the fact that filename
+        // may not contain '\0' anywhere in it, so we can
+        // freely use the filename.beg directly.
+        pushSource(filename.beg);
+
+        // TODO: Eat any extra tokens at the end of line (they
+        // should not be here, of course).
+    }
+
     void handleDirective(const char* directive, size_t length) {
     void handleDirective(const char* directive, size_t length) {
         // We use strncasecmp, because there seems to be no reasonable
         // We use strncasecmp, because there seems to be no reasonable
         // way to compare strings case-insensitive in C++
         // way to compare strings case-insensitive in C++
 
 
         // Warning: The order of compared strings does matter. The length
         // Warning: The order of compared strings does matter. The length
         // parameter applies to the first one only.
         // parameter applies to the first one only.
-        if (strncasecmp(directive, "INCLUDE", length)) {
-
-        } else if (strncasecmp(directive, "ORIGIN", length)) {
+        if (strncasecmp(directive, "INCLUDE", length) == 0) {
+            doInclude();
+        } else if (strncasecmp(directive, "ORIGIN", length) == 0) {
             // TODO: Implement
             // TODO: Implement
             isc_throw(isc::NotImplemented,
             isc_throw(isc::NotImplemented,
                       "Origin directive not implemented yet");
                       "Origin directive not implemented yet");
-        } else if (strncasecmp(directive, "TTL", length)) {
+        } else if (strncasecmp(directive, "TTL", length) == 0) {
             // TODO: Implement
             // TODO: Implement
             isc_throw(isc::NotImplemented,
             isc_throw(isc::NotImplemented,
                       "TTL directive not implemented yet");
                       "TTL directive not implemented yet");

+ 3 - 3
src/lib/dns/tests/master_loader_unittest.cc

@@ -160,15 +160,15 @@ TEST_F(MasterLoaderTest, include) {
         SCOPED_TRACE(*include);
         SCOPED_TRACE(*include);
         // Prepare input source that has no other content than just the
         // Prepare input source that has no other content than just the
         // include of the real master file.
         // include of the real master file.
-        const string include_str = string(*include) + " " + TEST_DATA_SRCDIR +
-            "/example.org\n";
+        const string include_str = "$" + string(*include) + " " +
+            TEST_DATA_SRCDIR + "/example.org\n";
         stringstream ss(include_str);
         stringstream ss(include_str);
         setLoader(ss, Name("example.org."), RRClass::IN(),
         setLoader(ss, Name("example.org."), RRClass::IN(),
                   MasterLoader::MANY_ERRORS);
                   MasterLoader::MANY_ERRORS);
 
 
         loader_->load();
         loader_->load();
         EXPECT_TRUE(loader_->loadedSucessfully());
         EXPECT_TRUE(loader_->loadedSucessfully());
-        EXPECT_TRUE(errors_.empty());
+        EXPECT_TRUE(errors_.empty()) << errors_[0];
         EXPECT_TRUE(warnings_.empty());
         EXPECT_TRUE(warnings_.empty());
 
 
         checkBasicRRs();
         checkBasicRRs();