-rw-r--r-- | include/opkele/curl.h | 20 | ||||
-rw-r--r-- | lib/curl.cc | 20 |
2 files changed, 40 insertions, 0 deletions
diff --git a/include/opkele/curl.h b/include/opkele/curl.h index 5cf8e48..bcaf11d 100644 --- a/include/opkele/curl.h +++ b/include/opkele/curl.h | |||
@@ -12,6 +12,24 @@ namespace opkele { | |||
12 | 12 | ||
13 | namespace util { | 13 | namespace util { |
14 | 14 | ||
15 | class curl_slist_t { | ||
16 | public: | ||
17 | curl_slist *_s; | ||
18 | |||
19 | curl_slist_t() : _s(0) { } | ||
20 | curl_slist_t(curl_slist *s) : _s(s) { } | ||
21 | virtual ~curl_slist_t() throw(); | ||
22 | |||
23 | curl_slist_t& operator=(curl_slist *s); | ||
24 | |||
25 | operator const curl_slist*(void) const { return _s; } | ||
26 | operator curl_slist*(void) { return _s; } | ||
27 | |||
28 | void append(const char *str); | ||
29 | void append(const string& str) { | ||
30 | append(str.c_str()); } | ||
31 | }; | ||
32 | |||
15 | class curl_t { | 33 | class curl_t { |
16 | public: | 34 | public: |
17 | CURL *_c; | 35 | CURL *_c; |
@@ -29,6 +47,8 @@ namespace opkele { | |||
29 | 47 | ||
30 | template<typename PT> | 48 | template<typename PT> |
31 | inline CURLcode easy_setopt(CURLoption o,PT p) { assert(_c); return curl_easy_setopt(_c,o,p); } | 49 | inline CURLcode easy_setopt(CURLoption o,PT p) { assert(_c); return curl_easy_setopt(_c,o,p); } |
50 | inline CURLcode easy_setopt(CURLoption o,const curl_slist_t& p) { | ||
51 | assert(_c); return curl_easy_setopt(_c,o,(const curl_slist*)p); } | ||
32 | CURLcode easy_perform() { assert(_c); return curl_easy_perform(_c); } | 52 | CURLcode easy_perform() { assert(_c); return curl_easy_perform(_c); } |
33 | template<typename IT> | 53 | template<typename IT> |
34 | inline CURLcode easy_getinfo(CURLINFO i,IT p) { assert(_c); return curl_easy_getinfo(_c,i,p); } | 54 | inline CURLcode easy_getinfo(CURLINFO i,IT p) { assert(_c); return curl_easy_getinfo(_c,i,p); } |
diff --git a/lib/curl.cc b/lib/curl.cc index 6172828..734e2ca 100644 --- a/lib/curl.cc +++ b/lib/curl.cc | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <opkele/exception.h> | ||
1 | #include <opkele/curl.h> | 2 | #include <opkele/curl.h> |
2 | 3 | ||
3 | #include "config.h" | 4 | #include "config.h" |
@@ -6,6 +7,25 @@ namespace opkele { | |||
6 | 7 | ||
7 | namespace util { | 8 | namespace util { |
8 | 9 | ||
10 | curl_slist_t::~curl_slist_t() throw() { | ||
11 | if(_s) | ||
12 | curl_slist_free_all(_s); | ||
13 | } | ||
14 | |||
15 | curl_slist_t& curl_slist_t::operator=(curl_slist *s) { | ||
16 | if(_s) | ||
17 | curl_slist_free_all(_s); | ||
18 | _s = s; | ||
19 | return *this; | ||
20 | } | ||
21 | |||
22 | void curl_slist_t::append(const char *str) { | ||
23 | curl_slist *s = curl_slist_append(_s,str); | ||
24 | if(!s) | ||
25 | throw opkele::exception(OPKELE_CP_ "failed to curl_slist_append()"); | ||
26 | _s=s; | ||
27 | } | ||
28 | |||
9 | curl_t::~curl_t() throw() { | 29 | curl_t::~curl_t() throw() { |
10 | if(_c) | 30 | if(_c) |
11 | curl_easy_cleanup(_c); | 31 | curl_easy_cleanup(_c); |