diff options
| author | ame <[email protected]> | 2024-02-24 03:03:50 -0600 |
|---|---|---|
| committer | ame <[email protected]> | 2024-02-24 03:03:50 -0600 |
| commit | ea535b120a4ff426b0d5a8458bde52bf2f049937 (patch) | |
| tree | aebfda99b19411626e3cab8b78dc72fd985dd5a5 | |
| parent | a70b76bf071c34692bac99da252a3c74a355db71 (diff) | |
linux tests (wow so much shit was broken)
| -rw-r--r-- | src/lua.h | 6 | ||||
| -rw-r--r-- | src/net.c | 24 | ||||
| -rw-r--r-- | src/types/parray.c | 4 | ||||
| -rw-r--r-- | src/types/str.c | 2 | ||||
| -rw-r--r-- | tests/net.lua | 2 |
5 files changed, 18 insertions, 20 deletions
@@ -1,6 +1,6 @@ -#include <lua.h>
-#include <lualib.h>
-#include <lauxlib.h>
+#include <lua5.4/lua.h>
+#include <lua5.4/lualib.h>
+#include <lua5.4/lauxlib.h>
#include <stdlib.h>
void* __malloc_(size_t);
@@ -59,7 +59,7 @@ pthread_mutex_t lua_mutex = PTHREAD_MUTEX_INITIALIZER; int64_t recv_full_buffer(int client_fd, char** _buffer, int* header_eof){
char* header, *buffer = malloc(BUFFER_SIZE * sizeof * buffer);
memset(buffer, 0, BUFFER_SIZE);
- size_t len = 0;
+ int64_t len = 0;
*header_eof = -1;
int n, content_len = -1;
@@ -77,7 +77,7 @@ int64_t recv_full_buffer(int client_fd, char** _buffer, int* header_eof){ if(cont_len_raw == NULL) {
len += n;
*_buffer = buffer;
- return len + BUFFER_SIZE;
+ return len;
}
str* cont_len_str = str_init("");
@@ -448,14 +448,13 @@ char* strnstr(const char *s1, const char *s2, size_t n) { * @param {lua_State*} lua state to put table into
* @param {char*} response buffer
* @param {str*} response header Content-Type value
- * @param {char**} pointer to the remaining body after all files
* @return {int} lua index of table
*/
-int file_parse(lua_State* L, char* buffer, str* content_type, char** end_buffer, size_t blen){
- //printf("***\n'%s', %i\n'",content_type->c, blen);
- //for(int i = 0; i != blen; i++)
- // printf("%c", buffer[i]);
- //printf("'\n");
+int file_parse(lua_State* L, char* buffer, str* content_type, size_t blen){
+ /*printf("***\n'%s', %i\n'",content_type->c, blen);
+ for(int i = 0; i != blen; i++)
+ printf("%c", buffer[i]);
+ printf("'\n");*/
str* boundary = str_init(""); //usually add + 2 to the length when using
int state = 0;
@@ -464,6 +463,7 @@ int file_parse(lua_State* L, char* buffer, str* content_type, char** end_buffer, if(content_type->c[i] == ';') state = 1;
if(content_type->c[i] == '=' && state == 1) state = 2;
}
+ if(state != 2) return -1;
char* end = buffer + blen;
lua_newtable(L);
int base_T = lua_gettop(L);
@@ -524,7 +524,6 @@ int file_parse(lua_State* L, char* buffer, str* content_type, char** end_buffer, }
str_free(boundary);
- *end_buffer = buffer + boundary->len + 4;
lua_pushvalue(L, base_T);
return base_T;
}
@@ -584,12 +583,11 @@ void* handle_client(void *_arg){ int res_idx = lua_gettop(L);
if(sT != NULL && bytes_received > 0){
- char* new_cont;
- int pf = file_parse(L, buffer + header_eof, sT, &new_cont, bytes_received - header_eof);
+ int pf = file_parse(L, buffer + header_eof, sT, bytes_received - header_eof);
if(pf >= 0){
luaI_tsetv(L, req_idx, "files", pf);
- parray_set(table, "Body", (void*)str_init(new_cont));
+ parray_set(table, "Body", (void*)str_init(""));
}
}
@@ -856,4 +854,4 @@ int l_listen(lua_State* L){ start_serv(L, port);
return 0;
-}
\ No newline at end of file +}
diff --git a/src/types/parray.c b/src/types/parray.c index 3dcc57f..25cd94c 100644 --- a/src/types/parray.c +++ b/src/types/parray.c @@ -3,7 +3,7 @@ #include <stdlib.h>
#include <string.h>
-#include "lua.h"
+#include "../lua.h"
#include "parray.h"
parray_t* parray_init(){
@@ -83,4 +83,4 @@ parray_t* parray_find(parray_t* p, char* match){ }
}
return ret;
-}
\ No newline at end of file +}
diff --git a/src/types/str.c b/src/types/str.c index 279567f..f790dba 100644 --- a/src/types/str.c +++ b/src/types/str.c @@ -1,5 +1,5 @@ #include "str.h" -#include "lua.h" +#include "../lua.h" str* str_init(char* init){ if(init == NULL){ diff --git a/tests/net.lua b/tests/net.lua index cb51ab5..bef4920 100644 --- a/tests/net.lua +++ b/tests/net.lua @@ -64,5 +64,5 @@ llib.net.listen( end,
- 8080
+ arg[1]
)
|
