31 const fs::path &configuration_file_path) {
39 std::vector<std::pair<std::string, std::string>> &options,
40 std::list<SectionInfo> §ions) {
42 std::string::size_type pos;
44 while (std::getline(stream, str)) {
45 bool used_hash =
false;
46 if ((pos = str.find(
'#')) != std::string::npos) {
47 str = str.substr(0, pos);
50 const static std::string pattern =
" \t\r\n";
53 if (*str.begin() ==
'[' && *str.rbegin() ==
']') {
54 const std::string section = str.substr(1, str.size() - 2);
55 sections.emplace_back(
SectionInfo{section, filepath, linenr});
57 }
else if (*str.begin() ==
'-') {
59 "parse error on line %i: %s, options in configuration file "
60 "must be specified without leading -",
63 }
else if ((pos = str.find(
'=')) != std::string::npos) {
66 TrimString(std::string_view{str}.substr(0, pos), pattern);
68 std::string_view{str}.substr(pos + 1), pattern);
70 name.find(
"rpcpassword") != std::string::npos) {
72 "parse error on line %i, using # in rpcpassword can be "
73 "ambiguous and should be avoided",
77 options.emplace_back(
name, value);
78 if ((pos =
name.rfind(
'.')) != std::string::npos &&
80 sections.emplace_back(
85 if (str.size() >= 2 && str.substr(0, 2) ==
"no") {
87 "option, use %s=1 instead",
99 const std::string &filepath,
101 bool ignore_invalid_keys) {
103 std::vector<std::pair<std::string, std::string>> options;
105 m_config_sections)) {
108 for (
const std::pair<std::string, std::string> &option : options) {
110 std::string key = option.first;
118 m_settings.ro_config[section][key].push_back(value);
120 if (ignore_invalid_keys) {
121 LogPrintf(
"Ignoring unknown configuration value %s\n",
125 option.first.c_str());
134 bool ignore_invalid_keys) {
137 m_settings.ro_config.clear();
138 m_config_sections.clear();
142 std::ifstream stream{conf_path};
147 ignore_invalid_keys)) {
153 bool use_conf_file{
true};
156 if (
auto *includes =
util::FindKey(m_settings.command_line_options,
161 use_conf_file =
false;
166 std::vector<std::string> conf_file_names;
168 auto add_includes = [&](
const std::string &network,
170 size_t num_values = 0;
175 for (
size_t i = std::max(
177 i < values->size(); ++i) {
178 conf_file_names.push_back((*values)[i].get_str());
180 num_values = values->size();
188 const size_t chain_includes = add_includes(chain_id);
189 const size_t default_includes = add_includes({});
191 for (
const std::string &conf_file_name : conf_file_names) {
192 std::ifstream conf_file_stream{
194 if (conf_file_stream.good()) {
196 error, ignore_invalid_keys)) {
199 LogPrintf(
"Included configuration file %s\n",
202 error =
"Failed to include configuration file " +
209 conf_file_names.clear();
210 add_includes(chain_id, chain_includes);
211 add_includes({}, default_includes);
213 if (chain_id_final != chain_id) {
216 add_includes(chain_id_final);
218 for (
const std::string &conf_file_name : conf_file_names) {
220 "warning: -includeconf cannot be used from "
221 "included files; ignoring -includeconf=%s\n",
230 error =
strprintf(
"specified data directory \"%s\" does not exist.",
231 GetArg(
"-datadir",
"").c_str());
239 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.
std::string GetChainTypeString() const
Returns the appropriate chain name string from the program arguments.
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)
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.