From a03fb8969ed551cb40305358889d8a367423a68f Mon Sep 17 00:00:00 2001 From: Bjoern Sikora Date: Tue, 15 Sep 2009 17:30:09 +0200 Subject: [PATCH] Generalized print_http_not_authorized to print_service_not_authorized. Added Log messages. --- src/logger.cpp | 43 ++++++++++++++++++++++++++++++++++++++----- src/logger.h | 6 +++++- src/service_dhs.cpp | 2 +- src/service_dyndns.cpp | 2 +- src/service_dyns.cpp | 2 +- src/service_easydns.cpp | 2 +- src/service_gnudip.cpp | 5 ++--- src/service_tzo.cpp | 2 +- src/service_zoneedit.cpp | 2 +- 9 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/logger.cpp b/src/logger.cpp index f265eae..c8ca7d8 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -831,7 +831,7 @@ void Logger::print_own_ipv6(const string& ip_addr_v6, const string& hostname) co */ void Logger::print_error_hostname_to_ip(const string& exception, const string& hostname) const { - int level = 1; + int level = 0; if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) { ostringstream msg; @@ -1256,18 +1256,18 @@ void Logger::print_curl_data(const string& curl_writedata_buff) const /** - * Not authorized to perform requested http operation - * @param url The requested url + * Not authorized to perform requested update operation + * @param service The requested service. * @param username Username * @param password Password */ -void Logger::print_http_not_authorized(const string& url, const string& username, const string& password) const +void Logger::print_service_not_authorized(const string& service, const string& username, const string& password) const { int level = 0; if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) { ostringstream msg; - msg << "Not authorized to perform update operation on url: " << url << " Please check username and password: " << username << ":" << password << endl; + msg << "Not authorized to perform update operation on service: " << service << " Please check username and password: " << username << ":" << password << endl; log_warning(msg.str(),level); } } @@ -1450,3 +1450,36 @@ void Logger::print_exception_md5_sum(const std::string& what) const log_error(msg.str(),level); } } + + +/** + * An network exception occured. + * @param what The exception occured. + */ +void Logger::print_network_error(const std::string& what) const +{ + int level = 0; + if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) + { + ostringstream msg; + msg << "An netowrk exception occured: " << what << endl; + log_error(msg.str(),level); + } +} + + +/** + * An undefined protocol error occured. + * @param protocol The protocol + * @param error The error + */ +void Logger::print_undefined_protocol_error(const std::string& protocol, const std::string& error) const +{ + int level = 0; + if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) + { + ostringstream msg; + msg << "An undefined protocol error occured. Protocol: " << protocol << " Error: " << error << endl; + log_error(msg.str(),level); + } +} diff --git a/src/logger.h b/src/logger.h index 7d85cdb..55cdfb3 100644 --- a/src/logger.h +++ b/src/logger.h @@ -186,7 +186,7 @@ public: void print_curl_data(const std::string& curl_writedata_buff) const; - void print_http_not_authorized(const std::string& url, const std::string& username, const std::string& password) const; + void print_service_not_authorized(const std::string& service, const std::string& username, const std::string& password) const; void print_http_status_code(const std::string& url, const long http_code) const; @@ -209,6 +209,10 @@ public: void print_gnudip_requires_servername() const; void print_exception_md5_sum(const std::string& what) const; + + void print_network_error(const std::string& what) const; + + void print_undefined_protocol_error(const std::string& protocol, const std::string& error) const; }; #endif diff --git a/src/service_dhs.cpp b/src/service_dhs.cpp index e0ac01d..337cca9 100644 --- a/src/service_dhs.cpp +++ b/src/service_dhs.cpp @@ -152,7 +152,7 @@ int ServiceDhs::perform_update(const std::string& ip) } else if ( http_status_code == 401 ) { - get_logger()->print_http_not_authorized(url,get_login(),get_password()); + get_logger()->print_service_not_authorized(url,get_login(),get_password()); } else { diff --git a/src/service_dyndns.cpp b/src/service_dyndns.cpp index 74dafb4..2748e66 100644 --- a/src/service_dyndns.cpp +++ b/src/service_dyndns.cpp @@ -120,7 +120,7 @@ int ServiceDyndns::perform_update(const std::string& ip) } else if ( curl_data == "badauth" ) { - get_logger()->print_http_not_authorized(url,get_login(),get_password()); + get_logger()->print_service_not_authorized(url,get_login(),get_password()); } else { diff --git a/src/service_dyns.cpp b/src/service_dyns.cpp index 00e85fc..c113027 100644 --- a/src/service_dyns.cpp +++ b/src/service_dyns.cpp @@ -125,7 +125,7 @@ int ServiceDyns::perform_update(const std::string& ip) } else if ( status_code == "401" ) { - get_logger()->print_http_not_authorized(url,get_login(),get_password()); + get_logger()->print_service_not_authorized(url,get_login(),get_password()); } else { diff --git a/src/service_easydns.cpp b/src/service_easydns.cpp index ca19579..9332eb9 100644 --- a/src/service_easydns.cpp +++ b/src/service_easydns.cpp @@ -204,7 +204,7 @@ int ServiceEasydns::perform_update(const std::string& ip) } else if ( curl_data == "NOACCESS" ) { - get_logger()->print_http_not_authorized(url,get_login(),get_password()); + get_logger()->print_service_not_authorized(url,get_login(),get_password()); } else { diff --git a/src/service_gnudip.cpp b/src/service_gnudip.cpp index fe5064a..6c2a517 100644 --- a/src/service_gnudip.cpp +++ b/src/service_gnudip.cpp @@ -57,8 +57,7 @@ ServiceGnudip::ServiceGnudip(const string& _protocol, const string& _gnudip_serv // create http helper class HTTPHelper::Ptr _http_help(new HTTPHelper(_logger,_proxy,_proxy_port,_login,_password)); - HTTPHelp = _http_help; - _http_help.reset(); + HTTPHelp.swap(_http_help); BaseUrl = assemble_base_url(get_hostname(),_gnudip_server); } @@ -271,7 +270,7 @@ int ServiceGnudip::perform_update(const std::string& ip) } else if ( update_return_code == "1" ) { - get_logger()->print_http_not_authorized(url,get_login(),get_password()); + get_logger()->print_service_not_authorized(url,get_login(),get_password()); } else { diff --git a/src/service_tzo.cpp b/src/service_tzo.cpp index 31b7c57..ce3cb2f 100644 --- a/src/service_tzo.cpp +++ b/src/service_tzo.cpp @@ -125,7 +125,7 @@ int ServiceTzo::perform_update(const std::string& ip) } else if ( status_code == "401" ) { - get_logger()->print_http_not_authorized(url,get_login(),get_password()); + get_logger()->print_service_not_authorized(url,get_login(),get_password()); } else { diff --git a/src/service_zoneedit.cpp b/src/service_zoneedit.cpp index 47e5e8d..a714146 100644 --- a/src/service_zoneedit.cpp +++ b/src/service_zoneedit.cpp @@ -124,7 +124,7 @@ int ServiceZoneedit::perform_update(const std::string& ip) } else if ( http_status_code == 401 ) { - get_logger()->print_http_not_authorized(url,get_login(),get_password()); + get_logger()->print_service_not_authorized(url,get_login(),get_password()); } else { -- 1.7.1