Diff for /parser3/src/main/pa_request.C between versions 1.245.2.37.2.4 and 1.245.2.37.2.5

version 1.245.2.37.2.4, 2003/03/20 09:41:46 version 1.245.2.37.2.5, 2003/03/21 13:42:31
Line 81  static const String& class_path_name(new Line 81  static const String& class_path_name(new
 // defines  // defines
   
 // op.C  // op.C
 VStateless_classPtr VClassMAIN_create();  VStateless_class* VClassMAIN_create();
 // op.C  // op.C
 VHashPtr exception2vhashconst Exception& e);  VHash* exception2vhashconst Exception& e);
   
 //  //
 Request::Request(SAPI_Info& asapi_info, Request_info& arequest_info,   Request::Request(SAPI_Info& asapi_info, Request_info& arequest_info, 
                                  Untaint_lang adefault_lang, bool status_allowed):                                   Language adefault_lang, bool status_allowed):
         // private          // private
         fpool(),          f
         anti_endless_execute_recoursion(0),          anti_endless_execute_recoursion(0),
   
         // public          // public
Line 109  Request::Request(SAPI_Info& asapi_info, Line 109  Request::Request(SAPI_Info& asapi_info,
         // public          // public
         sapi_info(asapi_info),          sapi_info(asapi_info),
         request_info(arequest_info),          request_info(arequest_info),
         charsets(pool(), *UTF8_charset, *UTF8_charset, *UTF8_charset), // default charsets          charsets(*UTF8_charset, *UTF8_charset, *UTF8_charset), // default charsets
   
         main_class(VClassMAIN_create()),          main_class(VClassMAIN_create()),
         form(new VForm),          form(new VForm),
Line 138  Request::Request(SAPI_Info& asapi_info, Line 138  Request::Request(SAPI_Info& asapi_info,
         /// methodless          /// methodless
         // env class          // env class
         classes().put(String* (new String(ENV_CLASS_NAME)),           classes().put(String* (new String(ENV_CLASS_NAME)), 
                         ValuePtr(new VEnv(pool(), asapi_info)));                          Value*(new VEnv(asapi_info)));
         // status class          // status class
         if(status_allowed)          if(status_allowed)
                 classes().put(String* (new String(STATUS_CLASS_NAME)),                   classes().put(String* (new String(STATUS_CLASS_NAME)), 
                         ValuePtr(new VStatus()));                          Value*(new VStatus()));
         // request class          // request class
         classes().put(String* (new String(REQUEST_CLASS_NAME)),           classes().put(String* (new String(REQUEST_CLASS_NAME)), 
                 ValuePtr(new VRequest(arequest_info, charsets)));                         Value*(new VRequest(arequest_info, charsets))); 
         // cookie class          // cookie class
         classes().put(String* (new String(COOKIE_CLASS_NAME)), cookie);          classes().put(String* (new String(COOKIE_CLASS_NAME)), cookie);
   
Line 160  Request::Request(SAPI_Info& asapi_info, Line 160  Request::Request(SAPI_Info& asapi_info,
         classes().put(mail->get_class()->base_class()->name(), mail);             classes().put(mail->get_class()->base_class()->name(), mail);   
         // math class          // math class
         {          {
                 ValuePtr math(new VMath);                  Value* math(new VMath);
                 classes().put(math->get_class()->base_class()->name(), math);                     classes().put(math->get_class()->base_class()->name(), math);   
         }          }
 }  }
Line 175  Request::~Request() { Line 175  Request::~Request() {
 #endif  #endif
 }  }
   
 ValuePtr Request::get_self() { return method_frame?method_frame->get_self():ValuePtr(0); }  Value* Request::get_self() { return method_frame?method_frame->get_self():0; }
   
 static void load_charset(HashStringValue::key_type akey, HashStringValue::value_type avalue, int) {  static void load_charset(HashStringValue::key_type akey, HashStringValue::value_type avalue, int) {
         ::charsets.load_charset(akey, avalue->as_string(0));          ::charsets.load_charset(akey, avalue->as_string(0));
Line 195  void Request::configure_admin(VStateless Line 195  void Request::configure_admin(VStateless
                         ...                          ...
                 ]                  ]
         */          */
         if(ValuePtr vcharsets=conf_class.get_element(charsets_name, conf_class, false)) {          if(Value* vcharsets=conf_class.get_element(charsets_name, conf_class, false)) {
                 if(!vcharsets->is_string())                  if(!vcharsets->is_string())
                         if(HashStringValue* charsets=vcharsets->get_hash(0))                          if(HashStringValue* charsets=vcharsets->get_hash(0))
                                 charsets->for_each(load_charset, 0);                                  charsets->for_each(load_charset, 0);
Line 285  gettimeofday(&mt[0],NULL); Line 285  gettimeofday(&mt[0],NULL);
                 methoded_array().configure_user(*this);                  methoded_array().configure_user(*this);
   
                 // $MAIN:MIME-TYPES                  // $MAIN:MIME-TYPES
                 if(ValuePtr element=main_class->get_element(mime_types_name, *main_class, false))                  if(Value* element=main_class->get_element(mime_types_name, *main_class, false))
                         if(Table *table=element->get_table())                          if(Table *table=element->get_table())
                                 mime_types=table;                                                         mime_types=table;                       
   
                 // filling form fields                  // filling form fields
                 form->fill_fields_and_tables(pool(), charsets, request_info);                  form->fill_fields_and_tables(charsets, request_info);
   
                 // filling cookies                  // filling cookies
                 cookie->fill_fields(pool(), request_info);                  cookie->fill_fields(request_info);
   
                 // filling mail received                  // filling mail received
                 mail->fill_received(*this);                  mail->fill_received(*this);
Line 314  gettimeofday(&mt[1],NULL); Line 314  gettimeofday(&mt[1],NULL);
 gettimeofday(&mt[2],NULL);  gettimeofday(&mt[2],NULL);
 #endif  #endif
   
                 Vconst String& body_vstring_before_post_process(new VString(body_string));                  const VString& body_vstring_before_post_process(new VString(body_string));
                 Vconst String& body_vstring_after_post_process(body_vstring_before_post_process);                  const VString& body_vstring_after_post_process(body_vstring_before_post_process);
                 // @postprocess                  // @postprocess
                 if(ValuePtr value=main_class->get_element(post_process_method_name, *main_class, false))                  if(Value* value=main_class->get_element(post_process_method_name, *main_class, false))
                         if(JunctionPtr junction=value->get_junction())                          if(Junction* junction=value->get_junction())
                                 if(const Method *method=junction->method) {                                  if(const Method *method=junction->method) {
                                         // preparing to pass parameters to                                           // preparing to pass parameters to 
                                         //      @postprocess[data]                                          //      @postprocess[data]
                                         VMethodFrame frame(pool(), method->name, *junction, 0/*no parent*/); frame.ref();                                          VMethodFrame frame(method->name, *junction, 0/*no parent*/); frame.ref();
                                         frame.set_self(main_class);                                          frame.set_self(main_class);
   
                                         frame.store_param(body_vstring_before_post_process);                                          frame.store_param(body_vstring_before_post_process);
Line 330  gettimeofday(&mt[2],NULL); Line 330  gettimeofday(&mt[2],NULL);
                                                 VString* (new VString(execute_method(frame, *method)));                                                  VString* (new VString(execute_method(frame, *method)));
                                 }                                  }
   
                 bool lorigins_mode=origins_mode();                  VFile* body_file=body_vstring_after_post_process->as_vfile(
                           String::L_UNSPECIFIED);
                 VFilePtr body_file=body_vstring_after_post_process->as_vfile(pool(),   
                         String::UL_UNSPECIFIED, lorigins_mode);  
   
                 // extract response body                  // extract response body
                 ValuePtr body_value=response->fields().get(download_name);                  Value* body_value=response->fields().get(download_name);
                 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);                          body_value=response->fields().get(body_name);
   
                 if(body_value) // there is some $response:body                  if(body_value) // there is some $response:body
                         body_file=body_value->as_vfile();                          body_file=body_value->as_vfile();
                 else if(lorigins_mode)  
                         response->fields().put(content_type_name,   
                                 ValuePtr(new VString(String* (new String(ORIGINS_CONTENT_TYPE)))));  
   
 #ifdef RESOURCES_DEBUG  #ifdef RESOURCES_DEBUG
 //measure:after postprocess  //measure:after postprocess
Line 364  double t[10]; Line 359  double t[10];
 for(int i=0;i<10;i++)  for(int i=0;i<10;i++)
     t[i]=mt[i].tv_sec+mt[i].tv_usec/1000000.0;      t[i]=mt[i].tv_sec+mt[i].tv_usec/1000000.0;
 //measure:log2 compile,main,postprocess,output  //measure:log2 compile,main,postprocess,output
 SAPI::log(pool(), "rmeasure: %s,%.2f,%.2f,%.2f %.2f,%.2f %.2f",   SAPI::log("rmeasure: %s,%.2f,%.2f,%.2f %.2f,%.2f %.2f", 
 request_info.uri,  request_info.uri,
 t[1]-t[0],  t[1]-t[0],
 t[2]-t[1],  t[2]-t[1],
Line 412  t[9]-t[3] Line 407  t[9]-t[3]
   
                         // maybe we'd be lucky enough as to report an error                          // maybe we'd be lucky enough as to report an error
                         // in a gracefull way...                          // in a gracefull way...
                         if(ValuePtr value=main_class->get_element(                          if(Value* value=main_class->get_element(
                                         String* (new String(UNHANDLED_EXCEPTION_METHOD_NAME)),                                           String* (new String(UNHANDLED_EXCEPTION_METHOD_NAME)), 
                                         *main_class,                                          *main_class,
                                         false)) {                                          false)) {
                                 if(JunctionPtr junction=value->get_junction()) {                                  if(Junction* junction=value->get_junction()) {
                                         if(const Method *method=junction->method) {                                          if(const Method *method=junction->method) {
                                                 // preparing to pass parameters to                                                   // preparing to pass parameters to 
                                                 //      @unhandled_exception[exception;stack]                                                  //      @unhandled_exception[exception;stack]
                                                 VMethodFrame frame(pool(), method->name, *junction, 0/*no caller*/); frame.ref();                                                  VMethodFrame frame(method->name, *junction, 0/*no caller*/); frame.ref();
                                                 frame.set_self(main_class);                                                  frame.set_self(main_class);
   
                                                 // $exception                                                  // $exception
                                                 frame.store_param(exception2vhash(pool(), e));                                                  frame.store_param(exception2vhash(e));
                                                 // $stack[^table::set{name      origin}]                                                  // $stack[^table::set{name      origin}]
                                                 Table::columns_type stack_trace_columns(new ArrayString);                                                  Table::columns_type stack_trace_columns(new ArrayString);
                                                 *stack_trace_columns+=String* (new String("name"));                                                  *stack_trace_columns+=String* (new String("name"));
                                                 *stack_trace_columns+=String* (new String("file"));                                                  *stack_trace_columns+=String* (new String("file"));
                                                 *stack_trace_columns+=String* (new String("lineno"));                                                  *stack_trace_columns+=String* (new String("lineno"));
                                                 Table* stack_trace(new Table(0, stack_trace_columns));                                                  Table* stack_trace(new Table(0, stack_trace_columns));
                                                 Array_iterator<String* > tracei(exception_trace);                                                  Array_iterator<String*> tracei(exception_trace);
                                                 while(tracei.has_next()) {                                                  while(tracei.has_next()) {
                                                         Table::element_type row(new ArrayString);                                                          Table::element_type row(new ArrayString);
   
Line 448  t[9]-t[3] Line 443  t[9]-t[3]
 #endif  #endif
                                                         *stack_trace+=row;                                                          *stack_trace+=row;
                                                 }                                                  }
                                                 frame.store_param(ValuePtr(new VTable(stack_trace)));                                                  frame.store_param(Value*(new VTable(stack_trace)));
   
                                                 // future $response:body=                                                  // future $response:body=
                                                 //   execute ^unhandled_exception[exception;stack]                                                  //   execute ^unhandled_exception[exception;stack]
Line 482  t[9]-t[3] Line 477  t[9]-t[3]
   
                                 // future $response:content-type                                  // future $response:content-type
                                 response->fields().put(content_type_name,                                   response->fields().put(content_type_name, 
                                         ValuePtr(new VString(String* (new String(UNHANDLED_EXCEPTION_CONTENT_TYPE)))));                                          Value*(new VString(String* (new String(UNHANDLED_EXCEPTION_CONTENT_TYPE)))));
                                 // future $response:body                                  // future $response:body
                                 body_string=String* (new String(buf));                                  body_string=String* (new String(buf));
                         }                          }
   
                         VString body_vstring(body_string);                          VString body_vstring(body_string);
                         VFilePtr body_file=body_vstring.as_vfile();                          VFile* body_file=body_vstring.as_vfile();
   
                         // ERROR. write it out                          // ERROR. write it out
                         output_result(body_file, header_only, false);                          output_result(body_file, header_only, false);
Line 513  void Request::use_file(VStateless_class& Line 508  void Request::use_file(VStateless_class&
                 file_spec=absolute(file_name);                  file_spec=absolute(file_name);
         else {          else {
                 file_spec=0;                  file_spec=0;
                 if(ValuePtr element=main_class->get_element(class_path_name, *main_class, false)) {                  if(Value* element=main_class->get_element(class_path_name, *main_class, false)) {
                         if(element->is_string()) {                          if(element->is_string()) {
                                 file_spec=file_readable(*absolute(element->as_string(&pool())), *file_name); // found at class_path?                                  file_spec=file_readable(*absolute(element->as_string()), *file_name); // found at class_path?
                         } else if(Table *table=element->get_table()) {                          } else if(Table *table=element->get_table()) {
                                 int size=table->count();                                  int size=table->count();
                                 for(int i=size; i--; ) {                                  for(int i=size; i--; ) {
Line 542  void Request::use_file(VStateless_class& Line 537  void Request::use_file(VStateless_class&
                 if(!entry_exists(file_spec))                  if(!entry_exists(file_spec))
                         return;                          return;
   
         if(const char* source=file_read_text(pool(), charsets.source(), file_spec, fail_on_read_problem))          if(const char* source=file_read_text(charsets.source(), file_spec, fail_on_read_problem))
                 use_buf(aclass, source, file_spec, file_spec->cstr());                  use_buf(aclass, source, file_spec, file_spec->cstr());
 }  }
   
Line 551  void Request::use_buf(VStateless_class& Line 546  void Request::use_buf(VStateless_class&
                                                                    const char* source,                                                                      const char* source, 
                                                                    const String& filespec, const char* filespec_cstr) {                                                                     const String& filespec, const char* filespec_cstr) {
         // temporary zero @conf so to maybe-replace it in compiled code          // temporary zero @conf so to maybe-replace it in compiled code
         Temp_method temp_method_conf(aclass, conf_method_name, MethodPtr(0));          Temp_method temp_method_conf(aclass, conf_method_name, Method*(0));
         // temporary zero @auto so to maybe-replace it in compiled code          // temporary zero @auto so to maybe-replace it in compiled code
         Temp_method temp_method_auto(aclass, auto_method_name, MethodPtr(0));          Temp_method temp_method_auto(aclass, auto_method_name, Method*(0));
   
         // compile loaded class          // compile loaded class
         VStateless_class& cclass=COMPILE(&aclass, source, filespec_cstr);          VStateless_class& cclass=COMPILE(&aclass, source, filespec_cstr);
   
         // locate and execute possible @conf[] static          // locate and execute possible @conf[] static
         Vconst String& vfilespec(new VString(filespec));          const VString& vfilespec(new VString(filespec));
         Execute_nonvirtual_method_result executed=execute_nonvirtual_method(cclass,           Execute_nonvirtual_method_result executed=execute_nonvirtual_method(cclass, 
                 conf_method_name, vfilespec,                  conf_method_name, vfilespec,
                 false/*no string result needed*/);                  false/*no string result needed*/);
Line 602  static void add_header_attribute( Line 597  static void add_header_attribute(
   
         SAPI::add_header_attribute(r->sapi_info,          SAPI::add_header_attribute(r->sapi_info,
                 aattribute->cstr(),                   aattribute->cstr(), 
                 attributed_meaning_to_string(r->pool(), ameaning, String::UL_HTTP_HEADER, false)->                  attributed_meaning_to_string(r->ameaning, String::L_HTTP_HEADER, false)->
                         cstr(String::UL_UNSPECIFIED));                          cstr(String::L_UNSPECIFIED));
 }  }
 void Request::output_result(VFilePtr body_file, bool header_only, bool as_attachment) {  void Request::output_result(VFile* body_file, bool header_only, bool as_attachment) {
         // header: cookies          // header: cookies
         cookie->output_result(pool(), sapi_info);          cookie->output_result(sapi_info);
                   
         ValuePtr body_file_content_type;          Value* body_file_content_type;
         // set content-type          // set content-type
         if(body_file_content_type=body_file->fields().get(content_type_name)) {          if(body_file_content_type=body_file->fields().get(content_type_name)) {
                 // body file content type                  // body file content type
Line 617  void Request::output_result(VFilePtr bod Line 612  void Request::output_result(VFilePtr bod
         } else {          } else {
                 // default content type                  // default content type
                 response->fields().put_dont_replace(content_type_name,                   response->fields().put_dont_replace(content_type_name, 
                         ValuePtr(new VString(String* (new String(DEFAULT_CONTENT_TYPE)))));                          Value*(new VString(String* (new String(DEFAULT_CONTENT_TYPE)))));
         }          }
   
         // content-disposition          // content-disposition
         if(ValuePtr vfile_name=body_file->fields().get(name_name))          if(Value* vfile_name=body_file->fields().get(name_name))
                 if(*vfile_name->get_string(&fpool)!=NONAME_DAT) {                  if(*vfile_name->get_string(&fpool)!=NONAME_DAT) {
                         VHashPtr hash(new VHash);                          VHash* hash(new VHash);
                         HashStringValue &h=hash->hash(0);                          HashStringValue &h=hash->hash(0);
                         if(as_attachment)                          if(as_attachment)
                                 h.put(value_name, ValuePtr(new VString(content_disposition_value)));                                  h.put(value_name, Value*(new VString(content_disposition_value)));
                         h.put(content_disposition_filename_name, vfile_name);                          h.put(content_disposition_filename_name, vfile_name);
                         response->fields().put(content_disposition_name, hash);                          response->fields().put(content_disposition_name, hash);
                 }                  }
Line 640  void Request::output_result(VFilePtr bod Line 635  void Request::output_result(VFilePtr bod
         if(body_file_content_type)          if(body_file_content_type)
                 if(HashStringValue *hash=body_file_content_type->get_hash(0))                  if(HashStringValue *hash=body_file_content_type->get_hash(0))
                         body_file_content_type=hash->get(value_name);                          body_file_content_type=hash->get(value_name);
         if(!body_file_content_type/*vstring.as_vfile*/ || body_file_content_type->as_string(&pool())->pos("text/")==0) {          if(!body_file_content_type/*vstring.as_vfile*/ || body_file_content_type->as_string()->pos("text/")==0) {
                 Charset::transcode(pool(),                  Charset::transcode(
                         charsets.source(), body_file->value_ptr(), body_file->value_size(),                          charsets.source(), body_file->value_ptr(), body_file->value_size(),
                         charsets.client(), client_body, client_content_length                          charsets.client(), client_body, client_content_length
                 );                  );
Line 667  const String& Request::mime_type_of(cons Line 662  const String& Request::mime_type_of(cons
         if(mime_types)          if(mime_types)
                 if(const char* cext=strrchr(user_file_name_cstr, '.')) {                  if(const char* cext=strrchr(user_file_name_cstr, '.')) {
                         String sext(++cext);                          String sext(++cext);
                         if(mime_types->locate(0, sext.change_case(pool(), charsets.source(), String::CC_LOWER)))                          if(mime_types->locate(0, sext.change_case(charsets.source(), String::CC_LOWER)))
                                 if(const String& result=mime_types->item(1))                                  if(const String& result=mime_types->item(1))
                                         return result;                                          return result;
                                 else                                  else
Line 679  const String& Request::mime_type_of(cons Line 674  const String& Request::mime_type_of(cons
         return String* (new String("application/octet-stream"));          return String* (new String("application/octet-stream"));
 }  }
   
 bool Request::origins_mode() {  
         return main_class->get_element(origins_mode_name, *main_class, false)!=0;  // $ORIGINS mode  
 }  
   
 #ifdef XML  #ifdef XML
   
 GdomeDOMString_auto_ptr Request::transcode(const String& s) {  GdomeDOMString_auto_ptr Request::transcode(const String& s) {
Line 694  const String& Request::transcode(GdomeDO Line 685  const String& Request::transcode(GdomeDO
         , const String& origin          , const String& origin
 #endif  #endif
         ) {          ) {
         return charsets.source().transcode(pool(), s          return charsets.source().transcode(s
 #ifndef NO_STRING_ORIGIN  #ifndef NO_STRING_ORIGIN
                 , origin                  , origin
 #endif  #endif
Line 706  const String& Request::transcode(xmlChar Line 697  const String& Request::transcode(xmlChar
         , const String& origin          , const String& origin
 #endif  #endif
         ) {          ) {
         return charsets.source().transcode(pool(), s          return charsets.source().transcode(s
 #ifndef NO_STRING_ORIGIN  #ifndef NO_STRING_ORIGIN
                 , origin                  , origin
 #endif  #endif

Removed from v.1.245.2.37.2.4  
changed lines
  Added in v.1.245.2.37.2.5


E-mail: