Refactor FastCGI server and compiler, enhance HTTP header parsing, and add WebSocket support
- Refactored FastCGIServer class to improve socket handling and added shutdown functionality. - Updated compiler functions to streamline HTML and text literal processing. - Enhanced split_kv function to support uppercase keys and added split_http_headers for better HTTP header parsing. - Introduced new session management functions to validate and handle session IDs. - Added WebSocket frame parsing and handling in the URI module. - Created systemd service scripts for easier deployment and management of the UCE FastCGI runtime. - Added new test cases for header handling, time parsing, and WebSocket functionality.
This commit is contained in:
+27
-10
@@ -70,8 +70,8 @@ int handle_complete(FastCGIRequest& request) {
|
||||
}
|
||||
}
|
||||
|
||||
// printf("(i) request ready\n");
|
||||
render_file(request.params["SCRIPT_FILENAME"]);
|
||||
DTree call_param;
|
||||
compiler_invoke(&request, request.params["SCRIPT_FILENAME"], call_param);
|
||||
|
||||
for( auto &f : request.uploaded_files)
|
||||
{
|
||||
@@ -86,6 +86,20 @@ int handle_complete(FastCGIRequest& request) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
volatile bool termination_signal_received = false;
|
||||
|
||||
void on_terminate(int sig)
|
||||
{
|
||||
if(termination_signal_received)
|
||||
return;
|
||||
termination_signal_received = true;
|
||||
if(getpid() != parent_pid)
|
||||
exit(1);
|
||||
printf("Terminating... PID %i:%i\n", getpid(), parent_pid);
|
||||
server.shutdown();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void listen_for_connections()
|
||||
{
|
||||
if(precompile_jobs.size() > 0)
|
||||
@@ -119,25 +133,27 @@ void init_base_process()
|
||||
|
||||
server_state.config["COMPILE_SCRIPT"] =
|
||||
server_state.config["COMPILER_SYS_PATH"] + "/" + server_state.config["COMPILE_SCRIPT"];
|
||||
if(server_state.config["LISTEN_PORT"] != "")
|
||||
server.listen(int_val(server_state.config["LISTEN_PORT"]));
|
||||
|
||||
if(server_state.config["FCGI_PORT"] != "")
|
||||
server.listen(int_val(server_state.config["FCGI_PORT"]));
|
||||
|
||||
printf("%s\n", var_dump(server_state.config).c_str());
|
||||
|
||||
if(server_state.config["SOCKET_PATH"] != "")
|
||||
if(server_state.config["FCGI_SOCKET_PATH"] != "")
|
||||
{
|
||||
server.listen(server_state.config["SOCKET_PATH"]);
|
||||
chmod(server_state.config["SOCKET_PATH"].c_str(), S_IRWXU | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
server.listen(server_state.config["FCGI_SOCKET_PATH"]);
|
||||
chmod(server_state.config["FCGI_SOCKET_PATH"].c_str(), S_IRWXU | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
}
|
||||
|
||||
//dirname(server_state.config.COMPILER_SYS_PATH);
|
||||
//basename(server_state.config.COMPILER_SYS_PATH);
|
||||
if(server_state.config["HTTP_PORT"] != "")
|
||||
server.listen_http(int_val(server_state.config["HTTP_PORT"]));
|
||||
|
||||
mkdir(server_state.config["BIN_DIRECTORY"]);
|
||||
mkdir(server_state.config["TMP_UPLOAD_PATH"]);
|
||||
mkdir(server_state.config["SESSION_PATH"]);
|
||||
|
||||
signal(SIGCHLD, on_child_exit);
|
||||
signal(SIGINT, on_terminate);
|
||||
srand(time());
|
||||
}
|
||||
|
||||
@@ -187,7 +203,8 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
spawn_subprocess(listen_for_connections);
|
||||
if(!termination_signal_received)
|
||||
spawn_subprocess(listen_for_connections);
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user