|
|
| version 1.54, 2012/06/02 22:52:36 | version 1.59, 2013/07/23 09:46:58 |
|---|---|
| Line 15 | Line 15 |
| volatile const char * IDENT_PA_HTTP_C="$Id$" IDENT_PA_HTTP_H; | volatile const char * IDENT_PA_HTTP_C="$Id$" IDENT_PA_HTTP_H; |
| #ifdef _MSC_VER | |
| #include <windows.h> | |
| #else | |
| #define closesocket close | |
| #endif | |
| // defines | // defines |
| #define HTTP_METHOD_NAME "method" | #define HTTP_METHOD_NAME "method" |
| Line 22 volatile const char * IDENT_PA_HTTP_C="$ | Line 28 volatile const char * IDENT_PA_HTTP_C="$ |
| #define HTTP_BODY_NAME "body" | #define HTTP_BODY_NAME "body" |
| #define HTTP_TIMEOUT_NAME "timeout" | #define HTTP_TIMEOUT_NAME "timeout" |
| #define HTTP_HEADERS_NAME "headers" | #define HTTP_HEADERS_NAME "headers" |
| #define HTTP_COOKIES_NAME "cookies" | |
| #define HTTP_FORM_ENCTYPE_NAME "enctype" | #define HTTP_FORM_ENCTYPE_NAME "enctype" |
| #define HTTP_ANY_STATUS_NAME "any-status" | #define HTTP_ANY_STATUS_NAME "any-status" |
| #define HTTP_OMIT_POST_CHARSET_NAME "omit-post-charset" // ^file::load[...;http://...;$.form[...]$.method[post]] | #define HTTP_OMIT_POST_CHARSET_NAME "omit-post-charset" // ^file::load[...;http://...;$.method[post]] by default adds charset to content-type |
| // by default add charset to content-type | |
| #define HTTP_TABLES_NAME "tables" | #define HTTP_TABLES_NAME "tables" |
| Line 35 volatile const char * IDENT_PA_HTTP_C="$ | Line 39 volatile const char * IDENT_PA_HTTP_C="$ |
| #define DEFAULT_USER_AGENT "parser3" | #define DEFAULT_USER_AGENT "parser3" |
| # ifndef INADDR_NONE | #ifndef INADDR_NONE |
| # define INADDR_NONE ((ulong) -1) | #define INADDR_NONE ((ulong) -1) |
| # endif | #endif |
| #undef CRLF | #undef CRLF |
| #define CRLF "\r\n" | #define CRLF "\r\n" |
| // helpers | // helpers |
| /// pa_internal_file_read_http uses this | |
| class Cookies_table_template_columns: public ArrayString { | class Cookies_table_template_columns: public ArrayString { |
| public: | public: |
| Cookies_table_template_columns() { | Cookies_table_template_columns() { |
| Line 547 static ArrayString* parse_cookie(Request | Line 551 static ArrayString* parse_cookie(Request |
| char *current=strdup(cookie.cstr()); | char *current=strdup(cookie.cstr()); |
| const String* name=0; | const String* name=0; |
| const String* value=0; | const String* value=&String::Empty; |
| const String* expires=0; | const String* expires=&String::Empty; |
| const String* max_age=0; | const String* max_age=&String::Empty; |
| const String* path=0; | const String* path=&String::Empty; |
| const String* domain=0; | const String* domain=&String::Empty; |
| const String* httponly=0; | const String* httponly=&String::Empty; |
| const String* secure=0; | const String* secure=&String::Empty; |
| bool first_pair=true; | bool first_pair=true; |
| Line 608 static ArrayString* parse_cookie(Request | Line 612 static ArrayString* parse_cookie(Request |
| return result; | return result; |
| } | } |
| Table* parse_cookies(Request& r, Table *cookies){ | |
| Table& result=*new Table(new Cookies_table_template_columns); | |
| for(Array_iterator<Table::element_type> i(*cookies); i.has_next(); ) | |
| if(ArrayString* row=parse_cookie(r, *i.next()->get(0))) | |
| result+=row; | |
| return &result; | |
| } | |
| /// @todo build .cookies field. use ^file.tables.SET-COOKIES.menu{ for now | /// @todo build .cookies field. use ^file.tables.SET-COOKIES.menu{ for now |
| File_read_http_result pa_internal_file_read_http(Request& r, | File_read_http_result pa_internal_file_read_http(Request& r, |
| const String& file_spec, | const String& file_spec, |
| Line 628 File_read_http_result pa_internal_file_r | Line 642 File_read_http_result pa_internal_file_r |
| Value* vcookies=0; | Value* vcookies=0; |
| Value* vbody=0; | Value* vbody=0; |
| Charset *asked_remote_charset=0; | Charset *asked_remote_charset=0; |
| Charset* real_remote_charset=0; | |
| const char* user_cstr=0; | const char* user_cstr=0; |
| const char* password_cstr=0; | const char* password_cstr=0; |
| const char* encode=0; | const char* encode=0; |
| Line 671 File_read_http_result pa_internal_file_r | Line 686 File_read_http_result pa_internal_file_r |
| omit_post_charset=vomit_post_charset->as_bool(); | omit_post_charset=vomit_post_charset->as_bool(); |
| } | } |
| if(Value* vcharset_name=options->get(PA_CHARSET_NAME)) { | if(Value* vcharset_name=options->get(PA_CHARSET_NAME)) { |
| asked_remote_charset=&charsets.get(vcharset_name->as_string(). | asked_remote_charset=&charsets.get(vcharset_name->as_string().change_case(r.charsets.source(), String::CC_UPPER)); |
| change_case(r.charsets.source(), String::CC_UPPER)); | } |
| if(Value* vresponse_charset_name=options->get(PA_RESPONSE_CHARSET_NAME)) { | |
| real_remote_charset=&charsets.get(vresponse_charset_name->as_string().change_case(r.charsets.source(), String::CC_UPPER)); | |
| } | } |
| if(Value* vuser=options->get(HTTP_USER)) { | if(Value* vuser=options->get(HTTP_USER)) { |
| valid_options++; | valid_options++; |
| Line 886 File_read_http_result pa_internal_file_r | Line 903 File_read_http_result pa_internal_file_r |
| result.headers=new HashStringValue; | result.headers=new HashStringValue; |
| VHash* vtables=new VHash; | VHash* vtables=new VHash; |
| result.headers->put(HTTP_TABLES_NAME, vtables); | result.headers->put(HTTP_TABLES_NAME, vtables); |
| Charset* real_remote_charset=0; // undetected, yet | |
| if(headers_end_at) { | if(headers_end_at) { |
| *headers_end_at=0; | *headers_end_at=0; |
| Line 909 File_read_http_result pa_internal_file_r | Line 925 File_read_http_result pa_internal_file_r |
| "bad response from host - bad header \"%s\"", line.cstr()); | "bad response from host - bad header \"%s\"", line.cstr()); |
| const String::Body HEADER_NAME=line.mid(0, pos).change_case(r.charsets.source(), String::CC_UPPER); | 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"); | 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) | if(as_text && HEADER_NAME==HTTP_CONTENT_TYPE_UPPER && !real_remote_charset) |
| real_remote_charset=detect_charset(HEADER_VALUE.cstr()); | real_remote_charset=detect_charset(HEADER_VALUE.cstr()); |
| // tables | // tables |
| Line 939 File_read_http_result pa_internal_file_r | Line 955 File_read_http_result pa_internal_file_r |
| } | } |
| // filling $.cookies | // filling $.cookies |
| if(Value *vcookie=(Value *)tables.get("SET-COOKIE")){ | if(Value *vcookies=(Value *)tables.get("SET-COOKIE")) |
| Table& tcookies=*new Table(new Cookies_table_template_columns); | result.headers->put(HTTP_COOKIES_NAME, new VTable(parse_cookies(r, vcookies->get_table()))); |
| for(Array_iterator<Table::element_type> i(*vcookie->get_table()); i.has_next(); ) | |
| if(ArrayString* row=parse_cookie(r, *i.next()->get(0))) | |
| tcookies+=row; | |
| result.headers->put(HTTP_COOKIES_NAME, new VTable(&tcookies)); | |
| } | |
| } | } |
| if(as_text && raw_body_size>=3 && strncmp(raw_body, "\xEF\xBB\xBF", 3)==0){ | if(as_text && raw_body_size>=3 && strncmp(raw_body, "\xEF\xBB\xBF", 3)==0){ |