2 * kvlist - simple key/value store
4 * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #ifndef __LIBUBOX_KVLIST_H
19 #define __LIBUBOX_KVLIST_H
26 int (*get_len
)(struct kvlist
*kv
, const void *data
);
32 char data
[0] __attribute__((aligned(4)));
35 #define __ptr_to_kv(_ptr) container_of(((char *) (_ptr)), struct kvlist_node, data[0])
36 #define __avl_list_to_kv(_l) container_of(_l, struct kvlist_node, avl.list)
38 #define kvlist_for_each(kv, name, value) \
39 for (value = (void *) __avl_list_to_kv((kv)->avl.list_head.next)->data, \
40 name = (const char *) __ptr_to_kv(value)->avl.key, (void) name; \
41 &__ptr_to_kv(value)->avl.list != &(kv)->avl.list_head; \
42 value = (void *) (__avl_list_to_kv(__ptr_to_kv(value)->avl.list.next))->data, \
43 name = (const char *) __ptr_to_kv(value)->avl.key)
45 void kvlist_init(struct kvlist
*kv
, int (*get_len
)(struct kvlist
*kv
, const void *data
));
46 void kvlist_free(struct kvlist
*kv
);
47 void *kvlist_get(struct kvlist
*kv
, const char *name
);
48 void kvlist_set(struct kvlist
*kv
, const char *name
, const void *data
);
49 bool kvlist_delete(struct kvlist
*kv
, const char *name
);
51 int kvlist_strlen(struct kvlist
*kv
, const void *data
);
52 int kvlist_blob_len(struct kvlist
*kv
, const void *data
);