--- parser3/src/targets/isapi/parser3isapi.C 2026/04/25 13:38:46 1.136 +++ parser3/src/targets/isapi/parser3isapi.C 2026/10/18 21:05:35 1.142 @@ -5,7 +5,7 @@ Authors: Konstantin Morshnev , Alexandr Petrosian */ -volatile const char * IDENT_PARSER3ISAPI_C="$Id: parser3isapi.C,v 1.136 2026/04/25 13:38:46 moko Exp $"; +volatile const char * IDENT_PARSER3ISAPI_C="$Id: parser3isapi.C,v 1.142 2026/10/18 21:05:35 moko Exp $"; #ifndef _MSC_VER # error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)] @@ -82,7 +82,7 @@ void SAPI::log(SAPI_Info& SAPI_info, con const char* prefix="PARSER_ERROR:"; strcpy(buf, prefix); char *start=buf+strlen(prefix); - DWORD size=vsnprintf(start, MAX_LOG_STRING-strlen(prefix), fmt, args); + DWORD size=pa_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); @@ -231,7 +231,7 @@ void SAPI::send_headers(SAPI_Info& SAPI_ header_info.pszStatus="401 Authorization Required"; break; default: - snprintf(status_buf, MAX_STATUS_LENGTH, + pa_snprintf(status_buf, MAX_STATUS_LENGTH, "%d Undescribed", SAPI_info.http_response_code); header_info.pszStatus=status_buf; break; @@ -286,7 +286,7 @@ static void parser_done() { /// ISAPI // BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer) { pVer->dwExtensionVersion = HSE_VERSION; - pa_strncpy(pVer->lpszExtensionDesc, "Parser " PARSER_VERSION, HSE_MAX_EXT_DLL_NAME_LEN); + pa_strncpy(pVer->lpszExtensionDesc, "Parser " PARSER_VERSION_WITH_FEATURES, HSE_MAX_EXT_DLL_NAME_LEN); return parser_init(); } // dwFlags & HSE_TERM_MUST_UNLOAD means we can't return false @@ -310,7 +310,7 @@ BOOL WINAPI TerminateExtension( @test PARSER_VERSION from outside */ -void real_parser_handler(SAPI_Info& SAPI_info, bool header_only) { +void real_parser_handler(SAPI_Info& SAPI_info) { // collect garbage from prev request pa_gc_collect(); @@ -320,17 +320,13 @@ void real_parser_handler(SAPI_Info& SAPI // Request info Request_info request_info; memset(&request_info, 0, sizeof(request_info)); - char *filespec_to_process=pa_strdup(lpECB->lpszPathTranslated); -#ifdef WIN32 - back_slashes_to_slashes(filespec_to_process); -#endif + char *filespec_to_process=backslashes_to_slashes(lpECB->lpszPathTranslated); if(const char* path_info=SAPI::Env::get(SAPI_info, "PATH_INFO")) { // IIS - size_t len=strlen(filespec_to_process)-strlen(path_info); - char *buf=new(PointerFreeGC) char[len]; - pa_strncpy(buf, filespec_to_process, len); - request_info.document_root=buf; + size_t filespec_len=strlen(filespec_to_process); + size_t path_info_len=strlen(path_info); + request_info.set_document_root(filespec_len>path_info_len ? pa_strdup(filespec_to_process, filespec_len-path_info_len) : ""); } else throw Exception(PARSER_RUNTIME, 0, "ISAPI: no PATH_INFO defined (in reinventing DOCUMENT_ROOT)"); @@ -349,21 +345,21 @@ void real_parser_handler(SAPI_Info& SAPI // beside by binary static char beside_binary_path[MAX_STRING]; pa_strncpy(beside_binary_path, argv0, MAX_STRING); // filespec of my binary - if(!(rsplit(beside_binary_path, '/') || rsplit(beside_binary_path, '\\'))) { // strip filename + if(!rsplit(beside_binary_path, "/\\")) { // strip filename // no path, just filename beside_binary_path[0]='.'; beside_binary_path[1]=0; } char config_filespec[MAX_STRING]; - snprintf(config_filespec, MAX_STRING, "%s/%s", beside_binary_path, AUTO_FILE_NAME); + pa_snprintf(config_filespec, MAX_STRING, "%s/%s", beside_binary_path, AUTO_FILE_NAME); // process the request - request.core(entry_exists(config_filespec) ? config_filespec : NULL, header_only); + request.core(entry_exists(config_filespec) ? config_filespec : NULL); } #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) { try { - real_parser_handler(SAPI_info, header_only); + real_parser_handler(SAPI_info); } catch(const Exception& e) { return e; } @@ -371,16 +367,16 @@ static const Exception call_real_parser_ 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) { Exception parser_exception; LPEXCEPTION_POINTERS system_exception=0; __try { - parser_exception=call_real_parser_handler__do_PEH_return_it(SAPI_info, header_only); + parser_exception=call_real_parser_handler__do_PEH_return_it(SAPI_info); } __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 %p", er->ExceptionCode, er->ExceptionAddress); else throw Exception("system", 0, ""); else @@ -400,14 +396,13 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI 200 // default http_response_code [lpECB->dwHttpStatusCode seems to be always 0, even on 404 redirect to /404.html] }; - bool header_only=strcasecmp(lpECB->lpszMethod, "HEAD")==0; try { // global try #ifdef PA_SUPPRESS_SYSTEM_EXCEPTION call_real_parser_handler__supress_system_exception( #else real_parser_handler( #endif - SAPI_info, header_only); + SAPI_info); // successful finish } catch(const Exception& e) { // just in case // log it @@ -425,7 +420,7 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); // send body - if(!header_only) + if(strcasecmp(lpECB->lpszMethod, "HEAD")!=0) SAPI::send_body(SAPI_info, e.comment(), strlen(e.comment())); // unsuccessful finish @@ -446,4 +441,4 @@ BOOL WINAPI DllMain( ); return TRUE; -} \ No newline at end of file +}