fastdo  0.6.16
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 
14 {
15 public:
16  CUrlError( int errNo, winux::AnsiString const & errStr ) : winux::Error( errNo, errStr ) { }
17 };
18 
21 {
22 public:
23  static char const * GetVersion();
24 
25  CUrlLib();
26  ~CUrlLib();
28 };
29 
32 {
33 public:
34  SList();
35  virtual ~SList();
36  void free();
37  void append( char const * s );
38  void append( winux::AnsiString const & str );
39 
40  operator struct curl_slist * () const { return _slist; }
41 private:
42  struct curl_slist * _slist;
43 
45 };
46 
49 {
50 public:
51  PostMultipart();
52  virtual ~PostMultipart();
53  void free();
55  void addVar( winux::AnsiString const & name, winux::AnsiString const & value );
57  void addFile( winux::AnsiString const & name, winux::AnsiString const & filename, winux::AnsiString const & showfilename = "" );
59  void addFile( winux::AnsiString const & name, char const * data, long size, winux::AnsiString 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 
68 };
69 
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::AnsiString 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::AnsiString const & username );
120 
122  void setPassword( winux::AnsiString const & password );
123 
125  void setPostFields( winux::AnsiString 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::AnsiString 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  // get curlinfo after call perform() --------------------------
179  winux::AnsiString getContentType() const;
180 
181  // attributes -------------------------------------------------
182  operator CURL * () const { return _curl; }
183 
185  int errNo() const { return _errNo; }
186 
188  char const * errNoStr() const;
189 
191  char const * error() const;
192 
193 protected:
194  // '写'回调函数,回调函数将转到成员虚函数进行响应
195  static size_t WriteCallback( char * buf, size_t itemSize, size_t count, void * data );
196  // 当发生'写'动作
197  virtual size_t OnWrite( char * buf, size_t itemSize, size_t count );
198 
199  // '读'回调函数
200  static size_t ReadCallback( char * buf, size_t itemSize, size_t count, void * data );
201  // 当发生'读'动作
202  virtual size_t OnRead( char * buf, size_t itemSize, size_t count );
203 
204  // '头部'数据回调函数
205  static size_t HeaderCallback( char * buf, size_t itemSize, size_t count, void * data );
206  // 当'头部'数据到
207  virtual size_t OnHeader( char * buf, size_t itemSize, size_t count );
208 
209  // '进度'回调函数
210  static int ProgressCallback( void * data, double dltotal, double dlnow, double ultotal, double ulnow );
211  // 当'下载进度'操作
212  virtual int OnDownloadProgress( double dltotal, double dlnow );
213  // 当'上传进度'操作
214  virtual int OnUploadProgress( double ultotal, double ulnow );
215 
216 protected:
218  int _errNo;
220 };
221 
222 
223 } // namespace eiennet
224 
225 #endif // __CURL_HPP__
XString< char > AnsiString
Definition: utilities.hpp:257
curl库初始化
libcurl的字符串链表
#define DISABLE_OBJECT_COPY(clsname)
Definition: utilities.hpp:85
void CURL
Definition: eiennet_curl.hpp:5
#define EIENNET_DLL
winux::AnsiString _errBuf
网络通信库
http post请求以“multipart/formdata”方式发送数据的支持类
CUrlError(int errNo, winux::AnsiString const &errStr)
错误类
Definition: utilities.hpp:838
int errNo() const
执行后得到的错误码(CURLcode)
unsigned long ulong
Definition: utilities.hpp:216
int _errNo
CURLcode.
libcurl低层封装,主要提供了CURL句柄资源管理功能
跨平台基础功能库
Definition: archives.hpp:7