Changeset c42e8b9


Ignore:
Timestamp:
2010-04-26T22:40:11Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
78a2f1e
Parents:
713d611
Message:

OAuth, it lives!

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • lib/oauth.c

    r713d611 rc42e8b9  
    302302        }
    303303       
     304        st->stage = OAUTH_REQUEST_TOKEN;
    304305        st->func( st );
    305306}
     
    322323       
    323324        if( req->status_code == 200 )
    324                 st->access_token = g_strdup( req->reply_body );
    325        
     325        {
     326                GSList *params;
     327                const char *token, *token_secret;
     328               
     329                oauth_params_parse( &params, req->reply_body );
     330                token = oauth_params_get( &params, "oauth_token" );
     331                token_secret = oauth_params_get( &params, "oauth_token_secret" );
     332                st->access_token = g_strdup_printf(
     333                        "oauth_token=%s&oauth_token_secret=%s", token, token_secret );
     334                oauth_params_free( &params );
     335        }
     336       
     337        st->stage = OAUTH_ACCESS_TOKEN;
    326338        st->func( st );
    327339}
  • lib/oauth.h

    r713d611 rc42e8b9  
    2727typedef void (*oauth_cb)( struct oauth_info * );
    2828
     29typedef enum
     30{
     31        OAUTH_INIT,
     32        OAUTH_REQUEST_TOKEN,
     33        OAUTH_ACCESS_TOKEN,
     34} oauth_stage_t;
     35
    2936struct oauth_info
    3037{
     38        oauth_stage_t stage;
     39       
    3140        oauth_cb func;
    3241        void *data;
  • protocols/twitter/twitter.c

    r713d611 rc42e8b9  
    7070static void twitter_oauth_start( struct im_connection *ic )
    7171{
     72        imcb_log( ic, "Requesting OAuth request token" );
     73
    7274        oauth_request_token( TWITTER_OAUTH_REQUEST_TOKEN, twitter_oauth_callback, ic );
    7375}
     
    7678{
    7779        struct im_connection *ic = info->data;
    78        
    79         if( info->request_token && info->access_token == NULL )
     80        struct twitter_data *td = ic->proto_data;
     81       
     82        if( info->stage == OAUTH_REQUEST_TOKEN )
    8083        {
    8184                char name[strlen(ic->acc->user)+9], *msg;
     85               
     86                if( info->request_token == NULL )
     87                {
     88                        imcb_error( ic, "OAuth error: %s", info->http->status_string );
     89                        imc_logout( ic, TRUE );
     90                        return;
     91                }
     92               
     93                td->oauth_info = info;
    8294               
    8395                sprintf( name, "twitter_%s", ic->acc->user );
     
    88100                g_free( msg );
    89101        }
     102        else if( info->stage == OAUTH_ACCESS_TOKEN )
     103        {
     104                if( info->access_token == NULL )
     105                {
     106                        imcb_error( ic, "OAuth error: %s", info->http->status_string );
     107                        imc_logout( ic, TRUE );
     108                        return;
     109                }
     110               
     111                td->oauth = g_strdup( info->access_token );
     112               
     113                twitter_main_loop_start( ic );
     114        }
    90115}
    91116
     
    171196static int twitter_buddy_msg( struct im_connection *ic, char *who, char *message, int away )
    172197{
     198        struct twitter_data *td = ic->proto_data;
     199       
    173200        if (g_strncasecmp(who, "twitter_", 8) == 0 &&
    174201            g_strcasecmp(who + 8, ic->acc->user) == 0)
    175                 twitter_post_status(ic, message);
     202        {
     203                if( set_getbool( &ic->acc->set, "oauth" ) && td->oauth == NULL )
     204                        oauth_access_token( TWITTER_OAUTH_ACCESS_TOKEN, message, td->oauth_info );
     205                else
     206                        twitter_post_status(ic, message);
     207        }
    176208        else
     209        {
    177210                twitter_direct_messages_new(ic, who, message);
    178        
     211        }
    179212        return( 0 );
    180213}
  • protocols/twitter/twitter.h

    r713d611 rc42e8b9  
    3838        char* pass;
    3939        char* oauth;
     40        struct oauth_info *oauth_info;
    4041        guint64 home_timeline_id;
    4142        gint main_loop_id;
Note: See TracChangeset for help on using the changeset viewer.