Solved the item:
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Wed, 4 May 2011 09:41:06 +0000 (11:41 +0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Wed, 4 May 2011 09:41:06 +0000 (11:41 +0200)
- Perform a better treatment of missing configuration items, actually the
  application just crashes.

All items that are strictly required have default values, or are checked against
valid values. The last item missing was nameserver, which has a default value now.

TODO
src/config/configurationreader.cpp
src/config/configurationreader.h

diff --git a/TODO b/TODO
index 79c0ee8..7a30f9d 100644 (file)
--- a/TODO
+++ b/TODO
@@ -27,9 +27,6 @@ TODO
 Guilherme:
 - fix config parser:
 
-- Perform a better treatment of missing configuration items, actually the
-  application just crashes.
-
 - Documentation of the functions (doxygen)
 
 - Make the link down interval also configurable. Today it is possible just to
index d963fa9..0f11c1d 100644 (file)
@@ -34,6 +34,7 @@ ConfigurationReader::ConfigurationReader() :
     ConfigFileCmdDesc( "Name of the configuration file." ),
     SourceNetworkInterfaceCmdStr( "source-network-interface" ),
     SourceNetworkInterfaceCmdDesc( "The network interface from where the packets will be received and originated" ),
+    DefaultNameServer( "127.0.0.1" ),
     NameServerCmdStr( "nameserver" ),
     NameServerCmdDesc( "The local address from where the DNS query will be made." ),
     DefaultHostsDownLimit( 0 ), // no host down
@@ -169,7 +170,7 @@ options_description ConfigurationReader::get_configuration_options() const
     options_description options( "Configuration" );
     options.add_options()
         ( SourceNetworkInterfaceCmdStr.c_str(), value<string>(), SourceNetworkInterfaceCmdDesc.c_str() )
-        ( NameServerCmdStr.c_str(), value<string>(), NameServerCmdDesc.c_str() )
+        ( NameServerCmdStr.c_str(), value<string>()->default_value( DefaultNameServer ), NameServerCmdDesc.c_str() )
         ( HostsDownLimitCmdStr.c_str(), value<int>()->default_value( DefaultHostsDownLimit ), HostsDownLimitCmdDesc.c_str() )
         ( PingFailLimitCmdStr.c_str(), value<int>()->default_value( DefaultPingFailLimit ), PingFailLimitCmdDesc.c_str() )
         ( StatusNotifierCmdCmdStr.c_str(), value<string>(), StatusNotifierCmdCmdDesc.c_str() )
index f7b8e2a..68f7f43 100644 (file)
@@ -64,6 +64,7 @@ private:
     const std::string ConfigFileCmdDesc;
     const std::string SourceNetworkInterfaceCmdStr;
     const std::string SourceNetworkInterfaceCmdDesc;
+    const std::string DefaultNameServer;
     const std::string NameServerCmdStr;
     const std::string NameServerCmdDesc;
     const int DefaultHostsDownLimit;