TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags
[wireshark-sm.git] / wsutil / wsjson.h
blob180c0fb1ee36ff6e0c42636490fc1b1c253d903d
1 /** @file
3 * JSON parsing functions.
5 * Copyright 2016, Dario Lombardo
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
14 #ifndef __WSJSON_H__
15 #define __WSJSON_H__
17 #include "ws_symbol_export.h"
19 #include <inttypes.h>
20 #include <stdbool.h>
22 #include "jsmn.h"
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 /**
29 * Check if a buffer is json an returns true if it is.
31 WS_DLL_PUBLIC bool json_validate(const uint8_t *buf, const size_t len);
33 WS_DLL_PUBLIC int json_parse(const char *buf, jsmntok_t *tokens, unsigned int max_tokens);
35 /**
36 * Get the pointer to an object belonging to parent object and named as the name variable.
37 * Returns NULL if not found.
39 WS_DLL_PUBLIC jsmntok_t *json_get_object(const char *buf, jsmntok_t *parent, const char *name);
41 /**
42 * Get the pointer to an array belonging to parent object and named as the name variable.
43 * Returns NULL if not found.
45 WS_DLL_PUBLIC jsmntok_t *json_get_array(const char *buf, jsmntok_t *parent, const char *name);
47 /**
48 * Get the number of elements of an array.
49 * Returns -1 if the JSON objecct is not an array.
51 WS_DLL_PUBLIC int json_get_array_len(jsmntok_t *array);
53 /**
54 * Get the pointer to idx element of an array.
55 * Returns NULL if not found.
57 WS_DLL_PUBLIC jsmntok_t *json_get_array_index(jsmntok_t *parent, int idx);
59 /**
60 * Get the unescaped value of a string object belonging to parent object and named as the name variable.
61 * Returns NULL if not found. Caution: it modifies input buffer.
63 WS_DLL_PUBLIC char *json_get_string(char *buf, jsmntok_t *parent, const char *name);
65 /**
66 * Get the value of a number object belonging to parent object and named as the name variable.
67 * Returns false if not found. Caution: it modifies input buffer.
68 * Scientific notation not supported yet.
70 WS_DLL_PUBLIC bool json_get_double(char *buf, jsmntok_t *parent, const char *name, double *val);
72 /**
73 * Get the value of a boolean belonging to parent object and named as the name variable.
74 * Returns false if not found. (Not the same as the boolean present but false.)
76 WS_DLL_PUBLIC bool json_get_boolean(char *buf, jsmntok_t *parent, const char *name, bool *val);
78 /**
79 * Decode the contents of a JSON string value by overwriting the input data.
80 * Returns true on success and false if invalid characters were encountered.
82 WS_DLL_PUBLIC bool json_decode_string_inplace(char *text);
84 #ifdef __cplusplus
86 #endif
88 #endif
91 * Editor modelines - https://www.wireshark.org/tools/modelines.html
93 * Local variables:
94 * c-basic-offset: 4
95 * tab-width: 8
96 * indent-tabs-mode: nil
97 * End:
99 * vi: set shiftwidth=4 tabstop=8 expandtab:
100 * :indentSize=4:tabSize=8:noTabs=true: