--- parser3/src/classes/file.C 2004/08/17 10:00:33 1.129 +++ parser3/src/classes/file.C 2004/12/23 15:36:12 1.131 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_FILE_C="$Date: 2004/08/17 10:00:33 $"; +static const char * const IDENT_FILE_C="$Date: 2004/12/23 15:36:12 $"; #include "pa_config_includes.h" @@ -33,6 +33,8 @@ static const char * const IDENT_FILE_C=" #define STDIN_EXEC_PARAM_NAME "stdin" #define CHARSET_EXEC_PARAM_NAME "charset" +#define NAME_NAME "name" + // class class MFile: public Methoded { @@ -252,10 +254,10 @@ static void pass_cgi_header_attribute( ArrayString::element_type astring, Pass_cgi_header_attribute_info* info) { size_t colon_pos=astring->pos(':'); - if(colon_pos==STRING_NOT_FOUND) { + if(colon_pos!=STRING_NOT_FOUND) { const String& key=astring->mid(0, colon_pos).change_case( *info->charset, String::CC_UPPER); - Value* value=new VString(astring->mid(colon_pos+1, astring->length())); + Value* value=new VString(astring->mid(colon_pos+1, astring->length()).trim()); info->fields->put(key, value); if(key=="CONTENT-TYPE") info->content_type=value; @@ -644,8 +646,8 @@ class File_sql_event_handlers: public SQ int got_cells; public: String::C value; - String* user_file_name; - String* user_content_type; + const String* user_file_name; + const String* user_content_type; public: File_sql_event_handlers( const String& astatement_string, const char* astatement_cstr): @@ -671,10 +673,12 @@ public: value=String::C(str, length); break; case 1: - user_file_name=new String(str, length, true); + if(!user_file_name) // user not specified? + user_file_name=new String(str, length, true); break; case 2: - user_content_type=new String(str, length, true); + if(!user_content_type) // user not specified? + user_content_type=new String(str, length, true); break; default: error=SQL_Error("parser.runtime", "result must not contain more then one row, three rows"); @@ -689,17 +693,33 @@ public: }; #endif static void _sql(Request& r, MethodParams& params) { - const String* user_file_name=0; - if(params.get(0)->is_string()) - user_file_name=¶ms.get(0)->as_string(); - - Value& statement=params.as_junction(params.count()-1, "statement must be code"); + Value& statement=params.as_junction(0, "statement must be code"); Temp_lang temp_lang(r, String::L_SQL); const String& statement_string=r.process_to_string(statement); const char* statement_cstr= statement_string.cstr(String::L_UNSPECIFIED, r.connection()); File_sql_event_handlers handlers(statement_string, statement_cstr); + + if(params.count()>1) + 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++; + handlers.user_file_name=&vfilename->as_string(); + } + if(Value* vcontent_type=options->get(CONTENT_TYPE_NAME)) { + valid_options++; + handlers.user_content_type=&vcontent_type->as_string(); + } + if(valid_options!=options->count()) + throw Exception("parser.runtime", + 0, + "called with invalid option"); + } + + r.connection()->query( statement_cstr, 0, 0, @@ -712,10 +732,7 @@ static void _sql(Request& r, MethodParam 0, "produced no result"); - if(!user_file_name) - user_file_name=handlers.user_file_name; - - const char* user_file_name_cstr=user_file_name? user_file_name->cstr(): 0; + const char* user_file_name_cstr=handlers.user_file_name? handlers.user_file_name->cstr(): 0; VString* vcontent_type=handlers.user_content_type? new VString(*handlers.user_content_type)