Change default database path and configuration directory

Now respectively ${LOCALSTATEDIR}/lib/ndn/ndns/ndns.db
and ${SYSCONFDIR}/ndn/ndns

Refs: #4810
Change-Id: I351a6a15f8daa0a032845cb26d5d76179faa7b27
diff --git a/tools/ndns-add-rr.cpp b/tools/ndns-add-rr.cpp
index 0e664b6..605a355 100644
--- a/tools/ndns-add-rr.cpp
+++ b/tools/ndns-add-rr.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018, Regents of the University of California.
+ * Copyright (c) 2014-2019, Regents of the University of California.
  *
  * This file is part of NDNS (Named Data Networking Domain Name Service).
  * See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -17,11 +17,11 @@
  * NDNS, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "mgmt/management-tool.hpp"
-#include "ndns-label.hpp"
 #include "logger.hpp"
-#include "util/util.hpp"
+#include "ndns-label.hpp"
 #include "daemon/rrset-factory.hpp"
+#include "mgmt/management-tool.hpp"
+#include "util/util.hpp"
 
 #include <boost/program_options.hpp>
 #include <boost/filesystem.hpp>
@@ -37,13 +37,12 @@
 {
   using std::string;
   using namespace ndn;
-  using namespace ndns;
 
   int ttlInt = -1;
   int versionInt = -1;
   string zoneStr;
   Name dsk;
-  string db;
+  string db = ndns::getDefaultDatabaseFile();
   string rrLabelStr;
   string rrTypeStr;
   std::vector<std::string> content;
@@ -57,9 +56,8 @@
 
     po::options_description options("Generic Options");
     options.add_options()
-      ("help,h", "print help message")
-      ("db,b", po::value<std::string>(&db), "Set the path of NDNS server database. "
-       "Default: " DEFAULT_DATABASE_PATH "/ndns.db")
+      ("help,h",  "print this help message and exit")
+      ("db,b",    po::value<std::string>(&db)->default_value(db), "path to NDNS database file")
       ;
 
     po::options_description config("Record Options");
@@ -174,11 +172,11 @@
       tool.addRrsetFromFile(zoneName, file, ttl, dsk, ioEncoding, needResign);
     }
     else {
-      RrsetFactory rrsetFactory(db, zoneName, keyChain, dsk);
+      ndns::RrsetFactory rrsetFactory(db, zoneName, keyChain, dsk);
       rrsetFactory.checkZoneKey();
-      Rrset rrset;
+      ndns::Rrset rrset;
 
-      if (type == label::NS_RR_TYPE) {
+      if (type == ndns::label::NS_RR_TYPE) {
         ndn::DelegationList delegations;
         for (const auto& i : content) {
           std::vector<string> data;
@@ -190,7 +188,7 @@
         rrset = rrsetFactory.generateNsRrset(label,
                                              version, ttl, delegations);
       }
-      else if (type == label::TXT_RR_TYPE) {
+      else if (type == ndns::label::TXT_RR_TYPE) {
         rrset = rrsetFactory.generateTxtRrset(label,
                                               version, ttl, content);
       }
diff --git a/tools/ndns-create-zone.cpp b/tools/ndns-create-zone.cpp
index d477d4b..eaea7ee 100644
--- a/tools/ndns-create-zone.cpp
+++ b/tools/ndns-create-zone.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018, Regents of the University of California.
+ * Copyright (c) 2014-2019, Regents of the University of California.
  *
  * This file is part of NDNS (Named Data Networking Domain Name Service).
  * See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -17,10 +17,10 @@
  * NDNS, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "mgmt/management-tool.hpp"
-#include "ndns-label.hpp"
 #include "logger.hpp"
-#include "config.hpp"
+#include "ndns-label.hpp"
+#include "mgmt/management-tool.hpp"
+#include "util/util.hpp"
 
 #include <boost/program_options.hpp>
 #include <boost/filesystem.hpp>
@@ -40,16 +40,15 @@
   string dskStr;
   string kskStr;
   string dkeyStr;
-  string db;
+  string db = ndns::getDefaultDatabaseFile();
   try {
     namespace po = boost::program_options;
     po::variables_map vm;
 
     po::options_description options("Generic Options");
     options.add_options()
-      ("help,h", "print help message")
-      ("db,b", po::value<std::string>(&db), "Set the path of NDNS server database. "
-        "Default: " DEFAULT_DATABASE_PATH "/ndns.db")
+      ("help,h",  "print this help message and exit")
+      ("db,b",    po::value<std::string>(&db)->default_value(db), "path to NDNS database file")
       ;
 
     po::options_description config("Zone Options");
diff --git a/tools/ndns-daemon.cpp b/tools/ndns-daemon.cpp
index 34315b8..0414e1f 100644
--- a/tools/ndns-daemon.cpp
+++ b/tools/ndns-daemon.cpp
@@ -17,11 +17,11 @@
  * NDNS, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.hpp"
 #include "logger.hpp"
 #include "daemon/config-file.hpp"
 #include "daemon/name-server.hpp"
 #include "util/cert-helper.hpp"
+#include "util/util.hpp"
 
 #include <ndn-cxx/face.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
@@ -62,7 +62,7 @@
       BOOST_THROW_EXCEPTION(Error("zones section is empty"));
     }
 
-    std::string dbFile = DEFAULT_DATABASE_PATH "/" "ndns.db";
+    std::string dbFile = getDefaultDatabaseFile();
     auto item = section.find("dbFile");
     if (item != section.not_found()) {
       dbFile = item->second.get_value<std::string>();
@@ -70,7 +70,7 @@
     NDNS_LOG_INFO("DbFile = " << dbFile);
     m_dbMgr = make_unique<DbMgr>(dbFile);
 
-    std::string validatorConfigFile = DEFAULT_CONFIG_PATH "/" "validator.conf";
+    std::string validatorConfigFile(NDNS_CONFDIR "/validator.conf");
     item = section.find("validatorConfigFile");
     if (item != section.not_found()) {
       validatorConfigFile = item->second.get_value<std::string>();
@@ -136,7 +136,7 @@
 int
 main(int argc, char* argv[])
 {
-  std::string configFile(DEFAULT_CONFIG_PATH "/ndns.conf");
+  std::string configFile(NDNS_CONFDIR "/ndns.conf");
 
   namespace po = boost::program_options;
   po::options_description optsDesc("Options");
diff --git a/tools/ndns-delete-zone.cpp b/tools/ndns-delete-zone.cpp
index f08d020..2cefccc 100644
--- a/tools/ndns-delete-zone.cpp
+++ b/tools/ndns-delete-zone.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018, Regents of the University of California.
+ * Copyright (c) 2014-2019, Regents of the University of California.
  *
  * This file is part of NDNS (Named Data Networking Domain Name Service).
  * See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -17,9 +17,11 @@
  * NDNS, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "mgmt/management-tool.hpp"
-#include "ndns-label.hpp"
 #include "logger.hpp"
+#include "ndns-label.hpp"
+#include "mgmt/management-tool.hpp"
+#include "util/util.hpp"
+
 #include <boost/program_options.hpp>
 #include <boost/filesystem.hpp>
 #include <string>
@@ -30,16 +32,15 @@
   using std::string;
   using namespace ndn;
   string zoneStr;
-  string db;
+  string db = ndns::getDefaultDatabaseFile();
   try {
     namespace po = boost::program_options;
     po::variables_map vm;
 
     po::options_description options("Generic Options");
     options.add_options()
-      ("help,h", "print help message")
-      ("db,b", po::value<std::string>(&db), "Set the path of NDNS server database."
-        "Default: " DEFAULT_DATABASE_PATH "/ndns.db")
+      ("help,h",  "print this help message and exit")
+      ("db,b",    po::value<std::string>(&db)->default_value(db), "path to NDNS database file")
       ;
 
     po::options_description hidden("Hidden Options");
diff --git a/tools/ndns-export-certificate.cpp b/tools/ndns-export-certificate.cpp
index 6e49328..f3d7b8e 100644
--- a/tools/ndns-export-certificate.cpp
+++ b/tools/ndns-export-certificate.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018, Regents of the University of California.
+ * Copyright (c) 2014-2019, Regents of the University of California.
  *
  * This file is part of NDNS (Named Data Networking Domain Name Service).
  * See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -17,9 +17,11 @@
  * NDNS, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "mgmt/management-tool.hpp"
-#include "ndns-label.hpp"
 #include "logger.hpp"
+#include "ndns-label.hpp"
+#include "mgmt/management-tool.hpp"
+#include "util/util.hpp"
+
 #include <boost/program_options.hpp>
 #include <boost/filesystem.hpp>
 #include <string>
@@ -29,10 +31,9 @@
 {
   using std::string;
   using namespace ndn;
-  using namespace ndns;
 
   string certStr;
-  string db;
+  string db = ndns::getDefaultDatabaseFile();
   string output = "-";
   try {
     namespace po = boost::program_options;
@@ -40,9 +41,9 @@
 
     po::options_description options("Generic Options");
     options.add_options()
-      ("help,h", "print help message")
-      ("db,b", po::value<std::string>(&db), "Set the path of NDNS server database. "
-        "Default: " DEFAULT_DATABASE_PATH "/ndns.db");
+      ("help,h",  "print this help message and exit")
+      ("db,b",    po::value<std::string>(&db)->default_value(db), "path to NDNS database file")
+      ;
 
     po::options_description config("Output Options");
     config.add_options()
diff --git a/tools/ndns-get-rr.cpp b/tools/ndns-get-rr.cpp
index 1cdbdbd..dc40c37 100644
--- a/tools/ndns-get-rr.cpp
+++ b/tools/ndns-get-rr.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018, Regents of the University of California.
+ * Copyright (c) 2014-2019, Regents of the University of California.
  *
  * This file is part of NDNS (Named Data Networking Domain Name Service).
  * See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -17,9 +17,11 @@
  * NDNS, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "mgmt/management-tool.hpp"
-#include "ndns-label.hpp"
 #include "logger.hpp"
+#include "ndns-label.hpp"
+#include "mgmt/management-tool.hpp"
+#include "util/util.hpp"
+
 #include <boost/program_options.hpp>
 #include <boost/filesystem.hpp>
 #include <string>
@@ -29,10 +31,9 @@
 {
   using std::string;
   using namespace ndn;
-  using namespace ndns;
 
   string zoneStr;
-  string db;
+  string db = ndns::getDefaultDatabaseFile();
   string rrLabelStr;
   string rrTypeStr;
   try {
@@ -41,9 +42,8 @@
 
     po::options_description options("Generic Options");
     options.add_options()
-      ("help,h", "print help message")
-      ("db,b", po::value<std::string>(&db), "Set the path of NDNS server database. "
-        "Default: " DEFAULT_DATABASE_PATH "/ndns.db")
+      ("help,h",  "print this help message and exit")
+      ("db,b",    po::value<std::string>(&db)->default_value(db), "path to NDNS database file")
       ;
 
     po::options_description hidden("Hidden Options");
diff --git a/tools/ndns-list-all-zones.cpp b/tools/ndns-list-all-zones.cpp
index 126cbed..676815d 100644
--- a/tools/ndns-list-all-zones.cpp
+++ b/tools/ndns-list-all-zones.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018, Regents of the University of California.
+ * Copyright (c) 2014-2019, Regents of the University of California.
  *
  * This file is part of NDNS (Named Data Networking Domain Name Service).
  * See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -17,9 +17,11 @@
  * NDNS, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "mgmt/management-tool.hpp"
-#include "ndns-label.hpp"
 #include "logger.hpp"
+#include "ndns-label.hpp"
+#include "mgmt/management-tool.hpp"
+#include "util/util.hpp"
+
 #include <boost/program_options.hpp>
 #include <boost/filesystem.hpp>
 #include <string>
@@ -30,19 +32,17 @@
 {
   using std::string;
   using namespace ndn;
-  using namespace ndns;
 
   string zoneStr;
-  string db;
+  string db = ndns::getDefaultDatabaseFile();
   try {
     namespace po = boost::program_options;
     po::variables_map vm;
 
     po::options_description options("Generic Options");
     options.add_options()
-      ("help,h", "print help message")
-      ("db,b", po::value<std::string>(&db), "Set the path of NDNS server database. "
-        "Default: " DEFAULT_DATABASE_PATH "/ndns.db")
+      ("help,h",  "print this help message and exit")
+      ("db,b",    po::value<std::string>(&db)->default_value(db), "path to NDNS database file")
       ;
 
     po::positional_options_description postion;
diff --git a/tools/ndns-list-zone.cpp b/tools/ndns-list-zone.cpp
index d6738f5..840997e 100644
--- a/tools/ndns-list-zone.cpp
+++ b/tools/ndns-list-zone.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018, Regents of the University of California.
+ * Copyright (c) 2014-2019, Regents of the University of California.
  *
  * This file is part of NDNS (Named Data Networking Domain Name Service).
  * See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -17,9 +17,11 @@
  * NDNS, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "mgmt/management-tool.hpp"
-#include "ndns-label.hpp"
 #include "logger.hpp"
+#include "ndns-label.hpp"
+#include "mgmt/management-tool.hpp"
+#include "util/util.hpp"
+
 #include <boost/program_options.hpp>
 #include <boost/filesystem.hpp>
 #include <string>
@@ -30,10 +32,9 @@
 {
   using std::string;
   using namespace ndn;
-  using namespace ndns;
 
   string zoneStr;
-  string db;
+  string db = ndns::getDefaultDatabaseFile();
   bool printRaw = false;
   try {
     namespace po = boost::program_options;
@@ -41,9 +42,9 @@
 
     po::options_description options("Generic Options");
     options.add_options()
-      ("help,h", "print help message")
-      ("db,b", po::value<std::string>(&db), "Set the path of NDNS server database. "
-        "Default: " DEFAULT_DATABASE_PATH "/ndns.db");
+      ("help,h",  "print this help message and exit")
+      ("db,b",    po::value<std::string>(&db)->default_value(db), "path to NDNS database file")
+      ;
 
     po::options_description config("Output Options");
     config.add_options()
diff --git a/tools/ndns-remove-rr.cpp b/tools/ndns-remove-rr.cpp
index cdaf846..dfb072c 100644
--- a/tools/ndns-remove-rr.cpp
+++ b/tools/ndns-remove-rr.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018, Regents of the University of California.
+ * Copyright (c) 2014-2019, Regents of the University of California.
  *
  * This file is part of NDNS (Named Data Networking Domain Name Service).
  * See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -17,9 +17,11 @@
  * NDNS, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "mgmt/management-tool.hpp"
-#include "ndns-label.hpp"
 #include "logger.hpp"
+#include "ndns-label.hpp"
+#include "mgmt/management-tool.hpp"
+#include "util/util.hpp"
+
 #include <boost/program_options.hpp>
 #include <boost/filesystem.hpp>
 #include <string>
@@ -29,10 +31,9 @@
 {
   using std::string;
   using namespace ndn;
-  using namespace ndns;
 
   string zoneStr;
-  string db;
+  string db = ndns::getDefaultDatabaseFile();
   string rrLabelStr;
   string rrTypeStr;
   try {
@@ -41,9 +42,9 @@
 
     po::options_description options("Generic Options");
     options.add_options()
-      ("help,h", "print help message")
-      ("db,b", po::value<std::string>(&db), "Set the path of NDNS server database. "
-        "Default: " DEFAULT_DATABASE_PATH "/ndns.db");
+      ("help,h",  "print this help message and exit")
+      ("db,b",    po::value<std::string>(&db)->default_value(db), "path to NDNS database file")
+      ;
 
     po::options_description hidden("Hidden Options");
     hidden.add_options()