Normalized perform_update method. Improved readability.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Mon, 7 Sep 2009 11:32:50 +0000 (13:32 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Mon, 7 Sep 2009 11:32:50 +0000 (13:32 +0200)
src/dhs.cpp
src/dyndns.cpp
src/dyns.cpp
src/easydns.cpp

index befed5c..485047a 100644 (file)
@@ -84,22 +84,14 @@ DHS::~DHS()
 string DHS::assemble_base_url(const string& hostname, const string& domain_part) const
 {
     string base_url;
-    if ( !domain_part.empty() )
-    {
-        base_url = "http://members.dhs.org";
-        base_url.append("/nic/hosts?hostscmd=edit&hostscmdstage=2&type=4&domain=");
-        base_url.append(domain_part);
-        base_url.append("&hostname=");
-        base_url.append(hostname);
-        base_url.append("&updatetype=Online&ip=");
-    }
-    else
-    {
-        base_url = "http://members.dhs.org";
-        base_url.append("/nic/hosts?hostscmd=edit&hostscmdstage=2&type=4&hostname=");
-        base_url.append(hostname);
-        base_url.append("&updatetype=Online&ip=");
-    }
+
+    base_url = "http://members.dhs.org";
+    base_url.append("/nic/hosts?hostscmd=edit&hostscmdstage=2&type=4&domain=");
+    base_url.append(domain_part);
+    base_url.append("&hostname=");
+    base_url.append(hostname);
+    base_url.append("&updatetype=Online&ip=");
+
     return base_url;
 }
 
@@ -149,24 +141,18 @@ int DHS::perform_update(const std::string& ip)
     string url = BaseUrl;
     url.append(ip);
 
-    long output = HTTPHelp->http_get(url);
+    // Perform curl operation on given url.
+    long http_status_code = HTTPHelp->http_get(url);
 
-    get_logger()->print_http_status_code(url,output);
+    get_logger()->print_http_status_code(url,http_status_code);
 
-    if ( output == 200 )
-    {
+    // Check the status code for protocol errors.
+    if ( http_status_code == 200 )
         ret_val = 0;
-    }
-    else if ( output == -1 )
-    {
-        ret_val = -1;
-    }
-    else if ( output == 401 )
-    {
+    else if ( http_status_code == 401 )
         get_logger()->print_http_not_authorized(url,get_login(),get_password());
-        // not authorized
-        ret_val = -1;
-    }
+    else
+        get_logger()->print_update_failure(url,http_status_code);
 
     return ret_val;
 }
index 22923c6..b77fd12 100644 (file)
@@ -103,13 +103,17 @@ int DYNDNS::perform_update(const std::string& ip)
     string url = BaseUrl;
     url.append(ip);
 
-    long output = HTTPHelp->http_get(url);
+    // Perform curl operation on given url
+    long http_status_code = HTTPHelp->http_get(url);
 
-    get_logger()->print_http_status_code(url,output);
+    get_logger()->print_http_status_code(url,http_status_code);
 
-    // HTTP operation completed successful, now we have to parse the data received by curl cause http status code is not significant for dyndns update errors
-    if ( output == 200 )
+    // HTTP operation completed successful.
+    // Now we have to parse the data received by curl,
+    // cause http status code is not significant for dyndns update errors
+    if ( http_status_code == 200 )
     {
+        // Get the received http data.
         string curl_data = HTTPHelp->get_curl_data();
 
         if ( curl_data == good )
index 4ef7391..4950757 100644 (file)
@@ -112,26 +112,21 @@ int DYNS::perform_update(const std::string& ip)
 
     get_logger()->print_http_status_code(url,http_status_code);
 
-    // HTTP operation completed successful, now we have to parse the data received by curl cause http status code is not significant for dyns update errors
+    // HTTP operation completed successful.
+    // Now we have to parse the data received by curl,
+    // cause http status code is not significant for dyns update errors
     if ( http_status_code == 200 )
     {
+        // Get the received http data and parse the status code.
         string curl_data = HTTPHelp->get_curl_data();
         string status_code = parse_status_code(curl_data);
 
         if ( status_code == "200" )
-        {
             ret_val = 0;
-        }
         else if ( status_code == "401" )
-        {
-            // badauth
             get_logger()->print_http_not_authorized(url,get_login(),get_password());
-        }
         else
-        {
-            // generic
             get_logger()->print_update_failure(url,curl_data);
-        }
     }
 
     return ret_val;
index 843fb9c..b2f0ad9 100644 (file)
@@ -188,13 +188,16 @@ int EASYDNS::perform_update(const std::string& ip)
     string url = BaseUrl;
     url.append(ip);
 
-    long output = HTTPHelp->http_get(url);
+    long http_status_code = HTTPHelp->http_get(url);
 
-    get_logger()->print_http_status_code(url,output);
+    get_logger()->print_http_status_code(url,http_status_code);
 
-    // HTTP operation completed successful, now we have to parse the data received by curl cause http status code is not significant for dyndns update errors
-    if ( output == 200 )
+    // HTTP operation completed successful.
+    // Now we have to parse the data received by curl,
+    // cause http status code is not significant for easydns update errors
+    if ( http_status_code == 200 )
     {
+        // Get the received http data.
         string curl_data = HTTPHelp->get_curl_data();
 
         if ( curl_data == "NOERROR" )