summaryrefslogtreecommitdiff
path: root/lib9p/srv.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r--lib9p/srv.c57
1 files changed, 26 insertions, 31 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c
index d5b643d..f2d1315 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -121,7 +121,7 @@ static uint32_t rerror_overhead_for_version(enum lib9p_version version,
scratch); /* net_bytes */
assert(!e);
- uint32_t min_msg_size = decode_u32le(scratch);
+ uint32_t min_msg_size = uint32le_decode(scratch);
/* Assert that min_msg_size + biggest_possible_MAX_ERR_SIZE
* won't overflow uint32... because using
@@ -143,11 +143,8 @@ static void respond_error(struct _lib9p_srv_req *req) {
ssize_t r;
struct lib9p_msg_Rerror host = {
.tag = req->tag,
- .ename = {
- .len = strnlen(req->ctx.basectx.err_msg,
- CONFIG_9P_MAX_ERR_SIZE),
- .utf8 = req->ctx.basectx.err_msg,
- },
+ .ename = lib9p_strn(req->ctx.basectx.err_msg,
+ CONFIG_9P_MAX_ERR_SIZE),
#if CONFIG_9P_ENABLE_9P2000_u
.errno = req->ctx.basectx.err_num,
#endif
@@ -167,7 +164,7 @@ static void respond_error(struct _lib9p_srv_req *req) {
cr_mutex_lock(&sess->parent_conn->writelock);
r = VCALL(sess->parent_conn->fd, write,
- req->net_bytes, decode_u32le(req->net_bytes));
+ req->net_bytes, uint32le_decode(req->net_bytes));
cr_mutex_unlock(&sess->parent_conn->writelock);
if (r < 0)
nonrespond_errorf("write: %s", net_strerror(-r));
@@ -229,7 +226,7 @@ static void handle_message(struct _lib9p_srv_req *ctx);
size_t done = 0;
if (read_at_least(conn.fd, buf, 4, &done))
goto close;
- size_t goal = decode_u32le(buf);
+ size_t goal = uint32le_decode(buf);
if (goal < 7) {
nonrespond_errorf("T-message is impossibly small");
goto close;
@@ -238,7 +235,7 @@ static void handle_message(struct _lib9p_srv_req *ctx);
goto close;
struct _lib9p_srv_req req = {
.parent_sess = &sess,
- .tag = decode_u16le(&buf[5]),
+ .tag = uint16le_decode(&buf[5]),
.net_bytes = buf,
.ctx = {
.basectx = {
@@ -296,7 +293,7 @@ COROUTINE lib9p_srv_write_cr(void *_srv) {
/* Deep-copy the request from the reader coroutine's
* stack to our stack. */
req = *rpc_handle.req;
- memcpy(net, req.net_bytes, decode_u32le(req.net_bytes));
+ memcpy(net, req.net_bytes, uint32le_decode(req.net_bytes));
req.net_bytes = net;
/* Record that we have it. */
reqmap_store(&req.parent_sess->reqs, req.tag, &req);
@@ -395,7 +392,7 @@ static void handle_message(struct _lib9p_srv_req *ctx) {
cr_mutex_lock(&ctx->parent_sess->parent_conn->writelock);
VCALL(ctx->parent_sess->parent_conn->fd, write,
- ctx->net_bytes, decode_u32le(ctx->net_bytes));
+ ctx->net_bytes, uint32le_decode(ctx->net_bytes));
cr_mutex_unlock(&ctx->parent_sess->parent_conn->writelock);
}
}
@@ -443,14 +440,14 @@ static void handle_Tversion(struct _lib9p_srv_req *ctx,
'0' <= req->version.utf8[3] && req->version.utf8[3] <= '9' &&
'0' <= req->version.utf8[4] && req->version.utf8[4] <= '9' &&
'0' <= req->version.utf8[5] && req->version.utf8[5] <= '9' &&
- (req->version.utf8[6] == '\0' || req->version.utf8[6] == '.')) {
+ (req->version.len == 6 || req->version.utf8[6] == '.')) {
version = LIB9P_VER_9P2000;
#if CONFIG_9P_ENABLE_9P2000_u
- if (strcmp(&req->version.utf8[6], ".u") == 0)
+ if (lib9p_str_eq(lib9p_str_sliceleft(req->version, 6), lib9p_str(".u")))
version = LIB9P_VER_9P2000_u;
#endif
#if CONFIG_9P_ENABLE_9P2000_e
- if (strcmp(&req->version.utf8[6], ".e") == 0)
+ if (lib9p_str_eq(lib9p_str_sliceleft(req->version, 6), lib9p_str(".e")))
version = LIB9P_VER_9P2000_e;
#endif
}
@@ -463,11 +460,7 @@ static void handle_Tversion(struct _lib9p_srv_req *ctx,
return;
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
- resp->version.utf8 = lib9p_version_str(version);
-#pragma GCC diagnostic pop
- resp->version.len = strlen(resp->version.utf8);
+ resp->version = lib9p_str((char *)lib9p_version_str(version)); /* cast to discard "const" qualifier */
resp->max_msg_size = (CONFIG_9P_MAX_MSG_SIZE < req->max_msg_size)
? CONFIG_9P_MAX_MSG_SIZE
: req->max_msg_size;
@@ -511,7 +504,7 @@ static void handle_Tauth(struct _lib9p_srv_req *ctx,
util_handler_common(ctx, req, resp);
ctx->ctx.uid = req->n_uid;
- ctx->ctx.uname = req->uname.utf8;
+ ctx->ctx.uname = req->uname;
struct lib9p_srv *srv = ctx->parent_sess->parent_conn->parent_srv;
if (!srv->auth) {
@@ -520,7 +513,7 @@ static void handle_Tauth(struct _lib9p_srv_req *ctx,
return;
}
- srv->auth(&ctx->ctx, req->aname.utf8);
+ srv->auth(&ctx->ctx, req->aname);
lib9p_error(&ctx->ctx.basectx,
LINUX_EOPNOTSUPP, "TODO: auth not implemented");
}
@@ -531,7 +524,7 @@ static void handle_Tattach(struct _lib9p_srv_req *ctx,
util_handler_common(ctx, req, resp);
ctx->ctx.uid = req->n_uid;
- ctx->ctx.uname = req->uname.utf8;
+ ctx->ctx.uname = req->uname;
struct lib9p_srv *srv = ctx->parent_sess->parent_conn->parent_srv;
if (srv->auth) {
@@ -543,14 +536,16 @@ static void handle_Tattach(struct _lib9p_srv_req *ctx,
else if (fh->type != FH_AUTH)
lib9p_error(&ctx->ctx.basectx,
LINUX_EACCES, "FID provided as auth-file is not an auth-file");
- else if (strcmp(fh->data.auth.uname, req->uname.utf8) != 0)
+ else if (!lib9p_str_eq(fh->data.auth.uname, req->uname))
lib9p_errorf(&ctx->ctx.basectx,
- LINUX_EACCES, "FID provided as auth-file is for user=\"%s\" and cannot be used for user=\"%s\"",
- fh->data.auth.uname, req->uname.utf8);
- else if (strcmp(fh->data.auth.aname, req->aname.utf8) != 0)
+ LINUX_EACCES, "FID provided as auth-file is for user=\"%.*s\" and cannot be used for user=\"%.*s\"",
+ fh->data.auth.uname.len, fh->data.auth.uname.utf8,
+ req->uname.len, req->uname.utf8);
+ else if (!lib9p_str_eq(fh->data.auth.aname, req->aname))
lib9p_errorf(&ctx->ctx.basectx,
- LINUX_EACCES, "FID provided as auth-file is for tree=\"%s\" and cannot be used for tree=\"%s\"",
- fh->data.auth.aname, req->aname.utf8);
+ LINUX_EACCES, "FID provided as auth-file is for tree=\"%.*s\" and cannot be used for tree=\"%.*s\"",
+ fh->data.auth.aname.len, fh->data.auth.aname.utf8,
+ req->aname.len, req->aname.utf8);
else if (!fh->data.auth.authenticated)
lib9p_error(&ctx->ctx.basectx,
LINUX_EACCES, "FID provided as auth-file has not completed authentication");
@@ -575,7 +570,7 @@ static void handle_Tattach(struct _lib9p_srv_req *ctx,
return;
}
- implements_lib9p_srv_file *rootdir = srv->rootdir(&ctx->ctx, req->aname.utf8);
+ implements_lib9p_srv_file *rootdir = srv->rootdir(&ctx->ctx, req->aname);
assert((rootdir == NULL) == lib9p_ctx_has_error(&ctx->ctx.basectx));
if (lib9p_ctx_has_error(&ctx->ctx.basectx))
return;
@@ -647,7 +642,7 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx,
resp->wqid = (struct lib9p_qid *)(&resp[1]);
for (resp->nwqid = 0; resp->nwqid < req->nwname; resp->nwqid++) {
implements_lib9p_srv_file *member;
- if (strcmp(req->wname[resp->nwqid].utf8, "..") == 0) {
+ if (lib9p_str_eq(req->wname[resp->nwqid], lib9p_str(".."))) {
member = dir->_parent_dir;
} else {
if (!isdir) {
@@ -656,7 +651,7 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx,
break;
}
- member = VCALL(dir, dopen, &ctx->ctx, req->wname[resp->nwqid].utf8);
+ member = VCALL(dir, dopen, &ctx->ctx, req->wname[resp->nwqid]);
assert((member == NULL) == lib9p_ctx_has_error(&ctx->ctx.basectx));
if (lib9p_ctx_has_error(&ctx->ctx.basectx))
break;