--- parser3/src/targets/cgi/parser3.C 2020/10/14 00:13:01 1.301 +++ parser3/src/targets/cgi/parser3.C 2020/10/14 16:51:46 1.304 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.301 2020/10/14 00:13:01 moko Exp $"; +volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.304 2020/10/14 16:51:46 moko Exp $"; #include "pa_config_includes.h" @@ -105,7 +105,7 @@ static void log(const char* fmt, va_list fwrite(buf, size, 1, f); if(request_info.method) { - fprintf(f, " [uri=%s, method=%s, cl=%lu]\n", request_info.uri ? request_info.uri : "", request_info.method, request_info.content_length); + fprintf(f, " [uri=%s, method=%s, cl=%lu]\n", request_info.uri ? request_info.uri : "", request_info.method, (unsigned long)request_info.content_length); } else fputs(" [no request info]\n", f); @@ -327,19 +327,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 +428,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; @@ -452,7 +456,7 @@ static void real_parser_handler(const ch 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 + // clearing ::request in RequestController destructor to prevent signal handlers from accessing invalid memory } // finalize libraries