|
|
| version 1.184, 2001/12/14 12:53:48 | version 1.189, 2001/12/21 12:50:18 |
|---|---|
| Line 7 | Line 7 |
| $Id$ | $Id$ |
| */ | */ |
| #include "pa_config_includes.h" | |
| extern "C" unsigned char pcre_default_tables[]; // pcre/chartables.c | |
| #include "pa_sapi.h" | #include "pa_sapi.h" |
| #include "pa_common.h" | #include "pa_common.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| Line 23 extern "C" unsigned char pcre_default_ta | Line 19 extern "C" unsigned char pcre_default_ta |
| #include "pa_vtable.h" | #include "pa_vtable.h" |
| #include "pa_vfile.h" | #include "pa_vfile.h" |
| #include "pa_dictionary.h" | #include "pa_dictionary.h" |
| #include "pa_charset_manager.h" | #include "pa_charsets.h" |
| #include "pa_charset_connection.h" | #include "pa_charset.h" |
| /// content type of exception response, when no @MAIN:exception handler defined | /// content type of exception response, when no @MAIN:exception handler defined |
| const char *UNHANDLED_EXCEPTION_CONTENT_TYPE="text/plain"; | const char *UNHANDLED_EXCEPTION_CONTENT_TYPE="text/plain"; |
| Line 36 const char *ORIGINS_CONTENT_TYPE="text/p | Line 32 const char *ORIGINS_CONTENT_TYPE="text/p |
| Methoded *MOP_create(Pool&); | Methoded *MOP_create(Pool&); |
| static void load_charset(const Hash::Key& akey, Hash::Val *avalue, | static void load_charset(const Hash::Key& akey, Hash::Val *avalue, |
| void *info) { | void *) { |
| Value& value=*static_cast<Value *>(avalue); | Value& value=*static_cast<Value *>(avalue); |
| Hash& CTYPE=*static_cast<Hash *>(info); | |
| Charset_connection& connection= | if(!charsets->get(akey)) // don't we know that charset? |
| charset_manager->get_connection(akey, value.as_string()); | charsets->put(akey, |
| new(charsets->pool()) Charset(charsets->pool(), akey, &value.as_string())); | |
| // charset->transcoder | |
| CTYPE.put(akey, &connection.transcoder()); | |
| } | } |
| // | // |
| Line 62 Request::Request(Pool& apool, | Line 55 Request::Request(Pool& apool, |
| response(apool), | response(apool), |
| cookie(apool), | cookie(apool), |
| fclasses(apool), | fclasses(apool), |
| CTYPE(apool), | |
| fdefault_lang(adefault_lang), flang(adefault_lang), | fdefault_lang(adefault_lang), flang(adefault_lang), |
| info(ainfo), | info(ainfo), |
| post_data(0), post_size(0), | post_data(0), post_size(0), |
| Line 78 Request::Request(Pool& apool, | Line 70 Request::Request(Pool& apool, |
| ,sql_connect_time(0),sql_request_time(0) | ,sql_connect_time(0),sql_request_time(0) |
| #endif | #endif |
| { | { |
| // default charsets | |
| pool().set_source_charset(*utf8_charset); | |
| pool().set_client_charset(*utf8_charset); | |
| // maybe expire old caches | // maybe expire old caches |
| cache_managers->maybe_expire(); | cache_managers->maybe_expire(); |
| Line 144 gettimeofday(&mt[0],NULL); | Line 140 gettimeofday(&mt[0],NULL); |
| true/*ignore class_path*/, root_config_fail_on_read_problem, | true/*ignore class_path*/, root_config_fail_on_read_problem, |
| main_class_name, main_class); | main_class_name, main_class); |
| } | } |
| // charsets must only be specified in root config | |
| // so that users would not interfere | |
| if(main_class) { | if(main_class) { |
| /* $MAIN:CHARSETS[ | /* $MAIN:CHARSETS[ |
| $.charsetname1[/full/path/to/charset/file.cfg] | $.charsetname1[/full/path/to/charset/file.cfg] |
| Line 153 gettimeofday(&mt[0],NULL); | Line 150 gettimeofday(&mt[0],NULL); |
| */ | */ |
| if(Value *vcharsets=main_class->get_element(*charsets_name)) { | if(Value *vcharsets=main_class->get_element(*charsets_name)) { |
| if(Hash *charsets=vcharsets->get_hash(0)) | if(Hash *charsets=vcharsets->get_hash(0)) |
| charsets->for_each(load_charset, &CTYPE); | charsets->for_each(load_charset); |
| else | else |
| throw Exception(0, 0, | throw Exception(0, 0, |
| &vcharsets->name(), | &vcharsets->name(), |
| "must be hash"); | "must be hash"); |
| } | } |
| } | } |
| // configure root options | // configure root options |
| // until someone with less privileges have overriden them | // until someone with less privileges have overriden them |
| OP.configure_admin(*this); | OP.configure_admin(*this); |
| Line 232 gettimeofday(&mt[0],NULL); | Line 228 gettimeofday(&mt[0],NULL); |
| gettimeofday(&mt[1],NULL); | gettimeofday(&mt[1],NULL); |
| #endif | #endif |
| // execute @main[] | // execute @main[] |
| const String *body_string=execute_virtual_method( | const String *body_string=execute_virtual_method(*main_class, *main_method_name); |
| *main_class, *main_method_name); | |
| if(!body_string) | if(!body_string) |
| throw Exception(0,0, | throw Exception(0,0, |
| 0, | 0, |
| Line 258 gettimeofday(&mt[2],NULL); | Line 253 gettimeofday(&mt[2],NULL); |
| frame.store_param(method->name, | frame.store_param(method->name, |
| &body_vstring_before_post_process); | &body_vstring_before_post_process); |
| body_vstring_after_post_process= | body_vstring_after_post_process= |
| NEW VString(*execute_method(frame, *method)); | NEW VString(execute_method(frame, *method)); |
| } | } |
| bool origins_mode=main_class->get_element(*origins_mode_name)!=0; | bool origins_mode=main_class->get_element(*origins_mode_name)!=0; |
| Line 431 t[9]-t[3] | Line 426 t[9]-t[3] |
| // future $response:body= | // future $response:body= |
| // execute ^exception[origin;source;comment;type;code;stack] | // execute ^exception[origin;source;comment;type;code;stack] |
| body_string=execute_method(frame, *method); | body_string=&execute_method(frame, *method); |
| } | } |
| } | } |
| Line 503 VStateless_class *Request::use_file(cons | Line 498 VStateless_class *Request::use_file(cons |
| if(main_class) | if(main_class) |
| if(Value *element=main_class->get_element(*class_path_name)) { | if(Value *element=main_class->get_element(*class_path_name)) { |
| if(element->is_string()) { | if(element->is_string()) { |
| file_spec=file_readable(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->size(); | int size=table->size(); |
| for(int i=size; i--; ) { | for(int i=size; i--; ) { |
| const String& path=*static_cast<Array *>(table->get(i))->get_string(0); | const String& path=*static_cast<Array *>(table->get(i))->get_string(0); |
| if(file_spec=file_readable(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 606 void Request::output_result(const VFile& | Line 601 void Request::output_result(const VFile& |
| // prepare header: $response:fields without :body | // prepare header: $response:fields without :body |
| response.fields().for_each(add_header_attribute, this); | response.fields().for_each(add_header_attribute, this); |
| // source bytes+transcoder | // transcode |
| const Transcoder *source_transcoder=transcoder(); | |
| const void *source_body=body_file.value_ptr(); | |
| size_t source_content_length=body_file.value_size(); | |
| // client bytes+transcoder | |
| Transcoder *client_transcoder; | |
| Value *vclient_charset=static_cast<Value *>(response.fields().get(*charset_name)); | |
| client_transcoder=vclient_charset?(Transcoder *)CTYPE.get(vclient_charset->as_string()):0; | |
| const void *client_body; | const void *client_body; |
| size_t client_content_length; | size_t client_content_length; |
| Charset::transcode(pool(), | |
| // transcode | pool().get_source_charset(), body_file.value_ptr(), body_file.value_size(), |
| transcoder_transcode(pool(), | pool().get_client_charset(), client_body, client_content_length |
| source_transcoder, source_body, source_content_length, | |
| client_transcoder, client_body, client_content_length | |
| ); | ); |
| // prepare header: content-length | // prepare header: content-length |
| Line 653 const String& Request::mime_type_of(cons | Line 638 const String& Request::mime_type_of(cons |
| } | } |
| return *NEW String(pool(), "application/octet-stream"); | return *NEW String(pool(), "application/octet-stream"); |
| } | } |
| const Transcoder* Request::transcoder() { | |
| return (Transcoder *)CTYPE.get(pool().get_charset()); | |
| } | |
| const unsigned char *Request::pcre_tables() { | |
| if(const Transcoder *ltranscoder=transcoder()) | |
| return ltranscoder->pcre_tables; | |
| // this is not for pcre itself, | |
| // it can do default, it's for string.lower&co | |
| return pcre_default_tables; | |
| } |