--- parser3/src/main/pa_common.C 2003/11/20 15:35:31 1.166 +++ parser3/src/main/pa_common.C 2003/12/17 10:12:34 1.170 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_COMMON_C="$Date: 2003/11/20 15:35:31 $"; +static const char * const IDENT_COMMON_C="$Date: 2003/12/17 10:12:34 $"; #include "pa_common.h" #include "pa_exception.h" @@ -330,7 +330,8 @@ struct File_read_http_result { /// @todo build .cookies field. use ^file.tables.SET-COOKIES.menu{ for now static File_read_http_result file_read_http(Request_charsets& charsets, const String& file_spec, - HashStringValue *options=0) { + bool as_text, + HashStringValue *options=0) { File_read_http_result result; char host[MAX_STRING]; const char* uri; @@ -351,7 +352,7 @@ static File_read_http_result file_read_h valid_options++; timeout=vtimeout->as_int(); } - if(vheaders=options->get(http_headers_name)) { + if((vheaders=options->get(http_headers_name))) { valid_options++; } if(Value* vany_status=options->get(http_any_status_name)) { @@ -410,7 +411,7 @@ static File_read_http_result file_read_h bool user_agent_specified=false; if(vheaders && !vheaders->is_string()) { // allow empty if(HashStringValue *headers=vheaders->get_hash()) { - Http_pass_header_info info={&charsets, &request}; + Http_pass_header_info info={&charsets, &request, false}; headers->for_each(http_pass_header, &info); user_agent_specified=info.user_agent_specified; } else @@ -501,12 +502,10 @@ static File_read_http_result file_read_h if(!real_remote_charset) real_remote_charset=asked_remote_charset; - // todo: do that only if ^file::load[text // output response - String::C real_body=Charset::transcode( - String::C(raw_body.cstrm()/*must be modifiable*/, raw_body.length()), - *real_remote_charset, - charsets.source()); + String::C real_body=String::C(raw_body.cstrm()/*must be modifiable*/, raw_body.length()); + if(as_text && raw_body.length()) // must be checked because transcode returns CONST string in case length==0, which contradicts hacking few lines below + real_body=Charset::transcode(real_body, *real_remote_charset, charsets.source()); result.str=const_cast(real_body.str); // hacking a little result.length=real_body.length; @@ -549,11 +548,11 @@ static void file_read_action( File_read_result file_read(Request_charsets& charsets, const String& file_spec, bool as_text, HashStringValue *params, bool fail_on_read_problem) { - File_read_result result={false}; + File_read_result result={false, 0, 0, 0}; #ifdef PA_HTTP if(file_spec.starts_with("http://")) { // fail on read problem - File_read_http_result http=file_read_http(charsets, file_spec, params); + File_read_http_result http=file_read_http(charsets, file_spec, as_text, params); result.success=true; result.str=http.str; result.length=http.length; @@ -583,8 +582,6 @@ File_read_result file_read(Request_chars } fix_line_breaks((char *)(result.str), result.length); - // note: after fixing - ((char*&)(result.str))[result.length]=0; } return result; @@ -1078,7 +1075,7 @@ int __vsnprintf(char* b, size_t s, const if(r<0) r=0; - else if(r>s) + else if((size_t)r>s) r=s; #endif b[r]=0;