--- parser3/src/classes/file.C 2002/09/18 09:44:51 1.100 +++ parser3/src/classes/file.C 2002/11/20 10:01:01 1.103 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_FILE_C="$Date: 2002/09/18 09:44:51 $"; +static const char* IDENT_FILE_C="$Date: 2002/11/20 10:01:01 $"; #include "pa_config_includes.h" @@ -248,6 +248,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 +256,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 +268,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 +281,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! @@ -421,7 +424,7 @@ static void _list(Request& r, const Stri char *file_name_cstr=(char *)pool.malloc(file_name_size); memcpy(file_name_cstr, ffblk.ff_name, file_name_size); String &file_name=*new(pool) String(pool); - file_name.APPEND(file_name_cstr, file_name_size, String::UL_FILE_SPEC, + file_name.APPEND_TAINTED(file_name_cstr, file_name_size, method_name.origin().file, method_name.origin().line); Array& row=*new(pool) Array(pool); @@ -545,6 +548,22 @@ static void _justext(Request& r, const S r.write_assign_lang(file_spec.mid(afterdot, file_spec.size())); } +static void _fullpath(Request& r, const String& method_name, MethodParams *params) { + const String& file_spec=params->as_string(0, "file name must be string"); + const String *result; + if(file_spec.first_char()=='/') + result=&file_spec; + else { + // /some/page.html: ^file:fullpath[a.gif] => /some/a.gif + const String& full_disk_path=r.absolute(file_spec); + size_t document_root_length=strlen(r.info.document_root); + if(document_root_length>0) + --document_root_length; + result=&full_disk_path.mid(document_root_length, full_disk_path.size()); + } + r.write_assign_lang(*result); +} + // constructor @@ -595,6 +614,8 @@ MFile::MFile(Pool& apool) : Methoded(apo add_native_method("justname", Method::CT_STATIC, _justname, 1, 1); // ^file:justext[/a/some.tar.gz]=gz add_native_method("justext", Method::CT_STATIC, _justext, 1, 1); + // /some/page.html: ^file:fullpath[a.gif] => /some/a.gif + add_native_method("fullpath", Method::CT_STATIC, _fullpath, 1, 1); } // global variable