--- parser3/src/main/pa_http.C 2009/07/03 01:28:47 1.28 +++ parser3/src/main/pa_http.C 2009/08/21 08:38:55 1.34 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_HTTP_C="$Date: 2009/07/03 01:28:47 $"; +static const char * const IDENT_HTTP_C="$Date: 2009/08/21 08:38:55 $"; #include "pa_http.h" #include "pa_common.h" @@ -339,7 +339,7 @@ static void http_pass_cookie(HashStringV Http_pass_header_info *info) { *info->request << String(name, String::L_HTTP_COOKIE) << "=" - << attributed_meaning_to_string(*value, String::L_HTTP_COOKIE, false) + << attributed_meaning_to_string(*value, String::L_HTTP_COOKIE, true) << "; "; } @@ -365,9 +365,7 @@ static void form_string_value2string( const String& value, String& result) { - result << String(key, String::L_URI) << "="; - result.append(value, String::L_URI, true); - result << "&"; + result << String(key, String::L_URI) << "=" << String(value, String::L_URI) << "&"; } #ifndef DOXYGEN @@ -401,7 +399,7 @@ static void form_value2string( const char* pa_form2string(HashStringValue& form, Request_charsets& charsets) { String string; form.for_each(form_value2string, &string); - return string.cstr(String::L_UNSPECIFIED, 0, &charsets); + return string.transcode_and_untaint_cstr(String::L_URI, &charsets); } struct FormPart { @@ -458,7 +456,7 @@ static void form_value2part( Form_table_value2string_info info(key, part.string); part.info = &info; tvalue->for_each(form_table_value2part, &part); - } else if(VFile* vfile=static_cast(value->as("file", false))){ + } else if(VFile* vfile=static_cast(value->as("file"))){ form_file_value2part(key, *vfile, part); } else throw Exception(PARSER_RUNTIME, @@ -474,7 +472,7 @@ const char* pa_form2string_multipart(Has form.for_each(form_value2part, formpart); formpart.string << "--" << boundary << "--"; post_size=formpart.string.length(); // very surprizing, but it calculates correct post_size even with binary files! - return formpart.string.cstr(String::L_UNSPECIFIED); // without transcoding + return formpart.string.untaint_cstr(String::L_AS_IS); // without transcoding } static void find_headers_end(char* p, @@ -607,16 +605,14 @@ File_read_http_result pa_internal_file_r } //preparing request - String& connect_string=*new String; - // not in ^sql{... L_SQL ...} spirit, but closer to ^file::load one - connect_string.append(file_spec, String::L_URI); // tainted pieces -> URI pieces + String& connect_string=*new String(file_spec); String request_head_and_body; { // influence URLencoding of tainted pieces to String::L_URI lang Temp_client_charset temp(r.charsets, *asked_remote_charset); - const char* connect_string_cstr=connect_string.cstr(String::L_UNSPECIFIED, 0, &(r.charsets)); + const char* connect_string_cstr=connect_string.transcode_and_untaint_cstr(String::L_URI, &(r.charsets)); const char* current=connect_string_cstr; if(strncmp(current, "http://", 7)!=0) @@ -626,9 +622,9 @@ File_read_http_result pa_internal_file_r current+=7; strncpy(host, current, sizeof(host)-1); host[sizeof(host)-1]=0; - char* host_uri=lsplit(host, '/'); - uri=host_uri?current+(host_uri-1-host):"/"; - char* port_cstr=lsplit(host, ':'); + char* host_uri=lsplit(host, '/'); + uri=host_uri?current+(host_uri-1-host):"/"; + char* port_cstr=lsplit(host, ':'); char* error_pos=0; port=port_cstr?(short)strtol(port_cstr, &error_pos, 0):80; @@ -671,7 +667,7 @@ File_read_http_result pa_internal_file_r head << CRLF; } else if (vbody) { // transcode tainted pieces and then URI-encode them - body_cstr=vbody->as_string().cstr(String::L_UNSPECIFIED, 0, &(r.charsets)); + body_cstr=vbody->as_string().untaint_cstr(String::L_AS_IS, 0, &(r.charsets)); // now transcode is needed only if own content-type was specified _and_ clean chars with code>127 are in the body // @todo: I don't like the current behaviour @@ -724,7 +720,7 @@ File_read_http_result pa_internal_file_r head << "content-length: " << format(post_size, "%u") << CRLF; // head + end of header - request_head_and_body << head.cstr(String::L_UNSPECIFIED, 0, &(r.charsets)) << CRLF; + request_head_and_body << head.untaint_cstr(String::L_AS_IS, 0, &(r.charsets)) << CRLF; // body if(body_cstr) @@ -780,7 +776,7 @@ File_read_http_result pa_internal_file_r const String::Body HEADER_NAME=line.mid(0, pos).change_case(r.charsets.source(), String::CC_UPPER); const String& HEADER_VALUE=line.mid(pos+1, line.length()).trim(String::TRIM_BOTH, " \t\r"); if(as_text && HEADER_NAME==HTTP_CONTENT_TYPE_UPPER) - real_remote_charset=detect_charset(HEADER_VALUE.cstr(), true/*already uppercased*/); + real_remote_charset=detect_charset(HEADER_VALUE.cstr()); // tables {