diff options
author | Matt Ranostay <matt.ranostay@konsulko.com> | 2019-06-11 22:11:36 -0700 |
---|---|---|
committer | Matt Ranostay <matt.ranostay@konsulko.com> | 2019-06-11 22:19:37 -0700 |
commit | 11282b3522d20b39775ce50655ad46ca36394cea (patch) | |
tree | f392d0d4b9b68c27d92ad22276e8d18aab6bde7c /binding | |
parent | 3639b502949565aa203559c908cd4ad878a180ae (diff) |
binding: bluetooth-map: add parsing functionality to sent messages
Sent messages have a slightly different ordering of tags, and the parser
needs to take that into account.
Bug-AGL: SPEC-2512
Change-Id: I21e120ab7674831fbaca93bb6fe060ef6661fd26
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding')
-rw-r--r-- | binding/bluetooth-map-bmessage.c | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/binding/bluetooth-map-bmessage.c b/binding/bluetooth-map-bmessage.c index d8e8f63..282669c 100644 --- a/binding/bluetooth-map-bmessage.c +++ b/binding/bluetooth-map-bmessage.c @@ -75,14 +75,14 @@ static gboolean __expect(gchar ***msg, gchar *str, json_object *jresp, gboolean #define expect(msg, str, jresp) { if (!__expect(msg, str, jresp, TRUE)) { return FALSE; }; } -static gboolean parse_sender_vcard(gchar ***msg, json_object *jresp) +static gboolean parse_vcard(gchar ***msg, json_object *jresp, char *key) { json_object *jobj; expect(msg, "VERSION:", NULL); jobj = json_object_new_object(); - json_object_object_add(jresp, "sender", jobj); + json_object_object_add(jresp, key, jobj); expect(msg, "FN", jobj); expect(msg, "N", jobj); @@ -93,8 +93,9 @@ static gboolean parse_sender_vcard(gchar ***msg, json_object *jresp) static gboolean __bmessage_parse(gchar **msg, json_object *jresp) { - gboolean benv = FALSE, bmsg = FALSE, vcard = FALSE; + gboolean benv = FALSE, bmsg = FALSE, vcard = FALSE, incoming; GString *message = g_string_new(NULL); + const char *folder; // BMSG: Begin of valid message expect(&msg, "BEGIN:BMSG", NULL); @@ -105,21 +106,43 @@ static gboolean __bmessage_parse(gchar **msg, json_object *jresp) expect(&msg, "TYPE:", jresp); expect(&msg, "FOLDER:", jresp); + folder = json_object_get_string(json_object_object_get(jresp, "folder")); + incoming = g_ascii_strcasecmp("telecom/msg/sent", folder); + // BMSG: iOS puts some non-standard stuff here while (*msg) { - if (!vcard && __expect(&msg, "BEGIN:VCARD", NULL, TRUE)) { - vcard = parse_sender_vcard(&msg, jresp); - continue; - } - - // VCARD: any BENV is invalid if comes before the recipient data - if (!vcard) - continue; - - if (!benv && __expect(&msg, "BEGIN:BENV", NULL, TRUE)) { - benv = TRUE; - continue; + // parse received message + if (incoming) { + if (!vcard && __expect(&msg, "BEGIN:VCARD", NULL, TRUE)) { + vcard = parse_vcard(&msg, jresp, "sender"); + continue; + } + + // VCARD: any BENV is invalid if comes before the sender data + if (!vcard) + continue; + + if (!benv && __expect(&msg, "BEGIN:BENV", NULL, TRUE)) { + benv = TRUE; + continue; + } + + // parse sent/outgoing message + } else { + if (!benv && __expect(&msg, "BEGIN:BENV", NULL, TRUE)) { + benv = TRUE; + continue; + } + + if (!vcard && __expect(&msg, "BEGIN:VCARD", NULL, TRUE)) { + vcard = parse_vcard(&msg, jresp, "recipient"); + continue; + } + + // VCARD: any BENV is invalid if comes after the recipient data + if (!vcard) + continue; } // BENV: can't be in the message body yet |