--- parser3/src/main/pa_common.C 2003/07/21 07:09:02 1.143.2.21.2.29 +++ parser3/src/main/pa_common.C 2003/09/25 09:15:03 1.156 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_COMMON_C="$Date: 2003/07/21 07:09:02 $"; +static const char* IDENT_COMMON_C="$Date: 2003/09/25 09:15:03 $"; #include "pa_common.h" #include "pa_exception.h" @@ -19,6 +19,8 @@ static const char* IDENT_COMMON_C="$Date #ifdef PA_HTTP #include "pa_vstring.h" #include "pa_vint.h" +#include "pa_vhash.h" +#include "pa_vtable.h" #ifdef CYGWIN #define _GNU_H_WINDOWS32_SOCKETS @@ -133,6 +135,7 @@ const String file_status_name(FILE_STATU #define HTTP_HEADERS_NAME "headers" #define HTTP_ANY_STATUS_NAME "any-status" #define HTTP_CHARSET_NAME "charset" +#define HTTP_TABLES_NAME "tables" // statics @@ -141,6 +144,7 @@ static const String http_timeout_name(HT static const String http_headers_name(HTTP_HEADERS_NAME); static const String http_any_status_name(HTTP_ANY_STATUS_NAME); static const String http_charset_name(HTTP_CHARSET_NAME); +static const String http_tables_name(HTTP_TABLES_NAME); // defines @@ -337,7 +341,7 @@ static void http_pass_header(HashStringV static Charset* detect_charset(Charset& source_charset, const String& content_type_value) { - const StringBody CONTENT_TYPE_VALUE= + const String::Body CONTENT_TYPE_VALUE= content_type_value.change_case(source_charset, String::CC_UPPER); // content-type: xxx/xxx; source_charset=WE-NEED-THIS // content-type: xxx/xxx; source_charset="WE-NEED-THIS" @@ -359,7 +363,7 @@ static Charset* detect_charset(Charset& if(delim_pos!=STRING_NOT_FOUND) charset_end=delim_pos; } - const StringBody CHARSET_NAME_BODY= + const String::Body CHARSET_NAME_BODY= CONTENT_TYPE_VALUE.mid(charset_begin, charset_end); return &charsets.get(CHARSET_NAME_BODY); @@ -375,6 +379,7 @@ struct File_read_http_result { HashStringValue* headers; }; #endif +/// @todo build .cookies field. use ^file.tables.SET-COOKIES.menu{ for now static File_read_http_result file_read_http(Request_charsets& charsets, const String& file_spec, HashStringValue *options=0) { @@ -496,6 +501,10 @@ static File_read_http_result file_read_h ArrayString aheaders; result.headers=new HashStringValue; + VHash* vtables=new VHash; + result.headers->put(http_tables_name, vtables); + HashStringValue& tables=vtables->hash(); + size_t pos_after=0; header_block.split(aheaders, pos_after, CRLF); @@ -509,11 +518,35 @@ static File_read_http_result file_read_h throw Exception("http.response", &connect_string, "bad response from host - bad header \"%s\"", line.cstr()); - const StringBody HEADER_NAME= + const String::Body HEADER_NAME= line.mid(0, pos).change_case(charsets.source(), String::CC_UPPER); const String& header_value=line.mid(pos+2, line.length()); if(HEADER_NAME=="CONTENT-TYPE") real_remote_charset=detect_charset(charsets.source(), header_value); + + // tables + { + Value *valready=(Value *)tables.get(HEADER_NAME); + bool existed=valready!=0; + Table *table; + if(existed) { + // second+ appearence + table=valready->get_table(); + } else { + // first appearence + Table::columns_type columns =new ArrayString(1); + *columns+=new String("value"); + table=new Table(columns); + } + // this string becomes next row + ArrayString& row=*new ArrayString(1); + row+=&header_value; + *table+=&row; + // not existed before? add it + if(!existed) + tables.put(HEADER_NAME, new VTable(table)); + } + result.headers->put(HEADER_NAME, new VString(header_value)); } // defaulting to used-asked charset [it's never empty!]