Changes in protocols/twitter/twitter.c [18dbb20:db57e7c]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
r18dbb20 rdb57e7c 23 23 24 24 #include "nogaim.h" 25 #include "oauth.h"26 25 #include "twitter.h" 27 26 #include "twitter_http.h" … … 50 49 // If we are still logged in run this function again after timeout. 51 50 return (ic->flags & OPT_LOGGED_IN) == OPT_LOGGED_IN; 52 }53 54 static 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_loop64 // 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 68 static gboolean twitter_oauth_callback( struct oauth_info *info );69 70 static void twitter_oauth_start( struct im_connection *ic )71 {72 struct twitter_data *td = ic->proto_data;73 74 imcb_log( ic, "Requesting OAuth request token" );75 76 td->oauth_info = oauth_request_token(77 TWITTER_OAUTH_REQUEST_TOKEN, twitter_oauth_callback, ic );78 }79 80 static gboolean twitter_oauth_callback( struct oauth_info *info )81 {82 struct im_connection *ic = info->data;83 struct twitter_data *td;84 85 if( !g_slist_find( twitter_connections, ic ) )86 return FALSE;87 88 td = ic->proto_data;89 if( info->stage == OAUTH_REQUEST_TOKEN )90 {91 char name[strlen(ic->acc->user)+9], *msg;92 93 if( info->request_token == NULL )94 {95 imcb_error( ic, "OAuth error: %s", info->http->status_string );96 imc_logout( ic, TRUE );97 return FALSE;98 }99 100 sprintf( name, "twitter_%s", ic->acc->user );101 msg = g_strdup_printf( "To finish OAuth authentication, please visit "102 "%s?%s and respond with the resulting PIN code.",103 TWITTER_OAUTH_AUTHORIZE, info->auth_params );104 imcb_buddy_msg( ic, name, msg, 0, 0 );105 g_free( msg );106 }107 else if( info->stage == OAUTH_ACCESS_TOKEN )108 {109 if( info->access_token == NULL )110 {111 imcb_error( ic, "OAuth error: %s", info->http->status_string );112 imc_logout( ic, TRUE );113 return FALSE;114 }115 116 td->oauth = g_strdup( info->access_token );117 118 /* IM mods didn't do this so far and it's ugly but I should119 be able to get away with it... */120 g_free( ic->acc->pass );121 ic->acc->pass = g_strdup( info->access_token );122 123 twitter_main_loop_start( ic );124 }125 126 return TRUE;127 51 } 128 52 … … 143 67 s = set_add( &acc->set, "mode", "one", set_eval_mode, acc ); 144 68 s->flags |= ACC_SET_OFFLINE_ONLY; 145 146 s = set_add( &acc->set, "oauth", "true", set_eval_bool, acc );147 69 } 148 70 … … 158 80 159 81 twitter_connections = g_slist_append( twitter_connections, ic ); 82 83 td->user = acc->user; 84 td->pass = acc->pass; 85 td->home_timeline_id = 0; 86 160 87 ic->proto_data = td; 161 162 td->user = acc->user; 163 if( !set_getbool( &acc->set, "oauth" ) ) 164 td->pass = g_strdup( acc->pass ); 165 else if( strstr( acc->pass, "oauth_token=" ) ) 166 td->oauth = g_strdup( acc->pass ); 167 td->home_timeline_id = 0; 88 89 imcb_log( ic, "Connecting to Twitter" ); 90 91 // Run this once. After this queue the main loop function. 92 twitter_main_loop(ic, -1, 0); 93 94 // Queue the main_loop 95 // Save the return value, so we can remove the timeout on logout. 96 td->main_loop_id = b_timeout_add(60000, twitter_main_loop, ic); 168 97 169 98 sprintf( name, "twitter_%s", acc->user ); 170 99 imcb_add_buddy( ic, name, NULL ); 171 100 imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL ); 172 173 if( td->pass || td->oauth )174 twitter_main_loop_start( ic );175 else176 twitter_oauth_start( ic );177 101 } 178 102 … … 195 119 if( td ) 196 120 { 197 oauth_info_free( td->oauth_info );198 199 g_free( td->pass );200 g_free( td->oauth );201 121 g_free( td ); 202 122 } … … 210 130 static int twitter_buddy_msg( struct im_connection *ic, char *who, char *message, int away ) 211 131 { 212 struct twitter_data *td = ic->proto_data;213 214 132 if (g_strncasecmp(who, "twitter_", 8) == 0 && 215 133 g_strcasecmp(who + 8, ic->acc->user) == 0) 216 { 217 if( set_getbool( &ic->acc->set, "oauth" ) && td->oauth_info ) 218 { 219 oauth_access_token( TWITTER_OAUTH_ACCESS_TOKEN, message, td->oauth_info ); 220 td->oauth_info = NULL; 221 } 222 else 223 twitter_post_status(ic, message); 224 } 134 twitter_post_status(ic, message); 225 135 else 226 {227 136 twitter_direct_messages_new(ic, who, message); 228 }137 229 138 return( 0 ); 230 139 }
Note: See TracChangeset
for help on using the changeset viewer.