diff options
author | jgeboski <jgeboski@gmail.com> | 2015-06-22 15:35:13 -0400 |
---|---|---|
committer | jgeboski <jgeboski@gmail.com> | 2015-06-22 15:35:13 -0400 |
commit | 75b3f5b0c29782b8a31009ba6ff2972a5ce736e3 (patch) | |
tree | da82a18f26270dcef34f52047ce9c553308849bd | |
parent | bacc420b42c5e844d2d411f8bd4315e3410777eb (diff) | |
download | bitlbee-facebook-75b3f5b0c29782b8a31009ba6ff2972a5ce736e3.tar.gz bitlbee-facebook-75b3f5b0c29782b8a31009ba6ff2972a5ce736e3.tar.bz2 bitlbee-facebook-75b3f5b0c29782b8a31009ba6ff2972a5ce736e3.tar.xz |
facebook-api: fixed JSON parse errors with messages
It was assumed there was always a leading "NULL" byte prepended to each
message. This is not the case, the NULL byte is actually a variable
integer, which is the size for a Thrift string. In order to navigate
directly the JSON data, just read the data as a thrift string in order
to obtain the offset of the JSON data.
-rw-r--r-- | facebook/facebook-api.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/facebook/facebook-api.c b/facebook/facebook-api.c index 381568f..dfb4e9a 100644 --- a/facebook/facebook-api.c +++ b/facebook/facebook-api.c @@ -445,6 +445,7 @@ static void fb_api_cb_publish_ms(fb_api_t *api, const GByteArray *pload) { GSList *msgs; fb_api_msg_t msg; + fb_thrift_t *thft; json_value *json; json_value *jv; json_value *jx; @@ -454,8 +455,14 @@ static void fb_api_cb_publish_ms(fb_api_t *api, const GByteArray *pload) gint64 in; guint i; - /* Start at 1 to skip the NULL byte */ - if (!fb_api_json_new(api, (gchar*) pload->data + 1, pload->len - 1, &json)) + thft = fb_thrift_new((GByteArray*) pload, 0, TRUE); + fb_thrift_read_str(thft, NULL); + i = thft->pos; + fb_thrift_free(thft); + + g_return_if_fail(i < pload->len); + + if (!fb_api_json_new(api, (gchar*) pload->data + i, pload->len - i, &json)) return; msgs = NULL; |