diff options
Diffstat (limited to 'src/net.c')
| -rw-r--r-- | src/net.c | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -740,19 +740,19 @@ void* handle_client(void *_arg){ str* aa = str_init(portc);
struct net_path_t parsed_path;
path_parse(&parsed_path, path);
-
+
str* decoded_path;
int decoded_err = percent_decode(parsed_path.path, &decoded_path);
larray_t* params = NULL;
parray_t* v = NULL;
- if(decoded_err == 1 || paths == NULL){
+ if(decoded_err == 1 || args->paths == NULL){
net_error(client_fd, 400);
} else {
str_push(aa, decoded_path->c);
params = larray_init();
- v = route_match(paths, aa->c, ¶ms);
+ v = route_match(args->paths, aa->c, ¶ms);
if(sT != NULL)
rolling_file_parse(L, &files_idx, &body_idx, header + 4, sT, bite - header_eof - 4, file_cont);
@@ -929,7 +929,7 @@ int clean_lullaby_net(lua_State* L){ return 0;
}
-int start_serv(lua_State* L, int port){
+int start_serv(lua_State* L, int port, parray_t* paths){
parse_mimetypes();
//need these on windows for sockets (stupid)
#ifdef _WIN32
@@ -982,6 +982,7 @@ int start_serv(lua_State* L, int port){ args->port = port;
args->cli = client_addr;
args->L = luaL_newstate();
+ args->paths = paths;
int old_top = lua_gettop(L);
lua_getglobal(L, "_G");
@@ -1004,6 +1005,10 @@ int start_serv(lua_State* L, int port){ }
int l_req_com(lua_State* L, char* req){
+ lua_pushstring(L, "paths");
+ lua_gettable(L, 1);
+ parray_t* paths = lua_touserdata(L, -1);
+
lua_pushstring(L, "port");
lua_gettable(L, 1);
int port = luaL_checkinteger(L, -1);
@@ -1024,9 +1029,6 @@ int l_req_com(lua_State* L, char* req){ strcpy(awa->req, req);
free(uwu); //yes this *should* be str_free but awa kinda owns it now:p
- if(paths == NULL)
- paths = parray_init();
-
//please free this
void* v_old_paths = parray_get(paths, portss->c);
struct sarray_t* old_paths;
@@ -1085,15 +1087,16 @@ int l_listen(lua_State* L){ luaI_tsetcf(L, mt, "PATCH", l_PATCHq);
luaI_tsetcf(L, mt, "all", l_allq);
- lua_pushstring(L, "port");
- lua_pushvalue(L, 2);
- lua_settable(L, -3);
+ luaI_tsetv(L, mt, "port", 2);
+
+ parray_t* paths = parray_init();
+ luaI_tsetlud(L, mt, "paths", paths);
lua_pushvalue(L, 1); //the function
- lua_pushvalue(L, -2); //the server table
+ lua_pushvalue(L, mt); //the server table
lua_pcall(L, 1, 0, 0);
- start_serv(L, port);
+ start_serv(L, port, paths);
return 0;
}
|
