@@ -354,23 +354,19 @@ const std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const
354354 return unsuitables;
355355}
356356
357-
358- const std::set<std::string> ArgsManager::GetUnrecognizedSections () const
357+ const std::list<SectionInfo> ArgsManager::GetUnrecognizedSections () const
359358{
360359 // Section names to be recognized in the config file.
361360 static const std::set<std::string> available_sections{
362361 CBaseChainParams::REGTEST,
363362 CBaseChainParams::TESTNET,
364363 CBaseChainParams::MAIN
365364 };
366- std::set<std::string> diff;
367365
368366 LOCK (cs_args);
369- std::set_difference (
370- m_config_sections.begin (), m_config_sections.end (),
371- available_sections.begin (), available_sections.end (),
372- std::inserter (diff, diff.end ()));
373- return diff;
367+ std::list<SectionInfo> unrecognized = m_config_sections;
368+ unrecognized.remove_if ([](const SectionInfo& appeared){ return available_sections.find (appeared.m_name ) != available_sections.end (); });
369+ return unrecognized;
374370}
375371
376372void ArgsManager::SelectConfigNetwork (const std::string& network)
@@ -794,7 +790,7 @@ static std::string TrimString(const std::string& str, const std::string& pattern
794790 return str.substr (front, end - front + 1 );
795791}
796792
797- static bool GetConfigOptions (std::istream& stream, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::set<std::string >& sections)
793+ 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)
798794{
799795 std::string str, prefix;
800796 std::string::size_type pos;
@@ -810,7 +806,7 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
810806 if (!str.empty ()) {
811807 if (*str.begin () == ' [' && *str.rbegin () == ' ]' ) {
812808 const std::string section = str.substr (1 , str.size () - 2 );
813- sections.insert ( section);
809+ sections.emplace_back (SectionInfo{ section, filepath, linenr} );
814810 prefix = section + ' .' ;
815811 } else if (*str.begin () == ' -' ) {
816812 error = strprintf (" parse error on line %i: %s, options in configuration file must be specified without leading -" , linenr, str);
@@ -823,8 +819,8 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
823819 return false ;
824820 }
825821 options.emplace_back (name, value);
826- if ((pos = name.rfind (' .' )) != std::string::npos) {
827- sections.insert ( name.substr (0 , pos));
822+ if ((pos = name.rfind (' .' )) != std::string::npos && prefix. length () <= pos ) {
823+ sections.emplace_back (SectionInfo{ name.substr (0 , pos), filepath, linenr} );
828824 }
829825 } else {
830826 error = strprintf (" parse error on line %i: %s" , linenr, str);
@@ -839,12 +835,11 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
839835 return true ;
840836}
841837
842- bool ArgsManager::ReadConfigStream (std::istream& stream, std::string& error, bool ignore_invalid_keys)
838+ bool ArgsManager::ReadConfigStream (std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys)
843839{
844840 LOCK (cs_args);
845841 std::vector<std::pair<std::string, std::string>> options;
846- m_config_sections.clear ();
847- if (!GetConfigOptions (stream, error, options, m_config_sections)) {
842+ if (!GetConfigOptions (stream, filepath, error, options, m_config_sections)) {
848843 return false ;
849844 }
850845 for (const std::pair<std::string, std::string>& option : options) {
@@ -875,14 +870,15 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
875870 {
876871 LOCK (cs_args);
877872 m_config_args.clear ();
873+ m_config_sections.clear ();
878874 }
879875
880876 const std::string confPath = GetArg (" -conf" , BITCOIN_CONF_FILENAME);
881877 fsbridge::ifstream stream (GetConfigFile (confPath));
882878
883879 // ok to not have a config file
884880 if (stream.good ()) {
885- if (!ReadConfigStream (stream, error, ignore_invalid_keys)) {
881+ if (!ReadConfigStream (stream, confPath, error, ignore_invalid_keys)) {
886882 return false ;
887883 }
888884 // if there is an -includeconf in the override args, but it is empty, that means the user
@@ -913,7 +909,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
913909 for (const std::string& to_include : includeconf) {
914910 fsbridge::ifstream include_config (GetConfigFile (to_include));
915911 if (include_config.good ()) {
916- if (!ReadConfigStream (include_config, error, ignore_invalid_keys)) {
912+ if (!ReadConfigStream (include_config, to_include, error, ignore_invalid_keys)) {
917913 return false ;
918914 }
919915 LogPrintf (" Included configuration file %s\n " , to_include.c_str ());
0 commit comments