30 const fs::path &configuration_file_path) {
38 std::vector<std::pair<std::string, std::string>> &options,
39 std::list<SectionInfo> §ions) {
41 std::string::size_type pos;
43 while (std::getline(stream, str)) {
44 bool used_hash =
false;
45 if ((pos = str.find(
'#')) != std::string::npos) {
46 str = str.substr(0, pos);
49 const static std::string pattern =
" \t\r\n";
52 if (*str.begin() ==
'[' && *str.rbegin() ==
']') {
53 const std::string section = str.substr(1, str.size() - 2);
54 sections.emplace_back(
SectionInfo{section, filepath, linenr});
56 }
else if (*str.begin() ==
'-') {
58 "parse error on line %i: %s, options in configuration file "
59 "must be specified without leading -",
62 }
else if ((pos = str.find(
'=')) != std::string::npos) {
65 TrimString(std::string_view{str}.substr(0, pos), pattern);
67 std::string_view{str}.substr(pos + 1), pattern);
69 name.find(
"rpcpassword") != std::string::npos) {
71 "parse error on line %i, using # in rpcpassword can be "
72 "ambiguous and should be avoided",
76 options.emplace_back(
name, value);
77 if ((pos =
name.rfind(
'.')) != std::string::npos &&
79 sections.emplace_back(
84 if (str.size() >= 2 && str.substr(0, 2) ==
"no") {
86 "option, use %s=1 instead",
98 const std::string &filepath,
100 bool ignore_invalid_keys) {
102 std::vector<std::pair<std::string, std::string>> options;
104 m_config_sections)) {
107 for (
const std::pair<std::string, std::string> &option : options) {
109 std::string key = option.first;
117 m_settings.ro_config[section][key].push_back(value);
119 if (ignore_invalid_keys) {
120 LogPrintf(
"Ignoring unknown configuration value %s\n",
124 option.first.c_str());
133 bool ignore_invalid_keys) {
136 m_settings.ro_config.clear();
137 m_config_sections.clear();
141 std::ifstream stream{conf_path};
146 ignore_invalid_keys)) {
152 bool use_conf_file{
true};
155 if (
auto *includes =
util::FindKey(m_settings.command_line_options,
160 use_conf_file =
false;
165 std::vector<std::string> conf_file_names;
167 auto add_includes = [&](
const std::string &network,
169 size_t num_values = 0;
174 for (
size_t i = std::max(
176 i < values->size(); ++i) {
177 conf_file_names.push_back((*values)[i].get_str());
179 num_values = values->size();
187 const size_t chain_includes = add_includes(chain_id);
188 const size_t default_includes = add_includes({});
190 for (
const std::string &conf_file_name : conf_file_names) {
191 std::ifstream conf_file_stream{
193 if (conf_file_stream.good()) {
195 error, ignore_invalid_keys)) {
198 LogPrintf(
"Included configuration file %s\n",
201 error =
"Failed to include configuration file " +
208 conf_file_names.clear();
209 add_includes(chain_id, chain_includes);
210 add_includes({}, default_includes);
212 if (chain_id_final != chain_id) {
215 add_includes(chain_id_final);
217 for (
const std::string &conf_file_name : conf_file_names) {
219 "warning: -includeconf cannot be used from "
220 "included files; ignoring -includeconf=%s\n",
229 error =
strprintf(
"specified data directory \"%s\" does not exist.",
230 GetArg(
"-datadir",
"").c_str());
238 if (path.is_absolute()) {
bool CheckValid(const std::string &key, const util::SettingsValue &val, unsigned int flags, std::string &error)
Check settings value validity according to flags.
bool CheckDataDirOption(const ArgsManager &args)
util::SettingsValue InterpretOption(std::string §ion, std::string &key, const std::string &value)
Interpret -nofoo as if the user supplied -foo=0.
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
std::optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
void ClearPathCache()
Clear cached directory paths.
fs::path GetDataDirBase() const
Get data directory path.
fs::path GetConfigFilePath() const
Return config file path (read-only)
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
bool ReadConfigStream(std::istream &stream, const std::string &filepath, std::string &error, bool ignore_invalid_keys=false)
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
static bool GetConfigOptions(std::istream &stream, const std::string &filepath, std::string &error, std::vector< std::pair< std::string, std::string > > &options, std::list< SectionInfo > §ions)
fs::path AbsPathForConfigVal(const ArgsManager &args, const fs::path &path, bool net_specific)
Most paths passed as configuration arguments are treated as relative to the datadir if they are not a...
fs::path GetConfigFile(const ArgsManager &args, const fs::path &configuration_file_path)
bool error(const char *fmt, const Args &...args)
static std::string PathToString(const path &path)
Convert path object to byte string.
static path PathFromString(const std::string &string)
Convert byte string to path object.
fs::path AbsPathJoin(const fs::path &base, const fs::path &path)
Helper function for joining two paths.
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
std::string TrimString(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
std::string_view TrimStringView(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
Accessor for list of settings that skips negated values when iterated over.
size_t negated() const
Number of negated values.
bool last_negated() const
True if the last value is negated.