diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
commit | e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc (patch) | |
tree | 68cb5ef9081156392f1dd62a00c6ccc1451b93df /wsutil/wsjson.h | |
parent | Initial commit. (diff) | |
download | wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.tar.xz wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.zip |
Adding upstream version 4.2.2.upstream/4.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wsutil/wsjson.h')
-rw-r--r-- | wsutil/wsjson.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/wsutil/wsjson.h b/wsutil/wsjson.h new file mode 100644 index 00000000..be232767 --- /dev/null +++ b/wsutil/wsjson.h @@ -0,0 +1,95 @@ +/** @file + * + * JSON parsing functions. + * + * Copyright 2016, Dario Lombardo + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef __WSJSON_H__ +#define __WSJSON_H__ + +#include "ws_symbol_export.h" + +#include <inttypes.h> +#include <stdbool.h> + +#include "jsmn.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Check if a buffer is json an returns true if it is. + */ +WS_DLL_PUBLIC bool json_validate(const uint8_t *buf, const size_t len); + +WS_DLL_PUBLIC int json_parse(const char *buf, jsmntok_t *tokens, unsigned int max_tokens); + +/** + * Get the pointer to an object belonging to parent object and named as the name variable. + * Returns NULL if not found. + */ +WS_DLL_PUBLIC jsmntok_t *json_get_object(const char *buf, jsmntok_t *parent, const char *name); + +/** + * Get the pointer to an array belonging to parent object and named as the name variable. + * Returns NULL if not found. + */ +WS_DLL_PUBLIC jsmntok_t *json_get_array(const char *buf, jsmntok_t *parent, const char *name); + +/** + * Get the number of elements of an array. + * Returns -1 if the JSON objecct is not an array. + */ +WS_DLL_PUBLIC int json_get_array_len(jsmntok_t *array); + +/** + * Get the pointer to idx element of an array. + * Returns NULL if not found. + */ +WS_DLL_PUBLIC jsmntok_t *json_get_array_index(jsmntok_t *parent, int idx); + +/** + * Get the unescaped value of a string object belonging to parent object and named as the name variable. + * Returns NULL if not found. Caution: it modifies input buffer. + */ +WS_DLL_PUBLIC char *json_get_string(char *buf, jsmntok_t *parent, const char *name); + +/** + * Get the value of a number object belonging to parent object and named as the name variable. + * Returns false if not found. Caution: it modifies input buffer. + * Scientific notation not supported yet. + */ +WS_DLL_PUBLIC bool json_get_double(char *buf, jsmntok_t *parent, const char *name, double *val); + +/** + * Decode the contents of a JSON string value by overwriting the input data. + * Returns true on success and false if invalid characters were encountered. + */ +WS_DLL_PUBLIC bool json_decode_string_inplace(char *text); + +#ifdef __cplusplus +} +#endif + +#endif + +/* + * Editor modelines - https://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ |