diff --git a/bin/uce_fastcgi.debug.linux.bin b/bin/uce_fastcgi.debug.linux.bin index 51995ca..ab8ebc7 100755 Binary files a/bin/uce_fastcgi.debug.linux.bin and b/bin/uce_fastcgi.debug.linux.bin differ diff --git a/src/lib/compiler.h b/src/lib/compiler.h index 9986810..dd9871c 100644 --- a/src/lib/compiler.h +++ b/src/lib/compiler.h @@ -77,7 +77,8 @@ string process_html_literal(SharedUnit* su, string content) string preprocess_shared_unit(SharedUnit* su) { string content = file_get_contents(su->file_name); - string pc = "#include \""+context->server_state->config.COMPILER_SYS_PATH +"/src/lib/uce_gen.h\" \n"; + printf("(c) compiling with root dir %s\n", context->server->config.COMPILER_SYS_PATH.c_str()); + string pc = ("#include \"")+context->server->config.COMPILER_SYS_PATH +"/src/lib/uce_gen.h\" \n"; string token = ""; string html_buffer = ""; u8 mode = 0; @@ -144,8 +145,8 @@ void setup_unit_paths(SharedUnit* su, string file_name) return; su->src_path = dirname(file_name); - su->bin_path = context->server_state->config.BIN_DIRECTORY + su->src_path; - su->pre_path = context->server_state->config.BIN_DIRECTORY + su->src_path; + su->bin_path = context->server->config.BIN_DIRECTORY + su->src_path; + su->pre_path = context->server->config.BIN_DIRECTORY + su->src_path; su->src_file_name = basename(file_name); su->bin_file_name = su->src_file_name + ".so"; @@ -202,7 +203,7 @@ void compile_shared_unit(SharedUnit* su, string file_name) printf("Config.COMPILE_SCRIPT %s\n", string(su->pre_path + "/" + su->pre_file_name).c_str()); - su->compiler_messages = trim(shell_exec(context->server_state->config.COMPILE_SCRIPT+" "+ + su->compiler_messages = trim(shell_exec(context->server->config.COMPILE_SCRIPT+" "+ shell_escape(su->src_path)+" "+ shell_escape(su->bin_path)+" "+ shell_escape(su->file_name)+" "+ @@ -223,7 +224,7 @@ void compile_shared_unit(SharedUnit* su, string file_name) SharedUnit* get_shared_unit(string file_name) { - SharedUnit* su = context->server_state->units[file_name]; + SharedUnit* su = context->server->units[file_name]; auto mod_time = file_mtime(file_name); bool do_recompile = false; if(su && (su->last_compiled < mod_time || mod_time == 0)) @@ -247,13 +248,14 @@ SharedUnit* get_shared_unit(string file_name) compile_shared_unit(su, file_name); } - context->server_state->units[file_name] = su; + context->server->units[file_name] = su; } return(su); } -void invoke(string file_name) +void compiler_invoke(string file_name) { + printf("(i) invoke %s\n", file_name.c_str()); if(file_name[0] != '/') { file_name = expand_path(file_name); @@ -283,3 +285,5 @@ void invoke(string file_name) } } } + +invoke_handler invoke; diff --git a/src/lib/sys.h b/src/lib/sys.h index cfb4603..d1ef8ac 100644 --- a/src/lib/sys.h +++ b/src/lib/sys.h @@ -162,5 +162,6 @@ void on_segfault(int sig) { // print out all the frames to stderr fprintf(stderr, "SEG FAULT: %d:\n", sig); backtrace_symbols_fd(array, size, STDERR_FILENO); + exit(1); } diff --git a/src/lib/types.h b/src/lib/types.h index 59bd5d7..0f1b0e5 100644 --- a/src/lib/types.h +++ b/src/lib/types.h @@ -58,7 +58,7 @@ struct ServerSettings { string SOCKET_PATH = "/run/uce.sock"; string TMP_UPLOAD_PATH = "/tmp/uce/uploads"; string SESSION_PATH = "/tmp/uce/sessions"; - string COMPILER_SYS_PATH = ""; + string COMPILER_SYS_PATH = "."; u32 LISTEN_PORT = 9993; u64 SESSION_TIME = 60*60*24*30; @@ -108,7 +108,7 @@ struct ServerState { struct Request { - ServerState* server_state; + ServerState* server; StringMap params; StringMap get; @@ -130,6 +130,8 @@ struct Request { f64 time_start; f64 time_end; + invoke_handler invoke; + void print(string s) { out.append(s); diff --git a/src/lib/uce_gen.h b/src/lib/uce_gen.h index 4406ec8..7b46a61 100644 --- a/src/lib/uce_gen.h +++ b/src/lib/uce_gen.h @@ -14,6 +14,7 @@ Request* context; extern "C" void set_current_request(Request* _request) { context = _request; + invoke = _request->invoke; signal(SIGSEGV, on_segfault); } diff --git a/src/lib/uri.h b/src/lib/uri.h index 45252d8..e19c77c 100644 --- a/src/lib/uri.h +++ b/src/lib/uri.h @@ -120,7 +120,7 @@ StringMap parse_multipart(string q, string boundary, std::vector& { nibble("=\"", field); UploadedFile f; - f.tmp_name = context->server_state->config.TMP_UPLOAD_PATH + std::to_string(rand()); + f.tmp_name = context->server->config.TMP_UPLOAD_PATH + std::to_string(rand()); f.file_name = nibble("\"", field); string bin = field.substr(4, field.length()-6); f.size = bin.length(); @@ -285,19 +285,19 @@ string make_session_id() StringMap load_session_data(string session_id) { - return(parse_query(file_get_contents(context->server_state->config.SESSION_PATH + "/" + session_id))); + return(parse_query(file_get_contents(context->server->config.SESSION_PATH + "/" + session_id))); } void save_session_data(string session_id, StringMap data) { - file_put_contents(context->server_state->config.SESSION_PATH + "/" + session_id, encode_query(data)); + file_put_contents(context->server->config.SESSION_PATH + "/" + session_id, encode_query(data)); } string session_start(string session_name = "uce-session") { if(context->cookies[session_name].length() == 0) { - set_cookie(session_name, make_session_id(), time() + context->server_state->config.SESSION_TIME); + set_cookie(session_name, make_session_id(), time() + context->server->config.SESSION_TIME); } context->session_id = context->cookies[session_name]; context->session_name = session_name; @@ -309,7 +309,7 @@ void session_destroy(string session_name = "uce-session") { if(context->cookies[session_name].length() > 0) { - set_cookie(session_name, "", time() - context->server_state->config.SESSION_TIME); + set_cookie(session_name, "", time() - context->server->config.SESSION_TIME); context->session.clear(); context->session_id = ""; } diff --git a/src/linux_fastcgi.cpp b/src/linux_fastcgi.cpp index a97d797..89c1f46 100644 --- a/src/linux_fastcgi.cpp +++ b/src/linux_fastcgi.cpp @@ -34,11 +34,13 @@ int handle_complete(FastCGIRequest& request) { // The event handler can also be a class member function. This // event occurs when the parameters and standard input streams are // both closed, and thus the request is complete. - context = &request; - request.server_state = &server_state; - request.time_start = microtime(); + // printf("(i) request handle\n"); - request.header["Content-Type"] = context->server_state->config.CONTENT_TYPE; + context = &request; + request.server = &server_state; + request.time_start = microtime(); + request.invoke = compiler_invoke; + request.header["Content-Type"] = context->server->config.CONTENT_TYPE; request.get = parse_query(request.params["QUERY_STRING"]); if(request.params["HTTP_COOKIE"].length() > 0) @@ -60,6 +62,7 @@ int handle_complete(FastCGIRequest& request) { } } + // printf("(i) request ready\n"); invoke(request.params["SCRIPT_FILENAME"]); string headers = @@ -92,13 +95,18 @@ int main(int argc, char** argv) signal(SIGSEGV, on_segfault); srand(time()); + invoke = compiler_invoke; + // Set up our request handlers server.request_handler(&handle_request); server.data_handler(&handle_data); server.complete_handler(&handle_complete); - if(server_state.config.COMPILER_SYS_PATH == "") + //if(server_state.config.COMPILER_SYS_PATH == "") server_state.config.COMPILER_SYS_PATH = get_cwd(); + + printf("Compiler base path: %s\n", server_state.config.COMPILER_SYS_PATH.c_str()); + server_state.config.BIN_DIRECTORY = server_state.config.COMPILER_SYS_PATH + "/" + server_state.config.BIN_DIRECTORY; server_state.config.COMPILE_SCRIPT = diff --git a/test/text-json.uce b/test/text-json.uce new file mode 100644 index 0000000..e683ac3 --- /dev/null +++ b/test/text-json.uce @@ -0,0 +1,12 @@ + + +RENDER() +{ + + DTree t; + + echo(json_encode(t)); + + echo(string("PATH: ") + context->server->config.COMPILER_SYS_PATH + "\n"); + +}