Removed redundant code into separate member function.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Tue, 12 Oct 2010 08:51:05 +0000 (10:51 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Tue, 12 Oct 2010 09:15:48 +0000 (11:15 +0200)
src/config.cpp
src/config.hpp

index 84f672b..401f4c1 100644 (file)
@@ -59,62 +59,7 @@ Config::Config()
     , DialupBurstPeriodSeconds(120)
     , DialupSleepSeconds(10 * 60)
 {
-    // Available service description config options
-    po::options_description opt_desc_service("Service description options");
-    opt_desc_service.add_options()
-        ("protocol",po::value<string>(),"The service protocol.")
-        ("server",po::value<string>(),"Servername needed for gnudip protocol.")
-        ("host",po::value<string>(),"The hostname to update.")
-        ("login",po::value<string>(),"Login name.")
-        ("password",po::value<string>(),"Corresponding password.")
-        ("update_interval",po::value<int>()->default_value(-1),"Update interval in minutes.")
-        ("max_updates_within_interval",po::value<int>()->default_value(-1),"How many updates can be made in one interval.")
-        ("dns_cache_ttl",po::value<int>()->default_value(-1),"How long a dns record is valid.")
-    ;
-
-    // Available command line only options
-    po::options_description opt_desc_cmd_only("Command line only options");
-    opt_desc_cmd_only.add_options()
-        ("help,?","Show help.")
-        ("version,v","Show version.")
-        ("config,c",po::value<string>()->default_value("/etc/bpdyndnsd"),"Set the config path.")
-    ;
-
-     // Available generic options. Valid on cmd or in config file.
-    po::options_description opt_desc_generic("Generic config options");
-    opt_desc_generic.add_options()
-        ("daemon_mode",po::value<bool>()->default_value(false),"Run as system daemon.")
-        ("loglevel",po::value<int>()->default_value(0),"Loglevel.")
-        ("syslog",po::value<bool>()->default_value(false),"Use syslog facility.")
-        ("enable_ipv6",po::value<bool>()->default_value(false),"Try to use IPv6.")
-        ("webcheck_enabled",po::value<bool>()->default_value(false),"Use webcheck url to determine actual IP address.")
-        ("webcheck_url",po::value<string>()->default_value(""),"Use this URL to determine IP.")
-        ("webcheck_url_alt",po::value<string>()->default_value(""),"Use this alternative URL to determine IP.")
-        ("webcheck_interval",po::value<int>()->default_value(10),"The webcheck interval in minutes.")
-        ("http_proxy",po::value<string>(),"Use this proxy for all http requests.")
-        ("http_proxy_port",po::value<int>(),"Port of the proxy.")
-        ("external_warning_log",po::value<string>()->default_value(""),"External programm to pass warning log messages to.")
-        ("external_warning_level",po::value<int>()->default_value(0),"Warning messages of which loglevel should be passed to external programm.")
-        ("external_log_only_once",po::value<bool>()->default_value(false),"Log the same external message only once until next reload or restart.")
-        ("start_offline",po::value<bool>()->default_value(false),"Start in offline mode.")
-        ("dialup_mode",po::value<bool>()->default_value(false),"Enable dialup mode (sleep periods between network traffic)")
-        ("dialup_burst_period_seconds",po::value<int>()->default_value(120),"Seconds of normal operation before entering dialup mode")
-        ("dialup_sleep_seconds",po::value<int>()->default_value(10 * 60),"Seconds to sleep between network traffic")
-    ;
-
-    // Define valid command line parameters
-    OptDescCmd = Options_descriptionPtr(new po::options_description("Command line options"));
-    OptDescCmd->add(opt_desc_cmd_only);
-    OptDescCmd->add(opt_desc_generic);
-    OptDescCmd->add(opt_desc_service);
-
-    // Define valid config file options
-    OptDescConfMain = Options_descriptionPtr(new po::options_description("Config file options"));
-    OptDescConfMain->add(opt_desc_generic);
-
-    // Define valid service file options
-    OptDescConfService = Options_descriptionPtr(new po::options_description("Service file options"));
-    OptDescConfService->add(opt_desc_service);
+    define_config_options();
 }
 
 
@@ -141,6 +86,23 @@ Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder)
     , DialupBurstPeriodSeconds(120)
     , DialupSleepSeconds(10 * 60)
 {
+    define_config_options();
+}
+
+
+/**
+ * Default Destructor
+ */
+Config::~Config()
+{
+}
+
+
+/**
+* Define valid config options with default parameters.
+*/
+void Config::define_config_options()
+{
     // Available service description config options
     po::options_description opt_desc_service("Service description options");
     opt_desc_service.add_options()
@@ -162,7 +124,7 @@ Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder)
         ("config,c",po::value<string>()->default_value("/etc/bpdyndnsd"),"Set the config path.")
     ;
 
-     // Available generic options. Valid on cmd or in config file.
+    // Available generic options. Valid on cmd or in config file.
     po::options_description opt_desc_generic("Generic config options");
     opt_desc_generic.add_options()
         ("daemon_mode",po::value<bool>()->default_value(false),"Run as system daemon.")
@@ -201,14 +163,6 @@ Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder)
 
 
 /**
- * Default Destructor
- */
-Config::~Config()
-{
-}
-
-
-/**
  * Parses the command line arguments and does the needed actions.
  * @param argc Command line argument number given to main.
  * @param argv[] Pointer to command line argument array given to main.
index 9c94754..a5b75f3 100644 (file)
@@ -56,6 +56,7 @@ private:
     Service::Ptr create_service(const std::string& protocol, const std::string& server, const std::string& hostname, const std::string& login, const std::string& password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl);
     int load_main_config_file(const std::string& full_filename);
     int load_service_config_file(const std::string& full_filename);
+    void define_config_options();
 
 public: