--- parser3/src/main/pa_http.C 2015/04/02 22:04:41 1.62 +++ parser3/src/main/pa_http.C 2015/04/30 17:37:43 1.65 @@ -13,7 +13,7 @@ #include "pa_vfile.h" #include "pa_random.h" -volatile const char * IDENT_PA_HTTP_C="$Id: pa_http.C,v 1.62 2015/04/02 22:04:41 moko Exp $" IDENT_PA_HTTP_H; +volatile const char * IDENT_PA_HTTP_C="$Id: pa_http.C,v 1.65 2015/04/30 17:37:43 moko Exp $" IDENT_PA_HTTP_H; #ifdef _MSC_VER #include @@ -68,19 +68,13 @@ static bool set_addr(struct sockaddr_in addr->sin_family=AF_INET; addr->sin_port=htons(port); if(host) { - ulong packed_ip=inet_addr(host); - if(packed_ip!=INADDR_NONE) - memcpy(&addr->sin_addr, &packed_ip, sizeof(packed_ip)); - else { - struct hostent *hostIP=gethostbyname(host); - if(hostIP) - memcpy(&addr->sin_addr, hostIP->h_addr, hostIP->h_length); - else - return false; - } - } else - addr->sin_addr.s_addr=INADDR_ANY; - return true; + struct hostent *hostIP=gethostbyname(host); + if(hostIP && hostIP->h_addrtype == AF_INET){ + memcpy(&addr->sin_addr, hostIP->h_addr, hostIP->h_length); + return true; + } + } + return false; } size_t guess_content_length(char* buf) { @@ -410,7 +404,7 @@ static void form_value2string( } else throw Exception(PARSER_RUNTIME, new String(key, String::L_TAINTED), - "is %s, "HTTP_FORM_NAME" option value can be string or table only (file is allowed for $."HTTP_METHOD_NAME"[POST] + $."HTTP_FORM_ENCTYPE_NAME"["HTTP_CONTENT_TYPE_MULTIPART_FORMDATA"])", value->type()); + "is %s, " HTTP_FORM_NAME " option value can be string or table only (file is allowed for $." HTTP_METHOD_NAME "[POST] + $." HTTP_FORM_ENCTYPE_NAME "[" HTTP_CONTENT_TYPE_MULTIPART_FORMDATA "])", value->type()); } const char* pa_form2string(HashStringValue& form, Request_charsets& charsets) { @@ -516,7 +510,7 @@ static void form_value2part( } else throw Exception(PARSER_RUNTIME, new String(key, String::L_TAINTED), - "is %s, "HTTP_FORM_NAME" option value can be string, table or file only", value->type()); + "is %s, " HTTP_FORM_NAME " option value can be string, table or file only", value->type()); } const char* pa_form2string_multipart(HashStringValue& form, Request& r, const char* boundary, size_t& post_size){ @@ -548,7 +542,7 @@ static void find_headers_end(char* p, // Set-Cookie: name=value; Domain=docs.foo.com; Path=/accounts; Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; HttpOnly static ArrayString* parse_cookie(Request& r, const String& cookie) { - char *current=strdup(cookie.cstr()); + char *current=pa_strdup(cookie.cstr()); const String* name=0; const String* value=&String::Empty; @@ -711,26 +705,26 @@ File_read_http_result pa_internal_file_r if(method_is_get) throw Exception(PARSER_RUNTIME, 0, - "you can not use $."HTTP_FORM_ENCTYPE_NAME" option with method GET"); + "you can not use $." HTTP_FORM_ENCTYPE_NAME " option with method GET"); multipart=strcasecmp(encode, HTTP_CONTENT_TYPE_MULTIPART_FORMDATA)==0; if(!multipart && strcasecmp(encode, HTTP_CONTENT_TYPE_FORM_URLENCODED)!=0) throw Exception(PARSER_RUNTIME, 0, - "$."HTTP_FORM_ENCTYPE_NAME" option value can be "HTTP_CONTENT_TYPE_FORM_URLENCODED" or "HTTP_CONTENT_TYPE_MULTIPART_FORMDATA" only"); + "$." HTTP_FORM_ENCTYPE_NAME " option value can be " HTTP_CONTENT_TYPE_FORM_URLENCODED " or " HTTP_CONTENT_TYPE_MULTIPART_FORMDATA " only"); } if(vbody){ if(method_is_get) throw Exception(PARSER_RUNTIME, 0, - "you can not use $."HTTP_BODY_NAME" option with method GET"); + "you can not use $." HTTP_BODY_NAME " option with method GET"); if(form) throw Exception(PARSER_RUNTIME, 0, - "you can not use options $."HTTP_BODY_NAME" and $."HTTP_FORM_NAME" together"); + "you can not use options $." HTTP_BODY_NAME " and $." HTTP_FORM_NAME " together"); } //preparing request @@ -890,7 +884,7 @@ File_read_http_result pa_internal_file_r // sending request int status_code=http_request(response, response_size, - host, port, request, request_size, + pa_idna_encode(host, r.charsets.source()), port, request, request_size, timeout_secs, fail_on_status_ne_200); // processing results