--- parser3/src/classes/file.C 2007/11/14 12:46:02 1.162 +++ parser3/src/classes/file.C 2008/02/14 09:10:23 1.166 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_FILE_C="$Date: 2007/11/14 12:46:02 $"; +static const char * const IDENT_FILE_C="$Date: 2008/02/14 09:10:23 $"; #include "pa_config_includes.h" @@ -353,7 +353,7 @@ 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)?(size_t)-1:p-s1; + return (p==0)?STRING_NOT_FOUND:p-s1; } /// @todo fix `` in perl - they produced flipping consoles and no output to perl @@ -488,65 +488,71 @@ static void _exec_cgi(Request& r, Method // match silent conversion in OS // exec! - PA_exec_result execution= - pa_exec(false/*forced_allow*/, script_name, &env, argv, *in); + PA_exec_result execution=pa_exec(false/*forced_allow*/, script_name, &env, argv, *in); File_read_result *file_out=&execution.out; String *real_err=&execution.err; - if(is_text_mode(mode_name)){ + // transcode err if necessary (@todo: need fix line breaks in err as well ) + if(charset) + real_err=&Charset::transcode(*real_err, *charset, r.charsets.source()); + + if(file_out->length && is_text_mode(mode_name)){ fix_line_breaks(file_out->str, file_out->length); // treat output as string String *real_out = new String(file_out->str, file_out->length); - // transcode if necessary - if(charset) { + // transcode out if necessary + if(charset) real_out=&Charset::transcode(*real_out, *charset, r.charsets.source()); - real_err=&Charset::transcode(*real_err, *charset, r.charsets.source()); - } + // FIXME: unsafe cast - file_out->str = (char*)real_out->cstr(); + file_out->str=const_cast(real_out->cstr()); // hacking a little file_out->length = real_out->length(); } VFile& self=GET_SELF(r, VFile); if(cgi) { // ^file::cgi - const char* eol_marker=0; size_t eol_marker_size; + const char* eol_marker=0; + size_t eol_marker_size; + // construct with 'out' body and header - size_t dos_pos=strpos(file_out->str, "\r\n\r\n"); - size_t unix_pos=strpos(file_out->str, "\n\n"); + size_t dos_pos=(file_out->length)?strpos(file_out->str, "\r\n\r\n"):STRING_NOT_FOUND; + size_t unix_pos=(file_out->length)?strpos(file_out->str, "\n\n"):STRING_NOT_FOUND; bool unix_header_break; switch((dos_pos!=STRING_NOT_FOUND?10:00) + (unix_pos!=STRING_NOT_FOUND?01:00)) { - case 10: // dos - unix_header_break=false; - break; - case 01: // unix - unix_header_break=true; - break; - case 11: // dos & unix - unix_header_break=unix_poslength, file_out->str, - (uint)real_err->length(), real_err->cstr()); - break; //never reached + case 10: // dos + unix_header_break=false; + break; + case 01: // unix + unix_header_break=true; + break; + case 11: // dos & unix + unix_header_break=unix_poslength, (file_out->length) ? (file_out->str) : "", + (size_t)real_err->length(), real_err->cstr()); + break; //never reached } - int header_break_pos; + size_t header_break_pos; if(unix_header_break) { header_break_pos=unix_pos; - eol_marker="\n"; eol_marker_size=1; + eol_marker="\n"; + eol_marker_size=1; } else { header_break_pos=dos_pos; - eol_marker="\r\n"; eol_marker_size=2; + eol_marker="\r\n"; + eol_marker_size=2; } file_out->str[header_break_pos] = 0; @@ -555,7 +561,7 @@ static void _exec_cgi(Request& r, Method file_out->str += headersize; file_out->length -= headersize; - // body + // $body self.set(false/*not tainted*/, file_out->str, file_out->length); // $fields << header @@ -570,7 +576,8 @@ static void _exec_cgi(Request& r, Method if(info.content_type) self.fields().put(content_type_name, info.content_type); } - } else { + } else { // ^file::exec + // $body self.set(false/*not tainted*/, file_out->str, file_out->length); }