|
myMPD
Internal API documentation
|
Jsonrpc implementation. More...
#include "compile_time.h"#include "src/lib/json/json_query.h"#include "dist/mongoose/mongoose.h"#include "src/lib/convert.h"#include "src/lib/log.h"#include "src/lib/mem.h"#include "src/lib/sds_extras.h"#include "src/lib/sticker.h"#include <string.h>
Functions | |
| static enum json_vtype | get_vtype (char p) |
| static bool | icb_json_get_field (const char *path, sds key, sds value, enum json_vtype vtype, validate_callback vcb, void *userdata, struct t_json_parse_error *error) |
| static bool | json_get_string_unescape (sds s, const char *path, size_t min, size_t max, sds *result, validate_callback vcb, struct t_json_parse_error *error) |
| static void | set_parse_error (struct t_json_parse_error *error, const char *path, const char *key, const char *fmt,...) |
| 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_fields_as_string (sds s, sds *fields, struct t_json_parse_error *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_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_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_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) |
| static bool | icb_json_get_array_string (const char *path, sds key, sds value, enum json_vtype vtype, validate_callback vcb, void *userdata, 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) |
| static bool | icb_json_get_array_int64 (const char *path, sds key, sds value, enum json_vtype vtype, validate_callback vcb, void *userdata, 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) |
| static bool | icb_json_get_object_string (const char *path, sds key, sds value, enum json_vtype vtype, validate_callback vcb, void *userdata, 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_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) |
Jsonrpc implementation.
| const char * get_mjson_toktype_name | ( | enum json_vtype | vtype | ) |
Returns the name of a mjson token type
| vtype | token type |
|
static |
This unit provides functions for json parsing Json parsing is done by mjson private definitions
Detects the json value type by first char of value
| p | First char of value |
|
static |
Iteration callback to populate a list with json array of int64_t
| path | json path |
| key | json key |
| value | json value |
| vtype | mjson value type |
| vcb | validation callback - not used |
| userdata | pointer to a t_list struct to populate |
| error | pointer to t_json_parse_error |
|
static |
Iteration callback to populate a list with json array of strings
| path | json path |
| key | json key |
| value | json value |
| vtype | mjson value type |
| vcb | validation callback |
| userdata | pointer to a t_list struct to populate |
| error | pointer to t_json_parse_error |
|
static |
Iteration callback to populate a t_fields struct
| path | json path |
| key | not used |
| value | value to parse as mpd tag |
| vtype | mjson value type |
| vcb | not used - we validate directly |
| userdata | void pointer to t_fields struct |
| error | pointer to t_json_parse_error |
|
static |
Iteration callback to populate a list with json object key/values
| path | json path |
| key | json key |
| value | json value |
| vtype | mjson value type |
| vcb | validation callback |
| userdata | pointer to a t_list struct to populate |
| error | pointer to t_json_parse_error |
| 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 |
|
static |
Helper function to get a string from a json object Enclosing quotes are removed and string is unescaped
| s | json object to parse |
| path | path to the string to extract |
| min | minimum length |
| max | maximum length |
| result | newly allocated sds string 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 |
|
static |
Helper function to set parsing errors
| error | already initialized t_json_parse_error struct to propagate the error or NULL for log only |
| path | json path where the error occurred |
| key | optional json key inside the path where the error occurred set this to a blank string for none object paths |
| fmt | printf format string |
| ... | arguments for the format string |