nserver

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 51738cdf6627b6c3d48d7d7002a2af36babc917a
parent d770ecf0ddbbd46b1530f5be8ef6d96acc395550
Author: rsiddharth <s@ricketyspace.net>
Date:   Thu, 28 Nov 2019 00:49:19 -0500

nserver: nserve.c: check_cmd_size -> check_cmd.

* nserver/src/nserve.c (check_cmd_size): Rename to ...
(check_cmd): ...this. Remove argument sock. Now returns a char *. The
returned char * is NULL on success and is pointer to err string on
failure.

Diffstat:
nserver/src/nserve.c | 26+++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/nserver/src/nserve.c b/nserver/src/nserve.c @@ -40,26 +40,30 @@ int sanitize(char *cmd) return -1; } -int check_cmd_size(char *cmd, int sock) +char *check_cmd(char *cmd) { + char *err = NULL; + check(cmd != NULL, "cmd is NULL"); + int rc = sanitize(cmd); + check(rc != -1, "sanitize failed"); + size_t len = strlen(cmd); if (len >= CMD_MIN_SIZE && len <= CMD_MAX_SIZE) { - return 0; - } else if (len == 0) { - char *q = "closing connection\n"; - size_t bytes = barfsock(q, strlen(q), sock); - check(bytes == strlen(q), "send sock failed"); + return NULL; + } + + if (len == 0) { + err = "closing connection\n"; } else { - char *err = "cmd size invalid\n"; - size_t bytes = barfsock(err, strlen(err), sock); - check(bytes == strlen(err), "send sock failed"); + err = "command size invalid\n"; } - return 1; + return err; error: - return -1; + err = "internal error\n"; + return err; }