obj: object header is no longer allocated automatically

This commit is contained in:
2023-05-06 19:48:14 +01:00
parent 79c30e5393
commit f52ca2f1e2
13 changed files with 97 additions and 66 deletions

View File

@@ -1,9 +1,13 @@
#include <socks/object.h>
#define NAMESPACE_CAST(p) OBJECT_C_CAST(struct object_namespace, ns_base, &ns_type, p)
static struct object_type ns_type;
static struct object_namespace *global_ns;
struct object_namespace {
/* root directory set object */
struct object ns_base;
struct object *ns_root;
};
@@ -16,13 +20,13 @@ static kern_status_t ns_query_name(struct object *obj, char out[OBJECT_NAME_MAX]
static kern_status_t ns_get_child_at(struct object *obj, size_t at, struct object **out)
{
struct object_namespace *ns = object_data(obj);
struct object_namespace *ns = NAMESPACE_CAST(obj);
return object_get_child_at(ns->ns_root, at, out);
}
static kern_status_t ns_get_child_named(struct object *obj, const char *name, struct object **out)
{
struct object_namespace *ns = object_data(obj);
struct object_namespace *ns = NAMESPACE_CAST(obj);
return object_get_child_named(ns->ns_root, name, out);
}
@@ -36,7 +40,6 @@ static struct object_type ns_type = {
},
};
void init_global_namespace(void)
{
object_type_register(&ns_type);
@@ -51,7 +54,7 @@ struct object_namespace *global_namespace(void)
struct object_namespace *object_namespace_create(void)
{
struct object *ns_object = object_create(&ns_type);
struct object_namespace *ns = object_data(ns_object);
struct object_namespace *ns = NAMESPACE_CAST(ns_object);
ns->ns_root = set_create("/");
return ns;
}
@@ -93,6 +96,11 @@ static void cleanup_object_path(char *path, size_t len, size_t *parts)
path[final_len] = 0;
}
struct object *ns_header(struct object_namespace *ns)
{
return &ns->ns_base;
}
kern_status_t object_publish(struct object_namespace *ns, const char *path, struct object *obj)
{
if (*path != '/') {