1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*
* curlfuncs.h
*
* See the README file for copyright information and how to reach the author.
*
*/
#ifndef __LIB_CURL__
#define __LIB_CURL__
#include <curl/curl.h>
#include <curl/easy.h>
#include <string>
#include "common.h"
#include "config.h"
#include "configuration.h"
#define CURL_USERAGENT "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Mayukh's libcurl wrapper http://www.mayukhbose.com/)"
//***************************************************************************
// CURL
//***************************************************************************
class cCurl
{
public:
cCurl();
~cCurl();
int init(const char* httpproxy = "");
int exit();
static int create();
static int destroy();
int GetUrl(const char *url, std::string *sOutput, const std::string &sReferer="");
int GetUrlFile(const char *url, const char *filename, const std::string &sReferer="");
int SetCookieFile(char *filename);
int PostUrl(const char *url, const std::string &sPost, std::string *sOutput, const std::string &sReferer = "");
int PostRaw(const char *url, const std::string &sPost, std::string *sOutput, const std::string &sReferer = "");
int DoPost(const char *url, std::string *sOutput, const std::string &sReferer,
struct curl_httppost *formpost, struct curl_slist *headerlist);
char* EscapeUrl(const char *url);
void Free(char* str);
int downloadFile(const char* url, int& size, MemoryStruct* data, int timeout = 30,
const char* userAgent = CURL_USERAGENT, struct curl_slist *headerlist = 0);
// static stuff
static void setSystemNotification(cSystemNotification* s) { sysNotification = s; }
static std::string sBuf; // dirty
protected:
// data
CURL* handle;
static cSystemNotification* sysNotification;
// statics
static size_t WriteMemoryCallback(void* ptr, size_t size, size_t nmemb, void* data);
static size_t WriteHeaderCallback(char* ptr, size_t size, size_t nmemb, void* data);
static int curlInitialized;
};
extern cCurl curl;
//***************************************************************************
#endif // __LIB_CURL__
|