Don't update the same IP more than 2 times in success.
[bpdyndnsd] / src / logger.cpp
index 5ec6f35..e953a99 100644 (file)
@@ -816,7 +816,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<time_t> 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 max_equal_updates_in_succession, const int dns_cache_ttl , const string& actual_ip, std::map<time_t,std::string> lastupdated) const
 {
     int level = 1;
     if ( level <= Loglevel )
@@ -829,11 +829,12 @@ void Logger::print_service_object(const string& message, const string& protocol,
         msg << "\t" << "Password:         " << password << endl;
         msg << "\t" << "Update Interval:  " << update_interval << endl;
         msg << "\t" << "Max Updates:      " << max_updates_within_interval << endl;
+        msg << "\t" << "Max equal Updates:" << max_equal_updates_in_succession << endl;
         msg << "\t" << "DNS Cache TTL:    " << dns_cache_ttl << endl;
         msg << "\t" << "Actual_IP:        " << actual_ip << endl;
-        BOOST_FOREACH( time_t update_time, lastupdated)
+        for ( std::map<time_t,std::string>::reverse_iterator r_iter = lastupdated.rbegin(); r_iter != lastupdated.rend(); r_iter++ )
         {
-            msg << "\t" << "Lastupdated:      " << update_time << endl;
+            msg << "\t" << "Lastupdated:      " << r_iter->first << " -> " << r_iter->second << endl;
         }
         log_notice(msg.str());
     }
@@ -1948,3 +1949,49 @@ void Logger::print_msg( const string& msg ) const
         log_error(msg);
     }
 }
+
+
+/**
+ * Print the last updates.
+ * @param ip_host Actual host IP.
+ * @param max_equal_updates_in_succession Maximal number of updates for the same IP in succession.
+ * @param last_updates Map with the last updates in it.
+ * @param hostname The service hostname.
+ */
+void Logger::print_last_updates( const std::string& ip_host, const int max_equal_updates_in_succession, const std::map<time_t,std::string>& last_updates, const std::string& hostname ) const
+{
+    int level = 1;
+    if ( level <= Loglevel )
+    {
+        ostringstream msg;
+        msg << "Last updates for " << hostname << " : ";
+
+        int i = 0;
+        for ( std::map<time_t,std::string>::reverse_iterator r_iter; (r_iter != last_updates.rend()) && (i < max_equal_updates_in_succession); r_iter++ )
+        {
+            msg << r_iter->first << "->" << r_iter->second;
+            i++;
+        }
+        msg << ". Actual internet IP: " << ip_host << endl;
+
+        log_notice(msg.str());
+    }
+}
+
+
+/**
+ * Print the burnt IP.
+ * @param ip_host Actual host IP which is burnt.
+ * @param hostname The service hostname.
+ */
+void Logger::print_ip_burnt( const std::string& ip_host, const std::string& hostname ) const
+{
+    int level = 0;
+    if ( level <= Loglevel )
+    {
+        ostringstream msg;
+        msg << "IP address " << ip_host << " was updated too often in succession, host " << hostname  << " blocked until IP Address will be different." << endl;
+        log_error(msg.str());
+    }
+}