--- parser3/src/main/pa_request.C 2015/10/20 18:17:19 1.348 +++ parser3/src/main/pa_request.C 2016/04/01 16:27:32 1.352 @@ -1,7 +1,7 @@ /** @file Parser: request class main part. @see compile.C and execute.C. - Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ @@ -32,7 +32,7 @@ #include "pa_vconsole.h" #include "pa_vdate.h" -volatile const char * IDENT_PA_REQUEST_C="$Id: pa_request.C,v 1.348 2015/10/20 18:17:19 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H; +volatile const char * IDENT_PA_REQUEST_C="$Id: pa_request.C,v 1.352 2016/04/01 16:27:32 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H; // consts @@ -154,7 +154,7 @@ Request::Request(SAPI_Info& asapi_info, /// directly used // MAIN class, operators - classes().put(main_class.name(), &main_class); + classes().put(main_class.type(), &main_class); // classes: // table, file, random, mail, image, ... methoded_array().register_directly_used(*this); @@ -172,22 +172,22 @@ Request::Request(SAPI_Info& asapi_info, classes().put(CONSOLE_CLASS_NAME, &console); /// methoded // response class - classes().put(response.get_class()->name(), &response); + classes().put(response.get_class()->type(), &response); /// bases used // form class - classes().put(form.get_class()->base_class()->name(), &form); + classes().put(form.get_class()->base_class()->type(), &form); // mail class - classes().put(mail.get_class()->base_class()->name(), &mail); + classes().put(mail.get_class()->base_class()->type(), &mail); // math class { Value& math=*new VMath; - classes().put(math.get_class()->base_class()->name(), &math); + classes().put(math.get_class()->base_class()->type(), &math); } // memory class { Value& memory=*new VMemory; - classes().put(memory.get_class()->base_class()->name(), &memory); + classes().put(memory.get_class()->base_class()->type(), &memory); } } @@ -271,42 +271,40 @@ void Request::configure_admin(VStateless methoded_array().configure_admin(*this); } -const char* Request::get_exception_cstr( - const Exception& e, - Request::Exception_details& details) { +const char* Request::get_exception_cstr(const Exception& e, Request::Exception_details& details) { + #define PA_URI_FORMAT "%s: " +#define PA_COMMENT_TYPE_FORMAT "%s [%s]" + #define PA_ORIGIN_FILE_POS_FORMAT "%s(%d:%d): " #define PA_SOURCE_FORMAT "'%s' " -#define PA_COMMENT_TYPE_FORMAT "%s [%s]" + +#define PA_ORIGIN_FILE_POS_VALUE file_list[details.origin.file_no].cstr(), 1+details.origin.line, 1+details.origin.col, +#define PA_SOURCE_VALUE details.problem_source->cstr(), + +#define EXCEPTION_CSTR(f1,v1,f2,v2) \ + snprintf(result, MAX_STRING, \ + PA_URI_FORMAT \ + f1 f2 \ + PA_COMMENT_TYPE_FORMAT, \ + request_info.uri, \ + v1 v2 \ + e.comment(), e.type() \ + ); + char* result=new(PointerFreeGC) char[MAX_STRING]; if(details.problem_source) { // do we know the guy? - if(details.trace) { // do whe know where he came from? - Operation::Origin origin=details.trace.origin(); - snprintf(result, MAX_STRING, - PA_URI_FORMAT - PA_ORIGIN_FILE_POS_FORMAT - PA_SOURCE_FORMAT PA_COMMENT_TYPE_FORMAT, - request_info.uri, - file_list[origin.file_no].cstr(), 1+origin.line, 1+origin.col, - details.problem_source->cstr(), - e.comment(), e.type() - ); - } else - snprintf(result, MAX_STRING, - PA_URI_FORMAT - PA_SOURCE_FORMAT PA_COMMENT_TYPE_FORMAT, - request_info.uri, - details.problem_source->cstr(), - e.comment(), e.type() - ); - } else - snprintf(result, MAX_STRING, - PA_URI_FORMAT - PA_COMMENT_TYPE_FORMAT, - request_info.uri, - e.comment(), e.type() - ); + if(details.origin.file_no) // do whe know where he came from? + EXCEPTION_CSTR(PA_ORIGIN_FILE_POS_FORMAT, PA_ORIGIN_FILE_POS_VALUE, PA_SOURCE_FORMAT, PA_SOURCE_VALUE) + else + EXCEPTION_CSTR(PA_SOURCE_FORMAT, PA_SOURCE_VALUE,,) + } else { + if(details.origin.file_no) // do whe know where he came from? + EXCEPTION_CSTR(PA_ORIGIN_FILE_POS_FORMAT, PA_ORIGIN_FILE_POS_VALUE,,) + else + EXCEPTION_CSTR(,,,) + } return result; } @@ -544,9 +542,7 @@ void Request::use_file_directly(VStatele } -void Request::use_file(VStateless_class& aclass, - const String& file_name, - const String* use_filespec/*absolute*/) { +void Request::use_file(VStateless_class& aclass, const String& file_name, const String* use_filespec/*absolute*/) { if(file_name.is_empty()) throw Exception(PARSER_RUNTIME, @@ -594,6 +590,15 @@ void Request::use_file(VStateless_class& use_file_directly(aclass, *filespec); } +void Request::use_file(VStateless_class& aclass, const String& file_name, const String* use_filespec/*absolute*/, Operation::Origin origin) { + static String use("USE"); + try { + use_file(aclass, file_name, use_filespec); + } catch (...) { + exception_trace.push(Trace(&use, origin)); + rethrow; + } +} void Request::use_buf(VStateless_class& aclass, const char* source, const String* main_alias, @@ -935,45 +940,34 @@ const String& Request::transcode(const x } #endif - -const Request::Trace Request::Exception_trace::extract_origin(const String*& problem_source) { - Trace result; - if(!is_empty()) { - result=bottom_value(); - if(!problem_source) { // we don't know who trigged the bug? - problem_source=result.name(); // consider the stack-top-guy (we usually know source of next-from-throw-point exception) did that - fbottom++; - } else if(result.name()==problem_source) // it is that same guy? - fbottom++; // throw away that trace - else { - // stack top contains not us, - // leaving result intact - // it would help ^throw - } - } - - return result; -} - Request::Exception_details Request::get_details(const Exception& e) { const String* problem_source=e.problem_source(); - Trace trace=exception_trace.extract_origin(problem_source); - VHash& vhash=*new VHash; HashStringValue& hash=vhash.hash(); + Operation::Origin origin={0, 0, 0}; + + if(!exception_trace.is_empty()) { + Trace bottom=exception_trace.bottom_value(); + origin=bottom.origin(); + if(!problem_source) { // we don't know who trigged the bug + problem_source=bottom.name(); // we usually know source of next-from-throw-point exception did that + exception_trace.set_bottom_index(exception_trace.bottom_index()+1); + } else if (bottom.name()==problem_source) { // it is that same guy? + exception_trace.set_bottom_index(exception_trace.bottom_index()+1); // throw away that trace + } else { + // stack top contains not us, leaving intact to help ^throw + } + } // $.type if(const char* type=e.type(true)) hash.put(exception_type_part_name, new VString(*new String(type))); // $.source - if(problem_source) { - String& source=*new String(*problem_source, String::L_TAINTED); - hash.put(exception_source_part_name, new VString(source)); - } + if(problem_source) + hash.put(exception_source_part_name, new VString(*new String(*problem_source, String::L_TAINTED))); - // $.file lineno colno - if(trace) { - const Operation::Origin origin=trace.origin(); + // $.file $.lineno $.colno + if(origin.file_no){ hash.put("file", new VString(*new String(file_list[origin.file_no], String::L_TAINTED))); hash.put("lineno", new VInt(1+origin.line)); hash.put("colno", new VInt(1+origin.col)); @@ -981,13 +975,12 @@ Request::Exception_details Request::get_ // $.comment if(const char* comment=e.comment(true)) - hash.put(exception_comment_part_name, - new VString(*new String(comment, String::L_TAINTED))); + hash.put(exception_comment_part_name, new VString(*new String(comment, String::L_TAINTED))); // $.handled(0) hash.put(exception_handled_part_name, &VBool::get(false)); - return Request::Exception_details(trace, problem_source, vhash); + return Request::Exception_details(origin, problem_source, vhash); } Temp_value_element::Temp_value_element(Request& arequest, Value& awhere, const String& aname, Value* awhat) :