-rw-r--r-- | lib/oauth-consumer.cc | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/oauth-consumer.cc b/lib/oauth-consumer.cc index 0c4c9e3..bb4e89b 100644 --- a/lib/oauth-consumer.cc +++ b/lib/oauth-consumer.cc | |||
@@ -151,17 +151,17 @@ namespace opkele { | |||
151 | if(!rv.secret.empty()) /* TODO: specialize */ | 151 | if(!rv.secret.empty()) /* TODO: specialize */ |
152 | throw opkele::exception(OPKELE_CP_ "found oauth_secret twice"); | 152 | throw opkele::exception(OPKELE_CP_ "found oauth_secret twice"); |
153 | rv.secret = util::url_decode(part.substr(eq+1)); | 153 | rv.secret = util::url_decode(part.substr(eq+1)); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | return rv; | 156 | return rv; |
157 | } | 157 | } |
158 | 158 | ||
159 | void basic_consumer::prepare_request( | 159 | http_request_t& basic_consumer::prepare_request( |
160 | http_request_t& req, | 160 | http_request_t& req, |
161 | const basic_fields& qf,const basic_fields& pf, | 161 | const basic_fields& qf,const basic_fields& pf, |
162 | oauth_method_t om,const string& sm, | 162 | oauth_method_t om,const string& sm, |
163 | const token_t *t,const string& realm) { | 163 | const token_t *t,const string& realm) { |
164 | fields_t op; | 164 | fields_t op; |
165 | op.set_field("oauth_consumer_key",consumer_token.key); | 165 | op.set_field("oauth_consumer_key",consumer_token.key); |
166 | if(t) op.set_field("oauth_token",t->key); | 166 | if(t) op.set_field("oauth_token",t->key); |
167 | op.set_field("oauth_signature_method",sm); | 167 | op.set_field("oauth_signature_method",sm); |
@@ -204,29 +204,41 @@ namespace opkele { | |||
204 | }else if(om==oauth_url_query) { | 204 | }else if(om==oauth_url_query) { |
205 | fields_t q; | 205 | fields_t q; |
206 | qf.append_to(q); op.append_to(q); | 206 | qf.append_to(q); op.append_to(q); |
207 | req.url = q.append_query(req.url); | 207 | req.url = q.append_query(req.url); |
208 | req.body = pf.query_string(); | 208 | req.body = pf.query_string(); |
209 | }else | 209 | }else |
210 | throw opkele::exception(OPKELE_CP_ /* TODO: specialize */ | 210 | throw opkele::exception(OPKELE_CP_ /* TODO: specialize */ |
211 | "Unknown oauth method"); | 211 | "Unknown oauth method"); |
212 | return req; | ||
212 | } | 213 | } |
213 | 214 | ||
214 | void basic_consumer::prepare_request( | 215 | http_request_t& basic_consumer::prepare_request( |
215 | http_request_t& req, | 216 | http_request_t& req, |
216 | const basic_fields& qf,const basic_fields& pf, | 217 | const basic_fields& qf,const basic_fields& pf, |
217 | const service_endpoint_t& sep, | 218 | const service_endpoint_t& sep, |
218 | const token_t *t,const string& realm) { | 219 | const token_t *t,const string& realm) { |
219 | prepare_request( | 220 | return prepare_request( |
220 | req, qf, pf, | 221 | req, qf, pf, |
221 | sep.oauth_method,sep.signature_method, | 222 | sep.oauth_method,sep.signature_method, |
222 | t,realm); | 223 | t,realm); |
223 | } | 224 | } |
224 | 225 | ||
226 | http_request_t& basic_consumer::prepare_request( | ||
227 | http_request_t& req, | ||
228 | const basic_fields& qf,const basic_fields& pf, | ||
229 | const token_t *t,const string& realm) { | ||
230 | service_endpoint_t sep; | ||
231 | return prepare_request( | ||
232 | req, qf, pf, | ||
233 | get_endpoints().get_url_endpoint(sep,req.url), | ||
234 | t, realm ); | ||
235 | } | ||
236 | |||
225 | void http_request_t::setup_curl(CURL *curl) { | 237 | void http_request_t::setup_curl(CURL *curl) { |
226 | CURLcode r; | 238 | CURLcode r; |
227 | r = curl_easy_setopt(curl,CURLOPT_URL,url.c_str()); | 239 | r = curl_easy_setopt(curl,CURLOPT_URL,url.c_str()); |
228 | if(r) | 240 | if(r) |
229 | throw exception_curl(OPKELE_CP_ "failed to set curly urlie",r); | 241 | throw exception_curl(OPKELE_CP_ "failed to set curly urlie",r); |
230 | if(method=="POST") { | 242 | if(method=="POST") { |
231 | (r = curl_easy_setopt(curl,CURLOPT_POST,1)) | 243 | (r = curl_easy_setopt(curl,CURLOPT_POST,1)) |
232 | || (r = curl_easy_setopt(curl,CURLOPT_POSTFIELDS,body.c_str())) | 244 | || (r = curl_easy_setopt(curl,CURLOPT_POSTFIELDS,body.c_str())) |