--- parser3/src/main/pa_request.C 2015/05/27 13:34:11 1.343 +++ parser3/src/main/pa_request.C 2015/10/09 11:42:38 1.347 @@ -32,7 +32,7 @@ #include "pa_vconsole.h" #include "pa_vdate.h" -volatile const char * IDENT_PA_REQUEST_C="$Id: pa_request.C,v 1.343 2015/05/27 13:34:11 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H; +volatile const char * IDENT_PA_REQUEST_C="$Id: pa_request.C,v 1.347 2015/10/09 11:42:38 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H; // consts @@ -50,7 +50,6 @@ 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" #define EXCEPTION_COMMENT_PART_NAME "comment" @@ -61,7 +60,6 @@ const String main_method_name(MAIN_METHO const String auto_method_name(AUTO_METHOD_NAME); const String autouse_method_name(AUTOUSE_METHOD_NAME); -const String body_name(BODY_NAME); const String exception_type_part_name(EXCEPTION_TYPE_PART_NAME); const String exception_source_part_name(EXCEPTION_SOURCE_PART_NAME); const String exception_comment_part_name(EXCEPTION_COMMENT_PART_NAME); @@ -75,10 +73,12 @@ const String exception_handled_part_name #define ORIGINS_MODE_NAME "ORIGINS" #define CONF_METHOD_NAME "conf" #define POST_PROCESS_METHOD_NAME "postprocess" -#define DOWNLOAD_NAME "download" #define CLASS_PATH_NAME "CLASS_PATH" #define RESPONSE_BODY_FILE_NAME "file" +#define DOWNLOAD_NAME_UPPER "DOWNLOAD" +#define BODY_NAME_UPPER "BODY" + // statics static const String charsets_name(CHARSETS_NAME); @@ -88,12 +88,24 @@ static const String strict_vars_name(STR static const String origins_mode_name(ORIGINS_MODE_NAME); static const String conf_method_name(CONF_METHOD_NAME); static const String post_process_method_name(POST_PROCESS_METHOD_NAME); -static const String download_name(DOWNLOAD_NAME); static const String class_path_name(CLASS_PATH_NAME); static const String response_body_file_name(RESPONSE_BODY_FILE_NAME); +static const String download_name_upper(DOWNLOAD_NAME_UPPER); +static const String body_name_upper(BODY_NAME_UPPER); + +// more static + +static const String content_type_name_upper(HTTP_CONTENT_TYPE_UPPER); +static const String content_disposition_name_upper(CONTENT_DISPOSITION_UPPER); +static const String content_disposition_inline(CONTENT_DISPOSITION_INLINE); +static const String content_disposition_attachment(CONTENT_DISPOSITION_ATTACHMENT); + // defines +#define CHARSET_NAME_UPPER "CHARSET" +#define LAST_MODIFIED_NAME_UPPER "LAST-MODIFIED" + // op.C VStateless_class& VClassMAIN_create(); @@ -137,8 +149,8 @@ Request::Request(SAPI_Info& asapi_info, pa_register_thread_request(*this); // file_no=0 => unknown - file_list+=String::Body("UNKNOWN"); - file_list+=String::Body("-body of process-"); // pseudo_file_no__process + file_list+="UNKNOWN"; + file_list+="-body of process-"; // pseudo_file_no__process // maybe expire old caches cache_managers->maybe_expire(); @@ -152,15 +164,15 @@ Request::Request(SAPI_Info& asapi_info, /// methodless // env class - classes().put(String::Body(ENV_CLASS_NAME), new VEnv(asapi_info)); + classes().put(ENV_CLASS_NAME, new VEnv(asapi_info)); // status class - classes().put(String::Body(STATUS_CLASS_NAME), new VStatus()); + classes().put(STATUS_CLASS_NAME, new VStatus()); // request class - classes().put(String::Body(REQUEST_CLASS_NAME), new VRequest(arequest_info, charsets, form, asapi_info)); + classes().put(REQUEST_CLASS_NAME, new VRequest(arequest_info, charsets, form, asapi_info)); // cookie class - classes().put(String::Body(COOKIE_CLASS_NAME), &cookie); + classes().put(COOKIE_CLASS_NAME, &cookie); // console class - classes().put(String::Body(CONSOLE_CLASS_NAME), &console); + classes().put(CONSOLE_CLASS_NAME, &console); /// methoded // response class classes().put(response.get_class()->name(), &response); @@ -389,10 +401,10 @@ void Request::core(const char* config_fi "'" MAIN_METHOD_NAME "' method not found"); // extract response body - Value* body_value=response.fields().get(download_name); // $response:download? + Value* body_value=response.fields().get(download_name_upper); // $response:download? bool as_attachment=body_value!=0; if(!body_value) - body_value=response.fields().get(body_name); // $response:body + body_value=response.fields().get(body_name_upper); // $response:body if(!body_value) body_value=new VString(*body_string); // just result of ^main[] @@ -480,7 +492,7 @@ void Request::core(const char* config_fi // doing that ugly // future $response:content-type - response.fields().put(http_content_type, new VString(*new String(UNHANDLED_EXCEPTION_CONTENT_TYPE))); + response.fields().put(content_type_name_upper, new VString(*new String(UNHANDLED_EXCEPTION_CONTENT_TYPE))); // future $response:body body_string=new String(exception_cstr); } @@ -656,24 +668,19 @@ public: bool add_last_modified; }; #endif -static void add_header_attribute( - HashStringValue::key_type name, - HashStringValue::value_type value, - Add_header_attribute_info* info) { - if(name==BODY_NAME - || name==DOWNLOAD_NAME - || name==CHARSET_NAME) +static void add_header_attribute(HashStringValue::key_type name, HashStringValue::value_type value, Add_header_attribute_info* info) { + if(name==BODY_NAME_UPPER || name==DOWNLOAD_NAME_UPPER || name==CHARSET_NAME_UPPER) return; + if(name==LAST_MODIFIED_NAME_UPPER) + info->add_last_modified=false; + const char* aname=String(name, String::L_URI).untaint_and_transcode_cstr(String::L_URI, &info->r.charsets); SAPI::add_header_attribute(info->r.sapi_info, - aname, + aname, attributed_meaning_to_string(*value, String::L_URI, false).untaint_and_transcode_cstr(String::L_URI, &info->r.charsets) ); - - if(strcasecmp(aname, "last-modified")==0) - info->add_last_modified=false; } static void output_sole_piece(Request& r, @@ -835,7 +842,7 @@ void Request::output_result(VFile* body_ h.put(value_name, new VString( as_attachment ? content_disposition_attachment : content_disposition_inline )); h.put(content_disposition_filename_name, new VString(*new String(sfile_name, String::L_HTTP_HEADER))); - response.fields().put(content_disposition, &hash); + response.fields().put(content_disposition_name_upper, &hash); if(!body_file_content_type) body_file_content_type=new VString(mime_type_of(sfile_name.cstr())); @@ -845,10 +852,10 @@ void Request::output_result(VFile* body_ // set Content-Type if(body_file_content_type) { // body file content type - response.fields().put(content_type_name, body_file_content_type); + response.fields().put(content_type_name_upper, body_file_content_type); } else { // default content type - response.fields().put_dont_replace(content_type_name, new VString(*new String(DEFAULT_CONTENT_TYPE))); + response.fields().put_dont_replace(content_type_name_upper, new VString(*new String(DEFAULT_CONTENT_TYPE))); } // prepare header: $response:fields without :body, :download and :charset @@ -872,7 +879,7 @@ void Request::output_result(VFile* body_ throw Exception(PARSER_RUNTIME, 0, "mdate must be a date"); } if(!vdate) - vdate=new VDate(mtime); + vdate=new VDate((pa_time_t)mtime); output_pieces(*this, header_only, sresponse_body_file, @@ -970,10 +977,9 @@ Request::Exception_details Request::get_ // $.file lineno colno if(trace) { const Operation::Origin origin=trace.origin(); - hash.put(String::Body("file"), - new VString(*new String(file_list[origin.file_no], String::L_TAINTED))); - hash.put(String::Body("lineno"), new VInt(1+origin.line)); - hash.put(String::Body("colno"), new VInt(1+origin.col)); + hash.put("file", new VString(*new String(file_list[origin.file_no], String::L_TAINTED))); + hash.put("lineno", new VInt(1+origin.line)); + hash.put("colno", new VInt(1+origin.col)); } // $.comment