--- parser3/src/main/pa_request.C 2002/04/18 11:41:29 1.202 +++ parser3/src/main/pa_request.C 2002/05/07 07:39:19 1.207 @@ -4,7 +4,7 @@ Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) - $Id: pa_request.C,v 1.202 2002/04/18 11:41:29 paf Exp $ + $Id: pa_request.C,v 1.207 2002/05/07 07:39:19 paf Exp $ */ #include "pa_sapi.h" @@ -22,6 +22,9 @@ #include "pa_charsets.h" #include "pa_charset.h" +const char *POST_PROCESS_METHOD_NAME="postprocess"; +const char *UNHANDLED_EXCEPTION_METHOD_NAME="unhandled_exception"; + /// content type of exception response, when no @MAIN:exception handler defined const char *UNHANDLED_EXCEPTION_CONTENT_TYPE="text/plain"; @@ -43,6 +46,7 @@ Request::Request(Pool& apool, Info& ainfo, uchar adefault_lang, bool status_allowed) : Pooled(apool), + main_method_name(apool, MAIN_METHOD_NAME), stack(apool), OP(*MOP_create(apool)), env(apool), @@ -238,7 +242,7 @@ gettimeofday(&mt[0],NULL); gettimeofday(&mt[1],NULL); #endif // execute @main[] - const String *body_string=execute_virtual_method(*main_class, *main_method_name); + const String *body_string=execute_virtual_method(*main_class, main_method_name); if(!body_string) throw Exception("parser.runtime", 0, @@ -252,7 +256,7 @@ gettimeofday(&mt[2],NULL); VString body_vstring_before_post_process(*body_string); VString *body_vstring_after_post_process=&body_vstring_before_post_process; // @postprocess - if(Value *value=main_class->get_element(*post_process_method_name)) + if(Value *value=main_class->get_element(*NEW String(pool(), POST_PROCESS_METHOD_NAME))) if(Junction *junction=value->get_junction()) if(const Method *method=junction->method) { // preparing to pass parameters to @@ -265,17 +269,17 @@ gettimeofday(&mt[2],NULL); NEW VString(execute_method(frame, *method)); } - bool origins_mode=main_class->get_element(*origins_mode_name)!=0; + bool lorigins_mode=origins_mode(); const VFile *body_file=body_vstring_after_post_process->as_vfile( - String::UL_UNSPECIFIED, origins_mode); + String::UL_UNSPECIFIED, lorigins_mode); // extract response body Value *body_value=static_cast( response.fields().get(*body_name)); if(body_value) // there is some $response.body body_file=body_value->as_vfile(); - else if(origins_mode) + else if(lorigins_mode) response.fields().put(*content_type_name, NEW VString(*NEW String(pool(), ORIGINS_CONTENT_TYPE))); @@ -309,8 +313,7 @@ t[9]-t[3] // we're returning not result, but error explanation try { // log the beast - const String *problem_source=e.problem_source(); - if(problem_source && problem_source->size()) + if(const String *problem_source=e.problem_source()) SAPI::log(pool(), "%s: " #ifndef NO_STRING_ORIGIN @@ -324,15 +327,14 @@ t[9]-t[3] #endif problem_source->cstr(), e.comment(), - e.type()?e.type():"-" + e.type() ); else SAPI::log(pool(), "%s: " "%s [%s]", info.uri, - e.comment(), - e.type()?e.type():"-" + e.comment(), e.type() ); // reset language to default @@ -347,7 +349,8 @@ t[9]-t[3] if(main_class) { // we've managed to end up with some main_class // maybe we'd be lucky enough as to report an error // in a gracefull way... - if(Value *value=main_class->get_element(*unhandled_exception_method_name)) + if(Value *value=main_class->get_element( + *NEW String(pool(), UNHANDLED_EXCEPTION_METHOD_NAME))) if(Junction *junction=value->get_junction()) if(const Method *method=junction->method) { // preparing to pass parameters to @@ -394,8 +397,7 @@ t[9]-t[3] // make up result: $origin $source $comment $type $code char *buf=(char *)malloc(MAX_STRING); size_t printed=0; - const String *problem_source=e.problem_source(); - if(problem_source) { + if(const String *problem_source=e.problem_source()) { #ifndef NO_STRING_ORIGIN const Origin& origin=problem_source->origin(); if(origin.file) @@ -407,9 +409,9 @@ t[9]-t[3] printed+=snprintf(buf+printed, MAX_STRING-printed, "'%s' ", problem_source->cstr()); } - printed+=snprintf(buf+printed, MAX_STRING-printed, "%s", - e.comment()); - if(const char *type=e.type()) + if(const char *comment=e.comment(true)) + printed+=snprintf(buf+printed, MAX_STRING-printed, "%s", comment); + if(const char *type=e.type(true)) printed+=snprintf(buf+printed, MAX_STRING-printed, " type: %s", type); // future $response:content-type @@ -469,7 +471,7 @@ VStateless_class *Request::use_file(cons if(!file_spec) throw Exception("parser.runtime", &file_name, - "usage failed - no " MAIN_CLASS_NAME ":" CLASS_PATH_NAME " were specified"); + "usage failed - no $" MAIN_CLASS_NAME ":" CLASS_PATH_NAME " were specified"); } char *source=file_read_text(pool(), *file_spec, fail_on_read_problem);