From 3bdf71c456a905607cb597ccc515bb222f86321d Mon Sep 17 00:00:00 2001 From: amelia squires Date: Wed, 4 Sep 2024 01:17:25 -0500 Subject: add to server, and fix leaks --- src/net.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/net.c') diff --git a/src/net.c b/src/net.c index 2966905..48c685d 100644 --- a/src/net.c +++ b/src/net.c @@ -71,7 +71,22 @@ void* handle_client(void *_arg){ str_push(aa, sk->c); //parray_t* v = parray_find(paths, aa->c); - parray_t* v = route_match(paths, aa->c); + larray_t* params = larray_init(); + parray_t* v = route_match(paths, aa->c, ¶ms); + + /*for(int i = 0; i != params->len; i++){ + int id = larray_geti(params, i); + parray_t* par = params->arr[id].value; + printf("%i\n", i); + for(int x = 0; x != par->len; x++){ + printf("\t%s : %s\n",par->P[x].key->c, (char*)par->P[x].value); + } + + parray_clear(par, STR); + + } + + larray_clear(params);*/ if(sT != NULL) rolling_file_parse(L, &files_idx, &body_idx, buffer + header_eof + 4, sT, bytes_received - header_eof - 4, file_cont); @@ -154,13 +169,27 @@ void* handle_client(void *_arg){ luaI_tsets(L, header_idx, "Content-Type", "text/html"); luaI_tsetv(L, res_idx, "header", header_idx); - + //get all function that kinda match parray_t* owo = (parray_t*)v; for(int i = 0; i != owo->len; i++){ //though these are arrays of arrays we have to iterate *again* struct sarray_t* awa = (struct sarray_t*)owo->P[i].value; + //push url params + lua_newtable(L); + int new_param_idx = lua_gettop(L); + + int id = larray_geti(params, i); + parray_t* par = params->arr[id].value; + + for(int z = 0; z != par->len; z++){ + luaI_tsets(L, new_param_idx, par->P[z].key->c, (char*)par->P[z].value); + } + parray_clear(par, FREE); + + luaI_tsetv(L, req_idx, "paramaters", new_param_idx); + for(int z = 0; z != awa->len; z++){ char* path; struct lchar* wowa = awa->cs[z]; @@ -181,6 +210,7 @@ void* handle_client(void *_arg){ } } } + larray_clear(params); parray_lclear(owo); //dont free the rest lua_pushstring(L, "client_fd"); -- cgit v1.2.3