17 CONFIG_FILE_NETWORK_SECTION,
18 CONFIG_FILE_DEFAULT_SECTION
27 template <
typename Fn>
28 static void MergeSettings(
const Settings &settings,
29 const std::string §ion,
30 const std::string &
name, Fn &&fn) {
44 if (!section.empty()) {
48 Source::CONFIG_FILE_NETWORK_SECTION);
55 fn(
SettingsSpan(*values), Source::CONFIG_FILE_DEFAULT_SECTION);
62 std::map<std::string, SettingsValue> &values,
63 std::vector<std::string> &errors) {
74 if (!file.is_open()) {
81 if (!in.
read(std::string{std::istreambuf_iterator<char>(file),
82 std::istreambuf_iterator<char>()})) {
83 errors.emplace_back(
strprintf(
"Unable to parse settings file %s",
89 errors.emplace_back(
strprintf(
"Failed reading settings file %s",
98 strprintf(
"Found non-object value %s in settings file %s",
103 const std::vector<std::string> &in_keys = in.
getKeys();
104 const std::vector<SettingsValue> &in_values = in.
getValues();
105 for (
size_t i = 0; i < in_keys.size(); ++i) {
106 auto inserted = values.emplace(in_keys[i], in_values[i]);
107 if (!inserted.second) {
109 strprintf(
"Found duplicate key %s in settings file %s",
113 return errors.empty();
117 const std::map<std::string, SettingsValue> &values,
118 std::vector<std::string> &errors) {
120 for (
const auto &value : values) {
121 out.
__pushKV(value.first, value.second);
127 strprintf(
"Error: Unable to open settings file %s for writing",
131 file << out.
write( 1, 4) << std::endl;
137 const std::string &
name,
138 bool ignore_default_section_config,
139 bool get_chain_name) {
150 const bool never_ignore_negated_setting = span.
last_negated();
157 const bool reverse_precedence =
158 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
159 source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
168 const bool skip_negated_command_line = get_chain_name;
175 if (ignore_default_section_config &&
176 source == Source::CONFIG_FILE_DEFAULT_SECTION &&
177 !never_ignore_negated_setting) {
187 result = reverse_precedence ? span.
begin()[0] : span.
end()[-1];
198 const std::string §ion,
199 const std::string &
name,
200 bool ignore_default_section_config) {
201 std::vector<SettingsValue> result;
204 bool prev_negated_empty =
false;
214 const bool add_zombie_config_values =
215 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
216 source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
220 if (ignore_default_section_config &&
221 source == Source::CONFIG_FILE_DEFAULT_SECTION) {
227 if (!done || add_zombie_config_values) {
228 for (
const auto &value : span) {
229 if (value.isArray()) {
230 result.insert(result.end(), value.getValues().begin(),
231 value.getValues().end());
233 result.push_back(value);
244 prev_negated_empty |= span.
last_negated() && result.empty();
250 const std::string §ion,
251 const std::string &
name) {
252 bool has_default_section_setting =
false;
253 bool has_other_setting =
false;
258 }
else if (
source == Source::CONFIG_FILE_DEFAULT_SECTION) {
259 has_default_section_setting =
true;
261 has_other_setting =
true;
267 return has_default_section_setting && !has_other_setting;
285 for (
size_t i =
size; i > 0; --i) {
286 if (
data[i - 1].isFalse()) {
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
void __pushKV(const std::string &key, const UniValue &val)
const std::vector< UniValue > & getValues() const
const std::vector< std::string > & getKeys() const
bool read(const char *raw, size_t len)
Path class wrapper to prepare application code for transition from boost::filesystem library to std::...
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to byte string.
std::vector< SettingsValue > GetSettingsList(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config)
Get combined setting value similar to GetSetting(), except if setting was specified multiple times,...
bool ReadSettings(const fs::path &path, std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Read settings file.
bool OnlyHasDefaultSectionSetting(const Settings &settings, const std::string §ion, const std::string &name)
Return true if a setting is set in the default config file section, and not overridden by a higher pr...
bool WriteSettings(const fs::path &path, const std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Write settings file.
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
SettingsValue GetSetting(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config, bool get_chain_name)
Get settings value from combined sources: forced settings, command line arguments,...
std::map< std::string, SettingsValue > rw_settings
Map of setting name to read-write file setting value.
std::map< std::string, SettingsValue > forced_settings
Map of setting name to forced setting value.
std::map< std::string, std::map< std::string, std::vector< SettingsValue > > > ro_config
Map of config section name and setting name to list of config file values.
std::map< std::string, std::vector< SettingsValue > > command_line_options
Map of setting name to list of command line values.
Accessor for list of settings that skips negated values when iterated over.
size_t negated() const
Number of negated values.
const SettingsValue * end() const
Pointer to end of values.
bool empty() const
True if there are any non-negated values.
const SettingsValue * data
bool last_negated() const
True if the last value is negated.
const SettingsValue * begin() const
Pointer to first non-negated value.