--- parser3/src/targets/isapi/parser3isapi.C 2024/11/04 03:53:25 1.129 +++ parser3/src/targets/isapi/parser3isapi.C 2026/04/25 13:38:46 1.136 @@ -1,11 +1,11 @@ /** @file Parser: IIS extension. - Copyright (c) 2000-2024 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2000-2026 Art. Lebedev Studio (https://www.artlebedev.com) Authors: Konstantin Morshnev , Alexandr Petrosian */ -volatile const char * IDENT_PARSER3ISAPI_C="$Id: parser3isapi.C,v 1.129 2024/11/04 03:53:25 moko Exp $"; +volatile const char * IDENT_PARSER3ISAPI_C="$Id: parser3isapi.C,v 1.136 2026/04/25 13:38:46 moko Exp $"; #ifndef _MSC_VER # error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)] @@ -56,6 +56,8 @@ const int IIS51var_count=sizeof(IIS51var // globals char argv0[MAX_STRING]=""; +const char* parser3_mode="isapi"; // $status:mode +const char *parser3_log_filespec(){ return ""; } // $status:log-filename // SAPI @@ -99,6 +101,14 @@ void SAPI::die(const char* fmt, ...) { // va_end(args); } +void SAPI::send_error(SAPI_Info& SAPI_info, const char *exception_cstr, const char *status){ + // capitalized headers passed for preventing malloc during capitalization + add_header_attribute(SAPI_info, HTTP_STATUS_CAPITALIZED, status); + add_header_attribute(SAPI_info, HTTP_CONTENT_TYPE_CAPITALIZED, "text/plain"); + send_headers(SAPI_info); + send_body(SAPI_info, exception_cstr, strlen(exception_cstr)); +} + char* SAPI::Env::get(SAPI_Info& SAPI_info, const char* name) { char *variable_buf=new(PointerFreeGC) char[MAX_STRING]; DWORD variable_len = MAX_STRING-1; @@ -206,7 +216,7 @@ void SAPI::add_header_attribute(SAPI_Inf } /// @todo intelligent cache-control -void SAPI::send_header(SAPI_Info& SAPI_info) { +void SAPI::send_headers(SAPI_Info& SAPI_info) { HSE_SEND_HEADER_EX_INFO header_info; char status_buf[MAX_STATUS_LENGTH]; @@ -238,6 +248,10 @@ void SAPI::send_header(SAPI_Info& SAPI_i HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); } +void SAPI::clear_headers(SAPI_Info& SAPI_info) { + SAPI_info.header=new String; +} + size_t SAPI::send_body(SAPI_Info& SAPI_info, const void *buf, size_t size) { DWORD num_bytes=size; if(!SAPI_info.lpECB->WriteClient(SAPI_info.lpECB->ConnID, @@ -395,19 +409,19 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI #endif SAPI_info, header_only); // successful finish - } catch(const Exception& e) { // exception in unhandled exception + } catch(const Exception& e) { // just in case // log it SAPI::log(SAPI_info, "%s", e.comment()); HSE_SEND_HEADER_EX_INFO header_info; - header_info.pszStatus="200 OK"; + header_info.pszStatus="500 Internal Server Error"; header_info.cchStatus=strlen(header_info.pszStatus); 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->dwHttpStatusCode=500; lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); // send body