- Timestamp:
- 2010-04-25T23:21:00Z (15 years ago)
- Branches:
- master
- Children:
- 508c340
- Parents:
- 346dfd9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/oauth.c
r346dfd9 rb2bc25c 50 50 char *auth_params; 51 51 char *token; 52 53 char *access_token; 52 54 }; 53 55 … … 147 149 { 148 150 g_free( l->data ); 149 *params = g_slist_remove( *params, l );151 *params = g_slist_remove( *params, l->data ); 150 152 } 151 153 } … … 223 225 224 226 return g_string_free( str, FALSE ); 227 } 228 229 static void oauth_add_default_params( GSList **params ) 230 { 231 char *s; 232 233 oauth_params_set( params, "oauth_consumer_key", CONSUMER_KEY ); 234 oauth_params_set( params, "oauth_signature_method", "HMAC-SHA1" ); 235 236 s = g_strdup_printf( "%d", (int) time( NULL ) ); 237 oauth_params_set( params, "oauth_timestamp", s ); 238 g_free( s ); 239 240 s = oauth_nonce(); 241 oauth_params_set( params, "oauth_nonce", s ); 242 g_free( s ); 243 244 oauth_params_set( params, "oauth_version", "1.0" ); 225 245 } 226 246 … … 241 261 params = *params_; 242 262 243 oauth_params_set( ¶ms, "oauth_consumer_key", CONSUMER_KEY ); 244 oauth_params_set( ¶ms, "oauth_signature_method", "HMAC-SHA1" ); 245 246 s = g_strdup_printf( "%d", (int) time( NULL ) ); 247 oauth_params_set( ¶ms, "oauth_timestamp", s ); 248 g_free( s ); 249 250 s = oauth_nonce(); 251 oauth_params_set( ¶ms, "oauth_nonce", s ); 252 g_free( s ); 253 254 oauth_params_set( ¶ms, "oauth_version", "1.0" ); 263 oauth_add_default_params( ¶ms ); 255 264 256 265 params_s = oauth_params_string( params ); … … 328 337 static void oauth_access_token_done( struct http_request *req ) 329 338 { 330 } 339 struct oauth_info *st = req->data; 340 341 if( req->status_code == 200 ) 342 st->access_token = g_strdup( req->reply_body ); 343 344 //st->func( st ); 345 } 346 347 char *oauth_http_header( char *access_token, const char *method, const char *url ) 348 { 349 GSList *params, *l; 350 char *token_secret, *sig, *params_s; 351 GString *ret = NULL; 352 353 params = oauth_params_parse( access_token ); 354 if( params == NULL ) 355 goto err; 356 token_secret = g_strdup( oauth_params_get( ¶ms, "oauth_token_secret" ) ); 357 if( token_secret == NULL ) 358 goto err; 359 oauth_params_del( ¶ms, "oauth_token_secret" ); 360 361 oauth_add_default_params( ¶ms ); 362 363 params_s = oauth_params_string( params ); 364 sig = oauth_sign( method, url, params_s, token_secret ); 365 g_free( params_s ); 366 sig = g_realloc( sig, strlen( sig ) * 3 + 1 ); 367 http_encode( sig ); 368 369 ret = g_string_new( "OAuth " ); 370 for( l = params; l; l = l->next ) 371 { 372 char *kv = l->data; 373 char *eq = strchr( kv, '=' ); 374 char esc[strlen(kv)*3+1]; 375 376 if( eq == NULL ) 377 break; /* WTF */ 378 379 strcpy( esc, eq + 1 ); 380 http_encode( esc ); 381 382 g_string_append_len( ret, kv, eq - kv + 1 ); 383 g_string_append_c( ret, '"' ); 384 g_string_append( ret, esc ); 385 g_string_append( ret, "\", " ); 386 } 387 388 g_string_append_printf( ret, "oauth_signature=\"%s\"", sig ); 389 390 err: 391 oauth_params_free( ¶ms ); 392 g_free( sig ); 393 g_free( token_secret ); 394 395 return ret ? g_string_free( ret, FALSE ) : NULL; 396 }
Note: See TracChangeset
for help on using the changeset viewer.