/soc/2015/jgeboski/facebook: 2d85594bb9ee: facebook: fixed JSON ...
James Geboski <[email protected]>
| Newsgroups | gmane.comp.gnome.gaim.cvs |
|---|---|
| Message-ID | <[email protected]> |
Changeset: 2d85594bb9ee9913178ef6b6e70f092398b54a49 Author: James Geboski <[email protected]> Date: 2015-06-22 16:46 -0400 Branch: facebook URL: https://hg.pidgin.im/soc/2015/jgeboski/facebook/rev/2d85594bb9ee Description: facebook: 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. diffstat: libpurple/protocols/facebook/api.c | 12 ++++++++++-- libpurple/protocols/facebook/thrift.c | 20 ++++++++++++++++++++ libpurple/protocols/facebook/thrift.h | 6 ++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diffs (80 lines): diff --git a/libpurple/protocols/facebook/api.c b/libpurple/protocols/facebook/api.c --- a/libpurple/protocols/facebook/api.c +++ b/libpurple/protocols/facebook/api.c @@ -647,6 +647,7 @@ fb_api_cb_publish_ms(FbApi *api, const G const gchar *str; FbApiMessage msg; FbApiPrivate *priv = api->priv; + FbThrift *thft; GError *err = NULL; gint64 tid; gint64 uid; @@ -654,13 +655,20 @@ fb_api_cb_publish_ms(FbApi *api, const G GList *l; gpointer mptr; GSList *msgs = NULL; + guint i; JsonArray *arr; JsonNode *mode; JsonNode *node; JsonNode *root; - /* Start at 1 to skip the NULL byte */ - if (!fb_api_json_chk(api, pload->data + 1, pload->len - 1, &root)) { + thft = fb_thrift_new((GByteArray*) pload, 0, TRUE); + fb_thrift_read_str(thft, NULL); + i = fb_thrift_get_pos(thft); + g_object_unref(thft); + + g_return_if_fail(i < pload->len); + + if (!fb_api_json_chk(api, pload->data + i, pload->len - i, &root)) { return; } diff --git a/libpurple/protocols/facebook/thrift.c b/libpurple/protocols/facebook/thrift.c --- a/libpurple/protocols/facebook/thrift.c +++ b/libpurple/protocols/facebook/thrift.c @@ -88,6 +88,26 @@ fb_thrift_new(GByteArray *bytes, guint o return thft; } +guint +fb_thrift_get_pos(FbThrift *thft) +{ + FbThriftPrivate *priv; + + g_return_val_if_fail(FB_IS_THRIFT(thft), 0); + priv = thft->priv; + return priv->pos; +} + +void +fb_thrift_set_pos(FbThrift *thft, guint pos) +{ + FbThriftPrivate *priv; + + g_return_if_fail(FB_IS_THRIFT(thft)); + priv = thft->priv; + priv->pos = pos; +} + void fb_thrift_reset(FbThrift *thft) { diff --git a/libpurple/protocols/facebook/thrift.h b/libpurple/protocols/facebook/thrift.h --- a/libpurple/protocols/facebook/thrift.h +++ b/libpurple/protocols/facebook/thrift.h @@ -84,6 +84,12 @@ fb_thrift_get_type(void); FbThrift * fb_thrift_new(GByteArray *bytes, guint offset, gboolean compact); +guint +fb_thrift_get_pos(FbThrift *thft); + +void +fb_thrift_set_pos(FbThrift *thft, guint pos); + void fb_thrift_reset(FbThrift *thft); _______________________________________________ Commits mailing list [email protected] https://pidgin.im/cgi-bin/mailman/listinfo/commits