Make command parsing more robust

This commit is contained in:
2024-10-06 21:33:50 -04:00
parent de92335134
commit e31ac94a8b
4 changed files with 147 additions and 127 deletions
+22
View File
@@ -0,0 +1,22 @@
#ifndef RDBSERVER_CMDBUF_H_
#define RDBSERVER_CMDBUF_H_
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct CommandBuf {
char *buf;
size_t len;
} CommandBuf;
/* Try to consume a string literal. */
bool cmd_match_str(CommandBuf *cmd, const char *str);
/* Try to consume a string literal, if it is the only thing left in the buffer. */
bool cmd_match_only_str(CommandBuf *cmd, const char *str);
/* Try to consume a base-16 number, and return the value. */
bool cmd_match_hex_number(CommandBuf *cmd, uint32_t *value);
/* Try to consume a hex-encoded list of bytes, and return the value. */
bool cmd_match_hex_bytes(CommandBuf *cmd, const uint32_t count, char *value);
#endif