]> granicus.if.org Git - pdns/commitdiff
Support for include-dir directive
authorAki Tuomi <cmouse@desteem.org>
Wed, 15 May 2013 14:05:01 +0000 (17:05 +0300)
committerAki Tuomi <cmouse@desteem.org>
Wed, 15 May 2013 14:05:01 +0000 (17:05 +0300)
pdns/arguments.cc
pdns/arguments.hh

index b9f2fece43fb5d914595783df72ec87ac2f161d2..23467de5ba4402ee1c722ca7a0e0e2c238cf6a1d 100644 (file)
 */
 #include "arguments.hh"
 #include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/filesystem.hpp> 
+#include <boost/foreach.hpp>
 #include "namespaces.hh"
+#include "logger.hh"
 
 const ArgvMap::param_t::const_iterator ArgvMap::begin()
 {
@@ -384,14 +388,21 @@ bool ArgvMap::preParseFile(const char *fname, const string &arg, const string& t
   return true;
 }
 
-
 bool ArgvMap::file(const char *fname, bool lax)
+{
+   return file(fname,lax,false);
+}
+
+bool ArgvMap::file(const char *fname, bool lax, bool included)
 {
   ifstream f(fname);
   if(!f) {
     return false;
   }
 
+  if (!included)  // inject include-dir
+    set("include-dir","Directory to include configuration files from");
+
   string line;
   string pline;
   string::size_type pos;
@@ -420,5 +431,19 @@ bool ArgvMap::file(const char *fname, bool lax)
     line="";
   }
 
+  // handle include here (avoid re-include)
+  if (!included && parmIsset("include-dir")) {
+      // rerun parser for all files
+      boost::filesystem::path targetDir(params["include-dir"]);
+      if (!boost::filesystem::exists(targetDir)) {
+         L << Logger::Error << params["include-dir"] << " does not exist!" << std::endl;
+         throw ArgException(params["include-dir"] + " does not exist!");
+      }
+      boost::filesystem::directory_iterator bfd_it(targetDir), eod;
+      BOOST_FOREACH(boost::filesystem::path const &p, std::make_pair(bfd_it, eod)) {
+          if (boost::ends_with(p.native(),".conf") && is_regular_file(p)) file(p.c_str(), lax, true);
+      }
+  }
+
   return true;
 }
index 9f196a686accbe4ce20c1a55dbf312efe00e9efe..865239337c72f0502de1966efc54d4af5afb9a9b 100644 (file)
@@ -85,6 +85,7 @@ public:
   bool preParseFile(const char *fname, const string &arg, const string& theDefault=""); //!< use this to preparse a single var in configuration
 
   bool file(const char *fname, bool lax=false); //!< Parses a file with parameters
+  bool file(const char *fname, bool lax, bool included); 
   bool laxFile(const char *fname) 
   {
     return file(fname,true);