--- parser3/src/classes/file.C 2008/02/14 09:10:23 1.166 +++ parser3/src/classes/file.C 2008/09/03 15:15:32 1.178 @@ -5,12 +5,10 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_FILE_C="$Date: 2008/02/14 09:10:23 $"; +static const char * const IDENT_FILE_C="$Date: 2008/09/03 15:15:32 $"; #include "pa_config_includes.h" -#include "pcre.h" - #include "classes.h" #include "pa_vmethod_frame.h" @@ -232,8 +230,7 @@ static void _load(Request& r, MethodPara :lfile_name.cstr(String::L_FILE_SPEC); Value* vcontent_type=0; - if(file.headers) - { + if(file.headers){ if(Value* remote_content_type=file.headers->get("CONTENT-TYPE")) vcontent_type=new VString(*new String(remote_content_type->as_string().cstr())); } @@ -242,8 +239,21 @@ static void _load(Request& r, MethodPara VFile& self=GET_SELF(r, VFile); self.set(true/*tainted*/, file.str, file.length, user_file_name, vcontent_type); - if(file.headers) + + if(file.headers){ file.headers->for_each(_load_pass_param, &self.fields()); + } else { + size_t size; + time_t atime, mtime, ctime; + + file_stat(lfile_name, size, atime, mtime, ctime); + + HashStringValue& ff=self.fields(); + ff.put(adate_name, new VDate(atime)); + ff.put(mdate_name, new VDate(mtime)); + ff.put(cdate_name, new VDate(ctime)); + } + } static void _create(Request& r, MethodParams& params) { @@ -276,13 +286,15 @@ static void _stat(Request& r, MethodPara size, atime, mtime, ctime); + const char* user_file_name=lfile_name.cstr(String::L_FILE_SPEC); + VFile& self=GET_SELF(r, VFile); - self.set(true/*tainted*/, 0/*no bytes*/, size); + + self.set(true/*tainted*/, 0/*no bytes*/, size, user_file_name, new VString(r.mime_type_of(user_file_name))); HashStringValue& ff=self.fields(); ff.put(adate_name, new VDate(atime)); ff.put(mdate_name, new VDate(mtime)); ff.put(cdate_name, new VDate(ctime)); - ff.put(content_type_name, new VString(r.mime_type_of(lfile_name.cstr(String::L_FILE_SPEC)))); } static bool is_safe_env_key(const char* key) { @@ -351,11 +363,6 @@ static void append_to_argv(Request& r, A } } -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 static void _exec_cgi(Request& r, MethodParams& params, bool cgi) { @@ -607,15 +614,19 @@ static void _list(Request& r, MethodPara if(params.count()>1) { regexp=¶ms.as_no_junction(1, "regexp must not be code").as_string(); - const char* pattern=regexp->cstr(); + const char* pattern=regexp->cstr(String::L_UNSPECIFIED); const char* errptr; int erroffset; - regexp_code=pcre_compile(pattern, PCRE_EXTRA | PCRE_DOTALL, + int options=PCRE_EXTRA | PCRE_DOTALL; + if(r.charsets.source().isUTF8()) + options=options|PCRE_UTF8; + + regexp_code=pcre_compile(pattern, options, &errptr, &erroffset, r.charsets.source().pcre_tables); if(!regexp_code) - throw Exception(0, + throw Exception(PCRE_EXCEPTION_TYPE, ®exp->mid(erroffset, regexp->length()), "regular expression syntax error - %s", errptr); } else { @@ -643,9 +654,9 @@ static void _list(Request& r, MethodPara suits=false; else if(exec_result<0) { (*pcre_free)(regexp_code); - throw Exception(0, - regexp, - "regular expression execute (%d)", + throw Exception(PCRE_EXCEPTION_TYPE, + regexp, + print_pcre_exec_error_text(exec_result), exec_result); } } @@ -863,9 +874,11 @@ static void _sql(Request& r, MethodParam statement_string.cstr(String::L_UNSPECIFIED, r.connection()); File_sql_event_handlers handlers(statement_string, statement_cstr); + ulong limit=SQL_NO_LIMIT; + ulong offset=0; + if(params.count()>1) - if(HashStringValue* options= - params.as_no_junction(1, PARAM_MUST_NOT_BE_CODE).get_hash()) { + if(HashStringValue* options=params.as_no_junction(1, PARAM_MUST_NOT_BE_CODE).get_hash()){ int valid_options=0; if(Value* vfilename=options->get(NAME_NAME)) { valid_options++; @@ -875,6 +888,14 @@ static void _sql(Request& r, MethodParam valid_options++; handlers.user_content_type=&vcontent_type->as_string(); } + if(Value* vlimit=options->get(sql_limit_name)) { + valid_options++; + limit=(ulong)r.process_to_value(*vlimit).as_double(); + } + if(Value* voffset=options->get(sql_offset_name)) { + valid_options++; + offset=(ulong)r.process_to_value(*voffset).as_double(); + } if(valid_options!=options->count()) throw Exception(PARSER_RUNTIME, 0, @@ -885,7 +906,7 @@ static void _sql(Request& r, MethodParam r.connection()->query( statement_cstr, 0, 0, - 0, 0, + offset, limit, handlers, statement_string);