Changeset 508c340
- Timestamp:
- 2010-04-26T00:42:37Z (15 years ago)
- Branches:
- master
- Children:
- acba168
- Parents:
- b2bc25c
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/oauth.c
rb2bc25c r508c340 175 175 } 176 176 177 GSList *oauth_params_parse( char *in ) 178 { 179 GSList *ret = NULL; 177 static void oauth_params_parse( GSList **params, char *in ) 178 { 180 179 char *amp, *eq; 181 180 … … 190 189 *amp = '\0'; 191 190 192 oauth_params_add( &ret, in, eq + 1 );191 oauth_params_add( params, in, eq + 1 ); 193 192 194 193 *eq = '='; … … 199 198 in = amp + 1; 200 199 } 201 202 return ret;203 200 } 204 201 … … 312 309 if( req->status_code == 200 ) 313 310 { 314 GSList *params ;311 GSList *params = NULL; 315 312 316 313 st->auth_params = g_strdup( req->reply_body ); 317 params = oauth_params_parse(st->auth_params );314 oauth_params_parse( ¶ms, st->auth_params ); 318 315 st->token = g_strdup( oauth_params_get( ¶ms, "oauth_token" ) ); 319 316 oauth_params_free( ¶ms ); … … 345 342 } 346 343 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 ;344 char *oauth_http_header( char *access_token, const char *method, const char *url, char *args ) 345 { 346 GSList *params = NULL, *l; 347 char *token_secret, *sig, *params_s, *s; 351 348 GString *ret = NULL; 352 349 353 params = oauth_params_parse(access_token );350 oauth_params_parse( ¶ms, access_token ); 354 351 if( params == NULL ) 355 352 goto err; … … 361 358 oauth_add_default_params( ¶ms ); 362 359 360 ret = g_string_new( "OAuth " ); 361 for( l = params; l; l = l->next ) 362 { 363 char *kv = l->data; 364 char *eq = strchr( kv, '=' ); 365 char esc[strlen(kv)*3+1]; 366 367 if( eq == NULL ) 368 break; /* WTF */ 369 370 strcpy( esc, eq + 1 ); 371 http_encode( esc ); 372 373 g_string_append_len( ret, kv, eq - kv + 1 ); 374 g_string_append_c( ret, '"' ); 375 g_string_append( ret, esc ); 376 g_string_append( ret, "\", " ); 377 } 378 379 if( args ) 380 oauth_params_parse( ¶ms, args ); 381 if( ( s = strchr( url, '?' ) ) ) 382 { 383 s = g_strdup( s + 1 ); 384 oauth_params_parse( ¶ms, s + 1 ); 385 g_free( s ); 386 } 387 363 388 params_s = oauth_params_string( params ); 364 389 sig = oauth_sign( method, url, params_s, token_secret ); … … 367 392 http_encode( sig ); 368 393 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 394 g_string_append_printf( ret, "oauth_signature=\"%s\"", sig ); 389 395 -
lib/oauth.h
rb2bc25c r508c340 21 21 * * 22 22 \***************************************************************************/ 23 24 char *oauth_http_header( char *access_token, const char *method, const char *url, char *args ); -
protocols/twitter/twitter.c
rb2bc25c r508c340 82 82 83 83 td->user = acc->user; 84 td->pass = acc->pass; 84 if( strstr( acc->pass, "oauth_token=" ) == NULL ) 85 td->pass = g_strdup( acc->pass ); 86 else 87 td->oauth = g_strdup( acc->pass ); 85 88 td->home_timeline_id = 0; 86 89 … … 119 122 if( td ) 120 123 { 124 g_free( td->pass ); 125 g_free( td->oauth ); 121 126 g_free( td ); 122 127 } -
protocols/twitter/twitter.h
rb2bc25c r508c340 37 37 char* user; 38 38 char* pass; 39 char* oauth; 39 40 guint64 home_timeline_id; 40 41 gint main_loop_id; -
protocols/twitter/twitter_http.c
rb2bc25c r508c340 35 35 #include "misc.h" 36 36 #include "base64.h" 37 #include "oauth.h" 37 38 #include <ctype.h> 38 39 #include <errno.h> … … 45 46 * This is actually pretty generic function... Perhaps it should move to the lib/http_client.c 46 47 */ 47 void *twitter_http(char *url_string, http_input_function func, gpointer data, int is_post, char* user, char* pass, char* * arguments, int arguments_len)48 void *twitter_http(char *url_string, http_input_function func, gpointer data, int is_post, char* user, char* pass, char* oauth_token, char** arguments, int arguments_len) 48 49 { 49 50 url_t *url = g_new0( url_t, 1 ); … … 110 111 111 112 // If a pass and user are given we append them to the request. 112 if (userpass_base64) 113 if (oauth_token) 114 { 115 char *full_header; 116 117 full_header = oauth_http_header(oauth_token, 118 is_post ? "POST" : "GET", 119 url_string, url_arguments); 120 121 tmp = g_strdup_printf("%sAuthorization: %s\r\n", request, full_header); 122 g_free(request); 123 g_free(full_header); 124 request = tmp; 125 } 126 else if (userpass_base64) 113 127 { 114 128 tmp = g_strdup_printf("%sAuthorization: Basic %s\r\n", request, userpass_base64); -
protocols/twitter/twitter_http.h
rb2bc25c r508c340 29 29 30 30 void *twitter_http(char *url_string, http_input_function func, gpointer data, int is_post, 31 char* user, char* pass, char** arguments, int arguments_len);31 char* user, char* pass, char *oauth_token, char** arguments, int arguments_len); 32 32 33 33 #endif //_TWITTER_HTTP_H -
protocols/twitter/twitter_lib.c
rb2bc25c r508c340 130 130 args[0] = "cursor"; 131 131 args[1] = g_strdup_printf ("%d", next_cursor); 132 twitter_http(TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, td->user, td->pass, args, 2);132 twitter_http(TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, td->user, td->pass, td->oauth, args, 2); 133 133 134 134 g_free(args[1]); … … 396 396 } 397 397 398 twitter_http(TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, td->user, td->pass, args, td->home_timeline_id ? 4 : 2);398 twitter_http(TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, td->user, td->pass, td->oauth, args, td->home_timeline_id ? 4 : 2); 399 399 400 400 g_free(args[1]); … … 620 620 args[1] = g_strdup_printf ("%d", next_cursor); 621 621 622 twitter_http(TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, td->user, td->pass, args, 2);622 twitter_http(TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, td->user, td->pass, td->oauth, args, 2); 623 623 624 624 g_free(args[1]); … … 654 654 args[0] = "status"; 655 655 args[1] = msg; 656 twitter_http(TWITTER_STATUS_UPDATE_URL, twitter_http_post_status, ic, 1, td->user, td->pass, args, 2);656 twitter_http(TWITTER_STATUS_UPDATE_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth, args, 2); 657 657 // g_free(args[1]); 658 658 } … … 672 672 args[3] = msg; 673 673 // Use the same callback as for twitter_post_status, since it does basically the same. 674 twitter_http(TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post_status, ic, 1, td->user, td->pass, args, 4);674 twitter_http(TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth, args, 4); 675 675 // g_free(args[1]); 676 676 // g_free(args[3]);
Note: See TracChangeset
for help on using the changeset viewer.