Diff for /parser3/src/classes/file.C between versions 1.63 and 1.78

version 1.63, 2001/10/29 17:49:57 version 1.78, 2002/04/15 13:17:03
Line 1 Line 1
 /** @file  /** @file
         Parser: @b file parser class.          Parser: @b file parser class.
   
         Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
   
         $Id$          $Id$
 */  */
Line 20 Line 20
 #include "pa_vdate.h"  #include "pa_vdate.h"
 #include "pa_dir.h"  #include "pa_dir.h"
 #include "pa_vtable.h"  #include "pa_vtable.h"
   #include "pa_charset.h"
   
 // consts  // consts
   
Line 60  static void _save(Request& r, const Stri Line 61  static void _save(Request& r, const Stri
 }  }
   
 static void _delete(Request& r, const String&, MethodParams *params) {  static void _delete(Request& r, const String&, MethodParams *params) {
         Pool& pool=r.pool();  
         Value& vfile_name=params->as_no_junction(0, "file name must not be code");          Value& vfile_name=params->as_no_junction(0, "file name must not be code");
   
         // unlink          // unlink
         file_delete(pool, r.absolute(vfile_name.as_string()));          file_delete(r.absolute(vfile_name.as_string()));
 }  }
   
 static void _move(Request& r, const String&, MethodParams *params) {  static void _move(Request& r, const String&, MethodParams *params) {
         Pool& pool=r.pool();  
         Value& vfrom_file_name=params->as_no_junction(0, "from file name must not be code");          Value& vfrom_file_name=params->as_no_junction(0, "from file name must not be code");
         Value& vto_file_name=params->as_no_junction(1, "to file name must not be code");          Value& vto_file_name=params->as_no_junction(1, "to file name must not be code");
   
         // move          // move
         file_move(pool,           file_move(
                 r.absolute(vfrom_file_name.as_string()),                  r.absolute(vfrom_file_name.as_string()),
                 r.absolute(vto_file_name.as_string()));                  r.absolute(vto_file_name.as_string()));
 }  }
