core, main: make missing config file section behavior configurable

refs: #1499

Change-Id: I01cce3c73214f592d8c342d8aeda4fbafc6804b8
diff --git a/core/config-file.cpp b/core/config-file.cpp
index 436c480..5887c2b 100644
--- a/core/config-file.cpp
+++ b/core/config-file.cpp
@@ -32,7 +32,30 @@
 
 NFD_LOG_INIT("ConfigFile");
 
-ConfigFile::ConfigFile()
+void
+ConfigFile::throwErrorOnUnknownSection(const std::string& filename,
+                                       const std::string& sectionName,
+                                       const ConfigSection& section,
+                                       bool isDryRun)
+{
+  std::string msg = "Error processing configuration file ";
+  msg += filename;
+  msg += ": no module subscribed for section \"" + sectionName + "\"";
+
+  throw ConfigFile::Error(msg);
+}
+
+void
+ConfigFile::ignoreUnknownSection(const std::string& filename,
+                                 const std::string& sectionName,
+                                 const ConfigSection& section,
+                                 bool isDryRun)
+{
+  // do nothing
+}
+
+ConfigFile::ConfigFile(UnknownConfigSectionHandler unknownSectionCallback)
+  : m_unknownSectionCallback(unknownSectionCallback)
 {
 }
 
@@ -93,8 +116,7 @@
 
   if (m_global.begin() == m_global.end())
     {
-      std::string msg = "Error processing configuration file";
-      msg += ": ";
+      std::string msg = "Error processing configuration file: ";
       msg += filename;
       msg += " no data";
       throw Error(msg);
@@ -113,11 +135,7 @@
         }
       else
         {
-          std::string msg = "Error processing configuration file";
-          msg += " ";
-          msg += filename;
-          msg += " no module subscribed for section: " + sectionName;
-          throw Error(msg);
+          m_unknownSectionCallback(filename, sectionName, section, isDryRun);
         }
     }
 }