Changeset 18dbb20
- Timestamp:
- 2010-04-27T22:42:07Z (15 years ago)
- Branches:
- master
- Children:
- 0bff877
- Parents:
- ee84bdb
- Files:
-
- 3 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 ); -
protocols/twitter/twitter.c
ree84bdb r18dbb20 66 66 } 67 67 68 static voidtwitter_oauth_callback( struct oauth_info *info );68 static gboolean twitter_oauth_callback( struct oauth_info *info ); 69 69 70 70 static void twitter_oauth_start( struct im_connection *ic ) 71 71 { 72 struct twitter_data *td = ic->proto_data; 73 72 74 imcb_log( ic, "Requesting OAuth request token" ); 73 75 74 oauth_request_token( TWITTER_OAUTH_REQUEST_TOKEN, twitter_oauth_callback, ic ); 75 } 76 77 static void twitter_oauth_callback( struct oauth_info *info ) 76 td->oauth_info = oauth_request_token( 77 TWITTER_OAUTH_REQUEST_TOKEN, twitter_oauth_callback, ic ); 78 } 79 80 static gboolean twitter_oauth_callback( struct oauth_info *info ) 78 81 { 79 82 struct im_connection *ic = info->data; 80 struct twitter_data *td = ic->proto_data; 81 83 struct twitter_data *td; 84 85 if( !g_slist_find( twitter_connections, ic ) ) 86 return FALSE; 87 88 td = ic->proto_data; 82 89 if( info->stage == OAUTH_REQUEST_TOKEN ) 83 90 { … … 88 95 imcb_error( ic, "OAuth error: %s", info->http->status_string ); 89 96 imc_logout( ic, TRUE ); 90 return ;97 return FALSE; 91 98 } 92 93 td->oauth_info = info;94 99 95 100 sprintf( name, "twitter_%s", ic->acc->user ); … … 106 111 imcb_error( ic, "OAuth error: %s", info->http->status_string ); 107 112 imc_logout( ic, TRUE ); 108 return ;113 return FALSE; 109 114 } 110 115 … … 118 123 twitter_main_loop_start( ic ); 119 124 } 125 126 return TRUE; 120 127 } 121 128 … … 188 195 if( td ) 189 196 { 197 oauth_info_free( td->oauth_info ); 198 190 199 g_free( td->pass ); 191 200 g_free( td->oauth ); … … 206 215 g_strcasecmp(who + 8, ic->acc->user) == 0) 207 216 { 208 if( set_getbool( &ic->acc->set, "oauth" ) && td->oauth == NULL ) 217 if( set_getbool( &ic->acc->set, "oauth" ) && td->oauth_info ) 218 { 209 219 oauth_access_token( TWITTER_OAUTH_ACCESS_TOKEN, message, td->oauth_info ); 220 td->oauth_info = NULL; 221 } 210 222 else 211 223 twitter_post_status(ic, message);
Note: See TracChangeset
for help on using the changeset viewer.