- Timestamp:
- 2012-11-10T23:52:21Z (12 years ago)
- Branches:
- master
- Children:
- dff0e0b
- Parents:
- 8bd866f
- Location:
- protocols/twitter
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.h
r8bd866f rddc2de5 57 57 guint64 last_status_id; /* For undo */ 58 58 gint main_loop_id; 59 struct http_request *stream; 59 60 struct groupchat *timeline_gc; 60 61 gint http_fails; -
protocols/twitter/twitter_http.c
r8bd866f rddc2de5 47 47 * This is actually pretty generic function... Perhaps it should move to the lib/http_client.c 48 48 */ 49 void*twitter_http(struct im_connection *ic, char *url_string, http_input_function func,50 gpointer data, int is_post, char **arguments, int arguments_len)49 struct http_request *twitter_http(struct im_connection *ic, char *url_string, http_input_function func, 50 gpointer data, int is_post, char **arguments, int arguments_len) 51 51 { 52 52 struct twitter_data *td = ic->proto_data; … … 55 55 void *ret; 56 56 char *url_arguments; 57 url_t *base_url = NULL; 57 58 58 59 url_arguments = g_strdup(""); … … 67 68 } 68 69 } 70 71 if (strstr(url_string, "://")) { 72 base_url = g_new0(url_t, 1); 73 if (!url_set(base_url, url_string)) { 74 g_free(base_url); 75 return NULL; 76 } 77 } 78 69 79 // Make the request. 70 80 g_string_printf(request, "%s %s%s%s%s HTTP/1.0\r\n" … … 72 82 "User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n", 73 83 is_post ? "POST" : "GET", 74 td->url_path, url_string, 75 is_post ? "" : "?", is_post ? "" : url_arguments, td->url_host); 84 base_url ? base_url->file : td->url_path, 85 base_url ? "" : url_string, 86 is_post ? "" : "?", is_post ? "" : url_arguments, 87 base_url ? base_url->host : td->url_host); 76 88 77 89 // If a pass and user are given we append them to the request. … … 80 92 char *full_url; 81 93 82 full_url = g_strconcat(set_getstr(&ic->acc->set, "base_url"), url_string, NULL); 94 if (base_url) 95 full_url = g_strdup(url_string); 96 else 97 full_url = g_strconcat(set_getstr(&ic->acc->set, "base_url"), url_string, NULL); 83 98 full_header = oauth_http_header(td->oauth_info, is_post ? "POST" : "GET", 84 99 full_url, url_arguments); … … 109 124 } 110 125 111 ret = http_dorequest(td->url_host, td->url_port, td->url_ssl, request->str, func, data); 126 if (base_url) 127 ret = http_dorequest(base_url->host, base_url->port, base_url->proto == PROTO_HTTPS, request->str, func, data); 128 else 129 ret = http_dorequest(td->url_host, td->url_port, td->url_ssl, request->str, func, data); 112 130 113 131 g_free(url_arguments); 114 132 g_string_free(request, TRUE); 133 g_free(base_url); 115 134 return ret; 116 135 } -
protocols/twitter/twitter_http.h
r8bd866f rddc2de5 30 30 struct oauth_info; 31 31 32 void*twitter_http(struct im_connection *ic, char *url_string, http_input_function func,33 gpointer data, int is_post, char** arguments, int arguments_len);32 struct http_request *twitter_http(struct im_connection *ic, char *url_string, http_input_function func, 33 gpointer data, int is_post, char** arguments, int arguments_len); 34 34 35 35 #endif //_TWITTER_HTTP_H -
protocols/twitter/twitter_lib.c
r8bd866f rddc2de5 727 727 } 728 728 729 static void twitter_http_get_home_timeline(struct http_request *req); 730 static void twitter_http_get_mentions(struct http_request *req); 729 static void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor); 730 static void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor); 731 732 static void twitter_http_stream(struct http_request *req) 733 { 734 int len; 735 int i; 736 char c; 737 json_value *j; 738 739 printf( "%d bytes in stream\n", req->body_size ); 740 741 /* m/^[\d\s]*/ /* why is there a second commend here? :-) */ 742 for (i = 0; i < req->body_size; i ++) { 743 if (!isspace(req->reply_body[i]) && !isdigit(req->reply_body[i])) 744 break; 745 } 746 747 /* Nothing but numbers and whitespace in there. Try again later. */ 748 if (i == req->body_size) 749 return; 750 751 /* Get length. */ 752 if (sscanf(req->reply_body, "%d", &len) != 1) 753 return; 754 755 if (req->body_size < i + len) { 756 printf("Not enough bytes in buffer yet\n"); 757 return; 758 } 759 760 http_flush_bytes(req, i); 761 c = req->reply_body[len]; 762 req->reply_body[len] = '\0'; 763 764 printf("JSON: %s\n", req->reply_body); 765 printf("parsed: %p\n", (j = json_parse(req->reply_body))); 766 json_value_free(j); 767 req->reply_body[len] = c; 768 769 http_flush_bytes(req, len); 770 } 731 771 732 772 /** … … 751 791 if (include_mentions) { 752 792 twitter_get_mentions(ic, next_cursor); 793 } 794 795 static int bla = 0; 796 797 if (bla) 798 return; 799 bla = 1; 800 801 char *args[4]; 802 args[0] = "with"; 803 args[1] = "followings"; 804 args[2] = "delimited"; 805 args[3] = "length"; 806 807 if ((td->stream = twitter_http(ic, "https://userstream.twitter.com/1.1/user.json", 808 twitter_http_stream, ic, 0, args, 4))) { 809 td->stream->flags |= HTTPC_STREAMING; 753 810 } 754 811 } … … 810 867 } 811 868 869 static void twitter_http_get_home_timeline(struct http_request *req); 870 static void twitter_http_get_mentions(struct http_request *req); 871 812 872 /** 813 873 * Get the timeline. 814 874 */ 815 void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor)875 static void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor) 816 876 { 817 877 struct twitter_data *td = ic->proto_data; … … 849 909 * Get mentions. 850 910 */ 851 void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor)911 static void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor) 852 912 { 853 913 struct twitter_data *td = ic->proto_data; -
protocols/twitter/twitter_lib.h
r8bd866f rddc2de5 81 81 void twitter_get_timeline(struct im_connection *ic, gint64 next_cursor); 82 82 void twitter_get_friends_ids(struct im_connection *ic, gint64 next_cursor); 83 void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor);84 void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor);85 83 void twitter_get_statuses_friends(struct im_connection *ic, gint64 next_cursor); 86 84
Note: See TracChangeset
for help on using the changeset viewer.