summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2008-03-07 19:45:26 (UTC)
committer Michael Krelin <hacker@klever.net>2008-03-07 19:45:26 (UTC)
commit0d19bbaa23b7bd07ec4f5e3683ffdd8df4641bc9 (patch) (unidiff)
tree589401b7985fc8b6c9afeafe48a19569d65dcc4c
parentf56409b28ff418a5317743ad01821609881cd664 (diff)
downloadlibopkele-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>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/opkele/oauth/consumer.h5
-rw-r--r--lib/oauth-consumer.cc28
2 files changed, 33 insertions, 0 deletions
diff --git a/include/opkele/oauth/consumer.h b/include/opkele/oauth/consumer.h
index 1e2784c..9196297 100644
--- a/include/opkele/oauth/consumer.h
+++ b/include/opkele/oauth/consumer.h
@@ -4,6 +4,7 @@
4#include <string> 4#include <string>
5#include <opkele/types.h> 5#include <opkele/types.h>
6#include <opkele/oauth.h> 6#include <opkele/oauth.h>
7#include <opkele/curl.h>
7 8
8namespace opkele { 9namespace opkele {
9 namespace oauth { 10 namespace oauth {
@@ -41,8 +42,12 @@ namespace opkele {
41 string url; 42 string url;
42 string body; 43 string body;
43 44
45 util::curl_slist_t _curl_headers_list;
46
44 http_request_t(const string& m,const string& u) 47 http_request_t(const string& m,const string& u)
45 : method(m), url(u) { } 48 : method(m), url(u) { }
49
50 void setup_curl(CURL *curl);
46 }; 51 };
47 52
48 class basic_consumer { 53 class basic_consumer {
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
@@ -222,6 +222,34 @@ namespace opkele {
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; }