diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:26 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:26 +0000 |
commit | c4e8a3222648fcf22ca207f1815ebbf7cd144eeb (patch) | |
tree | 93d5c6aa93d9987680dd1adad5685e2ad698f223 /wsutil/wsjson.c | |
parent | Adding upstream version 4.2.6. (diff) | |
download | wireshark-c4e8a3222648fcf22ca207f1815ebbf7cd144eeb.tar.xz wireshark-c4e8a3222648fcf22ca207f1815ebbf7cd144eeb.zip |
Adding upstream version 4.4.0.upstream/4.4.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | wsutil/wsjson.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/wsutil/wsjson.c b/wsutil/wsjson.c index d2e55771..4a53e971 100644 --- a/wsutil/wsjson.c +++ b/wsutil/wsjson.c @@ -194,6 +194,43 @@ bool json_get_double(char *buf, jsmntok_t *parent, const char *name, double *val return false; } +bool json_get_boolean(char *buf, jsmntok_t *parent, const char *name, bool *val) +{ + int i; + size_t tok_len; + jsmntok_t *cur = parent+1; + + for (i = 0; i < parent->size; i++) { + if (cur->type == JSMN_STRING && + !strncmp(&buf[cur->start], name, cur->end - cur->start) + && strlen(name) == (size_t)(cur->end - cur->start) && + cur->size == 1 && (cur+1)->type == JSMN_PRIMITIVE) { + /* JSMN_STRICT guarantees that a primitive starts with the + * correct character. + */ + tok_len = (cur+1)->end - (cur+1)->start; + switch (buf[(cur+1)->start]) { + case 't': + if (tok_len == 4 && strncmp(&buf[(cur+1)->start], "true", tok_len) == 0) { + *val = true; + return true; + } + return false; + case 'f': + if (tok_len == 5 && strncmp(&buf[(cur+1)->start], "false", tok_len) == 0) { + *val = false; + return true; + } + return false; + default: + return false; + } + } + cur = json_get_next_object(cur); + } + return false; +} + bool json_decode_string_inplace(char *text) { |