Changeset 23784065 for protocols/twitter/twitter.c
- Timestamp:
- 2010-04-28T07:44:45Z (14 years ago)
- Branches:
- master
- Children:
- a7c6d0e
- Parents:
- f1b7711 (diff), 3f668e47 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
rf1b7711 r23784065 23 23 24 24 #include "nogaim.h" 25 #include "oauth.h" 25 26 #include "twitter.h" 26 27 #include "twitter_http.h" … … 49 50 // If we are still logged in run this function again after timeout. 50 51 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_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 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 should 119 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; 51 127 } 52 128 … … 67 143 s = set_add( &acc->set, "mode", "one", set_eval_mode, acc ); 68 144 s->flags |= ACC_SET_OFFLINE_ONLY; 145 146 s = set_add( &acc->set, "oauth", "true", set_eval_bool, acc ); 69 147 } 70 148 … … 80 158 81 159 twitter_connections = g_slist_append( twitter_connections, ic ); 82 160 ic->proto_data = td; 161 83 162 td->user = acc->user; 84 td->pass = acc->pass; 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 ); 85 167 td->home_timeline_id = 0; 86 87 ic->proto_data = td;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_loop95 // 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);97 168 98 169 sprintf( name, "twitter_%s", acc->user ); 99 170 imcb_add_buddy( ic, name, NULL ); 100 171 imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL ); 172 173 if( td->pass || td->oauth ) 174 twitter_main_loop_start( ic ); 175 else 176 twitter_oauth_start( ic ); 101 177 } 102 178 … … 119 195 if( td ) 120 196 { 197 oauth_info_free( td->oauth_info ); 198 199 g_free( td->pass ); 200 g_free( td->oauth ); 121 201 g_free( td ); 122 202 } … … 130 210 static int twitter_buddy_msg( struct im_connection *ic, char *who, char *message, int away ) 131 211 { 212 struct twitter_data *td = ic->proto_data; 213 132 214 if (g_strncasecmp(who, "twitter_", 8) == 0 && 133 215 g_strcasecmp(who + 8, ic->acc->user) == 0) 134 twitter_post_status(ic, message); 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 } 135 225 else 226 { 136 227 twitter_direct_messages_new(ic, who, message); 137 228 } 138 229 return( 0 ); 139 230 }
Note: See TracChangeset
for help on using the changeset viewer.