Changeset 18dbb20


Ignore:
Timestamp:
2010-04-27T22:42:07Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
0bff877
Parents:
ee84bdb
Message:

Valgrind cleanup.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lib/oauth.c

    ree84bdb r18dbb20  
    225225}
    226226
     227void 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
    227238static void oauth_add_default_params( GSList **params )
    228239{
     
    286297static void oauth_request_token_done( struct http_request *req );
    287298
    288 void *oauth_request_token( const char *url, oauth_cb func, void *data )
     299struct oauth_info *oauth_request_token( const char *url, oauth_cb func, void *data )
    289300{
    290301        struct oauth_info *st = g_new0( struct oauth_info, 1 );
     
    296307        oauth_params_add( &params, "oauth_callback", "oob" );
    297308       
    298         return oauth_post_request( url, NULL, oauth_request_token_done, st );
     309        if( !oauth_post_request( url, &params, oauth_request_token_done, st ) )
     310        {
     311                oauth_info_free( st );
     312                return NULL;
     313        }
     314       
     315        return st;
    299316}
    300317
     
    316333       
    317334        st->stage = OAUTH_REQUEST_TOKEN;
    318         st->func( st );
     335        if( !st->func( st ) )
     336                oauth_info_free( st );
    319337}
    320338
    321339static void oauth_access_token_done( struct http_request *req );
    322340
    323 void *oauth_access_token( const char *url, const char *pin, struct oauth_info *st )
     341void oauth_access_token( const char *url, const char *pin, struct oauth_info *st )
    324342{
    325343        GSList *params = NULL;
     
    328346        oauth_params_add( &params, "oauth_verifier", pin );
    329347       
    330         return oauth_post_request( url, &params, oauth_access_token_done, st );
     348        if( !oauth_post_request( url, &params, oauth_access_token_done, st ) )
     349                oauth_info_free( st );
    331350}
    332351
     
    337356        if( req->status_code == 200 )
    338357        {
    339                 GSList *params;
     358                GSList *params = NULL;
    340359                const char *token, *token_secret;
    341360               
     
    350369        st->stage = OAUTH_ACCESS_TOKEN;
    351370        st->func( st );
     371        oauth_info_free( st );
    352372}
    353373
     
    358378        GString *ret = NULL;
    359379       
     380        /* First, get the two pieces of info from the access token that we need. */
    360381        oauth_params_parse( &params, access_token );
    361382        if( params == NULL )
    362383                goto err;
     384       
     385        /* Pick out the token secret, we shouldn't include it but use it for signing. */
    363386        token_secret = g_strdup( oauth_params_get( &params, "oauth_token_secret" ) );
    364387        if( token_secret == NULL )
     
    368391        oauth_add_default_params( &params );
    369392       
     393        /* Start building the OAuth header. 'key="value", '... */
    370394        ret = g_string_new( "OAuth " );
    371395        for( l = params; l; l = l->next )
     
    387411        }
    388412       
     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). */
    389416        if( args )
    390417                oauth_params_parse( &params, args );
     
    396423        }
    397424       
     425        /* Append the signature and we're done! */
    398426        params_s = oauth_params_string( params );
    399427        sig = oauth_sign( method, url, params_s, token_secret );
  • lib/oauth.h

    ree84bdb r18dbb20  
    2525
    2626struct 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. */
     30typedef gboolean (*oauth_cb)( struct oauth_info * );
    2831
    2932typedef enum
     
    5356   authorization URL for the user. This is passed to the callback function
    5457   in a struct oauth_info. */
    55 void *oauth_request_token( const char *url, oauth_cb func, void *data );
     58struct oauth_info *oauth_request_token( const char *url, oauth_cb func, void *data );
    5659
    5760/* http://oauth.net/core/1.0a/#auth_step3 (section 6.3)
     
    5962   token. This is passed to the callback function in the same
    6063   struct oauth_info. */
    61 void *oauth_access_token( const char *url, const char *pin, struct oauth_info *st );
     64void oauth_access_token( const char *url, const char *pin, struct oauth_info *st );
    6265
    6366/* http://oauth.net/core/1.0a/#anchor12 (section 7)
     
    6770   automatically be grabbed from url. */
    6871char *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. */
     74void oauth_info_free( struct oauth_info *info );
  • protocols/twitter/twitter.c

    ree84bdb r18dbb20  
    6666}
    6767
    68 static void twitter_oauth_callback( struct oauth_info *info );
     68static gboolean twitter_oauth_callback( struct oauth_info *info );
    6969
    7070static void twitter_oauth_start( struct im_connection *ic )
    7171{
     72        struct twitter_data *td = ic->proto_data;
     73       
    7274        imcb_log( ic, "Requesting OAuth request token" );
    7375
    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
     80static gboolean twitter_oauth_callback( struct oauth_info *info )
    7881{
    7982        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;
    8289        if( info->stage == OAUTH_REQUEST_TOKEN )
    8390        {
     
    8895                        imcb_error( ic, "OAuth error: %s", info->http->status_string );
    8996                        imc_logout( ic, TRUE );
    90                         return;
     97                        return FALSE;
    9198                }
    92                
    93                 td->oauth_info = info;
    9499               
    95100                sprintf( name, "twitter_%s", ic->acc->user );
     
    106111                        imcb_error( ic, "OAuth error: %s", info->http->status_string );
    107112                        imc_logout( ic, TRUE );
    108                         return;
     113                        return FALSE;
    109114                }
    110115               
     
    118123                twitter_main_loop_start( ic );
    119124        }
     125       
     126        return TRUE;
    120127}
    121128
     
    188195        if( td )
    189196        {
     197                oauth_info_free( td->oauth_info );
     198               
    190199                g_free( td->pass );
    191200                g_free( td->oauth );
     
    206215            g_strcasecmp(who + 8, ic->acc->user) == 0)
    207216        {
    208                 if( set_getbool( &ic->acc->set, "oauth" ) && td->oauth == NULL )
     217                if( set_getbool( &ic->acc->set, "oauth" ) && td->oauth_info )
     218                {
    209219                        oauth_access_token( TWITTER_OAUTH_ACCESS_TOKEN, message, td->oauth_info );
     220                        td->oauth_info = NULL;
     221                }
    210222                else
    211223                        twitter_post_status(ic, message);
Note: See TracChangeset for help on using the changeset viewer.