Ignore:
Timestamp:
2012-11-10T23:52:21Z (8 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
dff0e0b
Parents:
8bd866f
Message:

Very immature code for reading from the streaming API. It reads from a
fixed URL and tried to parse individual JSON objects. Not doing anything
useful with it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter_lib.c

    r8bd866f rddc2de5  
    727727}
    728728
    729 static void twitter_http_get_home_timeline(struct http_request *req);
    730 static void twitter_http_get_mentions(struct http_request *req);
     729static void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor);
     730static void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor);
     731
     732static 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}
    731771
    732772/**
     
    751791        if (include_mentions) {
    752792                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;
    753810        }
    754811}
     
    810867}
    811868
     869static void twitter_http_get_home_timeline(struct http_request *req);
     870static void twitter_http_get_mentions(struct http_request *req);
     871
    812872/**
    813873 * Get the timeline.
    814874 */
    815 void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor)
     875static void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor)
    816876{
    817877        struct twitter_data *td = ic->proto_data;
     
    849909 * Get mentions.
    850910 */
    851 void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor)
     911static void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor)
    852912{
    853913        struct twitter_data *td = ic->proto_data;
Note: See TracChangeset for help on using the changeset viewer.