From c3b9d7e802d7d2e31131692d621515ac88178ebb Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Mon, 16 Dec 2024 14:51:10 -0500 Subject: lib9p: Split lib9p_{validate,unmarshal,marshal} into _Tmsg and _Rmsg variants --- lib9p/srv.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'lib9p/srv.c') diff --git a/lib9p/srv.c b/lib9p/srv.c index 3535f9a..f98db67 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -1,6 +1,6 @@ /* lib9p/srv.c - 9P server * - * Copyright (C) 2024 Luke T. Shumaker + * Copyright (C) 2024-2025 Luke T. Shumaker * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -116,9 +116,9 @@ static uint32_t rerror_overhead_for_version(enum lib9p_version version, struct lib9p_msg_Rerror empty_error = { 0 }; bool e; - e = lib9p_marshal(&empty_ctx, LIB9P_TYP_Rerror, - &empty_error, /* host_body */ - scratch); /* net_bytes */ + e = lib9p_Rmsg_marshal(&empty_ctx, LIB9P_TYP_Rerror, + &empty_error, /* host_body */ + scratch); /* net_bytes */ assert(!e); uint32_t min_msg_size = decode_u32le(scratch); @@ -162,8 +162,8 @@ static void respond_error(struct _lib9p_srv_req *req) { if (((uint32_t)host.ename.len) + sess->rerror_overhead > sess->max_msg_size) host.ename.len = sess->max_msg_size - sess->rerror_overhead; - lib9p_marshal(&req->ctx.basectx, LIB9P_TYP_Rerror, - &host, req->net_bytes); + lib9p_Rmsg_marshal(&req->ctx.basectx, LIB9P_TYP_Rerror, + &host, req->net_bytes); cr_mutex_lock(&sess->parent_conn->writelock); r = VCALL(sess->parent_conn->fd, write, @@ -369,14 +369,7 @@ static void handle_message(struct _lib9p_srv_req *ctx) { uint8_t host_resp[CONFIG_9P_MAX_HOSTMSG_SIZE]; /* Unmarshal it. */ - enum lib9p_msg_type typ = ctx->net_bytes[4]; - if (typ % 2 != 0) { - lib9p_errorf(&ctx->ctx.basectx, - LINUX_EOPNOTSUPP, "expected a T-message but got an R-message: message_type=%s", - lib9p_msg_type_str(&ctx->ctx.basectx, typ)); - goto write; - } - ssize_t host_size = lib9p_validate(&ctx->ctx.basectx, ctx->net_bytes); + ssize_t host_size = lib9p_Tmsg_validate(&ctx->ctx.basectx, ctx->net_bytes); if (host_size < 0) goto write; if ((size_t)host_size > sizeof(host_req)) { @@ -385,7 +378,8 @@ static void handle_message(struct _lib9p_srv_req *ctx) { host_size, sizeof(host_req)); goto write; } - lib9p_unmarshal(&ctx->ctx.basectx, ctx->net_bytes, + enum lib9p_msg_type typ; + lib9p_Tmsg_unmarshal(&ctx->ctx.basectx, ctx->net_bytes, &typ, host_req); /* Handle it. */ @@ -395,8 +389,8 @@ static void handle_message(struct _lib9p_srv_req *ctx) { if (lib9p_ctx_has_error(&ctx->ctx.basectx)) respond_error(ctx); else { - if (lib9p_marshal(&ctx->ctx.basectx, typ+1, host_resp, - ctx->net_bytes)) + if (lib9p_Rmsg_marshal(&ctx->ctx.basectx, typ+1, host_resp, + ctx->net_bytes)) goto write; cr_mutex_lock(&ctx->parent_sess->parent_conn->writelock); -- cgit v1.2.3-2-g168b