summaryrefslogtreecommitdiff
path: root/lib9p/internal.h
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-09-27 17:25:36 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-09-27 17:25:36 -0600
commite5e15c04bc58c34906e6d7cfcbad68d1a5617563 (patch)
tree580f5fb0fafc7e974c969fc8aae229205c836195 /lib9p/internal.h
parent71e1a86a033c380f85dd300d788af63bfef25bab (diff)
wip
Diffstat (limited to 'lib9p/internal.h')
-rw-r--r--lib9p/internal.h79
1 files changed, 52 insertions, 27 deletions
diff --git a/lib9p/internal.h b/lib9p/internal.h
index 61977d4..ebdc3f3 100644
--- a/lib9p/internal.h
+++ b/lib9p/internal.h
@@ -1,21 +1,20 @@
-/* 9p/internal.h - TODO
+/* lib9p/internal.h - TODO
*
* Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
* SPDX-Licence-Identifier: AGPL-3.0-or-later
*/
-#ifndef _9P_INTERNAL_H_
-#define _9P_INTERNAL_H_
+#ifndef _LIB9P_INTERNAL_H_
+#define _LIB9P_INTERNAL_H_
#include <assert.h>
-#include <stdint.h>
#include <stdbool.h>
-#include "9p/defs.h"
+#include <lib9p/9p.h>
-#define USE_CONFIG_9P
+#define USE_CONFIG_LIB9P
#include "config.h"
-static_assert(CONFIG_9P_MAX_ERR_SIZE <= UINT16_MAX);
+static_assert(CONFIG_LIB9P_MAX_ERR_SIZE <= UINT16_MAX);
/* C language *****************************************************************/
@@ -23,39 +22,65 @@ static_assert(CONFIG_9P_MAX_ERR_SIZE <= UINT16_MAX);
/* types **********************************************************************/
-struct p9_ctx {
- enum p9_version version;
- uint32_t max_msg_size;
- uint32_t Rerror_overhead;
+/* NB: We declare this here instead of in the public <lib9p/9p.h>
+ * because we don't want to include "config.h" from public headers,
+ * and I want the MAX_ERR_SIZE to be configurable. */
+struct lib9p_ctx {
+ /* negotiated */
+ enum lib9p_version version;
+ uint32_t max_msg_size;
+ /* negotiated (server) */
+ uint32_t Rerror_overhead;
+
+ /* state */
+ uint32_t err_num;
+ char err_msg[CONFIG_LIB9P_MAX_ERR_SIZE];
+};
+
+/* vtables ********************************************************************/
- uint32_t err_num;
- char err_msg[CONFIG_9P_MAX_ERR_SIZE];
+struct _checksize_ctx {
+ struct lib9p_ctx *ctx;
+ uint32_t net_size;
+ uint8_t net_bytes;
+
+ uint32_t net_offset;
+ /* Increment `host_extra` to pre-allocate space that is
+ * "extra" beyond sizeof(). */
+ size_t host_extra;
};
-static inline enum p9_version p9_ctx_version(p9_ctx *ctx) {
- assert(ctx);
- return ctx->version;
-}
+struct _unmarshal_ctx {
+ struct lib9p_ctx *ctx;
-/* vtables ********************************************************************/
+ uint32_t net_offset;
+ /* `extra` points to the beginning of unallocated space. */
+ void *extra;
+};
+
+struct _marshal_ctx {
+ struct lib9p_ctx *ctx;
+
+ uint8_t *net_bytes;
+ uint32_t net_offset;
+};
-typedef bool (*_checksize_fn_t)(uint32_t net_len, uint8_t *net_bytes, uint32_t *mut_net_offset, size_t *mut_host_extra);
-typedef bool (*_unmarshal_fn_t)(uint8_t *net_bytes, uint32_t *mut_net_offset, void **mut_host_extra, void *out);
-typedef bool (*_marshal_fn_t)(struct p9_ctx *ctx, void *val, uint8_t *out_net_bytes, uint32_t *mut_net_offset);
+typedef bool (*_checksize_fn_t)(struct _checksize_ctx *ctx);
+typedef void (*_unmarshal_fn_t)(struct _unmarshal_ctx *ctx, void *out);
+typedef bool (*_marshal_fn_t)(struct _marshal_ctx *ctx, void *host_val);
-struct msg_vtable {
+struct _vtable_msg {
size_t unmarshal_basesize;
_checksize_fn_t unmarshal_extrasize;
_unmarshal_fn_t unmarshal;
_marshal_fn_t marshal;
};
-struct version {
- struct msg_vtable msgs[0xFF];
+struct _vtable_version {
+ struct _vtable_msg msgs[0xFF];
};
-extern struct version version_9P2000;
-/*extern struct version version_9P2000u; */
+extern struct _vtable_version _lib9p_vtables[LIB9P_VER_NUM];
/* unmarshal utilities ********************************************************/
@@ -136,4 +161,4 @@ static inline void encode_u64le(uint64_t in, uint8_t *out) {
out[7] = (uint8_t)((in >> 56) & 0xFF);
}
-#endif /* _9P_INTERNAL_H_ */
+#endif /* _LIB9P_INTERNAL_H_ */