aboutsummaryrefslogtreecommitdiff
path: root/shared/protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'shared/protocol.c')
-rw-r--r--shared/protocol.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/shared/protocol.c b/shared/protocol.c
index ca0edc4..fcc84a4 100644
--- a/shared/protocol.c
+++ b/shared/protocol.c
@@ -3,6 +3,7 @@
#include <string.h>
#include "protocol.h"
+#include "util.h"
#define WS_CMD_MAP(parsed_cmd, name, code) \
if (strlen(parsed_cmd->argv[0]) == strlen(name) && strncmp(parsed_cmd->argv[0], name, strlen(name)) == 0) return code;
@@ -99,10 +100,7 @@ ws_s_protocol_req_parser_state* ws_protocol_req_parser_alloc() {
void ws_protocol_req_cmd_init(ws_s_protocol_req_parser_state* state) {
state->target = malloc(sizeof(ws_s_protocol_parsed_req_cmd) + sizeof(char*) * state->arg_len);
for (unsigned int i = 0; i < state->arg_len; i++)
- state->target->argv[i] = malloc(sizeof(char) * (state->args_len[i] + 1)); // segfaults on 2nd run?
- // state->target->argv stays empty according to debugger
- // goes to HardFault_Handler on 2nd iteration
- // this might be the stm running out of heap memory though i'm not sure
+ state->target->argv[i] = malloc(sizeof(char) * (state->args_len[i] + 1));
state->target->argc = state->arg_len;
@@ -138,3 +136,11 @@ void ws_protocol_req_cmd_free(ws_s_protocol_parsed_req_cmd* cmd) {
free(cmd);
return;
}
+
+unsigned short ws_protocol_get_header_size(ws_s_protocol_res* response) {
+ unsigned short size = 2; // comma and trailing newline
+ if (response->success == WS_PROTOCOL_CMD_RETURN_OK) size += 2; // ok
+ if (response->success == WS_PROTOCOL_CMD_RETURN_ERROR) size += 5; // error
+ size += ws_log16(response->msg->bytes); // amount of characters for message size (hex)
+ return size;
+} \ No newline at end of file