From 68c6b4af71ca51c228d82f1ba4b5398e251e3013 Mon Sep 17 00:00:00 2001 From: Bjoern Sikora Date: Tue, 11 Aug 2009 17:27:43 +0200 Subject: [PATCH] Separated Service update into update and perform_update. Improved logging. Prepared support for IPv6. --- src/dhs.cpp | 26 ++++++++++++++++++++++---- src/dhs.h | 2 ++ src/iphelper.cpp | 4 ++-- src/logger.cpp | 11 +++++++++++ src/logger.h | 2 ++ 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/dhs.cpp b/src/dhs.cpp index 21fe15a..8d8139c 100644 --- a/src/dhs.cpp +++ b/src/dhs.cpp @@ -59,11 +59,29 @@ DHS::~DHS() */ void DHS::update(const string& ip) { - // if update was successful, we need to set the lastupdated base member. - time_t actual_time = time(NULL); - set_lastupdated(actual_time); + if ( this->get_actual_ip() != ip ) + { + this->get_logger()->print_update_service("DHS"); + + if ( perform_update(ip) == 0 ) + { + // if update was successful, we need to set the Lastupdated and ActualIP base member. + this->set_lastupdated(time(NULL)); + this->set_actual_ip(ip); + this->get_logger()->print_update_service_successful("DHS"); + } + } +} + - get_logger()->print_update_service("DHS"); +/** + * Performs the Service update. + * @param ip IP Address to set. + * @return 0 if all is fine, -1 otherwise. + */ +int DHS::perform_update(const std::string& ip) +{ + return 0; } diff --git a/src/dhs.h b/src/dhs.h index 6ca1384..feb2fd0 100644 --- a/src/dhs.h +++ b/src/dhs.h @@ -49,6 +49,8 @@ public: int get_max_updates_within_timeout() const; void update(const std::string&); + + int perform_update(const std::string&); }; #endif diff --git a/src/iphelper.cpp b/src/iphelper.cpp index 9e9bfff..bc114ed 100644 --- a/src/iphelper.cpp +++ b/src/iphelper.cpp @@ -21,8 +21,8 @@ IPHelper::IPHelper() : Hostname("") , WebcheckUrl("") , WebcheckUrlAlt("") - , Log(new Logger) , UseIPv6(false) + , Log(new Logger) { } @@ -34,8 +34,8 @@ IPHelper::IPHelper(Logger::Ptr _log) : Hostname("") , WebcheckUrl("") , WebcheckUrlAlt("") - , Log(new Logger) , UseIPv6(false) + , Log(new Logger) { Log = _log; } diff --git a/src/logger.cpp b/src/logger.cpp index d8c2bc1..37d994c 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -744,3 +744,14 @@ void Logger::print_error_hostname_to_ip(const std::string& exception, const std: log_error(msg.str()); } } + + +void Logger::print_update_service_successful(const std::string& service) +{ + if ( 0 <= Loglevel ) + { + ostringstream msg; + msg << "Updated service successful: " << service << endl; + log_error(msg.str()); + } +} diff --git a/src/logger.h b/src/logger.h index 1eb88db..cc767c7 100644 --- a/src/logger.h +++ b/src/logger.h @@ -130,6 +130,8 @@ public: void print_own_ip(const std::string&, const std::string&) const; void print_error_hostname_to_ip(const std::string&, const std::string&) const; + + void print_update_service_successful(const std::string&); }; #endif -- 1.7.1