Changeset 18dbb20 for lib


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

Valgrind cleanup.

Location:
lib
Files:
2 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 );
Note: See TracChangeset for help on using the changeset viewer.