24 #include <boost/property_tree/ini_parser.hpp>
30 : m_path(findConfigFile())
44 ConfigFile::findConfigFile()
46 using namespace std::filesystem;
48 #ifdef NDN_CXX_WITH_TESTS
49 if (std::getenv(
"TEST_HOME")) {
50 path testHome(std::getenv(
"TEST_HOME"));
51 testHome /=
".ndn/client.conf";
52 if (exists(testHome)) {
53 return absolute(testHome);
58 if (std::getenv(
"HOME")) {
59 path home(std::getenv(
"HOME"));
60 home /=
".ndn/client.conf";
62 return absolute(home);
66 #ifdef NDN_CXX_SYSCONFDIR
67 path sysconfdir(NDN_CXX_SYSCONFDIR);
68 sysconfdir /=
"ndn/client.conf";
69 if (exists(sysconfdir)) {
70 return absolute(sysconfdir);
74 path etc(
"/etc/ndn/client.conf");
90 if (!m_input.good() || !m_input.is_open()) {
99 if (m_input.is_open()) {
107 if (m_path.empty()) {
108 NDN_THROW(Error(
"Failed to locate configuration file for parsing"));
110 if (!m_input.is_open() && !open()) {
111 NDN_THROW(Error(
"Failed to open configuration file for parsing"));
115 boost::property_tree::read_ini(m_input, m_config);
117 catch (
const boost::property_tree::ini_parser_error& error) {
118 NDN_THROW(Error(
"Failed to parse configuration file " + error.filename() +
119 " line " +
to_string(error.line()) +
": " + error.message()));
ConfigFile()
Locate, open, and parse a library configuration file.
boost::property_tree::ptree Parsed
std::string to_string(const errinfo_stacktrace &x)