From: Bjoern Sikora Date: Mon, 21 Sep 2009 09:53:20 +0000 (+0200) Subject: Bugfix: Catch also generic program_options error. X-Git-Tag: v1.1~172 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=c1b8cb7907351b5c0fd87b2e246b92d90d5ae227;p=bpdyndnsd Bugfix: Catch also generic program_options error. Don't use pointer to std::list, make a copy. --- diff --git a/src/config.cpp b/src/config.cpp index 8ca4025..3ab375b 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -242,6 +242,12 @@ int Config::parse_cmd_line(int argc, char *argv[]) Log->print_usage(OptDescCmd); return -1; } + catch( po::error e ) + { + Log->print_error_parsing_cmd(e.what()); + Log->print_usage(OptDescCmd); + return -1; + } return 0; } @@ -350,7 +356,7 @@ int Config::load_service_config_file(const string& full_filename) string protocol = vm["protocol"].as(); string host = vm["host"].as(); string login = vm["login"].as(); - string password = vm["password"].as(); + string password = vm["password"].as(); protocol = ba::to_lower_copy(protocol); @@ -393,12 +399,18 @@ int Config::load_service_config_file(const string& full_filename) Log->print_unknown_service_conf_option(full_filename,e.what()); return -1; } - catch(po::multiple_occurrences e) + catch( po::multiple_occurrences e ) { service_config_file.close(); Log->print_multiple_service_conf_option(full_filename,e.what()); return -1; } + catch( po::error e ) + { + service_config_file.close(); + Log->print_error_parsing_config_file(full_filename,e.what()); + return -1; + } service_config_file.close(); } else diff --git a/src/logger.cpp b/src/logger.cpp index bf8a58a..5986e70 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -659,7 +659,7 @@ void Logger::print_deserialized_objects_success() const * @param actual_ip Service's actual_ip. * @param lastupdated Service's lastupdated. */ -void Logger::print_service_object(const string& message, const string& protocol, const string& hostname, const string& login, const string& password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl , const string& actual_ip, list* lastupdated) const +void Logger::print_service_object(const string& message, const string& protocol, const string& hostname, const string& login, const string& password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl , const string& actual_ip, list lastupdated) const { int level = 1; if ( level <= Loglevel ) @@ -674,7 +674,7 @@ void Logger::print_service_object(const string& message, const string& protocol, msg << "\t" << "Max Updates: " << max_updates_within_interval << endl; msg << "\t" << "DNS Cache TTL: " << dns_cache_ttl << endl; msg << "\t" << "Actual_IP: " << actual_ip << endl; - BOOST_FOREACH( int update_time, *lastupdated) + BOOST_FOREACH( int update_time, lastupdated) { msg << "\t" << "Lastupdated: " << update_time << endl; } @@ -1411,7 +1411,7 @@ void Logger::print_gnudip_requires_servername() const * An exception occured while computing the md5 sum. * @param what The exception occured. */ -void Logger::print_exception_md5_sum(const std::string& what) const +void Logger::print_exception_md5_sum(const string& what) const { int level = 0; if ( level <= Loglevel ) @@ -1427,7 +1427,7 @@ void Logger::print_exception_md5_sum(const std::string& what) const * An network exception occured. * @param what The exception occured. */ -void Logger::print_network_error(const std::string& what) const +void Logger::print_network_error(const string& what) const { int level = 0; if ( level <= Loglevel ) @@ -1444,7 +1444,7 @@ void Logger::print_network_error(const std::string& what) const * @param protocol The protocol * @param error The error */ -void Logger::print_undefined_protocol_error(const std::string& protocol, const std::string& error) const +void Logger::print_undefined_protocol_error(const string& protocol, const string& error) const { int level = 0; if ( level <= Loglevel ) @@ -1459,7 +1459,7 @@ void Logger::print_undefined_protocol_error(const std::string& protocol, const s * Error while trying to log through external program. * @param external_prog The external program called. */ -void Logger::print_error_external_logging(const std::string& external_prog) const +void Logger::print_error_external_logging(const string& external_prog) const { int level = 0; if ( level <= Loglevel ) @@ -1469,3 +1469,36 @@ void Logger::print_error_external_logging(const std::string& external_prog) cons log_notice(msg.str(),level); } } + + +/** + * Error while parsing config file. + * @param error Error occured. + * @param config_file Config file. + */ +void Logger::print_error_parsing_config_file(const string& filename, const string& error) const +{ + int level = 0; + if ( level <= Loglevel ) + { + ostringstream msg; + msg << "Error while parsing config file: " << filename << " Error: " << error << endl; + log_notice(msg.str(),level); + } +} + + +/** + * Error while parsing cmd option + * @param error Error + */ +void Logger::print_error_parsing_cmd(const string& error) const +{ + int level = 0; + if ( level <= Loglevel ) + { + ostringstream msg; + msg << "Error while parsing cmd options: " << error << endl; + log_error(msg.str(),level); + } +} diff --git a/src/logger.h b/src/logger.h index 97bec42..6381142 100644 --- a/src/logger.h +++ b/src/logger.h @@ -116,7 +116,7 @@ public: void print_deserialized_objects_success() const; - void print_service_object(const std::string& message, const std::string& protocol, 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 , const std::string& actual_ip, std::list* lastupdated) const; + void print_service_object(const std::string& message, const std::string& protocol, 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 , const std::string& actual_ip, std::list lastupdated) const; void print_exception_serialize(const std::string& exception) const; @@ -213,6 +213,10 @@ public: void print_undefined_protocol_error(const std::string& protocol, const std::string& error) const; void print_error_external_logging(const std::string& external_prog) const; + + void print_error_parsing_config_file(const std::string& filename, const std::string& error) const; + + void print_error_parsing_cmd(const std::string& error) const; }; #endif diff --git a/src/serializeservicecontainer.h b/src/serializeservicecontainer.h index b890865..85eac11 100644 --- a/src/serializeservicecontainer.h +++ b/src/serializeservicecontainer.h @@ -14,6 +14,7 @@ #include "logger.h" #include +#include #include #include diff --git a/src/service.cpp b/src/service.cpp index 7dc10e8..86ff045 100644 --- a/src/service.cpp +++ b/src/service.cpp @@ -37,27 +37,6 @@ Service::~Service() /** - * Although this is an abstract class, we need the serialize function that we can serialize derived classes through a Service *. - * @param ar Archive. - * @param version Version. - */ -/* -template -void Service::serialize(Archive & ar, const unsigned int version) -{ - // protocol and hostname are the unique identifier for each service. - ar & Protocol; - ar & Hostname; - // lastupdated and actual_ip must also be serialized, cause these are essential infos of each service. - ar & LastUpdates; - ar & ActualIP; - ar & UpdateInterval; - ar & MaxUpdatesWithinInterval; - ar & DNSCacheTTL; -} -*/ - -/** * Setter for member Protocol. * @param _protocol Value to set Protocol to. */ @@ -157,10 +136,10 @@ Logger::Ptr Service::get_logger() const } -void Service::set_last_updates(std::list* _last_updates) +void Service::set_last_updates(std::list _last_updates) { LastUpdates.clear(); - BOOST_FOREACH( int update_time, *_last_updates ) + BOOST_FOREACH( int update_time, _last_updates ) { LastUpdates.push_back(update_time); } @@ -171,9 +150,9 @@ void Service::set_last_updates(std::list* _last_updates) * Getter for member Lastupdated. * @return Value of member Lastupdated. */ -list* Service::get_last_updates() +list Service::get_last_updates() { - return &LastUpdates; + return LastUpdates; } diff --git a/src/service.h b/src/service.h index 572a600..338f33e 100644 --- a/src/service.h +++ b/src/service.h @@ -91,8 +91,8 @@ public: void set_password(const std::string& _password); std::string get_password() const; - void set_last_updates(std::list* _last_updates); - std::list* get_last_updates(); + void set_last_updates(std::list _last_updates); + std::list get_last_updates(); void set_actual_ip(const std::string& _actual_ip); std::string get_actual_ip() const; diff --git a/src/serviceholder.cpp b/src/serviceholder.cpp index 7dfbd3f..2e5c395 100644 --- a/src/serviceholder.cpp +++ b/src/serviceholder.cpp @@ -56,7 +56,7 @@ int Serviceholder::serialize_services() BOOST_FOREACH(Service::Ptr &service, OldServices) { - if ( ( service->get_last_updates()->front() + (service->get_update_interval()*60) ) >= current_time ) // UpdateInterval timeout of service isn't expired. + if ( ( service->get_last_updates().front() + (service->get_update_interval()*60) ) >= current_time ) // UpdateInterval timeout of service isn't expired. service_container->add_service(service); } diff --git a/src/updater.cpp b/src/updater.cpp index 9d055f2..7b76c0a 100644 --- a/src/updater.cpp +++ b/src/updater.cpp @@ -218,8 +218,8 @@ void Updater::update_services() int current_time = time(NULL); int lastupdated = 0; - if ( service->get_last_updates()->size() > 0 ) - lastupdated = service->get_last_updates()->front(); + if ( service->get_last_updates().size() > 0 ) + lastupdated = service->get_last_updates().front(); // If the dns cache ttl is expired or the service is updated for the first time, then get the actual ip of the dns record (this should be the IP in the last update) if ( ((lastupdated != 0) && ((lastupdated + service->get_dns_cache_ttl()) < current_time)) || (lastupdated == 0) )