Diff for /parser3/src/main/pa_request.C between versions 1.245.2.37.2.7 and 1.245.2.37.2.11

version 1.245.2.37.2.7, 2003/03/21 15:36:04 version 1.245.2.37.2.11, 2003/03/24 13:43:41
Line 81  static const String class_path_name(CLAS Line 81  static const String class_path_name(CLAS
 // defines  // defines
   
 // op.C  // op.C
 VStateless_class* VClassMAIN_create();  VStateless_class& VClassMAIN_create();
 // op.C  // op.C
 VHash& exception2vhash(const Exception& e);  VHash& exception2vhash(const Exception& e);
   
Line 96  Request::Request(SAPI_Info& asapi_info, Line 96  Request::Request(SAPI_Info& asapi_info,
         rcontext(0),          rcontext(0),
         wcontext(0),          wcontext(0),
         flang(adefault_lang),          flang(adefault_lang),
         fconnection(0),          fconnection(),
         finterrupted(false),          finterrupted(false),
   
         // public          // public
Line 110  Request::Request(SAPI_Info& asapi_info, Line 110  Request::Request(SAPI_Info& asapi_info,
         request_info(arequest_info),          request_info(arequest_info),
         charsets(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),
         mail(*new VMail),          mail(*new VMail),
         response(*new VResponse(arequest_info, charsets)),          response(*new VResponse(arequest_info, charsets)),
Line 136  Request::Request(SAPI_Info& asapi_info, Line 136  Request::Request(SAPI_Info& asapi_info,
   
         /// methodless          /// methodless
         // env class          // env class
         classes().put(*new StringBody(ENV_CLASS_NAME), new VEnv(asapi_info));          classes().put(StringBody(ENV_CLASS_NAME), new VEnv(asapi_info));
         // status class          // status class
         if(status_allowed)          if(status_allowed)
                 classes().put(*new StringBody(STATUS_CLASS_NAME), new VStatus());                  classes().put(StringBody(STATUS_CLASS_NAME), new VStatus());
         // request class          // request class
         classes().put(*new StringBody(REQUEST_CLASS_NAME), new VRequest(arequest_info, charsets));                classes().put(StringBody(REQUEST_CLASS_NAME), new VRequest(arequest_info, charsets));   
         // cookie class          // cookie class
         classes().put(*new StringBody(COOKIE_CLASS_NAME), &cookie);          classes().put(StringBody(COOKIE_CLASS_NAME), &cookie);
   
         /// methoded          /// methoded
         // response class          // response class
Line 176  Value& Request::get_self() { return meth Line 176  Value& Request::get_self() { return meth
 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(*new String(akey, String::L_CLEAN), avalue->as_string());          ::charsets.load_charset(*new String(akey, String::L_CLEAN), avalue->as_string());
 }  }
 void Request::configure_admin(VStateless_class& conf_class, const String* source) {  void Request::configure_admin(VStateless_class& conf_class) {
         if(configure_admin_done)          if(configure_admin_done)
                 throw Exception("parser.runtime",                  throw Exception("parser.runtime",
                 source,                  0,
                 "parser already configured");                  "parser already configured");
         configure_admin_done=true;          configure_admin_done=true;
                   
Line 272  gettimeofday(&mt[0],NULL); Line 272  gettimeofday(&mt[0],NULL);
   
                 // configure method_frame options if not configured yet                  // configure method_frame options if not configured yet
                 if(!configure_admin_done)                  if(!configure_admin_done)
                         configure_admin(main_class, 0);                          configure_admin(main_class);
   
                 // configure not-method_frame=user options                  // configure not-method_frame=user options
                 methoded_array().configure_user(*this);                  methoded_array().configure_user(*this);
Line 408  t[9]-t[3] Line 408  t[9]-t[3]
                                                 frame.store_param(exception2vhash(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+=*new StringBody("name"));                                                  *stack_trace_columns+=new String("name");
                                                 *stack_trace_columns+=*new StringBody("file"));                                                  *stack_trace_columns+=new String("file");
                                                 *stack_trace_columns+=*new StringBody("lineno"));                                                  *stack_trace_columns+=new String("lineno");
                                                 Table* stack_trace(new Table(0, stack_trace_columns));                                                  Table& stack_trace=*new Table(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);
   
                                                         const String& name=tracei.next();                                                          const String* name=tracei.next();
                                                         *row+=name; // name column                                                          *row+=name; // name column
 #ifndef NO_STRING_ORIGIN  #ifndef NO_STRING_ORIGIN
                                                         const String_fragment::Origin& origin=name->origin();                                                          const String_fragment::Origin& origin=name->origin();
                                                         if(origin.file) {                                                          if(origin.file) {
                                                                 *row+=*new StringBody(origin.file, 0, true)); // file column                                                                  *row+=StringBody(origin.file, 0, true)); // file column
                                                                 *row+=*new StringBody(                                                                  *row+=StringBody(
                                                                         pool().format_integer(1+origin.line),                                                                           pool().format_integer(1+origin.line), 
                                                                         0, true)); // line column                                                                          0, true)); // line column
                                                         }                                                          }
 #endif  #endif
                                                         *stack_trace+=row;                                                          *stack_trace+=row;
                                                 }                                                  }*/
                                                 frame.store_param(new VTable(stack_trace)));                                                  frame.store_param(*new VTable(&stack_trace));
   
                                                 // future $response:body=                                                  // future $response:body=
                                                 //   execute ^unhandled_exception[exception;stack]                                                  //   execute ^unhandled_exception[exception;stack]
                                                 body_string=execute_method(frame, *method);                                                  body_string=&execute_method(frame, *method);
                                         }                                          }
                                 }                                  }
                         }                          }