Line 86  static void _find(Request& r, const Stri Line 85  static void _find(Request& r, const Stri
   
         // passed file name simply exists in current dir          // passed file name simply exists in current dir
         if(file_readable(r.absolute(lfile_name))) {          if(file_readable(r.absolute(lfile_name))) {
                 r.write_no_lang(*new(pool) VString(lfile_name));                  r.write_no_lang(lfile_name);
                 return;                  return;
         }          }
   
         // scan .. dirs for result          // scan .. dirs for result
         for(int i=0; i<FIND_MONKEY_MAX_HOPS; i++) {          for(int i=0; i<FIND_MONKEY_MAX_HOPS; i++) {
                 String test_name(pool);                  String local_test_name(pool);
                 for(int j=0; j<i; j++)                  for(int j=0; j<i; j++)
                         test_name.APPEND_CONST("../");                          local_test_name.APPEND_CONST("../");
                 test_name.append(lfile_name, String::UL_CLEAN);                  local_test_name.append(lfile_name, String::UL_CLEAN);
                 if(file_readable(r.absolute(test_name))) {                  if(file_readable(r.absolute(local_test_name))) {
                         r.write_no_lang(*new(pool) VString(*new(pool) String(test_name)));                          r.write_no_lang(*new(pool) String(local_test_name));
                         return;                          return;
                 }                  }
         }          }
Line 193  static void _exec_cgi(Request& r, const Line 192  static void _exec_cgi(Request& r, const
         // from Request.info          // from Request.info
         ECSTR(DOCUMENT_ROOT, r.info.document_root);          ECSTR(DOCUMENT_ROOT, r.info.document_root);
         ECSTR(PATH_TRANSLATED, r.info.path_translated);          ECSTR(PATH_TRANSLATED, r.info.path_translated);
         ECSTR(SERVER_PROTOCOL, r.info.method);          ECSTR(REQUEST_METHOD, r.info.method);
         ECSTR(QUERY_STRING, r.info.query_string);          ECSTR(QUERY_STRING, r.info.query_string);
         ECSTR(REQUEST_URI, r.info.uri);          ECSTR(REQUEST_URI, r.info.uri);
         ECSTR(CONTENT_TYPE, r.info.content_type);          ECSTR(CONTENT_TYPE, r.info.content_type);
Line 204  static void _exec_cgi(Request& r, const Line 203  static void _exec_cgi(Request& r, const
         ECSTR(HTTP_COOKIE, r.info.cookie);          ECSTR(HTTP_COOKIE, r.info.cookie);
         ECSTR(HTTP_USER_AGENT, r.info.user_agent);          ECSTR(HTTP_USER_AGENT, r.info.user_agent);
         // passing some SAPI:get_env-s          // passing some SAPI:get_env-s
           EPASS(SERVER_PROTOCOL);
         EPASS(SERVER_NAME);          EPASS(SERVER_NAME);
         EPASS(SERVER_PORT);          EPASS(SERVER_PORT);
         EPASS(HTTP_REFERER);          EPASS(HTTP_REFERER);
Line 236  static void _exec_cgi(Request& r, const Line 236  static void _exec_cgi(Request& r, const
         //out.APPEND_CONST("content-type:text/plain\nheader:test-header\n\ntest-body");          //out.APPEND_CONST("content-type:text/plain\nheader:test-header\n\ntest-body");
         //out<<in;          //out<<in;
         String& err=*new(pool) String(pool);          String& err=*new(pool) String(pool);
         int status=pa_exec(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.self);
   
Line 252  static void _exec_cgi(Request& r, const Line 252  static void _exec_cgi(Request& r, const
                 }                  }
                 if(pos<0) {                  if(pos<0) {
                         delim_size=0; // calm down, compiler                          delim_size=0; // calm down, compiler
                         throw Exception(0, 0,                          throw Exception(0,
                                 &method_name,                                  &method_name,
                                 "output does not contain CGI header; exit code=%d; outsize=%u; out: \"%s\"; errsize=%u; err: \"%s\"",                                   "output does not contain CGI header; exit code=%d; outsize=%u; out: \"%s\"; errsize=%u; err: \"%s\"", 
                                         status,                                           status, 
Line 271  static void _exec_cgi(Request& r, const Line 271  static void _exec_cgi(Request& r, const
                 }                  }
         }          }
         // body          // body
         self.set(false/*not tainted*/, body->cstr(String::UL_AS_IS), body->size());          self.set(false/*not tainted*/, body->cstr(), body->size());
   
         // $status          // $status
         self.fields().put(          self.fields().put(
Line 306  static void _list(Request& r, const Stri Line 306  static void _list(Request& r, const Stri
         if(params->size()>1) {          if(params->size()>1) {
                 regexp=&params->as_no_junction(1, "regexp must not be code").as_string();                  regexp=&params->as_no_junction(1, "regexp must not be code").as_string();
   
                 const char *pattern=regexp->cstr(String::UL_AS_IS);                  const char *pattern=regexp->cstr();
                 const char *errptr;                  const char *errptr;
                 int erroffset;                  int erroffset;
                 regexp_code=pcre_compile(pattern, PCRE_EXTRA | PCRE_DOTALL,                   regexp_code=pcre_compile(pattern, PCRE_EXTRA | PCRE_DOTALL, 
                         &errptr, &erroffset,                           &errptr, &erroffset, 
                         r.pcre_tables());                          pool.get_client_charset().pcre_tables);
   
                 if(!regexp_code)                  if(!regexp_code)
                         throw Exception(0, 0,                           throw Exception(0, 
                                 &regexp->mid(erroffset, regexp->size()),                                   &regexp->mid(erroffset, regexp->size()), 
                                 "regular expression syntax error - %s", errptr);                                  "regular expression syntax error - %s", errptr);
   
Line 342  static void _list(Request& r, const Stri Line 342  static void _list(Request& r, const Stri
                                 suits=false;                                  suits=false;
                         else if(exec_result<0) {                          else if(exec_result<0) {
                                 (*pcre_free)(regexp_code);                                  (*pcre_free)(regexp_code);
                                 throw Exception(0, 0,                                   throw Exception(0, 
                                         regexp,                                           regexp, 
                                         "regular expression execute (%d)",                                           "regular expression execute (%d)", 
                                                 exec_result);                                                  exec_result);
Line 371  static void _list(Request& r, const Stri Line 371  static void _list(Request& r, const Stri
         r.write_no_lang(result);          r.write_no_lang(result);
 }  }
   
   #ifndef DOXYGEN
   struct Lock_execute_body_info {
           Request *r;
           Value *body_code;
   };
   #endif
   static void lock_execute_body(int , void *context) {
           Lock_execute_body_info& info=*static_cast<Lock_execute_body_info *>(context);
   
           // execute body
           info.r->write_assign_lang(info.r->process(*info.body_code));
   };
   static void _lock(Request& r, const String& method_name, MethodParams *params) {
           const String& file_spec=r.absolute(params->as_string(0, "file name must be string"));
           Value& body_code=params->as_junction(1, "body must be code");
   
           Lock_execute_body_info info={&r, &body_code};
           file_write_action_under_lock(file_spec, "lock", lock_execute_body, &info);
   }
   
 // constructor  // constructor
   
 MFile::MFile(Pool& apool) : Methoded(apool) {  MFile::MFile(Pool& apool) : Methoded(apool) {
Line 411  MFile::MFile(Pool& apool) : Methoded(apo Line 431  MFile::MFile(Pool& apool) : Methoded(apo
         // ^file:list[path][regexp]          // ^file:list[path][regexp]
         add_native_method("list", Method::CT_STATIC, _list, 1, 2);          add_native_method("list", Method::CT_STATIC, _list, 1, 2);
   
           // ^file:lock[path]{code}
           add_native_method("lock", Method::CT_STATIC, _lock, 2, 2);
   
 }  }
   
 // global variable  // global variable

Removed from v.1.63  
changed lines
  Added in v.1.78


E-mail: