fastdo
0.6.8
首页
命名空间
类
文件
文件列表
文件成员
eiennet_curl.hpp
浏览该文件的文档.
1
#ifndef __CURL_HPP__
2
#define __CURL_HPP__
3
4
// curl.h的一些类型
5
typedef
void
CURL
;
6
struct
curl_slist;
7
struct
curl_httppost;
8
9
namespace
eiennet
10
{
11
13
class
EIENNET_DLL
CUrlError
:
public
winux::Error
14
{
15
public
:
16
CUrlError
(
int
errNo,
char
const
* err ) :
winux
::Error( errNo, err ) { }
17
};
18
20
class
EIENNET_DLL
CUrlLib
21
{
22
public
:
23
static
char
const
* GetVersion();
24
25
CUrlLib
();
26
~
CUrlLib
();
27
DISABLE_OBJECT_COPY
(
CUrlLib
)
28
};
29
31
class
EIENNET_DLL
SList
32
{
33
public
:
34
SList
();
35
virtual
~
SList
();
36
void
free();
37
void
append(
char
const
* s );
38
void
append(
winux::String
const
& str );
39
40
operator
struct
curl_slist * ()
const
{
return
_slist; }
41
private
:
42
struct
curl_slist * _slist;
43
44
DISABLE_OBJECT_COPY
(
SList
)
45
};
46
48
class
EIENNET_DLL
PostMultipart
49
{
50
public
:
51
PostMultipart
();
52
virtual
~
PostMultipart
();
53
void
free();
55
void
addVar(
winux::String
const
& name,
winux::String
const
& value );
57
void
addFile(
winux::String
const
& name,
winux::String
const
& filename,
winux::String
const
& showfilename =
""
);
59
void
addFile(
winux::String
const
& name,
char
const
* data,
long
size,
winux::String
const
& showfilename );
60
61
operator
struct
curl_httppost * ()
const
{
return
_first; }
62
63
private
:
64
struct
curl_httppost * _first;
65
struct
curl_httppost * _last;
66
67
DISABLE_OBJECT_COPY
(
PostMultipart
)
68
};
69
71
class
EIENNET_DLL
CUrl
72
{
73
public
:
75
CUrl
(
bool
isInit =
true
);
76
CUrl
(
CUrl
const
& other );
77
virtual
~
CUrl
();
78
80
CUrl
& operator = (
CUrl
const
& other );
81
83
void
init();
84
86
void
cleanup();
87
89
bool
perform();
90
92
void
reset();
93
94
// set options ------------------------------------------------
98
void
setHttpGet(
bool
b =
true
);
99
104
void
setHttpPost(
bool
b =
true
);
105
107
void
setUrl(
winux::String
const
& url );
108
110
void
setTimeout(
winux::ulong
timeout );
111
113
void
setErrorBuffer(
char
* errBuf );
114
116
void
setNoProgress(
bool
b );
117
119
void
setUsername(
winux::String
const
& username );
120
122
void
setPassword(
winux::String
const
& password );
123
125
void
setPostFields(
winux::String
const
& data );
126
128
void
setPostFieldSize(
long
size );
129
131
void
setPostMultipart(
PostMultipart
const
& data );
132
134
void
setHttpHeader(
SList
const
& headers );
135
137
void
setVerbose(
bool
b );
138
140
void
setCookieJar(
winux::String
const
& filename );
141
145
void
setSslVerifyPeer(
bool
b );
146
150
void
setSslVerifyHost(
bool
b );
151
152
// set handlers -----------------------------------------------
153
typedef
size_t (* WriteFunction)(
char
* buf,
size_t
itemSize,
size_t
count,
void
* data );
155
void
setWriteHandler( WriteFunction handler );
157
void
setWriteHandlerData(
void
* data );
158
159
typedef
size_t (* ReadFunction)(
char
* buf,
size_t
itemSize,
size_t
count,
void
* data );
161
void
setReadHandler( ReadFunction handler );
163
void
setReadHandlerData(
void
* data );
164
165
typedef
size_t (* HeaderFunction)(
char
* buf,
size_t
itemSize,
size_t
count,
void
* data );
167
void
setHeaderHandler( HeaderFunction handler );
169
void
setHeaderHandlerData(
void
* data );
170
171
typedef
int (* ProgressFunction)(
void
* data,
double
dltotal,
double
dlnow,
double
ultotal,
double
ulnow );
173
void
setProgressHandler( ProgressFunction handler );
175
void
setProgressHandlerData(
void
* data );
176
177
// attributes -------------------------------------------------
178
operator
CURL
* ()
const
{
return
_curl; }
179
181
int
errNo
()
const
{
return
_errNo; }
182
184
char
const
* errNoStr()
const
;
185
187
char
const
* error()
const
;
188
189
protected
:
190
// '写'回调函数,回调函数将转到成员虚函数进行响应
191
static
size_t
WriteCallback(
char
* buf,
size_t
itemSize,
size_t
count,
void
* data );
192
// 当发生'写'动作
193
virtual
size_t
OnWrite(
char
* buf,
size_t
itemSize,
size_t
count );
194
195
// '读'回调函数
196
static
size_t
ReadCallback(
char
* buf,
size_t
itemSize,
size_t
count,
void
* data );
197
// 当发生'读'动作
198
virtual
size_t
OnRead(
char
* buf,
size_t
itemSize,
size_t
count );
199
200
// '头部'数据回调函数
201
static
size_t
HeaderCallback(
char
* buf,
size_t
itemSize,
size_t
count,
void
* data );
202
// 当'头部'数据到
203
virtual
size_t
OnHeader(
char
* buf,
size_t
itemSize,
size_t
count );
204
205
// '进度'回调函数
206
static
int
ProgressCallback(
void
* data,
double
dltotal,
double
dlnow,
double
ultotal,
double
ulnow );
207
// 当'下载进度'操作
208
virtual
int
OnDownloadProgress(
double
dltotal,
double
dlnow );
209
// 当'上传进度'操作
210
virtual
int
OnUploadProgress(
double
ultotal,
double
ulnow );
211
212
protected
:
213
CURL
*
_curl
;
214
int
_errNo
;
215
winux::AnsiString
_errBuf
;
216
};
217
219
class
EIENNET_DLL
HttpCUrl
:
public
CUrl
220
{
221
public
:
222
HttpCUrl
();
223
virtual
~
HttpCUrl
();
224
228
winux::Buffer
const
& getResponse()
const
;
229
233
char
const
* getResponseStr(
size_t
* size = NULL )
const
;
234
236
size_t
getResponseSize()
const
;
237
239
winux::String
getResponseContentType()
const
;
240
242
winux::String
getResponseMime()
const
;
243
245
winux::String
getResponseCharset()
const
;
246
248
bool
get
(
winux::String
const
& url,
http::Header
const
& headers =
http::Header
() );
250
bool
post(
winux::String
const
& url,
winux::Mixed
const
& postVars =
winux::Mixed
(),
http::Header
const
& headers =
http::Header
() );
252
bool
post(
winux::String
const
& url,
PostMultipart
const
& multipart,
http::Header
const
& headers =
http::Header
() );
254
bool
post(
winux::String
const
& url,
winux::String
const
& contentType,
winux::AnsiString
const
& postData,
http::Header
const
& headers =
http::Header
() );
255
256
protected
:
257
// 当发生'写'动作
258
virtual
size_t
OnWrite(
char
* buf,
size_t
itemSize,
size_t
count );
259
260
private
:
261
winux::GrowBuffer
_response;
262
winux::String
_contentType;
263
};
264
265
266
}
// namespace eiennet
267
268
#endif // __CURL_HPP__
winux::AnsiString
XString< char > AnsiString
Definition:
utilities.hpp:212
http::Header
代表HTTP头部
Definition:
http_misc.hpp:10
eiennet::CUrlLib
curl库初始化
Definition:
eiennet_curl.hpp:20
eiennet::SList
libcurl的字符串链表
Definition:
eiennet_curl.hpp:31
eiennet::CUrl::_curl
CURL * _curl
Definition:
eiennet_curl.hpp:213
winux::String
XString< tchar > String
Definition:
utilities.hpp:216
DISABLE_OBJECT_COPY
#define DISABLE_OBJECT_COPY(clsname)
Definition:
utilities.hpp:81
eiennet::CUrlError::CUrlError
CUrlError(int errNo, char const *err)
Definition:
eiennet_curl.hpp:16
CURL
void CURL
Definition:
eiennet_curl.hpp:5
eiennet::HttpCUrl
CURL的HTTP协议封装,默认30秒超时
Definition:
eiennet_curl.hpp:219
winux::Buffer
缓冲区,表示内存中一块二进制数据(利用malloc/realloc进行内存分配)
Definition:
utilities.hpp:528
EIENNET_DLL
#define EIENNET_DLL
Definition:
eiennet_base.hpp:22
eiennet::CUrl::_errBuf
winux::AnsiString _errBuf
Definition:
eiennet_curl.hpp:215
eiennet
网络通信库
Definition:
eiennet_base.hpp:30
winux::GrowBuffer
高效的可增长缓冲区,1.33倍冗余量
Definition:
utilities.hpp:659
eiennet::PostMultipart
http post请求以“multipart/formdata”方式发送数据的支持类
Definition:
eiennet_curl.hpp:48
winux::Mixed
混合体,能表示多种类型的值
Definition:
utilities.hpp:750
winux::Error
错误类
Definition:
utilities.hpp:505
eiennet::CUrl::errNo
int errNo() const
执行后得到的错误码(CURLcode)
Definition:
eiennet_curl.hpp:181
eiennet::CUrlError
curl错误
Definition:
eiennet_curl.hpp:13
winux::ulong
unsigned long ulong
Definition:
utilities.hpp:171
eiennet::CUrl::_errNo
int _errNo
CURLcode.
Definition:
eiennet_curl.hpp:214
eiennet::CUrl
libcurl低层封装,主要提供了CURL句柄资源管理功能
Definition:
eiennet_curl.hpp:71
winux
跨平台基础功能库
Definition:
archives.hpp:7
build
windows
include
eiennet_curl.hpp
生成于 2023年 六月 18日 星期日 10:25:57 , 为 fastdo使用
1.8.11