From 52e7ca7159345119d6ee06fa8ca29331f8fcfeab Mon Sep 17 00:00:00 2001 From: Bjoern Sikora Date: Tue, 15 Sep 2009 17:35:29 +0200 Subject: [PATCH] Added Util::parse_status_code(). --- src/service_dyns.cpp | 16 ++-------------- src/service_dyns.h | 2 -- src/service_tzo.cpp | 16 ++-------------- src/service_tzo.h | 2 -- src/service_zoneedit.cpp | 16 ++-------------- src/service_zoneedit.h | 2 -- src/util.cpp | 13 +++++++++++++ src/util.h | 4 +++- 8 files changed, 22 insertions(+), 49 deletions(-) diff --git a/src/service_dyns.cpp b/src/service_dyns.cpp index c113027..b8ad563 100644 --- a/src/service_dyns.cpp +++ b/src/service_dyns.cpp @@ -8,6 +8,7 @@ */ #include "service_dyns.h" +#include "util.h" #include #include @@ -117,7 +118,7 @@ int ServiceDyns::perform_update(const std::string& ip) { // 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); + string status_code = Util::parse_status_code(curl_data); if ( status_code == "200" ) { @@ -142,19 +143,6 @@ int ServiceDyns::perform_update(const std::string& ip) /** - * Get the status code from the returned http data - * @param data The returned http data. - * @return The status code. - */ -string ServiceDyns::parse_status_code(const string& data) const -{ - list tokens; - ba::split(tokens,data,boost::is_any_of(" ")); - return tokens.front(); -} - - -/** * Serialize function needed by boost/serialization to define which members should be stored as the object state. * @param ar Archive * @param version Version diff --git a/src/service_dyns.h b/src/service_dyns.h index aaa7b73..2fc868a 100644 --- a/src/service_dyns.h +++ b/src/service_dyns.h @@ -34,8 +34,6 @@ private: std::string assemble_base_url(const std::string& fqhn, const std::string& username, const std::string& password) const; - std::string parse_status_code(const std::string& data) const; - public: typedef boost::shared_ptr Ptr; diff --git a/src/service_tzo.cpp b/src/service_tzo.cpp index ce3cb2f..8ee64bd 100644 --- a/src/service_tzo.cpp +++ b/src/service_tzo.cpp @@ -8,6 +8,7 @@ */ #include "service_tzo.h" +#include "util.h" #include #include @@ -117,7 +118,7 @@ int ServiceTzo::perform_update(const std::string& ip) { // 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); + string status_code = Util::parse_status_code(curl_data); if ( status_code == "200" ) { @@ -142,19 +143,6 @@ int ServiceTzo::perform_update(const std::string& ip) /** - * Get the status code from the returned http data - * @param data The returned http data. - * @return The status code. - */ -string ServiceTzo::parse_status_code(const string& data) const -{ - list tokens; - ba::split(tokens,data,boost::is_any_of(" ")); - return tokens.front(); -} - - -/** * Serialize function needed by boost/serialization to define which members should be stored as the object state. * @param ar Archive * @param version Version diff --git a/src/service_tzo.h b/src/service_tzo.h index cfb6f2c..7e58f9d 100644 --- a/src/service_tzo.h +++ b/src/service_tzo.h @@ -34,8 +34,6 @@ private: std::string assemble_base_url(const std::string& fqhn, const std::string& username, const std::string& password) const; - std::string parse_status_code(const std::string& data) const; - public: typedef boost::shared_ptr Ptr; diff --git a/src/service_zoneedit.cpp b/src/service_zoneedit.cpp index a714146..61cbaa0 100644 --- a/src/service_zoneedit.cpp +++ b/src/service_zoneedit.cpp @@ -8,6 +8,7 @@ */ #include "service_zoneedit.h" +#include "util.h" #include #include @@ -111,7 +112,7 @@ int ServiceZoneedit::perform_update(const std::string& ip) { // 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); + string status_code = Util::parse_status_code(curl_data); if ( status_code == "200" ) { @@ -136,19 +137,6 @@ int ServiceZoneedit::perform_update(const std::string& ip) /** - * Get the status code from the returned http data - * @param data The returned http data. - * @return The status code. - */ -string ServiceZoneedit::parse_status_code(const string& data) const -{ - list tokens; - ba::split(tokens,data,boost::is_any_of(" ")); - return tokens.front(); -} - - -/** * Serialize function needed by boost/serialization to define which members should be stored as the object state. * @param ar Archive * @param version Version diff --git a/src/service_zoneedit.h b/src/service_zoneedit.h index 98dfc3d..7e5dc5b 100644 --- a/src/service_zoneedit.h +++ b/src/service_zoneedit.h @@ -34,8 +34,6 @@ private: std::string assemble_base_url(const std::string& fqhn) const; - std::string parse_status_code(const std::string& data) const; - public: typedef boost::shared_ptr Ptr; diff --git a/src/util.cpp b/src/util.cpp index d2078d7..18ad24c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -73,3 +73,16 @@ string Util::compute_md5_digest(string data) throw (invalid_argument) return oss_digest_md5_hex.str(); } + + +/** + * Get the status code from the given data. + * @param data The data containing the status code at front, limited by " ". + * @return The parsed status code. + */ +string Util::parse_status_code(string data) +{ + list tokens; + ba::split(tokens,data,boost::is_any_of(" ")); + return tokens.front(); +} diff --git a/src/util.h b/src/util.h index b7cb9fc..870c346 100644 --- a/src/util.h +++ b/src/util.h @@ -13,7 +13,9 @@ namespace Util { - static std::string compute_md5_digest(std::string) throw (std::invalid_argument); + static std::string compute_md5_digest(std::string data) throw (std::invalid_argument); + + static std::string parse_status_code(std::string data); }; #endif -- 1.7.1