Diff for /parser3/src/classes/file.C between versions 1.292 and 1.298

version 1.292, 2024/12/11 00:37:04 version 1.298, 2025/10/05 19:41:27
Line 35  volatile const char * IDENT_FILE_C="$Id$ Line 35  volatile const char * IDENT_FILE_C="$Id$
 #define CHARSET_EXEC_PARAM_NAME "charset"  #define CHARSET_EXEC_PARAM_NAME "charset"
   
 #define NAME_NAME "name"  #define NAME_NAME "name"
   #define MODE_APPEND "append"
 #define KEEP_EMPTY_DIRS_NAME "keep-empty-dirs"  #define KEEP_EMPTY_DIRS_NAME "keep-empty-dirs"
 #define SUPPRESS_EXCEPTION_NAME "exception"  #define SUPPRESS_EXCEPTION_NAME "exception"
   
Line 133  static const String::Body cdate_name("cd Line 134  static const String::Body cdate_name("cd
 // methods  // methods
   
 static void _save(Request& r, MethodParams& params) {  static void _save(Request& r, MethodParams& params) {
         bool is_text=VFile::is_text_mode(params.as_string(0, MODE_MUST_NOT_BE_CODE));          bool do_append=false;
           bool is_text=VFile::is_text_mode(params.as_string(0, MODE_MUST_BE_STRING));
         const String& file_name=params.as_file_name(1);          const String& file_name=params.as_file_name(1);
   
         Charset* asked_charset=0;          Charset* asked_charset=0;
Line 144  static void _save(Request& r, MethodPara Line 146  static void _save(Request& r, MethodPara
                                 asked_charset=&pa_charsets.get(vcharset_name->as_string());                                  asked_charset=&pa_charsets.get(vcharset_name->as_string());
                                 valid_options++;                                  valid_options++;
                         }                          }
                           if(Value* vappend=options->get(MODE_APPEND)){
                                   do_append=vappend->as_bool();
                                   valid_options++;
                           }
                         if(valid_options != options->count())                          if(valid_options != options->count())
                                 throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION);                                  throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION);
                 }                  }
   
         // save          // save
         GET_SELF(r, VFile).save(r.charsets, r.full_disk_path(file_name), is_text, asked_charset);          GET_SELF(r, VFile).save(r.charsets, r.full_disk_path(file_name), is_text, do_append, asked_charset);
 }  }
   
 static void _delete(Request& r, MethodParams& params) {  static void _delete(Request& r, MethodParams& params) {
Line 208  static void copy_process_source(struct s Line 214  static void copy_process_source(struct s
                 nCount = file_block_read(from_file, buffer, sizeof(buffer));                  nCount = file_block_read(from_file, buffer, sizeof(buffer));
                 int written=write(to_file, buffer, nCount);                   int written=write(to_file, buffer, nCount); 
                 if( written < 0 )                  if( written < 0 )
                         throw Exception("file.access",                           throw Exception("file.write", 0, "write failed: %s (%d)", strerror(errno), errno);
                                 0,   
                                 "write failed: %s (%d)",  strerror(errno), errno);   
                                   
         } while(nCount > 0);          } while(nCount > 0);
 }  }
