Greenbone Vulnerability Management Libraries: util/jsonpull.h File Reference

Greenbone Vulnerability Management Libraries 23.7.0

Data Structures | Macros | Typedefs | Enumerations | Functions
jsonpull.h File Reference
`#include "json.h"`
`#include <glib.h>`
`#include <stdio.h>`

Go to the source code of this file.

## Data Structures
struct | gvm_json_path_elem
| Path element types for the JSON pull parser. More...
struct | gvm_json_pull_event_t
| Event generated by the JSON pull parser. More...
struct | gvm_json_pull_parser_t
| A json pull parser. More...

## Macros
#define | _GNU_SOURCE
#define | GVM_JSON_PULL_PARSE_BUFFER_LIMIT 10485760
#define | GVM_JSON_PULL_READ_BUFFER_SIZE 4096

## Typedefs
typedef struct gvm_json_path_elem | gvm_json_path_elem_t
| Path element types for the JSON pull parser.

## Enumerations
enum | gvm_json_pull_container_type_t { GVM_JSON_PULL_CONTAINER_NONE = 0 , GVM_JSON_PULL_CONTAINER_ARRAY , GVM_JSON_PULL_CONTAINER_OBJECT }
| Type of container the parser is currently in. More...
enum | gvm_json_pull_event_type_t { GVM_JSON_PULL_EVENT_UNDEFINED = 0 , GVM_JSON_PULL_EVENT_ARRAY_START , GVM_JSON_PULL_EVENT_ARRAY_END , GVM_JSON_PULL_EVENT_OBJECT_START , GVM_JSON_PULL_EVENT_OBJECT_END , GVM_JSON_PULL_EVENT_STRING , GVM_JSON_PULL_EVENT_NUMBER , GVM_JSON_PULL_EVENT_BOOLEAN , GVM_JSON_PULL_EVENT_NULL , GVM_JSON_PULL_EVENT_EOF , GVM_JSON_PULL_EVENT_ERROR }
| Event types for the JSON pull parser. More...
enum | gvm_json_pull_expect_t { GVM_JSON_PULL_EXPECT_UNDEFINED = 0 , GVM_JSON_PULL_EXPECT_VALUE , GVM_JSON_PULL_EXPECT_KEY , GVM_JSON_PULL_EXPECT_COMMA , GVM_JSON_PULL_EXPECT_EOF }
| Expected token state for the JSON pull parser. More...

## Functions
gvm_json_path_elem_t * | gvm_json_pull_path_elem_new (gvm_json_pull_container_type_t, int)
| Creates a new JSON path element.
void | gvm_json_pull_path_elem_free (gvm_json_path_elem_t *)
| Frees a JSON path element.
void | gvm_json_pull_event_init (gvm_json_pull_event_t *)
| Initializes a JSON pull event data structure.
void | gvm_json_pull_event_cleanup (gvm_json_pull_event_t *)
| Frees all data of JSON pull event data structure.
void | gvm_json_pull_parser_init_full (gvm_json_pull_parser_t *, FILE *, size_t, size_t)
| Initializes a JSON pull parser.
void | gvm_json_pull_parser_init (gvm_json_pull_parser_t *, FILE *)
| Initializes a JSON pull parser with default buffer sizes.
void | gvm_json_pull_parser_cleanup (gvm_json_pull_parser_t *)
| Frees the data of a JSON pull parser.
void | gvm_json_pull_parser_next (gvm_json_pull_parser_t *, gvm_json_pull_event_t *)
| Get the next event from a JSON pull parser.
cJSON * | gvm_json_pull_expand_container (gvm_json_pull_parser_t *, gchar **)
| Expands the current array or object of a JSON pull parser.
gchar * | gvm_json_path_to_string (GQueue *path)
| Converts a path as used by a JSON pull parser to a JSONPath string.

## Macro Definition Documentation

## ◆ _GNU_SOURCE

#define _GNU_SOURCE

## ◆ GVM_JSON_PULL_PARSE_BUFFER_LIMIT

#define GVM_JSON_PULL_PARSE_BUFFER_LIMIT 10485760

## ◆ GVM_JSON_PULL_READ_BUFFER_SIZE

#define GVM_JSON_PULL_READ_BUFFER_SIZE 4096

## Typedef Documentation

## ◆ gvm_json_path_elem_t

typedef struct gvm_json_path_elem gvm_json_path_elem_t

Path element types for the JSON pull parser.

## Enumeration Type Documentation

## ◆ gvm_json_pull_container_type_t

enum gvm_json_pull_container_type_t

Type of container the parser is currently in.

Enumerator
GVM_JSON_PULL_CONTAINER_NONE | No container / document root.
GVM_JSON_PULL_CONTAINER_ARRAY | Array.
GVM_JSON_PULL_CONTAINER_OBJECT | Object.

## ◆ gvm_json_pull_event_type_t

enum gvm_json_pull_event_type_t

Event types for the JSON pull parser.

Enumerator
GVM_JSON_PULL_EVENT_UNDEFINED |
GVM_JSON_PULL_EVENT_ARRAY_START |
GVM_JSON_PULL_EVENT_ARRAY_END |
GVM_JSON_PULL_EVENT_OBJECT_START |
GVM_JSON_PULL_EVENT_OBJECT_END |
GVM_JSON_PULL_EVENT_STRING |
GVM_JSON_PULL_EVENT_NUMBER |
GVM_JSON_PULL_EVENT_BOOLEAN |
GVM_JSON_PULL_EVENT_NULL |
GVM_JSON_PULL_EVENT_EOF |
GVM_JSON_PULL_EVENT_ERROR |

## ◆ gvm_json_pull_expect_t

enum gvm_json_pull_expect_t

Expected token state for the JSON pull parser.

Enumerator
GVM_JSON_PULL_EXPECT_UNDEFINED | Undefined state.
GVM_JSON_PULL_EXPECT_VALUE | Expect start of a value.
GVM_JSON_PULL_EXPECT_KEY | Expect start of a key.
GVM_JSON_PULL_EXPECT_COMMA | Expect comma or container end brace.
GVM_JSON_PULL_EXPECT_EOF | Expect end of file.

## Function Documentation

## ◆ gvm_json_path_to_string()

gchar * gvm_json_path_to_string | ( | GQueue * | path | ) |

Converts a path as used by a JSON pull parser to a JSONPath string.

Parameters

  [in] | path | The path to convert

Returns
  Newly allocated string of the path in JSONPath bracket notation

## ◆ gvm_json_pull_event_cleanup()

void gvm_json_pull_event_cleanup | ( | gvm_json_pull_event_t * | event | ) |

Frees all data of JSON pull event data structure.

Parameters

  [in] | event | The event structure to clean up

## ◆ gvm_json_pull_event_init()

void gvm_json_pull_event_init | ( | gvm_json_pull_event_t * | event | ) |

Initializes a JSON pull event data structure.

Parameters

  [in] | event | The event structure to initialize

## ◆ gvm_json_pull_expand_container()

cJSON * gvm_json_pull_expand_container | ( | gvm_json_pull_parser_t * | parser,
|  | gchar ** | error_message )

Expands the current array or object of a JSON pull parser.

This should be called after an array or object start event.

Parameters

  [in] | parser | Parser to get the current container element from
  [out] | error_message | Error message output

Returns
  The expanded container as a cJSON object if successful, else NULL

## ◆ gvm_json_pull_parser_cleanup()

void gvm_json_pull_parser_cleanup | ( | gvm_json_pull_parser_t * | parser | ) |

Frees the data of a JSON pull parser.

Parameters

  [in] | parser | The parser data structure to free the data of

## ◆ gvm_json_pull_parser_init()

void gvm_json_pull_parser_init | ( | gvm_json_pull_parser_t * | parser,
|  | FILE * | input_stream )

Initializes a JSON pull parser with default buffer sizes.

Parameters

  [in] | parser | The parser data structure to initialize
  [in] | input_stream | The JSON input stream

## ◆ gvm_json_pull_parser_init_full()

void gvm_json_pull_parser_init_full | ( | gvm_json_pull_parser_t * | parser,
|  | FILE * | input_stream,
|  | size_t | parse_buffer_limit,
|  | size_t | read_buffer_size )

Initializes a JSON pull parser.

Parameters

  [in] | parser | The parser data structure to initialize
  [in] | input_stream | The JSON input stream
  [in] | parse_buffer_limit | Maximum buffer size for parsing values
  [in] | read_buffer_size | Buffer size for reading from the stream

## ◆ gvm_json_pull_parser_next()

void gvm_json_pull_parser_next | ( | gvm_json_pull_parser_t * | parser,
|  | gvm_json_pull_event_t * | event )

Get the next event from a JSON pull parser.

Note: This invalidates previous event data like the cJSON value.

Parameters

  [in] | parser | The JSON pull parser to process until the next event
  [in] | event | Structure to store event data in.

## ◆ gvm_json_pull_path_elem_free()

void gvm_json_pull_path_elem_free | ( | gvm_json_path_elem_t * | elem | ) |

Frees a JSON path element.

Parameters

  [in] | elem | The element to free

## ◆ gvm_json_pull_path_elem_new()

gvm_json_path_elem_t * gvm_json_pull_path_elem_new | ( | gvm_json_pull_container_type_t | parent_type,
|  | int | depth )

Creates a new JSON path element.

Parameters

  [in] | parent_type | Type of the parent (array, object, none/root)
  [in] | depth | The depth in the document tree

Returns
  The newly allocated path element