author | Michael Krelin <hacker@klever.net> | 2008-03-07 19:45:26 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2008-03-07 19:45:26 (UTC) |
commit | 0d19bbaa23b7bd07ec4f5e3683ffdd8df4641bc9 (patch) (unidiff) | |
tree | 589401b7985fc8b6c9afeafe48a19569d65dcc4c /lib | |
parent | f56409b28ff418a5317743ad01821609881cd664 (diff) | |
download | libopkele-0d19bbaa23b7bd07ec4f5e3683ffdd8df4641bc9.zip libopkele-0d19bbaa23b7bd07ec4f5e3683ffdd8df4641bc9.tar.gz libopkele-0d19bbaa23b7bd07ec4f5e3683ffdd8df4641bc9.tar.bz2 |
added a helper to prepare curl request based on http_request_t
* added curl_slist to http_request_t structure
* added http_request_t::setup_curl(CURL*)
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | lib/oauth-consumer.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/oauth-consumer.cc b/lib/oauth-consumer.cc index d717ed3..0c4c9e3 100644 --- a/lib/oauth-consumer.cc +++ b/lib/oauth-consumer.cc | |||
@@ -219,12 +219,40 @@ namespace opkele { | |||
219 | prepare_request( | 219 | prepare_request( |
220 | req, qf, pf, | 220 | req, qf, pf, |
221 | sep.oauth_method,sep.signature_method, | 221 | sep.oauth_method,sep.signature_method, |
222 | t,realm); | 222 | t,realm); |
223 | } | 223 | } |
224 | 224 | ||
225 | void http_request_t::setup_curl(CURL *curl) { | ||
226 | CURLcode r; | ||
227 | r = curl_easy_setopt(curl,CURLOPT_URL,url.c_str()); | ||
228 | if(r) | ||
229 | throw exception_curl(OPKELE_CP_ "failed to set curly urlie",r); | ||
230 | if(method=="POST") { | ||
231 | (r = curl_easy_setopt(curl,CURLOPT_POST,1)) | ||
232 | || (r = curl_easy_setopt(curl,CURLOPT_POSTFIELDS,body.c_str())) | ||
233 | || (r = curl_easy_setopt(curl,CURLOPT_POSTFIELDSIZE,body.size())); | ||
234 | }else if(method=="GET") { | ||
235 | r = curl_easy_setopt(curl,CURLOPT_HTTPGET,1); | ||
236 | }else if(method=="HEAD") { | ||
237 | r = curl_easy_setopt(curl,CURLOPT_NOBODY,1); | ||
238 | }else /* TODO: specialize exception */ | ||
239 | throw exception(OPKELE_CP_ "don't know how to handle http method"); | ||
240 | if(r) | ||
241 | throw exception_curl(OPKELE_CP_ "failed to set curly options",r); | ||
242 | if(!authorize_header.empty()) { | ||
243 | r = curl_easy_setopt(curl,CURLOPT_HTTPHEADER,(curl_slist*)( | ||
244 | _curl_headers_list = curl_slist_append( | ||
245 | 0,string("Authorization: "+authorize_header).c_str() | ||
246 | ) | ||
247 | ) ); | ||
248 | if(r) | ||
249 | throw exception_curl(OPKELE_CP_ "failed to setup curlie header"); | ||
250 | } | ||
251 | } | ||
252 | |||
225 | 253 | ||
226 | const basic_provider_endpoints& simple_consumer::get_endpoints() const { | 254 | const basic_provider_endpoints& simple_consumer::get_endpoints() const { |
227 | return peps; } | 255 | return peps; } |
228 | 256 | ||
229 | const string simple_consumer::allocate_nonce(time_t ts) { | 257 | const string simple_consumer::allocate_nonce(time_t ts) { |
230 | # ifndef HAVE_LIBUUID | 258 | # ifndef HAVE_LIBUUID |