Added config option for starting in offline mode.
[bpdyndnsd] / src / httphelper.h
1 /** @file
2  * @brief HTTPHelper class header. This class represents a Helper to perform HTTP operations easily.
3  *
4  *
5  *
6  * @copyright Intra2net AG
7  * @license GPLv2
8 */
9
10 #ifndef HTTPHELPER_H
11 #define HTTPHELPER_H
12
13 #include "logger.h"
14
15 #include <boost/shared_ptr.hpp>
16 #include <curl/curl.h>
17
18
19 class HTTPHelper
20 {
21
22 private:
23
24     Logger::Ptr Log;
25     std::string Proxy;
26     int ProxyPort;
27     CURLcode CurlError;
28     CURL* CurlEasyHandle;
29     std::string CurlWritedataBuff;
30     std::string ReceivedCurlData;
31     char CurlErrBuff[CURL_ERROR_SIZE];
32
33     CURLcode set_curl_url(const std::string& url);
34     CURLcode set_curl_auth(const std::string& username, const std::string& password);
35     CURL* init_curl(std::string& curl_writedata_buff, char* curl_err_buff);
36
37 public:
38
39     typedef boost::shared_ptr<HTTPHelper> Ptr;
40
41     HTTPHelper();
42
43     HTTPHelper(Logger::Ptr _log, const std::string& _proxy, const int _proxy_port, const std::string& _username, const std::string& _password);
44
45     HTTPHelper(Logger::Ptr _log, const std::string& _proxy, const int _proxy_port);
46
47     ~HTTPHelper();
48
49     long http_get(const std::string& ip);
50
51     std::string get_curl_data() const;
52
53     bool is_initialized() const;
54
55     // libcurl is a C library, so we have to make the callback member function static :-(
56     static size_t http_receive(const char *inBuffer, size_t size, size_t nmemb, std::string *outBuffer);
57 };
58
59 #endif