Diff for /parser3/src/main/pa_request.C between versions 1.342 and 1.348

version 1.342, 2015/04/08 18:08:53 version 1.348, 2015/10/20 18:17:19
Line 43  const char* UNHANDLED_EXCEPTION_CONTENT_ Line 43  const char* UNHANDLED_EXCEPTION_CONTENT_
   
 /// content type of response when no $MAIN:defaults.content-type defined  /// content type of response when no $MAIN:defaults.content-type defined
 const char* DEFAULT_CONTENT_TYPE="text/html";  const char* DEFAULT_CONTENT_TYPE="text/html";
 const char* ORIGINS_CONTENT_TYPE="text/plain";  
   
 // defines for globals  // defines for globals
   
 #define MAIN_METHOD_NAME "main"  #define MAIN_METHOD_NAME "main"
 #define AUTO_METHOD_NAME "auto"  #define AUTO_METHOD_NAME "auto"
 #define AUTOUSE_METHOD_NAME "autouse"  #define AUTOUSE_METHOD_NAME "autouse"
 #define BODY_NAME "body"  
 #define EXCEPTION_TYPE_PART_NAME "type"  #define EXCEPTION_TYPE_PART_NAME "type"
 #define EXCEPTION_SOURCE_PART_NAME "source"  #define EXCEPTION_SOURCE_PART_NAME "source"
 #define EXCEPTION_COMMENT_PART_NAME "comment"  #define EXCEPTION_COMMENT_PART_NAME "comment"
