--- parser3/src/targets/cgi/parser3.C 2001/11/15 16:30:02 1.131 +++ parser3/src/targets/cgi/parser3.C 2001/11/16 12:38:44 1.136 @@ -4,7 +4,7 @@ Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) Author: Alexander Petrosyan (http://paf.design.ru) - $Id: parser3.C,v 1.131 2001/11/15 16:30:02 paf Exp $ + $Id: parser3.C,v 1.136 2001/11/16 12:38:44 paf Exp $ */ #include "pa_config_includes.h" @@ -116,6 +116,26 @@ void SAPI::die(const char *fmt, ...) { ::log(fmt, args); va_end(args); + char body[MAX_STRING]; + size_t size=vsnprintf(body, MAX_STRING, fmt, args); + + // + int content_length=strlen(body); + + // prepare header + // let's be honest, that's bad we couldn't produce valid output + SAPI::add_header_attribute(pool, "status", "500"); + SAPI::add_header_attribute(pool, "content-type", "text/plain"); + char content_length_cstr[MAX_NUMBER]; + snprintf(content_length_cstr, MAX_NUMBER, "%u", content_length); + SAPI::add_header_attribute(pool, "content-length", content_length_cstr); + + // send header + SAPI::send_header(pool); + + // body + SAPI::send_body(pool, body, content_length); + exit(1); } @@ -269,7 +289,7 @@ void real_parser_handler( // prepare to process request Request request(pool, request_info, - cgi ? String::UL_USER_HTML : String::UL_AS_IS, + cgi ? String::UL_OPTIMIZED_HTML : String::UL_AS_IS, true /* status_allowed */); // some root-controlled location @@ -324,7 +344,7 @@ void real_parser_handler( void call_real_parser_handler__do_SEH( const char *filespec_to_process, const char *request_method, bool header_only) { -#if _MSC_VER & !defined(_DEBUG) +#if _MSC_VER && !defined(_DEBUG) LPEXCEPTION_POINTERS system_exception=0; __try { #endif @@ -332,7 +352,7 @@ void call_real_parser_handler__do_SEH( filespec_to_process, request_method, header_only); -#if _MSC_VER & !defined(_DEBUG) +#if _MSC_VER && !defined(_DEBUG) } __except ( (system_exception=GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) { @@ -350,49 +370,20 @@ void call_real_parser_handler__do_SEH( #endif } -void report_error(const char *prefix, const char *body, bool header_only) { - if(!body) - body=""; - - // log it - SAPI::log(pool, "%s%s", prefix?prefix:"", body); - - // - int content_length=strlen(body); - - // prepare header - SAPI::add_header_attribute(pool, "content-type", "text/plain"); - char content_length_cstr[MAX_NUMBER]; - snprintf(content_length_cstr, MAX_NUMBER, "%u", content_length); - SAPI::add_header_attribute(pool, "content-length", content_length_cstr); - - // send header - SAPI::send_header(pool); - - // body - if(!header_only) - SAPI::send_body(pool, body, content_length); -} - #ifdef WIN32 int failed_new(size_t size) { - const char *msg="out of memory"; - report_error(0, msg, false/*header_only*/); - SAPI::die(msg); + SAPI::die("out of memory in 'new', failed to allocated %u bytes", size); return 0; // not reached } #endif #ifdef HAVE_SET_NEW_HANDLER void failed_new() { - const char *msg="out of memory"; - report_error(0, msg, false/*header_only*/); - SAPI::die(msg); + SAPI::die("out of memory in 'new'"); } #endif int main(int argc, char *argv[]) { - int result; argv0=argv[0]; umask(2); @@ -437,30 +428,23 @@ int main(int argc, char *argv[]) { #endif #ifdef HAVE_SET_NEW_HANDLER - set_new_handler(failed_new); + std::set_new_handler(failed_new); #endif try { // global try call_real_parser_handler__do_SEH( filespec_to_process, request_method, header_only); - - // successful finish - result=0; } 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 - report_error("exception in request exception handler: ", e.comment(), header_only); - - // unsuccessful finish - result=1; + SAPI::die("exception in request exception handler: ", e.comment()); +#ifndef _DEBUG } catch(...) { - report_error(0, "", header_only); - - // unsuccessful finish - result=1; + SAPI::die(""); +#endif } @@ -469,5 +453,5 @@ int main(int argc, char *argv[]) { if(!cgi) SAPI::send_body(pool, "\n", 1); #endif - return result; + return 0; }