@@ -371,15 +371,17 @@ ArgsManager::ArgsManager() :
371
371
// nothing to do
372
372
}
373
373
374
- void ArgsManager::WarnForSectionOnlyArgs ()
374
+ const std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs () const
375
375
{
376
+ std::set<std::string> unsuitables;
377
+
376
378
LOCK (cs_args);
377
379
378
380
// if there's no section selected, don't worry
379
- if (m_network.empty ()) return ;
381
+ if (m_network.empty ()) return std::set<std::string> {} ;
380
382
381
383
// if it's okay to use the default section for this network, don't worry
382
- if (m_network == CBaseChainParams::MAIN) return ;
384
+ if (m_network == CBaseChainParams::MAIN) return std::set<std::string> {} ;
383
385
384
386
for (const auto & arg : m_network_only_args) {
385
387
std::pair<bool , std::string> found_result;
@@ -397,8 +399,28 @@ void ArgsManager::WarnForSectionOnlyArgs()
397
399
if (!found_result.first ) continue ;
398
400
399
401
// otherwise, issue a warning
400
- LogPrintf ( " Warning: Config setting for %s only applied on %s network when in [%s] section. \n " , arg, m_network, m_network );
402
+ unsuitables. insert ( arg);
401
403
}
404
+ return unsuitables;
405
+ }
406
+
407
+
408
+ const std::set<std::string> ArgsManager::GetUnrecognizedSections () const
409
+ {
410
+ // Section names to be recognized in the config file.
411
+ static const std::set<std::string> available_sections{
412
+ CBaseChainParams::REGTEST,
413
+ CBaseChainParams::TESTNET,
414
+ CBaseChainParams::MAIN
415
+ };
416
+ std::set<std::string> diff;
417
+
418
+ LOCK (cs_args);
419
+ std::set_difference (
420
+ m_config_sections.begin (), m_config_sections.end (),
421
+ available_sections.begin (), available_sections.end (),
422
+ std::inserter (diff, diff.end ()));
423
+ return diff;
402
424
}
403
425
404
426
void ArgsManager::SelectConfigNetwork (const std::string& network)
@@ -819,7 +841,7 @@ static std::string TrimString(const std::string& str, const std::string& pattern
819
841
return str.substr (front, end - front + 1 );
820
842
}
821
843
822
- static bool GetConfigOptions (std::istream& stream, std::string& error, std::vector<std::pair<std::string, std::string>> & options)
844
+ static bool GetConfigOptions (std::istream& stream, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::set<std::string>& sections )
823
845
{
824
846
std::string str, prefix;
825
847
std::string::size_type pos;
@@ -834,7 +856,9 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
834
856
str = TrimString (str, pattern);
835
857
if (!str.empty ()) {
836
858
if (*str.begin () == ' [' && *str.rbegin () == ' ]' ) {
837
- prefix = str.substr (1 , str.size () - 2 ) + ' .' ;
859
+ const std::string section = str.substr (1 , str.size () - 2 );
860
+ sections.insert (section);
861
+ prefix = section + ' .' ;
838
862
} else if (*str.begin () == ' -' ) {
839
863
error = strprintf (" parse error on line %i: %s, options in configuration file must be specified without leading -" , linenr, str);
840
864
return false ;
@@ -846,6 +870,9 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
846
870
return false ;
847
871
}
848
872
options.emplace_back (name, value);
873
+ if ((pos = name.rfind (' .' )) != std::string::npos) {
874
+ sections.insert (name.substr (0 , pos));
875
+ }
849
876
} else {
850
877
error = strprintf (" parse error on line %i: %s" , linenr, str);
851
878
if (str.size () >= 2 && str.substr (0 , 2 ) == " no" ) {
@@ -863,7 +890,8 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, std::string& error, boo
863
890
{
864
891
LOCK (cs_args);
865
892
std::vector<std::pair<std::string, std::string>> options;
866
- if (!GetConfigOptions (stream, error, options)) {
893
+ m_config_sections.clear ();
894
+ if (!GetConfigOptions (stream, error, options, m_config_sections)) {
867
895
return false ;
868
896
}
869
897
for (const std::pair<std::string, std::string>& option : options) {
0 commit comments