face+security: Introduce environment variables to set/override transport, pib, and tpm configurations.

- NDN_CLIENT_TRANSPORT: equivalent of transport in client.conf
- NDN_CLIENT_PIB: equivalent of pib in client.conf
- NDN_CLIENT_TPM: equivalent of tpm in client.conf

Whenever an environment variable is set, it takes precedence over any
values specified in the configuration file.

Change-Id: I44c2347168616387a0489b6bf5c2c3a12db29863
Refs: #2925, #2514
diff --git a/src/transport/tcp-transport.cpp b/src/transport/tcp-transport.cpp
index afde1e0..20952ab 100644
--- a/src/transport/tcp-transport.cpp
+++ b/src/transport/tcp-transport.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2015 Regents of the University of California.
+ * Copyright (c) 2013-2016 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -38,27 +38,28 @@
 }
 
 shared_ptr<TcpTransport>
-TcpTransport::create(const ConfigFile& config)
+TcpTransport::create(const std::string& uri)
 {
-  const auto hostAndPort(getDefaultSocketHostAndPort(config));
+  const auto hostAndPort(getSocketHostAndPortFromUri(uri));
   return make_shared<TcpTransport>(hostAndPort.first, hostAndPort.second);
 }
 
 std::pair<std::string, std::string>
-TcpTransport::getDefaultSocketHostAndPort(const ConfigFile& config)
+TcpTransport::getSocketHostAndPortFromUri(const std::string& uriString)
 {
-  const ConfigFile::Parsed& parsed = config.getParsedConfiguration();
-
   std::string host = "localhost";
   std::string port = "6363";
 
+  if (uriString.empty()) {
+    return {host, port};
+  }
+
   try {
-    const util::FaceUri uri(parsed.get<std::string>("transport", "tcp://" + host));
+    const util::FaceUri uri(uriString);
 
     const std::string scheme = uri.getScheme();
     if (scheme != "tcp" && scheme != "tcp4" && scheme != "tcp6") {
-      BOOST_THROW_EXCEPTION(Transport::Error("Cannot create TcpTransport from \"" +
-                                             scheme + "\" URI"));
+      BOOST_THROW_EXCEPTION(Error("Cannot create TcpTransport from \"" + scheme + "\" URI"));
     }
 
     if (!uri.getHost().empty()) {
@@ -70,7 +71,7 @@
     }
   }
   catch (const util::FaceUri::Error& error) {
-    BOOST_THROW_EXCEPTION(ConfigFile::Error(error.what()));
+    BOOST_THROW_EXCEPTION(Error(error.what()));
   }
 
   return {host, port};
diff --git a/src/transport/tcp-transport.hpp b/src/transport/tcp-transport.hpp
index 0ddd1a9..b0b5124 100644
--- a/src/transport/tcp-transport.hpp
+++ b/src/transport/tcp-transport.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2014 Regents of the University of California.
+ * Copyright (c) 2013-2016 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -62,13 +62,18 @@
   virtual void
   send(const Block& header, const Block& payload);
 
+  /**
+   * @brief Create transport with parameters defined in URI
+   *
+   * @throws Transport::Error if incorrect URI or unsupported protocol is specified
+   */
   static shared_ptr<TcpTransport>
-  create(const ConfigFile& config);
+  create(const std::string& uri);
 
 NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
 
   static std::pair<std::string, std::string>
-  getDefaultSocketHostAndPort(const ConfigFile& config);
+  getSocketHostAndPortFromUri(const std::string& uri);
 
 private:
   std::string m_host;
diff --git a/src/transport/unix-transport.cpp b/src/transport/unix-transport.cpp
index 6b86a34..0c63960 100644
--- a/src/transport/unix-transport.cpp
+++ b/src/transport/unix-transport.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2015 Regents of the University of California.
+ * Copyright (c) 2013-2016 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -39,46 +39,38 @@
 }
 
 std::string
-UnixTransport::getDefaultSocketName(const ConfigFile& config)
+UnixTransport::getSocketNameFromUri(const std::string& uriString)
 {
-  const ConfigFile::Parsed& parsed = config.getParsedConfiguration();
-
-  try
-    {
-      const util::FaceUri uri(parsed.get<std::string>("transport"));
-
-      if (uri.getScheme() != "unix")
-        {
-          BOOST_THROW_EXCEPTION(Transport::Error("Cannot create UnixTransport from \"" +
-                                                 uri.getScheme() + "\" URI"));
-        }
-
-      if (!uri.getPath().empty())
-        {
-          return uri.getPath();
-        }
-    }
-  catch (const boost::property_tree::ptree_bad_path& error)
-    {
-      // no transport specified
-    }
-  catch (const boost::property_tree::ptree_bad_data& error)
-    {
-      BOOST_THROW_EXCEPTION(ConfigFile::Error(error.what()));
-    }
-  catch (const util::FaceUri::Error& error)
-    {
-      BOOST_THROW_EXCEPTION(ConfigFile::Error(error.what()));
-    }
-
   // Assume the default nfd.sock location.
-  return "/var/run/nfd.sock";
+  std::string path = "/var/run/nfd.sock";
+
+  if (uriString.empty()) {
+    return path;
+  }
+
+  try {
+    const util::FaceUri uri(uriString);
+
+    if (uri.getScheme() != "unix") {
+      BOOST_THROW_EXCEPTION(Error("Cannot create UnixTransport from \"" +
+                                  uri.getScheme() + "\" URI"));
+    }
+
+    if (!uri.getPath().empty()) {
+      path = uri.getPath();
+    }
+  }
+  catch (const util::FaceUri::Error& error) {
+    BOOST_THROW_EXCEPTION(Error(error.what()));
+  }
+
+  return path;
 }
 
 shared_ptr<UnixTransport>
-UnixTransport::create(const ConfigFile& config)
+UnixTransport::create(const std::string& uri)
 {
-  return make_shared<UnixTransport>(getDefaultSocketName(config));
+  return make_shared<UnixTransport>(getSocketNameFromUri(uri));
 }
 
 void
@@ -131,4 +123,4 @@
   m_impl->resume();
 }
 
-}
+} // namespace ndn
diff --git a/src/transport/unix-transport.hpp b/src/transport/unix-transport.hpp
index 5a73047..6d16c26 100644
--- a/src/transport/unix-transport.hpp
+++ b/src/transport/unix-transport.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2014 Regents of the University of California.
+ * Copyright (c) 2013-2016 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -69,18 +69,18 @@
   virtual void
   send(const Block& header, const Block& payload);
 
+  /**
+   * @brief Create transport with parameters defined in URI
+   *
+   * @throws Transport::Error if incorrect URI or unsupported protocol is specified
+   */
   static shared_ptr<UnixTransport>
-  create(const ConfigFile& config);
+  create(const std::string& uri);
 
 NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
-  /**
-   * Determine the default NFD unix socket
-   *
-   * @returns transport value if present in config, else /var/run/nfd.sock
-   * @throws ConfigFile::Error if fail to parse value of a present "transport" field
-   */
+
   static std::string
-  getDefaultSocketName(const ConfigFile& config);
+  getSocketNameFromUri(const std::string& uri);
 
 private:
   std::string m_unixSocket;