--- parser3/src/main/pa_request.C 2003/03/21 15:36:04 1.245.2.37.2.7 +++ parser3/src/main/pa_request.C 2003/03/24 17:52:19 1.245.2.37.2.13 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_REQUEST_C="$Date: 2003/03/21 15:36:04 $"; +static const char* IDENT_REQUEST_C="$Date: 2003/03/24 17:52:19 $"; #include "pa_sapi.h" #include "pa_common.h" @@ -81,7 +81,7 @@ static const String class_path_name(CLAS // defines // op.C -VStateless_class* VClassMAIN_create(); +VStateless_class& VClassMAIN_create(); // op.C VHash& exception2vhash(const Exception& e); @@ -96,7 +96,7 @@ Request::Request(SAPI_Info& asapi_info, rcontext(0), wcontext(0), flang(adefault_lang), - fconnection(0), + fconnection(), finterrupted(false), // public @@ -110,7 +110,7 @@ Request::Request(SAPI_Info& asapi_info, request_info(arequest_info), charsets(UTF8_charset, UTF8_charset, UTF8_charset), // default charsets - main_class(*VClassMAIN_create()), + main_class(VClassMAIN_create()), form(*new VForm), mail(*new VMail), response(*new VResponse(arequest_info, charsets)), @@ -136,14 +136,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 @@ -176,10 +176,10 @@ Value& Request::get_self() { return meth static void load_charset(HashStringValue::key_type akey, HashStringValue::value_type avalue, int) { ::charsets.load_charset(*new String(akey, String::L_CLEAN), avalue->as_string()); } -void Request::configure_admin(VStateless_class& conf_class, const String* source) { +void Request::configure_admin(VStateless_class& conf_class) { if(configure_admin_done) throw Exception("parser.runtime", - source, + 0, "parser already configured"); configure_admin_done=true; @@ -272,7 +272,7 @@ gettimeofday(&mt[0],NULL); // configure method_frame options if not configured yet if(!configure_admin_done) - configure_admin(main_class, 0); + configure_admin(main_class); // configure not-method_frame=user options methoded_array().configure_user(*this); @@ -408,32 +408,32 @@ t[9]-t[3] frame.store_param(exception2vhash(e)); // $stack[^table::set{name origin}] Table::columns_type stack_trace_columns(new ArrayString); - *stack_trace_columns+=*new StringBody("name")); - *stack_trace_columns+=*new StringBody("file")); - *stack_trace_columns+=*new StringBody("lineno")); - Table* stack_trace(new Table(0, stack_trace_columns)); - Array_iterator tracei(exception_trace); + *stack_trace_columns+=new String("name"); + *stack_trace_columns+=new String("file"); + *stack_trace_columns+=new String("lineno"); + Table& stack_trace=*new Table(stack_trace_columns); + /*Array_iterator tracei(exception_trace); while(tracei.has_next()) { Table::element_type row(new ArrayString); - const String& name=tracei.next(); + 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( + *row+=StringBody(origin.file, 0, true)); // file column + *row+=StringBody( pool().format_integer(1+origin.line), 0, true)); // line column } #endif *stack_trace+=row; - } - frame.store_param(new VTable(stack_trace))); + }*/ + frame.store_param(*new VTable(&stack_trace)); // future $response:body= // execute ^unhandled_exception[exception;stack] - body_string=execute_method(frame, *method); + body_string=&execute_method(frame, *method); } } } @@ -442,19 +442,18 @@ 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()) { -#ifndef NO_STRING_ORIGIN - const String_fragment::Origin& origin=problem_source->origin(); + /*const String_fragment::Origin& origin=problem_source->origin(); if(origin.file) printed+=snprintf(buf+printed, MAX_STRING-printed, ORIGIN_FILE_LINE_FORMAT": ", origin.file, 1+origin.line ); -#endif printed+=snprintf(buf+printed, MAX_STRING-printed, "'%s' ", problem_source->cstr().get()); + */ } if(const char* comment=e.comment(true)) printed+=snprintf(buf+printed, MAX_STRING-printed, "%s", comment); @@ -463,12 +462,12 @@ t[9]-t[3] // future $response:content-type response.fields().put(content_type_name, - new VString(*new StringBody(UNHANDLED_EXCEPTION_CONTENT_TYPE))))); + new VString(*new String(UNHANDLED_EXCEPTION_CONTENT_TYPE))); // future $response:body - body_string=*new StringBody(buf)); + body_string=new String(buf); } - VString body_vstring(body_string); + VString body_vstring(*body_string); VFile* body_file=body_vstring.as_vfile(); // ERROR. write it out @@ -487,21 +486,21 @@ void Request::use_file(VStateless_class& return; used_files.put(file_name, true); - const String& file_spec; + const String* file_spec; if(ignore_class_path) // ignore_class_path? - file_spec=file_name; - else if(file_name->first_char()=='/') //absolute path, no need to scan MAIN:CLASS_PATH? - file_spec=absolute(file_name); + file_spec=&file_name; + else if(file_name.first_char()=='/') //absolute path, no need to scan MAIN:CLASS_PATH? + file_spec=&absolute(file_name); else { file_spec=0; if(Value* element=main_class.get_element(class_path_name, main_class, false)) { if(element->is_string()) { - file_spec=file_readable(*absolute(element->as_string()), *file_name); // found at class_path? + file_spec=file_readable(absolute(element->as_string()), file_name); // found at class_path? } else if(Table *table=element->get_table()) { int size=table->count(); for(int i=size; i--; ) { - const String& path=(*table->get(i))[0]; - if(file_spec=file_readable(*absolute(path), *file_name)) + const String& path=*(*table->get(i))[0]; + if(file_spec=file_readable(absolute(path), file_name)) break; // found along class_path } } else @@ -510,21 +509,21 @@ void Request::use_file(VStateless_class& "$" CLASS_PATH_NAME " must be string or table"); if(!file_spec) throw Exception("parser.runtime", - file_name, + &file_name, "not found along " MAIN_CLASS_NAME ":" CLASS_PATH_NAME); } if(!file_spec) throw Exception("parser.runtime", - file_name, + &file_name, "usage failed - no $" MAIN_CLASS_NAME ":" CLASS_PATH_NAME " were specified"); } if(fail_on_read_problem && !fail_on_file_absence) // ignore file absence if asked for - if(!entry_exists(file_spec)) + if(!entry_exists(*file_spec)) return; - if(const char* source=file_read_text(charsets.source(), file_spec, fail_on_read_problem)) - use_buf(aclass, source, file_spec, file_spec->cstr()); + if(const char* source=file_read_text(charsets.source(), *file_spec, fail_on_read_problem)) + use_buf(aclass, source, *file_spec, file_spec->cstr()); } @@ -532,20 +531,20 @@ void Request::use_buf(VStateless_class& const char* source, const String& filespec, const char* filespec_cstr) { // temporary zero @conf so to maybe-replace it in compiled code - Temp_method temp_method_conf(aclass, conf_method_name, Method*(0)); + 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, Method*(0)); + 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, filespec_cstr); // locate and execute possible @conf[] static - const VString& vfilespec(new VString(filespec)); + VString* vfilespec=new VString(filespec); Execute_nonvirtual_method_result executed=execute_nonvirtual_method(cclass, conf_method_name, vfilespec, false/*no string result needed*/); if(executed.method) - configure_admin(cclass, executed.method->name); + configure_admin(cclass/*, executed.method->name*/); // locate and execute possible @auto[] static execute_nonvirtual_method(cclass, @@ -554,41 +553,42 @@ void Request::use_buf(VStateless_class& } const String& Request::relative(const char* apath, const String& relative_name) { - char *hpath=pool().copy(apath); - const String& result(new String); - if(rsplit(hpath, '/')) // if something/splitted - *result << hpath << "/"; - *result << relative_name; - return result; + char *hpath=strdup(apath); + String& result=*new String; + if(rsplit(hpath, '/')) // if something/splitted + result << hpath << "/"; + result << relative_name; + return result; } const String& Request::absolute(const String& relative_name) { - if(relative_name->first_char()=='/') { - const String& result=*new StringBody(request_info.document_root)); - *result << relative_name; + if(relative_name.first_char()=='/') { + String& result=*new String(strdup(request_info.document_root)); + 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" } static void add_header_attribute( - HashStringValue::key_type aattribute, - HashStringValue::value_type ameaning, - Request *r) { - if(*aattribute==BODY_NAME - || *aattribute==DOWNLOAD_NAME - || *aattribute==CHARSET_NAME) + HashStringValue::key_type aattribute, + HashStringValue::value_type ameaning, + Request *r) { + if(aattribute==BODY_NAME + || aattribute==DOWNLOAD_NAME + || aattribute==CHARSET_NAME) return; SAPI::add_header_attribute(r->sapi_info, - aattribute->cstr(), - attributed_meaning_to_string(r->ameaning, String::L_HTTP_HEADER, false)-> + aattribute.cstr(), + 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) { // header: cookies - cookie->output_result(sapi_info); + cookie.output_result(sapi_info); Value* body_file_content_type; // set content-type @@ -598,18 +598,18 @@ void Request::output_result(VFile* body_ } else { // default content type response.fields().put_dont_replace(content_type_name, - new VString(*new StringBody(DEFAULT_CONTENT_TYPE))))); + new VString(*new String(DEFAULT_CONTENT_TYPE))); } // content-disposition if(Value* vfile_name=body_file->fields().get(name_name)) - if(*vfile_name->get_string(&fpool)!=NONAME_DAT) { - VHash* hash(new VHash); - HashStringValue &h=hash->hash(0); + if(*vfile_name->get_string()!=NONAME_DAT) { + VHash& hash=*new VHash(); + HashStringValue &h=hash.hash(); if(as_attachment) - h.put(value_name, new VString(content_disposition_value))); + h.put(value_name, new VString(content_disposition_value)); h.put(content_disposition_filename_name, vfile_name); - response.fields().put(content_disposition_name, hash); + response.fields().put(content_disposition_name, &hash); } // prepare header: $response:fields without :body @@ -649,44 +649,27 @@ const String& Request::mime_type_of(cons if(const char* cext=strrchr(user_file_name_cstr, '.')) { String sext(++cext); if(mime_types->locate(0, sext.change_case(charsets.source(), String::CC_LOWER))) - if(const String& result=mime_types->item(1)) - return result; + if(const String* result=mime_types->item(1)) + return *result; else throw Exception("parser.runtime", - mime_types->origin_string(), + 0, MIME_TYPES_NAME " table column elements must not be empty"); } - return *new StringBody("application/octet-stream")); + return *new String("application/octet-stream"); } #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 - ); +const String& Request::transcode(GdomeDOMString* 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(xmlChar* s) { + return charsets.source().transcode(s); } #endif