Line 61  const String main_method_name(MAIN_METHO Line 59  const String main_method_name(MAIN_METHO
 const String auto_method_name(AUTO_METHOD_NAME);  const String auto_method_name(AUTO_METHOD_NAME);
 const String autouse_method_name(AUTOUSE_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_type_part_name(EXCEPTION_TYPE_PART_NAME);
 const String exception_source_part_name(EXCEPTION_SOURCE_PART_NAME);  const String exception_source_part_name(EXCEPTION_SOURCE_PART_NAME);
 const String exception_comment_part_name(EXCEPTION_COMMENT_PART_NAME);  const String exception_comment_part_name(EXCEPTION_COMMENT_PART_NAME);
Line 72  const String exception_handled_part_name Line 69  const String exception_handled_part_name
 #define CHARSETS_NAME "CHARSETS"  #define CHARSETS_NAME "CHARSETS"
 #define MIME_TYPES_NAME "MIME-TYPES"  #define MIME_TYPES_NAME "MIME-TYPES"
 #define STRICT_VARS_NAME "STRICT-VARS"  #define STRICT_VARS_NAME "STRICT-VARS"
 #define ORIGINS_MODE_NAME "ORIGINS"  
 #define CONF_METHOD_NAME "conf"  #define CONF_METHOD_NAME "conf"
 #define POST_PROCESS_METHOD_NAME "postprocess"  #define POST_PROCESS_METHOD_NAME "postprocess"
 #define DOWNLOAD_NAME "download"  
 #define CLASS_PATH_NAME "CLASS_PATH"  #define CLASS_PATH_NAME "CLASS_PATH"
 #define RESPONSE_BODY_FILE_NAME "file"  #define RESPONSE_BODY_FILE_NAME "file"
   
   #define DOWNLOAD_NAME_UPPER "DOWNLOAD"
   #define BODY_NAME_UPPER "BODY"
   
 // statics  // statics
   
 static const String charsets_name(CHARSETS_NAME);  static const String charsets_name(CHARSETS_NAME);
 static const String main_class_name(MAIN_CLASS_NAME);  static const String main_class_name(MAIN_CLASS_NAME);
 static const String mime_types_name(MIME_TYPES_NAME);  static const String mime_types_name(MIME_TYPES_NAME);
 static const String strict_vars_name(STRICT_VARS_NAME);  static const String strict_vars_name(STRICT_VARS_NAME);
 static const String origins_mode_name(ORIGINS_MODE_NAME);  
 static const String conf_method_name(CONF_METHOD_NAME);  static const String conf_method_name(CONF_METHOD_NAME);
 static const String post_process_method_name(POST_PROCESS_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 class_path_name(CLASS_PATH_NAME);
 static const String response_body_file_name(RESPONSE_BODY_FILE_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  // defines
   
   #define CHARSET_NAME_UPPER "CHARSET"
   #define LAST_MODIFIED_NAME_UPPER "LAST-MODIFIED"
   
 // op.C  // op.C
 VStateless_class& VClassMAIN_create();  VStateless_class& VClassMAIN_create();
   
Line 137  Request::Request(SAPI_Info& asapi_info, Line 146  Request::Request(SAPI_Info& asapi_info,
         pa_register_thread_request(*this);          pa_register_thread_request(*this);
   
         // file_no=0 => unknown          // file_no=0 => unknown
         file_list+=String::Body("UNKNOWN");          file_list+="UNKNOWN";
         file_list+=String::Body("-body of process-"); // pseudo_file_no__process          file_list+="-body of process-"; // pseudo_file_no__process
   
         // maybe expire old caches          // maybe expire old caches
         cache_managers->maybe_expire();          cache_managers->maybe_expire();
Line 152  Request::Request(SAPI_Info& asapi_info, Line 161  Request::Request(SAPI_Info& asapi_info,
   
         /// methodless          /// methodless
         // env class          // env class
         classes().put(String::Body(ENV_CLASS_NAME), new VEnv(asapi_info));          classes().put(ENV_CLASS_NAME, new VEnv(asapi_info));
         // status class          // status class
         classes().put(String::Body(STATUS_CLASS_NAME), new VStatus());          classes().put(STATUS_CLASS_NAME, new VStatus());
         // request class          // 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          // cookie class
         classes().put(String::Body(COOKIE_CLASS_NAME), &cookie);          classes().put(COOKIE_CLASS_NAME, &cookie);
         // console class          // console class
         classes().put(String::Body(CONSOLE_CLASS_NAME), &console);          classes().put(CONSOLE_CLASS_NAME, &console);
         /// methoded          /// methoded
         // response class          // response class
         classes().put(response.get_class()->name(), &response);          classes().put(response.get_class()->name(), &response);
Line 389  void Request::core(const char* config_fi Line 398  void Request::core(const char* config_fi
                                 "'" MAIN_METHOD_NAME "' method not found");                                  "'" MAIN_METHOD_NAME "' method not found");
   
                 // extract response body                  // 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;                  bool as_attachment=body_value!=0;
                 if(!body_value)                  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)                  if(!body_value)
                         body_value=new VString(*body_string); // just result of ^main[]                          body_value=new VString(*body_string); // just result of ^main[]
   
Line 480  void Request::core(const char* config_fi Line 489  void Request::core(const char* config_fi
                         // doing that ugly                          // doing that ugly
   
                         // future $response:content-type                          // 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                          // future $response:body
                         body_string=new String(exception_cstr);                          body_string=new String(exception_cstr);
                 }                  }
Line 656  public: Line 665  public:
         bool add_last_modified;          bool add_last_modified;
 };  };
 #endif  #endif
 static void add_header_attribute(  static void add_header_attribute(HashStringValue::key_type name, HashStringValue::value_type value, Add_header_attribute_info* info) {
                                  HashStringValue::key_type name,           if(name==BODY_NAME_UPPER || name==DOWNLOAD_NAME_UPPER || name==CHARSET_NAME_UPPER)
                                  HashStringValue::value_type value,   
                                  Add_header_attribute_info* info) {  
         if(name==BODY_NAME  
                 || name==DOWNLOAD_NAME  
                 || name==CHARSET_NAME)  
                 return;                  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);          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,          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)                          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,  static void output_sole_piece(Request& r,
Line 833  void Request::output_result(VFile* body_ Line 837  void Request::output_result(VFile* body_
                         VHash& hash=*new VHash();                          VHash& hash=*new VHash();
                         HashStringValue &h=hash.hash();                          HashStringValue &h=hash.hash();
                         h.put(value_name, new VString( as_attachment ? content_disposition_attachment : content_disposition_inline ));                          h.put(value_name, new VString( as_attachment ? content_disposition_attachment : content_disposition_inline ));
                         h.put(content_disposition_filename_name, new VString(String(sfile_name, String::L_HTTP_HEADER)));                          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)                          if(!body_file_content_type)
                                 body_file_content_type=new VString(mime_type_of(sfile_name.cstr()));                                  body_file_content_type=new VString(mime_type_of(sfile_name.cstr()));
Line 845  void Request::output_result(VFile* body_ Line 849  void Request::output_result(VFile* body_
         // set Content-Type          // set Content-Type
         if(body_file_content_type) {          if(body_file_content_type) {
                 // 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 {          } else {
                 // default content type                  // 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          // prepare header: $response:fields without :body, :download and :charset
Line 872  void Request::output_result(VFile* body_ Line 876  void Request::output_result(VFile* body_
                                 throw Exception(PARSER_RUNTIME, 0, "mdate must be a date");                                  throw Exception(PARSER_RUNTIME, 0, "mdate must be a date");
                 }                  }
                 if(!vdate)                  if(!vdate)
                         vdate=new VDate(mtime);                          vdate=new VDate((pa_time_t)mtime);
   
                 output_pieces(*this, header_only,                   output_pieces(*this, header_only, 
                         sresponse_body_file,                          sresponse_body_file,
Line 970  Request::Exception_details Request::get_ Line 974  Request::Exception_details Request::get_
         // $.file lineno colno          // $.file lineno colno
         if(trace) {          if(trace) {
                 const Operation::Origin origin=trace.origin();                  const Operation::Origin origin=trace.origin();
                 hash.put(String::Body("file"),                  hash.put("file", new VString(*new String(file_list[origin.file_no], String::L_TAINTED)));
                         new VString(*new String(file_list[origin.file_no], String::L_TAINTED)));                  hash.put("lineno", new VInt(1+origin.line));
                 hash.put(String::Body("lineno"), new VInt(1+origin.line));                  hash.put("colno", new VInt(1+origin.col));
                 hash.put(String::Body("colno"), new VInt(1+origin.col));  
         }          }
   
         // $.comment          // $.comment

Removed from v.1.342  
changed lines
  Added in v.1.348


E-mail: