obj->type = type;
INIT_LIST_HEAD(&obj->list);
- type->refcount++;
+ INIT_LIST_HEAD(&obj->events);
+ if (type)
+ type->refcount++;
return obj;
struct ubus_object_type *type = NULL;
if (attr[UBUS_ATTR_OBJTYPE])
- type = ubus_get_obj_type(blob_get_int32(attr[UBUS_ATTR_OBJTYPE]));
+ type = ubus_get_obj_type(blob_get_u32(attr[UBUS_ATTR_OBJTYPE]));
else if (attr[UBUS_ATTR_SIGNATURE])
type = ubus_create_obj_type(attr[UBUS_ATTR_SIGNATURE]);
- if (!type)
+ if (!!type ^ !!attr[UBUS_ATTR_OBJPATH])
return NULL;
obj = ubusd_create_object_internal(type, 0);
- ubus_unref_object_type(type);
+ if (type)
+ ubus_unref_object_type(type);
if (!obj)
return NULL;
obj->client = cl;
list_add(&obj->list, &cl->objects);
+
return obj;
free:
void ubusd_free_object(struct ubus_object *obj)
{
+ ubusd_event_cleanup_object(obj);
if (obj->path.key) {
avl_delete(&path, &obj->path);
free(obj->path.key);
if (!list_empty(&obj->list))
list_del(&obj->list);
ubus_free_id(&objects, &obj->id);
- ubus_unref_object_type(obj->type);
+ if (obj->type)
+ ubus_unref_object_type(obj->type);
free(obj);
}
-static int ubus_cmp_path(const void *k1, const void *k2, void *ptr)
-{
- return strcmp(k1, k2);
-}
-
static void __init ubusd_obj_init(void)
{
ubus_init_id_tree(&objects);
ubus_init_id_tree(&obj_types);
- avl_init(&path, ubus_cmp_path, false, NULL);
+ ubus_init_string_tree(&path, false);
+ ubusd_event_init();
}