Line 442  t[9]-t[3] Line 442  t[9]-t[3]
                                 // doing that ugly                                  // doing that ugly
   
                                 // make up result: $origin $source $comment $type $code                                  // make up result: $origin $source $comment $type $code
                                 char *buf=new char[MAX_STRING];                                  char *buf=new(PointerFreeGC) char[MAX_STRING];
                                 size_t printed=0;                                  size_t printed=0;
                                 if(const String* problem_source=e.problem_source()) {                                  if(const String* problem_source=e.problem_source()) {
 #ifndef NO_STRING_ORIGIN                                          /*const String_fragment::Origin& origin=problem_source->origin();
                                         const String_fragment::Origin& origin=problem_source->origin();  
                                         if(origin.file)                                          if(origin.file)
                                                 printed+=snprintf(buf+printed, MAX_STRING-printed,                                                   printed+=snprintf(buf+printed, MAX_STRING-printed, 
                                                         ORIGIN_FILE_LINE_FORMAT": ",                                                           ORIGIN_FILE_LINE_FORMAT": ", 
                                                         origin.file, 1+origin.line                                                          origin.file, 1+origin.line
                                                 );                                                  );
 #endif  
                                         printed+=snprintf(buf+printed, MAX_STRING-printed, "'%s' ",                                           printed+=snprintf(buf+printed, MAX_STRING-printed, "'%s' ", 
                                                 problem_source->cstr().get());                                                  problem_source->cstr().get());
                                                   */
                                 }                                  }
                                 if(const char* comment=e.comment(true))                                  if(const char* comment=e.comment(true))
                                         printed+=snprintf(buf+printed, MAX_STRING-printed, "%s", comment);                                          printed+=snprintf(buf+printed, MAX_STRING-printed, "%s", comment);
