24 #include <boost/property_tree/ini_parser.hpp> 25 #include <boost/filesystem.hpp> 30 : m_path(findConfigFile())
41 if (m_input.is_open())
47 boost::filesystem::path
48 ConfigFile::findConfigFile()
50 using namespace boost::filesystem;
52 #ifdef NDN_CXX_HAVE_TESTS 53 if (std::getenv(
"TEST_HOME"))
55 path testHome(std::getenv(
"TEST_HOME"));
56 testHome /=
".ndn/client.conf";
59 return absolute(testHome);
62 #endif // NDN_CXX_HAVE_TESTS 64 if (std::getenv(
"HOME"))
66 path home(std::getenv(
"HOME"));
67 home /=
".ndn/client.conf";
70 return absolute(home);
74 #ifdef NDN_CXX_SYSCONFDIR 75 path sysconfdir(NDN_CXX_SYSCONFDIR);
76 sysconfdir /=
"ndn/client.conf";
78 if (exists(sysconfdir))
80 return absolute(sysconfdir);
82 #endif // NDN_CXX_SYSCONFDIR 84 path etc(
"/etc/ndn/client.conf");
103 m_input.open(m_path.c_str());
104 if (!m_input.good() || !m_input.is_open())
114 if (m_input.is_open())
126 BOOST_THROW_EXCEPTION(
Error(
"Failed to locate configuration file for parsing"));
128 else if (!m_input.is_open() && !open())
130 BOOST_THROW_EXCEPTION(
Error(
"Failed to open configuration file for parsing"));
135 boost::property_tree::read_ini(m_input, m_config);
137 catch (boost::property_tree::ini_parser_error& error)
139 std::stringstream msg;
140 msg <<
"Failed to parse configuration file";
141 msg <<
" " << m_path;
142 msg <<
" " << error.message() <<
" line " << error.line();
143 BOOST_THROW_EXCEPTION(
Error(msg.str()));
Copyright (c) 2013-2017 Regents of the University of California.
boost::property_tree::ptree Parsed
ConfigFile()
Locate, open, and parse a library configuration file.