--- parser3/src/main/pa_request.C 2005/11/24 14:00:34 1.278 +++ parser3/src/main/pa_request.C 2008/07/15 12:54:37 1.298 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_REQUEST_C="$Date: 2005/11/24 14:00:34 $"; +static const char * const IDENT_REQUEST_C="$Date: 2008/07/15 12:54:37 $"; #include "pa_sapi.h" #include "pa_common.h" @@ -58,8 +58,10 @@ 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 content_transfer_encoding_name(CONTENT_TRANSFER_ENCODING_NAME); const String content_disposition_name(CONTENT_DISPOSITION_NAME); -const String content_disposition_value(CONTENT_DISPOSITION_VALUE); +const String content_disposition_inline(CONTENT_DISPOSITION_INLINE); +const String content_disposition_attachment(CONTENT_DISPOSITION_ATTACHMENT); const String content_disposition_filename_name(CONTENT_DISPOSITION_FILENAME_NAME); const String body_name(BODY_NAME); const String exception_type_part_name(EXCEPTION_TYPE_PART_NAME); @@ -107,7 +109,7 @@ Request::Request(SAPI_Info& asapi_info, wcontext(0), flang(adefault_lang), fconnection(0), - finterrupted(false), + finterrupted(false),fskip(SKIP_NOTHING), // public #ifdef RESOURCES_DEBUG @@ -124,7 +126,8 @@ Request::Request(SAPI_Info& asapi_info, form(*new VForm(charsets, arequest_info)), mail(*new VMail), response(*new VResponse(arequest_info, charsets)), - cookie(*new VCookie), + cookie(*new VCookie(charsets, arequest_info)), + console(*new VConsole), // private configure_admin_done(false), @@ -157,12 +160,11 @@ Request::Request(SAPI_Info& asapi_info, if(status_allowed) classes().put(String::Body(STATUS_CLASS_NAME), new VStatus()); // request class - classes().put(String::Body(REQUEST_CLASS_NAME), new VRequest(arequest_info, charsets)); + classes().put(String::Body(REQUEST_CLASS_NAME), new VRequest(arequest_info, charsets, form)); // cookie class classes().put(String::Body(COOKIE_CLASS_NAME), &cookie); // console class - classes().put(String::Body(CONSOLE_CLASS_NAME), new VConsole()); - + classes().put(String::Body(CONSOLE_CLASS_NAME), &console); /// methoded // response class classes().put(response.get_class()->name(), &response); @@ -204,7 +206,7 @@ static void load_charset(HashStringValue } void Request::configure_admin(VStateless_class& conf_class) { if(configure_admin_done) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "parser already configured"); configure_admin_done=true; @@ -220,9 +222,9 @@ void Request::configure_admin(VStateless if(Value* vcharsets=conf_class.get_element(charsets_name, conf_class, false)) { if(!vcharsets->is_string()) if(HashStringValue* charsets=vcharsets->get_hash()) - charsets->for_each(load_charset, &this->charsets); + charsets->for_each(load_charset, &this->charsets); else - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "$" MAIN_CLASS_NAME ":" CHARSETS_NAME " must be hash"); } @@ -304,9 +306,6 @@ struct timeval mt[10]; gettimeofday(&mt[0],NULL); #endif try { - // filling cookies - cookie.fill_fields(request_info); - // filling mail received mail.fill_received(*this); @@ -373,7 +372,7 @@ gettimeofday(&mt[1],NULL); // execute @main[] const String* body_string=execute_virtual_method(main_class, main_method_name); if(!body_string) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "'"MAIN_METHOD_NAME"' method not found"); @@ -463,39 +462,41 @@ t[9]-t[3] false)) { if(Junction* junction=value->get_junction()) { if(const Method *method=junction->method) { -// preparing to pass parameters to -// @unhandled_exception[exception;stack] -VMethodFrame frame(/*method->name, */ *junction, 0/*no caller*/); -frame.set_self(main_class); - -// $exception -frame.store_param(details.vhash); -// $stack[^table::set{name origin}] -Table::columns_type stack_trace_columns(new ArrayString); -*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); -if(!exception_trace.is_empty()/*signed!*/) -for(size_t i=exception_trace.bottom_index(); iname, */ *junction, 0/*no caller*/); + frame.set_self(main_class); + + // $exception + frame.store_param(details.vhash); + // $stack[^table::create{name file lineno colno}] + Table::columns_type stack_trace_columns(new ArrayString); + *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); + if(!exception_trace.is_empty()/*signed!*/) + for(size_t i=exception_trace.bottom_index(); iname*/); - - // locate and execute possible @auto[] static - execute_nonvirtual_method(cclass, - auto_method_name, vfilespec, - false/*no result needed*/); + + for(size_t i=0; iname*/); + + // locate and execute possible @auto[] static + execute_nonvirtual_method(cclass, + auto_method_name, vfilespec, + false/*no result needed*/); + } } const String& Request::relative(const char* apath, const String& relative_name) { @@ -655,21 +662,21 @@ public: }; #endif static void add_header_attribute( - HashStringValue::key_type aattribute, - HashStringValue::value_type ameaning, + HashStringValue::key_type name, + HashStringValue::value_type value, Add_header_attribute_info* info) { - if(aattribute==BODY_NAME - || aattribute==DOWNLOAD_NAME - || aattribute==CHARSET_NAME) + if(name==BODY_NAME + || name==DOWNLOAD_NAME + || name==CHARSET_NAME) return; + + const char* aname=String(name, String::L_URI).cstr(String::L_UNSPECIFIED, 0, &info->r.charsets); - const char* a=aattribute.cstr(); SAPI::add_header_attribute(info->r.sapi_info, - a, - attributed_meaning_to_string(*ameaning, String::L_HTTP_HEADER, false). - cstr(String::L_UNSPECIFIED)); + aname, + attributed_meaning_to_string(*value, String::L_URI, false).cstr(String::L_UNSPECIFIED, 0, &info->r.charsets)); - if(strcasecmp(a, "last-modified")==0) + if(strcasecmp(aname, "last-modified")==0) info->add_last_modified = false; } @@ -835,14 +842,12 @@ void Request::output_result(VFile* body_ if(vfile_name) { const String& sfile_name=vfile_name->as_string(); if(sfile_name!=NONAME_DAT) { - if(as_attachment) - { - VHash& hash=*new VHash(); - HashStringValue &h=hash.hash(); - h.put(value_name, new VString(content_disposition_value)); - h.put(content_disposition_filename_name, vfile_name); - response.fields().put(content_disposition_name, &hash); - } + VHash& hash=*new VHash(); + HashStringValue &h=hash.hash(); + h.put(value_name, new VString( as_attachment ? content_disposition_attachment : content_disposition_inline )); + + h.put(content_disposition_filename_name, vfile_name); + response.fields().put(content_disposition_name, &hash); if(!body_file_content_type) body_file_content_type=new VString(mime_type_of(sfile_name.cstr())); @@ -861,7 +866,7 @@ void Request::output_result(VFile* body_ // prepare header: $response:fields without :body Add_header_attribute_info info(*this); - response.fields().for_each(add_header_attribute, &info); + response.fields().for_each(add_header_attribute, &info); if(body_file_content_type) if(HashStringValue *hash=body_file_content_type->get_hash()) @@ -880,7 +885,7 @@ void Request::output_result(VFile* body_ if(Value* vdatep=v->as(VDATE_TYPE, false)) vdate=static_cast(vdatep); else - throw Exception("parser.runtime", 0, "mdate must be a date"); + throw Exception(PARSER_RUNTIME, 0, "mdate must be a date"); } if(!vdate) vdate=new VDate(mtime); @@ -905,7 +910,7 @@ const String& Request::mime_type_of(cons if(const String* result=mime_types->item(1)) return *result; else - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, MIME_TYPES_NAME " table column elements must not be empty"); } @@ -914,19 +919,15 @@ const String& Request::mime_type_of(cons } #ifdef XML -GdomeDOMString_auto_ptr Request::transcode(const String& s) { +xmlChar* Request::transcode(const String& s) { return charsets.source().transcode(s); } -GdomeDOMString_auto_ptr Request::transcode(const String::Body s) { +xmlChar* Request::transcode(const String::Body s) { return charsets.source().transcode(s); } -const String& Request::transcode(GdomeDOMString* s) { - return charsets.source().transcode(s); -} - -const String& Request::transcode(xmlChar* s) { +const String& Request::transcode(const xmlChar* s) { return charsets.source().transcode(s); } #endif @@ -937,13 +938,15 @@ const Request::Trace Request::Exception_ if(!is_empty()) { result=bottom_value(); if(!problem_source) { // we don't know who trigged the bug? - problem_source=result.name(); // consider the stack-top-guy did that + problem_source=result.name(); // consider the stack-top-guy (we usually know source of next-from-throw-point exception) did that fbottom++; } else if(result.name()==problem_source) // it is that same guy? fbottom++; // throw away that trace - // else stack top contains not us, - // leaving result intact - // it would help ^throw + else { + // stack top contains not us, + // leaving result intact + // it would help ^throw + } } return result;