Changeset 1fdb0a4 for protocols/twitter/twitter_lib.c
- Timestamp:
- 2010-06-05T23:26:07Z (14 years ago)
- Branches:
- master
- Children:
- 4aa0f6b, bc49ec2
- Parents:
- b308cf9 (diff), 3dc6d86 (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_lib.c
rb308cf9 r1fdb0a4 117 117 } 118 118 119 /* Warning: May return a malloc()ed value, which will be free()d on the next 120 call. Only for short-term use. */ 121 static char *twitter_parse_error(struct http_request *req) 122 { 123 static char *ret = NULL; 124 struct xt_parser *xp = NULL; 125 struct xt_node *node; 126 127 g_free(ret); 128 ret = NULL; 129 130 if (req->body_size > 0) 131 { 132 xp = xt_new(NULL, NULL); 133 xt_feed(xp, req->reply_body, req->body_size); 134 135 if ((node = xt_find_node(xp->root, "hash")) && 136 (node = xt_find_node(node->children, "error")) && 137 node->text_len > 0) 138 { 139 ret = g_strdup_printf("%s (%s)", req->status_string, node->text); 140 xt_free(xp); 141 return ret; 142 } 143 144 xt_free(xp); 145 } 146 147 return req->status_string; 148 } 149 119 150 static void twitter_http_get_friends_ids(struct http_request *req); 120 151 … … 124 155 void twitter_get_friends_ids(struct im_connection *ic, int next_cursor) 125 156 { 126 struct twitter_data *td = ic->proto_data;127 128 157 // Primitive, but hey! It works... 129 158 char* args[2]; 130 159 args[0] = "cursor"; 131 160 args[1] = g_strdup_printf ("%d", next_cursor); 132 twitter_http( TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, td->user, td->pass, td->oauth_info, args, 2);161 twitter_http(ic, TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, args, 2); 133 162 134 163 g_free(args[1]); … … 196 225 // It didn't go well, output the error and return. 197 226 if (++td->http_fails >= 5) 198 imcb_error(ic, "Could not retrieve friends . HTTP STATUS: %d", req->status_code);227 imcb_error(ic, "Could not retrieve friends: %s", twitter_parse_error(req)); 199 228 200 229 return; … … 396 425 } 397 426 398 twitter_http( TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, td->user, td->pass, td->oauth_info, args, td->home_timeline_id ? 4 : 2);427 twitter_http(ic, TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, args, td->home_timeline_id ? 4 : 2); 399 428 400 429 g_free(args[1]); … … 434 463 twitter_add_buddy(ic, status->user->screen_name, status->user->name); 435 464 465 strip_html(status->text); 466 436 467 // Say it! 437 468 if (g_strcasecmp(td->user, status->user->screen_name) == 0) … … 471 502 status = l->data; 472 503 504 strip_html( status->text ); 473 505 if( mode_one ) 474 506 text = g_strdup_printf( "\002<\002%s\002>\002 %s", … … 523 555 // It didn't go well, output the error and return. 524 556 if (++td->http_fails >= 5) 525 imcb_error(ic, "Could not retrieve " TWITTER_HOME_TIMELINE_URL " . HTTP STATUS: %d", req->status_code);557 imcb_error(ic, "Could not retrieve " TWITTER_HOME_TIMELINE_URL ": %s", twitter_parse_error(req)); 526 558 527 559 return; … … 575 607 // It didn't go well, output the error and return. 576 608 if (++td->http_fails >= 5) 577 imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL " HTTP STATUS: %d", req->status_code);609 imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req)); 578 610 579 611 return; … … 614 646 void twitter_get_statuses_friends(struct im_connection *ic, int next_cursor) 615 647 { 616 struct twitter_data *td = ic->proto_data;617 618 648 char* args[2]; 619 649 args[0] = "cursor"; 620 650 args[1] = g_strdup_printf ("%d", next_cursor); 621 651 622 twitter_http( TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, td->user, td->pass, td->oauth_info, args, 2);652 twitter_http(ic, TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, args, 2); 623 653 624 654 g_free(args[1]); … … 626 656 627 657 /** 628 * Callback after sending a new updateto twitter.629 */ 630 static void twitter_http_post _status(struct http_request *req)658 * Callback to use after sending a post request to twitter. 659 */ 660 static void twitter_http_post(struct http_request *req) 631 661 { 632 662 struct im_connection *ic = req->data; … … 639 669 if (req->status_code != 200) { 640 670 // It didn't go well, output the error and return. 641 imcb_error(ic, " Could not post message... HTTP STATUS: %d", req->status_code);671 imcb_error(ic, "HTTP error: %s", twitter_parse_error(req)); 642 672 return; 643 673 } … … 649 679 void twitter_post_status(struct im_connection *ic, char* msg) 650 680 { 651 struct twitter_data *td = ic->proto_data;652 653 681 char* args[2]; 654 682 args[0] = "status"; 655 683 args[1] = msg; 656 twitter_http( TWITTER_STATUS_UPDATE_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth_info, args, 2);684 twitter_http(ic, TWITTER_STATUS_UPDATE_URL, twitter_http_post, ic, 1, args, 2); 657 685 // g_free(args[1]); 658 686 } … … 664 692 void twitter_direct_messages_new(struct im_connection *ic, char *who, char *msg) 665 693 { 666 struct twitter_data *td = ic->proto_data;667 668 694 char* args[4]; 669 695 args[0] = "screen_name"; … … 672 698 args[3] = msg; 673 699 // Use the same callback as for twitter_post_status, since it does basically the same. 674 twitter_http( TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth_info, args, 4);700 twitter_http(ic, TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post, ic, 1, args, 4); 675 701 // g_free(args[1]); 676 702 // g_free(args[3]); 677 703 } 704 705 void twitter_friendships_create_destroy(struct im_connection *ic, char *who, int create) 706 { 707 char* args[2]; 708 args[0] = "screen_name"; 709 args[1] = who; 710 twitter_http(ic, create ? TWITTER_FRIENDSHIPS_CREATE_URL : TWITTER_FRIENDSHIPS_DESTROY_URL, twitter_http_post, ic, 1, args, 2); 711 }
Note: See TracChangeset
for help on using the changeset viewer.