Safe one indent level by reversing empty IP logic
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 6 Oct 2010 12:45:57 +0000 (14:45 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 6 Oct 2010 12:45:57 +0000 (14:45 +0200)
src/main.cpp
src/updater.cpp

index 6d00532..72f6860 100644 (file)
@@ -330,7 +330,7 @@ int main(int argc, char *argv[])
             updater->get_logger()->print_offline_mode();
         }
 
-        // Snore, snore... don't hug the cpu if we are in daemon_mode.
+        // Snore, snore... don't hog the cpu if we are in daemon_mode.
         if ( updater->get_config()->get_daemon_mode() == 1 )
             sleep(10); /*lint !e534 */
 
index 758bf66..81e277e 100644 (file)
@@ -223,78 +223,76 @@ void Updater::update_services() const
 
     // Get the actual IP of this host.
     string ip_host = IPAddrHelp->get_actual_ip(Conf->get_webcheck_enabled());
+    if ( ip_host.empty() )
+    {
+        Log->print_no_wan_ip();
+        return;
+    }
 
-    if ( !ip_host.empty() )
+    BOOST_FOREACH(Service::Ptr &service, services )
     {
-        BOOST_FOREACH(Service::Ptr &service, services )
-        {
-            string ip_last_update = service->get_actual_ip();
-            string hostname = service->get_hostname();
-            time_t lastupdated = 0;
-            time_t current_time = time(NULL);
+        string ip_last_update = service->get_actual_ip();
+        string hostname = service->get_hostname();
+        time_t lastupdated = 0;
+        time_t current_time = time(NULL);
 
-            // Try to get the lastupdated time of the actual service if there is one.
-            if ( service->get_last_updates().size() > 0 )
-                lastupdated = service->get_last_updates().front(); /*lint !e1793 */
+        // Try to get the lastupdated time of the actual service if there is one.
+        if ( service->get_last_updates().size() > 0 )
+            lastupdated = service->get_last_updates().front(); /*lint !e1793 */
 
-            Log->print_check_service_update(hostname, current_time, lastupdated);
+        Log->print_check_service_update(hostname, current_time, lastupdated);
 
-            // Do a DNS Query for the dynamic hostname.
-            string ip_dns_recheck = IPAddrHelp->dns_query(hostname);
+        // Do a DNS Query for the dynamic hostname.
+        string ip_dns_recheck = IPAddrHelp->dns_query(hostname);
 
-            Log->print_cached_dns_entry(hostname, ip_dns_recheck, ip_last_update, ip_host);
+        Log->print_cached_dns_entry(hostname, ip_dns_recheck, ip_last_update, ip_host);
 
-            // Test if the DNS-Record could not be found.
-            if ( ip_dns_recheck.empty() )
+        // Test if the DNS-Record could not be found.
+        if ( ip_dns_recheck.empty() )
+        {
+            // Next in BOOST_FOREACH
+        }
+        // Test if the actual DNS-Record differs from the host's IP.
+        else if ( ip_host != ip_dns_recheck )
+        {
+            // Check if the service will be updated for the first time.
+            if ( lastupdated == 0 )
             {
-                // Next in BOOST_FOREACH
+                // Update for the firt time.
+                Log->print_update_service_firttime(hostname, ip_dns_recheck, ip_host);
+                service->update(ip_host,current_time);
             }
-            // Test if the actual DNS-Record differs from the host's IP.
-            else if ( ip_host != ip_dns_recheck )
+            else
             {
-                // Check if the service will be updated for the first time.
-                if ( lastupdated == 0 )
+                // We already have updated, check if the IP set in last update differs from the actual host's ip.
+                if ( ip_last_update != ip_host )
                 {
-                    // Update for the firt time.
-                    Log->print_update_service_firttime(hostname, ip_dns_recheck, ip_host);
+                    // Update
+                    Log->print_update_service(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated);
                     service->update(ip_host,current_time);
                 }
                 else
                 {
-                    // We already have updated, check if the IP set in last update differs from the actual host's ip.
-                    if ( ip_last_update != ip_host )
+                    int dns_cache_ttl = service->get_dns_cache_ttl();
+                    // Check if DNS Cache TTL is expired, if so, then update the same IP again.
+                    if ( (lastupdated + dns_cache_ttl) < current_time )
                     {
                         // Update
-                        Log->print_update_service(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated);
+                        Log->print_update_service_ttl_expired(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated, dns_cache_ttl, current_time);
                         service->update(ip_host,current_time);
                     }
                     else
                     {
-                        int dns_cache_ttl = service->get_dns_cache_ttl();
-                        // Check if DNS Cache TTL is expired, if so, then update the same IP again.
-                        if ( (lastupdated + dns_cache_ttl) < current_time )
-                        {
-                            // Update
-                            Log->print_update_service_ttl_expired(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated, dns_cache_ttl, current_time);
-                            service->update(ip_host,current_time);
-                        }
-                        else
-                        {
-                            // DNS cache TTL isn't expired
-                            Log->print_update_service_ttl_not_expired(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated, dns_cache_ttl, current_time);
-                        }
+                        // DNS cache TTL isn't expired
+                        Log->print_update_service_ttl_not_expired(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated, dns_cache_ttl, current_time);
                     }
                 }
             }
-            else
-            {
-                Log->print_no_update_needed(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated);
-            }
         }
-    }
-    else
-    {
-        Log->print_no_wan_ip();
+        else
+        {
+            Log->print_no_update_needed(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated);
+        }
     }
 }