aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/twitter/twitter_lib.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2012-11-10 23:52:21 +0000
committerWilmer van der Gaast <wilmer@gaast.net>2012-11-10 23:52:21 +0000
commitddc2de54664ec25b95bbce997fbbb6a7104f1203 (patch)
treef1f76bf48e9e5ca4eeb6eaa0b84687253f0f78f3 /protocols/twitter/twitter_lib.c
parent8bd866f3d336cb695006bc48592cf7475139aa36 (diff)
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.
Diffstat (limited to 'protocols/twitter/twitter_lib.c')
-rw-r--r--protocols/twitter/twitter_lib.c68
1 files changed, 64 insertions, 4 deletions
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c
index 654cf467..8d10a406 100644
--- a/protocols/twitter/twitter_lib.c
+++ b/protocols/twitter/twitter_lib.c
@@ -726,8 +726,48 @@ static void twitter_private_message_chat(struct im_connection *ic, GSList * list
}
}
-static void twitter_http_get_home_timeline(struct http_request *req);
-static void twitter_http_get_mentions(struct http_request *req);
+static void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor);
+static void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor);
+
+static void twitter_http_stream(struct http_request *req)
+{
+ int len;
+ int i;
+ char c;
+ json_value *j;
+
+ printf( "%d bytes in stream\n", req->body_size );
+
+ /* m/^[\d\s]*/ /* why is there a second commend here? :-) */
+ for (i = 0; i < req->body_size; i ++) {
+ if (!isspace(req->reply_body[i]) && !isdigit(req->reply_body[i]))
+ break;
+ }
+
+ /* Nothing but numbers and whitespace in there. Try again later. */
+ if (i == req->body_size)
+ return;
+
+ /* Get length. */
+ if (sscanf(req->reply_body, "%d", &len) != 1)
+ return;
+
+ if (req->body_size < i + len) {
+ printf("Not enough bytes in buffer yet\n");
+ return;
+ }
+
+ http_flush_bytes(req, i);
+ c = req->reply_body[len];
+ req->reply_body[len] = '\0';
+
+ printf("JSON: %s\n", req->reply_body);
+ printf("parsed: %p\n", (j = json_parse(req->reply_body)));
+ json_value_free(j);
+ req->reply_body[len] = c;
+
+ http_flush_bytes(req, len);
+}
/**
* Get the timeline with optionally mentions
@@ -751,6 +791,23 @@ void twitter_get_timeline(struct im_connection *ic, gint64 next_cursor)
if (include_mentions) {
twitter_get_mentions(ic, next_cursor);
}
+
+ static int bla = 0;
+
+ if (bla)
+ return;
+ bla = 1;
+
+ char *args[4];
+ args[0] = "with";
+ args[1] = "followings";
+ args[2] = "delimited";
+ args[3] = "length";
+
+ if ((td->stream = twitter_http(ic, "https://userstream.twitter.com/1.1/user.json",
+ twitter_http_stream, ic, 0, args, 4))) {
+ td->stream->flags |= HTTPC_STREAMING;
+ }
}
/**
@@ -809,10 +866,13 @@ void twitter_flush_timeline(struct im_connection *ic)
td->home_timeline_obj = td->mentions_obj = NULL;
}
+static void twitter_http_get_home_timeline(struct http_request *req);
+static void twitter_http_get_mentions(struct http_request *req);
+
/**
* Get the timeline.
*/
-void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor)
+static void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor)
{
struct twitter_data *td = ic->proto_data;
@@ -848,7 +908,7 @@ void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor)
/**
* Get mentions.
*/
-void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor)
+static void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor)
{
struct twitter_data *td = ic->proto_data;