Diff for /parser3/src/classes/file.C between versions 1.95 and 1.99

version 1.95, 2002/08/08 09:35:22 version 1.99, 2002/09/18 08:52:47
Line 95  static void _save(Request& r, const Stri Line 95  static void _save(Request& r, const Stri
         Value& vfile_name=params->as_no_junction(1, "file name must not be code");          Value& vfile_name=params->as_no_junction(1, "file name must not be code");
   
         // save          // save
         static_cast<VFile *>(r.self)->save(r.absolute(vfile_name.as_string()),          static_cast<VFile *>(r.get_self())->save(r.absolute(vfile_name.as_string()),
                 vmode_name.as_string()==TEXT_MODE_NAME);                  vmode_name.as_string()==TEXT_MODE_NAME);
 }  }
   
Line 129  static void _load(Request& r, const Stri Line 129  static void _load(Request& r, const Stri
                 params->as_string(2, "filename must be string").cstr(String::UL_FILE_SPEC)                  params->as_string(2, "filename must be string").cstr(String::UL_FILE_SPEC)
                 :lfile_name.cstr(String::UL_FILE_SPEC);                  :lfile_name.cstr(String::UL_FILE_SPEC);
                   
         static_cast<VFile *>(r.self)->set(true/*tainted*/, data, size,           static_cast<VFile *>(r.get_self())->set(true/*tainted*/, data, size, 
                 user_file_name, new(pool) VString(r.mime_type_of(user_file_name)));                  user_file_name, new(pool) VString(r.mime_type_of(user_file_name)));
 }  }
   
Line 145  static void _stat(Request& r, const Stri Line 145  static void _stat(Request& r, const Stri
                 size,                  size,
                 atime, mtime, ctime);                  atime, mtime, ctime);
                   
         VFile& vfile=*static_cast<VFile *>(r.self);          VFile& vfile=*static_cast<VFile *>(r.get_self());
         vfile.set(true/*tainted*/, 0/*no bytes*/, size);          vfile.set(true/*tainted*/, 0/*no bytes*/, size);
         Hash& ff=vfile.fields();          Hash& ff=vfile.fields();
         ff.put(*new(pool) String(pool, "adate"), new(pool) VDate(pool, atime));          ff.put(*new(pool) String(pool, "adate"), new(pool) VDate(pool, atime));
Line 277  static void _exec_cgi(Request& r, const Line 277  static void _exec_cgi(Request& r, const
         String& err=*new(pool) String(pool);          String& err=*new(pool) String(pool);
         int status=pa_exec(false/*forced_allow*/, script_name, &env, argv, in, out, err);          int status=pa_exec(false/*forced_allow*/, script_name, &env, argv, in, out, err);
   
         VFile& self=*static_cast<VFile *>(r.self);          VFile& self=*static_cast<VFile *>(r.get_self());
   
         const String *body=&out; // ^file:exec          const String *body=&out; // ^file:exec
         Value *content_type=0;          Value *content_type=0;
         const char *eol_marker="\r\n"; size_t eol_marker_size=2;          const char *eol_marker=0; size_t eol_marker_size;
         const String *header=0;          const String *header=0;
         if(cgi) { // ^file:cgi          if(cgi) { // ^file:cgi
                 // construct with 'out' body and header                  // construct with 'out' body and header
                 int delim_size;                  int dos_pos=out.pos("\r\n\r\n", 4);
                 int pos=out.pos("\r\n\r\n", delim_size=4);                  int unix_pos=out.pos("\n\n", 2);
                 if(pos<0) {  
                         eol_marker="\n"; eol_marker_size=1;                  bool unix_header_break;
                         pos=out.pos("\n\n", delim_size=2);                  switch((dos_pos >= 0?10:00) + (unix_pos >= 0?01:00)) {
                 }                  case 10: // dos
                 if(pos<0) {                          unix_header_break=false;
                         delim_size=0; // calm down, compiler                          break;
                   case 01: // unix
                           unix_header_break=true;
                           break;
                   case 11: // dos & unix
                           unix_header_break=unix_pos<dos_pos;
                           break;
                   default: // 00
                           unix_header_break=false; // calm down, compiler
                         throw Exception(0,                          throw Exception(0,
                                 &method_name,                                  &method_name,
                                 "output does not contain CGI header; "                                  "output does not contain CGI header; "
Line 300  static void _exec_cgi(Request& r, const Line 308  static void _exec_cgi(Request& r, const
                                         status,                                           status, 
                                         (uint)out.size(), out.cstr(),                                          (uint)out.size(), out.cstr(),
                                         (uint)err.size(), err.cstr());                                          (uint)err.size(), err.cstr());
                           break; //never reached
                 }                  }
   
                 header=&out.mid(0, pos);                  int header_break_pos;
                 body=&out.mid(pos+delim_size, out.size());                  if(unix_header_break) {
                           header_break_pos=unix_pos;
                           eol_marker="\n"; eol_marker_size=1;
                   } else {
                           header_break_pos=dos_pos;
                           eol_marker="\r\n"; eol_marker_size=2;
                   }
   
                   header=&out.mid(0, header_break_pos);
                   body=&out.mid(header_break_pos+eol_marker_size*2, out.size());
         }          }
         // body          // body
         self.set(false/*not tainted*/, body->cstr(), body->size());          self.set(false/*not tainted*/, body->cstr(), body->size());
   
         // $fields << header          // $fields << header
         if(header) {          if(header && eol_marker) {
                 Array rows(pool);                  Array rows(pool);
                 header->split(rows, 0, eol_marker, eol_marker_size);                  header->split(rows, 0, eol_marker, eol_marker_size);
                 Pass_cgi_header_attribute_info info={&self.fields()};                  Pass_cgi_header_attribute_info info={&self.fields()};
Line 328  static void _exec_cgi(Request& r, const Line 346  static void _exec_cgi(Request& r, const
                 self.fields().put(                  self.fields().put(
                         *new(pool) String(pool, "stderr"),                          *new(pool) String(pool, "stderr"),
                         new(pool) VString(err));                          new(pool) VString(err));
   
                 SAPI::log(pool, "file:%s: %s", cgi?"cgi":"exec", err.cstr());  
         }          }
 }  }
 static void _exec(Request& r, const String& method_name, MethodParams *params) {  static void _exec(Request& r, const String& method_name, MethodParams *params) {
Line 459  static void _find(Request& r, const Stri Line 475  static void _find(Request& r, const Stri
   
         // easy way          // easy way
         if(file_readable(r.absolute(*file_spec))) {          if(file_readable(r.absolute(*file_spec))) {
                 r.write_no_lang(*file_spec);                  r.write_assign_lang(*file_spec);
                 return;                  return;
         }          }
   
Line 474  static void _find(Request& r, const Stri Line 490  static void _find(Request& r, const Stri
                 local_test_name<<*(dirname=&dirname->mid(0, after_monkey_slash));                  local_test_name<<*(dirname=&dirname->mid(0, after_monkey_slash));
                 local_test_name<<basename;                  local_test_name<<basename;
                 if(file_readable(r.absolute(local_test_name))) {                  if(file_readable(r.absolute(local_test_name))) {
                         r.write_no_lang(*new(pool) String(local_test_name));                          r.write_assign_lang(*new(pool) String(local_test_name));
                         return;                          return;
                 }                  }
         }          }

Removed from v.1.95  
changed lines
  Added in v.1.99


E-mail: