1 #include <libubox/avl.h>
2 #include <libubox/avl-cmp.h>
6 __blobmsg_list_init(struct blobmsg_list
*list
, int offset
, int len
)
8 avl_init(&list
->avl
, avl_strcmp
, false, NULL
);
9 list
->node_offset
= offset
;
14 blobmsg_list_fill(struct blobmsg_list
*list
, void *data
, int len
)
16 struct avl_tree
*tree
= &list
->avl
;
17 struct blobmsg_list_node
*node
;
18 struct blob_attr
*cur
;
23 __blob_for_each_attr(cur
, data
, rem
) {
24 if (!blobmsg_check_attr(cur
, true))
27 ptr
= calloc(1, list
->node_len
);
31 node
= (void *) ((char *)ptr
+ list
->node_offset
);
32 node
->avl
.key
= blobmsg_name(cur
);
34 if (avl_insert(tree
, &node
->avl
)) {
46 blobmsg_list_move(struct blobmsg_list
*list
, struct blobmsg_list
*src
)
48 struct blobmsg_list_node
*node
, *tmp
;
51 avl_remove_all_elements(&src
->avl
, node
, avl
, tmp
) {
52 if (!avl_insert(&list
->avl
, &node
->avl
)) {
53 ptr
= ((char *) node
- list
->node_offset
);
60 blobmsg_list_free(struct blobmsg_list
*list
)
62 struct blobmsg_list_node
*node
, *tmp
;
65 avl_remove_all_elements(&list
->avl
, node
, avl
, tmp
) {
66 ptr
= ((char *) node
- list
->node_offset
);
72 blobmsg_list_equal(struct blobmsg_list
*l1
, struct blobmsg_list
*l2
)
74 struct blobmsg_list_node
*n1
, *n2
;
75 int count
= l1
->avl
.count
;
77 if (count
!= l2
->avl
.count
)
80 n1
= avl_first_element(&l1
->avl
, n1
, avl
);
81 n2
= avl_first_element(&l2
->avl
, n2
, avl
);
86 len
= blob_len(n1
->data
);
87 if (len
!= blob_len(n2
->data
))
90 if (memcmp(n1
->data
, n2
->data
, len
) != 0)
96 n1
= avl_next_element(n1
, avl
);
97 n2
= avl_next_element(n2
, avl
);