--- parser3/src/targets/cgi/parser3.C 2001/11/21 08:34:43 1.142 +++ parser3/src/targets/cgi/parser3.C 2001/12/13 13:02:43 1.148 @@ -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.142 2001/11/21 08:34:43 paf Exp $ + $Id: parser3.C,v 1.148 2001/12/13 13:02:43 paf Exp $ */ #include "pa_config_includes.h" @@ -15,6 +15,7 @@ #if _MSC_VER # include +# include #endif #include "pa_sapi.h" @@ -119,21 +120,22 @@ void SAPI::die(const char *fmt, ...) { log_pool_stats(pool); #endif + va_list args; + va_start(args,fmt); // log // logging is more important than user // she can cancel download, we'd get SIG_PIPE, // nothing would be logged then - va_list args; - va_start(args,fmt); ::log(fmt, args); - va_end(args); // inform user char body[MAX_STRING]; int content_length=vsnprintf(body, MAX_STRING, fmt, args); + va_end(args); + // prepare header // let's be honest, that's bad we couldn't produce valid output SAPI::add_header_attribute(pool, "status", "500"); @@ -176,7 +178,7 @@ void SAPI::add_header_attribute(Pool& , /// @todo intelligent cache-control void SAPI::send_header(Pool& ) { if(cgi) { - puts("expires: Fri, 23 Mar 2001 09:32:23 GMT"); +// puts("expires: Fri, 23 Mar 2001 09:32:23 GMT"); // header | body delimiter puts(""); @@ -199,6 +201,24 @@ char *full_file_spec(char *file_name) { return file_name; } +#ifdef XML +/** + * Terminate Xalan and Xerces. + * + * Should be called only once per process after deleting all + * instances of XalanTransformer. Once a process has called + * this function, it cannot use the API for the remaining + * lifetime of the process. + + + this requirement is fullfilled by using Pool::register_cleanup + */ +void callXalanTerminate(void *) { + //_asm int 3; + XalanTerminate(); +} +#endif + /** main workhorse @@ -206,6 +226,7 @@ main workhorse IIS: remove trailing default-document[index.html] from $request.uri. to do that we need to consult metabase, wich is tested but seems slow. + IIS5 todo find out proper 'illegal call' check */ void real_parser_handler( const char *filespec_to_process, @@ -222,6 +243,7 @@ void real_parser_handler( */ //_asm int 3; XalanInitialize(); + pool.register_cleanup(callXalanTerminate, 0); #endif // init global classes @@ -230,9 +252,7 @@ void real_parser_handler( pa_globals_init(pool); if(!filespec_to_process) - throw Exception(0, 0, - 0, - "Parser/%s", PARSER_VERSION); + SAPI::die("Parser/%s", PARSER_VERSION); // Request info Request::Info request_info; @@ -280,15 +300,16 @@ void real_parser_handler( 0, "CGI: no PATH_INFO defined(in reinventing REQUEST_URI)"); +#ifndef WIN32 + // they've changed this under IIS5. if(const char *script_name=SAPI::get_env(pool, "SCRIPT_NAME")) { size_t script_name_len=strlen(script_name); size_t uri_len=strlen(request_info.uri); if(strncmp(request_info.uri,script_name, script_name_len)==0 && script_name_len != uri_len) // under IIS they are the same - throw Exception(0, 0, - 0, - "CGI: illegal call"); + SAPI::die("CGI: illegal call"); } +#endif } else request_info.uri=0; @@ -301,7 +322,12 @@ void real_parser_handler( // prepare to process request Request request(pool, request_info, - cgi ? String::UL_HTML|String::UL_OPTIMIZE_BIT : String::UL_AS_IS, +#ifdef _DEBUG + String::UL_HTML|String::UL_OPTIMIZE_BIT +#else + cgi ? String::UL_HTML|String::UL_OPTIMIZE_BIT : String::UL_AS_IS +#endif + , true /* status_allowed */); // some root-controlled location @@ -396,6 +422,7 @@ void failed_new() { #endif int main(int argc, char *argv[]) { +// _asm int 3; argv0=argv[0]; umask(2); @@ -428,6 +455,20 @@ int main(int argc, char *argv[]) { #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; + + // Set flag to the new value + _CrtSetDbgFlag( tmpFlag ); +// _CrtSetBreakAlloc(471); + +#endif + #endif #ifdef HAVE_SET_NEW_HANDLER @@ -452,7 +493,7 @@ int main(int argc, char *argv[]) { // possible pool' exception not catch-ed now // and there could be out-of-memory exception - SAPI::die("exception in request exception handler: ", e.comment()); + SAPI::die("exception in request exception handler: %s", e.comment()); #ifndef _DEBUG } catch(...) { SAPI::die("");