--- parser3/src/main/pa_http.C 2005/11/28 11:32:47 1.2 +++ parser3/src/main/pa_http.C 2007/04/23 10:30:32 1.7 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_HTTP_C="$Date: 2005/11/28 11:32:47 $"; +static const char * const IDENT_HTTP_C="$Date: 2007/04/23 10:30:32 $"; #include "pa_http.h" #include "pa_common.h" @@ -20,7 +20,7 @@ static const char * const IDENT_HTTP_C=" #define HTTP_TIMEOUT_NAME "timeout" #define HTTP_HEADERS_NAME "headers" #define HTTP_ANY_STATUS_NAME "any-status" -#define HTTP_CHARSET_NAME "charset" +// #define HTTP_CHARSET_NAME "charset" #define HTTP_TABLES_NAME "tables" #define HTTP_USER "user" #define HTTP_PASSWORD "password" @@ -305,7 +305,7 @@ static Charset* detect_charset(Charset& // content-type: xxx/xxx; source_charset="WE-NEED-THIS"; size_t before_charseteq_pos=CONTENT_TYPE_VALUE.pos("CHARSET="); if(before_charseteq_pos!=STRING_NOT_FOUND) { - size_t charset_begin=before_charseteq_pos+8/*CHARSET="*/; + size_t charset_begin=before_charseteq_pos+8/*CHARSET=*/; size_t open_quote_pos=CONTENT_TYPE_VALUE.pos('"', charset_begin); bool quoted=open_quote_pos==charset_begin; if(quoted) @@ -321,7 +321,7 @@ static Charset* detect_charset(Charset& charset_end=delim_pos; } const String::Body CHARSET_NAME_BODY= - CONTENT_TYPE_VALUE.mid(charset_begin, charset_end); + CONTENT_TYPE_VALUE.mid(charset_begin, charset_end - charset_begin); return &charsets.get(CHARSET_NAME_BODY); } @@ -380,10 +380,10 @@ static void form_value2string( new String(key, String::L_TAINTED), "is %s, "HTTP_FORM_NAME" option value must either string or table", value->type()); } -const char* pa_form2string(HashStringValue& form) { +const char* pa_form2string(HashStringValue& form, Request_charsets& charsets) { String string; - form.for_each(form_value2string, &string); - return string.cstr(String::L_UNSPECIFIED); + form.for_each(form_value2string, &string); + return string.cstr(String::L_UNSPECIFIED, 0, &charsets); } static void find_headers_end(char* p, char*& headers_end_at, @@ -449,8 +449,8 @@ File_read_http_result pa_internal_file_r valid_options++; fail_on_status_ne_200=!vany_status->as_bool(); } - if(Value* vcharset_name=options->get(HTTP_CHARSET_NAME)) { - valid_options++; + if(Value* vcharset_name=options->get(PA_CHARSET_NAME)) { +// valid_options++; asked_remote_charset=&::charsets.get(vcharset_name->as_string(). change_case(charsets.source(), String::CC_UPPER)); } @@ -464,7 +464,7 @@ File_read_http_result pa_internal_file_r } if(valid_options!=options->count()) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "invalid option passed"); } @@ -473,7 +473,7 @@ File_read_http_result pa_internal_file_r method_is_get=strcmp(method, "GET")==0; if(method_is_get && body_cstr) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "you can not use $."HTTP_BODY_NAME" option with method GET"); @@ -487,7 +487,7 @@ File_read_http_result pa_internal_file_r // influence URLencoding of tainted pieces to String::L_URI lang Temp_client_charset temp(charsets, *asked_remote_charset); - const char* connect_string_cstr=connect_string.cstr(String::L_UNSPECIFIED); + const char* connect_string_cstr=connect_string.cstr(String::L_UNSPECIFIED, 0, &charsets); const char* current=connect_string_cstr; if(strncmp(current, "http://", 7)!=0) @@ -511,12 +511,12 @@ File_read_http_result pa_internal_file_r head << " " << uri; if(form) if(method_is_get) - head << (uri_has_query_string?"&":"?") << pa_form2string(*form); + head << (uri_has_query_string?"&":"?") << pa_form2string(*form, charsets); head <<" HTTP/1.0" CRLF "host: "<< host << CRLF; if(form && !method_is_get) { head << "content-type: application/x-www-form-urlencoded" CRLF; - body_cstr = pa_form2string(*form); + body_cstr = pa_form2string(*form, charsets); } // http://www.ietf.org/rfc/rfc2617.txt @@ -527,10 +527,10 @@ File_read_http_result pa_internal_file_r if(vheaders && !vheaders->is_string()) { // allow empty if(HashStringValue *headers=vheaders->get_hash()) { Http_pass_header_info info={&charsets, &head, false}; - headers->for_each(http_pass_header, &info); + headers->for_each(http_pass_header, &info); user_agent_specified=info.user_agent_specified; } else - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, &connect_string, "headers param must be hash"); }; @@ -540,23 +540,25 @@ File_read_http_result pa_internal_file_r if(body_cstr) { // recode those pieces which are not in String::L_URI lang // [those violating HTTP standard, but widly used] +/* body_cstr=Charset::transcode( String::C(body_cstr, strlen(body_cstr)), charsets.source(), *asked_remote_charset); - +*/ head << "content-length: " << format(strlen(body_cstr), "%u") << CRLF; } - const char* head_cstr=head.cstr(String::L_UNSPECIFIED); + const char* head_cstr=head.cstr(String::L_UNSPECIFIED, 0, &charsets); // recode those pieces which are not in String::L_URI lang // [those violating HTTP standard, but widly used] +/* head_cstr=Charset::transcode( String::C(head_cstr, strlen(head_cstr)), charsets.source(), *asked_remote_charset); - +*/ // head + end of header request_head_and_body << head_cstr << CRLF; // body