From 60559d638a60e0a96e1f0e9e1164fc8d3056c6d4 Mon Sep 17 00:00:00 2001 From: Bjoern Sikora Date: Mon, 7 Sep 2009 13:32:50 +0200 Subject: [PATCH] Normalized perform_update method. Improved readability. --- src/dhs.cpp | 46 ++++++++++++++++------------------------------ src/dyndns.cpp | 12 ++++++++---- src/dyns.cpp | 13 ++++--------- src/easydns.cpp | 11 +++++++---- 4 files changed, 35 insertions(+), 47 deletions(-) diff --git a/src/dhs.cpp b/src/dhs.cpp index befed5c..485047a 100644 --- a/src/dhs.cpp +++ b/src/dhs.cpp @@ -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; } diff --git a/src/dyndns.cpp b/src/dyndns.cpp index 22923c6..b77fd12 100644 --- a/src/dyndns.cpp +++ b/src/dyndns.cpp @@ -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 ) diff --git a/src/dyns.cpp b/src/dyns.cpp index 4ef7391..4950757 100644 --- a/src/dyns.cpp +++ b/src/dyns.cpp @@ -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; diff --git a/src/easydns.cpp b/src/easydns.cpp index 843fb9c..b2f0ad9 100644 --- a/src/easydns.cpp +++ b/src/easydns.cpp @@ -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" ) -- 1.7.1