Use time_t instead of int.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Mon, 17 May 2010 09:51:06 +0000 (11:51 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Mon, 17 May 2010 09:51:06 +0000 (11:51 +0200)
src/logger.cpp
src/logger.h
src/service.cpp
src/service.h
src/service_dyndns.cpp
src/service_gnudip.cpp
src/service_gnudip.h
src/serviceholder.cpp

index a898fd2..4c9075c 100644 (file)
@@ -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<int> 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<time_t> 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;
         }
index f0e0ac0..5ab2f0d 100644 (file)
@@ -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<int> 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<time_t> lastupdated) const;
 
     void print_exception_serialize(const std::string& errMsg) const;
 
index b7cbb60..8fb7752 100644 (file)
@@ -133,10 +133,10 @@ Logger::Ptr Service::get_logger() const
 }
 
 
-void Service::set_last_updates(std::list<int> _last_updates)
+void Service::set_last_updates(std::list<time_t> _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<int> _last_updates)
  * Getter for member Lastupdated.
  * @return Value of member Lastupdated.
  */
-list<int> Service::get_last_updates() const
+list<time_t> 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<int>::iterator iter;
+    list<time_t>::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());
 
index 6fe6420..e2858f4 100644 (file)
@@ -37,7 +37,7 @@ private:
     int MaxUpdatesWithinInterval;
     int DNSCacheTTL;
 
-    std::list<int> LastUpdates;
+    std::list<time_t> LastUpdates;
 
     friend class boost::serialization::access;
     template<class Archive>
@@ -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<int> _last_updates);
-    std::list<int> get_last_updates() const;
+    void set_last_updates(std::list<time_t> _last_updates);
+    std::list<time_t> get_last_updates() const;
 
     void set_actual_ip(const std::string& _actual_ip);
     std::string get_actual_ip() const;
index 3f68d22..2999582 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "service_dyndns.h"
 
-#include <time.h>
 #include <boost/foreach.hpp>
 
 using namespace std;
index 54c9dfa..5a2cfd5 100644 (file)
@@ -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<string,string> 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<string,string>("salt",matches[1]));
-        get_logger()->print_regex_match(expr_salt.str(),matches[1]);
+        response.insert(pair<string,string>("salt",matches[1].str()));
+        get_logger()->print_regex_match(expr_salt.str(),matches[1].str());
     }
     else
     {
@@ -121,8 +121,8 @@ map<string,string> 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<string,string>("time",matches[1]));
-        get_logger()->print_regex_match(expr_salt.str(),matches[1]);
+        response.insert(pair<string,string>("time",matches[1].str()));
+        get_logger()->print_regex_match(expr_salt.str(),matches[1].str());
     }
     else
     {
@@ -134,8 +134,8 @@ map<string,string> 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<string,string>("sign",matches[1]));
-        get_logger()->print_regex_match(expr_salt.str(),matches[1]);
+        response.insert(pair<string,string>("sign",matches[1].str()));
+        get_logger()->print_regex_match(expr_salt.str(),matches[1].str());
     }
     else
     {
@@ -157,14 +157,14 @@ map<string,string> 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<string,string>::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);
index b58e6ff..5852d58 100644 (file)
@@ -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<std::string,std::string> 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:
 
index 906f29a..fbf1ba3 100644 (file)
@@ -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)
     {