| 873 | } |
| 874 | |
| 875 | 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>& sections) |
| 876 | { |
| 877 | std::string str, prefix; |
| 878 | std::string::size_type pos; |
| 879 | int linenr = 1; |
| 880 | while (std::getline(stream, str)) { |
| 881 | bool used_hash = false; |
| 882 | if ((pos = str.find('#')) != std::string::npos) { |
| 883 | str = str.substr(0, pos); |
| 884 | used_hash = true; |
| 885 | } |
| 886 | const static std::string pattern = " \t\r\n"; |
| 887 | str = TrimString(str, pattern); |
| 888 | if (!str.empty()) { |
| 889 | if (*str.begin() == '[' && *str.rbegin() == ']') { |
| 890 | const std::string section = str.substr(1, str.size() - 2); |
| 891 | sections.emplace_back(SectionInfo{section, filepath, linenr}); |
| 892 | prefix = section + '.'; |
| 893 | } else if (*str.begin() == '-') { |
| 894 | error = strprintf("parse error on line %i: %s, options in configuration file must be specified without leading -", linenr, str); |
| 895 | return false; |
| 896 | } else if ((pos = str.find('=')) != std::string::npos) { |
| 897 | std::string name = prefix + TrimString(str.substr(0, pos), pattern); |
| 898 | std::string value = TrimString(str.substr(pos + 1), pattern); |
| 899 | if (used_hash && name.find("rpcpassword") != std::string::npos) { |
| 900 | error = strprintf("parse error on line %i, using # in rpcpassword can be ambiguous and should be avoided", linenr); |
| 901 | return false; |
| 902 | } |
| 903 | options.emplace_back(name, value); |
| 904 | if ((pos = name.rfind('.')) != std::string::npos && prefix.length() <= pos) { |
| 905 | sections.emplace_back(SectionInfo{name.substr(0, pos), filepath, linenr}); |
| 906 | } |
| 907 | } else { |
| 908 | error = strprintf("parse error on line %i: %s", linenr, str); |
| 909 | if (str.size() >= 2 && str.substr(0, 2) == "no") { |
| 910 | error += strprintf(", if you intended to specify a negated option, use %s=1 instead", str); |
| 911 | } |
| 912 | return false; |
| 913 | } |
| 914 | } |
| 915 | ++linenr; |
| 916 | } |
| 917 | return true; |
| 918 | } |
| 919 | |
| 920 | bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys) |
| 921 | { |
no test coverage detected