--- parser3/src/classes/file.C 2002/10/21 08:22:17 1.102 +++ parser3/src/classes/file.C 2002/11/25 14:10:51 1.104 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_FILE_C="$Date: 2002/10/21 08:22:17 $"; +static const char* IDENT_FILE_C="$Date: 2002/11/25 14:10:51 $"; #include "pa_config_includes.h" @@ -120,17 +120,32 @@ static void _load(Request& r, const Stri Pool& pool=r.pool(); 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()); + Value *third_param=params->size()>2?¶ms->as_no_junction(2, "filename or options must not be code"):0; + Hash *third_param_hash=third_param?third_param->get_hash(&method_name):0; + int alt_filename_param_index=2; + if(third_param_hash) + alt_filename_param_index++; void *data; size_t size; + Hash *fields=0; file_read(pool, lfile_name, data, size, - vmode_name.as_string()==TEXT_MODE_NAME); + vmode_name.as_string()==TEXT_MODE_NAME, + third_param_hash, + &fields + ); - char *user_file_name=params->size()>2? - params->as_string(2, "filename must be string").cstr(String::UL_FILE_SPEC) + char *user_file_name=params->size()>alt_filename_param_index? + params->as_string(alt_filename_param_index, "filename must be string").cstr(String::UL_FILE_SPEC) :lfile_name.cstr(String::UL_FILE_SPEC); + + Value *vcontent_type=0; + if(fields) + vcontent_type=static_cast(fields->get(*content_type_name)); + if(!vcontent_type) + vcontent_type=new(pool) VString(r.mime_type_of(user_file_name)); - static_cast(r.get_self())->set(true/*tainted*/, data, size, - user_file_name, new(pool) VString(r.mime_type_of(user_file_name))); + VFile& self=*static_cast(r.get_self()); + self.set(true/*tainted*/, data, size, user_file_name, vcontent_type); } static void _stat(Request& r, const String& method_name, MethodParams *params) { @@ -248,6 +263,7 @@ static void _exec_cgi(Request& r, const env.put(*new(pool) String(pool, "SCRIPT_NAME"), &script_name); //env.put(*new(pool) String(pool, "SCRIPT_FILENAME"), ??&script_name); + bool stdin_specified=false; // environment & stdin from param String in(pool); if(params->size()>1) { @@ -255,10 +271,11 @@ static void _exec_cgi(Request& r, const if(Hash *user_env=venv.get_hash(&method_name)) { Append_env_pair_info info={&env}; user_env->for_each(append_env_pair, &info); - if(info.vstdin) - if(info.vstdin->is_string()) - in.append(*info.vstdin->get_string(), String::UL_CLEAN, true); - else + if(info.vstdin) { + stdin_specified=true; + if(const String *sstdin=info.vstdin->get_string()) { + in.append(*sstdin, String::UL_CLEAN, true); + } else if(VFile *vfile=static_cast(info.vstdin->as("file", false))) in.APPEND_TAINTED((const char *)vfile->value_ptr(), vfile->value_size(), "$.stdin[assigned]", 0); @@ -266,6 +283,7 @@ static void _exec_cgi(Request& r, const throw Exception("parser.runtime", &method_name, STDIN_EXEC_PARAM_NAME " parameter must be string or file"); + } } } @@ -278,7 +296,7 @@ static void _exec_cgi(Request& r, const } // passing POST data - if(in.is_empty()) // if $.stdin[...] not specified + if(!stdin_specified) // if $.stdin[...] not specified in.APPEND(r.post_data, r.post_size, String::UL_CLEAN, "POST data (passed)", 0); // exec! @@ -347,7 +365,7 @@ static void _exec_cgi(Request& r, const // $status self.fields().put( - *new(pool) String(pool, "status"), + *file_status_name, new(pool) VInt(pool, status)); // $stderr