--- parser3/src/targets/cgi/parser3.C 2016/11/27 23:42:26 1.273 +++ parser3/src/targets/cgi/parser3.C 2019/12/25 22:01:03 1.280 @@ -1,11 +1,11 @@ /** @file Parser: scripting and CGI main. - Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.273 2016/11/27 23:42:26 moko Exp $"; +volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.280 2019/12/25 22:01:03 moko Exp $"; #include "pa_config_includes.h" @@ -13,7 +13,6 @@ volatile const char * IDENT_PARSER3_C="$ #include "classes.h" #include "pa_common.h" #include "pa_request.h" -#include "pa_socks.h" #include "pa_version.h" #include "pa_vconsole.h" @@ -28,7 +27,7 @@ volatile const char * IDENT_PARSER3_C="$ // comment remove me after debugging //#define PA_DEBUG_CGI_ENTRY_EXIT "c:\\parser\\debug-parser3.log" -#if _MSC_VER && !defined(_DEBUG) +#if defined(_MSC_VER) && !defined(_DEBUG) # define PA_SUPPRESS_SYSTEM_EXCEPTION #endif @@ -58,7 +57,10 @@ bool execution_canceled=false; // SAPI -class SAPI_Info{} SAPI_info; +class SAPI_Info { +public: + int http_response_code; +} SAPI_info = { 0 }; static void log(const char* fmt, va_list args) { bool opened=false; @@ -233,6 +235,8 @@ 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(strcasecmp(dont_store_key, HTTP_STATUS)==0) + SAPI_info.http_response_code=atoi(dont_store_value); if( cgi && (!request || !request->console.was_used()) ) printf("%s: %s\n", capitalize(dont_store_key), dont_store_value); } @@ -253,9 +257,9 @@ static void full_file_spec(const char* f #ifdef WIN32 || file_name[0] && file_name[1]==':' #endif - ) - strncpy(buf, file_name, buf_size); - else { + ){ + strncpy(buf, file_name, buf_size-1); buf[buf_size-1]=0; + } else { char cwd[MAX_STRING]; snprintf(buf, buf_size, "%s/%s", getcwd(cwd, MAX_STRING) ? cwd : "", file_name); } @@ -297,7 +301,7 @@ static void SIGPIPE_handler(int /*sig*/) execution_canceled=true; if(request) - request->set_interrupted(true); + request->set_skip(Request::SKIP_INTERRUPTED); } #endif @@ -357,10 +361,8 @@ main workhorse wich is tested but seems slow. */ static void real_parser_handler(const char* filespec_to_process, const char* request_method, bool header_only) { - // init socks - pa_socks_init(); - // init global variables + // init libraries pa_globals_init(); if(!filespec_to_process || !*filespec_to_process) @@ -515,11 +517,8 @@ static void real_parser_handler(const ch // ::request cleared in RequestController desctructor to prevent signal handlers from accessing invalid memory } - // finalize global variables + // finalize libraries pa_globals_done(); - - // - pa_socks_done(); } #ifdef PA_SUPPRESS_SYSTEM_EXCEPTION @@ -565,7 +564,7 @@ static void call_real_parser_handler__su static void usage(const char* program) { printf( "Parser/%s\n" - "Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com)\n" + "Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com)\n" "Author: Alexandr Petrosian (http://paf.design.ru)\n" "\n" "Usage: %s [options] file\n" @@ -717,5 +716,5 @@ int main(int argc, char *argv[]) { #ifdef PA_DEBUG_CGI_ENTRY_EXIT log("main: successful return"); #endif - return 0; + return SAPI_info.http_response_code < 100 ? SAPI_info.http_response_code : 0; }