Line 463  t[9]-t[3] Line 462  t[9]-t[3]
   
                                 // future $response:content-type                                  // future $response:content-type
                                 response.fields().put(content_type_name,                                   response.fields().put(content_type_name, 
                                         new VString(*new StringBody(UNHANDLED_EXCEPTION_CONTENT_TYPE)))));                                          new VString(*new String(UNHANDLED_EXCEPTION_CONTENT_TYPE)));
                                 // future $response:body                                  // future $response:body
                                 body_string=*new StringBody(buf));                                  body_string=new String(buf);
                         }                          }
   
                         VString body_vstring(body_string);                          VString body_vstring(*body_string);
                         VFile* body_file=body_vstring.as_vfile();                          VFile* body_file=body_vstring.as_vfile();
   
                         // ERROR. write it out                          // ERROR. write it out
Line 487  void Request::use_file(VStateless_class& Line 486  void Request::use_file(VStateless_class&
                 return;                  return;
         used_files.put(file_name, true);          used_files.put(file_name, true);
   
         const String& file_spec;          const String* file_spec;
         if(ignore_class_path) // ignore_class_path?          if(ignore_class_path) // ignore_class_path?
                 file_spec=file_name;                  file_spec=&file_name;
         else if(file_name->first_char()=='/') //absolute path, no need to scan MAIN:CLASS_PATH?          else if(file_name.first_char()=='/') //absolute path, no need to scan MAIN:CLASS_PATH?
                 file_spec=absolute(file_name);                  file_spec=&absolute(file_name);
         else {          else {
                 file_spec=0;                  file_spec=0;
                 if(Value* 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()), *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--; ) {
                                         const String& path=(*table->get(i))[0];                                          const String& path=*(*table->get(i))[0];
                                         if(file_spec=file_readable(*absolute(path), *file_name))                                          if(file_spec=file_readable(absolute(path), file_name))
                                                 break; // found along class_path                                                  break; // found along class_path
                                 }                                  }
                         } else                          } else
