myMPD
Internal API documentation
Loading...
Searching...
No Matches
json_query.h
Go to the documentation of this file.
1/*
2 SPDX-License-Identifier: GPL-3.0-or-later
3 myMPD (c) 2018-2025 Juergen Mang <mail@jcgames.de>
4 https://github.com/jcorporation/mympd
5*/
6
11#ifndef MYMPD_JSON_QUERY_H
12#define MYMPD_JSON_QUERY_H
13
14#include "dist/sds/sds.h"
15#include "src/lib/fields.h"
16#include "src/lib/list.h"
17#include "src/lib/validate.h"
18
19#include <stdbool.h>
20
25 JSON_TOK_INVALID,
26 JSON_TOK_STRING,
27 JSON_TOK_NUMBER,
28 JSON_TOK_TRUE,
29 JSON_TOK_FALSE,
30 JSON_TOK_NULL,
31 JSON_TOK_ARRAY,
32 JSON_TOK_OBJECT
33};
34
39 sds message;
40 sds path;
41};
42
46typedef bool (*iterate_callback) (const char *, sds, sds, enum json_vtype, validate_callback, void *, struct t_json_parse_error *);
47
48void json_parse_error_init(struct t_json_parse_error *parse_error);
49void json_parse_error_clear(struct t_json_parse_error *parse_error);
50
51bool json_get_bool(sds s, const char *path, bool *result, struct t_json_parse_error *error);
52bool json_get_int_max(sds s, const char *path, int *result, struct t_json_parse_error *error);
53bool json_get_int(sds s, const char *path, int min, int max, int *result, struct t_json_parse_error *error);
54bool json_get_time_max(sds s, const char *path, time_t *result, struct t_json_parse_error *error);
55bool json_get_int64_max(sds s, const char *path, int64_t *result, struct t_json_parse_error *error);
56bool json_get_int64(sds s, const char *path, int64_t min, int64_t max, int64_t *result, struct t_json_parse_error *error);
57bool json_get_uint_max(sds s, const char *path, unsigned *result, struct t_json_parse_error *error);
58bool json_get_uint(sds s, const char *path, unsigned min, unsigned max, unsigned *result, struct t_json_parse_error *error);
59bool json_get_string_max(sds s, const char *path, sds *result, validate_callback vcb, struct t_json_parse_error *error);
60bool json_get_string(sds s, const char *path, size_t min, size_t max, sds *result, validate_callback vcb, struct t_json_parse_error *error);
61bool json_get_string_cmp(sds s, const char *path, size_t min, size_t max, const char *cmp, sds *result, struct t_json_parse_error *error);
62bool json_get_array_string(sds s, const char *path, struct t_list *l, validate_callback vcb, int max_elements, struct t_json_parse_error *error);
63bool json_get_array_int64(sds s, const char *path, struct t_list *l, int max_elements, struct t_json_parse_error *error);
64bool json_get_object_string(sds s, const char *path, struct t_list *l, validate_callback vcb_key,
65 validate_callback vcb_value, int max_elements, struct t_json_parse_error *error);
66bool json_iterate_object(sds s, const char *path, iterate_callback icb, void *icb_userdata,
67 validate_callback vcb_key, validate_callback vcb_value, int max_elements, struct t_json_parse_error *error);
68bool json_get_fields(sds s, const char *path, struct t_fields *tags, int max_elements, struct t_json_parse_error *error);
69
70bool json_find_key(sds s, const char *path);
71sds json_get_key_as_sds(sds s, const char *path);
72
73const char *get_mjson_toktype_name(enum json_vtype vtype);
74sds list_to_json_array(sds s, struct t_list *l);
75bool json_get_fields_as_string(sds s, sds *fields, struct t_json_parse_error *error);
76
77#endif
Fields handling.
bool json_get_uint_max(sds s, const char *path, unsigned *result, struct t_json_parse_error *error)
Definition json_query.c:215
bool json_get_object_string(sds s, const char *path, struct t_list *l, validate_callback vcb_key, validate_callback vcb_value, int max_elements, struct t_json_parse_error *error)
Definition json_query.c:550
bool json_get_int_max(sds s, const char *path, int *result, struct t_json_parse_error *error)
Definition json_query.c:103
bool(* iterate_callback)(const char *, sds, sds, enum json_vtype, validate_callback, void *, struct t_json_parse_error *)
Definition json_query.h:46
void json_parse_error_clear(struct t_json_parse_error *parse_error)
Definition json_query.c:53
bool json_find_key(sds s, const char *path)
Definition json_query.c:576
bool json_get_array_int64(sds s, const char *path, struct t_list *l, int max_elements, struct t_json_parse_error *error)
Definition json_query.c:510
json_vtype
Definition json_query.h:24
bool json_iterate_object(sds s, const char *path, iterate_callback icb, void *icb_userdata, validate_callback vcb_key, validate_callback vcb_value, int max_elements, struct t_json_parse_error *error)
Definition json_query.c:321
bool json_get_string(sds s, const char *path, size_t min, size_t max, sds *result, validate_callback vcb, struct t_json_parse_error *error)
Definition json_query.c:301
bool json_get_bool(sds s, const char *path, bool *result, struct t_json_parse_error *error)
Definition json_query.c:85
bool json_get_int(sds s, const char *path, int min, int max, int *result, struct t_json_parse_error *error)
Definition json_query.c:117
bool json_get_fields_as_string(sds s, sds *fields, struct t_json_parse_error *error)
Definition json_query.c:66
const char * get_mjson_toktype_name(enum json_vtype vtype)
Definition json_query.c:602
bool json_get_array_string(sds s, const char *path, struct t_list *l, validate_callback vcb, int max_elements, struct t_json_parse_error *error)
Definition json_query.c:468
bool json_get_uint(sds s, const char *path, unsigned min, unsigned max, unsigned *result, struct t_json_parse_error *error)
Definition json_query.c:229
bool json_get_int64(sds s, const char *path, int64_t min, int64_t max, int64_t *result, struct t_json_parse_error *error)
Definition json_query.c:187
sds json_get_key_as_sds(sds s, const char *path)
Definition json_query.c:589
sds list_to_json_array(sds s, struct t_list *l)
Definition json_print.c:231
bool json_get_string_max(sds s, const char *path, sds *result, validate_callback vcb, struct t_json_parse_error *error)
Definition json_query.c:259
bool json_get_string_cmp(sds s, const char *path, size_t min, size_t max, const char *cmp, sds *result, struct t_json_parse_error *error)
Definition json_query.c:278
bool json_get_time_max(sds s, const char *path, time_t *result, struct t_json_parse_error *error)
Definition json_query.c:147
bool json_get_int64_max(sds s, const char *path, int64_t *result, struct t_json_parse_error *error)
Definition json_query.c:173
bool json_get_fields(sds s, const char *path, struct t_fields *tags, int max_elements, struct t_json_parse_error *error)
Definition json_query.c:566
void json_parse_error_init(struct t_json_parse_error *parse_error)
Definition json_query.c:44
Linked list implementation.
Definition fields.h:37
Definition json_query.h:38
sds message
the error message
Definition json_query.h:39
sds path
the json path of the invalid value
Definition json_query.h:40
Definition list.h:32
String validation functions.
bool(* validate_callback)(sds)
Definition validate.h:21