- Timestamp:
- 2012-11-11T16:53:56Z (12 years ago)
- Branches:
- master
- Children:
- 1388d30
- Parents:
- dff0e0b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter_lib.c
rdff0e0b r62f6b45 732 732 { 733 733 struct im_connection *ic = req->data; 734 //struct twitter_data *td = ic->proto_data;735 734 json_value *parsed; 736 int len , i;737 char c ;735 int len = 0; 736 char c, *nl; 738 737 739 738 if (!g_slist_find(twitter_connections, ic)) 740 739 return; 741 //td = ic->proto_data;;742 740 743 741 printf( "%d bytes in stream\n", req->body_size ); 744 742 745 /* m/^[\d\s]*/ /* why is there a second commend here? :-) */ 746 for (i = 0; i < req->body_size; i ++) { 747 if (!isspace(req->reply_body[i]) && !isdigit(req->reply_body[i])) 748 break; 749 } 750 751 /* Nothing but numbers and whitespace in there. Try again later. */ 752 if (i == req->body_size) 753 return; 754 755 /* Get length. */ 756 if (sscanf(req->reply_body, "%d", &len) != 1) 757 return; 758 759 if (req->body_size < i + len) { 760 printf("Not enough bytes in buffer yet\n"); 761 return; 762 } 763 764 http_flush_bytes(req, i); 765 c = req->reply_body[len]; 766 req->reply_body[len] = '\0'; 767 768 printf("JSON: %s\n", req->reply_body); 769 printf("parsed: %p\n", (parsed = json_parse(req->reply_body))); 770 if (parsed) { 771 twitter_stream_handle_object(ic, parsed); 772 } 773 json_value_free(parsed); 774 req->reply_body[len] = c; 775 776 http_flush_bytes(req, len); 743 /* MUST search for CRLF, not just LF: 744 https://dev.twitter.com/docs/streaming-apis/processing#Parsing_responses */ 745 nl = strstr(req->reply_body, "\r\n"); 746 747 if (!nl) { 748 printf("Incomplete data\n"); 749 return; 750 } 751 752 len = nl - req->reply_body; 753 if (len > 0) { 754 c = req->reply_body[len]; 755 req->reply_body[len] = '\0'; 756 757 printf("JSON: %s\n", req->reply_body); 758 printf("parsed: %p\n", (parsed = json_parse(req->reply_body))); 759 if (parsed) { 760 twitter_stream_handle_object(ic, parsed); 761 } 762 json_value_free(parsed); 763 req->reply_body[len] = c; 764 } 765 766 http_flush_bytes(req, len + 2); 777 767 778 768 /* One notification might bring multiple events! */ … … 799 789 { 800 790 struct twitter_data *td = ic->proto_data; 801 char *args[ 4] = {"with", "followings", "delimited", "length"};791 char *args[2] = {"with", "followings"}; 802 792 803 793 if ((td->stream = twitter_http(ic, TWITTER_USER_STREAM_URL, 804 twitter_http_stream, ic, 0, args, 4))) {794 twitter_http_stream, ic, 0, args, 2))) { 805 795 /* This flag must be enabled or we'll get no data until EOF 806 796 (which err, kind of, defeats the purpose of a streaming API). */
Note: See TracChangeset
for help on using the changeset viewer.