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/face.cpp b/src/face.cpp
index 9f64aa6..51519c9 100644
--- a/src/face.cpp
+++ b/src/face.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).
*
@@ -91,32 +91,42 @@
// transport=unix:///var/run/nfd.sock
// transport=tcp://localhost:6363
- ConfigFile config;
- const auto& transportUri = config.getParsedConfiguration()
- .get_optional<std::string>("transport");
- if (!transportUri) {
+ std::string transportUri;
+
+ if (getenv("NDN_CLIENT_TRANSPORT") != nullptr) {
+ transportUri = getenv("NDN_CLIENT_TRANSPORT");
+ }
+ else {
+ ConfigFile config;
+ transportUri = config.getParsedConfiguration().get<std::string>("transport", "");
+ }
+
+ if (transportUri.empty()) {
// transport not specified, use default Unix transport.
- return UnixTransport::create(config);
+ return UnixTransport::create("");
}
std::string protocol;
try {
- util::FaceUri uri(*transportUri);
+ util::FaceUri uri(transportUri);
protocol = uri.getScheme();
+
+ if (protocol == "unix") {
+ return UnixTransport::create(transportUri);
+ }
+ else if (protocol == "tcp" || protocol == "tcp4" || protocol == "tcp6") {
+ return TcpTransport::create(transportUri);
+ }
+ else {
+ BOOST_THROW_EXCEPTION(ConfigFile::Error("Unsupported transport protocol \"" + protocol + "\""));
+ }
+ }
+ catch (const Transport::Error& error) {
+ BOOST_THROW_EXCEPTION(ConfigFile::Error(error.what()));
}
catch (const util::FaceUri::Error& error) {
BOOST_THROW_EXCEPTION(ConfigFile::Error(error.what()));
}
-
- if (protocol == "unix") {
- return UnixTransport::create(config);
- }
- else if (protocol == "tcp" || protocol == "tcp4" || protocol == "tcp6") {
- return TcpTransport::create(config);
- }
- else {
- BOOST_THROW_EXCEPTION(ConfigFile::Error("Unsupported transport protocol \"" + protocol + "\""));
- }
}
void