*/
Config::Config(Logger::Ptr _log)
: Log(new Logger)
- , Daemon_mode(false)
+ , DaemonMode(false)
, Loglevel(0)
, Syslog(false)
- , Config_path("/etc/bpdyndnsd")
+ , ConfigPath("/etc/bpdyndnsd")
{
// initialize Logger
Log = _log;
// Define valid command line parameters
Options_descriptionPtr _opt_desc_cmd(new po::options_description("Command line options"));
- Opt_desc_cmd = _opt_desc_cmd;
+ OptDescCmd = _opt_desc_cmd;
_opt_desc_cmd.reset();
- Opt_desc_cmd->add(opt_desc_cmd_only);
- Opt_desc_cmd->add(opt_desc_generic);
- Opt_desc_cmd->add(opt_desc_service);
+ OptDescCmd->add(opt_desc_cmd_only);
+ OptDescCmd->add(opt_desc_generic);
+ OptDescCmd->add(opt_desc_service);
// Define valid config file options
Options_descriptionPtr _opt_desc_conf_main(new po::options_description("Config file options"));
- Opt_desc_conf_main = _opt_desc_conf_main;
+ OptDescConfMain = _opt_desc_conf_main;
_opt_desc_conf_main.reset();
- Opt_desc_conf_main->add(opt_desc_generic);
+ OptDescConfMain->add(opt_desc_generic);
// Define valid service file options
Options_descriptionPtr _opt_desc_conf_service(new po::options_description("Service file options"));
- Opt_desc_conf_service = _opt_desc_conf_service;
+ OptDescConfService = _opt_desc_conf_service;
_opt_desc_conf_service.reset();
- Opt_desc_conf_service->add(opt_desc_service);
+ OptDescConfService->add(opt_desc_service);
}
/**
- * This function serializes all Service objects in Services and Old_services (where the update Timeout isn't expired) into a specified file.
+ * This function serializes all Service objects in Services and OldServices (where the update Timeout isn't expired) into a specified file.
* @return 0 if all is fine, -1 otherwise.
*/
int Config::serialize_services()
int current_time = time(NULL);
- BOOST_FOREACH(Service::Ptr service, Old_services)
+ BOOST_FOREACH(Service::Ptr service, OldServices)
{
if ( ( service->get_lastupdated() + service->get_timeout() ) >= current_time ) // Update Timeout of service isn't expired.
service_holder->add_service(service);
BOOST_FOREACH(Service::Ptr old_service, _old_services)
{
// Put the deserialized service into the Old_service member list.
- Old_services.push_back(old_service);
+ OldServices.push_back(old_service);
Log->print_service_object("Deserialized following Service object:", old_service->get_protocol(), old_service->get_hostname(), old_service->get_login() ,old_service->get_password() ,old_service->get_actual_ip(), old_service->get_lastupdated());
}
BOOST_FOREACH(Service::Ptr service, Services)
{
- BOOST_FOREACH(Service::Ptr old_service, Old_services)
+ BOOST_FOREACH(Service::Ptr old_service, OldServices)
{
if ( *service == *old_service )
{
}
}
}
- //TODO: debug output of Old_services (is element really removed from list if values were adopted???)
+ //TODO: debug output of OldServices (is element really removed from list if values were adopted???)
Log->print_deserialized_objects_success();
}
else
{
try
{
- po::store(po::parse_command_line(argc, argv, *this->Opt_desc_cmd), Variables_map);
- po::notify(Variables_map);
+ po::store(po::parse_command_line(argc, argv, *this->OptDescCmd), VariablesMap);
+ po::notify(VariablesMap);
- if ( Variables_map.count("help") )
+ if ( VariablesMap.count("help") )
{
- Log->print_usage(Opt_desc_cmd);
+ Log->print_usage(OptDescCmd);
return 1;
}
- else if ( Variables_map.count("version") )
+ else if ( VariablesMap.count("version") )
{
Log->print_version();
return 1;
}
// Create a service object if all needed options are set on the command line
- if ( Variables_map.count("protocol") && Variables_map.count("host") && Variables_map.count("login") && Variables_map.count("password") )
+ if ( VariablesMap.count("protocol") && VariablesMap.count("host") && VariablesMap.count("login") && VariablesMap.count("password") )
{
// Get the cmd parameter values for protocol host login and password
- string protocol = Variables_map["protocol"].as<string>();
- string host = Variables_map["host"].as<string>();
- string login = Variables_map["login"].as<string>();
- string password = Variables_map["password"].as<string>();
+ string protocol = VariablesMap["protocol"].as<string>();
+ string host = VariablesMap["host"].as<string>();
+ string login = VariablesMap["login"].as<string>();
+ string password = VariablesMap["password"].as<string>();
//TODO: convert protocol option to lowercase
else
return 1;
}
- else if ( Variables_map.count("protocol") || Variables_map.count("host") || Variables_map.count("login") || Variables_map.count("password") )
+ else if ( VariablesMap.count("protocol") || VariablesMap.count("host") || VariablesMap.count("login") || VariablesMap.count("password") )
{
Log->print_missing_cmd_service_option();
- Log->print_usage(Opt_desc_cmd);
+ Log->print_usage(OptDescCmd);
return 1;
}
- if ( Variables_map.count("config") )
+ if ( VariablesMap.count("config") )
{
- fs::path full_config_path = fs::system_complete(fs::path(Variables_map["config"].as<string>()));
- Config_path = full_config_path.string();
+ fs::path full_config_path = fs::system_complete(fs::path(VariablesMap["config"].as<string>()));
+ ConfigPath = full_config_path.string();
if ( !fs::exists(full_config_path) || !fs::is_directory(full_config_path) )
{
// Config path doesn't exist or is not a directory
- Log->print_error_config_path(Config_path);
+ Log->print_error_config_path(ConfigPath);
return 1;
}
}
- if ( Variables_map.count("loglevel") )
- Loglevel = Variables_map["loglevel"].as<int>();
+ if ( VariablesMap.count("loglevel") )
+ Loglevel = VariablesMap["loglevel"].as<int>();
- if ( Variables_map.count("syslog") )
- Syslog = Variables_map["syslog"].as<bool>();
+ if ( VariablesMap.count("syslog") )
+ Syslog = VariablesMap["syslog"].as<bool>();
}
catch(po::unknown_option e)
{
Log->print_unknown_cmd_option(e.what());
- Log->print_usage(Opt_desc_cmd);
+ Log->print_usage(OptDescCmd);
return 1;
}
return 0;
try
{
po::variables_map vm;
- po::parsed_options parsed_service_options = po::parse_config_file(service_config_file,*this->Opt_desc_conf_service,true);
+ po::parsed_options parsed_service_options = po::parse_config_file(service_config_file,*this->OptDescConfService,true);
po::store(parsed_service_options,vm);
po::notify(vm);
{
try
{
- po::parsed_options parsed_main_options = po::parse_config_file(main_config_file,*this->Opt_desc_conf_main,true);
- po::store(parsed_main_options,Variables_map);
- po::notify(Variables_map);
+ po::parsed_options parsed_main_options = po::parse_config_file(main_config_file,*this->OptDescConfMain,true);
+ po::store(parsed_main_options,VariablesMap);
+ po::notify(VariablesMap);
- if(Variables_map.count("daemon_mode") && Variables_map.count("loglevel") && Variables_map.count("syslog"))
+ if(VariablesMap.count("daemon_mode") && VariablesMap.count("loglevel") && VariablesMap.count("syslog"))
{
- Daemon_mode = Variables_map["daemon_mode"].as<bool>();
- Loglevel = Variables_map["loglevel"].as<int>();
- Syslog = Variables_map["syslog"].as<bool>();
+ DaemonMode = VariablesMap["daemon_mode"].as<bool>();
+ Loglevel = VariablesMap["loglevel"].as<int>();
+ Syslog = VariablesMap["syslog"].as<bool>();
}
}
catch ( po::unknown_option e ) // at the moment 04-08-2009 this exception is never thrown :-(
*/
int Config::load_config_from_files()
{
- fs::path full_config_path = fs::path(Config_path);
+ fs::path full_config_path = fs::path(ConfigPath);
fs::directory_iterator end_iter;
for ( fs::directory_iterator dir_itr(full_config_path) ; dir_itr != end_iter ; ++dir_itr )
}
}
// Config file successfully loaded
- Log->print_conf_loaded(Config_path);
+ Log->print_conf_loaded(ConfigPath);
return 0;
}
/**
- * Getter method for member Opt_desc_cmd.
+ * Getter method for member OptDescCmd.
* @return options_description*.
*/
Config::Options_descriptionPtr Config::get_opt_desc_cmd()
{
- return Opt_desc_cmd;
+ return OptDescCmd;
}
/**
- * Getter method for member Opt_desc_conf_main.
+ * Getter method for member OptDescConfMain.
* @return options_description*.
*/
Config::Options_descriptionPtr Config::get_opt_desc_conf_main()
{
- return Opt_desc_conf_main;
+ return OptDescConfMain;
}
/**
- * Getter method for member Opt_desc_conf_service.
+ * Getter method for member OptDescConfService.
* @return options_description*.
*/
Config::Options_descriptionPtr Config::get_opt_desc_conf_service()
{
- return Opt_desc_conf_service;
+ return OptDescConfService;
}
/**
- * Getter for member Daemon_mode.
+ * Getter for member DaemonMode.
* @return TRUE if enabled, FALSE if disabled.
*/
bool Config::get_daemon_mode()
{
- return Daemon_mode;
+ return DaemonMode;
}
*/
void Config::delete_variables_map()
{
- Variables_map.clear();
+ VariablesMap.clear();
po::variables_map _variables_map;
- Variables_map = _variables_map;
+ VariablesMap = _variables_map;
}
*/
DHS::DHS()
: Timeout(0)
- , Max_updates_per_timeout(0)
- , Updates_within_timeout(0)
+ , MaxUpdatesWithinTimeout(0)
+ , ActualUpdatesWithinTimeout(0)
{
}
*/
DHS::DHS(const string& _protocol, const string& _hostname, const string& _login, const string& _password, const Logger::Ptr& _logger, const int _lastupdated, const int _timeout, const int _max_updates_per_timeout)
: Timeout(_timeout)
- , Max_updates_per_timeout(_max_updates_per_timeout)
- , Updates_within_timeout(1)
+ , MaxUpdatesWithinTimeout(_max_updates_per_timeout)
+ , ActualUpdatesWithinTimeout(0)
{
set_protocol(_protocol);
set_hostname(_hostname);
{
ar & boost::serialization::base_object<Service>(*this);
ar & Timeout;
- ar & Max_updates_per_timeout;
- ar & Updates_within_timeout;
+ ar & MaxUpdatesWithinTimeout;
+ ar & ActualUpdatesWithinTimeout;
}
/**
- * Setter for member Max_updates_per_timeout.
- * @param _max_updates_per_timeout Value to set Max_updates_per_timeout to.
+ * Setter for member MaxUpdatesWithinTimeout.
+ * @param _max_updates_per_timeout Value to set MaxUpdatesWithinTimeout to.
*/
void DHS::set_max_updates_per_timeout(const int _max_updates_per_timeout)
{
- Max_updates_per_timeout = _max_updates_per_timeout;
+ MaxUpdatesWithinTimeout = _max_updates_per_timeout;
}
/**
- * Getter for member Max_updates_per_timeout.
- * @return Value of Max_updates_per_timeout.
+ * Getter for member MaxUpdatesWithinTimeout.
+ * @return Value of MaxUpdatesWithinTimeout.
*/
int DHS::get_max_updates_per_timeout() const
{
- return Max_updates_per_timeout;
+ return MaxUpdatesWithinTimeout;
}
*/
ODS::ODS()
: Timeout(0)
- , Max_updates_per_timeout(0)
- , Updates_within_timeout(0)
+ , MaxUpdatesWithinTimeout(0)
+ , ActualUpdatesWithinTimeout(0)
{
}
* @param _password The corresponding password.
*/
ODS::ODS(const string& _protocol, const string& _hostname, const string& _login, const string& _password, const Logger::Ptr& _logger, const int _lastupdated, const int _timeout, const int _max_updates_per_timeout)
- : Updates_within_timeout(1)
+ : Timeout(_timeout)
+ , MaxUpdatesWithinTimeout(_max_updates_per_timeout)
+ , ActualUpdatesWithinTimeout(0)
{
- Timeout = _timeout;
- Max_updates_per_timeout = _max_updates_per_timeout;
-
set_protocol(_protocol);
set_hostname(_hostname);
set_login(_login);
{
ar & boost::serialization::base_object<Service>(*this);
ar & Timeout;
- ar & Max_updates_per_timeout;
- ar & Updates_within_timeout;
+ ar & MaxUpdatesWithinTimeout;
+ ar & ActualUpdatesWithinTimeout;
}
* Setter for member Max_updates_per_timeout.
* @param _max_updates_per_timeout Value to set Max_updates_per_timeout to.
*/
-void ODS::set_max_updates_per_timeout(const int _max_updates_per_timeout)
+void ODS::set_max_updates_within_timeout(const int _max_updates_per_timeout)
{
- Max_updates_per_timeout = _max_updates_per_timeout;
+ MaxUpdatesWithinTimeout = _max_updates_per_timeout;
}
* Getter for member Max_updates_per_timeout.
* @return Value of Max_updates_per_timeout.
*/
-int ODS::get_max_updates_per_timeout()
+int ODS::get_max_updates_within_timeout()
{
- return Max_updates_per_timeout;
+ return MaxUpdatesWithinTimeout;
}