Changeset View
Changeset View
Standalone View
Standalone View
src/util/system.cpp
Show First 20 Lines • Show All 866 Lines • ▼ Show 20 Lines | |||||
static bool | static bool | ||||
GetConfigOptions(std::istream &stream, std::string &error, | GetConfigOptions(std::istream &stream, std::string &error, | ||||
std::vector<std::pair<std::string, std::string>> &options) { | std::vector<std::pair<std::string, std::string>> &options) { | ||||
std::string str, prefix; | std::string str, prefix; | ||||
std::string::size_type pos; | std::string::size_type pos; | ||||
int linenr = 1; | int linenr = 1; | ||||
while (std::getline(stream, str)) { | while (std::getline(stream, str)) { | ||||
bool used_hash = false; | |||||
if ((pos = str.find('#')) != std::string::npos) { | if ((pos = str.find('#')) != std::string::npos) { | ||||
str = str.substr(0, pos); | str = str.substr(0, pos); | ||||
used_hash = true; | |||||
} | } | ||||
const static std::string pattern = " \t\r\n"; | const static std::string pattern = " \t\r\n"; | ||||
str = TrimString(str, pattern); | str = TrimString(str, pattern); | ||||
if (!str.empty()) { | if (!str.empty()) { | ||||
if (*str.begin() == '[' && *str.rbegin() == ']') { | if (*str.begin() == '[' && *str.rbegin() == ']') { | ||||
prefix = str.substr(1, str.size() - 2) + '.'; | prefix = str.substr(1, str.size() - 2) + '.'; | ||||
} else if (*str.begin() == '-') { | } else if (*str.begin() == '-') { | ||||
error = strprintf( | error = strprintf( | ||||
"parse error on line %i: %s, options in configuration file " | "parse error on line %i: %s, options in configuration file " | ||||
"must be specified without leading -", | "must be specified without leading -", | ||||
linenr, str); | linenr, str); | ||||
return false; | return false; | ||||
} else if ((pos = str.find('=')) != std::string::npos) { | } else if ((pos = str.find('=')) != std::string::npos) { | ||||
std::string name = | std::string name = | ||||
prefix + TrimString(str.substr(0, pos), pattern); | prefix + TrimString(str.substr(0, pos), pattern); | ||||
std::string value = TrimString(str.substr(pos + 1), pattern); | std::string value = TrimString(str.substr(pos + 1), pattern); | ||||
if (used_hash && name == "rpcpassword") { | |||||
error = strprintf( | |||||
"parse error on line %i, using # in rpcpassword can be " | |||||
"ambiguous and should be avoided", | |||||
linenr); | |||||
return false; | |||||
} | |||||
options.emplace_back(name, value); | options.emplace_back(name, value); | ||||
} else { | } else { | ||||
error = strprintf("parse error on line %i: %s", linenr, str); | error = strprintf("parse error on line %i: %s", linenr, str); | ||||
if (str.size() >= 2 && str.substr(0, 2) == "no") { | if (str.size() >= 2 && str.substr(0, 2) == "no") { | ||||
error += strprintf(", if you intended to specify a negated " | error += strprintf(", if you intended to specify a negated " | ||||
"option, use %s=1 instead", | "option, use %s=1 instead", | ||||
str); | str); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 468 Lines • Show Last 20 Lines |