Line 228  static void _copy(Request& r, MethodPara Line 232  static void _copy(Request& r, MethodPara
         if(params.count()>2)          if(params.count()>2)
                 if(HashStringValue* options=params.as_hash(2)){                  if(HashStringValue* options=params.as_hash(2)){
                         int valid_options=0;                          int valid_options=0;
                         if(Value* vappend=options->get("append")){                          if(Value* vappend=options->get(MODE_APPEND)){
                                 append=r.process(*vappend).as_bool();                                  append=r.process(*vappend).as_bool();
                                 valid_options++;                                  valid_options++;
                         }                          }
Line 256  static void _load_pass_param( Line 260  static void _load_pass_param(
 }  }
   
 static void _load(Request& r, MethodParams& params) {  static void _load(Request& r, MethodParams& params) {
         bool as_text=VFile::is_text_mode(params.as_string(0, MODE_MUST_NOT_BE_CODE));          bool as_text=VFile::is_text_mode(params.as_string(0, MODE_MUST_BE_STRING));
         const String& lfile_name=r.full_disk_path(params.as_file_name(1));          const String& lfile_name=r.full_disk_path(params.as_file_name(1));
   
         size_t param_index=params.count()-1;          size_t param_index=params.count()-1;
Line 316  static void _create(Request& r, MethodPa Line 320  static void _create(Request& r, MethodPa
   
         if(params.count()>=3){          if(params.count()>=3){
                 // old format: ^file::create[text|binary;file-name;string-or-file-content[;options]]                   // old format: ^file::create[text|binary;file-name;string-or-file-content[;options]] 
                 mode=&params.as_string(0, MODE_MUST_NOT_BE_CODE);                  mode=&params.as_string(0, MODE_MUST_BE_STRING);
                 is_text=VFile::is_text_mode(*mode);                  is_text=VFile::is_text_mode(*mode);
                 file_name=&params.as_string(1, FILE_NAME_MUST_BE_STRING);                  file_name=&params.as_string(1, FILE_NAME_MUST_BE_STRING);
                 content_index=2;                  content_index=2;
Line 478  static void append_to_argv(Request& r, A Line 482  static void append_to_argv(Request& r, A
 static void _exec_cgi(Request& r, MethodParams& params, bool cgi) {  static void _exec_cgi(Request& r, MethodParams& params, bool cgi) {
         bool is_text=true;          bool is_text=true;
         size_t param_index=0;          size_t param_index=0;
         const String& mode=params.as_string(0, FIRST_ARG_MUST_NOT_BE_CODE);          const String& mode=params.as_string(0, "mode must be string");
         if(VFile::is_valid_mode(mode)) {          if(VFile::is_valid_mode(mode)) {
                 is_text=VFile::is_text_mode(mode);                  is_text=VFile::is_text_mode(mode);
                 param_index++;                  param_index++;
Line 490  static void _exec_cgi(Request& r, Method Line 494  static void _exec_cgi(Request& r, Method
         const String& script_name=r.full_disk_path(params.as_file_name(param_index++));          const String& script_name=r.full_disk_path(params.as_file_name(param_index++));
   
         HashStringString env;          HashStringString env;
         #define ECSTR(name, value_cstr) if(value_cstr) env.put(#name, value_cstr);          #define ECSTR(name, value_cstr) if(value_cstr) env.put(#name, String::Body(value_cstr));
         // passing environment          // passing environment
         for(SAPI::Env::Iterator i(r.sapi_info); i; i.next() )          for(SAPI::Env::Iterator i(r.sapi_info); i; i.next() )
                 env.put(i.key(), i.value() );                  env.put(i.key(), String::Body(i.value()) );
   
         // const          // const
         ECSTR(GATEWAY_INTERFACE, "CGI/1.1");          ECSTR(GATEWAY_INTERFACE, "CGI/1.1");
Line 1066  extern Base64Options base64_encode_optio Line 1070  extern Base64Options base64_encode_optio
 Base64Options base64_decode_options(Request& r, HashStringValue* options, VString** vcontent_type) {  Base64Options base64_decode_options(Request& r, HashStringValue* options, VString** vcontent_type) {
         Base64Options result;          Base64Options result;
         if(options) {          if(options) {
                 int valid_options=0;  
                 for(HashStringValue::Iterator i(*options); i; i.next() ) {                  for(HashStringValue::Iterator i(*options); i; i.next() ) {
                         String::Body key=i.key();                          String::Body key=i.key();
                         Value* value=i.value();                          Value* value=i.value();
                         if(key == "pad") {                          if(key == "pad") {
                                 result.pad=r.process(*value).as_bool();                                  result.pad=r.process(*value).as_bool();
                                 valid_options++;  
                         } else if(key == "strict") {                          } else if(key == "strict") {
                                 result.strict=r.process(*value).as_bool();                                  result.strict=r.process(*value).as_bool();
                                 valid_options++;  
                         } else if(key == CONTENT_TYPE_NAME) {                          } else if(key == CONTENT_TYPE_NAME) {
                                 *vcontent_type=new VString(value->as_string());                                  *vcontent_type=new VString(value->as_string());
                                 valid_options++;  
                         } else if(key == "url-safe") {                          } else if(key == "url-safe") {
                                 if(r.process(*value).as_bool())                                  if(r.process(*value).as_bool())
                                         result.set_url_safe_abc();                                          result.set_url_safe_abc();
                                 valid_options++;                          } else
                         }                                  throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION);
                 }                  }
   
                 if(valid_options != options->count())  
                         throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION);  
         }          }
         return result;          return result;
 }  }
Line 1111  static void _base64(Request& r, MethodPa Line 1108  static void _base64(Request& r, MethodPa
                                 if(params.count() < 3)                                  if(params.count() < 3)
                                         throw Exception(PARSER_RUNTIME, 0, "constructor cannot have less than 3 parameters (has %d parameters)", params.count()); // actually it accepts 1 parameter (backward)                                          throw Exception(PARSER_RUNTIME, 0, "constructor cannot have less than 3 parameters (has %d parameters)", params.count()); // actually it accepts 1 parameter (backward)
   
                                 is_text=VFile::is_text_mode(params.as_string(0, MODE_MUST_NOT_BE_CODE));                                  is_text=VFile::is_text_mode(params.as_string(0, MODE_MUST_BE_STRING));
                                 user_file_name=&params.as_string(1, FILE_NAME_MUST_BE_STRING);                                  user_file_name=&params.as_string(1, FILE_NAME_MUST_BE_STRING);
   
                                 if(params.count() == 4)                                  if(params.count() == 4)
Line 1229  MFile::MFile(): Methoded("file") { Line 1226  MFile::MFile(): Methoded("file") {
         add_native_method("create", Method::CT_DYNAMIC, _create, 1, 4);          add_native_method("create", Method::CT_DYNAMIC, _create, 1, 4);
   
         // ^file.save[mode;file-name]          // ^file.save[mode;file-name]
         // ^file.save[mode;file-name;$.charset[...]]          // ^file.save[mode;file-name;$.charset[...]$.append(false)]
         add_native_method("save", Method::CT_DYNAMIC, _save, 2, 3);          add_native_method("save", Method::CT_DYNAMIC, _save, 2, 3);
   
         // ^file:delete[file-name]          // ^file:delete[file-name]

Removed from v.1.292  
changed lines
  Added in v.1.298


E-mail: