From df76a7205da255a7924448589ed5cae5d9bd07ad Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Wed, 4 May 2011 10:22:45 +0200 Subject: [PATCH] Allowing unknown options and changed the default host down limit to 0 --- src/config/configurationreader.cpp | 26 ++++++++++++++++---------- 1 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/config/configurationreader.cpp b/src/config/configurationreader.cpp index 49d83b9..7be6ee6 100644 --- a/src/config/configurationreader.cpp +++ b/src/config/configurationreader.cpp @@ -36,7 +36,7 @@ ConfigurationReader::ConfigurationReader() : SourceNetworkInterfaceCmdDesc( "The network interface from where the packets will be received and originated" ), NameServerCmdStr( "nameserver" ), NameServerCmdDesc( "The local address from where the DNS query will be made." ), - DefaultHostsDownLimit( 1 ), // 1 host down at most + DefaultHostsDownLimit( 0 ), // no host down HostsDownLimitCmdStr( "hosts-down-limit" ), HostsDownLimitCmdDesc( "Limit of host that have to be down in order to notify." ), DefaultPingFailLimit( 50 ), // 50 pings can fail at most @@ -246,8 +246,8 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) } // [host] name - size_t hosts_names_count = 0; - if ( vm.count( HostNameCmdStr ) > 0 ) + size_t hosts_names_count = vm.count( HostNameCmdStr ); + if ( hosts_names_count > 0 ) { HostList hosts_list; @@ -263,14 +263,13 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) Config.set_hosts( hosts_list ); - hosts_names_count = hosts_names.size(); - + BOOST_ASSERT( hosts_names_count == hosts_names.size() ); BOOST_ASSERT( hosts_names_count >= static_cast( host_down_limit ) ); } // [host] interval - size_t hosts_interval_count = 0; - if ( vm.count( HostIntervalCmdStr ) > 0 ) + size_t hosts_interval_count = vm.count( HostIntervalCmdStr ); + if ( hosts_interval_count > 0 ) { HostList hosts_list = Config.get_hosts(); HostList::iterator hosts_it = hosts_list.begin(); @@ -286,7 +285,7 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) << host_interval_in_sec << endl; } - hosts_interval_count = hosts_intervals.size(); + BOOST_ASSERT( hosts_interval_count == hosts_intervals.size() ); } // TODO deal when interval for a given host was not set. use DefaultHostIntervalInSec @@ -314,7 +313,10 @@ bool ConfigurationReader::process_command_line( (void) p.add( HostNameCmdStr.c_str(), -1 ); parsed_options parsed_opt = command_line_parser( argc, argv ). - options( cmdline_options ).positional( p ).run(); + options( cmdline_options ). + positional( p ). + allow_unregistered(). + run(); store( parsed_opt, vm ); notify( vm ); @@ -330,9 +332,13 @@ bool ConfigurationReader::process_command_line( bool ConfigurationReader::process_configuration_file( variables_map &vm ) { string config_file_name = ""; - // parse the command line options to retrieve the config file name + // parse the command line options to retrieve the config file name, if the + // config-file option was not specified in the command line, it will return + // the default file if ( parse_configuration_options( vm ) ) + { config_file_name = Config.get_config_file_name(); + } return process_configuration_file( config_file_name, vm ); } -- 1.7.1