Changeset 713d611 for protocols/twitter


Ignore:
Timestamp:
2010-04-26T21:50:48Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
c42e8b9
Parents:
acba168
Message:

Twitter module now generates authorize URLs.

Location:
protocols/twitter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    racba168 r713d611  
    2323
    2424#include "nogaim.h"
     25#include "oauth.h"
    2526#include "twitter.h"
    2627#include "twitter_http.h"
     
    4950        // If we are still logged in run this function again after timeout.
    5051        return (ic->flags & OPT_LOGGED_IN) == OPT_LOGGED_IN;
     52}
     53
     54static void twitter_main_loop_start( struct im_connection *ic )
     55{
     56        struct twitter_data *td = ic->proto_data;
     57       
     58        imcb_log( ic, "Connecting to Twitter" );
     59
     60        // Run this once. After this queue the main loop function.
     61        twitter_main_loop(ic, -1, 0);
     62
     63        // Queue the main_loop
     64        // Save the return value, so we can remove the timeout on logout.
     65        td->main_loop_id = b_timeout_add(60000, twitter_main_loop, ic);
     66}
     67
     68static void twitter_oauth_callback( struct oauth_info *info );
     69
     70static void twitter_oauth_start( struct im_connection *ic )
     71{
     72        oauth_request_token( TWITTER_OAUTH_REQUEST_TOKEN, twitter_oauth_callback, ic );
     73}
     74
     75static void twitter_oauth_callback( struct oauth_info *info )
     76{
     77        struct im_connection *ic = info->data;
     78       
     79        if( info->request_token && info->access_token == NULL )
     80        {
     81                char name[strlen(ic->acc->user)+9], *msg;
     82               
     83                sprintf( name, "twitter_%s", ic->acc->user );
     84                msg = g_strdup_printf( "To finish OAuth authentication, please visit "
     85                                       "%s?%s and respond with the resulting PIN code.",
     86                                       TWITTER_OAUTH_AUTHORIZE, info->auth_params );
     87                imcb_buddy_msg( ic, name, msg, 0, 0 );
     88                g_free( msg );
     89        }
    5190}
    5291
     
    67106        s = set_add( &acc->set, "mode", "one", set_eval_mode, acc );
    68107        s->flags |= ACC_SET_OFFLINE_ONLY;
     108       
     109        s = set_add( &acc->set, "oauth", "true", set_eval_bool, acc );
    69110}
    70111
     
    80121
    81122        twitter_connections = g_slist_append( twitter_connections, ic );
    82 
     123        ic->proto_data = td;
     124       
    83125        td->user = acc->user;
    84         if( strstr( acc->pass, "oauth_token=" ) == NULL )
     126        if( !set_getbool( &acc->set, "oauth" ) )
    85127                td->pass = g_strdup( acc->pass );
    86         else
     128        else if( strstr( acc->pass, "oauth_token=" ) )
    87129                td->oauth = g_strdup( acc->pass );
    88130        td->home_timeline_id = 0;
    89 
    90         ic->proto_data = td;
    91 
    92         imcb_log( ic, "Connecting to Twitter" );
    93 
    94         // Run this once. After this queue the main loop function.
    95         twitter_main_loop(ic, -1, 0);
    96 
    97         // Queue the main_loop
    98         // Save the return value, so we can remove the timeout on logout.
    99         td->main_loop_id = b_timeout_add(60000, twitter_main_loop, ic);
    100131       
    101132        sprintf( name, "twitter_%s", acc->user );
    102133        imcb_add_buddy( ic, name, NULL );
    103134        imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL );
     135       
     136        if( td->pass || td->oauth )
     137                twitter_main_loop_start( ic );
     138        else
     139                twitter_oauth_start( ic );
    104140}
    105141
  • protocols/twitter/twitter.h

    racba168 r713d611  
    5151GSList *twitter_connections;
    5252
     53#define TWITTER_OAUTH_REQUEST_TOKEN "http://api.twitter.com/oauth/request_token"
     54#define TWITTER_OAUTH_ACCESS_TOKEN  "http://api.twitter.com/oauth/access_token"
     55#define TWITTER_OAUTH_AUTHORIZE     "http://api.twitter.com/oauth/authorize"
     56
    5357#endif //_TWITTER_H
Note: See TracChangeset for help on using the changeset viewer.