From fe168cff249a672aced9cda1439ac7aea343c9af Mon Sep 17 00:00:00 2001 From: ame Date: Fri, 24 Apr 2026 05:06:15 -0500 Subject: http body parsing & request reading --- src/util.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c index 39f2569..eacb196 100644 --- a/src/util.c +++ b/src/util.c @@ -5,6 +5,14 @@ #include "lua.h" #include "net.h" +/* + simple function to parse key=value; strings which are common in http headers + values may be null, because these strings can often just be a key such as + content-type: multipart/form-data; boundary=awa + will set the table to + multipart/form-data = (null) + boundary = awa +*/ int gen_parse(char* inp, int len, parray_t** _table){ str* current = str_init(""), *last = NULL; int state = 0; @@ -13,17 +21,18 @@ int gen_parse(char* inp, int len, parray_t** _table){ for(int i = 0; i < len; i++){ if(state != 1 && inp[i] == ';'){ - if(last != NULL){ - parray_set(table, last->c, (void*)current); - str_free(last); - } + //if(last != NULL){ + if(last == NULL) swap(str*, current, last); + parray_set(table, last->c, (void*)current); + str_free(last); + //} last = NULL; current = str_init(""); state = 0; } else if(state != 1 && inp[i] == '='){ last = current; current = str_init(""); - if(inp[i+1] == '"'){ + if(i + 1 < len && inp[i+1] == '"'){ state = 1; i++; } @@ -32,7 +41,8 @@ int gen_parse(char* inp, int len, parray_t** _table){ } else if(current->c[0] != '\0' || inp[i] != ' ') str_pushl(current, inp + i, 1); } - if(last != NULL){ + if(current->len > 0){ + if(last == NULL) swap(str*, current, last); parray_set(table, last->c, (void*)current); str_free(last); } -- cgit v1.2.3