Line 510  void Request::use_file(VStateless_class& Line 509  void Request::use_file(VStateless_class&
                                         "$" CLASS_PATH_NAME " must be string or table");                                          "$" CLASS_PATH_NAME " must be string or table");
                         if(!file_spec)                          if(!file_spec)
                                 throw Exception("parser.runtime",                                  throw Exception("parser.runtime",
                                         file_name,                                          &file_name,
                                         "not found along " MAIN_CLASS_NAME ":" CLASS_PATH_NAME);                                          "not found along " MAIN_CLASS_NAME ":" CLASS_PATH_NAME);
                 }                  }
                 if(!file_spec)                  if(!file_spec)
                         throw Exception("parser.runtime",                          throw Exception("parser.runtime",
                                 file_name,                                  &file_name,
                                 "usage failed - no $" MAIN_CLASS_NAME  ":" CLASS_PATH_NAME " were specified");                                  "usage failed - no $" MAIN_CLASS_NAME  ":" CLASS_PATH_NAME " were specified");
         }          }
   
         if(fail_on_read_problem && !fail_on_file_absence) // ignore file absence if asked for          if(fail_on_read_problem && !fail_on_file_absence) // ignore file absence if asked for
                 if(!entry_exists(file_spec))                  if(!entry_exists(*file_spec))
                         return;                          return;
   
         if(const char* source=file_read_text(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 532  void Request::use_buf(VStateless_class& Line 531  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, Method*(0));          Temp_method temp_method_conf(aclass, conf_method_name, 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, Method*(0));          Temp_method temp_method_auto(aclass, auto_method_name, 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
         const VString& vfilespec(new VString(filespec));          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*/);
         if(executed.method)          if(executed.method)
                 configure_admin(cclass, executed.method->name);                  configure_admin(cclass/*, executed.method->name*/);
   
         // locate and execute possible @auto[] static          // locate and execute possible @auto[] static
         execute_nonvirtual_method(cclass,           execute_nonvirtual_method(cclass, 
Line 554  void Request::use_buf(VStateless_class& Line 553  void Request::use_buf(VStateless_class&
 }  }
   
 const String& Request::relative(const char* apath, const String& relative_name) {  const String& Request::relative(const char* apath, const String& relative_name) {
     char *hpath=pool().copy(apath);          char *hpath=strdup(apath);
         const String& result(new String);          String& result=*new String;
     if(rsplit(hpath, '/')) // if something/splitted          if(rsplit(hpath, '/')) // if something/splitted
                 *result << hpath << "/";                  result << hpath << "/";
     *result << relative_name;          result << relative_name;
     return result;          return result;
 }  }
   
 const String& Request::absolute(const String& relative_name) {  const String& Request::absolute(const String& relative_name) {
         if(relative_name->first_char()=='/') {          if(relative_name.first_char()=='/') {
                 const String& result=*new StringBody(request_info.document_root));                  String& result=*new String(strdup(request_info.document_root));
                 *result << relative_name;                  result << relative_name;
                 return result;                  return result;
         } else           } else 
                 return relative_name->pos("://")<0? relative(request_info.path_translated, relative_name)                  return relative_name.pos("://")<0? relative(request_info.path_translated, relative_name)
                         :relative_name; // something like "http://xxx"                          :relative_name; // something like "http://xxx"
 }  }
   
 static void add_header_attribute(  static void add_header_attribute(
                                                                  HashStringValue::key_type aattribute,                                    HashStringValue::key_type aattribute, 
                                                                  HashStringValue::value_type ameaning,                                    HashStringValue::value_type ameaning, 
                                                                  Request *r) {                                   Request *r) {
         if(*aattribute==BODY_NAME          if(aattribute==BODY_NAME
                 || *aattribute==DOWNLOAD_NAME                  || aattribute==DOWNLOAD_NAME
                 || *aattribute==CHARSET_NAME)                  || aattribute==CHARSET_NAME)
                 return;                  return;
   
         SAPI::add_header_attribute(r->sapi_info,          SAPI::add_header_attribute(r->sapi_info,
                 aattribute->cstr(),                   aattribute.cstr(), 
                 attributed_meaning_to_string(r->ameaning, String::L_HTTP_HEADER, false)->                  attributed_meaning_to_string(*ameaning, String::L_HTTP_HEADER, false).
                         cstr(String::L_UNSPECIFIED));                          cstr(String::L_UNSPECIFIED));
 }  }
 void Request::output_result(VFile* 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(sapi_info);          cookie.output_result(sapi_info);
                   
         Value* body_file_content_type;          Value* body_file_content_type;
         // set content-type          // set content-type
Line 598  void Request::output_result(VFile* body_ Line 597  void Request::output_result(VFile* body_
         } else {          } else {
                 // default content type                  // default content type
                 response.fields().put_dont_replace(content_type_name,                   response.fields().put_dont_replace(content_type_name, 
                         new VString(*new StringBody(DEFAULT_CONTENT_TYPE)))));                          new VString(*new String(DEFAULT_CONTENT_TYPE)));
         }          }
   
         // content-disposition          // content-disposition
         if(Value* 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()!=NONAME_DAT) {
                         VHash* hash(new VHash);                          VHash& hash=*new VHash();
                         HashStringValue &h=hash->hash(0);                          HashStringValue &h=hash.hash();
                         if(as_attachment)                          if(as_attachment)
                                 h.put(value_name, new VString(content_disposition_value)));                                  h.put(value_name, 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);
                 }                  }
   
         // prepare header: $response:fields without :body          // prepare header: $response:fields without :body
Line 649  const String& Request::mime_type_of(cons Line 648  const String& Request::mime_type_of(cons
                 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(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
                                         throw Exception("parser.runtime",                                          throw Exception("parser.runtime",
                                                 mime_types->origin_string(),                                                  0,
                                                 MIME_TYPES_NAME  " table column elements must not be empty");                                                  MIME_TYPES_NAME  " table column elements must not be empty");
                 }                  }
   
         return *new StringBody("application/octet-stream"));          return *new String("application/octet-stream");
 }  }
   
 #ifdef XML  #ifdef XML

Removed from v.1.245.2.37.2.7  
changed lines
  Added in v.1.245.2.37.2.11


E-mail: