Refactoring: Renamed class IPHelper to a more meaningful name IPAddrHelper.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Wed, 9 Sep 2009 13:55:02 +0000 (15:55 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Wed, 9 Sep 2009 13:55:02 +0000 (15:55 +0200)
src/ip_addr_helper.cpp [moved from src/iphelper.cpp with 91% similarity]
src/ip_addr_helper.h [moved from src/iphelper.h with 77% similarity]
src/main.cpp
src/updater.cpp
src/updater.h

similarity index 91%
rename from src/iphelper.cpp
rename to src/ip_addr_helper.cpp
index f06dcc4..0c7894c 100644 (file)
@@ -7,7 +7,7 @@
  * @license GPLv2
 */
 
-#include "iphelper.h"
+#include "ip_addr_helper.h"
 #include <boost/asio.hpp>
 #include <boost/regex.hpp>
 
@@ -18,7 +18,7 @@ namespace net = boost::asio;
 /**
  * Default constructor.
  */
-IPHelper::IPHelper()
+IPAddrHelper::IPAddrHelper()
     : Log(new Logger)
     , ProxyPort(0)
     , UseIPv6(false)
@@ -29,7 +29,7 @@ IPHelper::IPHelper()
 /**
  * Constructor.
  */
-IPHelper::IPHelper(const Logger::Ptr _log, const string& _webcheck_url, const string& _webcheck_url_alt, const bool _use_ipv6, const string& _proxy, const int _proxy_port)
+IPAddrHelper::IPAddrHelper(const Logger::Ptr _log, const string& _webcheck_url, const string& _webcheck_url_alt, const bool _use_ipv6, const string& _proxy, const int _proxy_port)
     : Log(_log)
     , WebcheckIpUrl(_webcheck_url)
     , WebcheckIpUrlAlt(_webcheck_url_alt)
@@ -45,7 +45,7 @@ IPHelper::IPHelper(const Logger::Ptr _log, const string& _webcheck_url, const st
 /**
  * Default destructor
  */
-IPHelper::~IPHelper()
+IPAddrHelper::~IPAddrHelper()
 {
 }
 
@@ -55,7 +55,7 @@ IPHelper::~IPHelper()
  * @param ip The IP to test
  * @return true if given IP is local, false if not.
  */
-bool IPHelper::is_local(const string ip) const
+bool IPAddrHelper::is_local(const string ip) const
 {
     // 127.0.0.1
     boost::regex expr_loopback("127\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}");
@@ -119,7 +119,7 @@ bool IPHelper::is_local(const string ip) const
  * Get the actual IP of this host through a conventional DNS query or through a IP webcheck URL if configured so.
  * @return A string representation of the actual IP in dotted format or an empty string if something went wrong.
  */
-string IPHelper::get_actual_ip() const
+string IPAddrHelper::get_actual_ip() const
 {
     string ip;
     if ( WebcheckIpUrl.empty() )
@@ -147,7 +147,7 @@ string IPHelper::get_actual_ip() const
  * @param _hostname The hostname for the dns lookup, if empty string, then perform a dns lookup to the local hostname.
  * @return A string representation of the actual IP in dotted format or an empty string if something went wrong.
  */
-string IPHelper::dns_query(const string& _hostname) const
+string IPAddrHelper::dns_query(const string& _hostname) const
 {
     string ip_addr_v4;
     string ip_addr_v6;
@@ -196,7 +196,7 @@ string IPHelper::dns_query(const string& _hostname) const
  * Get the actual IP of this host through a IP webcheck URL.
  * @return A string representation of the actual IP in dotted format or an empty string if something went wrong.
  */
-string IPHelper::webcheck_ip() const
+string IPAddrHelper::webcheck_ip() const
 {
     string ip_addr = "";
 
@@ -250,7 +250,7 @@ string IPHelper::webcheck_ip() const
  * @param data The string data to search in for a valid IPv4-Address.
  * @return The IP Address found or an empty string.
  */
-string IPHelper::parse_ip(const string& data) const
+string IPAddrHelper::parse_ip(const string& data) const
 {
     string ip = "";
 
@@ -280,7 +280,7 @@ string IPHelper::parse_ip(const string& data) const
  * @param actual_url The actual configured URL.
  * @return 0 if all is fine, 1 if an connection problem to the configured url occurs, -1 on other errors.
  */
-int IPHelper::perform_curl_operation(CURL * curl_easy_handle, char* curl_err_buff, const string& actual_url) const
+int IPAddrHelper::perform_curl_operation(CURL * curl_easy_handle, char* curl_err_buff, const string& actual_url) const
 {
     int curl_err_code;
     if ( (curl_err_code = curl_easy_perform(curl_easy_handle) ) != 0 )
@@ -309,7 +309,7 @@ int IPHelper::perform_curl_operation(CURL * curl_easy_handle, char* curl_err_buf
  * @param curl_easy_handle The easy curl handle to set the url for.
  * @param url The url to set.
  */
-void IPHelper::set_curl_url(CURL * curl_easy_handle, const string& url) const
+void IPAddrHelper::set_curl_url(CURL * curl_easy_handle, const string& url) const
 {
     curl_easy_setopt(curl_easy_handle,CURLOPT_URL,url.c_str());
 }
@@ -321,7 +321,7 @@ void IPHelper::set_curl_url(CURL * curl_easy_handle, const string& url) const
  * @param curl_err_buff A pointer to an char array which will be filled with error message.
  * @return A pointer to the easy curl handle.
  */
-CURL * IPHelper::init_curl(string& curl_writedata_buff,char* curl_err_buff) const
+CURL * IPAddrHelper::init_curl(string& curl_writedata_buff,char* curl_err_buff) const
 {
     CURL *curl_easy_handle = curl_easy_init();
 
@@ -351,7 +351,7 @@ CURL * IPHelper::init_curl(string& curl_writedata_buff,char* curl_err_buff) cons
  * @param outBuffer Pointer to output stream.
  * @return The size received.
  */
-int IPHelper::http_receive( char *inBuffer, size_t size, size_t nmemb, string *outBuffer )
+int IPAddrHelper::http_receive( char *inBuffer, size_t size, size_t nmemb, string *outBuffer )
 {
     outBuffer->append(inBuffer);
     return (size*nmemb);
similarity index 77%
rename from src/iphelper.h
rename to src/ip_addr_helper.h
index c1ff7f6..5d7765b 100644 (file)
@@ -7,8 +7,8 @@
  * @license GPLv2
 */
 
-#ifndef IPHELPER_H
-#define IPHELPER_H
+#ifndef IPADDRHELPER_H
+#define IPADDRHELPER_H
 
 #include "logger.h"
 
@@ -16,7 +16,7 @@
 #include <curl/curl.h>
 
 
-class IPHelper
+class IPAddrHelper
 {
 private:
 
@@ -36,13 +36,13 @@ private:
 
 public:
 
-    typedef boost::shared_ptr<IPHelper> Ptr;
+    typedef boost::shared_ptr<IPAddrHelper> Ptr;
 
-    IPHelper();
+    IPAddrHelper();
 
-    IPHelper(const Logger::Ptr _log, const std::string& _webcheck_url, const std::string& _webcheck_url_alt, const bool _use_ipv6, const std::string& _proxy, const int _proxy_port);
+    IPAddrHelper(const Logger::Ptr _log, const std::string& _webcheck_url, const std::string& _webcheck_url_alt, const bool _use_ipv6, const std::string& _proxy, const int _proxy_port);
 
-    ~IPHelper();
+    ~IPAddrHelper();
 
     std::string dns_query(const std::string& _hostname) const;
 
index a45dca2..6de0f65 100644 (file)
@@ -33,7 +33,7 @@
 #include "service.cpp"
 #include "serviceholder.cpp"
 #include "updater.cpp"
-#include "iphelper.cpp"
+#include "ip_addr_helper.cpp"
 #include "httphelper.cpp"
 #include "serializeservicecontainer.cpp"
 #include "util.cpp"
index 30e160a..7083d84 100644 (file)
@@ -41,7 +41,7 @@ using namespace std;
  * Default constructor which initializes the member Conf.
  */
 Updater::Updater()
-    : IPHelp(new IPHelper)
+    : IPAddrHelp(new IPAddrHelper)
 {
     // Initialize program wide Logger, at this point we don't know where to log and with which loglevel.
     Logger::Ptr _log(new Logger);
@@ -185,9 +185,9 @@ int Updater::init_helper_classes()
 int Updater::init_ip_helper()
 {
     // initialize IPHelper
-    IPHelper::Ptr _iphelp(new IPHelper(Log,Conf->get_webcheck_ip_url(),Conf->get_webcheck_ip_url_alt(),Conf->get_enable_ipv6(),Conf->get_proxy(),Conf->get_proxy_port()));
-    IPHelp = _iphelp;
-    _iphelp.reset();
+    IPAddrHelper::Ptr _ipaddrhelp(new IPAddrHelper(Log,Conf->get_webcheck_ip_url(),Conf->get_webcheck_ip_url_alt(),Conf->get_enable_ipv6(),Conf->get_proxy(),Conf->get_proxy_port()));
+    IPAddrHelp = _ipaddrhelp;
+    _ipaddrhelp.reset();
 
     return 0;
 }
@@ -230,7 +230,7 @@ void Updater::update_services()
 {
     list<Service::Ptr> services = ServiceHolder->get_services();
 
-    string ip = IPHelp->get_actual_ip();
+    string ip = IPAddrHelp->get_actual_ip();
 
     if ( !ip.empty() )
     {
@@ -247,7 +247,7 @@ void Updater::update_services()
             if ( ((lastupdated != 0) && ((lastupdated + service->get_dns_cache_ttl()) < current_time)) || (lastupdated == 0) )
             {
                 Log->print_recheck_dns_entry(service->get_hostname(),lastupdated,service->get_dns_cache_ttl(),current_time);
-                string _dns_recheck_ip = IPHelp->dns_query(service->get_hostname());
+                string _dns_recheck_ip = IPAddrHelp->dns_query(service->get_hostname());
                 Log->print_cached_dns_entry(service->get_hostname(), _dns_recheck_ip, service->get_actual_ip());
                 if (!_dns_recheck_ip.empty())
                     dns_recheck_ip = _dns_recheck_ip;
index cc9bf13..34e67f3 100644 (file)
@@ -11,7 +11,7 @@
 #define UPDATER_H
 
 #include "config.h"
-#include "iphelper.h"
+#include "ip_addr_helper.h"
 #include "httphelper.h"
 #include "logger.h"
 #include "serviceholder.h"
@@ -25,7 +25,7 @@ class Updater
 private:
 
     Config::Ptr Conf;
-    IPHelper::Ptr IPHelp;
+    IPAddrHelper::Ptr IPAddrHelp;
     HTTPHelper::Ptr HTTPHelp;
     Logger::Ptr Log;
     Serviceholder::Ptr ServiceHolder;