--- parser3/src/targets/cgi/parser3.C 2003/02/17 15:41:27 1.216.2.7 +++ parser3/src/targets/cgi/parser3.C 2003/02/21 15:10:10 1.216.2.16 @@ -5,12 +5,11 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_PARSER3_C="$Date: 2003/02/17 15:41:27 $"; +static const char* IDENT_PARSER3_C="$Date: 2003/02/21 15:10:10 $"; #include "pa_config_includes.h" #if _MSC_VER -# include # include #endif @@ -43,6 +42,7 @@ static const char* argv0; static const char* config_filespec_cstr=0; static bool fail_on_config_read_problem=true; +static bool force_header_output=false; static bool cgi; ///< we were started as CGI? static bool mail_received=false; ///< we were started with -m option? [asked to parse incoming message to $mail:received] @@ -111,6 +111,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); @@ -147,6 +148,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 @@ -190,13 +192,13 @@ size_t SAPI::read_post(SAPI_Info& , char } void SAPI::add_header_attribute(SAPI_Info& , const char* dont_store_key, const char* dont_store_value) { - if(cgi) + if(cgi || force_header_output) printf("%s: %s\n", dont_store_key, dont_store_value); } /// @todo intelligent cache-control void SAPI::send_header(SAPI_Info& ) { - if(cgi) { + if(cgi || force_header_output) { // puts("expires: Fri, 23 Mar 2001 09:32:23 GMT"); // header | body delimiter @@ -296,7 +298,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 @@ -425,47 +427,68 @@ static void real_parser_handler( #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( @@ -478,6 +501,7 @@ static void usage(const char* program) { " -m Parse mail, put received letter to $mail:received\n" #endif " -f config_file Use this config file (/path/to/auto.p)\n" + " -H Output CGI header\n" " -h Display usage information (this message)\n" , PARSER_VERSION, program); @@ -502,9 +526,9 @@ int main(int argc, char *argv[]) { #endif #ifdef _DEBUG - //_crtBreakAlloc=1684; + //_crtBreakAlloc=4042; #endif -// _asm int 3; + //_asm int 3; argv0=argv[0]; umask(2); @@ -525,7 +549,7 @@ int main(int argc, char *argv[]) { optind = 1; opterr = 0; int c; - while((c = getopt(argc, argv, "hf:" + while((c = getopt(argc, argv, "hHf:" #ifdef WITH_MAILRECEIVE "m" #endif @@ -534,6 +558,9 @@ int main(int argc, char *argv[]) { case 'h': usage(argv[0]); break; + case 'H': + force_header_output=true; + break; case 'f': config_filespec_cstr=optarg; break; @@ -563,14 +590,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 ); @@ -580,10 +606,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)); @@ -600,12 +622,8 @@ int main(int argc, char *argv[]) { // and there could be out-of-memory exception SAPI::die("exception in request exception handler: %s", e.comment()); -#ifndef _DEBUG - } catch(...) { - SAPI::die(""); -#endif } - //_asm int 3; +// _asm int 3; return 0; }