Commit | Line | Data |
---|---|---|
efbde536 BS |
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 | ||
4de6a9b8 | 13 | #include "logger.hpp" |
efbde536 BS |
14 | |
15 | #include <boost/shared_ptr.hpp> | |
16 | #include <curl/curl.h> | |
17 | ||
18 | ||
19 | class HTTPHelper | |
20 | { | |
92beaba3 | 21 | |
efbde536 BS |
22 | private: |
23 | ||
b30f392d | 24 | Logger::Ptr Log; |
efbde536 BS |
25 | std::string Proxy; |
26 | int ProxyPort; | |
31af6a2e | 27 | CURLcode CurlError; |
e417b034 | 28 | CURLcode CurlInitError; |
efbde536 BS |
29 | CURL* CurlEasyHandle; |
30 | std::string CurlWritedataBuff; | |
1fda5599 | 31 | std::string ReceivedCurlData; |
3ef770e2 | 32 | char CurlErrBuff[CURL_ERROR_SIZE]; |
e417b034 BS |
33 | std::string Username; |
34 | std::string Password; | |
efbde536 | 35 | |
c730deea BS |
36 | CURLcode set_curl_url(const std::string& url); |
37 | CURLcode set_curl_auth(const std::string& username, const std::string& password); | |
31af6a2e | 38 | CURL* init_curl(std::string& curl_writedata_buff, char* curl_err_buff); |
2dd2db3e | 39 | |
efbde536 BS |
40 | public: |
41 | ||
42 | typedef boost::shared_ptr<HTTPHelper> Ptr; | |
43 | ||
44 | HTTPHelper(); | |
45 | ||
2dd2db3e | 46 | HTTPHelper(Logger::Ptr _log, const std::string& _proxy, const int _proxy_port, const std::string& _username, const std::string& _password); |
efbde536 | 47 | |
7de01277 BS |
48 | HTTPHelper(Logger::Ptr _log, const std::string& _proxy, const int _proxy_port); |
49 | ||
efbde536 BS |
50 | ~HTTPHelper(); |
51 | ||
d5a516ba | 52 | long http_get(const std::string& ip); |
efbde536 | 53 | |
b6228761 BS |
54 | std::string get_curl_data() const; |
55 | ||
08a5a621 | 56 | bool is_initialized() const; |
31af6a2e | 57 | |
e417b034 BS |
58 | void re_initialize(); |
59 | ||
efbde536 | 60 | // libcurl is a C library, so we have to make the callback member function static :-( |
0955e6a2 | 61 | static size_t http_receive(void *inBuffer, size_t size, size_t nmemb, std::string *outBuffer); |
efbde536 BS |
62 | }; |
63 | ||
64 | #endif |