--- parser3/src/targets/cgi/parser3.C 2001/10/22 16:44:43 1.124 +++ parser3/src/targets/cgi/parser3.C 2001/11/16 12:38:44 1.136 @@ -2,15 +2,16 @@ Parser: scripting and CGI main. Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Author: Alexander Petrosyan (http://paf.design.ru) - $Id: parser3.C,v 1.124 2001/10/22 16:44:43 parser Exp $ + $Id: parser3.C,v 1.136 2001/11/16 12:38:44 paf Exp $ */ #include "pa_config_includes.h" #ifdef WIN32 # include +# include #endif #include "pa_sapi.h" @@ -19,6 +20,7 @@ #include "pa_request.h" #include "pa_socks.h" #include "pa_version.h" +#include "pool_storage.h" #ifdef XML #include @@ -58,7 +60,8 @@ const char **RCSIds[]={ const size_t READ_POST_CHUNK_SIZE=0x400*0x400; // 1M const char *argv0; -Pool pool(0); // global pool [dont describe to doxygen: it confuses it with param names] +Pool_storage pool_storage; +Pool pool(&pool_storage); // global pool [dont describe to doxygen: it confuses it with param names] bool cgi; ///< we were started as CGI? // SAPI @@ -113,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); } @@ -125,7 +148,7 @@ size_t SAPI::read_post(Pool& , char *buf do { int chunk_size=read(fileno(stdin), buf+read_size, min(READ_POST_CHUNK_SIZE, max_bytes-read_size)); - if(chunk_size<0) + if(chunk_size<=0) break; read_size+=chunk_size; } while(read_size(http://design.ru/paf)\n" + "Author: Alexander Petrosyan (http://paf.design.ru)\n" "\n" "Usage: %s \n", PARSER_VERSION, @@ -387,40 +422,29 @@ int main(int argc, char *argv[]) { const char *request_method=getenv("REQUEST_METHOD"); bool header_only=request_method && strcasecmp(request_method, "HEAD")==0; + +#ifdef WIN32 + _set_new_handler(failed_new); +#endif + +#ifdef HAVE_SET_NEW_HANDLER + 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 - const char *body=e.comment(); - // log it - SAPI::log(pool, "exception in request exception handler: %s", 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); - - // unsuccessful finish - result=1; + SAPI::die("exception in request exception handler: ", e.comment()); +#ifndef _DEBUG + } catch(...) { + SAPI::die(""); +#endif } @@ -429,5 +453,5 @@ int main(int argc, char *argv[]) { if(!cgi) SAPI::send_body(pool, "\n", 1); #endif - return result; + return 0; }