Parcourir la source

[2377] Prepare MasterLoader::pushSource for future

When we support $INCLUDE, it should report reasonable place of error,
not :0.
Michal 'vorner' Vaner il y a 12 ans
Parent
commit
2edd97ec54
2 fichiers modifiés avec 13 ajouts et 2 suppressions
  1. 9 2
      src/lib/dns/master_loader.cc
  2. 4 0
      src/lib/dns/master_loader.h

+ 9 - 2
src/lib/dns/master_loader.cc

@@ -63,8 +63,15 @@ public:
     void pushSource(const std::string& filename) {
     void pushSource(const std::string& filename) {
         std::string error;
         std::string error;
         if (!lexer_.pushSource(filename.c_str(), &error)) {
         if (!lexer_.pushSource(filename.c_str(), &error)) {
-            reportError("", 0, error);
-            ok_ = false;
+            if (initialized_) {
+                // $INCLUDE file
+                reportError(lexer_.getSourceName(), lexer_.getSourceLine(),
+                            error);
+            } else {
+                // Top-level file
+                reportError("", 0, error);
+                ok_ = false;
+            }
         }
         }
         initialized_ = true;
         initialized_ = true;
     }
     }

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

@@ -66,6 +66,10 @@ public:
     /// \param zone_class The class of zone to be expected inside the
     /// \param zone_class The class of zone to be expected inside the
     ///     master file.
     ///     master file.
     /// \param callbacks The callbacks by which it should report problems.
     /// \param callbacks The callbacks by which it should report problems.
+    ///     Usually, the callback carries a filename and line number of the
+    ///     input where the problem happens. There's a special case of empty
+    ///     filename and zero line in case the opening of the top-level master
+    ///     file fails.
     /// \param add_callback The callback which would be called with each
     /// \param add_callback The callback which would be called with each
     ///     loaded RR.
     ///     loaded RR.
     /// \param options Options for the parsing, which is bitwise-or of
     /// \param options Options for the parsing, which is bitwise-or of