XMMS2
Macros | Typedefs | Functions | Variables
value.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include "xmmsc/xmmsv.h"
#include "xmmsc/xmmsc_idnumbers.h"
#include "xmmsc/xmmsc_errorcodes.h"
#include "xmmsc/xmmsc_stdbool.h"
#include "xmmsc/xmmsc_util.h"
#include "xmmspriv/xmms_list.h"

Go to the source code of this file.

Macros

#define GEN_DICT_EXTRACTOR_FUNC(typename, type)
 
#define GEN_DICT_SET_FUNC(typename, type)
 
#define GEN_DICT_ITER_EXTRACTOR_FUNC(typename, type)
 
#define GEN_DICT_ITER_SET_FUNC(typename, type)
 
#define GEN_LIST_EXTRACTOR_FUNC(typename, type)
 
#define GEN_LIST_SET_FUNC(typename, type)
 
#define GEN_LIST_INSERT_FUNC(typename, type)
 
#define GEN_LIST_APPEND_FUNC(typename, type)
 
#define GEN_LIST_ITER_EXTRACTOR_FUNC(typename, type)
 
#define GEN_LIST_ITER_INSERT_FUNC(typename, type)
 

Typedefs

typedef struct xmmsv_list_St xmmsv_list_t
 
typedef struct xmmsv_dict_St xmmsv_dict_t
 
typedef struct xmmsv_bin_St xmmsv_bin_t
 

Functions

xmmsv_txmmsv_new_none (void)
 Allocates a new empty xmmsv_t. More...
 
xmmsv_txmmsv_new_error (const char *errstr)
 Allocates a new error xmmsv_t. More...
 
xmmsv_txmmsv_new_int (int32_t i)
 Allocates a new integer xmmsv_t. More...
 
xmmsv_txmmsv_new_string (const char *s)
 Allocates a new string xmmsv_t. More...
 
xmmsv_txmmsv_new_coll (xmmsv_coll_t *c)
 Allocates a new collection xmmsv_t. More...
 
xmmsv_txmmsv_new_bin (const unsigned char *data, unsigned int len)
 Allocates a new binary data xmmsv_t. More...
 
xmmsv_txmmsv_new_list (void)
 Allocates a new list xmmsv_t. More...
 
xmmsv_txmmsv_new_dict (void)
 Allocates a new dict xmmsv_t. More...
 
xmmsv_txmmsv_ref (xmmsv_t *val)
 References the xmmsv_t. More...
 
void xmmsv_unref (xmmsv_t *val)
 Decreases the references for the xmmsv_t When the number of references reaches 0 it will be freed. More...
 
xmmsv_type_t xmmsv_get_type (const xmmsv_t *val)
 Get the type of the value. More...
 
int xmmsv_is_type (const xmmsv_t *val, xmmsv_type_t t)
 Check if value is of specified type. More...
 
int xmmsv_is_error (const xmmsv_t *val)
 Check if the value stores an error. More...
 
int xmmsv_is_list (const xmmsv_t *val)
 Check if the value stores a list. More...
 
int xmmsv_is_dict (const xmmsv_t *val)
 Check if the value stores a dict. More...
 
const char * xmmsv_get_error_old (const xmmsv_t *val)
 Legacy alias to retrieve the error string from an xmmsv_t. More...
 
xmmsv_txmmsv_make_stringlist (char *array[], int num)
 Helper function to build a list xmmsv_t containing the strings from the input array. More...
 
xmmsv_type_t xmmsv_dict_entry_get_type (xmmsv_t *val, const char *key)
 Gets the type of a dict entry. More...
 
xmmsv_txmmsv_propdict_to_dict (xmmsv_t *propdict, const char **src_prefs)
 Helper function to transform a key-source-value dict-of-dict xmmsv_t (formerly a propdict) to a regular key-value dict, given a list of source preference. More...
 
int xmmsv_get_error (const xmmsv_t *val, const char **r)
 Retrieves an error string describing the server error from the value. More...
 
int xmmsv_get_int (const xmmsv_t *val, int32_t *r)
 Retrieves a signed integer from the value. More...
 
int xmmsv_get_uint (const xmmsv_t *val, uint32_t *r)
 Retrieves a unsigned integer from the value. More...
 
int xmmsv_get_string (const xmmsv_t *val, const char **r)
 Retrieves a string from the value. More...
 
int xmmsv_get_coll (const xmmsv_t *val, xmmsv_coll_t **c)
 Retrieves a collection from the value. More...
 
int xmmsv_get_bin (const xmmsv_t *val, const unsigned char **r, unsigned int *rlen)
 Retrieves binary data from the value. More...
 
int xmmsv_get_list_iter (const xmmsv_t *val, xmmsv_list_iter_t **it)
 Retrieves a list iterator from a list xmmsv_t. More...
 
int xmmsv_get_dict_iter (const xmmsv_t *val, xmmsv_dict_iter_t **it)
 Retrieves a dict iterator from a dict xmmsv_t. More...
 
int xmmsv_list_get (xmmsv_t *listv, int pos, xmmsv_t **val)
 Get the element at the given position in the list xmmsv_t. More...
 
int xmmsv_list_set (xmmsv_t *listv, int pos, xmmsv_t *val)
 Set the element at the given position in the list xmmsv_t. More...
 
int xmmsv_list_insert (xmmsv_t *listv, int pos, xmmsv_t *val)
 Insert an element at the given position in the list xmmsv_t. More...
 
int xmmsv_list_remove (xmmsv_t *listv, int pos)
 Remove the element at the given position from the list xmmsv_t. More...
 
int xmmsv_list_move (xmmsv_t *listv, int old_pos, int new_pos)
 Move the element from position #old to position #new. More...
 
int xmmsv_list_append (xmmsv_t *listv, xmmsv_t *val)
 Append an element to the end of the list xmmsv_t. More...
 
int xmmsv_list_clear (xmmsv_t *listv)
 Empty the list from all its elements. More...
 
int xmmsv_list_foreach (xmmsv_t *listv, xmmsv_list_foreach_func func, void *user_data)
 Apply a function to each element in the list, in sequential order. More...
 
int xmmsv_list_get_size (xmmsv_t *listv)
 Return the size of the list. More...
 
int xmmsv_list_restrict_type (xmmsv_t *listv, xmmsv_type_t type)
 
void xmmsv_list_iter_explicit_destroy (xmmsv_list_iter_t *it)
 Explicitly free list iterator. More...
 
int xmmsv_list_iter_entry (xmmsv_list_iter_t *it, xmmsv_t **val)
 Get the element currently pointed at by the iterator. More...
 
int xmmsv_list_iter_valid (xmmsv_list_iter_t *it)
 Check whether the iterator is valid and points to a valid element. More...
 
void xmmsv_list_iter_first (xmmsv_list_iter_t *it)
 Rewind the iterator to the start of the list. More...
 
void xmmsv_list_iter_last (xmmsv_list_iter_t *it)
 Move the iterator to end of the list. More...
 
void xmmsv_list_iter_next (xmmsv_list_iter_t *it)
 Advance the iterator to the next element in the list. More...
 
void xmmsv_list_iter_prev (xmmsv_list_iter_t *it)
 Move the iterator to the previous element in the list. More...
 
int xmmsv_list_iter_seek (xmmsv_list_iter_t *it, int pos)
 Move the iterator to the n-th element in the list. More...
 
int xmmsv_list_iter_tell (const xmmsv_list_iter_t *it)
 Tell the position of the iterator. More...
 
xmmsv_txmmsv_list_iter_get_parent (const xmmsv_list_iter_t *it)
 Return the parent xmmsv_t of an iterator. More...
 
int xmmsv_list_iter_insert (xmmsv_list_iter_t *it, xmmsv_t *val)
 Insert an element in the list at the position pointed at by the iterator. More...
 
int xmmsv_list_iter_remove (xmmsv_list_iter_t *it)
 Remove the element in the list at the position pointed at by the iterator. More...
 
int xmmsv_dict_get (xmmsv_t *dictv, const char *key, xmmsv_t **val)
 Get the element corresponding to the given key in the dict xmmsv_t (if it exists). More...
 
int xmmsv_dict_set (xmmsv_t *dictv, const char *key, xmmsv_t *val)
 Insert an element under the given key in the dict xmmsv_t. More...
 
int xmmsv_dict_remove (xmmsv_t *dictv, const char *key)
 Remove the element corresponding to a given key in the dict xmmsv_t (if it exists). More...
 
int xmmsv_dict_clear (xmmsv_t *dictv)
 Empty the dict of all its elements. More...
 
int xmmsv_dict_foreach (xmmsv_t *dictv, xmmsv_dict_foreach_func func, void *user_data)
 Apply a function to each key-element pair in the list. More...
 
int xmmsv_dict_get_size (xmmsv_t *dictv)
 Return the size of the dict. More...
 
void xmmsv_dict_iter_explicit_destroy (xmmsv_dict_iter_t *it)
 Explicitly free dict iterator. More...
 
int xmmsv_dict_iter_pair (xmmsv_dict_iter_t *it, const char **key, xmmsv_t **val)
 Get the key-element pair currently pointed at by the iterator. More...
 
int xmmsv_dict_iter_valid (xmmsv_dict_iter_t *it)
 Check whether the iterator is valid and points to a valid pair. More...
 
void xmmsv_dict_iter_first (xmmsv_dict_iter_t *it)
 Rewind the iterator to the start of the dict. More...
 
void xmmsv_dict_iter_next (xmmsv_dict_iter_t *it)
 Advance the iterator to the next pair in the dict. More...
 
int xmmsv_dict_iter_find (xmmsv_dict_iter_t *it, const char *key)
 Move the iterator to the pair with the given key (if it exists) or move it to the position where the key would have to be put (if it doesn't exist yet). More...
 
int xmmsv_dict_iter_set (xmmsv_dict_iter_t *it, xmmsv_t *val)
 Replace the element of the pair currently pointed to by the iterator. More...
 
int xmmsv_dict_iter_remove (xmmsv_dict_iter_t *it)
 Remove the pair in the dict pointed at by the iterator. More...
 
xmmsv_txmmsv_decode_url (const xmmsv_t *inv)
 Decode an URL-encoded string. More...
 
xmmsv_txmmsv_build_dict (const char *firstkey,...)
 
xmmsv_txmmsv_build_list_va (xmmsv_t *first_entry, va_list ap)
 
xmmsv_txmmsv_build_list (xmmsv_t *first_entry,...)
 
int xmmsv_dict_format (char *target, int len, const char *fmt, xmmsv_t *val)
 This function will make a pretty string about the information in xmmsv dict. More...
 
int xmmsv_utf8_validate (const char *str)
 Check if a string is valid UTF-8. More...
 
int xmmsv_dict_has_key (xmmsv_t *dictv, const char *key)
 
xmmsv_txmmsv_bitbuffer_new_ro (const unsigned char *v, int len)
 
xmmsv_txmmsv_bitbuffer_new (void)
 
int xmmsv_bitbuffer_get_bits (xmmsv_t *v, int bits, int *res)
 
int xmmsv_bitbuffer_get_data (xmmsv_t *v, unsigned char *b, int len)
 
int xmmsv_bitbuffer_put_bits (xmmsv_t *v, int bits, int d)
 
int xmmsv_bitbuffer_put_bits_at (xmmsv_t *v, int bits, int d, int offset)
 
int xmmsv_bitbuffer_put_data (xmmsv_t *v, const unsigned char *b, int len)
 
int xmmsv_bitbuffer_align (xmmsv_t *v)
 
int xmmsv_bitbuffer_goto (xmmsv_t *v, int pos)
 
int xmmsv_bitbuffer_pos (xmmsv_t *v)
 
int xmmsv_bitbuffer_rewind (xmmsv_t *v)
 
int xmmsv_bitbuffer_end (xmmsv_t *v)
 
int xmmsv_bitbuffer_len (xmmsv_t *v)
 
const unsigned char * xmmsv_bitbuffer_buffer (xmmsv_t *v)
 

Variables

const char * default_source_pref []
 

Macro Definition Documentation

◆ GEN_DICT_EXTRACTOR_FUNC

#define GEN_DICT_EXTRACTOR_FUNC (   typename,
  type 
)
Value:
int \
xmmsv_dict_entry_get_##typename (xmmsv_t *val, const char *key, \
type *r) \
{ \
xmmsv_t *v; \
if (!xmmsv_dict_get (val, key, &v)) { \
return 0; \
} \
return xmmsv_get_##typename (v, r); \
}
struct xmmsv_St xmmsv_t
Definition: xmmsv_general.h:48
int xmmsv_dict_get(xmmsv_t *dictv, const char *key, xmmsv_t **val)
Get the element corresponding to the given key in the dict xmmsv_t (if it exists).
Definition: value.c:1717

Definition at line 521 of file value.c.

◆ GEN_DICT_ITER_EXTRACTOR_FUNC

#define GEN_DICT_ITER_EXTRACTOR_FUNC (   typename,
  type 
)
Value:
int \
xmmsv_dict_iter_pair_##typename (xmmsv_dict_iter_t *it, \
const char **key, \
type *r) \
{ \
xmmsv_t *v; \
if (!xmmsv_dict_iter_pair (it, key, &v)) { \
return 0; \
} \
if (r) { \
return xmmsv_get_##typename (v, r); \
} else { \
return 1; \
} \
}
int xmmsv_dict_iter_pair(xmmsv_dict_iter_t *it, const char **key, xmmsv_t **val)
Get the key-element pair currently pointed at by the iterator.
Definition: value.c:1948
struct xmmsv_dict_iter_St xmmsv_dict_iter_t
Definition: xmmsv_dict.h:59

Definition at line 557 of file value.c.

◆ GEN_DICT_ITER_SET_FUNC

#define GEN_DICT_ITER_SET_FUNC (   typename,
  type 
)
Value:
int \
xmmsv_dict_iter_set_##typename (xmmsv_dict_iter_t *it, type elem) \
{ \
int ret; \
xmmsv_t *v; \
\
v = xmmsv_new_##typename (elem); \
ret = xmmsv_dict_iter_set (it, v); \
xmmsv_unref (v); \
\
return ret; \
}
int xmmsv_dict_iter_set(xmmsv_dict_iter_t *it, xmmsv_t *val)
Replace the element of the pair currently pointed to by the iterator.
Definition: value.c:2101
struct xmmsv_dict_iter_St xmmsv_dict_iter_t
Definition: xmmsv_dict.h:59

Definition at line 579 of file value.c.

◆ GEN_DICT_SET_FUNC

#define GEN_DICT_SET_FUNC (   typename,
  type 
)
Value:
int \
xmmsv_dict_set_##typename (xmmsv_t *dict, const char *key, type elem) \
{ \
int ret; \
xmmsv_t *v; \
\
v = xmmsv_new_##typename (elem); \
ret = xmmsv_dict_set (dict, key, v); \
xmmsv_unref (v); \
\
return ret; \
}
int xmmsv_dict_set(xmmsv_t *dictv, const char *key, xmmsv_t *val)
Insert an element under the given key in the dict xmmsv_t.
Definition: value.c:1752
struct xmmsv_St xmmsv_t
Definition: xmmsv_general.h:48

Definition at line 538 of file value.c.

◆ GEN_LIST_APPEND_FUNC

#define GEN_LIST_APPEND_FUNC (   typename,
  type 
)
Value:
int \
xmmsv_list_append_##typename (xmmsv_t *list, type elem) \
{ \
int ret; \
xmmsv_t *v; \
\
v = xmmsv_new_##typename (elem); \
ret = xmmsv_list_append (list, v); \
xmmsv_unref (v); \
\
return ret; \
}
int xmmsv_list_append(xmmsv_t *listv, xmmsv_t *val)
Append an element to the end of the list xmmsv_t.
Definition: value.c:1340
struct xmmsv_St xmmsv_t
Definition: xmmsv_general.h:48

Definition at line 652 of file value.c.

◆ GEN_LIST_EXTRACTOR_FUNC

#define GEN_LIST_EXTRACTOR_FUNC (   typename,
  type 
)
Value:
int \
xmmsv_list_get_##typename (xmmsv_t *val, int pos, type *r) \
{ \
xmmsv_t *v; \
if (!xmmsv_list_get (val, pos, &v)) { \
return 0; \
} \
return xmmsv_get_##typename (v, r); \
}
struct xmmsv_St xmmsv_t
Definition: xmmsv_general.h:48
int xmmsv_list_get(xmmsv_t *listv, int pos, xmmsv_t **val)
Get the element at the given position in the list xmmsv_t.
Definition: value.c:1218

