Changeset eb6df6a for protocols/twitter
- Timestamp:
- 2010-07-11T17:21:21Z (15 years ago)
- Branches:
- master
- Children:
- be999a5
- Parents:
- 3759849 (diff), 00540d4 (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. - Location:
- protocols/twitter
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
r3759849 reb6df6a 40 40 return 0; 41 41 42 // If the user uses multiple private message windows we need to get the43 // users buddies.44 if (g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "many") == 0)45 twitter_get_statuses_friends(ic, -1);46 47 42 // Do stuff.. 48 43 twitter_get_home_timeline(ic, -1); … … 56 51 struct twitter_data *td = ic->proto_data; 57 52 58 imcb_log( ic, " Connecting to Twitter" );53 imcb_log( ic, "Getting initial statuses" ); 59 54 60 55 // Run this once. After this queue the main loop function. … … 66 61 } 67 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 } 68 80 69 81 static const struct oauth_service twitter_oauth = … … 128 140 ic->acc->pass = oauth_to_string( info ); 129 141 130 twitter_ main_loop_start( ic );142 twitter_login_finish( ic ); 131 143 } 132 144 … … 211 223 imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL ); 212 224 213 if( td->oauth_info || !set_getbool( &acc->set, "oauth" ) ) 214 twitter_main_loop_start( ic ); 215 else 216 twitter_oauth_start( ic ); 225 imcb_log( ic, "Connecting" ); 226 227 twitter_login_finish( ic ); 217 228 } 218 229 … … 236 247 { 237 248 oauth_info_free( td->oauth_info ); 249 g_free( td->url_host ); 250 g_free( td->url_path ); 238 251 g_free( td->pass ); 239 252 g_free( td ); … … 256 269 td->oauth_info && td->oauth_info->token == NULL ) 257 270 { 258 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 ) ) 259 279 { 260 280 imcb_error( ic, "OAuth error: %s", "Failed to send access token request" ); -
protocols/twitter/twitter.h
r3759849 reb6df6a 33 33 #endif 34 34 35 typedef enum 36 { 37 TWITTER_HAVE_FRIENDS = 1, 38 } twitter_flags_t; 39 35 40 struct twitter_data 36 41 { … … 42 47 struct groupchat *home_timeline_gc; 43 48 gint http_fails; 49 twitter_flags_t flags; 44 50 45 51 gboolean url_ssl; … … 56 62 GSList *twitter_connections; 57 63 64 void twitter_login_finish( struct im_connection *ic ); 65 58 66 #endif //_TWITTER_H -
protocols/twitter/twitter_lib.c
r3759849 reb6df6a 42 42 struct twitter_xml_list { 43 43 int type; 44 intnext_cursor;44 gint64 next_cursor; 45 45 GSList *list; 46 46 gpointer data; … … 58 58 guint64 id; 59 59 }; 60 61 static void twitter_groupchat_init(struct im_connection *ic); 60 62 61 63 /** … … 153 155 * Get the friends ids. 154 156 */ 155 void twitter_get_friends_ids(struct im_connection *ic, intnext_cursor)157 void twitter_get_friends_ids(struct im_connection *ic, gint64 next_cursor) 156 158 { 157 159 // Primitive, but hey! It works... 158 160 char* args[2]; 159 161 args[0] = "cursor"; 160 args[1] = g_strdup_printf ("% d",next_cursor);162 args[1] = g_strdup_printf ("%lld", (long long) next_cursor); 161 163 twitter_http(ic, TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, args, 2); 162 164 … … 169 171 static xt_status twitter_xt_next_cursor( struct xt_node *node, struct twitter_xml_list *txl ) 170 172 { 171 // Do something with the cursor. 172 txl->next_cursor = node->text != NULL ? atoi(node->text) : -1; 173 char *end = NULL; 174 175 if( node->text ) 176 txl->next_cursor = g_ascii_strtoll( node->text, &end, 10 ); 177 if( end == NULL ) 178 txl->next_cursor = -1; 173 179 174 180 return XT_HANDLED; … … 413 419 * Get the timeline. 414 420 */ 415 void twitter_get_home_timeline(struct im_connection *ic, intnext_cursor)421 void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor) 416 422 { 417 423 struct twitter_data *td = ic->proto_data; … … 419 425 char* args[4]; 420 426 args[0] = "cursor"; 421 args[1] = g_strdup_printf ("% d",next_cursor);427 args[1] = g_strdup_printf ("%lld", (long long) next_cursor); 422 428 if (td->home_timeline_id) { 423 429 args[2] = "since_id"; … … 431 437 g_free(args[3]); 432 438 } 439 } 440 441 static void twitter_groupchat_init(struct im_connection *ic) 442 { 443 char *name_hint; 444 struct groupchat *gc; 445 struct twitter_data *td = ic->proto_data; 446 447 td->home_timeline_gc = gc = imcb_chat_new( ic, "home/timeline" ); 448 449 name_hint = g_strdup_printf( "Twitter_%s", ic->acc->user ); 450 imcb_chat_name_hint( gc, name_hint ); 451 g_free( name_hint ); 433 452 } 434 453 … … 445 464 // Create a new groupchat if it does not exsist. 446 465 if (!td->home_timeline_gc) 447 { 448 char *name_hint = g_strdup_printf( "Twitter_%s", ic->acc->user ); 449 td->home_timeline_gc = gc = imcb_chat_new( ic, "home/timeline" ); 450 imcb_chat_name_hint( gc, name_hint ); 451 g_free( name_hint ); 452 // Add the current user to the chat... 466 twitter_groupchat_init(ic); 467 468 gc = td->home_timeline_gc; 469 if (!gc->joined) 453 470 imcb_chat_add_buddy( gc, ic->acc->user ); 454 }455 else456 {457 gc = td->home_timeline_gc;458 }459 471 460 472 for ( l = list; l ; l = g_slist_next(l) ) … … 604 616 605 617 // Check if the HTTP request went well. 606 if (req->status_code != 200) { 618 if (req->status_code == 401) 619 { 620 imcb_error( ic, "Authentication failure" ); 621 imc_logout( ic, FALSE ); 622 return; 623 } else if (req->status_code != 200) { 607 624 // It didn't go well, output the error and return. 608 if (++td->http_fails >= 5) 609 imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req)); 610 625 imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req)); 626 imc_logout( ic, TRUE ); 611 627 return; 612 628 } else { 613 629 td->http_fails = 0; 614 630 } 631 632 if( !td->home_timeline_gc && 633 g_strcasecmp( set_getstr( &ic->acc->set, "mode" ), "chat" ) == 0 ) 634 twitter_groupchat_init( ic ); 615 635 616 636 txl = g_new0(struct twitter_xml_list, 1); … … 634 654 // if the next_cursor is set to something bigger then 0 there are more friends to gather. 635 655 if (txl->next_cursor > 0) 656 { 636 657 twitter_get_statuses_friends(ic, txl->next_cursor); 637 658 } 659 else 660 { 661 td->flags |= TWITTER_HAVE_FRIENDS; 662 twitter_login_finish(ic); 663 } 664 638 665 // Free the structure. 639 666 txl_free(txl); … … 644 671 * Get the friends. 645 672 */ 646 void twitter_get_statuses_friends(struct im_connection *ic, intnext_cursor)673 void twitter_get_statuses_friends(struct im_connection *ic, gint64 next_cursor) 647 674 { 648 675 char* args[2]; 649 676 args[0] = "cursor"; 650 args[1] = g_strdup_printf ("% d",next_cursor);677 args[1] = g_strdup_printf ("%lld", (long long) next_cursor); 651 678 652 679 twitter_http(ic, TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, args, 2); -
protocols/twitter/twitter_lib.h
r3759849 reb6df6a 76 76 #define TWITTER_BLOCKS_DESTROY_URL "/blocks/destroy/" 77 77 78 void twitter_get_friends_ids(struct im_connection *ic, intnext_cursor);79 void twitter_get_home_timeline(struct im_connection *ic, intnext_cursor);80 void twitter_get_statuses_friends(struct im_connection *ic, intnext_cursor);78 void twitter_get_friends_ids(struct im_connection *ic, gint64 next_cursor); 79 void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor); 80 void twitter_get_statuses_friends(struct im_connection *ic, gint64 next_cursor); 81 81 82 82 void twitter_post_status(struct im_connection *ic, char *msg);
Note: See TracChangeset
for help on using the changeset viewer.