1 #include <libubox/avl.h>
2 #include <libubox/avl-cmp.h>
6 __blobmsg_list_init(struct blobmsg_list *list, int offset, int len, blobmsg_list_cmp cmp)
8 avl_init(&list->avl, avl_strcmp, false, NULL);
9 list->node_offset = offset;
15 blobmsg_list_fill(struct blobmsg_list *list, void *data, int len, bool array)
17 struct avl_tree *tree = &list->avl;
18 struct blobmsg_list_node *node;
19 struct blob_attr *cur;
24 __blob_for_each_attr(cur, data, rem) {
25 if (!blobmsg_check_attr(cur, !array))
28 ptr = calloc(1, list->node_len);
32 node = (void *) ((char *)ptr + list->node_offset);
34 node->avl.key = blobmsg_data(cur);
36 node->avl.key = blobmsg_name(cur);
38 if (avl_insert(tree, &node->avl)) {
50 blobmsg_list_move(struct blobmsg_list *list, struct blobmsg_list *src)
52 struct blobmsg_list_node *node, *tmp;
55 avl_remove_all_elements(&src->avl, node, avl, tmp) {
56 if (avl_insert(&list->avl, &node->avl)) {
57 ptr = ((char *) node - list->node_offset);
64 blobmsg_list_free(struct blobmsg_list *list)
66 struct blobmsg_list_node *node, *tmp;
69 avl_remove_all_elements(&list->avl, node, avl, tmp) {
70 ptr = ((char *) node - list->node_offset);
76 blobmsg_list_equal(struct blobmsg_list *l1, struct blobmsg_list *l2)
78 struct blobmsg_list_node *n1, *n2;
79 int count = l1->avl.count;
81 if (count != l2->avl.count)
84 n1 = avl_first_element(&l1->avl, n1, avl);
85 n2 = avl_first_element(&l2->avl, n2, avl);
90 len = blob_len(n1->data);
91 if (len != blob_len(n2->data))
94 if (memcmp(n1->data, n2->data, len) != 0)
97 if (l1->cmp && !l1->cmp(n1, n2))
103 n1 = avl_next_element(n1, avl);
104 n2 = avl_next_element(n2, avl);