|
Wireshark 4.7.0
The Wireshark network protocol analyzer
|
#include "ws_symbol_export.h"#include <inttypes.h>#include <stdbool.h>#include <stdio.h>#include <glib.h>Go to the source code of this file.
Classes | |
| struct | json_dumper |
Macros | |
| #define | JSON_DUMPER_MAX_DEPTH 1100 |
| #define | JSON_DUMPER_FLAGS_PRETTY_PRINT (1 << 0) /* Enable pretty printing. */ |
| #define | JSON_DUMPER_DOT_TO_UNDERSCORE (1 << 1) /* Convert dots to underscores in keys */ |
| #define | JSON_DUMPER_FLAGS_NO_DEBUG (1 << 17) /* Disable fatal ws_error messages on error(intended for speeding up fuzzing). */ |
Typedefs | |
| typedef struct json_dumper | json_dumper |
Functions | |
| WS_DLL_PUBLIC void | json_dumper_begin_object (json_dumper *dumper) |
| Begins a new JSON object. | |
| WS_DLL_PUBLIC void | json_dumper_set_member_name (json_dumper *dumper, const char *name) |
| Sets the name of the next member in a JSON object. | |
| WS_DLL_PUBLIC void | json_dumper_end_object (json_dumper *dumper) |
| Ends the current JSON object. | |
| WS_DLL_PUBLIC void | json_dumper_begin_array (json_dumper *dumper) |
| Begins a new JSON array. | |
| WS_DLL_PUBLIC void | json_dumper_end_array (json_dumper *dumper) |
| Ends the current JSON array. | |
| WS_DLL_PUBLIC void | json_dumper_value_string (json_dumper *dumper, const char *value) |
| Writes a string value to the JSON output. | |
| WS_DLL_PUBLIC void | json_dumper_value_double (json_dumper *dumper, double value) |
| Writes a double-precision numeric value to the JSON output. | |
| WS_DLL_PUBLIC void | json_dumper_value_anyf (json_dumper *dumper, const char *format,...) G_GNUC_PRINTF(2 |
| Writes a formatted literal value to the JSON output. | |
| WS_DLL_PUBLIC void WS_DLL_PUBLIC void | json_dumper_value_va_list (json_dumper *dumper, const char *format, va_list ap) |
| Writes a formatted literal value using a va_list. | |
| WS_DLL_PUBLIC void | json_dumper_begin_base64 (json_dumper *dumper) |
| Begins a base64-encoded data block. | |
| WS_DLL_PUBLIC void | json_dumper_end_base64 (json_dumper *dumper) |
| Ends a base64-encoded data block. | |
| WS_DLL_PUBLIC void | json_dumper_write_base64 (json_dumper *dumper, const unsigned char *data, size_t len) |
| Writes binary data in base64 format. | |
| WS_DLL_PUBLIC bool | json_dumper_finish (json_dumper *dumper) |
| Finalizes the JSON output. | |
Routines for serializing data as JSON.
Copyright 2018, Peter Wu peter.nosp@m.@lek.nosp@m.enste.nosp@m.yn.n.nosp@m.l
Wireshark - Network traffic analyzer By Gerald Combs geral.nosp@m.d@wi.nosp@m.resha.nosp@m.rk.o.nosp@m.rg Copyright 1998 Gerald Combs
SPDX-License-Identifier: GPL-2.0-or-later
| #define JSON_DUMPER_MAX_DEPTH 1100 |
Example:
json_dumper dumper = { .output_file = stdout, // or .output_string = g_string_new(NULL) .flags = JSON_DUMPER_FLAGS_PRETTY_PRINT, }; json_dumper_begin_object(&dumper); json_dumper_set_member_name(&dumper, "key"); json_dumper_value_string(&dumper, "value"); json_dumper_set_member_name(&dumper, "array"); json_dumper_begin_array(&dumper); json_dumper_value_anyf(&dumper, "true"); json_dumper_value_double(&dumper, 1.0); json_dumper_begin_base64(&dumper); json_dumper_write_base64(&dumper, (const unsigned char *)"abcd", 4); json_dumper_write_base64(&dumper, (const unsigned char *)"1234", 4); json_dumper_end_base64(&dumper); json_dumper_begin_object(&dumper); json_dumper_end_object(&dumper); json_dumper_begin_array(&dumper); json_dumper_end_array(&dumper); json_dumper_end_array(&dumper); json_dumper_end_object(&dumper); json_dumper_finish(&dumper); Maximum object/array nesting depth.
| WS_DLL_PUBLIC void json_dumper_begin_array | ( | json_dumper * | dumper | ) |
Begins a new JSON array.
Starts a JSON array context. Must be paired with a call to json_dumper_end_array().
| dumper | The JSON dumper context. |
| WS_DLL_PUBLIC void json_dumper_begin_base64 | ( | json_dumper * | dumper | ) |
Begins a base64-encoded data block.
Starts a base64 encoding context for binary data. Must be paired with json_dumper_end_base64().
| dumper | The JSON dumper context. |
| WS_DLL_PUBLIC void json_dumper_begin_object | ( | json_dumper * | dumper | ) |
Begins a new JSON object.
Starts a JSON object context. Must be paired with a call to json_dumper_end_object().
| dumper | The JSON dumper context. |
| WS_DLL_PUBLIC void json_dumper_end_array | ( | json_dumper * | dumper | ) |
Ends the current JSON array.
Closes the current array context started by json_dumper_begin_array().
| dumper | The JSON dumper context. |
| WS_DLL_PUBLIC void json_dumper_end_base64 | ( | json_dumper * | dumper | ) |
Ends a base64-encoded data block.
Closes the base64 encoding context started by json_dumper_begin_base64().
| dumper | The JSON dumper context. |
| WS_DLL_PUBLIC void json_dumper_end_object | ( | json_dumper * | dumper | ) |
Ends the current JSON object.
Closes the current object context started by json_dumper_begin_object().
| dumper | The JSON dumper context. |
| WS_DLL_PUBLIC bool json_dumper_finish | ( | json_dumper * | dumper | ) |
Finalizes the JSON output.
Completes the JSON dump and checks for structural correctness (e.g., matching open/close calls).
| dumper | The JSON dumper context. |
| WS_DLL_PUBLIC void json_dumper_set_member_name | ( | json_dumper * | dumper, |
| const char * | name | ||
| ) |
Sets the name of the next member in a JSON object.
Specifies the key for the next value to be written inside an open JSON object.
| dumper | The JSON dumper context. |
| name | The name of the member key. |
| WS_DLL_PUBLIC void json_dumper_value_anyf | ( | json_dumper * | dumper, |
| const char * | format, | ||
| ... | |||
| ) |
Writes a formatted literal value to the JSON output.
Dumps a literal value such as a number, "true", "false", or "null" using printf-style formatting.
| dumper | The JSON dumper context. |
| format | The format string for the value. |
| ... | Additional arguments for formatting. |
| WS_DLL_PUBLIC void json_dumper_value_double | ( | json_dumper * | dumper, |
| double | value | ||
| ) |
Writes a double-precision numeric value to the JSON output.
Adds a floating-point number to the current object or array.
| dumper | The JSON dumper context. |
| value | The double value to write. |
| WS_DLL_PUBLIC void json_dumper_value_string | ( | json_dumper * | dumper, |
| const char * | value | ||
| ) |
Writes a string value to the JSON output.
Adds a properly escaped string value to the current object or array.
| dumper | The JSON dumper context. |
| value | The string value to write. |
| WS_DLL_PUBLIC void WS_DLL_PUBLIC void json_dumper_value_va_list | ( | json_dumper * | dumper, |
| const char * | format, | ||
| va_list | ap | ||
| ) |
Writes a formatted literal value using a va_list.
Similar to json_dumper_value_anyf(), but accepts a va_list for formatting. String values must be properly quoted and escaped by the caller. Not safe for untrusted input.
| dumper | The JSON dumper context. |
| format | The format string for the value. |
| ap | The va_list of arguments. |
| WS_DLL_PUBLIC void json_dumper_write_base64 | ( | json_dumper * | dumper, |
| const unsigned char * | data, | ||
| size_t | len | ||
| ) |
Writes binary data in base64 format.
Encodes and writes the given binary data as base64 within an active base64 context.
| dumper | The JSON dumper context. |
| data | Pointer to the binary data. |
| len | Length of the binary data in bytes. |