diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-12-26 18:01:31 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-01-11 23:34:14 -0700 |
commit | cd64085694c7c4aa96312e88905015eea4d8b63d (patch) | |
tree | 2cabaaafe3a0f5a24b8145b87031ff3d8dd3ed9c /lib9p/9p.c | |
parent | 7eda822ef31a15d22de03fc1eec7d995f661b26d (diff) |
lib9p: Split the generated tables up
Diffstat (limited to 'lib9p/9p.c')
-rw-r--r-- | lib9p/9p.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -1,6 +1,6 @@ /* lib9p/9p.c - Base 9P protocol utilities for both clients and servers * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -9,6 +9,9 @@ #include <stdio.h> /* for vsnprintf() */ #include <string.h> /* for strncpy() */ +#define LOG_NAME 9P +#include <libmisc/log.h> /* for const_byte_str() */ + #include <lib9p/9p.h> #include "internal.h" @@ -69,7 +72,7 @@ const char *lib9p_msg_type_str(struct lib9p_ctx *ctx, enum lib9p_msg_type typ) { #pragma GCC diagnostic ignored "-Wtype-limits" assert(0 <= typ && typ <= 0xFF); #pragma GCC diagnostic pop - return _lib9p_versions[ctx->version].msgs[typ].name; + return _lib9p_table_msg_name[ctx->version][typ] ?: const_byte_str(typ); } /* main message functions *****************************************************/ @@ -87,7 +90,7 @@ ssize_t lib9p_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes) { if (subctx.net_size < 5) return lib9p_error(ctx, LINUX_EBADMSG, "message is impossibly short"); uint8_t typ = net_bytes[4]; - struct _table_msg table = _lib9p_versions[ctx->version].msgs[typ]; + struct _lib9p_recv_tentry table = ((typ % 2 == 0) ? _lib9p_table_Tmsg_recv : _lib9p_table_Rmsg_recv)[ctx->version][typ/2]; if (!table.validate) return lib9p_errorf(ctx, LINUX_EOPNOTSUPP, "unknown message type: %s (protocol_version=%s)", lib9p_msg_type_str(ctx, typ), lib9p_version_str(ctx->version)); @@ -116,8 +119,9 @@ void lib9p_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, .net_offset = 0, }; - *ret_typ = net_bytes[4]; - struct _table_msg table = _lib9p_versions[ctx->version].msgs[*ret_typ]; + enum lib9p_msg_type typ = net_bytes[4]; + *ret_typ = typ; + struct _lib9p_recv_tentry table = ((typ % 2 == 0) ? _lib9p_table_Tmsg_recv : _lib9p_table_Rmsg_recv)[ctx->version][typ/2]; subctx.extra = ret_body + table.basesize; table.unmarshal(&subctx, ret_body); } @@ -130,7 +134,7 @@ bool lib9p_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, .net_offset = 0, }; - struct _table_msg table = _lib9p_versions[ctx->version].msgs[typ]; + struct _lib9p_send_tentry table = ((typ % 2 == 0) ? _lib9p_table_Tmsg_send : _lib9p_table_Rmsg_send)[ctx->version][typ/2]; return table.marshal(&subctx, body); } |