myMPD
Internal API documentation
Loading...
Searching...
No Matches
json_query.h File Reference

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>
Include dependency graph for json_query.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  t_json_parse_error
 

Typedefs

typedef bool(* iterate_callback) (const char *, sds, sds, int, validate_callback, void *, struct t_json_parse_error *)
 

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_get_tag_values (sds s, const char *path, struct mpd_song *song, validate_callback vcb, 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 (int 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)
 

Detailed Description

Json query implementation.

Typedef Documentation

◆ iterate_callback

typedef bool(* iterate_callback) (const char *, sds, sds, int, validate_callback, void *, struct t_json_parse_error *)

Iteration callback definition

Function Documentation

◆ get_mjson_toktype_name()

const char * get_mjson_toktype_name ( int  vtype)

Returns the name of a mjson token type

Parameters
vtypetoken type
Returns
token type as string

◆ json_find_key()

bool json_find_key ( sds  s,
const char *  path 
)

Searches for a key in json object

Parameters
sjson object to search
pathmjson path expression
Returns
true on success, else false

◆ json_get_array_int64()

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

Parameters
sjson object to parse
pathmjson path expression
lt_list struct to populate
max_elementsmaximum of elements
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_get_array_string()

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

Parameters
sjson object to parse
pathmjson path expression
lt_list struct to populate
vcbvalidation callback
max_elementsmaximum of elements
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_get_bool()

bool json_get_bool ( sds  s,
const char *  path,
bool *  result,
struct t_json_parse_error error 
)

Gets a bool value by json path

Parameters
sjson object to parse
pathmjson path expression
resultpointer to bool with the result
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_get_fields()

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

Parameters
sjson object to parse
pathmjson path expression
tagst_tags struct to populate
max_elementsmaximum of elements
errorpointer to t_json_parse_error
Returns
true on success, else false

◆ json_get_fields_as_string()

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

Parameters
ssds string to parse
fieldssds string to append the fields
errorpointer to t_json_parse_error
Returns
true on success, else false

◆ json_get_int()

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

Parameters
sjson object to parse
pathmjson path expression
minminimum value (including)
maxmaximum value (including)
resultpointer to int with the result
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_get_int64()

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

Parameters
sjson object to parse
pathmjson path expression
minminimum value (including)
maxmaximum value (including)
resultpointer to int64_t with the result
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_get_int64_max()

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

Parameters
sjson object to parse
pathmjson path expression
resultpointer to int64_t with the result
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_get_int_max()

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

Parameters
sjson object to parse
pathmjson path expression
resultpointer to int with the result
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_get_key_as_sds()

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

Parameters
sjson object to search
pathmjson path expression
Returns
Key value as sds

◆ json_get_object_string()

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

Parameters
sjson object to parse
pathmjson path expression
lt_list struct to populate
vcb_keyvalidation callback for key
vcb_valuevalidation callback for value
max_elementsmaximum of elements
errorpointer to t_json_parse_error
Returns
true on success, else false

◆ json_get_string()

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

Parameters
sjson object to parse
pathmjson path expression
resultpointer to int with the result
minminimum length (inclusive)
maxmaximum length (inclusive)
vcbvalidation callback
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_get_string_cmp()

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

Parameters
sjson object to parse
pathmjson path expression
resultpointer to sds with the result
minminimum length (inclusive)
maxmaximum length (inclusive)
cmpcompare result against this string
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_get_string_max()

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

Parameters
sjson object to parse
pathmjson path expression
resultpointer to sds with the result
vcbvalidation callback
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_get_tag_values()

bool json_get_tag_values ( sds  s,
const char *  path,
struct mpd_song *  song,
validate_callback  vcb,
int  max_elements,
struct t_json_parse_error error 
)

Converts a json array to a mpd song tag value(s) Shortcut for json_iterate_object with icb_json_get_tag_value

Parameters
sjson object to parse
pathmjson path expression
songmpd_song struct
vcbvalidation callback
max_elementsmaximum of elements
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_get_time_max()

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

Parameters
sjson object to parse
pathmjson path expression
resultpointer to time_t with the result
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_get_uint()

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

Parameters
sjson object to parse
pathmjson path expression
minminimum value (including)
maxmaximum value (including)
resultpointer to unsigned int with the result
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_get_uint_max()

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

Parameters
sjson object to parse
pathmjson path expression
resultpointer to unsigned int with the result
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_iterate_object()

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

Parameters
sjson object to parse
pathmjson path expression
icbiteration callback
icb_userdatacustom data for iteration callback
vcb_keyvalidation callback for the key
vcb_valuevalidation callback for the value
max_elementsmaximum of elements
errorpointer to t_json_parse_error
Returns
true on success else false

◆ json_parse_error_clear()

void json_parse_error_clear ( struct t_json_parse_error parse_error)

Clears the sds strings

Parameters
parse_errort_json_parse_error struct to clear

◆ json_parse_error_init()

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

Parameters
parse_errort_json_parse_error struct to initialize

◆ list_to_json_array()

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

Parameters
ssds string to append
lpointer to list to add keys from
Returns
pointer to s