Definition at line 598 of file value.c.

◆ GEN_LIST_INSERT_FUNC

#define GEN_LIST_INSERT_FUNC (   typename,
  type 
)
Value:
int \
xmmsv_list_insert_##typename (xmmsv_t *list, int pos, type elem) \
{ \
int ret; \
xmmsv_t *v; \
\
v = xmmsv_new_##typename (elem); \
ret = xmmsv_list_insert (list, pos, v); \
xmmsv_unref (v); \
\
return ret; \
}
struct xmmsv_St xmmsv_t
Definition: xmmsv_general.h:48
int xmmsv_list_insert(xmmsv_t *listv, int pos, xmmsv_t *val)
Insert an element at the given position in the list xmmsv_t.
Definition: value.c:1282

Definition at line 633 of file value.c.

◆ GEN_LIST_ITER_EXTRACTOR_FUNC

#define GEN_LIST_ITER_EXTRACTOR_FUNC (   typename,
  type 
)
Value:
int \
xmmsv_list_iter_entry_##typename (xmmsv_list_iter_t *it, type *r) \
{ \
xmmsv_t *v; \
if (!xmmsv_list_iter_entry (it, &v)) { \
return 0; \
} \
return xmmsv_get_##typename (v, r); \
}
struct xmmsv_list_iter_St xmmsv_list_iter_t
Definition: xmmsv_list.h:69
int xmmsv_list_iter_entry(xmmsv_list_iter_t *it, xmmsv_t **val)
Get the element currently pointed at by the iterator.
Definition: value.c:1495

Definition at line 671 of file value.c.

◆ GEN_LIST_ITER_INSERT_FUNC

#define GEN_LIST_ITER_INSERT_FUNC (   typename,
  type 
)
Value:
int \
xmmsv_list_iter_insert_##typename (xmmsv_list_iter_t *it, type elem) \
{ \
int ret; \
xmmsv_t *v; \
\
v = xmmsv_new_##typename (elem); \
ret = xmmsv_list_iter_insert (it, v); \
xmmsv_unref (v); \
\
return ret; \
}
struct xmmsv_list_iter_St xmmsv_list_iter_t
Definition: xmmsv_list.h:69
int xmmsv_list_iter_insert(xmmsv_list_iter_t *it, xmmsv_t *val)
Insert an element in the list at the position pointed at by the iterator.
Definition: value.c:1636

Definition at line 687 of file value.c.

◆ GEN_LIST_SET_FUNC

#define GEN_LIST_SET_FUNC (   typename,
  type 
)
Value:
int \
xmmsv_list_set_##typename (xmmsv_t *list, int pos, type elem) \
{ \
int ret; \
xmmsv_t *v; \
\
v = xmmsv_new_##typename (elem); \
ret = xmmsv_list_set (list, pos, v); \
xmmsv_unref (v); \
\
return ret; \
}
struct xmmsv_St xmmsv_t
Definition: xmmsv_general.h:48
int xmmsv_list_set(xmmsv_t *listv, int pos, xmmsv_t *val)
Set the element at the given position in the list xmmsv_t.
Definition: value.c:1249

Definition at line 614 of file value.c.

Typedef Documentation

◆ xmmsv_bin_t

typedef struct xmmsv_bin_St xmmsv_bin_t

◆ xmmsv_dict_t

typedef struct xmmsv_dict_St xmmsv_dict_t

Definition at line 47 of file value.c.

◆ xmmsv_list_t

typedef struct xmmsv_list_St xmmsv_list_t

Definition at line 46 of file value.c.

Variable Documentation

◆ default_source_pref

const char* default_source_pref[]
Initial value:
= {
"server",
"client/*",
"plugin/playlist",
"plugin/id3v2",
"plugin/segment",
"plugin/*",
"*",
NULL
}

Definition at line 34 of file value.c.

Referenced by xmmsv_propdict_to_dict().