--- parser3/src/main/pa_common.C 2004/12/10 08:37:53 1.201 +++ parser3/src/main/pa_common.C 2005/11/16 14:49:41 1.206 @@ -1,11 +1,11 @@ /** @file Parser: commonly functions. - Copyright(c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com) + Copyright(c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_COMMON_C="$Date: 2004/12/10 08:37:53 $"; +static const char * const IDENT_COMMON_C="$Date: 2005/11/16 14:49:41 $"; #include "pa_common.h" #include "pa_exception.h" @@ -131,6 +131,21 @@ char* file_read_text(Request_charsets& c return file.success?file.str:0; } +/// these options were handled but not checked elsewhere, now check them +static int get_valid_file_options_count(HashStringValue& options) +{ + int result=0; + if(options.get(PA_SQL_LIMIT_NAME)) + result++; + if(options.get(PA_SQL_OFFSET_NAME)) + result++; + if(options.get(PA_COLUMN_SEPARATOR_NAME)) + result++; + if(options.get(PA_COLUMN_ENCLOSER_NAME)) + result++; + return result; +} + //http request stuff #ifdef PA_HTTP @@ -165,7 +180,9 @@ static int http_read_response(char*& res while(true) { char buf[MAX_STRING*10]; ssize_t received_size=recv(sock, buf, sizeof(buf), 0); - if(received_size<=0) { + if(received_size==0) + break; + if(received_size<0) { if(int no=pa_socks_errno()) throw Exception("http.timeout", 0, @@ -456,7 +473,8 @@ static File_read_http_result file_read_h const char* password_cstr=0; if(options) { - int valid_options=0; + int valid_options=get_valid_file_options_count(*options); + if(Value* vmethod=options->get(HTTP_METHOD_NAME)) { valid_options++; method=vmethod->as_string().cstr(); @@ -733,6 +751,11 @@ File_read_result file_read(Request_chars File_read_result result={false, 0, 0, 0}; #ifdef PA_HTTP if(file_spec.starts_with("http://")) { + if(offset || count) + throw Exception("parser.runtime", + 0, + "offset and load options are not supported for HTTP:// file load"); + // fail on read problem File_read_http_result http=file_read_http(charsets, file_spec, as_text, params); result.success=true; @@ -741,10 +764,13 @@ File_read_result file_read(Request_chars result.headers=http.headers; } else { #endif - if(params && params->count()) - throw Exception("parser.runtime", - 0, - "invalid option passed"); + if(params) { + int valid_options=get_valid_file_options_count(*params); + if(valid_options!=params->count()) + throw Exception("parser.runtime", + 0, + "invalid option passed"); + } File_read_action_info info={&result.str, &result.length, buf, offset, count}; @@ -842,7 +868,7 @@ bool file_read_action_under_lock(const S } } -static void create_dir_for_file(const String& file_spec) { +void create_dir_for_file(const String& file_spec) { size_t pos_after=1; size_t pos_before; while((pos_before=file_spec.pos('/', pos_after))!=STRING_NOT_FOUND) {