38 std::vector<std::pair<std::string, std::string>> &options,
41 std::string::size_type pos;
43 while (std::getline(stream, str)) {
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);
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) {
67 name.find(
"rpcpassword") != std::string::npos) {
69 "parse error on line %i, using # in rpcpassword can be "
70 "ambiguous and should be avoided",
74 options.emplace_back(
name, value);
75 if ((pos =
name.rfind(
'.')) != std::string::npos &&
82 if (str.size() >= 2 && str.substr(0, 2) ==
"no") {
84 "option, use %s=1 instead",
100 std::vector<std::pair<std::string, std::string>> options;
105 for (
const std::pair<std::string, std::string> &
option : options) {
107 std::string key =
option.first;
118 LogPrintf(
"Ignoring unknown configuration value %s\n",
172 for (
size_t i = std::max(
174 i < values->size(); ++i) {
196 LogPrintf(
"Included configuration file %s\n",
199 error =
"Failed to include configuration file " +
217 "warning: -includeconf cannot be used from "
218 "included files; ignoring -includeconf=%s\n",
227 error =
strprintf(
"specified data directory \"%s\" does not exist.",
236 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 GetConfigFile(const ArgsManager &args, const fs::path &configuration_file_path)
const fs::path & GetDataDirBase() const
Get data directory path.
std::optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
void ClearPathCache()
Clear cached directory paths.
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
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.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
std::string TrimString(const std::string &str, const std::string &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.