summaryrefslogtreecommitdiff
path: root/lib9p/9p.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p/9p.c')
-rw-r--r--lib9p/9p.c70
1 files changed, 16 insertions, 54 deletions
diff --git a/lib9p/9p.c b/lib9p/9p.c
index 78d23a0..c11bcd6 100644
--- a/lib9p/9p.c
+++ b/lib9p/9p.c
@@ -123,13 +123,8 @@ ssize_t _lib9p_validate(uint8_t xxx_low_typ_bit,
const struct _lib9p_recv_tentry xxx_table[LIB9P_VER_NUM][0x80],
struct lib9p_ctx *ctx, uint8_t *net_bytes) {
/* Inspect the first 5 bytes ourselves. */
- struct _validate_ctx subctx = {
- /* input */
- .ctx = ctx,
- .net_size = uint32le_decode(net_bytes),
- .net_bytes = net_bytes,
- };
- if (subctx.net_size < 5)
+ uint32_t net_size = uint32le_decode(net_bytes);
+ if (net_size < 5)
return lib9p_error(ctx, LINUX_EBADMSG, "message is impossibly short");
uint8_t typ = net_bytes[4];
if (typ % 2 != xxx_low_typ_bit)
@@ -141,7 +136,7 @@ ssize_t _lib9p_validate(uint8_t xxx_low_typ_bit,
lib9p_msgtype_str(ctx->version, typ), lib9p_version_str(ctx->version));
/* Now use the message-type-specific tentry to process the whole thing. */
- return tentry.validate(&subctx);
+ return tentry.validate(ctx, net_size, net_bytes);
}
ssize_t lib9p_Tmsg_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes) {
@@ -162,16 +157,7 @@ void _lib9p_unmarshal(const struct _lib9p_recv_tentry xxx_table[LIB9P_VER_NUM][0
*ret_typ = typ;
struct _lib9p_recv_tentry tentry = xxx_table[ctx->version][typ/2];
- struct _unmarshal_ctx subctx = {
- /* input */
- .ctx = ctx,
- .net_bytes = net_bytes,
-
- /* output */
- .net_offset = 0,
- .extra = ret_body + tentry.basesize,
- };
- tentry.unmarshal(&subctx, ret_body);
+ tentry.unmarshal(ctx, net_bytes, ret_body);
}
void lib9p_Tmsg_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes,
@@ -190,11 +176,7 @@ static
bool _lib9p_marshal(const struct _lib9p_send_tentry xxx_table[LIB9P_VER_NUM][0x80],
struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body,
size_t *ret_iov_cnt, struct iovec *ret_iov, uint8_t *ret_copied) {
- struct _marshal_ctx subctx = {
- /* input */
- .ctx = ctx,
-
- /* ouptut */
+ struct _marshal_ret ret = {
.net_iov_cnt = 1,
.net_iov = ret_iov,
.net_copied_size = 0,
@@ -202,10 +184,10 @@ bool _lib9p_marshal(const struct _lib9p_send_tentry xxx_table[LIB9P_VER_NUM][0x8
};
struct _lib9p_send_tentry tentry = xxx_table[ctx->version][typ/2];
- bool ret_erred = tentry.marshal(&subctx, body);
- if (ret_iov[subctx.net_iov_cnt-1].iov_len == 0)
- subctx.net_iov_cnt--;
- *ret_iov_cnt = subctx.net_iov_cnt;
+ bool ret_erred = tentry.marshal(ctx, body, &ret);
+ if (ret_iov[ret.net_iov_cnt-1].iov_len == 0)
+ ret.net_iov_cnt--;
+ *ret_iov_cnt = ret.net_iov_cnt;
return ret_erred;
}
@@ -231,13 +213,7 @@ bool lib9p_Rmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *bo
bool lib9p_stat_validate(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_bytes,
uint32_t *ret_net_size, ssize_t *ret_host_size) {
- struct _validate_ctx subctx = {
- /* input */
- .ctx = ctx,
- .net_size = net_size,
- .net_bytes = net_bytes,
- };
- ssize_t host_size = _lib9p_stat_validate(&subctx, ret_net_size);
+ ssize_t host_size = _lib9p_stat_validate(ctx, net_size, net_bytes, ret_net_size);
if (host_size < 0)
return true;
if (ret_host_size)
@@ -245,19 +221,9 @@ bool lib9p_stat_validate(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_
return false;
}
-uint32_t lib9p_stat_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes,
- struct lib9p_stat *ret_obj, void *ret_extra) {
- struct _unmarshal_ctx subctx = {
- /* input */
- .ctx = ctx,
- .net_bytes = net_bytes,
-
- /* output */
- .net_offset = 0,
- .extra = ret_extra,
- };
- _lib9p_stat_unmarshal(&subctx, ret_obj);
- return subctx.net_offset;
+void lib9p_stat_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes,
+ struct lib9p_stat *ret) {
+ _lib9p_stat_unmarshal(ctx, net_bytes, ret);
}
uint32_t lib9p_stat_marshal(struct lib9p_ctx *ctx, uint32_t max_net_size, struct lib9p_stat *obj,
@@ -266,17 +232,13 @@ uint32_t lib9p_stat_marshal(struct lib9p_ctx *ctx, uint32_t max_net_size, struct
_ctx.max_msg_size = max_net_size;
struct iovec iov = {0};
- struct _marshal_ctx subctx = {
- /* input */
- .ctx = &_ctx,
-
- /* output */
+ struct _marshal_ret ret = {
.net_iov_cnt = 1,
.net_iov = &iov,
.net_copied_size = 0,
.net_copied = ret_bytes,
};
- if (_lib9p_stat_marshal(&subctx, obj))
+ if (_lib9p_stat_marshal(&_ctx, obj, &ret))
return 0;
- return subctx.net_iov[0].iov_len;
+ return ret.net_iov[0].iov_len;
}