22 #include "xmmsclientpriv/xmmsclient_util.h" 24 static bool _internal_put_on_bb_bin (
xmmsv_t *bb,
const unsigned char *data,
unsigned int len);
25 static bool _internal_put_on_bb_error (
xmmsv_t *bb,
const char *errmsg);
26 static bool _internal_put_on_bb_int32 (
xmmsv_t *bb, int32_t v);
27 static bool _internal_put_on_bb_string (
xmmsv_t *bb,
const char *str);
29 static bool _internal_put_on_bb_value_list (
xmmsv_t *bb,
xmmsv_t *v);
30 static bool _internal_put_on_bb_value_dict (
xmmsv_t *bb,
xmmsv_t *v);
32 static bool _internal_get_from_bb_error_alloc (
xmmsv_t *bb,
char **buf,
unsigned int *len);
33 static bool _internal_get_from_bb_int32 (
xmmsv_t *bb, int32_t *v);
34 static bool _internal_get_from_bb_int32_positive (
xmmsv_t *bb, int32_t *v);
35 static bool _internal_get_from_bb_string_alloc (
xmmsv_t *bb,
char **buf,
unsigned int *len);
37 static bool _internal_get_from_bb_bin_alloc (
xmmsv_t *bb,
unsigned char **buf,
unsigned int *len);
43 _internal_put_on_bb_append_coll_attr (
const char *key,
xmmsv_t *value,
void *userdata)
52 _internal_put_on_bb_string (bb, key);
53 _internal_put_on_bb_string (bb, s);
57 _internal_put_on_bb_count_coll_attr (
const char *key,
xmmsv_t *value,
void *userdata)
59 int *n = (
int *)userdata;
64 _internal_put_on_bb_bin (
xmmsv_t *bb,
65 const unsigned char *data,
75 _internal_put_on_bb_error (
xmmsv_t *bb,
const char *errmsg)
92 _internal_put_on_bb_int32 (
xmmsv_t *bb, int32_t v)
98 _internal_put_on_bb_string (
xmmsv_t *bb,
const char *str)
154 x_api_error (
"Non integer in idlist", 0);
174 x_api_error (
"Non collection operand", 0);
179 ret = _internal_put_on_bb_collection (bb, op);
192 uint32_t offset, count;
223 uint32_t ret, offset, count;
236 ret = _internal_put_on_bb_string (bb, key);
249 _internal_get_from_bb_data (
xmmsv_t *bb,
void *buf,
unsigned int len)
258 _internal_get_from_bb_error_alloc (
xmmsv_t *bb,
char **buf,
262 return _internal_get_from_bb_string_alloc (bb, buf, len);
266 _internal_get_from_bb_int32 (
xmmsv_t *bb, int32_t *v)
272 _internal_get_from_bb_int32_positive (
xmmsv_t *bb, int32_t *v)
275 ret = _internal_get_from_bb_int32 (bb, v);
281 _internal_get_from_bb_string_alloc (
xmmsv_t *bb,
char **buf,
287 if (!_internal_get_from_bb_int32_positive (bb, &l)) {
296 if (!_internal_get_from_bb_data (bb, str, l)) {
310 _internal_get_from_bb_bin_alloc (
xmmsv_t *bb,
317 if (!_internal_get_from_bb_int32_positive (bb, &l)) {
326 if (!_internal_get_from_bb_data (bb, b, l)) {
344 int32_t *idlist = NULL;
348 if (!_internal_get_from_bb_int32_positive (bb, &type)) {
355 if (!_internal_get_from_bb_int32_positive (bb, &n_items)) {
359 for (i = 0; i < n_items; i++) {
361 if (!_internal_get_from_bb_string_alloc (bb, &key, &len)) {
364 if (!_internal_get_from_bb_string_alloc (bb, &val, &len)) {
375 if (!_internal_get_from_bb_int32_positive (bb, &n_items)) {
379 if (!(idlist =
x_new (int32_t, n_items + 1))) {
383 for (i = 0; i < n_items; i++) {
384 if (!_internal_get_from_bb_int32 (bb, &
id)) {
397 if (!_internal_get_from_bb_int32_positive (bb, &n_items)) {
401 for (i = 0; i < n_items; i++) {
404 if (!_internal_get_from_bb_int32_positive (bb, &type) ||
406 !_internal_get_from_bb_collection_alloc (bb, &operand)) {
417 if (idlist != NULL) {
437 if (!_internal_get_from_bb_int32_positive (bb, &len)) {
444 if (!_internal_get_from_bb_string_alloc (bb, &key, &ignore)) {
463 x_internal_error (
"Message from server did not parse correctly!");
476 if (!_internal_get_from_bb_int32_positive (bb, &len)) {
495 x_internal_error (
"Message from server did not parse correctly!");
512 if (!_internal_get_from_bb_error_alloc (bb, &s, &len)) {
519 if (!_internal_get_from_bb_int32 (bb, &i)) {
525 if (!_internal_get_from_bb_string_alloc (bb, &s, &len)) {
532 if (!xmmsc_deserialize_dict (bb, val)) {
538 if (!xmmsc_deserialize_list (bb, val)) {
544 if (!_internal_get_from_bb_collection_alloc (bb, &c)) {
552 if (!_internal_get_from_bb_bin_alloc (bb, &d, &len)) {
563 x_internal_error (
"Got message of unknown type!");
579 const unsigned char *bc;
584 ret = _internal_put_on_bb_int32 (bb, type);
593 ret = _internal_put_on_bb_error (bb, s);
599 ret = _internal_put_on_bb_int32 (bb, i);
605 ret = _internal_put_on_bb_string (bb, s);
611 ret = _internal_put_on_bb_collection (bb, c);
617 ret = _internal_put_on_bb_bin (bb, bc, bl);
620 ret = _internal_put_on_bb_value_list (bb, v);
623 ret = _internal_put_on_bb_value_dict (bb, v);
629 x_internal_error (
"Tried to serialize value of unsupported type");
641 if (!_internal_get_from_bb_int32 (bb, &type)) {
645 return _internal_get_from_bb_value_of_type_alloc (bb, type, val);
677 const unsigned char *data;
void xmmsv_list_iter_first(xmmsv_list_iter_t *it)
Rewind the iterator to the start of the list.
xmmsv_t * xmmsv_bitbuffer_new_ro(const unsigned char *v, int len)
struct xmmsv_list_iter_St xmmsv_list_iter_t
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.
void xmmsv_unref(xmmsv_t *val)
Decreases the references for the xmmsv_t When the number of references reaches 0 it will be freed...
int xmmsv_list_append(xmmsv_t *listv, xmmsv_t *val)
Append an element to the end of the list xmmsv_t.
xmmsv_t * xmmsv_new_error(const char *errstr)
Allocates a new error xmmsv_t.
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.
xmmsv_t * xmmsv_new_none(void)
Allocates a new empty xmmsv_t.
void xmmsv_coll_attribute_set(xmmsv_coll_t *coll, const char *key, const char *value)
Set an attribute in the given collection.
xmmsv_t * xmmsv_new_string(const char *s)
Allocates a new string xmmsv_t.
xmmsv_t * xmmsv_deserialize(xmmsv_t *v)
int xmmsv_get_int(const xmmsv_t *val, int32_t *r)
Retrieves a signed integer from the value.
int xmmsv_get_list_iter(const xmmsv_t *val, xmmsv_list_iter_t **it)
Retrieves a list iterator from a list xmmsv_t.
int xmmsv_bitbuffer_get_data(xmmsv_t *v, unsigned char *b, int len)
void xmmsv_dict_iter_next(xmmsv_dict_iter_t *it)
Advance the iterator to the next pair in the dict.
xmmsv_t * xmmsv_new_dict(void)
Allocates a new dict xmmsv_t.
struct xmmsv_St * xmmsv_coll_operands_get(xmmsv_coll_t *coll)
size_t xmmsv_coll_idlist_get_size(xmmsv_coll_t *coll)
Get the size of the idlist.
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.
int xmmsv_dict_iter_valid(xmmsv_dict_iter_t *it)
Check whether the iterator is valid and points to a valid pair.
struct xmmsv_St * xmmsv_coll_idlist_get(xmmsv_coll_t *coll)
Return the list of ids stored in the collection.
int xmmsv_bitbuffer_pos(xmmsv_t *v)
void xmmsv_list_iter_next(xmmsv_list_iter_t *it)
Advance the iterator to the next element in the list.
const unsigned char * xmmsv_bitbuffer_buffer(xmmsv_t *v)
xmmsv_t * xmmsv_new_list(void)
Allocates a new list xmmsv_t.
void xmmsv_list_iter_explicit_destroy(xmmsv_list_iter_t *it)
Explicitly free list iterator.
struct xmmsv_coll_St xmmsv_coll_t
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)
xmmsv_t * xmmsv_serialize(xmmsv_t *v)
int xmmsv_bitbuffer_deserialize_value(xmmsv_t *bb, xmmsv_t **val)
xmmsv_t * xmmsv_new_coll(xmmsv_coll_t *coll)
Allocates a new collection xmmsv_t.
xmmsv_coll_t * xmmsv_coll_new(xmmsv_coll_type_t type)
Allocate a new collection of the given type.
int xmmsv_bitbuffer_len(xmmsv_t *v)
xmmsv_type_t xmmsv_get_type(const xmmsv_t *val)
Get the type of the value.
xmmsv_t * xmmsv_new_int(int32_t i)
Allocates a new integer xmmsv_t.
struct xmmsv_St * xmmsv_coll_attributes_get(xmmsv_coll_t *coll)
void xmmsv_coll_add_operand(xmmsv_coll_t *coll, xmmsv_coll_t *op)
Add the operand to the given collection.
int xmmsv_list_get_size(xmmsv_t *listv)
Return the size of the list.
void xmmsv_coll_set_idlist(xmmsv_coll_t *coll, int ids[])
Set the list of ids in the given collection.
int xmmsv_get_error(const xmmsv_t *val, const char **r)
Retrieves an error string describing the server error from the value.
int xmmsv_bitbuffer_serialize_value(xmmsv_t *bb, xmmsv_t *v)
int xmmsv_get_bin(const xmmsv_t *val, const unsigned char **r, unsigned int *rlen)
Retrieves binary data from the value.
int xmmsv_bitbuffer_put_data(xmmsv_t *v, const unsigned char *b, int len)
#define x_return_if_fail(expr)
int xmmsv_list_iter_valid(xmmsv_list_iter_t *it)
Check whether the iterator is valid and points to a valid element.
int xmmsv_get_string(const xmmsv_t *val, const char **r)
Retrieves a string from the value.
int xmmsv_bitbuffer_get_bits(xmmsv_t *v, int bits, int *res)
int xmmsv_list_iter_entry(xmmsv_list_iter_t *it, xmmsv_t **val)
Get the element currently pointed at by the iterator.
struct xmmsv_dict_iter_St xmmsv_dict_iter_t
int xmmsv_list_iter_entry_int(xmmsv_list_iter_t *it, int32_t *val)
xmmsv_t * xmmsv_new_bin(const unsigned char *data, unsigned int len)
Allocates a new binary data xmmsv_t.
int xmmsv_get_dict_iter(const xmmsv_t *val, xmmsv_dict_iter_t **it)
Retrieves a dict iterator from a dict xmmsv_t.
xmmsv_coll_type_t xmmsv_coll_get_type(xmmsv_coll_t *coll)
Return the type of the collection.
int xmmsv_get_coll(const xmmsv_t *val, xmmsv_coll_t **coll)
Retrieves a collection from the value.
xmmsv_t * xmmsv_bitbuffer_new(void)
void xmmsv_coll_unref(xmmsv_coll_t *coll)
Decreases the references for the xmmsv_coll_t When the number of references reaches 0 it will be free...