Make request parsing reentrant

This commit is contained in:
2024-10-07 00:55:44 -04:00
parent e31ac94a8b
commit e5932da1e5
9 changed files with 229 additions and 142 deletions
-1
View File
@@ -17,7 +17,6 @@ typedef struct RdbClient {
} RdbClient;
void rdb_client_init(RdbClient *self, int connfd);
ssize_t rdb_client_read(RdbClient *self, char *buf, size_t len);
void rdb_client_begin_packet(RdbClient *self);
bool rdb_client_write_str(RdbClient *self, const char *str);
bool rdb_client_write_str_hex(RdbClient *self, const char *str);
+8
View File
@@ -0,0 +1,8 @@
#ifndef V810_HEX_H_
#define V810_HEX_H_
#include <stdbool.h>
bool parse_hex_digit(char digit, char *out);
#endif
+41
View File
@@ -0,0 +1,41 @@
#ifndef RDBSERVER_REQUEST_H
#define RDBSERVER_REQUEST_H
#include <stddef.h>
#define INBUF_LEN 256
typedef enum rdb_read_result_t {
read_result_success,
read_result_error,
read_result_pending,
read_result_disconnected,
} rdb_read_result_t;
typedef enum rdb_read_state_t {
read_state_header,
read_state_body,
read_state_body_escape,
read_state_checksum_1,
read_state_checksum_2,
} rdb_read_state_t;
typedef struct RdbRequest {
int connfd;
struct Buffer {
char buf[INBUF_LEN];
size_t len;
size_t index;
} inbuf;
rdb_read_state_t state;
char *cmd;
size_t cmdlen;
size_t outlen;
char chk;
} RdbRequest;
void rdb_request_init(RdbRequest *req, int connfd, char *cmd, size_t cmdlen);
void rdb_request_reset(RdbRequest *req);
rdb_read_result_t rdb_request_read(RdbRequest *req, size_t *len);
#endif