diff options
-rw-r--r-- | lib/oauth.c | 27 | ||||
-rw-r--r-- | lib/oauth.h | 4 | ||||
-rw-r--r-- | protocols/twitter/twitter.c | 8 |
3 files changed, 35 insertions, 4 deletions
diff --git a/lib/oauth.c b/lib/oauth.c index 4c93cbf4..8012c37a 100644 --- a/lib/oauth.c +++ b/lib/oauth.c @@ -424,3 +424,30 @@ char *oauth_http_header( struct oauth_info *oi, const char *method, const char * return ret ? g_string_free( ret, FALSE ) : NULL; } + +char *oauth_to_string( struct oauth_info *oi ) +{ + GSList *params = NULL; + char *ret; + + oauth_params_add( ¶ms, "oauth_token", oi->token ); + oauth_params_add( ¶ms, "oauth_token_secret", oi->token_secret ); + ret = oauth_params_string( params ); + oauth_params_free( ¶ms ); + + return ret; +} + +struct oauth_info *oauth_from_string( char *in, struct oauth_service *sp ) +{ + struct oauth_info *oi = g_new0( struct oauth_info, 1 ); + GSList *params = NULL; + + oauth_params_parse( ¶ms, in ); + oi->token = g_strdup( oauth_params_get( ¶ms, "oauth_token" ) ); + oi->token_secret = g_strdup( oauth_params_get( ¶ms, "oauth_token_secret" ) ); + oauth_params_free( ¶ms ); + oi->sp = sp; + + return oi; +} diff --git a/lib/oauth.h b/lib/oauth.h index 849375be..6b51dc2c 100644 --- a/lib/oauth.h +++ b/lib/oauth.h @@ -84,3 +84,7 @@ char *oauth_http_header( struct oauth_info *oi, const char *method, const char * /* Shouldn't normally be required unless the process is aborted by the user. */ void oauth_info_free( struct oauth_info *info ); + +/* Convert to and back from strings, for easier saving. */ +char *oauth_to_string( struct oauth_info *oi ); +struct oauth_info *oauth_from_string( char *in, struct oauth_service *sp ); diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 6d43d819..589f2088 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -123,8 +123,8 @@ static gboolean twitter_oauth_callback( struct oauth_info *info ) /* IM mods didn't do this so far and it's ugly but I should be able to get away with it... */ - //g_free( ic->acc->pass ); - //ic->acc->pass = g_strdup( info->access_token ); + g_free( ic->acc->pass ); + ic->acc->pass = oauth_to_string( info ); twitter_main_loop_start( ic ); } @@ -170,8 +170,8 @@ static void twitter_login( account_t *acc ) td->user = acc->user; if( !set_getbool( &acc->set, "oauth" ) ) td->pass = g_strdup( acc->pass ); - //else if( strstr( acc->pass, "oauth_token=" ) ) - // td->oauth = g_strdup( acc->pass ); + else if( strstr( acc->pass, "oauth_token=" ) ) + td->oauth_info = oauth_from_string( acc->pass, &twitter_oauth ); td->home_timeline_id = 0; sprintf( name, "twitter_%s", acc->user ); |