author | Michael Krelin <hacker@klever.net> | 2007-11-24 12:02:50 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-11-24 12:02:50 (UTC) |
commit | 986274e9f9a8e2ef0f92b08d2d2c9485bd19adec (patch) (unidiff) | |
tree | 72b3d134d9d635b2aadbdebf615e1717dd9d683b /lib | |
parent | ef66d79bf58f099179a932ca80d07ca93a42909c (diff) | |
download | libopkele-986274e9f9a8e2ef0f92b08d2d2c9485bd19adec.zip libopkele-986274e9f9a8e2ef0f92b08d2d2c9485bd19adec.tar.gz libopkele-986274e9f9a8e2ef0f92b08d2d2c9485bd19adec.tar.bz2 |
moved curl_t wrapper to util namespace
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | lib/consumer.cc | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/lib/consumer.cc b/lib/consumer.cc index 7881f5f..20f4174 100644 --- a/lib/consumer.cc +++ b/lib/consumer.cc | |||
@@ -1,15 +1,14 @@ | |||
1 | #include <algorithm> | 1 | #include <algorithm> |
2 | #include <cassert> | 2 | #include <cassert> |
3 | #include <cstring> | 3 | #include <cstring> |
4 | #include <opkele/util.h> | 4 | #include <opkele/util.h> |
5 | #include <opkele/curl.h> | ||
5 | #include <opkele/exception.h> | 6 | #include <opkele/exception.h> |
6 | #include <opkele/data.h> | 7 | #include <opkele/data.h> |
7 | #include <opkele/consumer.h> | 8 | #include <opkele/consumer.h> |
8 | #include <openssl/sha.h> | 9 | #include <openssl/sha.h> |
9 | #include <openssl/hmac.h> | 10 | #include <openssl/hmac.h> |
10 | #include <curl/curl.h> | ||
11 | |||
12 | #include <iostream> | 11 | #include <iostream> |
13 | 12 | ||
14 | #include "config.h" | 13 | #include "config.h" |
15 | 14 | ||
@@ -61,22 +60,8 @@ namespace opkele { | |||
61 | return pcre_exec(_p,NULL,s.c_str(),s.length(),0,0,m._ov,m._s); | 60 | return pcre_exec(_p,NULL,s.c_str(),s.length(),0,0,m._ov,m._s); |
62 | } | 61 | } |
63 | }; | 62 | }; |
64 | 63 | ||
65 | class curl_t { | ||
66 | public: | ||
67 | CURL *_c; | ||
68 | |||
69 | curl_t() : _c(0) { } | ||
70 | curl_t(CURL *c) : _c(c) { } | ||
71 | ~curl_t() throw() { if(_c) curl_easy_cleanup(_c); } | ||
72 | |||
73 | curl_t& operator=(CURL *c) { if(_c) curl_easy_cleanup(_c); _c=c; return *this; } | ||
74 | |||
75 | operator const CURL*(void) const { return _c; } | ||
76 | operator CURL*(void) { return _c; } | ||
77 | }; | ||
78 | |||
79 | static CURLcode curl_misc_sets(CURL* c) { | 64 | static CURLcode curl_misc_sets(CURL* c) { |
80 | CURLcode r; | 65 | CURLcode r; |
81 | (r=curl_easy_setopt(c,CURLOPT_FOLLOWLOCATION,1)) | 66 | (r=curl_easy_setopt(c,CURLOPT_FOLLOWLOCATION,1)) |
82 | || (r=curl_easy_setopt(c,CURLOPT_MAXREDIRS,5)) | 67 | || (r=curl_easy_setopt(c,CURLOPT_MAXREDIRS,5)) |
@@ -115,9 +100,9 @@ namespace opkele { | |||
115 | "&openid.assoc_type=HMAC-SHA1" | 100 | "&openid.assoc_type=HMAC-SHA1" |
116 | "&openid.session_type=DH-SHA1" | 101 | "&openid.session_type=DH-SHA1" |
117 | "&openid.dh_consumer_public="; | 102 | "&openid.dh_consumer_public="; |
118 | request += util::url_encode(util::bignum_to_base64(dh->pub_key)); | 103 | request += util::url_encode(util::bignum_to_base64(dh->pub_key)); |
119 | curl_t curl = curl_easy_init(); | 104 | util::curl_t curl = curl_easy_init(); |
120 | if(!curl) | 105 | if(!curl) |
121 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); | 106 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); |
122 | string response; | 107 | string response; |
123 | CURLcode r; | 108 | CURLcode r; |
@@ -275,9 +260,9 @@ namespace opkele { | |||
275 | request += '='; | 260 | request += '='; |
276 | request += util::url_encode(i->second); | 261 | request += util::url_encode(i->second); |
277 | } | 262 | } |
278 | } | 263 | } |
279 | curl_t curl = curl_easy_init(); | 264 | util::curl_t curl = curl_easy_init(); |
280 | if(!curl) | 265 | if(!curl) |
281 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); | 266 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); |
282 | string response; | 267 | string response; |
283 | CURLcode r; | 268 | CURLcode r; |
@@ -308,9 +293,9 @@ namespace opkele { | |||
308 | 293 | ||
309 | void consumer_t::retrieve_links(const string& url,string& server,string& delegate) { | 294 | void consumer_t::retrieve_links(const string& url,string& server,string& delegate) { |
310 | server.erase(); | 295 | server.erase(); |
311 | delegate.erase(); | 296 | delegate.erase(); |
312 | curl_t curl = curl_easy_init(); | 297 | util::curl_t curl = curl_easy_init(); |
313 | if(!curl) | 298 | if(!curl) |
314 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); | 299 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); |
315 | string html; | 300 | string html; |
316 | CURLcode r; | 301 | CURLcode r; |
@@ -414,9 +399,9 @@ namespace opkele { | |||
414 | } | 399 | } |
415 | 400 | ||
416 | string consumer_t::canonicalize(const string& url) { | 401 | string consumer_t::canonicalize(const string& url) { |
417 | string rv = normalize(url); | 402 | string rv = normalize(url); |
418 | curl_t curl = curl_easy_init(); | 403 | util::curl_t curl = curl_easy_init(); |
419 | if(!curl) | 404 | if(!curl) |
420 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); | 405 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); |
421 | string html; | 406 | string html; |
422 | CURLcode r; | 407 | CURLcode r; |