|
myMPD
Internal API documentation
|
Json query implementation. More...
#include "dist/sds/sds.h"#include "src/lib/fields.h"#include "src/lib/list.h"#include "src/lib/validate.h"#include <stdbool.h>

Go to the source code of this file.
Data Structures | |
| struct | t_json_parse_error |
Typedefs | |
| typedef bool(* | iterate_callback) (const char *, sds, sds, enum json_vtype, validate_callback, void *, struct t_json_parse_error *) |
Enumerations | |
| enum | json_vtype { JSON_TOK_INVALID , JSON_TOK_STRING , JSON_TOK_NUMBER , JSON_TOK_TRUE , JSON_TOK_FALSE , JSON_TOK_NULL , JSON_TOK_ARRAY , JSON_TOK_OBJECT } |
Functions | |
| void | json_parse_error_init (struct t_json_parse_error *parse_error) |
| void | json_parse_error_clear (struct t_json_parse_error *parse_error) |
| bool | json_get_bool (sds s, const char *path, bool *result, struct t_json_parse_error *error) |
| bool | json_get_int_max (sds s, const char *path, int *result, struct t_json_parse_error *error) |
| bool | json_get_int (sds s, const char *path, int min, int max, int *result, struct t_json_parse_error *error) |
| bool | json_get_time_max (sds s, const char *path, time_t *result, struct t_json_parse_error *error) |
| bool | json_get_int64_max (sds s, const char *path, int64_t *result, struct t_json_parse_error *error) |
| bool | json_get_int64 (sds s, const char *path, int64_t min, int64_t max, int64_t *result, struct t_json_parse_error *error) |
| bool | json_get_uint_max (sds s, const char *path, unsigned *result, struct t_json_parse_error *error) |
| bool | json_get_uint (sds s, const char *path, unsigned min, unsigned max, unsigned *result, struct t_json_parse_error *error) |
| bool | json_get_string_max (sds s, const char *path, sds *result, validate_callback vcb, struct t_json_parse_error *error) |
| 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) |
| 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) |
| 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) |
| bool | json_get_array_int64 (sds s, const char *path, struct t_list *l, int max_elements, struct t_json_parse_error *error) |
| 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) |
| 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) |
| bool | json_get_fields (sds s, const char *path, struct t_fields *tags, int max_elements, struct t_json_parse_error *error) |
| bool | json_find_key (sds s, const char *path) |
| sds | json_get_key_as_sds (sds s, const char *path) |
| const char * | get_mjson_toktype_name (enum json_vtype vtype) |
| sds | list_to_json_array (sds s, struct t_list *l) |
| bool | json_get_fields_as_string (sds s, sds *fields, struct t_json_parse_error *error) |
Json query implementation.
| typedef bool(* iterate_callback) (const char *, sds, sds, enum json_vtype, validate_callback, void *, struct t_json_parse_error *) |
Iteration callback definition
| enum json_vtype |
JSON value types
| const char * get_mjson_toktype_name | ( | enum json_vtype | vtype | ) |
Returns the name of a mjson token type
| vtype | token type |
| bool json_find_key | ( | sds | s, |
| const char * | path | ||
| ) |
Searches for a key in json object
| s | json object to search |
| path | mjson path expression |
| bool json_get_array_int64 | ( | sds | s, |
| const char * | path, | ||
| struct t_list * | l, | ||
| int | max_elements, | ||
| struct t_json_parse_error * | error | ||
| ) |
Converts a json array of int64_t to a t_list struct Shortcut for json_iterate_object with icb_json_get_array_int64
| s | json object to parse |
| path | mjson path expression |
| l | t_list struct to populate |
| max_elements | maximum of elements |
| error | pointer to t_json_parse_error |
| 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 | ||
| ) |
Converts a json array of strings to a t_list struct Shortcut for json_iterate_object with icb_json_get_array_string
| s | json object to parse |
| path | mjson path expression |
| l | t_list struct to populate |
| vcb | validation callback |
| max_elements | maximum of elements |
| error | pointer to t_json_parse_error |
| bool json_get_bool | ( | sds | s, |
| const char * | path, | ||
| bool * | result, | ||
| struct t_json_parse_error * | error | ||
| ) |
Gets a bool value by json path
| s | json object to parse |
| path | mjson path expression |
| result | pointer to bool with the result |
| error | pointer to t_json_parse_error |
| bool json_get_fields | ( | sds | s, |
| const char * | path, | ||
| struct t_fields * | tags, | ||
| int | max_elements, | ||
| struct t_json_parse_error * | error | ||
| ) |
Converts a json array to a struct t_tags Shortcut for json_iterate_object with icb_json_get_tag
| s | json object to parse |
| path | mjson path expression |
| tags | t_tags struct to populate |
| max_elements | maximum of elements |
| error | pointer to t_json_parse_error |
| bool json_get_fields_as_string | ( | sds | s, |
| sds * | fields, | ||
| struct t_json_parse_error * | error | ||
| ) |
Helper function to get myMPD fields out of a jsonrpc request and return a validated json array
| s | sds string to parse |
| fields | sds string to append the fields |
| error | pointer to t_json_parse_error |
| bool json_get_int | ( | sds | s, |
| const char * | path, | ||
| int | min, | ||
| int | max, | ||
| int * | result, | ||
| struct t_json_parse_error * | error | ||
| ) |
Gets a int value by json path
| s | json object to parse |
| path | mjson path expression |
| min | minimum value (including) |
| max | maximum value (including) |
| result | pointer to int with the result |
| error | pointer to t_json_parse_error |
| bool json_get_int64 | ( | sds | s, |
| const char * | path, | ||
| int64_t | min, | ||
| int64_t | max, | ||
| int64_t * | result, | ||
| struct t_json_parse_error * | error | ||
| ) |
Gets an int64_t value by json path
| s | json object to parse |
| path | mjson path expression |
| min | minimum value (including) |
| max | maximum value (including) |
| result | pointer to int64_t with the result |
| error | pointer to t_json_parse_error |
| bool json_get_int64_max | ( | sds | s, |
| const char * | path, | ||
| int64_t * | result, | ||
| struct t_json_parse_error * | error | ||
| ) |
Gets an int64_t value by json path
| s | json object to parse |
| path | mjson path expression |
| result | pointer to int64_t with the result |
| error | pointer to t_json_parse_error |
| bool json_get_int_max | ( | sds | s, |
| const char * | path, | ||
| int * | result, | ||
| struct t_json_parse_error * | error | ||
| ) |
Gets a int value by json path
| s | json object to parse |
| path | mjson path expression |
| result | pointer to int with the result |
| error | pointer to t_json_parse_error |
| sds json_get_key_as_sds | ( | sds | s, |
| const char * | path | ||
| ) |
Searches for a key in json object and returns its value as sds string
| s | json object to search |
| path | mjson path expression |
| 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 | ||
| ) |
Converts a json object key/values to a t_list struct Shortcut for json_iterate_object with icb_json_get_object_string
| s | json object to parse |
| path | mjson path expression |
| l | t_list struct to populate |
| vcb_key | validation callback for key |
| vcb_value | validation callback for value |
| max_elements | maximum of elements |
| error | pointer to t_json_parse_error |
| 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 | ||
| ) |
Gets a string value by json path
| s | json object to parse |
| path | mjson path expression |
| result | pointer to int with the result |
| min | minimum length (inclusive) |
| max | maximum length (inclusive) |
| vcb | validation callback |
| error | pointer to t_json_parse_error |
| 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 | ||
| ) |
Gets a string value by json path
| s | json object to parse |
| path | mjson path expression |
| result | pointer to sds with the result |
| min | minimum length (inclusive) |
| max | maximum length (inclusive) |
| cmp | compare result against this string |
| error | pointer to t_json_parse_error |
| bool json_get_string_max | ( | sds | s, |
| const char * | path, | ||
| sds * | result, | ||
| validate_callback | vcb, | ||
| struct t_json_parse_error * | error | ||
| ) |
Gets a string value by json path
| s | json object to parse |
| path | mjson path expression |
| result | pointer to sds with the result |
| vcb | validation callback |
| error | pointer to t_json_parse_error |
| bool json_get_time_max | ( | sds | s, |
| const char * | path, | ||
| time_t * | result, | ||
| struct t_json_parse_error * | error | ||
| ) |
Gets a time_t value by json path
| s | json object to parse |
| path | mjson path expression |
| result | pointer to time_t with the result |
| error | pointer to t_json_parse_error |
| bool json_get_uint | ( | sds | s, |
| const char * | path, | ||
| unsigned | min, | ||
| unsigned | max, | ||
| unsigned * | result, | ||
| struct t_json_parse_error * | error | ||
| ) |
Gets a unsigned int value by json path
| s | json object to parse |
| path | mjson path expression |
| min | minimum value (including) |
| max | maximum value (including) |
| result | pointer to unsigned int with the result |
| error | pointer to t_json_parse_error |
| bool json_get_uint_max | ( | sds | s, |
| const char * | path, | ||
| unsigned * | result, | ||
| struct t_json_parse_error * | error | ||
| ) |
Gets a unsigned int value by json path
| s | json object to parse |
| path | mjson path expression |
| result | pointer to unsigned int with the result |
| error | pointer to t_json_parse_error |
| 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 | ||
| ) |
Iterates through object/array found by path
| s | json object to parse |
| path | mjson path expression |
| icb | iteration callback |
| icb_userdata | custom data for iteration callback |
| vcb_key | validation callback for the key |
| vcb_value | validation callback for the value |
| max_elements | maximum of elements |
| error | pointer to t_json_parse_error |
| void json_parse_error_clear | ( | struct t_json_parse_error * | parse_error | ) |
Clears the sds strings
| parse_error | t_json_parse_error struct to clear |
| void json_parse_error_init | ( | struct t_json_parse_error * | parse_error | ) |
public functions Initializes the sds strings t_json_parse_error struct to NULL
| parse_error | t_json_parse_error struct to initialize |
| sds list_to_json_array | ( | sds | s, |
| struct t_list * | l | ||
| ) |
Prints the keys of a list as a json array Leading and ending square brackets are added
| s | sds string to append |
| l | pointer to list to add keys from |