--- parser3/src/main/pa_request.C 2003/03/24 11:05:28 1.245.2.37.2.9 +++ parser3/src/main/pa_request.C 2003/04/03 06:40:39 1.245.2.37.2.22 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_REQUEST_C="$Date: 2003/03/24 11:05:28 $"; +static const char* IDENT_REQUEST_C="$Date: 2003/04/03 06:40:39 $"; #include "pa_sapi.h" #include "pa_common.h" @@ -30,6 +30,7 @@ static const char* IDENT_REQUEST_C="$Dat #include "pa_vform.h" #include "pa_vcookie.h" #include "pa_vresponse.h" +#include "pa_vmemory.h" // consts @@ -96,7 +97,7 @@ Request::Request(SAPI_Info& asapi_info, rcontext(0), wcontext(0), flang(adefault_lang), - fconnection(), + fconnection(0), finterrupted(false), // public @@ -124,6 +125,9 @@ Request::Request(SAPI_Info& asapi_info, // private mime types mime_types(0) { + // file_no=0 => unknown + file_list+=StringBody("UNKNOWN"); + // maybe expire old caches cache_managers.maybe_expire(); @@ -136,14 +140,14 @@ Request::Request(SAPI_Info& asapi_info, /// methodless // env class - classes().put(*new StringBody(ENV_CLASS_NAME), new VEnv(asapi_info)); + classes().put(StringBody(ENV_CLASS_NAME), new VEnv(asapi_info)); // status class if(status_allowed) - classes().put(*new StringBody(STATUS_CLASS_NAME), new VStatus()); + classes().put(StringBody(STATUS_CLASS_NAME), new VStatus()); // request class - classes().put(*new StringBody(REQUEST_CLASS_NAME), new VRequest(arequest_info, charsets)); + classes().put(StringBody(REQUEST_CLASS_NAME), new VRequest(arequest_info, charsets)); // cookie class - classes().put(*new StringBody(COOKIE_CLASS_NAME), &cookie); + classes().put(StringBody(COOKIE_CLASS_NAME), &cookie); /// methoded // response class @@ -159,6 +163,11 @@ Request::Request(SAPI_Info& asapi_info, Value& math=*new VMath; classes().put(math.get_class()->base_class()->name(), &math); } + // memory class + { + Value& memory=*new VMemory; + classes().put(memory.get_class()->base_class()->name(), &memory); + } } Request::~Request() { @@ -250,7 +259,7 @@ gettimeofday(&mt[0],NULL); while(const char* before=strchr(after, '/')) { String& sfile_spec=*new String; if(after!=request_info.path_translated) { - sfile_spec.append( + sfile_spec.append_strdup( request_info.path_translated, before-request_info.path_translated, String::L_CLEAN); sfile_spec << "/" AUTO_FILE_NAME; @@ -265,7 +274,7 @@ gettimeofday(&mt[0],NULL); // compile requested file String& spath_translated=*new String; - spath_translated.append(request_info.path_translated, 0, String::L_TAINTED); + spath_translated.append_help_length(request_info.path_translated, 0, String::L_TAINTED); use_file(main_class, spath_translated, true/* ignore class_path */, true/* fail on read problem*/, true/* fail on abscence */); @@ -324,7 +333,7 @@ gettimeofday(&mt[2],NULL); } VFile* body_file=body_vstring_after_post_process->as_vfile( - String::L_UNSPECIFIED); + String::L_UNSPECIFIED, &charsets); // extract response body Value* body_value=response.fields().get(download_name); @@ -333,7 +342,7 @@ gettimeofday(&mt[2],NULL); body_value=response.fields().get(body_name); if(body_value) // there is some $response:body - body_file=body_value->as_vfile(); + body_file=body_value->as_vfile(String::L_UNSPECIFIED, &charsets); #ifdef RESOURCES_DEBUG //measure:after postprocess @@ -364,6 +373,8 @@ t[9]-t[3] } catch(const Exception& e) { // request handling problem // we're returning not result, but error explanation try { + //if(size_t top_index=!exception_trace.is_empty()) + // log the beast if(const String* problem_source=e.problem_source()) SAPI::log(sapi_info, @@ -411,24 +422,21 @@ t[9]-t[3] *stack_trace_columns+=new String("name"); *stack_trace_columns+=new String("file"); *stack_trace_columns+=new String("lineno"); + *stack_trace_columns+=new String("colno"); Table& stack_trace=*new Table(stack_trace_columns); - /*Array_iterator tracei(exception_trace); - while(tracei.has_next()) { + for(Array_iterator i(exception_trace); i.has_next(); ) { + Trace trace=i.next(); Table::element_type row(new ArrayString); - const String* name=tracei.next(); - *row+=name; // name column -#ifndef NO_STRING_ORIGIN - const String_fragment::Origin& origin=name->origin(); - if(origin.file) { - *row+=*new StringBody(origin.file, 0, true)); // file column - *row+=*new StringBody( - pool().format_integer(1+origin.line), - 0, true)); // line column + *row+=trace.name(); // name column + Operation::Info origin=trace.origin(); + if(origin.file_no) { + *row+=new String(file_list[origin.file_no], String::L_TAINTED); // 'file' column + *row+=new String(StringBody::Format(1+origin.line), String::L_CLEAN); // 'lineno' column + *row+=new String(StringBody::Format(1+origin.col), String::L_CLEAN); // 'colno' column } -#endif - *stack_trace+=row; - }*/ + stack_trace+=row; + } frame.store_param(*new VTable(&stack_trace)); // future $response:body= @@ -442,7 +450,7 @@ t[9]-t[3] // doing that ugly // make up result: $origin $source $comment $type $code - char *buf=new char[MAX_STRING]; + char *buf=new(PointerFreeGC) char[MAX_STRING]; size_t printed=0; if(const String* problem_source=e.problem_source()) { /*const String_fragment::Origin& origin=problem_source->origin(); @@ -468,7 +476,7 @@ t[9]-t[3] } VString body_vstring(*body_string); - VFile* body_file=body_vstring.as_vfile(); + VFile* body_file=body_vstring.as_vfile(String::L_UNSPECIFIED, &charsets); // ERROR. write it out output_result(body_file, header_only, false); @@ -479,13 +487,14 @@ t[9]-t[3] } void Request::use_file(VStateless_class& aclass, - const String& file_name, bool ignore_class_path, - bool fail_on_read_problem, bool fail_on_file_absence) { + const String& file_name, bool ignore_class_path, + bool fail_on_read_problem, bool fail_on_file_absence) { // cyclic dependence check if(used_files.get(file_name)) return; used_files.put(file_name, true); + const String* file_spec; if(ignore_class_path) // ignore_class_path? file_spec=&file_name; @@ -522,24 +531,26 @@ void Request::use_file(VStateless_class& if(!entry_exists(*file_spec)) return; + file_list+=file_name; if(const char* source=file_read_text(charsets.source(), *file_spec, fail_on_read_problem)) - use_buf(aclass, source, *file_spec, file_spec->cstr()); + use_buf(aclass, source, file_list.count()-1); } void Request::use_buf(VStateless_class& aclass, - const char* source, - const String& filespec, const char* filespec_cstr) { + const char* source, + uint file_no) { // temporary zero @conf so to maybe-replace it in compiled code Temp_method temp_method_conf(aclass, conf_method_name, 0); // temporary zero @auto so to maybe-replace it in compiled code Temp_method temp_method_auto(aclass, auto_method_name, 0); // compile loaded class - VStateless_class& cclass=compile(&aclass, source, filespec_cstr); + VStateless_class& cclass=compile(&aclass, source, file_no); // locate and execute possible @conf[] static - VString* vfilespec=new VString(filespec); + VString* vfilespec= + new VString(*new String(file_list[file_no], String::L_TAINTED)); Execute_nonvirtual_method_result executed=execute_nonvirtual_method(cclass, conf_method_name, vfilespec, false/*no string result needed*/); @@ -567,7 +578,8 @@ const String& Request::absolute(const St result << relative_name; return result; } else - return relative_name.pos("://")<0? relative(request_info.path_translated, relative_name) + return relative_name.pos("://")==STRING_NOT_FOUND? + relative(request_info.path_translated, relative_name) :relative_name; // something like "http://xxx" } @@ -582,7 +594,7 @@ static void add_header_attribute( SAPI::add_header_attribute(r->sapi_info, aattribute.cstr(), - attributed_meaning_to_string(ameaning, String::L_HTTP_HEADER, false). + attributed_meaning_to_string(*ameaning, String::L_HTTP_HEADER, false). cstr(String::L_UNSPECIFIED)); } void Request::output_result(VFile* body_file, bool header_only, bool as_attachment) { @@ -660,32 +672,19 @@ const String& Request::mime_type_of(cons } #ifdef XML - GdomeDOMString_auto_ptr Request::transcode(const String& s) { return charsets.source().transcode(s); } -const String& Request::transcode(GdomeDOMString* s -#ifndef NO_STRING_ORIGIN - , const String& origin -#endif - ) { - return charsets.source().transcode(s -#ifndef NO_STRING_ORIGIN - , origin -#endif - ); +GdomeDOMString_auto_ptr Request::transcode(const StringBody s) { + return charsets.source().transcode(s); } -const String& Request::transcode(xmlChar* s -#ifndef NO_STRING_ORIGIN - , const String& origin -#endif - ) { - return charsets.source().transcode(s -#ifndef NO_STRING_ORIGIN - , origin -#endif - ); +const String& Request::transcode(GdomeDOMString* s) { + return charsets.source().transcode(s); +} + +const String& Request::transcode(xmlChar* s) { + return charsets.source().transcode(s); } #endif