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!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.