--- parser3/src/targets/isapi/parser3isapi.C 2019/12/25 22:01:03 1.111 +++ parser3/src/targets/isapi/parser3isapi.C 2020/10/12 22:05:49 1.117 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -volatile const char * IDENT_PARSER3ISAPI_C="$Id: parser3isapi.C,v 1.111 2019/12/25 22:01:03 moko Exp $"; +volatile const char * IDENT_PARSER3ISAPI_C="$Id: parser3isapi.C,v 1.117 2020/10/12 22:05:49 moko Exp $"; #ifndef _MSC_VER # error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)] @@ -83,30 +83,19 @@ void SAPI::log(SAPI_Info& SAPI_info, con DWORD size=vsnprintf(start, MAX_LOG_STRING-strlen(prefix), fmt, args); size=remove_crlf(start, start+size); - SAPI_info.lpECB->ServerSupportFunction(SAPI_info.lpECB->ConnID, - HSE_APPEND_LOG_PARAMETER, buf, &size, 0); + SAPI_info.lpECB->ServerSupportFunction(SAPI_info.lpECB->ConnID, HSE_APPEND_LOG_PARAMETER, buf, &size, 0); } /// @todo event log -static void abort(const char* fmt, va_list args) { +void SAPI::die(const char* fmt, ...) { + va_list args; + va_start(args, fmt); if(FILE *log=fopen("c:\\parser3die.log", "at")) { vfprintf(log, fmt, args); fclose(log); } - // exit & try to produce core dump + // abnormal exit abort(); -} -void SAPI::die(const char* fmt, ...) { - va_list args; - va_start(args, fmt); - ::abort(fmt, args); -// va_end(args); -} - -void SAPI::abort(const char* fmt, ...) { - va_list args; - va_start(args, fmt); - ::abort(fmt, args); // va_end(args); } @@ -206,12 +195,11 @@ size_t SAPI::read_post(SAPI_Info& SAPI_i return total_read; } -void SAPI::add_header_attribute(SAPI_Info& SAPI_info, - const char* dont_store_key, const char* dont_store_value) { - if(strcasecmp(dont_store_key, "location")==0) +void SAPI::add_header_attribute(SAPI_Info& SAPI_info, const char* dont_store_key, const char* dont_store_value) { + if(strcasecmp(dont_store_key, "location")==0) SAPI_info.http_response_code=302; - if(strcasecmp(dont_store_key, HTTP_STATUS)==0) + if(strcasecmp(dont_store_key, HTTP_STATUS)==0) SAPI_info.http_response_code=atoi(dont_store_value); else (*SAPI_info.header) << capitalize(dont_store_key) << ": " << pa_strdup(dont_store_value) << "\r\n"; @@ -312,12 +300,9 @@ BOOL WINAPI TerminateExtension( void real_parser_handler(SAPI_Info& SAPI_info, bool header_only) { // collect garbage from prev request #ifndef PA_DEBUG_DISABLE_GC - { - int saved=GC_dont_gc; - GC_dont_gc=0; - GC_gcollect(); - GC_dont_gc=saved; - } + GC_dont_gc=0; + GC_gcollect(); + GC_dont_gc=1; #endif SAPI_info.header=new String; @@ -389,10 +374,7 @@ void real_parser_handler(SAPI_Info& SAPI } #ifdef PA_SUPPRESS_SYSTEM_EXCEPTION -static const Exception -call_real_parser_handler__do_PEH_return_it( - SAPI_Info& SAPI_info, bool header_only) -{ +static const Exception call_real_parser_handler__do_PEH_return_it(SAPI_Info& SAPI_info, bool header_only) { try { real_parser_handler(SAPI_info, header_only); } catch(const Exception& e) { @@ -401,33 +383,21 @@ call_real_parser_handler__do_PEH_return_ return Exception(); } -static void call_real_parser_handler__supress_system_exception( - SAPI_Info& SAPI_info, bool header_only) -{ + +static void call_real_parser_handler__supress_system_exception(SAPI_Info& SAPI_info, bool header_only) { Exception parser_exception; LPEXCEPTION_POINTERS system_exception=0; __try { - parser_exception=call_real_parser_handler__do_PEH_return_it( - SAPI_info, header_only); - } __except ( - (system_exception=GetExceptionInformation()), - EXCEPTION_EXECUTE_HANDLER) - { - + parser_exception=call_real_parser_handler__do_PEH_return_it(SAPI_info, header_only); + } __except ( (system_exception=GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) { if(system_exception) if(_EXCEPTION_RECORD *er=system_exception->ExceptionRecord) - throw Exception("system", - 0, - "0x%08X at 0x%08X", er->ExceptionCode, er->ExceptionAddress); + throw Exception("system", 0, "0x%08X at 0x%08X", er->ExceptionCode, er->ExceptionAddress); else - throw Exception("system", - 0, - ""); + throw Exception("system", 0, ""); else - throw Exception("system", - 0, - ""); + throw Exception("system", 0, ""); } if(parser_exception) @@ -452,75 +422,27 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI #endif SAPI_info, header_only); // successful finish - } catch(const Exception& e) { // global problem - // don't allocate anything on pool here: - // possible pool' exception not catch-ed now - // and there could be out-of-memory exception - const char* body=e.comment(); + } catch(const Exception& e) { // exception in unhandled exception // log it - SAPI::log(SAPI_info, "exception in request exception handler: %s", body); - - // - int content_length=strlen(body); - - // prepare header // not using SAPI func wich allocates on pool - char header_buf[MAX_STRING]; - int header_len=snprintf(header_buf, MAX_STRING, - HTTP_CONTENT_TYPE_CAPITALIZED ": text/plain\r\n" - HTTP_CONTENT_LENGTH_CAPITALIZED ": %u\r\n" -// "expires: Fri, 23 Mar 2001 09:32:23 GMT\r\n" - "\r\n", - content_length); + SAPI::log(SAPI_info, "%s", e.comment()); HSE_SEND_HEADER_EX_INFO header_info; header_info.pszStatus="200 OK"; header_info.cchStatus=strlen(header_info.pszStatus); - header_info.pszHeader=header_buf; - header_info.cchHeader=header_len; + header_info.pszHeader=HTTP_CONTENT_TYPE_CAPITALIZED ": text/plain\r\n\r\n"; + header_info.cchHeader=strlen(header_info.pszHeader); header_info.fKeepConn=true; // send header lpECB->dwHttpStatusCode=200; - lpECB->ServerSupportFunction(lpECB->ConnID, - HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); + lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); // send body if(!header_only) - SAPI::send_body(SAPI_info, body, content_length); + SAPI::send_body(SAPI_info, e.comment(), strlen(e.comment())); // unsuccessful finish } -/* - const char* body="test"; - - // - int content_length=strlen(body); - - // prepare header // not using SAPI func wich allocates on pool - char header_buf[MAX_STRING]; - int header_len=snprintf(header_buf, MAX_STRING, - HTTP_CONTENT_TYPE_CAPITALIZED ": text/plain\r\n" - HTTP_CONTENT_LENGTH_CAPITALIZED ": %u\r\n" - "expires: Fri, 23 Mar 2001 09:32:23 GMT\r\n" - "\r\n", - content_length); - HSE_SEND_HEADER_EX_INFO header_info; - header_info.pszStatus="200 OK"; - header_info.cchStatus=strlen(header_info.pszStatus); - header_info.pszHeader=header_buf; - header_info.cchHeader=header_len; - header_info.fKeepConn=true; - - // send header - lpECB->dwHttpStatusCode=200; - lpECB->ServerSupportFunction(lpECB->ConnID, - HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); - - // send body - DWORD num_bytes=content_length; - lpECB->WriteClient(lpECB->ConnID, - (void *)body, &num_bytes, HSE_IO_SYNC); -*/ return HSE_STATUS_SUCCESS_AND_KEEP_CONN; }