Fix 'occurred' typo
[bpdyndnsd] / src / ip_addr_helper.hpp
1 /** @file
2  * @brief IPHelper class header. This class represents a Helper to get the actual IP.
3  *
4  *
5  *
6  * @copyright Intra2net AG
7  * @license GPLv2
8 */
9
10 #ifndef IPADDRHELPER_H
11 #define IPADDRHELPER_H
12
13 #include "logger.hpp"
14
15 #include <boost/shared_ptr.hpp>
16 #include <curl/curl.h>
17
18 #include <boost/archive/text_oarchive.hpp>
19 #include <boost/archive/text_iarchive.hpp>
20
21
22 class IPAddrHelper
23 {
24
25 private:
26
27     friend class boost::serialization::access;
28     template<class Archive>
29     void serialize(Archive & ar, const unsigned int version)
30     {
31         ar & LastWebcheck;
32     }
33
34     Logger::Ptr Log;
35     std::string WebcheckIpUrl;
36     std::string WebcheckIpUrlAlt;
37     int WebcheckInterval;
38     time_t LastWebcheck;
39     std::string Proxy;
40     int ProxyPort;
41     bool UseIPv6;
42     std::string Hostname;
43
44     bool is_local_ipv4(const std::string ip) const;
45     bool is_local_ipv6(const std::string ip) const;
46     std::string webcheck_ip(bool changed_to_online);
47     CURL * init_curl(std::string& curl_writedata_buff, char* curl_err_buff) const;
48     int perform_curl_operation(CURL * curl_easy_handle, const char* curl_err_buff, const std::string& actual_url) const;
49     std::string parse_ipv4(const std::string& data) const;
50     CURLcode set_curl_url(CURL * curl_easy_handle, const std::string& url) const;
51
52 public:
53
54     typedef boost::shared_ptr<IPAddrHelper> Ptr;
55
56     IPAddrHelper();
57
58     IPAddrHelper(const Logger::Ptr _log, const std::string& _webcheck_url, const std::string& _webcheck_url_alt, const int _webcheck_interval, const time_t _last_webcheck, const bool _use_ipv6, const std::string& _proxy, const int _proxy_port);
59
60     ~IPAddrHelper();
61
62     std::string dns_query(const std::string& _hostname) const;
63
64     std::string get_actual_ip( bool use_webcheck, bool changed_to_online, const std::string &wan_override_ip );
65
66     std::string get_local_wan_nic_ip() const;
67
68     // libcurl is a C library, so we have to make the callback member function static :-(
69     static size_t http_receive(void *inBuffer, size_t size, size_t nmemb, std::string *outBuffer);
70
71     time_t get_last_webcheck() const;
72 };
73
74 #endif