From: Bjoern Sikora Date: Tue, 12 Oct 2010 08:51:05 +0000 (+0200) Subject: Removed redundant code into separate member function. X-Git-Tag: v1.1~61 X-Git-Url: http://developer.intra2net.com/git/?p=bpdyndnsd;a=commitdiff_plain;h=38a04d549a0f88ba46a882b09d018e2d79346195 Removed redundant code into separate member function. --- diff --git a/src/config.cpp b/src/config.cpp index 84f672b..401f4c1 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -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(),"The service protocol.") - ("server",po::value(),"Servername needed for gnudip protocol.") - ("host",po::value(),"The hostname to update.") - ("login",po::value(),"Login name.") - ("password",po::value(),"Corresponding password.") - ("update_interval",po::value()->default_value(-1),"Update interval in minutes.") - ("max_updates_within_interval",po::value()->default_value(-1),"How many updates can be made in one interval.") - ("dns_cache_ttl",po::value()->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()->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()->default_value(false),"Run as system daemon.") - ("loglevel",po::value()->default_value(0),"Loglevel.") - ("syslog",po::value()->default_value(false),"Use syslog facility.") - ("enable_ipv6",po::value()->default_value(false),"Try to use IPv6.") - ("webcheck_enabled",po::value()->default_value(false),"Use webcheck url to determine actual IP address.") - ("webcheck_url",po::value()->default_value(""),"Use this URL to determine IP.") - ("webcheck_url_alt",po::value()->default_value(""),"Use this alternative URL to determine IP.") - ("webcheck_interval",po::value()->default_value(10),"The webcheck interval in minutes.") - ("http_proxy",po::value(),"Use this proxy for all http requests.") - ("http_proxy_port",po::value(),"Port of the proxy.") - ("external_warning_log",po::value()->default_value(""),"External programm to pass warning log messages to.") - ("external_warning_level",po::value()->default_value(0),"Warning messages of which loglevel should be passed to external programm.") - ("external_log_only_once",po::value()->default_value(false),"Log the same external message only once until next reload or restart.") - ("start_offline",po::value()->default_value(false),"Start in offline mode.") - ("dialup_mode",po::value()->default_value(false),"Enable dialup mode (sleep periods between network traffic)") - ("dialup_burst_period_seconds",po::value()->default_value(120),"Seconds of normal operation before entering dialup mode") - ("dialup_sleep_seconds",po::value()->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()->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()->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. diff --git a/src/config.hpp b/src/config.hpp index 9c94754..a5b75f3 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -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: