Greenbone Vulnerability Management Libraries 22.32.0
jsonpull.c File Reference
#include "jsonpull.h"
#include <assert.h>
Include dependency graph for jsonpull.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define GVM_JSON_CHAR_EOF   -1
 End of file.
#define GVM_JSON_CHAR_ERROR   -2
 Error reading file.
#define GVM_JSON_CHAR_UNDEFINED   -3
 Undefined state.

Functions

gvm_json_path_elem_tgvm_json_pull_path_elem_new (gvm_json_pull_container_type_t parent_type, int depth)
 Creates a new JSON path element.
void gvm_json_pull_path_elem_free (gvm_json_path_elem_t *elem)
 Frees a JSON path element.
void gvm_json_pull_event_init (gvm_json_pull_event_t *event)
 Initializes a JSON pull event data structure.
void gvm_json_pull_event_cleanup (gvm_json_pull_event_t *event)
 Frees all data of JSON pull event data structure.
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.
void gvm_json_pull_parser_init (gvm_json_pull_parser_t *parser, FILE *input_stream)
 Initializes a JSON pull parser with default buffer sizes.
void gvm_json_pull_parser_cleanup (gvm_json_pull_parser_t *parser)
 Frees the data of a JSON pull parser.
static gchar * gvm_json_read_stream_error_str ()
 Generates message for an error that occurred reading the JSON stream.
static int gvm_json_pull_check_parse_buffer_size (const char *value_type, gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event)
 Checks if the parse buffer limit of a JSON pull parser is reached.
static int gvm_json_pull_parser_next_char (gvm_json_pull_parser_t *parser)
 Reads the next character in a pull parser input stream.
static int gvm_json_pull_parse_buffered (gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, const char *value_name, cJSON_bool(*validate_func)(const cJSON *const), cJSON **cjson_value)
 Tries to parse the buffer content of a JSON pull parser.
static void gvm_json_pull_handle_read_end (gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, gboolean allow_eof)
 Handles error or EOF after reading a character in JSON pull parser.
static int gvm_json_pull_skip_space (gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, gboolean allow_eof)
 Skips whitespaces in the input stream of a JSON pull parser.
static int gvm_json_pull_parse_string (gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, cJSON **cjson_value)
 Parses a string in a JSON pull parser.
static int gvm_json_pull_parse_number (gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, cJSON **cjson_value)
 Parses a number in a JSON pull parser.
static int gvm_json_pull_parse_keyword (gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, const char *keyword)
 Parses a keyword value in a JSON pull parser.
static void parse_value_next_expect (gvm_json_pull_parser_t *parser)
 Updates the expectation for a JSON pull parser according to the path.
static int gvm_json_pull_parse_key (gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event)
 Handles the case that an object key is expected in a JSON pull parser.
static int gvm_json_pull_parse_comma (gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event)
 Handles the case that a comma is expected in a JSON pull parser.
static int gvm_json_pull_parse_value (gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event)
 Handles the case that a value is expected in a JSON pull parser.
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.
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.
static void gvm_json_path_string_add_elem (gvm_json_path_elem_t *path_elem, GString *path_string)
 Appends a string path element to a JSONPath string.
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

◆ GVM_JSON_CHAR_EOF

#define GVM_JSON_CHAR_EOF   -1

◆ GVM_JSON_CHAR_ERROR

#define GVM_JSON_CHAR_ERROR   -2

◆ GVM_JSON_CHAR_UNDEFINED

#define GVM_JSON_CHAR_UNDEFINED   -3

Undefined state.

Definition at line 12 of file jsonpull.c.

Referenced by gvm_json_pull_parser_init_full(), and gvm_json_pull_parser_next().

Function Documentation

◆ gvm_json_path_string_add_elem()

void gvm_json_path_string_add_elem ( gvm_json_path_elem_t * path_elem,
GString * path_string )
static

Appends a string path element to a JSONPath string.

Parameters
[in]path_elemThe path element to append
[in]path_stringThe path string to append to

Definition at line 889 of file jsonpull.c.

891{
893 {
894 gchar *escaped_key = gvm_json_string_escape (path_elem->key, TRUE);
895 g_string_append_printf (path_string, "['%s']", escaped_key);
896 g_free (escaped_key);
897 }
898 else
899 g_string_append_printf (path_string, "[%d]", path_elem->index);
900}
gchar * gvm_json_string_escape(const char *string, gboolean single_quote)
Escapes a string according to the JSON or JSONPath standard.
Definition json.c:17
@ GVM_JSON_PULL_CONTAINER_OBJECT
Object.
Definition jsonpull.h:23
int index
Index of the element within the parent.
Definition jsonpull.h:32
char * key
Key if element is in an object.
Definition jsonpull.h:33
gvm_json_pull_container_type_t parent_type
parent container type
Definition jsonpull.h:31

References GVM_JSON_PULL_CONTAINER_OBJECT, gvm_json_string_escape(), gvm_json_path_elem::index, gvm_json_path_elem::key, and gvm_json_path_elem::parent_type.

Referenced by gvm_json_path_to_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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]pathThe path to convert
Returns
Newly allocated string of the path in JSONPath bracket notation

Definition at line 910 of file jsonpull.c.

911{
912 GString *path_string = g_string_new ("$");
913 g_queue_foreach (path, (GFunc) gvm_json_path_string_add_elem, path_string);
914 return g_string_free (path_string, FALSE);
915}
static void gvm_json_path_string_add_elem(gvm_json_path_elem_t *path_elem, GString *path_string)
Appends a string path element to a JSONPath string.
Definition jsonpull.c:889

References gvm_json_path_string_add_elem().

Referenced by parse_vt_json().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvm_json_pull_check_parse_buffer_size()

int gvm_json_pull_check_parse_buffer_size ( const char * value_type,
gvm_json_pull_parser_t * parser,
gvm_json_pull_event_t * event )
static

Checks if the parse buffer limit of a JSON pull parser is reached.

Parameters
[in]value_typeThe value type to include in the error message
[in]parserThe parser to check the parse buffer of
[in]eventEvent data for error status and message if needed
Returns
0 if buffer size is okay, 1 if limit was reached

Definition at line 151 of file jsonpull.c.

154{
155 if (parser->parse_buffer->len >= parser->parse_buffer_limit)
156 {
157 event->error_message =
158 g_strdup_printf ("%s exceeds size limit of %zu bytes", value_type,
159 parser->parse_buffer_limit);
160 event->type = GVM_JSON_PULL_EVENT_ERROR;
161 return 1;
162 }
163 return 0;
164}
@ GVM_JSON_PULL_EVENT_ERROR
Definition jsonpull.h:52
GString * parse_buffer
Buffer for parsing values and object keys.
Definition jsonpull.h:97
size_t parse_buffer_limit
Maximum parse buffer size.
Definition jsonpull.h:98

References GVM_JSON_PULL_EVENT_ERROR, gvm_json_pull_parser_t::parse_buffer, and gvm_json_pull_parser_t::parse_buffer_limit.

Referenced by gvm_json_pull_parse_number(), and gvm_json_pull_parse_string().

Here is the caller graph for this function:

◆ 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]eventThe event structure to clean up

Definition at line 61 of file jsonpull.c.

62{
63 cJSON_Delete (event->value);
64 if (event->error_message)
65 g_free (event->error_message);
66 memset (event, 0, sizeof (gvm_json_pull_event_t));
67}
Event generated by the JSON pull parser.
Definition jsonpull.h:59
gchar * error_message
Error message, NULL on success.
Definition jsonpull.h:63
cJSON * value
Value for non-container value events.
Definition jsonpull.h:62

References gvm_json_pull_event_t::error_message, and gvm_json_pull_event_t::value.

Referenced by Ensure(), Ensure(), and gvm_json_pull_parser_next().

Here is the caller graph for this function:

◆ 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]eventThe event structure to initialize

Definition at line 50 of file jsonpull.c.

51{
52 memset (event, 0, sizeof (gvm_json_pull_event_t));
53}

Referenced by Ensure().

Here is the caller graph for this function:

◆ 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]parserParser to get the current container element from
[out]error_messageError message output
Returns
The expanded container as a cJSON object if successful, else NULL

Definition at line 746 of file jsonpull.c.

748{
749 gvm_json_path_elem_t *path_tail = NULL;
750
751 int start_depth;
752 gboolean in_string, escape_next_char, in_expanded_container;
753 cJSON *expanded;
754
755 g_string_truncate (parser->parse_buffer, 0);
756
757 if (error_message)
758 *error_message = NULL;
759
760 // require "path_add" to only allow expansion at start of container
761 if (parser->path_add)
762 {
763 path_tail = parser->path_add;
764 g_queue_push_tail (parser->path, path_tail);
765 parser->path_add = NULL;
766 }
767
768 if (path_tail && path_tail->parent_type == GVM_JSON_PULL_CONTAINER_ARRAY)
769 g_string_append_c (parser->parse_buffer, '[');
770 else if (path_tail
772 g_string_append_c (parser->parse_buffer, '{');
773 else
774 {
775 if (error_message)
776 *error_message =
777 g_strdup ("can only expand after array or object start");
778 return NULL;
779 }
780
781 start_depth = path_tail->depth;
782 in_string = escape_next_char = FALSE;
783 in_expanded_container = TRUE;
784
785 while (parser->last_read_char >= 0 && in_expanded_container)
786 {
787 if (parser->parse_buffer->len >= parser->parse_buffer_limit)
788 {
789 if (error_message)
790 *error_message =
791 g_strdup_printf ("container exceeds size limit of %zu bytes",
792 parser->parse_buffer_limit);
793 return NULL;
794 }
795
796 g_string_append_c (parser->parse_buffer, parser->last_read_char);
797
798 if (escape_next_char)
799 {
800 escape_next_char = FALSE;
801 }
802 else if (in_string)
803 {
804 escape_next_char = (parser->last_read_char == '\\');
805 in_string = (parser->last_read_char != '"');
806 }
807 else
808 {
809 switch (parser->last_read_char)
810 {
811 case '"':
812 in_string = TRUE;
813 break;
814 case '[':
815 path_tail = gvm_json_pull_path_elem_new (
816 GVM_JSON_PULL_CONTAINER_ARRAY, parser->path->length);
817 g_queue_push_tail (parser->path, path_tail);
818 break;
819 case '{':
820 path_tail = gvm_json_pull_path_elem_new (
821 GVM_JSON_PULL_CONTAINER_OBJECT, parser->path->length);
822 g_queue_push_tail (parser->path, path_tail);
823 break;
824 case ']':
825 path_tail = g_queue_pop_tail (parser->path);
827 {
828 if (error_message)
829 *error_message =
830 g_strdup ("unexpected closing square bracket");
832 return NULL;
833 }
834 if (path_tail->depth == start_depth)
835 in_expanded_container = FALSE;
836
838 break;
839 case '}':
840 path_tail = g_queue_pop_tail (parser->path);
842 {
843 if (error_message)
844 *error_message =
845 g_strdup ("unexpected closing curly brace");
847 return NULL;
848 }
849 if (path_tail->depth == start_depth)
850 in_expanded_container = FALSE;
851
853 break;
854 }
855 }
857 }
858
859 if (parser->last_read_char == GVM_JSON_CHAR_ERROR)
860 {
861 if (error_message)
862 *error_message = gvm_json_read_stream_error_str ();
863 return NULL;
864 }
865 else if (in_expanded_container && parser->last_read_char == GVM_JSON_CHAR_EOF)
866 {
867 if (error_message)
868 *error_message = g_strdup ("unexpected EOF");
869 return NULL;
870 }
871
872 expanded = cJSON_Parse (parser->parse_buffer->str);
873 g_string_truncate (parser->parse_buffer, 0);
875
876 if (expanded == NULL && error_message)
877 *error_message = g_strdup ("could not parse expanded container");
878
879 return expanded;
880}
static int gvm_json_pull_parser_next_char(gvm_json_pull_parser_t *parser)
Reads the next character in a pull parser input stream.
Definition jsonpull.c:174
#define GVM_JSON_CHAR_ERROR
Error reading file.
Definition jsonpull.c:11
static void parse_value_next_expect(gvm_json_pull_parser_t *parser)
Updates the expectation for a JSON pull parser according to the path.
Definition jsonpull.c:406
#define GVM_JSON_CHAR_EOF
End of file.
Definition jsonpull.c:10
void gvm_json_pull_path_elem_free(gvm_json_path_elem_t *elem)
Frees a JSON path element.
Definition jsonpull.c:38
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.
Definition jsonpull.c:23
static gchar * gvm_json_read_stream_error_str()
Generates message for an error that occurred reading the JSON stream.
Definition jsonpull.c:136
@ GVM_JSON_PULL_CONTAINER_ARRAY
Array.
Definition jsonpull.h:22
struct gvm_json_path_elem gvm_json_path_elem_t
Path element types for the JSON pull parser.
int depth
Number of ancestor elements.
Definition jsonpull.h:34
gvm_json_path_elem_t * path_add
Path elem to add in next step.
Definition jsonpull.h:88
GQueue * path
Path to the current value.
Definition jsonpull.h:87
int last_read_char
Character last read from stream.
Definition jsonpull.h:95

References gvm_json_path_elem::depth, GVM_JSON_CHAR_EOF, GVM_JSON_CHAR_ERROR, GVM_JSON_PULL_CONTAINER_ARRAY, GVM_JSON_PULL_CONTAINER_OBJECT, gvm_json_pull_parser_next_char(), gvm_json_pull_path_elem_free(), gvm_json_pull_path_elem_new(), gvm_json_read_stream_error_str(), gvm_json_pull_parser_t::last_read_char, gvm_json_path_elem::parent_type, gvm_json_pull_parser_t::parse_buffer, gvm_json_pull_parser_t::parse_buffer_limit, parse_value_next_expect(), gvm_json_pull_parser_t::path, and gvm_json_pull_parser_t::path_add.

Referenced by Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), and parse_vt_json().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvm_json_pull_handle_read_end()

void gvm_json_pull_handle_read_end ( gvm_json_pull_parser_t * parser,
gvm_json_pull_event_t * event,
gboolean allow_eof )
static

Handles error or EOF after reading a character in JSON pull parser.

Parameters
[in]parserParser to get the last read character from
[in]eventEvent data to set EOF or error status in
[in]allow_eofWhether to allow EOF, generate error on EOF if FALSE

Definition at line 238 of file jsonpull.c.

240{
241 if (parser->last_read_char == GVM_JSON_CHAR_ERROR)
242 {
243 event->error_message = gvm_json_read_stream_error_str ();
244 event->type = GVM_JSON_PULL_EVENT_ERROR;
245 }
246 else if (allow_eof)
247 event->type = GVM_JSON_PULL_EVENT_EOF;
248 else
249 {
250 event->error_message = g_strdup ("unexpected EOF");
251 event->type = GVM_JSON_PULL_EVENT_ERROR;
252 }
253}
@ GVM_JSON_PULL_EVENT_EOF
Definition jsonpull.h:51

References GVM_JSON_CHAR_ERROR, GVM_JSON_PULL_EVENT_EOF, GVM_JSON_PULL_EVENT_ERROR, gvm_json_read_stream_error_str(), and gvm_json_pull_parser_t::last_read_char.

Referenced by gvm_json_pull_parse_keyword(), gvm_json_pull_parse_string(), gvm_json_pull_parser_next(), and gvm_json_pull_skip_space().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvm_json_pull_parse_buffered()

int gvm_json_pull_parse_buffered ( gvm_json_pull_parser_t * parser,
gvm_json_pull_event_t * event,
const char * value_name,
cJSON_bool(* validate_func )(const cJSON *const),
cJSON ** cjson_value )
static

Tries to parse the buffer content of a JSON pull parser.

Parameters
[in]parserThe parser to use the parse buffer of
[in]eventEvent set error of if necessary
[in]value_nameName of the value for error message if needed
[in]validate_funcFunction for validating the parsed value
[out]cjson_valueReturn of the parsed cJSON object on success
Returns
0 success, 1 error

Definition at line 211 of file jsonpull.c.

216{
217 cJSON *parsed_value = cJSON_Parse (parser->parse_buffer->str);
218 *cjson_value = NULL;
219 if (validate_func (parsed_value) == 0)
220 {
221 event->type = GVM_JSON_PULL_EVENT_ERROR;
222 event->error_message = g_strdup_printf ("error parsing %s", value_name);
223 cJSON_free (parsed_value);
224 return 1;
225 }
226 *cjson_value = parsed_value;
227 return 0;
228}

References GVM_JSON_PULL_EVENT_ERROR, and gvm_json_pull_parser_t::parse_buffer.

Referenced by gvm_json_pull_parse_number(), and gvm_json_pull_parse_string().

Here is the caller graph for this function:

◆ gvm_json_pull_parse_comma()

int gvm_json_pull_parse_comma ( gvm_json_pull_parser_t * parser,
gvm_json_pull_event_t * event )
static

Handles the case that a comma is expected in a JSON pull parser.

This will continue the parsing until a comma or the end of the current array/object was reached or an error occurred.

Parameters
[in]parserParser to process
[in]eventEvent data to set error or end of object status in
Returns
1 if an error occurred, 0 otherwise

Definition at line 497 of file jsonpull.c.

499{
500 if (gvm_json_pull_skip_space (parser, event, FALSE))
501 return 1;
502
503 gvm_json_path_elem_t *path_elem = NULL;
504 switch (parser->last_read_char)
505 {
506 case ',':
507 path_elem = g_queue_peek_tail (parser->path);
508 path_elem->index++;
511 else
514 break;
515 case ']':
516 path_elem = g_queue_peek_tail (parser->path);
517 if (path_elem == NULL
519 {
520 event->type = GVM_JSON_PULL_EVENT_ERROR;
521 event->error_message = g_strdup ("unexpected closing square bracket");
522 return 1;
523 }
524 event->type = GVM_JSON_PULL_EVENT_ARRAY_END;
525 event->value = NULL;
526 gvm_json_pull_path_elem_free (g_queue_pop_tail (parser->path));
529 break;
530 case '}':
531 path_elem = g_queue_peek_tail (parser->path);
532 if (path_elem == NULL
534 {
535 event->type = GVM_JSON_PULL_EVENT_ERROR;
536 event->error_message = g_strdup ("unexpected closing curly brace");
537 return 1;
538 }
539 event->type = GVM_JSON_PULL_EVENT_OBJECT_END;
540 event->value = NULL;
541 gvm_json_pull_path_elem_free (g_queue_pop_tail (parser->path));
544 break;
545 default:
546 event->error_message = g_strdup ("expected comma or end of container");
547 event->type = GVM_JSON_PULL_EVENT_ERROR;
548 return 1;
549 }
550 return 0;
551}
static int gvm_json_pull_skip_space(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, gboolean allow_eof)
Skips whitespaces in the input stream of a JSON pull parser.
Definition jsonpull.c:267
@ GVM_JSON_PULL_EXPECT_VALUE
Expect start of a value.
Definition jsonpull.h:72
@ GVM_JSON_PULL_EXPECT_KEY
Expect start of a key.
Definition jsonpull.h:73
@ GVM_JSON_PULL_EVENT_ARRAY_END
Definition jsonpull.h:44
@ GVM_JSON_PULL_EVENT_OBJECT_END
Definition jsonpull.h:46
gvm_json_pull_expect_t expect
Current expected token.
Definition jsonpull.h:89

References gvm_json_pull_parser_t::expect, GVM_JSON_PULL_CONTAINER_ARRAY, GVM_JSON_PULL_CONTAINER_OBJECT, GVM_JSON_PULL_EVENT_ARRAY_END, GVM_JSON_PULL_EVENT_ERROR, GVM_JSON_PULL_EVENT_OBJECT_END, GVM_JSON_PULL_EXPECT_KEY, GVM_JSON_PULL_EXPECT_VALUE, gvm_json_pull_parser_next_char(), gvm_json_pull_path_elem_free(), gvm_json_pull_skip_space(), gvm_json_path_elem::index, gvm_json_pull_parser_t::last_read_char, gvm_json_path_elem::parent_type, parse_value_next_expect(), and gvm_json_pull_parser_t::path.

Referenced by gvm_json_pull_parser_next().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvm_json_pull_parse_key()

int gvm_json_pull_parse_key ( gvm_json_pull_parser_t * parser,
gvm_json_pull_event_t * event )
static

Handles the case that an object key is expected in a JSON pull parser.

This will continue the parsing until the value is expected, the end of the current object was reached or an error occurred.

Parameters
[in]parserParser to process
[in]eventEvent data to set error or end of object status in
Returns
1 if an error occurred, 0 otherwise

Definition at line 426 of file jsonpull.c.

428{
429 if (gvm_json_pull_skip_space (parser, event, FALSE))
430 return 1;
431
432 cJSON *key_cjson = NULL;
433 gchar *key_str;
434 gvm_json_path_elem_t *path_elem;
435
436 switch (parser->last_read_char)
437 {
438 case '"':
439 if (gvm_json_pull_parse_string (parser, event, &key_cjson))
440 return 1;
441 key_str = g_strdup (key_cjson->valuestring);
442 cJSON_Delete (key_cjson);
443
444 // Expect colon:
445 if (gvm_json_pull_skip_space (parser, event, FALSE))
446 {
447 g_free (key_str);
448 return 1;
449 }
450 if (parser->last_read_char != ':')
451 {
452 event->type = GVM_JSON_PULL_EVENT_ERROR;
453 event->error_message = g_strdup_printf ("expected colon");
454 g_free (key_str);
455 return 1;
456 }
458
459 path_elem = g_queue_peek_tail (parser->path);
460 g_free (path_elem->key);
461 path_elem->key = key_str;
463
464 break;
465 case '}':
466 event->type = GVM_JSON_PULL_EVENT_OBJECT_END;
467 event->value = NULL;
468 gvm_json_pull_path_elem_free (g_queue_pop_tail (parser->path));
471 break;
472 case ']':
473 event->type = GVM_JSON_PULL_EVENT_ERROR;
474 event->error_message = g_strdup ("unexpected closing square bracket");
475 return 1;
476 default:
477 event->type = GVM_JSON_PULL_EVENT_ERROR;
478 event->error_message = g_strdup ("unexpected character");
479 return 1;
480 }
481
482 return 0;
483}
static int gvm_json_pull_parse_string(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, cJSON **cjson_value)
Parses a string in a JSON pull parser.
Definition jsonpull.c:293

References gvm_json_pull_parser_t::expect, GVM_JSON_PULL_EVENT_ERROR, GVM_JSON_PULL_EVENT_OBJECT_END, GVM_JSON_PULL_EXPECT_VALUE, gvm_json_pull_parse_string(), gvm_json_pull_parser_next_char(), gvm_json_pull_path_elem_free(), gvm_json_pull_skip_space(), gvm_json_path_elem::key, gvm_json_pull_parser_t::last_read_char, parse_value_next_expect(), and gvm_json_pull_parser_t::path.

Referenced by gvm_json_pull_parser_next().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvm_json_pull_parse_keyword()

int gvm_json_pull_parse_keyword ( gvm_json_pull_parser_t * parser,
gvm_json_pull_event_t * event,
const char * keyword )
static

Parses a keyword value in a JSON pull parser.

The parser is expected to be at the first character of the keyword and will be at the first character after the keyword on success.

Parameters
[in]parserParser to handle the keyword value in
[in]eventEvent data to set EOF or error status in
[in]keywordThe expected keyword, e.g. "null", "true", "false".
Returns
1 if an error occurred, 0 otherwise

Definition at line 378 of file jsonpull.c.

380{
381 for (size_t i = 0; i < strlen (keyword); i++)
382 {
383 if (parser->last_read_char < 0)
384 {
385 gvm_json_pull_handle_read_end (parser, event, FALSE);
386 return 1;
387 }
388 else if (parser->last_read_char != keyword[i])
389 {
390 event->type = GVM_JSON_PULL_EVENT_ERROR;
391 event->error_message =
392 g_strdup_printf ("misspelled keyword '%s'", keyword);
393 return 1;
394 }
396 }
397 return 0;
398}
static void gvm_json_pull_handle_read_end(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, gboolean allow_eof)
Handles error or EOF after reading a character in JSON pull parser.
Definition jsonpull.c:238

References GVM_JSON_PULL_EVENT_ERROR, gvm_json_pull_handle_read_end(), gvm_json_pull_parser_next_char(), and gvm_json_pull_parser_t::last_read_char.

Referenced by gvm_json_pull_parse_value().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvm_json_pull_parse_number()

int gvm_json_pull_parse_number ( gvm_json_pull_parser_t * parser,
gvm_json_pull_event_t * event,
cJSON ** cjson_value )
static

Parses a number in a JSON pull parser.

The parser is expected to be at the first character of the number and will be at the first non-number character on success.

Parameters
[in]parserParser to handle the number value in
[in]eventEvent data to set EOF or error status in
[out]cjson_valueThe cJSON value for the number on success.
Returns
1 if an error occurred, 0 otherwise

Definition at line 337 of file jsonpull.c.

339{
340 g_string_truncate (parser->parse_buffer, 0);
341 g_string_append_c (parser->parse_buffer, parser->last_read_char);
342 while (gvm_json_pull_parser_next_char (parser) >= 0)
343 {
344 if (gvm_json_pull_check_parse_buffer_size ("number", parser, event))
345 return 1;
346 if (g_ascii_isdigit (parser->last_read_char)
347 || parser->last_read_char == '.' || parser->last_read_char == 'e'
348 || parser->last_read_char == '-' || parser->last_read_char == '+')
349 g_string_append_c (parser->parse_buffer, parser->last_read_char);
350 else
351 break;
352 }
353
354 if (parser->last_read_char == GVM_JSON_CHAR_ERROR)
355 {
356 event->error_message = gvm_json_read_stream_error_str ();
357 event->type = GVM_JSON_PULL_EVENT_ERROR;
358 return 1;
359 }
360
361 return gvm_json_pull_parse_buffered (parser, event, "number", cJSON_IsNumber,
362 cjson_value);
363}
static int gvm_json_pull_parse_buffered(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, const char *value_name, cJSON_bool(*validate_func)(const cJSON *const), cJSON **cjson_value)
Tries to parse the buffer content of a JSON pull parser.
Definition jsonpull.c:211
static int gvm_json_pull_check_parse_buffer_size(const char *value_type, gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event)
Checks if the parse buffer limit of a JSON pull parser is reached.
Definition jsonpull.c:151

References GVM_JSON_CHAR_ERROR, gvm_json_pull_check_parse_buffer_size(), GVM_JSON_PULL_EVENT_ERROR, gvm_json_pull_parse_buffered(), gvm_json_pull_parser_next_char(), gvm_json_read_stream_error_str(), gvm_json_pull_parser_t::last_read_char, and gvm_json_pull_parser_t::parse_buffer.

Referenced by gvm_json_pull_parse_value().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvm_json_pull_parse_string()

int gvm_json_pull_parse_string ( gvm_json_pull_parser_t * parser,
gvm_json_pull_event_t * event,
cJSON ** cjson_value )
static

Parses a string in a JSON pull parser.

The parser is expected to be at the opening quote mark and will be at the character after the closing quote mark on success.

Parameters
[in]parserParser to handle the string value in
[in]eventEvent data to set EOF or error status in
[out]cjson_valueThe cJSON value for the string on success
Returns
1 if an error occurred (including EOF), 0 otherwise

Definition at line 293 of file jsonpull.c.

295{
296 gboolean escape_next_char = FALSE;
297 g_string_truncate (parser->parse_buffer, 0);
298 g_string_append_c (parser->parse_buffer, '"');
299 while (gvm_json_pull_parser_next_char (parser) >= 0)
300 {
301 if (gvm_json_pull_check_parse_buffer_size ("string", parser, event))
302 return 1;
303 g_string_append_c (parser->parse_buffer, parser->last_read_char);
304 if (escape_next_char)
305 escape_next_char = FALSE;
306 else if (parser->last_read_char == '\\')
307 escape_next_char = TRUE;
308 else if (parser->last_read_char == '"')
309 break;
310 }
311
312 if (parser->last_read_char < 0)
313 {
314 gvm_json_pull_handle_read_end (parser, event, FALSE);
315 return 1;
316 }
317
319
320 return gvm_json_pull_parse_buffered (parser, event, "string", cJSON_IsString,
321 cjson_value);
322}

References gvm_json_pull_check_parse_buffer_size(), gvm_json_pull_handle_read_end(), gvm_json_pull_parse_buffered(), gvm_json_pull_parser_next_char(), gvm_json_pull_parser_t::last_read_char, and gvm_json_pull_parser_t::parse_buffer.

Referenced by gvm_json_pull_parse_key(), and gvm_json_pull_parse_value().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvm_json_pull_parse_value()

int gvm_json_pull_parse_value ( gvm_json_pull_parser_t * parser,
gvm_json_pull_event_t * event )
static

Handles the case that a value is expected in a JSON pull parser.

This will continue the parsing until a value or the end of the current array/object was parsed or an error occurred.

Parameters
[in]parserParser to process
[in]eventEvent data to set error or end of object status in
Returns
1 if an error occurred, 0 otherwise

Definition at line 565 of file jsonpull.c.

567{
568 if (gvm_json_pull_skip_space (parser, event, FALSE))
569 return 1;
570
571 cJSON *cjson_value = NULL;
572 gvm_json_path_elem_t *path_elem = NULL;
573
574 switch (parser->last_read_char)
575 {
576 case '"':
577 if (gvm_json_pull_parse_string (parser, event, &cjson_value))
578 return 1;
579 event->type = GVM_JSON_PULL_EVENT_STRING;
580 event->value = cjson_value;
582 break;
583 case 'n':
584 if (gvm_json_pull_parse_keyword (parser, event, "null"))
585 return 1;
586 event->type = GVM_JSON_PULL_EVENT_NULL;
587 event->value = cJSON_CreateNull ();
589 break;
590 case 'f':
591 if (gvm_json_pull_parse_keyword (parser, event, "false"))
592 return 1;
593 event->type = GVM_JSON_PULL_EVENT_BOOLEAN;
594 event->value = cJSON_CreateFalse ();
596 break;
597 case 't':
598 if (gvm_json_pull_parse_keyword (parser, event, "true"))
599 return 1;
600 event->type = GVM_JSON_PULL_EVENT_BOOLEAN;
601 event->value = cJSON_CreateTrue ();
603 break;
604 case '[':
606 event->value = NULL;
608 GVM_JSON_PULL_CONTAINER_ARRAY, parser->path->length);
611 break;
612 case ']':
613 path_elem = g_queue_peek_tail (parser->path);
614 if (path_elem == NULL
616 {
617 event->type = GVM_JSON_PULL_EVENT_ERROR;
618 event->error_message = g_strdup ("unexpected closing square bracket");
619 return 1;
620 }
621 event->type = GVM_JSON_PULL_EVENT_ARRAY_END;
622 event->value = NULL;
623 gvm_json_pull_path_elem_free (g_queue_pop_tail (parser->path));
626 break;
627 case '{':
629 event->value = NULL;
631 GVM_JSON_PULL_CONTAINER_OBJECT, parser->path->length);
634 break;
635 case '}':
636 event->type = GVM_JSON_PULL_EVENT_ERROR;
637 event->error_message = g_strdup ("unexpected closing curly brace");
638 return 1;
639 break;
640 default:
641 if (g_ascii_isdigit (parser->last_read_char)
642 || parser->last_read_char == '-')
643 {
644 if (gvm_json_pull_parse_number (parser, event, &cjson_value))
645 return 1;
646 event->type = GVM_JSON_PULL_EVENT_NUMBER;
647 event->value = cjson_value;
649 }
650 else
651 {
652 event->type = GVM_JSON_PULL_EVENT_ERROR;
653 event->error_message = g_strdup ("unexpected character");
654 return 1;
655 }
656 }
657 return 0;
658}
static int gvm_json_pull_parse_number(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, cJSON **cjson_value)
Parses a number in a JSON pull parser.
Definition jsonpull.c:337
static int gvm_json_pull_parse_keyword(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, const char *keyword)
Parses a keyword value in a JSON pull parser.
Definition jsonpull.c:378
@ GVM_JSON_PULL_EVENT_STRING
Definition jsonpull.h:47
@ GVM_JSON_PULL_EVENT_OBJECT_START
Definition jsonpull.h:45
@ GVM_JSON_PULL_EVENT_NULL
Definition jsonpull.h:50
@ GVM_JSON_PULL_EVENT_NUMBER
Definition jsonpull.h:48
@ GVM_JSON_PULL_EVENT_ARRAY_START
Definition jsonpull.h:43
@ GVM_JSON_PULL_EVENT_BOOLEAN
Definition jsonpull.h:49

References gvm_json_pull_parser_t::expect, GVM_JSON_PULL_CONTAINER_ARRAY, GVM_JSON_PULL_CONTAINER_OBJECT, GVM_JSON_PULL_EVENT_ARRAY_END, GVM_JSON_PULL_EVENT_ARRAY_START, GVM_JSON_PULL_EVENT_BOOLEAN, GVM_JSON_PULL_EVENT_ERROR, GVM_JSON_PULL_EVENT_NULL, GVM_JSON_PULL_EVENT_NUMBER, GVM_JSON_PULL_EVENT_OBJECT_START, GVM_JSON_PULL_EVENT_STRING, GVM_JSON_PULL_EXPECT_KEY, GVM_JSON_PULL_EXPECT_VALUE, gvm_json_pull_parse_keyword(), gvm_json_pull_parse_number(), gvm_json_pull_parse_string(), gvm_json_pull_parser_next_char(), gvm_json_pull_path_elem_free(), gvm_json_pull_path_elem_new(), gvm_json_pull_skip_space(), gvm_json_pull_parser_t::last_read_char, gvm_json_path_elem::parent_type, parse_value_next_expect(), gvm_json_pull_parser_t::path, and gvm_json_pull_parser_t::path_add.

Referenced by gvm_json_pull_parser_next().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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]parserThe parser data structure to free the data of

Definition at line 120 of file jsonpull.c.

121{
122 assert (parser);
123 g_queue_free_full (parser->path,
124 (GDestroyNotify) gvm_json_pull_path_elem_free);
125 g_string_free (parser->parse_buffer, TRUE);
126 g_free (parser->read_buffer);
127 memset (parser, 0, sizeof (gvm_json_pull_parser_t));
128}
A json pull parser.
Definition jsonpull.h:86
char * read_buffer
Stream reading buffer.
Definition jsonpull.h:92

References gvm_json_pull_path_elem_free(), gvm_json_pull_parser_t::parse_buffer, gvm_json_pull_parser_t::path, and gvm_json_pull_parser_t::read_buffer.

Referenced by Ensure(), Ensure(), and Ensure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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]parserThe parser data structure to initialize
[in]input_streamThe JSON input stream

Definition at line 109 of file jsonpull.c.

110{
111 gvm_json_pull_parser_init_full (parser, input_stream, 0, 0);
112}
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.
Definition jsonpull.c:78

References gvm_json_pull_parser_init_full().

Referenced by Ensure(), and Ensure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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]parserThe parser data structure to initialize
[in]input_streamThe JSON input stream
[in]parse_buffer_limitMaximum buffer size for parsing values
[in]read_buffer_sizeBuffer size for reading from the stream

Definition at line 78 of file jsonpull.c.

81{
82 assert (parser);
83 assert (input_stream);
84 memset (parser, 0, sizeof (gvm_json_pull_parser_t));
85
86 if (parse_buffer_limit <= 0)
87 parse_buffer_limit = GVM_JSON_PULL_PARSE_BUFFER_LIMIT;
88
89 if (read_buffer_size <= 0)
90 read_buffer_size = GVM_JSON_PULL_READ_BUFFER_SIZE;
91
92 parser->input_stream = input_stream;
93 parser->path = g_queue_new ();
95 parser->parse_buffer_limit = parse_buffer_limit;
96 parser->parse_buffer = g_string_new ("");
97 parser->read_buffer_size = read_buffer_size;
98 parser->read_buffer = g_malloc0 (read_buffer_size);
100}
#define GVM_JSON_CHAR_UNDEFINED
Undefined state.
Definition jsonpull.c:12
#define GVM_JSON_PULL_READ_BUFFER_SIZE
Definition jsonpull.h:80
#define GVM_JSON_PULL_PARSE_BUFFER_LIMIT
Definition jsonpull.h:78
size_t read_buffer_size
Size of the stream reading buffer.
Definition jsonpull.h:93
FILE * input_stream
Input stream.
Definition jsonpull.h:91

References gvm_json_pull_parser_t::expect, GVM_JSON_CHAR_UNDEFINED, GVM_JSON_PULL_EXPECT_VALUE, GVM_JSON_PULL_PARSE_BUFFER_LIMIT, GVM_JSON_PULL_READ_BUFFER_SIZE, gvm_json_pull_parser_t::input_stream, gvm_json_pull_parser_t::last_read_char, gvm_json_pull_parser_t::parse_buffer, gvm_json_pull_parser_t::parse_buffer_limit, gvm_json_pull_parser_t::path, gvm_json_pull_parser_t::read_buffer, and gvm_json_pull_parser_t::read_buffer_size.

Referenced by gvm_json_pull_parser_init().

Here is the caller graph for this function:

◆ 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]parserThe JSON pull parser to process until the next event
[in]eventStructure to store event data in.

Definition at line 669 of file jsonpull.c.

671{
672 assert (parser);
673 assert (event);
674
677 {
678 // Handle first read of the stream
679 if (gvm_json_pull_parser_next_char (parser) < 0)
680 {
681 gvm_json_pull_handle_read_end (parser, event, TRUE);
682 return;
683 }
684 }
685
686 event->path = parser->path;
687
688 // Delayed addition to path after a container start element
689 if (parser->path_add)
690 {
691 g_queue_push_tail (parser->path, parser->path_add);
692 parser->path_add = NULL;
693 }
694
695 // Check for expected end of file
696 if (parser->expect == GVM_JSON_PULL_EXPECT_EOF)
697 {
698 if (gvm_json_pull_skip_space (parser, event, TRUE))
699 {
700 // EOF was reached, or an error occurred.
701 // The event type is already set, and if an error occurred, then
702 // error_message is also already set.
703 return;
704 }
705
706 // Skipping space succeeded. Check for unexpected characters at EOF.
707
708 if (parser->last_read_char == GVM_JSON_CHAR_EOF)
709 return;
710
711 event->type = GVM_JSON_PULL_EVENT_ERROR;
712 event->error_message = g_strdup_printf (
713 "unexpected character at end of file (%d)", parser->last_read_char);
714 return;
715 }
716
717 if (parser->expect == GVM_JSON_PULL_EXPECT_COMMA)
718 {
719 if (gvm_json_pull_parse_comma (parser, event))
720 return;
721 }
722
723 if (parser->expect == GVM_JSON_PULL_EXPECT_KEY)
724 {
725 if (gvm_json_pull_parse_key (parser, event))
726 return;
727 }
728
729 if (parser->expect == GVM_JSON_PULL_EXPECT_VALUE)
730 {
731 gvm_json_pull_parse_value (parser, event);
732 }
733}
static int gvm_json_pull_parse_comma(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event)
Handles the case that a comma is expected in a JSON pull parser.
Definition jsonpull.c:497
void gvm_json_pull_event_cleanup(gvm_json_pull_event_t *event)
Frees all data of JSON pull event data structure.
Definition jsonpull.c:61
static int gvm_json_pull_parse_value(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event)
Handles the case that a value is expected in a JSON pull parser.
Definition jsonpull.c:565
static int gvm_json_pull_parse_key(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event)
Handles the case that an object key is expected in a JSON pull parser.
Definition jsonpull.c:426
@ GVM_JSON_PULL_EXPECT_EOF
Expect end of file.
Definition jsonpull.h:75
@ GVM_JSON_PULL_EXPECT_COMMA
Expect comma or container end brace.
Definition jsonpull.h:74

References gvm_json_pull_parser_t::expect, GVM_JSON_CHAR_EOF, GVM_JSON_CHAR_UNDEFINED, gvm_json_pull_event_cleanup(), GVM_JSON_PULL_EVENT_ERROR, GVM_JSON_PULL_EXPECT_COMMA, GVM_JSON_PULL_EXPECT_EOF, GVM_JSON_PULL_EXPECT_KEY, GVM_JSON_PULL_EXPECT_VALUE, gvm_json_pull_handle_read_end(), gvm_json_pull_parse_comma(), gvm_json_pull_parse_key(), gvm_json_pull_parse_value(), gvm_json_pull_parser_next_char(), gvm_json_pull_skip_space(), gvm_json_pull_parser_t::last_read_char, gvm_json_pull_parser_t::path, and gvm_json_pull_parser_t::path_add.

Referenced by Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), and parse_vt_json().

Here is the call graph for this function:

◆ gvm_json_pull_parser_next_char()

int gvm_json_pull_parser_next_char ( gvm_json_pull_parser_t * parser)
static

Reads the next character in a pull parser input stream.

Parameters
[in]parserThe parser to read the next character from
Returns
The character code, GVM_JSON_CHAR_ERROR or GVM_JSON_CHAR_EOF.

Definition at line 174 of file jsonpull.c.

175{
176 parser->read_pos++;
177 if (parser->read_pos < parser->last_read_size)
178 {
179 parser->last_read_char =
180 (unsigned char) parser->read_buffer[parser->read_pos];
181 return parser->last_read_char;
182 }
183 else
184 {
185 parser->read_pos = 0;
186 parser->last_read_size = fread (
187 parser->read_buffer, 1, parser->read_buffer_size, parser->input_stream);
188 if (ferror (parser->input_stream))
190 else if (parser->last_read_size <= 0)
192 else
193 parser->last_read_char =
194 (unsigned char) parser->read_buffer[parser->read_pos];
195 return parser->last_read_char;
196 }
197}
size_t last_read_size
Size of last stream read.
Definition jsonpull.h:94
size_t read_pos
Position in current read.
Definition jsonpull.h:96

References GVM_JSON_CHAR_EOF, GVM_JSON_CHAR_ERROR, gvm_json_pull_parser_t::input_stream, gvm_json_pull_parser_t::last_read_char, gvm_json_pull_parser_t::last_read_size, gvm_json_pull_parser_t::read_buffer, gvm_json_pull_parser_t::read_buffer_size, and gvm_json_pull_parser_t::read_pos.

Referenced by gvm_json_pull_expand_container(), gvm_json_pull_parse_comma(), gvm_json_pull_parse_key(), gvm_json_pull_parse_keyword(), gvm_json_pull_parse_number(), gvm_json_pull_parse_string(), gvm_json_pull_parse_value(), gvm_json_pull_parser_next(), and gvm_json_pull_skip_space().

Here is the caller graph for this function:

◆ 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]elemThe element to free

Definition at line 38 of file jsonpull.c.

39{
40 g_free (elem->key);
41 g_free (elem);
42}

References gvm_json_path_elem::key.

Referenced by gvm_json_pull_expand_container(), gvm_json_pull_parse_comma(), gvm_json_pull_parse_key(), gvm_json_pull_parse_value(), and gvm_json_pull_parser_cleanup().

Here is the caller graph for this function:

◆ 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_typeType of the parent (array, object, none/root)
[in]depthThe depth in the document tree
Returns
The newly allocated path element

Definition at line 23 of file jsonpull.c.

25{
26 gvm_json_path_elem_t *new_elem = g_malloc0 (sizeof (gvm_json_path_elem_t));
27 new_elem->parent_type = parent_type;
28 new_elem->depth = depth;
29 return new_elem;
30}

References gvm_json_path_elem::depth, and gvm_json_path_elem::parent_type.

Referenced by gvm_json_pull_expand_container(), and gvm_json_pull_parse_value().

Here is the caller graph for this function:

◆ gvm_json_pull_skip_space()

int gvm_json_pull_skip_space ( gvm_json_pull_parser_t * parser,
gvm_json_pull_event_t * event,
gboolean allow_eof )
static

Skips whitespaces in the input stream of a JSON pull parser.

The parser will be at the first non-whitespace character on success.

Parameters
[in]parserParser to skip the whitespaces in
[in]eventEvent data to set EOF or error status in
[in]allow_eofWhether to allow EOF, generate error on EOF if FALSE
Returns
1 if EOF was reached or an error occurred, 0 otherwise

Definition at line 267 of file jsonpull.c.

269{
270 while (g_ascii_isspace (parser->last_read_char))
272 if (parser->last_read_char < 0)
273 {
274 gvm_json_pull_handle_read_end (parser, event, allow_eof);
275 return 1;
276 }
277 return 0;
278}

References gvm_json_pull_handle_read_end(), gvm_json_pull_parser_next_char(), and gvm_json_pull_parser_t::last_read_char.

Referenced by gvm_json_pull_parse_comma(), gvm_json_pull_parse_key(), gvm_json_pull_parse_value(), and gvm_json_pull_parser_next().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvm_json_read_stream_error_str()

gchar * gvm_json_read_stream_error_str ( )
static

Generates message for an error that occurred reading the JSON stream.

Returns
The newly allocated error message

Definition at line 136 of file jsonpull.c.

137{
138 return g_strdup_printf ("error reading JSON stream: %s", strerror (errno));
139}

Referenced by gvm_json_pull_expand_container(), gvm_json_pull_handle_read_end(), and gvm_json_pull_parse_number().

Here is the caller graph for this function:

◆ parse_value_next_expect()

void parse_value_next_expect ( gvm_json_pull_parser_t * parser)
static

Updates the expectation for a JSON pull parser according to the path.

Parameters
[in]parserThe parser to update.

Definition at line 406 of file jsonpull.c.

407{
408 if (parser->path->length)
410 else
412}

References gvm_json_pull_parser_t::expect, GVM_JSON_PULL_EXPECT_COMMA, GVM_JSON_PULL_EXPECT_EOF, and gvm_json_pull_parser_t::path.

Referenced by gvm_json_pull_expand_container(), gvm_json_pull_parse_comma(), gvm_json_pull_parse_key(), and gvm_json_pull_parse_value().

Here is the caller graph for this function: