From 62df5f332143f16e09403cf77b821e7c663e2cb1 Mon Sep 17 00:00:00 2001 From: Bjoern Sikora Date: Mon, 17 May 2010 11:51:06 +0200 Subject: [PATCH] Use time_t instead of int. --- src/logger.cpp | 4 ++-- src/logger.h | 2 +- src/service.cpp | 12 ++++++------ src/service.h | 10 +++++----- src/service_dyndns.cpp | 1 - src/service_gnudip.cpp | 30 +++++++++++++++--------------- src/service_gnudip.h | 4 ++-- src/serviceholder.cpp | 2 +- 8 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/logger.cpp b/src/logger.cpp index a898fd2..4c9075c 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( time_t update_time, lastupdated) { msg << "\t" << "Lastupdated: " << update_time << endl; } diff --git a/src/logger.h b/src/logger.h index f0e0ac0..5ab2f0d 100644 --- a/src/logger.h +++ b/src/logger.h @@ -118,7 +118,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& errMsg) const; diff --git a/src/service.cpp b/src/service.cpp index b7cbb60..8fb7752 100644 --- a/src/service.cpp +++ b/src/service.cpp @@ -133,10 +133,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( time_t update_time, _last_updates ) { LastUpdates.push_back(update_time); } @@ -147,7 +147,7 @@ void Service::set_last_updates(std::list _last_updates) * Getter for member Lastupdated. * @return Value of member Lastupdated. */ -list Service::get_last_updates() const +list Service::get_last_updates() const { return LastUpdates; } @@ -203,9 +203,9 @@ bool Service::operator!= (const Service& other) const * @param current_time Current time. * @return True if update is allowed, false if update would exceed max update interval. */ -bool Service::update_allowed(const int current_time) +bool Service::update_allowed(const time_t current_time) { - list::iterator iter; + list::iterator iter; int i=0; for (iter = LastUpdates.begin(); (iter != LastUpdates.end()) && ( i < MaxUpdatesWithinInterval ); iter++) @@ -225,7 +225,7 @@ bool Service::update_allowed(const int current_time) * Service update method, common to each service. * @param ip The new ip to set for the hostname. */ -void Service::update(const string& ip, const int current_time) +void Service::update(const string& ip, const time_t current_time) { Log->print_update_service(get_service_name()); diff --git a/src/service.h b/src/service.h index 6fe6420..e2858f4 100644 --- a/src/service.h +++ b/src/service.h @@ -37,7 +37,7 @@ private: int MaxUpdatesWithinInterval; int DNSCacheTTL; - std::list LastUpdates; + std::list LastUpdates; friend class boost::serialization::access; template @@ -66,9 +66,9 @@ public: virtual int perform_update(const std::string& ip) = 0; - void update(const std::string& ip, const int current_time); + void update(const std::string& ip, const time_t current_time); - bool update_allowed(const int current_time); + bool update_allowed(const time_t current_time); int get_update_interval()const; void set_update_interval(const int _update_interval); @@ -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() const; + void set_last_updates(std::list _last_updates); + std::list get_last_updates() const; void set_actual_ip(const std::string& _actual_ip); std::string get_actual_ip() const; diff --git a/src/service_dyndns.cpp b/src/service_dyndns.cpp index 3f68d22..2999582 100644 --- a/src/service_dyndns.cpp +++ b/src/service_dyndns.cpp @@ -9,7 +9,6 @@ #include "service_dyndns.h" -#include #include using namespace std; diff --git a/src/service_gnudip.cpp b/src/service_gnudip.cpp index 54c9dfa..5a2cfd5 100644 --- a/src/service_gnudip.cpp +++ b/src/service_gnudip.cpp @@ -58,7 +58,7 @@ ServiceGnudip::ServiceGnudip(const string& _protocol, const string& _gnudip_serv // create http helper class HTTPHelp = HTTPHelper::Ptr(new HTTPHelper(_logger,_proxy,_proxy_port,_login,_password)); - BaseUrl = assemble_base_url(get_hostname(),_gnudip_server); + BaseUrl = assemble_base_url(_gnudip_server); } @@ -72,10 +72,10 @@ ServiceGnudip::~ServiceGnudip() /** * Assemble the dyndns update url from the given fqhn - * @param hostname The fqhn hostname to update IP for. + * @param gnudip_server The gnudip update server. * @return The assembled update url without IP. */ -string ServiceGnudip::assemble_base_url(const string& fqhn, const string& gnudip_server) const +string ServiceGnudip::assemble_base_url(const string& gnudip_server) const { string base_url; @@ -108,8 +108,8 @@ map ServiceGnudip::parse_initial_request(const string& curl_data) // Get the salt out of received http data if ( boost::regex_search(curl_data,matches,expr_salt) ) { - response.insert(pair("salt",matches[1])); - get_logger()->print_regex_match(expr_salt.str(),matches[1]); + response.insert(pair("salt",matches[1].str())); + get_logger()->print_regex_match(expr_salt.str(),matches[1].str()); } else { @@ -121,8 +121,8 @@ map ServiceGnudip::parse_initial_request(const string& curl_data) // Get the time out of received http data if ( boost::regex_search(curl_data,matches,expr_time) ) { - response.insert(pair("time",matches[1])); - get_logger()->print_regex_match(expr_salt.str(),matches[1]); + response.insert(pair("time",matches[1].str())); + get_logger()->print_regex_match(expr_salt.str(),matches[1].str()); } else { @@ -134,8 +134,8 @@ map ServiceGnudip::parse_initial_request(const string& curl_data) // Get the sign out of received http data if ( boost::regex_search(curl_data,matches,expr_sign) ) { - response.insert(pair("sign",matches[1])); - get_logger()->print_regex_match(expr_salt.str(),matches[1]); + response.insert(pair("sign",matches[1].str())); + get_logger()->print_regex_match(expr_salt.str(),matches[1].str()); } else { @@ -157,14 +157,14 @@ map ServiceGnudip::parse_initial_request(const string& curl_data) * @param ip IP to update * @return The assembled update url. */ -string ServiceGnudip::assemble_update_url(const string& salt, const string& time, const string& sign, const string& secret, const string& ip) const +string ServiceGnudip::assemble_update_url(const string& salt, const string& curr_time, const string& sign, const string& secret, const string& ip) const { string url = BaseUrl; url.append("?salt="); url.append(salt); url.append("&time="); - url.append(time); + url.append(curr_time); url.append("&sign="); url.append(sign); url.append("&user="); @@ -209,7 +209,7 @@ int ServiceGnudip::perform_update(const std::string& ip) } // at this point we have salt, time and sign parsed successfully - string salt, time, sign; + string salt, sign_time, sign; map::iterator iter = salt_time_sign.find("salt"); if ( iter != salt_time_sign.end() ) @@ -217,13 +217,13 @@ int ServiceGnudip::perform_update(const std::string& ip) iter = salt_time_sign.find("time"); if ( iter != salt_time_sign.end() ) - time = iter->second; + sign_time = iter->second; iter = salt_time_sign.find("sign"); if ( iter != salt_time_sign.end() ) sign = iter->second; - if ( salt.empty() || time.empty() || sign.empty() ) + if ( salt.empty() || sign_time.empty() || sign.empty() ) get_logger()->print_could_not_get_initial_gnudip_data(); // compute md5 sum from users password and get the HEX representation @@ -254,7 +254,7 @@ int ServiceGnudip::perform_update(const std::string& ip) } // Now its time to issue the second http_get operation - string url = assemble_update_url(salt, time, sign, secret, ip); + string url = assemble_update_url(salt, sign_time, sign, secret, ip); // perform the update operation http_status_code = HTTPHelp->http_get(url); diff --git a/src/service_gnudip.h b/src/service_gnudip.h index b58e6ff..5852d58 100644 --- a/src/service_gnudip.h +++ b/src/service_gnudip.h @@ -36,9 +36,9 @@ private: HTTPHelper::Ptr HTTPHelp; - std::string assemble_base_url(const std::string& fqhn, const std::string& gnudip_server) const; + std::string assemble_base_url(const std::string& gnudip_server) const; std::map parse_initial_request(const std::string& curl_data) const; - std::string assemble_update_url(const std::string& salt, const std::string& time, const std::string& sign, const std::string& secret, const std::string& ip) const; + std::string assemble_update_url(const std::string& salt, const std::string& curr_time, const std::string& sign, const std::string& secret, const std::string& ip) const; public: diff --git a/src/serviceholder.cpp b/src/serviceholder.cpp index 906f29a..fbf1ba3 100644 --- a/src/serviceholder.cpp +++ b/src/serviceholder.cpp @@ -63,7 +63,7 @@ int Serviceholder::serialize_services() service_container->add_service(service); } - int current_time = time(NULL); + time_t current_time = time(NULL); BOOST_FOREACH(Service::Ptr &service, OldServices) { -- 1.7.1