-rw-r--r-- | lib/curl.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/curl.cc b/lib/curl.cc index 418aa79..3e69b47 100644 --- a/lib/curl.cc +++ b/lib/curl.cc | |||
@@ -1,42 +1,54 @@ | |||
1 | #include <opkele/curl.h> | 1 | #include <opkele/curl.h> |
2 | 2 | ||
3 | #include "config.h" | 3 | #include "config.h" |
4 | 4 | ||
5 | namespace opkele { | 5 | namespace opkele { |
6 | 6 | ||
7 | namespace util { | 7 | namespace util { |
8 | 8 | ||
9 | curl_t::~curl_t() throw() { | 9 | curl_t::~curl_t() throw() { |
10 | if(_c) | 10 | if(_c) |
11 | curl_easy_cleanup(_c); | 11 | curl_easy_cleanup(_c); |
12 | } | 12 | } |
13 | 13 | ||
14 | curl_t& curl_t::operator=(CURL *c) { | 14 | curl_t& curl_t::operator=(CURL *c) { |
15 | if(_c) | 15 | if(_c) |
16 | curl_easy_cleanup(_c); | 16 | curl_easy_cleanup(_c); |
17 | _c = c; | 17 | _c = c; |
18 | return *this; | 18 | return *this; |
19 | } | 19 | } |
20 | 20 | ||
21 | CURLcode curl_t::misc_sets() { | 21 | CURLcode curl_t::misc_sets() { |
22 | assert(_c); | 22 | assert(_c); |
23 | CURLcode r; | 23 | CURLcode r; |
24 | (r=easy_setopt(CURLOPT_FOLLOWLOCATION,1)) | 24 | (r=easy_setopt(CURLOPT_FOLLOWLOCATION,1)) |
25 | || (r=easy_setopt(CURLOPT_MAXREDIRS,5)) | 25 | || (r=easy_setopt(CURLOPT_MAXREDIRS,5)) |
26 | || (r=easy_setopt(CURLOPT_DNS_CACHE_TIMEOUT,120)) | 26 | || (r=easy_setopt(CURLOPT_DNS_CACHE_TIMEOUT,120)) |
27 | || (r=easy_setopt(CURLOPT_DNS_USE_GLOBAL_CACHE,1)) | 27 | || (r=easy_setopt(CURLOPT_DNS_USE_GLOBAL_CACHE,1)) |
28 | || (r=easy_setopt(CURLOPT_USERAGENT,PACKAGE_NAME"/"PACKAGE_SRC_VERSION)) | 28 | || (r=easy_setopt(CURLOPT_USERAGENT,PACKAGE_NAME"/"PACKAGE_SRC_VERSION)) |
29 | || (r=easy_setopt(CURLOPT_TIMEOUT,20)) | 29 | || (r=easy_setopt(CURLOPT_TIMEOUT,20)) |
30 | #ifdefDISABLE_CURL_SSL_VERIFYHOST | 30 | #ifdefDISABLE_CURL_SSL_VERIFYHOST |
31 | || (r=easy_setopt(CURLOPT_SSL_VERIFYHOST,0)) | 31 | || (r=easy_setopt(CURLOPT_SSL_VERIFYHOST,0)) |
32 | #endif | 32 | #endif |
33 | #ifdefDISABLE_CURL_SSL_VERIFYPEER | 33 | #ifdefDISABLE_CURL_SSL_VERIFYPEER |
34 | || (r=easy_setopt(CURLOPT_SSL_VERIFYPEER,0)) | 34 | || (r=easy_setopt(CURLOPT_SSL_VERIFYPEER,0)) |
35 | #endif | 35 | #endif |
36 | ; | 36 | ; |
37 | return r; | 37 | return r; |
38 | } | 38 | } |
39 | 39 | ||
40 | static size_t _write(void *p,size_t s,size_t nm,void *stream) { | ||
41 | return ((curl_t*)stream)->write(p,s,nm); | ||
42 | } | ||
43 | |||
44 | CURLcode curl_t::set_write() { | ||
45 | assert(_c); | ||
46 | CURLcode r; | ||
47 | (r = easy_setopt(CURLOPT_WRITEDATA,this)) | ||
48 | || (r = easy_setopt(CURLOPT_WRITEFUNCTION,_write)); | ||
49 | return r; | ||
50 | } | ||
51 | |||
40 | } | 52 | } |
41 | 53 | ||
42 | } | 54 | } |