core, main: make missing config file section behavior configurable

refs: #1499

Change-Id: I01cce3c73214f592d8c342d8aeda4fbafc6804b8
diff --git a/daemon/main.cpp b/daemon/main.cpp
index 5fd159f..a13dfe1 100644
--- a/daemon/main.cpp
+++ b/daemon/main.cpp
@@ -64,22 +64,38 @@
   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);
   }
 
+  class IgnoreRibAndLogSections
+  {
+  public:
+    void
+    operator()(const std::string& filename,
+               const std::string& sectionName,
+               const ConfigSection& section,
+               bool isDryRun)
+
+    {
+      // Ignore "log" and sections beginning with "rib_" (intended for rib manager),
+      // but raise an error if we're missing a handler for an NFD section.
+
+      if (sectionName.find("rib_") == 0 || sectionName == "log")
+        {
+          // do nothing
+        }
+      else
+        {
+          // missing NFD section
+          ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
+        }
+    }
+  };
+
   void
   initializeManagement(const std::string& configFile)
   {
@@ -99,15 +115,13 @@
     m_statusServer = make_shared<StatusServer>(m_internalFace,
                                                boost::ref(*m_forwarder));
 
-    ConfigFile config;
+    ConfigFile config((IgnoreRibAndLogSections()));
     m_internalFace->getValidator().setConfigFile(config);
 
     m_forwarder->addFace(m_internalFace);
 
     m_faceManager->setConfigFile(config);
 
-    config.addSectionHandler("log", bind(std::plus<int>(), 0, 0)); // no-op
-
     // parse config file
     config.parse(configFile, true);
     config.parse(configFile, false);
@@ -217,22 +231,8 @@
   shared_ptr<FaceManager>           m_faceManager;
   shared_ptr<StrategyChoiceManager> m_strategyChoiceManager;
   shared_ptr<StatusServer>          m_statusServer;
-
-  static const std::string SUPPORTED_CONFIG_SECTIONS[];
-  static const size_t      N_SUPPORTED_CONFIG_SECTIONS;
 };
 
-const std::string Nfd::SUPPORTED_CONFIG_SECTIONS[] =
-  {
-    "log",
-    "face_system",
-    "authorizations",
-    "rib_security",
-  };
-
-const size_t Nfd::N_SUPPORTED_CONFIG_SECTIONS =
-  sizeof(SUPPORTED_CONFIG_SECTIONS) / sizeof(std::string);
-
 } // namespace nfd
 
 int