Changes in protocols/twitter/twitter.c [1dd3470:64f8c425]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
r1dd3470 r64f8c425 27 27 #include "twitter_http.h" 28 28 #include "twitter_lib.h" 29 #include "url.h" 29 30 30 31 /** … … 39 40 return 0; 40 41 41 // If the user uses multiple private message windows we need to get the42 // users buddies.43 if (g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "many") == 0)44 twitter_get_statuses_friends(ic, -1);45 46 42 // Do stuff.. 47 43 twitter_get_home_timeline(ic, -1); … … 55 51 struct twitter_data *td = ic->proto_data; 56 52 57 imcb_log( ic, " Connecting to Twitter" );53 imcb_log( ic, "Getting initial statuses" ); 58 54 59 55 // Run this once. After this queue the main loop function. … … 65 61 } 66 62 63 static void twitter_oauth_start( struct im_connection *ic ); 64 65 void twitter_login_finish( struct im_connection *ic ) 66 { 67 struct twitter_data *td = ic->proto_data; 68 69 if( set_getbool( &ic->acc->set, "oauth" ) && !td->oauth_info ) 70 twitter_oauth_start( ic ); 71 else if( g_strcasecmp( set_getstr( &ic->acc->set, "mode" ), "one" ) != 0 && 72 !( td->flags & TWITTER_HAVE_FRIENDS ) ) 73 { 74 imcb_log( ic, "Getting contact list" ); 75 twitter_get_statuses_friends( ic, -1 ); 76 } 77 else 78 twitter_main_loop_start( ic ); 79 } 67 80 68 81 static const struct oauth_service twitter_oauth = … … 70 83 "http://api.twitter.com/oauth/request_token", 71 84 "http://api.twitter.com/oauth/access_token", 72 "http ://api.twitter.com/oauth/authorize",85 "https://api.twitter.com/oauth/authorize", 73 86 .consumer_key = "xsDNKJuNZYkZyMcu914uEA", 74 87 .consumer_secret = "FCxqcr0pXKzsF9ajmP57S3VQ8V6Drk4o2QYtqMcOszo", … … 127 140 ic->acc->pass = oauth_to_string( info ); 128 141 129 twitter_ main_loop_start( ic );142 twitter_login_finish( ic ); 130 143 } 131 144 … … 160 173 set_t *s; 161 174 175 s = set_add( &acc->set, "base_url", TWITTER_API_URL, NULL, acc ); 176 s->flags |= ACC_SET_OFFLINE_ONLY; 177 162 178 s = set_add( &acc->set, "message_length", "140", set_eval_int, acc ); 163 179 … … 175 191 { 176 192 struct im_connection *ic = imcb_new( acc ); 177 struct twitter_data *td = g_new0( struct twitter_data, 1 );193 struct twitter_data *td; 178 194 char name[strlen(acc->user)+9]; 179 195 url_t url; 196 197 if( !url_set( &url, set_getstr( &ic->acc->set, "base_url" ) ) || 198 ( url.proto != PROTO_HTTP && url.proto != PROTO_HTTPS ) ) 199 { 200 imcb_error( ic, "Incorrect API base URL: %s", set_getstr( &ic->acc->set, "base_url" ) ); 201 imc_logout( ic, FALSE ); 202 return; 203 } 204 180 205 twitter_connections = g_slist_append( twitter_connections, ic ); 206 td = g_new0( struct twitter_data, 1 ); 181 207 ic->proto_data = td; 182 ic->flags |= OPT_DOES_HTML; 208 209 td->url_ssl = url.proto == PROTO_HTTPS; 210 td->url_port = url.port; 211 td->url_host = g_strdup( url.host ); 212 if( strcmp( url.file, "/" ) != 0 ) 213 td->url_path = g_strdup( url.file ); 214 else 215 td->url_path = g_strdup( "" ); 183 216 184 217 td->user = acc->user; 185 if( !set_getbool( &acc->set, "oauth" ) ) 186 td->pass = g_strdup( acc->pass ); 187 else if( strstr( acc->pass, "oauth_token=" ) ) 218 if( strstr( acc->pass, "oauth_token=" ) ) 188 219 td->oauth_info = oauth_from_string( acc->pass, &twitter_oauth ); 189 td->home_timeline_id = 0;190 220 191 221 sprintf( name, "twitter_%s", acc->user ); … … 193 223 imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL ); 194 224 195 if( td->pass || td->oauth_info ) 196 twitter_main_loop_start( ic ); 197 else 198 twitter_oauth_start( ic ); 225 imcb_log( ic, "Connecting" ); 226 227 twitter_login_finish( ic ); 199 228 } 200 229 … … 218 247 { 219 248 oauth_info_free( td->oauth_info ); 249 g_free( td->url_host ); 250 g_free( td->url_path ); 220 251 g_free( td->pass ); 221 252 g_free( td ); … … 238 269 td->oauth_info && td->oauth_info->token == NULL ) 239 270 { 240 if( !oauth_access_token( message, td->oauth_info ) ) 271 char pin[strlen(message)+1], *s; 272 273 strcpy( pin, message ); 274 for( s = pin + sizeof( pin ) - 2; s > pin && isspace( *s ); s -- ) 275 *s = '\0'; 276 for( s = pin; *s && isspace( *s ); s ++ ) {} 277 278 if( !oauth_access_token( s, td->oauth_info ) ) 241 279 { 242 280 imcb_error( ic, "OAuth error: %s", "Failed to send access token request" ); … … 268 306 static void twitter_add_buddy( struct im_connection *ic, char *who, char *group ) 269 307 { 308 twitter_friendships_create_destroy(ic, who, 1); 270 309 } 271 310 272 311 static void twitter_remove_buddy( struct im_connection *ic, char *who, char *group ) 273 312 { 313 twitter_friendships_create_destroy(ic, who, 0); 274 314 } 275 315 … … 336 376 struct prpl *ret = g_new0(struct prpl, 1); 337 377 338 ret->options = OPT_NOOTR;339 378 ret->name = "twitter"; 340 379 ret->login = twitter_login;
Note: See TracChangeset
for help on using the changeset viewer.