- Timestamp:
- 2010-04-27T22:42:07Z (15 years ago)
- Branches:
- master
- Children:
- 0bff877
- Parents:
- ee84bdb
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/oauth.c
ree84bdb r18dbb20 225 225 } 226 226 227 void oauth_info_free( struct oauth_info *info ) 228 { 229 if( info ) 230 { 231 g_free( info->auth_params ); 232 g_free( info->request_token ); 233 g_free( info->access_token ); 234 g_free( info ); 235 } 236 } 237 227 238 static void oauth_add_default_params( GSList **params ) 228 239 { … … 286 297 static void oauth_request_token_done( struct http_request *req ); 287 298 288 void*oauth_request_token( const char *url, oauth_cb func, void *data )299 struct oauth_info *oauth_request_token( const char *url, oauth_cb func, void *data ) 289 300 { 290 301 struct oauth_info *st = g_new0( struct oauth_info, 1 ); … … 296 307 oauth_params_add( ¶ms, "oauth_callback", "oob" ); 297 308 298 return oauth_post_request( url, NULL, oauth_request_token_done, st ); 309 if( !oauth_post_request( url, ¶ms, oauth_request_token_done, st ) ) 310 { 311 oauth_info_free( st ); 312 return NULL; 313 } 314 315 return st; 299 316 } 300 317 … … 316 333 317 334 st->stage = OAUTH_REQUEST_TOKEN; 318 st->func( st ); 335 if( !st->func( st ) ) 336 oauth_info_free( st ); 319 337 } 320 338 321 339 static void oauth_access_token_done( struct http_request *req ); 322 340 323 void *oauth_access_token( const char *url, const char *pin, struct oauth_info *st )341 void oauth_access_token( const char *url, const char *pin, struct oauth_info *st ) 324 342 { 325 343 GSList *params = NULL; … … 328 346 oauth_params_add( ¶ms, "oauth_verifier", pin ); 329 347 330 return oauth_post_request( url, ¶ms, oauth_access_token_done, st ); 348 if( !oauth_post_request( url, ¶ms, oauth_access_token_done, st ) ) 349 oauth_info_free( st ); 331 350 } 332 351 … … 337 356 if( req->status_code == 200 ) 338 357 { 339 GSList *params ;358 GSList *params = NULL; 340 359 const char *token, *token_secret; 341 360 … … 350 369 st->stage = OAUTH_ACCESS_TOKEN; 351 370 st->func( st ); 371 oauth_info_free( st ); 352 372 } 353 373 … … 358 378 GString *ret = NULL; 359 379 380 /* First, get the two pieces of info from the access token that we need. */ 360 381 oauth_params_parse( ¶ms, access_token ); 361 382 if( params == NULL ) 362 383 goto err; 384 385 /* Pick out the token secret, we shouldn't include it but use it for signing. */ 363 386 token_secret = g_strdup( oauth_params_get( ¶ms, "oauth_token_secret" ) ); 364 387 if( token_secret == NULL ) … … 368 391 oauth_add_default_params( ¶ms ); 369 392 393 /* Start building the OAuth header. 'key="value", '... */ 370 394 ret = g_string_new( "OAuth " ); 371 395 for( l = params; l; l = l->next ) … … 387 411 } 388 412 413 /* Now, before generating the signature, add GET/POST arguments to params 414 since they should be included in the base signature string (but not in 415 the HTTP header). */ 389 416 if( args ) 390 417 oauth_params_parse( ¶ms, args ); … … 396 423 } 397 424 425 /* Append the signature and we're done! */ 398 426 params_s = oauth_params_string( params ); 399 427 sig = oauth_sign( method, url, params_s, token_secret ); -
lib/oauth.h
ree84bdb r18dbb20 25 25 26 26 struct oauth_info; 27 typedef void (*oauth_cb)( struct oauth_info * ); 27 28 /* Callback function called twice during the access token request process. 29 Return FALSE if something broke and the process must be aborted. */ 30 typedef gboolean (*oauth_cb)( struct oauth_info * ); 28 31 29 32 typedef enum … … 53 56 authorization URL for the user. This is passed to the callback function 54 57 in a struct oauth_info. */ 55 void*oauth_request_token( const char *url, oauth_cb func, void *data );58 struct oauth_info *oauth_request_token( const char *url, oauth_cb func, void *data ); 56 59 57 60 /* http://oauth.net/core/1.0a/#auth_step3 (section 6.3) … … 59 62 token. This is passed to the callback function in the same 60 63 struct oauth_info. */ 61 void *oauth_access_token( const char *url, const char *pin, struct oauth_info *st );64 void oauth_access_token( const char *url, const char *pin, struct oauth_info *st ); 62 65 63 66 /* http://oauth.net/core/1.0a/#anchor12 (section 7) … … 67 70 automatically be grabbed from url. */ 68 71 char *oauth_http_header( char *access_token, const char *method, const char *url, char *args ); 72 73 /* Shouldn't normally be required unless the process is aborted by the user. */ 74 void oauth_info_free( struct oauth_info *info );
Note: See TracChangeset
for help on using the changeset viewer.