From 2fe7b8af431af5c80426cdd5ed2aaa95bb14544c Mon Sep 17 00:00:00 2001 From: nirenjan Date: Sun, 7 Nov 2021 05:47:31 -0800 Subject: [PATCH] Cleanup response protocol This change removes the unnecessary response length field from the output buffer. It was added to check for possible issues in the communication between client and server, but is not needed anymore. This also makes the communication protocol standardized between client and server. --- daemon/x52d_command.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/daemon/x52d_command.c b/daemon/x52d_command.c index 6f6d2f2..aa18055 100644 --- a/daemon/x52d_command.c +++ b/daemon/x52d_command.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include "pinelog.h" @@ -138,8 +137,8 @@ static void response_formatted(char *buffer, int *buflen, const char *type, int typelen; typelen = strlen(type) + 1; - strcpy(response + 2, type); - resplen = typelen + 2; + strcpy(response, type); + resplen = typelen; if (*fmt) { va_start(ap, fmt); @@ -147,8 +146,6 @@ static void response_formatted(char *buffer, int *buflen, const char *type, va_end(ap); } - typelen = htons(resplen); - memcpy(response, &typelen, 2); memcpy(buffer, response, resplen); *buflen = resplen; } @@ -163,8 +160,8 @@ static void response_strings(char *buffer, int *buflen, const char *type, int co char *arg; arglen = strlen(type) + 1; - strcpy(response + 2, type); - resplen = arglen + 2; + strcpy(response, type); + resplen = arglen; va_start(ap, count); for (i = 0; i < count; i++) { @@ -180,8 +177,6 @@ static void response_strings(char *buffer, int *buflen, const char *type, int co } va_end(ap); - arglen = htons(resplen); - memcpy(response, &arglen, 2); memcpy(buffer, response, resplen); *buflen = resplen; } @@ -311,7 +306,7 @@ static void command_parser(char *buffer, int *buflen) MATCH(0, "config") { cmd_config(buffer, buflen, argc, argv); } else { - ERR("Unknown command '%s'", argv[0]); + ERR_fmt("Unknown command '%s'", argv[0]); } }