Diff for /parser3/src/classes/file.C between versions 1.151 and 1.166

version 1.151, 2007/02/07 15:50:32 version 1.166, 2008/02/14 09:10:23
Line 114  static const String::Body cdate_name("cd Line 114  static const String::Body cdate_name("cd
   
 // methods  // methods
   
   static bool is_valid_mode (const String& mode) {
           return (mode==TEXT_MODE_NAME || mode==BINARY_MODE_NAME);
   }
   
 static bool is_text_mode(const String& mode) {  static bool is_text_mode(const String& mode) {
         if(mode==TEXT_MODE_NAME)          if(mode==TEXT_MODE_NAME)
                 return true;                  return true;
         if(mode==BINARY_MODE_NAME)          if(mode==BINARY_MODE_NAME)
                 return false;                  return false;
         throw Exception("parser.runtime",          throw Exception(PARSER_RUNTIME,
                 &mode,                  &mode,
                 "is invalid mode, must be either '"TEXT_MODE_NAME"' or '"BINARY_MODE_NAME"'");                  "is invalid mode, must be either '"TEXT_MODE_NAME"' or '"BINARY_MODE_NAME"'");
 }  }
   
 static void _save(Request& r, MethodParams& params) {  static void _save(Request& r, MethodParams& params) {
         Value& vmode_name=params. as_no_junction(0, "mode must not be code");          Value& vmode_name=params.as_no_junction(0, MODE_MUST_NOT_BE_CODE);
         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
         GET_SELF(r, VFile).save(r.absolute(vfile_name.as_string()),          GET_SELF(r, VFile).save(r.absolute(vfile_name.as_string()),
Line 134  static void _save(Request& r, MethodPara Line 138  static void _save(Request& r, MethodPara
 }  }
   
 static void _delete(Request& r, MethodParams& params) {  static void _delete(Request& r, MethodParams& params) {
         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(r.absolute(vfile_name.as_string()));          file_delete(r.absolute(vfile_name.as_string()));
Line 182  static void _copy(Request& r, MethodPara Line 186  static void _copy(Request& r, MethodPara
         String from_spec = r.absolute(vfrom_file_name.as_string());          String from_spec = r.absolute(vfrom_file_name.as_string());
         const String& to_spec = r.absolute(vto_file_name.as_string());          const String& to_spec = r.absolute(vto_file_name.as_string());
                   
         create_dir_for_file(to_spec);   
           
         file_write_action_under_lock(          file_write_action_under_lock(
                         to_spec,                          to_spec,
                         "copy",                          "copy",
Line 198  static void _load_pass_param( Line 200  static void _load_pass_param(
         dest->put(key, value);          dest->put(key, value);
 }  }
 static void _load(Request& r, MethodParams& params) {  static void _load(Request& r, MethodParams& params) {
         Value& vmode_name=params. as_no_junction(0, "mode must not be code");          Value& vmode_name=params.as_no_junction(0, MODE_MUST_NOT_BE_CODE);
         const String& lfile_name=r.absolute(params.as_no_junction(1, "file name must not be code").as_string());          const String& lfile_name=r.absolute(params.as_no_junction(1, FILE_NAME_MUST_NOT_BE_CODE).as_string());
         Value* third_param=params.count()>2?&params.as_no_junction(2, "filename or options must not be code")          Value* third_param=params.count()>2?&params.as_no_junction(2, "filename or options must not be code")
                 :0;                  :0;
         HashStringValue* third_param_hash=third_param?third_param->get_hash():0;          HashStringValue* third_param_hash=third_param?third_param->get_hash():0;
Line 226  static void _load(Request& r, MethodPara Line 228  static void _load(Request& r, MethodPara
         );          );
   
         const char *user_file_name=params.count()>alt_filename_param_index?          const char *user_file_name=params.count()>alt_filename_param_index?
                 params.as_string(alt_filename_param_index, "filename must be string").cstr()                  params.as_string(alt_filename_param_index, FILE_NAME_MUST_BE_STRING).cstr()
                 :lfile_name.cstr(String::L_FILE_SPEC);                  :lfile_name.cstr(String::L_FILE_SPEC);
   
         Value* vcontent_type=0;          Value* vcontent_type=0;
Line 245  static void _load(Request& r, MethodPara Line 247  static void _load(Request& r, MethodPara
 }  }
   
 static void _create(Request& r, MethodParams& params) {  static void _create(Request& r, MethodParams& params) {
         Value& vmode_name=params. as_no_junction(0, "mode must not be code");          Value& vmode_name=params.as_no_junction(0, MODE_MUST_NOT_BE_CODE);
         if(!is_text_mode(vmode_name.as_string()))          if(!is_text_mode(vmode_name.as_string()))
                 throw Exception("parser.runtime",                  throw Exception(PARSER_RUNTIME,
                         0,                          0,
                         "only text mode is currently supported");                          "only text mode is currently supported");
   
         const char* user_file_name_cstr=r.absolute(          const char* user_file_name_cstr=r.absolute(
                 params.as_no_junction(1, "file name must not be code").as_string()).cstr(String::L_FILE_SPEC);                  params.as_no_junction(1, FILE_NAME_MUST_NOT_BE_CODE).as_string()).cstr(String::L_FILE_SPEC);
   
         const String& content=params.as_string(2, "content must be string");          const String& content=params.as_string(2, "content must be string");
         const char* content_cstr=content.cstr(String::L_UNSPECIFIED); // explode content, honor tainting changes          const char* content_cstr=content.cstr(String::L_UNSPECIFIED); // explode content, honor tainting changes
Line 264  static void _create(Request& r, MethodPa Line 266  static void _create(Request& r, MethodPa
 }  }
   
 static void _stat(Request& r, MethodParams& params) {  static void _stat(Request& r, MethodParams& params) {
         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);
   
         const String& lfile_name=vfile_name.as_string();          const String& lfile_name=vfile_name.as_string();
   
Line 316  static void append_env_pair( Line 318  static void append_env_pair(
                 // ignore, already processed                  // ignore, already processed
         } else {          } else {
                 if(!is_safe_env_key(akey.cstr()))                  if(!is_safe_env_key(akey.cstr()))
                         throw Exception("parser.runtime",                          throw Exception(PARSER_RUNTIME,
                                 new String(akey, String::L_TAINTED),                                  new String(akey, String::L_TAINTED),
                                 "not safe environment variable");                                  "not safe environment variable");
                 info->env->put(akey, avalue->as_string().cstr_to_string_body(String::L_UNSPECIFIED, 0, info->charsets));                  info->env->put(akey, avalue->as_string().cstr_to_string_body(String::L_UNSPECIFIED, 0, info->charsets));
Line 342  static void pass_cgi_header_attribute( Line 344  static void pass_cgi_header_attribute(
                         info->content_type=value;                          info->content_type=value;
         }          }
 }  }
   
   static void append_to_argv(Request& r, ArrayString& argv, const String* str){
           if( str->length() ){
                   argv+=new String(str->cstr_to_string_body(String::L_UNSPECIFIED, 0, &r.charsets), String::L_AS_IS);
           }
   }
   
   inline size_t strpos(const char *s1, const char *s2) {
           const char *p = strstr(s1, s2);
           return (p==0)?STRING_NOT_FOUND:p-s1;
   }
   
 /// @todo fix `` in perl - they produced flipping consoles and no output to perl  /// @todo fix `` in perl - they produced flipping consoles and no output to perl
 static void _exec_cgi(Request& r, MethodParams& params,  static void _exec_cgi(Request& r, MethodParams& params,
                                           bool cgi) {                                            bool cgi) {
   
         Value& vfile_name=params.as_no_junction(0, "file name must not be code");          Value& first_param=params.as_no_junction(0, FIRST_ARG_MUST_NOT_BE_CODE);                        
           
           bool is_mode_specified=is_valid_mode(first_param.as_string());
           const String& mode_name=(is_mode_specified) ? first_param.as_string() : *new String(TEXT_MODE_NAME);
   
           size_t param_index=1;
           if(!is_mode_specified){
                   --param_index;
           }
   
           if(param_index>=params.count())
                   throw Exception(PARSER_RUNTIME,
                           0,
                           "file name must be specified");
   
   
           Value& vfile_name=params.as_no_junction(param_index++, FILE_NAME_MUST_NOT_BE_CODE);
   
         const String& script_name=r.absolute(vfile_name.as_string());          const String& script_name=r.absolute(vfile_name.as_string());
   
Line 387  static void _exec_cgi(Request& r, Method Line 417  static void _exec_cgi(Request& r, Method
         // environment & stdin from param          // environment & stdin from param
         String *in=new String();          String *in=new String();
         Charset *charset=0; // default script works raw_in 'source' charset = no transcoding needed          Charset *charset=0; // default script works raw_in 'source' charset = no transcoding needed
         if(params.count()>1) {          if(param_index < params.count()) {
                 Value& venv=params.as_no_junction(1, "env must not be code");                  Value& venv=params.as_no_junction(param_index++, "env must not be code");
                 if(HashStringValue* user_env=venv.get_hash()) {                  if(HashStringValue* user_env=venv.get_hash()) {
                         // $.charset  [previewing to handle URI pieces]                          // $.charset  [previewing to handle URI pieces]
                         if(Value* vcharset=user_env->get(CHARSET_EXEC_PARAM_NAME))                          if(Value* vcharset=user_env->get(CHARSET_EXEC_PARAM_NAME))
Line 412  static void _exec_cgi(Request& r, Method Line 442  static void _exec_cgi(Request& r, Method
                                         if(VFile* vfile=static_cast<VFile *>(info.vstdin->as("file", false)))                                          if(VFile* vfile=static_cast<VFile *>(info.vstdin->as("file", false)))
                                                 in->append_know_length((const char* )vfile->value_ptr(), vfile->value_size(), String::L_TAINTED);                                                  in->append_know_length((const char* )vfile->value_ptr(), vfile->value_size(), String::L_TAINTED);
                                         else                                          else
                                                 throw Exception("parser.runtime",                                                  throw Exception(PARSER_RUNTIME,
                                                         0,                                                          0,
                                                         STDIN_EXEC_PARAM_NAME " parameter must be string or file");                                                          STDIN_EXEC_PARAM_NAME " parameter must be string or file");
                         }                          }
Line 421  static void _exec_cgi(Request& r, Method Line 451  static void _exec_cgi(Request& r, Method
   
         // argv from params          // argv from params
         ArrayString argv;          ArrayString argv;
         if(params.count()>2) {          if(param_index < params.count()) {
                 // influence tainting                   // influence tainting 
                 // main target -- URLencoding of tainted pieces to String::L_URI lang                  // main target -- URLencoding of tainted pieces to String::L_URI lang
                 Temp_client_charset temp(r.charsets, charset? *charset: r.charsets.source());                  Temp_client_charset temp(r.charsets, charset? *charset: r.charsets.source());
                 for(size_t i=2; i<params.count(); i++) {  
                         const String& param=params.as_string(i, "parameter must be string");                  for(size_t i=param_index; i<params.count(); i++) {
                         if(param.length() > 0) {                          Value& param=params.as_no_junction(i, PARAM_MUST_NOT_BE_CODE);
                                 argv+=new String(param.cstr_to_string_body(String::L_UNSPECIFIED, 0, &r.charsets), String::L_AS_IS);                          if(param.is_defined()){
                                   if(param.is_string()){
                                           append_to_argv(r, argv, param.get_string());
                                   } else {
                                           Table* table=param.get_table();
                                           if(table){
                                                   for(size_t i=0; i<table->count(); i++) {
                                                           append_to_argv(r, argv, table->get(i)->get(0));
                                                   }
                                           } else {
                                                   throw Exception(PARSER_RUNTIME,
                                                           0,
                                                           "param must be string or table");
                                           }
                                   }
                         }                          }
                 }                  }
         }          }
Line 444  static void _exec_cgi(Request& r, Method Line 488  static void _exec_cgi(Request& r, Method
         // match silent conversion in OS          // match silent conversion in OS
   
         // exec!          // exec!
         PA_exec_result execution=          PA_exec_result execution=pa_exec(false/*forced_allow*/, script_name, &env, argv, *in);
                 pa_exec(false/*forced_allow*/, script_name, &env, argv, *in);  
   
         String *real_out=&execution.out;          File_read_result *file_out=&execution.out;
         String *real_err=&execution.err;          String *real_err=&execution.err;
         // transcode if necessary  
         if(charset) {          // transcode err if necessary (@todo: need fix line breaks in err as well )
                 real_out=&Charset::transcode(*real_out, *charset, r.charsets.source());          if(charset)
                 real_err=&Charset::transcode(*real_err, *charset, r.charsets.source());                  real_err=&Charset::transcode(*real_err, *charset, r.charsets.source());
   
           if(file_out->length && is_text_mode(mode_name)){
                   fix_line_breaks(file_out->str, file_out->length);
                   // treat output as string
                   String *real_out = new String(file_out->str, file_out->length);
   
                   // transcode out if necessary
                   if(charset)
                           real_out=&Charset::transcode(*real_out, *charset, r.charsets.source());
   
                   // FIXME: unsafe cast
                   file_out->str=const_cast<char *>(real_out->cstr()); // hacking a little
                   file_out->length = real_out->length();
         }          }
   
         VFile& self=GET_SELF(r, VFile);          VFile& self=GET_SELF(r, VFile);
   
         const String* body=real_out; // ^file:exec          if(cgi) { // ^file::cgi
         const char* eol_marker=0; size_t eol_marker_size;                  const char* eol_marker=0;
         const String* header=0;                  size_t eol_marker_size;
         if(cgi) { // ^file:cgi  
                 // construct with 'out' body and header                  // construct with 'out' body and header
                 size_t dos_pos=real_out->pos("\r\n\r\n", 4);                  size_t dos_pos=(file_out->length)?strpos(file_out->str, "\r\n\r\n"):STRING_NOT_FOUND;
                 size_t unix_pos=real_out->pos("\n\n", 2);                  size_t unix_pos=(file_out->length)?strpos(file_out->str, "\n\n"):STRING_NOT_FOUND;
   
                 bool unix_header_break;                  bool unix_header_break;
                 switch((dos_pos!=STRING_NOT_FOUND?10:00) + (unix_pos!=STRING_NOT_FOUND?01:00)) {                  switch((dos_pos!=STRING_NOT_FOUND?10:00) + (unix_pos!=STRING_NOT_FOUND?01:00)) {
                 case 10: // dos                          case 10: // dos
                         unix_header_break=false;                                  unix_header_break=false;
                         break;                                  break;
                 case 01: // unix                          case 01: // unix
                         unix_header_break=true;                                  unix_header_break=true;
                         break;                                  break;
                 case 11: // dos & unix                          case 11: // dos & unix
                         unix_header_break=unix_pos<dos_pos;                                  unix_header_break=unix_pos<dos_pos;
                         break;                                  break;
                 default: // 00                          default: // 00
                         unix_header_break=false; // calm down, compiler                                  unix_header_break=false; // calm down, compiler
                         throw Exception(0,                                  throw Exception(0,
                                 0,                                          0,
                                 "output does not contain CGI header; "                                          "output does not contain CGI header; "
                                 "exit status=%d; stdoutsize=%u; stdout: \"%s\"; stderrsize=%u; stderr: \"%s\"",                                           "exit status=%d; stdoutsize=%u; stdout: \"%s\"; stderrsize=%u; stderr: \"%s\"", 
                                         execution.status,                                                   execution.status, 
                                         (uint)real_out->length(), real_out->cstr(),                                                  (size_t)file_out->length, (file_out->length) ? (file_out->str) : "",
                                         (uint)real_err->length(), real_err->cstr());                                                  (size_t)real_err->length(), real_err->cstr());
                         break; //never reached                                  break; //never reached
                 }                  }
   
                 int header_break_pos;                  size_t header_break_pos;
                 if(unix_header_break) {                  if(unix_header_break) {
                         header_break_pos=unix_pos;                          header_break_pos=unix_pos;
                         eol_marker="\n"; eol_marker_size=1;                          eol_marker="\n";
                           eol_marker_size=1;
                 } else {                  } else {
                         header_break_pos=dos_pos;                          header_break_pos=dos_pos;
                         eol_marker="\r\n"; eol_marker_size=2;                          eol_marker="\r\n";
                           eol_marker_size=2;
                 }                  }
   
                 header=&real_out->mid(0, header_break_pos);                  file_out->str[header_break_pos] = 0;
                 body=&real_out->mid(header_break_pos+eol_marker_size*2, real_out->length());                  String *header=new String(file_out->str, header_break_pos);
         }                  unsigned long headersize = header_break_pos+eol_marker_size*2;
         // body                  file_out->str += headersize;
         self.set(false/*not tainted*/, body->cstr(), body->length());                  file_out->length -= headersize;
   
         // $fields << header                  // $body
         if(header && eol_marker) {                  self.set(false/*not tainted*/, file_out->str, file_out->length);
                 ArrayString rows;  
                 size_t pos_after=0;                  // $fields << header
                 header->split(rows, pos_after, eol_marker);                  if(header && eol_marker) {
                 Pass_cgi_header_attribute_info info={0, 0, 0};                          ArrayString rows;
                 info.charset=&r.charsets.source();                          size_t pos_after=0;
                 info.fields=&self.fields();                          header->split(rows, pos_after, eol_marker);
                 rows.for_each(pass_cgi_header_attribute, &info);                          Pass_cgi_header_attribute_info info={0, 0, 0};
                 if(info.content_type)                          info.charset=&r.charsets.source();
                         self.fields().put(content_type_name, info.content_type);                          info.fields=&self.fields();
                           rows.for_each(pass_cgi_header_attribute, &info);
                           if(info.content_type)
                                   self.fields().put(content_type_name, info.content_type);
                   }
           } else { // ^file::exec
                   // $body
                   self.set(false/*not tainted*/, file_out->str, file_out->length);
         }          }
   
         // $status          // $status
Line 611  static void lock_execute_body(int , void Line 676  static void lock_execute_body(int , void
         info.r->write_assign_lang(info.r->process(*info.body_code));          info.r->write_assign_lang(info.r->process(*info.body_code));
 };  };
 static void _lock(Request& r, MethodParams& params) {  static void _lock(Request& r, MethodParams& params) {
         const String& file_spec=r.absolute(params.as_string(0, "file name must be string"));          const String& file_spec=r.absolute(params.as_string(0, FILE_NAME_MUST_BE_STRING));
         Lock_execute_body_info info={          Lock_execute_body_info info={
                 &r,                   &r, 
                 &params.as_junction(1, "body must be code")                  &params.as_junction(1, "body must be code")
         };          };
   
         file_write_action_under_lock(file_spec, "lock", lock_execute_body, &info);          file_write_action_under_lock(
                           file_spec,
                           "lock",
                           lock_execute_body,
                           &info);
 }  }
   
 static int lastposafter(const String& s, size_t after, const char* substr, size_t substr_size, bool beforelast=false) {  static int lastposafter(const String& s, size_t after, const char* substr, size_t substr_size, bool beforelast=false) {
Line 636  static int lastposafter(const String& s, Line 705  static int lastposafter(const String& s,
 }  }
   
 static void _find(Request& r, MethodParams& params) {  static void _find(Request& r, MethodParams& params) {
         const String& file_name=params.as_no_junction(0, "file name must not be code").as_string();          const String& file_name=params.as_no_junction(0, FILE_NAME_MUST_NOT_BE_CODE).as_string();
         const String* file_spec;          const String* file_spec;
         if(file_name.first_char()=='/')          if(file_name.first_char()=='/')
                 file_spec=&file_name;                  file_spec=&file_name;
Line 673  static void _find(Request& r, MethodPara Line 742  static void _find(Request& r, MethodPara
 }  }
   
 static void _dirname(Request& r, MethodParams& params) {  static void _dirname(Request& r, MethodParams& params) {
         const String& file_spec=params.as_string(0, "file name must be string");          const String& file_spec=params.as_string(0, FILE_NAME_MUST_BE_STRING);
     // /a/some.tar.gz > /a      // /a/some.tar.gz > /a
         // /a/b/ > /a          // /a/b/ > /a
         int afterslash=lastposafter(file_spec, 0, "/", 1, true);          int afterslash=lastposafter(file_spec, 0, "/", 1, true);
Line 684  static void _dirname(Request& r, MethodP Line 753  static void _dirname(Request& r, MethodP
 }  }
   
 static void _basename(Request& r, MethodParams& params) {  static void _basename(Request& r, MethodParams& params) {
         const String& file_spec=params.as_string(0, "file name must be string");          const String& file_spec=params.as_string(0, FILE_NAME_MUST_BE_STRING);
     // /a/some.tar.gz > some.tar.gz      // /a/some.tar.gz > some.tar.gz
         int afterslash=lastposafter(file_spec, 0, "/", 1);          int afterslash=lastposafter(file_spec, 0, "/", 1);
         r.write_assign_lang(file_spec.mid(afterslash, file_spec.length()));          r.write_assign_lang(file_spec.mid(afterslash, file_spec.length()));
 }  }
   
 static void _justname(Request& r, MethodParams& params) {  static void _justname(Request& r, MethodParams& params) {
         const String& file_spec=params.as_string(0, "file name must be string");          const String& file_spec=params.as_string(0, FILE_NAME_MUST_BE_STRING);
     // /a/some.tar.gz > some.tar      // /a/some.tar.gz > some.tar
         int afterslash=lastposafter(file_spec, 0, "/", 1);          int afterslash=lastposafter(file_spec, 0, "/", 1);
         int afterdot=lastposafter(file_spec, afterslash, ".", 1);          int afterdot=lastposafter(file_spec, afterslash, ".", 1);
         r.write_assign_lang(file_spec.mid(afterslash, afterdot!=afterslash?afterdot-1:file_spec.length()));          r.write_assign_lang(file_spec.mid(afterslash, afterdot!=afterslash?afterdot-1:file_spec.length()));
 }  }
 static void _justext(Request& r, MethodParams& params) {  static void _justext(Request& r, MethodParams& params) {
         const String& file_spec=params.as_string(0, "file name must be string");          const String& file_spec=params.as_string(0, FILE_NAME_MUST_BE_STRING);
     // /a/some.tar.gz > gz      // /a/some.tar.gz > gz
         int afterdot=lastposafter(file_spec, 0, ".", 1);          int afterdot=lastposafter(file_spec, 0, ".", 1);
         if(afterdot>0)          if(afterdot>0)
Line 706  static void _justext(Request& r, MethodP Line 775  static void _justext(Request& r, MethodP
 }  }
   
 static void _fullpath(Request& r, MethodParams& params) {  static void _fullpath(Request& r, MethodParams& params) {
         const String& file_spec=params.as_string(0, "file name must be string");          const String& file_spec=params.as_string(0, FILE_NAME_MUST_BE_STRING);
         const String* result;          const String* result;
         if(file_spec.first_char()=='/')          if(file_spec.first_char()=='/')
                 result=&file_spec;                  result=&file_spec;
Line 752  public: Line 821  public:
   
         bool add_column(SQL_Error& error, const char* /*str*/, size_t /*length*/) {          bool add_column(SQL_Error& error, const char* /*str*/, size_t /*length*/) {
                 if(got_columns++==3) {                  if(got_columns++==3) {
                         error=SQL_Error("parser.runtime", "result must contain not more then 3 columns");                          error=SQL_Error(PARSER_RUNTIME, "result must contain not more then 3 columns");
                         return true;                          return true;
                 }                  }
                 return false;                  return false;
Line 774  public: Line 843  public:
                                                 user_content_type=new String(str, length, true);                                                  user_content_type=new String(str, length, true);
                                         break;                                          break;
                                 default:                                  default:
                                         error=SQL_Error("parser.runtime", "result must not contain more then one row, three rows");                                          error=SQL_Error(PARSER_RUNTIME, "result must not contain more then one row, three rows");
                                         return true;                                          return true;
                         }                          }
                         return false;                          return false;
Line 796  static void _sql(Request& r, MethodParam Line 865  static void _sql(Request& r, MethodParam
   
         if(params.count()>1)          if(params.count()>1)
                 if(HashStringValue* options=                  if(HashStringValue* options=
                         params.as_no_junction(1, "param must not be code").get_hash()) {                          params.as_no_junction(1, PARAM_MUST_NOT_BE_CODE).get_hash()) {
                         int valid_options=0;                          int valid_options=0;
                         if(Value* vfilename=options->get(NAME_NAME)) {                          if(Value* vfilename=options->get(NAME_NAME)) {
                                 valid_options++;                                  valid_options++;
Line 807  static void _sql(Request& r, MethodParam Line 876  static void _sql(Request& r, MethodParam
                                 handlers.user_content_type=&vcontent_type->as_string();                                  handlers.user_content_type=&vcontent_type->as_string();
                         }                          }
                         if(valid_options!=options->count())                          if(valid_options!=options->count())
                                 throw Exception("parser.runtime",                                  throw Exception(PARSER_RUNTIME,
                                         0,                                          0,
                                         "called with invalid option");                                          "called with invalid option");
                 }                  }
Line 821  static void _sql(Request& r, MethodParam Line 890  static void _sql(Request& r, MethodParam
                 statement_string);                  statement_string);
   
         if(!handlers.value)          if(!handlers.value)
                 throw Exception("parser.runtime",                  throw Exception(PARSER_RUNTIME,
                         0,                          0,
                         "produced no result");                          "produced no result");
   
Line 842  static void _base64(Request& r, MethodPa Line 911  static void _base64(Request& r, MethodPa
         VFile& self=GET_SELF(r, VFile);          VFile& self=GET_SELF(r, VFile);
         if(params.count()) {          if(params.count()) {
                 // decode                  // decode
                 const char* cstr=params.as_string(0, "parameter must be string").cstr();                  const char* cstr=params.as_string(0, PARAMETER_MUST_BE_STRING).cstr();
                 char* decoded_cstr=0;                  char* decoded_cstr=0;
                 size_t decoded_size=0;                  size_t decoded_size=0;
                 pa_base64_decode(cstr, strlen(cstr), decoded_cstr, decoded_size);                  pa_base64_decode(cstr, strlen(cstr), decoded_cstr, decoded_size);
Line 855  static void _base64(Request& r, MethodPa Line 924  static void _base64(Request& r, MethodPa
         }          }
         } else {          } else {
                 // encode                  // encode
                 const String& file_spec=params.as_string(0, "file name must be string");                  const String& file_spec=params.as_string(0, FILE_NAME_MUST_BE_STRING);
                 const char* encoded=pa_base64_encode(r.absolute(file_spec));                  const char* encoded=pa_base64_encode(r.absolute(file_spec));
                 r.write_assign_lang(*new String(encoded, 0, true/*once ?param=base64(something) was needed*/));                  r.write_assign_lang(*new String(encoded, 0, true/*once ?param=base64(something) was needed*/));
         }          }
Line 866  static void _crc32(Request& r, MethodPar Line 935  static void _crc32(Request& r, MethodPar
         if(&r.get_self() == file_class) {          if(&r.get_self() == file_class) {
                 // ^file:crc32[file-name]                  // ^file:crc32[file-name]
                 if(params.count()) {                  if(params.count()) {
                         const String& file_spec=params.as_string(0, "file name must be string");                          const String& file_spec=params.as_string(0, FILE_NAME_MUST_BE_STRING);
                         crc32=pa_crc32(r.absolute(file_spec));                          crc32=pa_crc32(r.absolute(file_spec));
                 } else {                  } else {
                         throw Exception("parser.runtime",                          throw Exception(PARSER_RUNTIME,
                                 0,                                  0,
                                 "file name must be defined");                                  "file name must be defined");
                 }                  }
Line 928  static void _md5(Request& r, MethodParam Line 997  static void _md5(Request& r, MethodParam
         if(&r.get_self() == file_class) {          if(&r.get_self() == file_class) {
                 // ^file:md5[file-name]                  // ^file:md5[file-name]
                 if(params.count()) {                  if(params.count()) {
                         const String& file_spec=params.as_string(0, "file name must be string");                          const String& file_spec=params.as_string(0, FILE_NAME_MUST_BE_STRING);
                         md5=pa_md5(r.absolute(file_spec));                          md5=pa_md5(r.absolute(file_spec));
                 } else {                  } else {
                         throw Exception("parser.runtime",                          throw Exception(PARSER_RUNTIME,
                                 0,                                  0,
                                 "file name must be defined");                                  "file name must be defined");
                 }                  }
Line 967  MFile::MFile(): Methoded("file") { Line 1036  MFile::MFile(): Methoded("file") {
         // ^file::stat[disk-name]          // ^file::stat[disk-name]
         add_native_method("stat", Method::CT_DYNAMIC, _stat, 1, 1);          add_native_method("stat", Method::CT_DYNAMIC, _stat, 1, 1);
   
         // ^file::cgi[file-name]          // ^file::cgi[mode;file-name]
         // ^file::cgi[file-name;env hash]          // ^file::cgi[mode;file-name;env hash]
         // ^file::cgi[file-name;env hash;1cmd;2line;3ar;4g;5s]          // ^file::cgi[mode;file-name;env hash;1cmd;2line;3ar;4g;5s]
         add_native_method("cgi", Method::CT_DYNAMIC, _cgi, 1, 2+50);          add_native_method("cgi", Method::CT_DYNAMIC, _cgi, 1, 3+50);
   
         // ^file::exec[file-name]          // ^file::exec[mode;file-name]
         // ^file::exec[file-name;env hash]          // ^file::exec[mode;file-name;env hash]
         // ^file::exec[file-name;env hash;1cmd;2line;3ar;4g;5s]          // ^file::exec[mode;file-name;env hash;1cmd;2line;3ar;4g;5s]
         add_native_method("exec", Method::CT_DYNAMIC, _exec, 1, 2+50);          add_native_method("exec", Method::CT_DYNAMIC, _exec, 1, 3+50);
   
         // ^file:list[path]          // ^file:list[path]
         // ^file:list[path][regexp]          // ^file:list[path][regexp]

Removed from v.1.151  
changed lines
  Added in v.1.166


E-mail: