* @license GPLv2
*/
-#include "iphelper.h"
+#include "ip_addr_helper.h"
#include <boost/asio.hpp>
#include <boost/regex.hpp>
/**
* Default constructor.
*/
-IPHelper::IPHelper()
+IPAddrHelper::IPAddrHelper()
: Log(new Logger)
, ProxyPort(0)
, UseIPv6(false)
/**
* 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)
/**
* Default destructor
*/
-IPHelper::~IPHelper()
+IPAddrHelper::~IPAddrHelper()
{
}
* @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}");
* 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() )
* @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;
* 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 = "";
* @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 = "";
* @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 )
* @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());
}
* @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();
* @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);
* 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);
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;
}
{
list<Service::Ptr> services = ServiceHolder->get_services();
- string ip = IPHelp->get_actual_ip();
+ string ip = IPAddrHelp->get_actual_ip();
if ( !ip.empty() )
{
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;