--- parser3/src/targets/cgi/parser3.C 2003/03/12 10:47:13 1.216.2.25 +++ parser3/src/targets/cgi/parser3.C 2003/03/31 08:35:45 1.216.2.30.2.14 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_PARSER3_C="$Date: 2003/03/12 10:47:13 $"; +static const char* IDENT_PARSER3_C="$Date: 2003/03/31 08:35:45 $"; #include "pa_config_includes.h" @@ -20,6 +20,8 @@ static const char* IDENT_PARSER3_C="$Dat #include "pa_socks.h" #include "pa_version.h" + + #ifdef WIN32 # include # include "getopt.h" @@ -42,12 +44,13 @@ 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] // for signal handlers Request *request=0; +Request_info *request_info=0; +bool execution_canceled=false; // SAPI @@ -113,7 +116,7 @@ void SAPI::log(SAPI_Info&, const char* f static void die_or_abort(const char* fmt, va_list args, bool write_core) { //_asm int 3; #ifdef DEBUG_POOL_MALLOC - extern void log_pool_stats(Pool& pool); + extern void log_pool_stats(); log_pool_stats(SAPI_info); #endif @@ -171,14 +174,14 @@ void SAPI::abort(const char* fmt, ...) { va_end(args); } -char* SAPI::get_env(Pool& pool, SAPI_Info& , const char* name) { +char* SAPI::get_env(SAPI_Info& , const char* name) { if(char *local=getenv(name)) - return pool.copy(local); + return pa_strdup(local); else return 0; } -const char* const *SAPI::environment(SAPI_Info&, Pool&) { +const char* const *SAPI::environment(SAPI_Info&) { #ifdef _MSC_VER extern char **_environ; return _environ; @@ -202,13 +205,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 || force_header_output) + if(cgi) printf("%s: %s\n", dont_store_key, dont_store_value); } /// @todo intelligent cache-control void SAPI::send_header(SAPI_Info& ) { - if(cgi || force_header_output) { + if(cgi) { // puts("expires: Fri, 23 Mar 2001 09:32:23 GMT"); // header | body delimiter @@ -242,13 +245,17 @@ static void full_file_spec(const char* f } static void log_signal(const char* signal_name) { - SAPI::log(SAPI_info, request? "%s received. uri=%s, method=%s, qs=%s, cl=%u" - :"%s received. no request being processed", - signal_name, - request && request->request_info.uri?request->request_info.uri:"-", - request && request->request_info.method?request->request_info.method:"-", - request && request->request_info.query_string?request->request_info.query_string:"-", - request?request->request_info.content_length:0); + if(request_info) + SAPI::log(SAPI_info, "%s received while %s. uri=%s, method=%s, qs=%s, cl=%u", + signal_name, + request?"executing code":"reading data", + request_info->uri, + request_info->method, + request_info->query_string, + request_info->content_length); + else + SAPI::log(SAPI_info, "%s received before or after processing request", + signal_name); } #ifdef SIGUSR1 @@ -260,8 +267,9 @@ static void SIGUSR1_handler(int /*sig*/) #ifdef SIGPIPE static void SIGPIPE_handler(int /*sig*/){ log_signal("SIGPIPE"); + execution_canceled=true; if(request) - request->interrupt(); + request->set_interrupted(true); } #endif @@ -282,9 +290,6 @@ static void real_parser_handler( // init global variables pa_globals_init(); - // request pool, must be different ptr from global [used in VStateless_class.add_method] - Pool request_pool; - if(!filespec_to_process || !*filespec_to_process) SAPI::die("Parser/%s", PARSER_VERSION); @@ -301,7 +306,7 @@ static void real_parser_handler( request_info.document_root=document_root_buf; } else throw Exception("parser.runtime", - Exception::undefined_source, + 0, "CGI: no PATH_INFO defined(in reinventing DOCUMENT_ROOT)"); } else { full_file_spec("", document_root_buf, sizeof(document_root_buf)); @@ -325,9 +330,9 @@ static void real_parser_handler( request_info.uri=env_request_uri; else if(query_string) { - CharPtr reconstructed_uri(new char[ + char* reconstructed_uri=new(PointerFreeGC) 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); @@ -380,14 +385,18 @@ static void real_parser_handler( request_info.cookie=getenv("HTTP_COOKIE"); request_info.mail_received=mail_received; + // get request_info ptr for signal handlers + ::request_info=&request_info; + if(execution_canceled) + SAPI::die("Execution canceled"); // prepare to process request - Request request(request_pool, SAPI_info, + Request request(SAPI_info, request_info, /*#ifdef _DEBUG - String::UL_HTML|String::UL_OPTIMIZE_BIT + String::L_HTML|String::L_OPTIMIZE_BIT #else*/ - cgi ? String::UL_HTML|String::UL_OPTIMIZE_BIT : String::UL_AS_IS + cgi ? String::Language(String::L_HTML|String::L_OPTIMIZE_BIT) : String::L_AS_IS /*#endif*/ , true /* status_allowed */); @@ -433,7 +442,7 @@ static void real_parser_handler( pa_done_socks(); #ifdef DEBUG_POOL_MALLOC - extern void log_pool_stats(Pool& pool); + extern void log_pool_stats(); log_pool_stats(request_pool); #endif } @@ -487,16 +496,16 @@ static void call_real_parser_handler__do 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, + throw Exception(0, + 0, "Exception 0x%08X at 0x%08X", er->ExceptionCode, er->ExceptionAddress); else - throw Exception(Exception::undefined_type, - Exception::undefined_source, + throw Exception(0, + 0, "Exception "); else - throw Exception(Exception::undefined_type, - Exception::undefined_source, + throw Exception(0, + 0, "Exception "); #endif } @@ -519,6 +528,21 @@ static void usage(const char* program) { } int main(int argc, char *argv[]) { + GC_java_finalization=0; + +#ifndef PA_DEBUG_DISABLE_GC +// GC_dont_gc=1; // Dont collect unless explicitly requested +#endif + + /* + Array test; + test+=3; + test+=4; +// int a=test.count(); + int b=test.get(0); +// int b=test.get(10); + printf("%d", b);//test.count());*/ + #ifdef SIGUSR1 if(signal(SIGUSR1, SIGUSR1_handler)==SIG_ERR) SAPI::die("Can not set handler for SIGUSR1"); @@ -605,7 +629,10 @@ int main(int argc, char *argv[]) { // Set flag to the new value _CrtSetDbgFlag( tmpFlag ); -// _CrtSetBreakAlloc(266630); + //_CrtSetBreakAlloc(62143); //147302 + + _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); + _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR ); #endif char filespec_to_process[MAX_STRING];