--- parser3/src/targets/cgi/parser3.C 2003/02/14 17:28:20 1.216.2.3 +++ parser3/src/targets/cgi/parser3.C 2003/02/21 09:48:58 1.216.2.11 @@ -5,12 +5,11 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_PARSER3_C="$Date: 2003/02/14 17:28:20 $"; +static const char* IDENT_PARSER3_C="$Date: 2003/02/21 09:48:58 $"; #include "pa_config_includes.h" #if _MSC_VER -# include # include #endif @@ -29,17 +28,8 @@ static const char* IDENT_PARSER3_C="$Dat #endif //#define DEBUG_POOL_MALLOC -//#define DEBUG_STRING_APPENDS_VS_EXPANDS //#define DEBUG_MAILRECEIVE "mailreceive.eml" -#ifdef DEBUG_STRING_APPENDS_VS_EXPANDS -extern ulong - string_piece_appends, - wcontext_result_size, - total_alloc_size, - string_string_shortcut_economy; -#endif - // consts #define REDIRECT_PREFIX "REDIRECT_" @@ -120,6 +110,7 @@ void SAPI::log(SAPI_Info&, const char* f } void SAPI::die(const char* fmt, ...) { + //_asm int 3; #ifdef DEBUG_POOL_MALLOC extern void log_pool_stats(Pool& pool); log_pool_stats(SAPI_info); @@ -156,6 +147,7 @@ void SAPI::die(const char* fmt, ...) { SAPI::send_body(SAPI_info, body, content_length); #ifdef WIN32 + //_asm int 3; // IIS with abort failes to show STDOUT, it just barks "abnormal program termination" exit(1); #else @@ -305,7 +297,7 @@ static void real_parser_handler( } request_info.path_translated=filespec_to_process; request_info.method=request_method ? request_method : "GET"; - const char* query_string=SAPI::get_env(SAPI_info, "QUERY_STRING"); + CharPtr query_string=SAPI::get_env(SAPI_info, "QUERY_STRING"); request_info.query_string=query_string; if(cgi) { // few absolute obligatory @@ -321,9 +313,9 @@ static void real_parser_handler( request_info.uri=env_request_uri; else if(query_string) { - char *reconstructed_uri=(char *)request_pool.malloc( + char *reconstructed_uri=new(request_pool) char[ strlen(path_info)+1/*'?'*/+ - strlen(query_string)+1/*0*/); + strlen(query_string)+1/*0*/]; strcpy(reconstructed_uri, path_info); strcat(reconstructed_uri, "?"); strcat(reconstructed_uri, query_string); @@ -378,7 +370,7 @@ static void real_parser_handler( // prepare to process request - Request request(SAPI_info, request_pool, + Request request(request_pool, SAPI_info, request_info, /*#ifdef _DEBUG String::UL_HTML|String::UL_OPTIMIZE_BIT @@ -432,59 +424,70 @@ static void real_parser_handler( extern void log_pool_stats(Pool& pool); log_pool_stats(request_pool); #endif - -#ifdef DEBUG_STRING_APPENDS_VS_EXPANDS - SAPI::log(SAPI_info, - "string piece appends=%lu, wcontext_result_size=%lu, string_string_shortcut_economy_closer=%lu, total_alloc_size=%lu", - string_piece_appends, - wcontext_result_size, - string_string_shortcut_economy, - total_alloc_size); -#endif - } -static void call_real_parser_handler__do_SEH( +//#if _MSC_VER && !defined(_DEBUG) +# define PA_USE___TRY +struct Parser_executed { + bool with_system_exception; + LPEXCEPTION_POINTERS system_exception; +}; +//#endif + +static +#ifdef PA_USE___TRY +Parser_executed +#else +void +#endif +call_real_parser_handler__do_SEH_return_it( const char* filespec_to_process, const char* request_method, bool header_only) { -#if _MSC_VER && !defined(_DEBUG) - LPEXCEPTION_POINTERS system_exception=0; +#ifdef PA_USE___TRY + Parser_executed result={false}; __try { #endif real_parser_handler( filespec_to_process, request_method, header_only); -#if _MSC_VER && !defined(_DEBUG) +#ifdef PA_USE___TRY } __except ( - (system_exception=GetExceptionInformation()), + (result.system_exception=GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) { - - if(system_exception) - if(_EXCEPTION_RECORD *er=system_exception->ExceptionRecord) - throw Exception(0, - 0, - "Exception 0x%08X at 0x%08X", er->ExceptionCode, er->ExceptionAddress); - else - throw Exception(0, 0, "Exception "); - else - throw Exception(0, 0, "Exception "); + _asm int 3; + result.with_system_exception=true; } + return result; #endif } -#if _MSC_VER -int failed_new(size_t size) { - SAPI::die("out of memory in 'new', failed to allocated %u bytes", size); - return 0; // not reached -} +static void call_real_parser_handler__do_SEH( + const char* filespec_to_process, + const char* request_method, bool header_only) { +#ifdef PA_USE___TRY + Parser_executed executed= #endif + call_real_parser_handler__do_SEH_return_it(filespec_to_process, + request_method, header_only); -#ifdef HAVE_SET_NEW_HANDLER -static void failed_new() { - SAPI::die("out of memory in 'new'"); -} +#ifdef PA_USE___TRY + if(executed.with_system_exception) + if(executed.system_exception) + if(_EXCEPTION_RECORD *er=executed.system_exception->ExceptionRecord) + throw Exception(Exception::undefined_type, + Exception::undefined_source, + "Exception 0x%08X at 0x%08X", er->ExceptionCode, er->ExceptionAddress); + else + throw Exception(Exception::undefined_type, + Exception::undefined_source, + "Exception "); + else + throw Exception(Exception::undefined_type, + Exception::undefined_source, + "Exception "); #endif +} static void usage(const char* program) { printf( @@ -521,9 +524,9 @@ int main(int argc, char *argv[]) { #endif #ifdef _DEBUG -// _crtBreakAlloc=33112; + //_crtBreakAlloc=4042; #endif -// _asm int 3; + //_asm int 3; argv0=argv[0]; umask(2); @@ -582,14 +585,13 @@ int main(int argc, char *argv[]) { #endif #if _MSC_VER - _set_new_handler(failed_new); #ifdef _DEBUG // Get current flag int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); // Turn on leak-checking bit - tmpFlag |= _CRTDBG_LEAK_CHECK_DF; +// tmpFlag |= _CRTDBG_LEAK_CHECK_DF; // Set flag to the new value _CrtSetDbgFlag( tmpFlag ); @@ -599,10 +601,6 @@ int main(int argc, char *argv[]) { #endif -#ifdef HAVE_SET_NEW_HANDLER - std::set_new_handler(failed_new); -#endif - char filespec_to_process[MAX_STRING]; full_file_spec(raw_filespec_to_process, filespec_to_process, sizeof(filespec_to_process)); @@ -625,6 +623,6 @@ int main(int argc, char *argv[]) { #endif } - //_asm int 3; +// _asm int 3; return 0; }