|
|
| version 1.245.2.37.2.7, 2003/03/21 15:36:04 | version 1.245.2.37.2.18, 2003/03/27 14:51:28 |
|---|---|
| Line 30 static const char* IDENT_REQUEST_C="$Dat | Line 30 static const char* IDENT_REQUEST_C="$Dat |
| #include "pa_vform.h" | #include "pa_vform.h" |
| #include "pa_vcookie.h" | #include "pa_vcookie.h" |
| #include "pa_vresponse.h" | #include "pa_vresponse.h" |
| #include "pa_vmemory.h" | |
| // consts | // consts |
| Line 81 static const String class_path_name(CLAS | Line 82 static const String class_path_name(CLAS |
| // defines | // defines |
| // op.C | // op.C |
| VStateless_class* VClassMAIN_create(); | VStateless_class& VClassMAIN_create(); |
| // op.C | // op.C |
| VHash& exception2vhash(const Exception& e); | VHash& exception2vhash(const Exception& e); |
| Line 110 Request::Request(SAPI_Info& asapi_info, | Line 111 Request::Request(SAPI_Info& asapi_info, |
| request_info(arequest_info), | request_info(arequest_info), |
| charsets(UTF8_charset, UTF8_charset, UTF8_charset), // default charsets | charsets(UTF8_charset, UTF8_charset, UTF8_charset), // default charsets |
| main_class(*VClassMAIN_create()), | main_class(VClassMAIN_create()), |
| form(*new VForm), | form(*new VForm), |
| mail(*new VMail), | mail(*new VMail), |
| response(*new VResponse(arequest_info, charsets)), | response(*new VResponse(arequest_info, charsets)), |
| Line 136 Request::Request(SAPI_Info& asapi_info, | Line 137 Request::Request(SAPI_Info& asapi_info, |
| /// methodless | /// methodless |
| // env class | // 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 | // status class |
| if(status_allowed) | if(status_allowed) |
| classes().put(*new StringBody(STATUS_CLASS_NAME), new VStatus()); | classes().put(StringBody(STATUS_CLASS_NAME), new VStatus()); |
| // request class | // 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 | // cookie class |
| classes().put(*new StringBody(COOKIE_CLASS_NAME), &cookie); | classes().put(StringBody(COOKIE_CLASS_NAME), &cookie); |
| /// methoded | /// methoded |
| // response class | // response class |
| Line 159 Request::Request(SAPI_Info& asapi_info, | Line 160 Request::Request(SAPI_Info& asapi_info, |
| Value& math=*new VMath; | Value& math=*new VMath; |
| classes().put(math.get_class()->base_class()->name(), &math); | 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() { | Request::~Request() { |
| Line 176 Value& Request::get_self() { return meth | Line 182 Value& Request::get_self() { return meth |
| static void load_charset(HashStringValue::key_type akey, HashStringValue::value_type avalue, int) { | 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()); | ::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) | if(configure_admin_done) |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| source, | 0, |
| "parser already configured"); | "parser already configured"); |
| configure_admin_done=true; | configure_admin_done=true; |
| Line 250 gettimeofday(&mt[0],NULL); | Line 256 gettimeofday(&mt[0],NULL); |
| while(const char* before=strchr(after, '/')) { | while(const char* before=strchr(after, '/')) { |
| String& sfile_spec=*new String; | String& sfile_spec=*new String; |
| if(after!=request_info.path_translated) { | if(after!=request_info.path_translated) { |
| sfile_spec.append( | sfile_spec.append_strdup( |
| request_info.path_translated, before-request_info.path_translated, | request_info.path_translated, before-request_info.path_translated, |
| String::L_CLEAN); | String::L_CLEAN); |
| sfile_spec << "/" AUTO_FILE_NAME; | sfile_spec << "/" AUTO_FILE_NAME; |
| Line 265 gettimeofday(&mt[0],NULL); | Line 271 gettimeofday(&mt[0],NULL); |
| // compile requested file | // compile requested file |
| String& spath_translated=*new String; | 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, | use_file(main_class, |
| spath_translated, true/* ignore class_path */, | spath_translated, true/* ignore class_path */, |
| true/* fail on read problem*/, true/* fail on abscence */); | true/* fail on read problem*/, true/* fail on abscence */); |
| // configure method_frame options if not configured yet | // configure method_frame options if not configured yet |
| if(!configure_admin_done) | if(!configure_admin_done) |
| configure_admin(main_class, 0); | configure_admin(main_class); |
| // configure not-method_frame=user options | // configure not-method_frame=user options |
| methoded_array().configure_user(*this); | methoded_array().configure_user(*this); |
| Line 324 gettimeofday(&mt[2],NULL); | Line 330 gettimeofday(&mt[2],NULL); |
| } | } |
| VFile* body_file=body_vstring_after_post_process->as_vfile( | VFile* body_file=body_vstring_after_post_process->as_vfile( |
| String::L_UNSPECIFIED); | String::L_UNSPECIFIED, &charsets); |
| // extract response body | // extract response body |
| Value* body_value=response.fields().get(download_name); | Value* body_value=response.fields().get(download_name); |
| Line 333 gettimeofday(&mt[2],NULL); | Line 339 gettimeofday(&mt[2],NULL); |
| body_value=response.fields().get(body_name); | body_value=response.fields().get(body_name); |
| if(body_value) // there is some $response:body | 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 | #ifdef RESOURCES_DEBUG |
| //measure:after postprocess | //measure:after postprocess |
| Line 408 t[9]-t[3] | Line 414 t[9]-t[3] |
| frame.store_param(exception2vhash(e)); | frame.store_param(exception2vhash(e)); |
| // $stack[^table::set{name origin}] | // $stack[^table::set{name origin}] |
| Table::columns_type stack_trace_columns(new ArrayString); | Table::columns_type stack_trace_columns(new ArrayString); |
| *stack_trace_columns+=*new StringBody("name")); | *stack_trace_columns+=new String("name"); |
| *stack_trace_columns+=*new StringBody("file")); | *stack_trace_columns+=new String("file"); |
| *stack_trace_columns+=*new StringBody("lineno")); | *stack_trace_columns+=new String("lineno"); |
| Table* stack_trace(new Table(0, stack_trace_columns)); | Table& stack_trace=*new Table(stack_trace_columns); |
| Array_iterator<String*> tracei(exception_trace); | /*Array_iterator<String*> tracei(exception_trace); |
| while(tracei.has_next()) { | while(tracei.has_next()) { |
| Table::element_type row(new ArrayString); | Table::element_type row(new ArrayString); |
| const String& name=tracei.next(); | const String* name=tracei.next(); |
| *row+=name; // name column | *row+=name; // name column |
| #ifndef NO_STRING_ORIGIN | #ifndef NO_STRING_ORIGIN |
| const String_fragment::Origin& origin=name->origin(); | const String_fragment::Origin& origin=name->origin(); |
| if(origin.file) { | if(origin.file) { |
| *row+=*new StringBody(origin.file, 0, true)); // file column | *row+=StringBody(origin.file, 0, true)); // file column |
| *row+=*new StringBody( | *row+=StringBody( |
| pool().format_integer(1+origin.line), | pool().format_integer(1+origin.line), |
| 0, true)); // line column | 0, true)); // line column |
| } | } |
| #endif | #endif |
| *stack_trace+=row; | *stack_trace+=row; |
| } | }*/ |
| frame.store_param(new VTable(stack_trace))); | frame.store_param(*new VTable(&stack_trace)); |
| // future $response:body= | // future $response:body= |
| // execute ^unhandled_exception[exception;stack] | // execute ^unhandled_exception[exception;stack] |
| body_string=execute_method(frame, *method); | body_string=&execute_method(frame, *method); |
| } | } |
| } | } |
| } | } |
| Line 442 t[9]-t[3] | Line 448 t[9]-t[3] |
| // doing that ugly | // doing that ugly |
| // make up result: $origin $source $comment $type $code | // 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; | size_t printed=0; |
| if(const String* problem_source=e.problem_source()) { | 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) | if(origin.file) |
| printed+=snprintf(buf+printed, MAX_STRING-printed, | printed+=snprintf(buf+printed, MAX_STRING-printed, |
| ORIGIN_FILE_LINE_FORMAT": ", | ORIGIN_FILE_LINE_FORMAT": ", |
| origin.file, 1+origin.line | origin.file, 1+origin.line |
| ); | ); |
| #endif | |
| printed+=snprintf(buf+printed, MAX_STRING-printed, "'%s' ", | printed+=snprintf(buf+printed, MAX_STRING-printed, "'%s' ", |
| problem_source->cstr().get()); | problem_source->cstr().get()); |
| */ | |
| } | } |
| if(const char* comment=e.comment(true)) | if(const char* comment=e.comment(true)) |
| printed+=snprintf(buf+printed, MAX_STRING-printed, "%s", comment); | printed+=snprintf(buf+printed, MAX_STRING-printed, "%s", comment); |
| Line 463 t[9]-t[3] | Line 468 t[9]-t[3] |
| // future $response:content-type | // future $response:content-type |
| response.fields().put(content_type_name, | 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 | // 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(); | VFile* body_file=body_vstring.as_vfile(String::L_UNSPECIFIED, &charsets); |
| // ERROR. write it out | // ERROR. write it out |
| output_result(body_file, header_only, false); | output_result(body_file, header_only, false); |
| Line 487 void Request::use_file(VStateless_class& | Line 492 void Request::use_file(VStateless_class& |
| return; | return; |
| used_files.put(file_name, true); | used_files.put(file_name, true); |
| const String& file_spec; | const String* file_spec; |
| if(ignore_class_path) // ignore_class_path? | if(ignore_class_path) // ignore_class_path? |
| file_spec=file_name; | file_spec=&file_name; |
| else if(file_name->first_char()=='/') //absolute path, no need to scan MAIN:CLASS_PATH? | else if(file_name.first_char()=='/') //absolute path, no need to scan MAIN:CLASS_PATH? |
| file_spec=absolute(file_name); | file_spec=&absolute(file_name); |
| else { | else { |
| file_spec=0; | file_spec=0; |
| if(Value* element=main_class.get_element(class_path_name, main_class, false)) { | if(Value* element=main_class.get_element(class_path_name, main_class, false)) { |
| if(element->is_string()) { | 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()) { | } else if(Table *table=element->get_table()) { |
| int size=table->count(); | int size=table->count(); |
| for(int i=size; i--; ) { | for(int i=size; i--; ) { |
| const String& path=(*table->get(i))[0]; | const String& path=*(*table->get(i))[0]; |
| if(file_spec=file_readable(*absolute(path), *file_name)) | if(file_spec=file_readable(absolute(path), file_name)) |
| break; // found along class_path | break; // found along class_path |
| } | } |
| } else | } else |
| Line 510 void Request::use_file(VStateless_class& | Line 515 void Request::use_file(VStateless_class& |
| "$" CLASS_PATH_NAME " must be string or table"); | "$" CLASS_PATH_NAME " must be string or table"); |
| if(!file_spec) | if(!file_spec) |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| file_name, | &file_name, |
| "not found along " MAIN_CLASS_NAME ":" CLASS_PATH_NAME); | "not found along " MAIN_CLASS_NAME ":" CLASS_PATH_NAME); |
| } | } |
| if(!file_spec) | if(!file_spec) |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| file_name, | &file_name, |
| "usage failed - no $" MAIN_CLASS_NAME ":" CLASS_PATH_NAME " were specified"); | "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(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; | return; |
| if(const char* source=file_read_text(charsets.source(), file_spec, fail_on_read_problem)) | 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_spec, file_spec->cstr()); |
| } | } |
| Line 532 void Request::use_buf(VStateless_class& | Line 537 void Request::use_buf(VStateless_class& |
| const char* source, | const char* source, |
| const String& filespec, const char* filespec_cstr) { | const String& filespec, const char* filespec_cstr) { |
| // temporary zero @conf so to maybe-replace it in compiled code | // 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 | // 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 | // 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 | // 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, | Execute_nonvirtual_method_result executed=execute_nonvirtual_method(cclass, |
| conf_method_name, vfilespec, | conf_method_name, vfilespec, |
| false/*no string result needed*/); | false/*no string result needed*/); |
| if(executed.method) | if(executed.method) |
| configure_admin(cclass, executed.method->name); | configure_admin(cclass/*, executed.method->name*/); |
| // locate and execute possible @auto[] static | // locate and execute possible @auto[] static |
| execute_nonvirtual_method(cclass, | execute_nonvirtual_method(cclass, |
| Line 554 void Request::use_buf(VStateless_class& | Line 559 void Request::use_buf(VStateless_class& |
| } | } |
| const String& Request::relative(const char* apath, const String& relative_name) { | const String& Request::relative(const char* apath, const String& relative_name) { |
| char *hpath=pool().copy(apath); | char *hpath=strdup(apath); |
| const String& result(new String); | String& result=*new String; |
| if(rsplit(hpath, '/')) // if something/splitted | if(rsplit(hpath, '/')) // if something/splitted |
| *result << hpath << "/"; | result << hpath << "/"; |
| *result << relative_name; | result << relative_name; |
| return result; | return result; |
| } | } |
| const String& Request::absolute(const String& relative_name) { | const String& Request::absolute(const String& relative_name) { |
| if(relative_name->first_char()=='/') { | if(relative_name.first_char()=='/') { |
| const String& result=*new StringBody(request_info.document_root)); | String& result=*new String(strdup(request_info.document_root)); |
| *result << relative_name; | result << relative_name; |
| return result; | return result; |
| } else | } 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" | :relative_name; // something like "http://xxx" |
| } | } |
| static void add_header_attribute( | static void add_header_attribute( |
| HashStringValue::key_type aattribute, | HashStringValue::key_type aattribute, |
| HashStringValue::value_type ameaning, | HashStringValue::value_type ameaning, |
| Request *r) { | Request *r) { |
| if(*aattribute==BODY_NAME | if(aattribute==BODY_NAME |
| || *aattribute==DOWNLOAD_NAME | || aattribute==DOWNLOAD_NAME |
| || *aattribute==CHARSET_NAME) | || aattribute==CHARSET_NAME) |
| return; | return; |
| SAPI::add_header_attribute(r->sapi_info, | SAPI::add_header_attribute(r->sapi_info, |
| aattribute->cstr(), | aattribute.cstr(), |
| attributed_meaning_to_string(r->ameaning, String::L_HTTP_HEADER, false)-> | attributed_meaning_to_string(*ameaning, String::L_HTTP_HEADER, false). |
| cstr(String::L_UNSPECIFIED)); | cstr(String::L_UNSPECIFIED)); |
| } | } |
| void Request::output_result(VFile* body_file, bool header_only, bool as_attachment) { | void Request::output_result(VFile* body_file, bool header_only, bool as_attachment) { |
| // header: cookies | // header: cookies |
| cookie->output_result(sapi_info); | cookie.output_result(sapi_info); |
| Value* body_file_content_type; | Value* body_file_content_type; |
| // set content-type | // set content-type |
| Line 598 void Request::output_result(VFile* body_ | Line 604 void Request::output_result(VFile* body_ |
| } else { | } else { |
| // default content type | // default content type |
| response.fields().put_dont_replace(content_type_name, | response.fields().put_dont_replace(content_type_name, |
| new VString(*new StringBody(DEFAULT_CONTENT_TYPE))))); | new VString(*new String(DEFAULT_CONTENT_TYPE))); |
| } | } |
| // content-disposition | // content-disposition |
| if(Value* vfile_name=body_file->fields().get(name_name)) | if(Value* vfile_name=body_file->fields().get(name_name)) |
| if(*vfile_name->get_string(&fpool)!=NONAME_DAT) { | if(*vfile_name->get_string()!=NONAME_DAT) { |
| VHash* hash(new VHash); | VHash& hash=*new VHash(); |
| HashStringValue &h=hash->hash(0); | HashStringValue &h=hash.hash(); |
| if(as_attachment) | 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); | 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 | // prepare header: $response:fields without :body |
| Line 649 const String& Request::mime_type_of(cons | Line 655 const String& Request::mime_type_of(cons |
| if(const char* cext=strrchr(user_file_name_cstr, '.')) { | if(const char* cext=strrchr(user_file_name_cstr, '.')) { |
| String sext(++cext); | String sext(++cext); |
| if(mime_types->locate(0, sext.change_case(charsets.source(), String::CC_LOWER))) | if(mime_types->locate(0, sext.change_case(charsets.source(), String::CC_LOWER))) |
| if(const String& result=mime_types->item(1)) | if(const String* result=mime_types->item(1)) |
| return result; | return *result; |
| else | else |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| mime_types->origin_string(), | 0, |
| MIME_TYPES_NAME " table column elements must not be empty"); | MIME_TYPES_NAME " table column elements must not be empty"); |
| } | } |
| return *new StringBody("application/octet-stream")); | return *new String("application/octet-stream"); |
| } | } |
| #ifdef XML | #ifdef XML |
| GdomeDOMString_auto_ptr Request::transcode(const String& s) { | GdomeDOMString_auto_ptr Request::transcode(const String& s) { |
| return charsets.source().transcode(s); | return charsets.source().transcode(s); |
| } | } |
| const String& Request::transcode(GdomeDOMString* s | GdomeDOMString_auto_ptr Request::transcode(const StringBody s) { |
| #ifndef NO_STRING_ORIGIN | return charsets.source().transcode(s); |
| , const String& origin | |
| #endif | |
| ) { | |
| return charsets.source().transcode(s | |
| #ifndef NO_STRING_ORIGIN | |
| , origin | |
| #endif | |
| ); | |
| } | } |
| const String& Request::transcode(xmlChar* s | const String& Request::transcode(GdomeDOMString* s) { |
| #ifndef NO_STRING_ORIGIN | return charsets.source().transcode(s); |
| , const String& origin | } |
| #endif | |
| ) { | const String& Request::transcode(xmlChar* s) { |
| return charsets.source().transcode(s | return charsets.source().transcode(s); |
| #ifndef NO_STRING_ORIGIN | |
| , origin | |
| #endif | |
| ); | |
| } | } |
| #endif | #endif |