core, main: make missing config file section behavior configurable

refs: #1499

Change-Id: I01cce3c73214f592d8c342d8aeda4fbafc6804b8
diff --git a/rib/main.cpp b/rib/main.cpp
index 7598d6c..452b8a9 100644
--- a/rib/main.cpp
+++ b/rib/main.cpp
@@ -45,6 +45,30 @@
 class Nrd : noncopyable
 {
 public:
+  class IgnoreNfdAndLogSections
+  {
+  public:
+    void
+    operator()(const std::string& filename,
+               const std::string& sectionName,
+               const ConfigSection& section,
+               bool isDryRun)
+    {
+      // Ignore "log" and sections belonging to NFD,
+      // but raise an error if we're missing a handler for an "rib_" section.
+
+      if (sectionName.find("rib_") != 0 || sectionName == "log")
+        {
+          // do nothing
+        }
+      else
+        {
+          // missing NRD section
+          ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
+        }
+    }
+  };
+
   void
   initialize(const std::string& configFile)
   {
@@ -52,18 +76,9 @@
 
     m_ribManager = make_shared<RibManager>();
 
-    ConfigFile config;
+    ConfigFile config((IgnoreNfdAndLogSections()));
     m_ribManager->setConfigFile(config);
 
-    for (size_t i = 0; i < N_SUPPORTED_CONFIG_SECTIONS; ++i)
-      {
-        if (SUPPORTED_CONFIG_SECTIONS[i] != "rib_security")
-          {
-            config.addSectionHandler(SUPPORTED_CONFIG_SECTIONS[i],
-                                     bind(std::plus<int>(), 0, 0)); // no-op.
-          }
-      }
-
     // parse config file
     config.parse(configFile, true);
     config.parse(configFile, false);
@@ -75,18 +90,9 @@
   void
   initializeLogging(const std::string& configFile)
   {
-    ConfigFile config;
+    ConfigFile config(&ConfigFile::ignoreUnknownSection);
     LoggerFactory::getInstance().setConfigFile(config);
 
-    for (size_t i = 0; i < N_SUPPORTED_CONFIG_SECTIONS; ++i)
-      {
-        if (SUPPORTED_CONFIG_SECTIONS[i] != "log")
-          {
-            config.addSectionHandler(SUPPORTED_CONFIG_SECTIONS[i],
-                                     bind(std::plus<int>(), 0, 0)); // no-op.
-          }
-      }
-
     config.parse(configFile, true);
     config.parse(configFile, false);
   }
@@ -191,22 +197,8 @@
 
 private:
   shared_ptr<RibManager> m_ribManager;
-
-  static const std::string SUPPORTED_CONFIG_SECTIONS[];
-  static const size_t      N_SUPPORTED_CONFIG_SECTIONS;
 };
 
-const std::string Nrd::SUPPORTED_CONFIG_SECTIONS[] =
-  {
-    "log",
-    "face_system",
-    "authorizations",
-    "rib_security",
-  };
-
-const size_t Nrd::N_SUPPORTED_CONFIG_SECTIONS =
-  sizeof(SUPPORTED_CONFIG_SECTIONS) / sizeof(std::string);
-
 } // namespace rib
 } // namespace nfd