util, transport: add configuration file support and make default unix socket configurable
add sample library configuration file
refs: #1364
Change-Id: I3cb36d078aa3f0b0a50d9a83a521e95448df0a93
diff --git a/src/transport/unix-transport.cpp b/src/transport/unix-transport.cpp
index 33fad1c..ad6db2c 100644
--- a/src/transport/unix-transport.cpp
+++ b/src/transport/unix-transport.cpp
@@ -13,14 +13,6 @@
namespace ndn {
-UnixTransport::UnixTransport()
-{
- if (std::getenv("NFD") != 0)
- m_unixSocket = "/var/run/nfd.sock";
- else
- m_unixSocket = "/tmp/.ndnd.sock";
-}
-
UnixTransport::UnixTransport(const std::string& unixSocket)
: m_unixSocket(unixSocket)
{
@@ -30,6 +22,48 @@
{
}
+std::string
+UnixTransport::getDefaultSocketName(const ConfigFile& config)
+{
+ const ConfigFile::Parsed& parsed = config.getParsedConfiguration();
+ try
+ {
+ return parsed.get<std::string>("unix_socket");
+ }
+ catch (const boost::property_tree::ptree_bad_path& error)
+ {
+ // unix_socket not present, continue
+ }
+ catch (const boost::property_tree::ptree_bad_data& error)
+ {
+ throw ConfigFile::Error(error.what());
+ }
+
+ // no unix_socket specified so the default socket name
+ // depends on the protocol we're using
+ try
+ {
+ const std::string protocol = parsed.get<std::string>("protocol");
+ if (protocol == "ndnd-tlv-0.7")
+ {
+ return "/tmp/.ndnd.sock";
+ }
+ }
+ catch (boost::property_tree::ptree_bad_path& error)
+ {
+ return "/var/run/nfd.sock";
+ }
+ catch (boost::property_tree::ptree_bad_data& error)
+ {
+ throw ConfigFile::Error(error.what());
+ }
+
+ // A we made here, then there's no unix_socket specified in the configuration
+ // file. A protocol is present, but it's not ndnd.
+ // Assume the default nfd.sock location.
+ return "/var/run/nfd.sock";
+}
+
void
UnixTransport::connect(boost::asio::io_service& ioService,
const ReceiveCallback& receiveCallback)