--- parser3/src/main/pa_request.C 2009/07/06 12:07:04 1.304 +++ parser3/src/main/pa_request.C 2009/08/14 23:36:55 1.309 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_REQUEST_C="$Date: 2009/07/06 12:07:04 $"; +static const char * const IDENT_REQUEST_C="$Date: 2009/08/14 23:36:55 $"; #include "pa_sapi.h" #include "pa_common.h" @@ -49,6 +49,7 @@ const char* ORIGINS_CONTENT_TYPE="text/p #define MAIN_METHOD_NAME "main" #define AUTO_METHOD_NAME "auto" +#define AUTOUSE_METHOD_NAME "autouse" #define BODY_NAME "body" #define EXCEPTION_TYPE_PART_NAME "type" #define EXCEPTION_SOURCE_PART_NAME "source" @@ -58,6 +59,7 @@ const char* ORIGINS_CONTENT_TYPE="text/p const String main_method_name(MAIN_METHOD_NAME); const String auto_method_name(AUTO_METHOD_NAME); +const String autouse_method_name(AUTOUSE_METHOD_NAME); const String content_transfer_encoding_name(CONTENT_TRANSFER_ENCODING_NAME); const String content_disposition_name(CONTENT_DISPOSITION_NAME); const String content_disposition_inline(CONTENT_DISPOSITION_INLINE); @@ -109,7 +111,9 @@ Request::Request(SAPI_Info& asapi_info, wcontext(0), flang(adefault_lang), fconnection(0), - finterrupted(false),fskip(SKIP_NOTHING), + finterrupted(false), + fskip(SKIP_NOTHING), + fin_cycle(0), // public #ifdef RESOURCES_DEBUG @@ -198,6 +202,26 @@ Request::~Request() { Value& Request::get_self() { return method_frame/*always have!*/->self(); } +Value* Request::get_class(const String& name){ + Value* result=classes().get(name); + if(!result){ + if(Value* value=main_class.get_element(autouse_method_name)) + if(Junction* junction=value->get_junction()) + if(const Method *method=junction->method) { + Value *vname=new VString(name); + VMethodFrame frame(*junction, 0/*no parent*/); + + frame.set_self(main_class); + frame.store_params(&vname, 1); + // we don't need the result + execute_method(frame, *method); + + result=classes().get(name); + } + } + return result; +} + static void load_charset(HashStringValue::key_type akey, HashStringValue::value_type avalue, Request_charsets* charsets) { @@ -219,7 +243,7 @@ void Request::configure_admin(VStateless ... ] */ - if(Value* vcharsets=conf_class.get_element(charsets_name, conf_class, false)) { + if(Value* vcharsets=conf_class.get_element(charsets_name)) { if(!vcharsets->is_string()) if(HashStringValue* charsets=vcharsets->get_hash()) charsets->for_each(load_charset, &this->charsets); @@ -283,7 +307,7 @@ void Request::configure() { methoded_array().configure_user(*this); // $MAIN:MIME-TYPES - if(Value* element=main_class.get_element(mime_types_name, main_class, false)) + if(Value* element=main_class.get_element(mime_types_name)) if(Table *table=element->get_table()) mime_types=table; } @@ -390,7 +414,7 @@ gettimeofday(&mt[2],NULL); body_value=new VString(*body_string); // just result of ^main[] // @postprocess - if(Value* value=main_class.get_element(post_process_method_name, main_class, false)) + if(Value* value=main_class.get_element(post_process_method_name)) if(Junction* junction=value->get_junction()) if(const Method *method=junction->method) { // preparing to pass parameters to @@ -448,10 +472,7 @@ t[9]-t[3] // maybe we'd be lucky enough as to report an error // in a gracefull way... - if(Value* value=main_class.get_element( - *new String(UNHANDLED_EXCEPTION_METHOD_NAME), - main_class, - false)) { + if(Value* value=main_class.get_element(*new String(UNHANDLED_EXCEPTION_METHOD_NAME))) { if(Junction* junction=value->get_junction()) { if(const Method *method=junction->method) { // preparing to pass parameters to @@ -550,7 +571,7 @@ void Request::use_file(VStateless_class& file_spec=&absolute(file_name); else { 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)) { if(element->is_string()) { file_spec=file_exist(absolute(element->as_string()), file_name); // found at class_path? } else if(Table *table=element->get_table()) { @@ -661,7 +682,7 @@ static void add_header_attribute( || name==CHARSET_NAME) return; - const char* aname=String(name, String::L_TAINT).taint_cstr(String::L_URI, 0, &info->r.charsets); + const char* aname=String(name, String::L_TAINTED).taint_cstr(String::L_URI, 0, &info->r.charsets); SAPI::add_header_attribute(info->r.sapi_info, aname, @@ -874,7 +895,7 @@ void Request::output_result(VFile* body_ VDate* vdate=0; if(Value* v=body_file->fields().get("mdate")) { - if(Value* vdatep=v->as(VDATE_TYPE, false)) + if(Value* vdatep=v->as(VDATE_TYPE)) vdate=static_cast(vdatep); else throw Exception(PARSER_RUNTIME, 0, "mdate must be a date"); @@ -956,9 +977,7 @@ Request::Exception_details Request::get_ // $.source if(problem_source) { - String& source=*new String; - source.append(*problem_source, String::L_TAINTED, true/*forced*/); - + String& source=*new String(*problem_source, String::L_TAINTED); hash.put(exception_source_part_name, new VString(source)); }