projects
/
project
/
ubus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
do not reverse method sorting order
[project/ubus.git]
/
ubusd_id.c
diff --git
a/ubusd_id.c
b/ubusd_id.c
index
9443db9
..
a9cfeae
100644
(file)
--- a/
ubusd_id.c
+++ b/
ubusd_id.c
@@
-3,6
+3,7
@@
#include <unistd.h>
#include <fcntl.h>
#include <unistd.h>
#include <fcntl.h>
+#include "ubusmsg.h"
#include "ubusd_id.h"
static int random_fd = -1;
#include "ubusd_id.h"
static int random_fd = -1;
@@
-17,6
+18,16
@@
static int ubus_cmp_id(const void *k1, const void *k2, void *ptr)
return *id1 > *id2;
}
return *id1 > *id2;
}
+static int ubus_cmp_str(const void *k1, const void *k2, void *ptr)
+{
+ return strcmp(k1, k2);
+}
+
+void ubus_init_string_tree(struct avl_tree *tree, bool dup)
+{
+ avl_init(tree, ubus_cmp_str, dup, NULL);
+}
+
void ubus_init_id_tree(struct avl_tree *tree)
{
if (random_fd < 0) {
void ubus_init_id_tree(struct avl_tree *tree)
{
if (random_fd < 0) {
@@
-30,14
+41,19
@@
void ubus_init_id_tree(struct avl_tree *tree)
avl_init(tree, ubus_cmp_id, false, NULL);
}
avl_init(tree, ubus_cmp_id, false, NULL);
}
-bool ubus_alloc_id(struct avl_tree *tree, struct ubus_id *id)
+bool ubus_alloc_id(struct avl_tree *tree, struct ubus_id *id
, uint32_t val
)
{
id->avl.key = &id->id;
{
id->avl.key = &id->id;
+ if (val) {
+ id->id = val;
+ return avl_insert(tree, &id->avl) == 0;
+ }
+
do {
if (read(random_fd, &id->id, sizeof(id->id)) != sizeof(id->id))
return false;
do {
if (read(random_fd, &id->id, sizeof(id->id)) != sizeof(id->id))
return false;
- if (
!id->id
)
+ if (
id->id < UBUS_SYSTEM_OBJECT_MAX
)
continue;
} while (avl_insert(tree, &id->avl) != 0);
continue;
} while (avl_insert(tree, &id->avl) != 0);