--- parser3/src/targets/cgi/parser3.C 2020/10/14 00:14:45 1.302 +++ parser3/src/targets/cgi/parser3.C 2020/10/28 22:32:02 1.306 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.302 2020/10/14 00:14:45 moko Exp $"; +volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.306 2020/10/28 22:32:02 moko Exp $"; #include "pa_config_includes.h" @@ -154,6 +154,10 @@ char* SAPI::Env::get(SAPI_Info& info, co return info.get_env(name); } +bool SAPI::Env::set(SAPI_Info& info, const char* name, const char* value) { + return info.set_env(name, value); +} + const char* const *SAPI::Env::get(SAPI_Info& info) { return info.get_env(); } @@ -316,9 +320,8 @@ static void connection_handler(SAPI_Info { // initing ::request ptr for signal handlers RequestController rc(&request); - bool fail_on_config_read_problem=locate_config(); // process the request - request.core(config_filespec_cstr, fail_on_config_read_problem, strcasecmp(request_info.method, "HEAD")==0); + request.core(locate_config() ? config_filespec_cstr : NULL, strcasecmp(request_info.method, "HEAD")==0); // clearing ::request in RequestController desctructor to prevent signal handlers from accessing invalid memory } } @@ -327,19 +330,23 @@ static void httpd_mode(const char* files int sock = HTTPD_Server::bind(httpd_host_port); while(1){ - HTTPD_Connection *connection = HTTPD_Server::accept(sock, 5); - if(!connection) - continue; - - SAPI_Info_HTTPD info(*connection); - - try { // connection try - connection_handler(info, *connection, filespec_to_process); - } catch(const Exception& e) { // exception in connection handling or unhandled exception - SAPI::log(info, "%s", e.comment()); - SAPI::send_error(info, e.comment(), info.exception_http_status(e.type())); + try { + HTTPD_Connection connection; + if(!connection.accept(sock, 5)) + continue; + + SAPI_Info_HTTPD info(connection); + + try { // connection try + connection_handler(info, connection, filespec_to_process); + } catch(const Exception& e) { // exception in connection handling or unhandled exception + SAPI::log(info, "%s", e.comment()); + SAPI::send_error(info, e.comment(), info.exception_http_status(e.type())); + } + // closing connection socket in HTTPD_Connection destructor + } catch(const Exception& e) { // exception in accept or send_error + SAPI::log(*sapiInfo, "%s", e.comment()); } - connection->close(); } } @@ -424,7 +431,7 @@ static void real_parser_handler(const ch } request_info.content_type = getenv("CONTENT_TYPE"); - request_info.content_length = pa_atoui(getenv("CONTENT_LENGTH"), 10); + request_info.content_length = pa_atoul(getenv("CONTENT_LENGTH")); request_info.cookie = getenv("HTTP_COOKIE"); request_info.mail_received = mail_received; @@ -449,10 +456,9 @@ static void real_parser_handler(const ch { // initing ::request ptr for signal handlers RequestController rc(&request); - bool fail_on_config_read_problem=locate_config(); // process the request - request.core(config_filespec_cstr, fail_on_config_read_problem, strcasecmp(request_info.method, "HEAD")==0); - // clearing ::request in RequestController desctructor to prevent signal handlers from accessing invalid memory + request.core(locate_config() ? config_filespec_cstr : NULL, strcasecmp(request_info.method, "HEAD")==0); + // clearing ::request in RequestController destructor to prevent signal handlers from accessing invalid memory } // finalize libraries