--- parser3/src/main/pa_request.C 2010/08/01 14:49:33 1.322 +++ parser3/src/main/pa_request.C 2012/03/16 09:24:14 1.329 @@ -1,12 +1,10 @@ /** @file Parser: request class main part. @see compile.C and execute.C. - Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_REQUEST_C="$Date: 2010/08/01 14:49:33 $"; - #include "pa_sapi.h" #include "pa_common.h" #include "pa_request.h" @@ -34,6 +32,8 @@ static const char * const IDENT_REQUEST_ #include "pa_vconsole.h" #include "pa_vdate.h" +volatile const char * IDENT_PA_REQUEST_C="$Id: pa_request.C,v 1.329 2012/03/16 09:24:14 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H; + // consts #define UNHANDLED_EXCEPTION_METHOD_NAME "unhandled_exception" @@ -97,9 +97,10 @@ VStateless_class& VClassMAIN_create(); // Request::Request(SAPI_Info& asapi_info, Request_info& arequest_info, - String::Language adefault_lang, bool status_allowed): + String::Language adefault_lang): // private anti_endless_execute_recoursion(0), + anti_endless_json_string_recoursion(0), // public method_frame(0), @@ -157,8 +158,7 @@ Request::Request(SAPI_Info& asapi_info, // env class classes().put(String::Body(ENV_CLASS_NAME), new VEnv(asapi_info)); // status class - if(status_allowed) - classes().put(String::Body(STATUS_CLASS_NAME), new VStatus()); + classes().put(String::Body(STATUS_CLASS_NAME), new VStatus()); // request class classes().put(String::Body(REQUEST_CLASS_NAME), new VRequest(arequest_info, charsets, form)); // cookie class @@ -209,7 +209,7 @@ Value* Request::get_class(const String& frame.store_params(&vname, 1); // we don't need the result - execute_method(frame, *method); + execute_method(frame); result=classes().get(name); } @@ -411,7 +411,9 @@ gettimeofday(&mt[2],NULL); VMethodFrame frame(*method, 0 /*no parent*/, main_class); frame.store_params(&body_value, 1); - body_value=&execute_method(frame, *method).as_value(); + execute_method(frame); + + body_value=&frame.result().as_value(); } VFile* body_file=body_value->as_vfile(flang, &charsets); @@ -465,7 +467,6 @@ t[9]-t[3] if(const Method *method=junction->method) { // preparing to pass parameters to // @unhandled_exception[exception;stack] - VMethodFrame frame(*method, 0 /*no caller*/, main_class); // $stack[^table::create{name file lineno colno}] Table::columns_type stack_trace_columns(new ArrayString); @@ -489,13 +490,17 @@ t[9]-t[3] stack_trace+=row; } - Value *params[]={&details.vhash, new VTable(&stack_trace)}; - frame.store_params(params, 2); - // future $response:body= // execute ^unhandled_exception[exception;stack] exception_trace.clear(); // forget all about previous life, in case there would be error inside of this method, error handled would not be mislead by old stack contents (see extract_origin) - body_string=&execute_method(frame, *method).as_string(); + + VMethodFrame frame(*method, 0 /*no caller*/, main_class); + Value *params[]={&details.vhash, new VTable(&stack_trace)}; + + frame.store_params(params, 2); + execute_method(frame); + + body_string=&frame.result().as_string(); } } } @@ -563,6 +568,11 @@ void Request::use_file(VStateless_class& const String& file_name, const String* use_filespec/*absolute*/) { + if(file_name.is_empty()) + throw Exception(PARSER_RUNTIME, + 0, + "usage failed - no filename was specified"); + const String* filespec=0; if(file_name.first_char()=='/') //absolute path? [no need to scan MAIN:CLASS_PATH] @@ -841,7 +851,7 @@ void Request::output_result(VFile* body_ name_cstr=after_slash; if(char *after_slash=rsplit(name_cstr, '/')) name_cstr=after_slash; - vfile_name=new VString(*new String(name_cstr)); + vfile_name=new VString(*new String(name_cstr)); } } if(vfile_name) { @@ -850,7 +860,7 @@ void Request::output_result(VFile* body_ 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); + h.put(content_disposition_filename_name, new VString(String(sfile_name, String::L_HTTP_HEADER))); response.fields().put(content_disposition, &hash); @@ -906,6 +916,10 @@ void Request::output_result(VFile* body_ } } +const String& Request::mime_type_of(const String* file_name) { + return mime_type_of(file_name?file_name->taint_cstr(String::L_FILE_SPEC):0); +} + const String& Request::mime_type_of(const char* user_file_name_cstr) { if(mime_types) if(const char* cext=strrchr(user_file_name_cstr, '.')) {