ubusd: remove a faulty and redundant check
[project/ubus.git] / ubusd_id.h
1 /*
2 * Copyright (C) 2011 Felix Fietkau <nbd@openwrt.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2.1
6 * as published by the Free Software Foundation
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14 #ifndef __UBUSD_ID_H
15 #define __UBUSD_ID_H
16
17 #include <libubox/avl.h>
18 #include <stdint.h>
19
20 struct ubus_id {
21 struct avl_node avl;
22 uint32_t id;
23 };
24
25 void ubus_init_id_tree(struct avl_tree *tree);
26 void ubus_init_string_tree(struct avl_tree *tree, bool dup);
27 bool ubus_alloc_id(struct avl_tree *tree, struct ubus_id *id, uint32_t val);
28
29 static inline void ubus_free_id(struct avl_tree *tree, struct ubus_id *id)
30 {
31 avl_delete(tree, &id->avl);
32 }
33
34 static inline struct ubus_id *ubus_find_id(struct avl_tree *tree, uint32_t id)
35 {
36 struct avl_node *avl;
37
38 avl = avl_find(tree, &id);
39 if (!avl)
40 return NULL;
41
42 return container_of(avl, struct ubus_id, avl);
43 }
44
45 #endif