Changes in protocols/twitter/twitter_lib.c [3d93aed:7d53efb]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter_lib.c
r3d93aed r7d53efb 117 117 } 118 118 119 /* Warning: May return a malloc()ed value, which will be free()d on the next120 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 150 119 static void twitter_http_get_friends_ids(struct http_request *req); 151 120 … … 155 124 void twitter_get_friends_ids(struct im_connection *ic, int next_cursor) 156 125 { 126 struct twitter_data *td = ic->proto_data; 127 157 128 // Primitive, but hey! It works... 158 129 char* args[2]; 159 130 args[0] = "cursor"; 160 131 args[1] = g_strdup_printf ("%d", next_cursor); 161 twitter_http( ic, TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, args, 2);132 twitter_http(TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, td->user, td->pass, td->oauth_info, args, 2); 162 133 163 134 g_free(args[1]); … … 225 196 // It didn't go well, output the error and return. 226 197 if (++td->http_fails >= 5) 227 imcb_error(ic, "Could not retrieve friends : %s", twitter_parse_error(req));198 imcb_error(ic, "Could not retrieve friends. HTTP STATUS: %d", req->status_code); 228 199 229 200 return; … … 425 396 } 426 397 427 twitter_http( ic, TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, args, td->home_timeline_id ? 4 : 2);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); 428 399 429 400 g_free(args[1]); … … 463 434 twitter_add_buddy(ic, status->user->screen_name, status->user->name); 464 435 465 strip_html(status->text);466 467 436 // Say it! 468 437 if (g_strcasecmp(td->user, status->user->screen_name) == 0) … … 502 471 status = l->data; 503 472 504 strip_html( status->text );505 473 if( mode_one ) 506 474 text = g_strdup_printf( "\002<\002%s\002>\002 %s", … … 555 523 // It didn't go well, output the error and return. 556 524 if (++td->http_fails >= 5) 557 imcb_error(ic, "Could not retrieve " TWITTER_HOME_TIMELINE_URL " : %s", twitter_parse_error(req));525 imcb_error(ic, "Could not retrieve " TWITTER_HOME_TIMELINE_URL ". HTTP STATUS: %d", req->status_code); 558 526 559 527 return; … … 607 575 // It didn't go well, output the error and return. 608 576 if (++td->http_fails >= 5) 609 imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL " : %s", twitter_parse_error(req));577 imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL " HTTP STATUS: %d", req->status_code); 610 578 611 579 return; … … 646 614 void twitter_get_statuses_friends(struct im_connection *ic, int next_cursor) 647 615 { 616 struct twitter_data *td = ic->proto_data; 617 648 618 char* args[2]; 649 619 args[0] = "cursor"; 650 620 args[1] = g_strdup_printf ("%d", next_cursor); 651 621 652 twitter_http( ic, TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, args, 2);622 twitter_http(TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, td->user, td->pass, td->oauth_info, args, 2); 653 623 654 624 g_free(args[1]); … … 656 626 657 627 /** 658 * Callback after sending a new updateto twitter.659 */ 660 static void twitter_http_post _status(struct http_request *req)628 * Callback to use after sending a post request to twitter. 629 */ 630 static void twitter_http_post(struct http_request *req) 661 631 { 662 632 struct im_connection *ic = req->data; … … 669 639 if (req->status_code != 200) { 670 640 // It didn't go well, output the error and return. 671 imcb_error(ic, " Could not post message: %s", twitter_parse_error(req));641 imcb_error(ic, "HTTP Error... STATUS: %d", req->status_code); 672 642 return; 673 643 } … … 679 649 void twitter_post_status(struct im_connection *ic, char* msg) 680 650 { 651 struct twitter_data *td = ic->proto_data; 652 681 653 char* args[2]; 682 654 args[0] = "status"; 683 655 args[1] = msg; 684 twitter_http( ic, TWITTER_STATUS_UPDATE_URL, twitter_http_post_status, ic, 1, args, 2);656 twitter_http(TWITTER_STATUS_UPDATE_URL, twitter_http_post, ic, 1, td->user, td->pass, td->oauth_info, args, 2); 685 657 // g_free(args[1]); 686 658 } … … 692 664 void twitter_direct_messages_new(struct im_connection *ic, char *who, char *msg) 693 665 { 666 struct twitter_data *td = ic->proto_data; 667 694 668 char* args[4]; 695 669 args[0] = "screen_name"; … … 698 672 args[3] = msg; 699 673 // Use the same callback as for twitter_post_status, since it does basically the same. 700 twitter_http( ic, TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post_status, ic, 1, args, 4);674 twitter_http(TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post, ic, 1, td->user, td->pass, td->oauth_info, args, 4); 701 675 // g_free(args[1]); 702 676 // g_free(args[3]); 703 677 } 678 679 void twitter_friendships_create_destroy(struct im_connection *ic, char *who, int create) 680 { 681 struct twitter_data *td = ic->proto_data; 682 683 char* args[2]; 684 args[0] = "screen_name"; 685 args[1] = who; 686 twitter_http(create ? TWITTER_FRIENDSHIPS_CREATE_URL : TWITTER_FRIENDSHIPS_DESTROY_URL, twitter_http_post, ic, 1, td->user, td->pass, td->oauth_info, args, 2); 687 } 688 689 690
Note: See TracChangeset
for help on using the changeset viewer.