--- parser3/src/main/pa_common.C 2003/05/30 10:45:37 1.151 +++ parser3/src/main/pa_common.C 2003/07/21 07:07:16 1.153 @@ -5,14 +5,17 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_COMMON_C="$Date: 2003/05/30 10:45:37 $"; +static const char* IDENT_COMMON_C="$Date: 2003/07/21 07:07:16 $"; #include "pa_common.h" #include "pa_exception.h" #include "pa_globals.h" #include "pa_hash.h" +#include "pa_table.h" #include "pa_vstring.h" #include "pa_vdate.h" +#include "pa_vhash.h" +#include "pa_vtable.h" #ifdef WIN32 # include @@ -182,11 +185,11 @@ static void timeout_handler(int sig){ #endif static int http_request(String& response, - const String *origin_string, - const char* host, int port, - const char* request, - int timeout, - bool fail_on_status_ne_200) { + const String *origin_string, + const char* host, int port, + const char* request, + int timeout, + bool fail_on_status_ne_200) { if(!host) throw Exception("http.host", origin_string, @@ -252,6 +255,9 @@ static int http_request(String& response #endif } +#undef CRLF +#define CRLF "\r\n" + #ifndef DOXYGEN struct Http_pass_header_info { String* request; @@ -265,11 +271,12 @@ static void http_pass_header(const Hash: *(i.request)<(value), String::UL_HTTP_HEADER, false) - <<"\n"; + << CRLF; if(key.change_case(pool, String::CC_UPPER)=="USER-AGENT") i.user_agent_specified=true; } +/// @todo build .cookies field. use ^file.tables.SET-COOKIES.menu{ for now static void file_read_http(Pool& pool, const String& file_spec, void*& data, size_t& data_size, Hash *options=0, Hash** out_fields=0) { @@ -325,7 +332,7 @@ static void file_read_http(Pool& pool, c //making request String request(pool); - request<< method <<" "<< uri <<" HTTP/1.0\nHost: "<< host<<"\n"; + request<< method <<" "<< uri <<" HTTP/1.0" CRLF "Host: "<< host<< CRLF; bool user_agent_specified=false; if(vheaders && !vheaders->is_string()) { // allow empty if(Hash *headers=vheaders->get_hash(&connect_string)) { @@ -338,8 +345,8 @@ static void file_read_http(Pool& pool, c "headers param must be hash"); }; if(!user_agent_specified) // defaulting - request << "user-agent: " DEFAULT_USER_AGENT "\n"; - request<<"\n"; + request << "user-agent: " DEFAULT_USER_AGENT CRLF; + request<hash(0); + size_t pos_after_ref=0; - header_block.split(aheaders, &pos_after_ref, "\r\n", 2); + header_block.split(aheaders, &pos_after_ref, CRLF, 2); //processing headers for(int i=1;icstr()); - - headers.put( - line->mid(0, pos).change_case(pool, String::CC_UPPER), - new(pool) VString(line->mid(pos+2, line->size()))); + + const String& sname=line->mid(0, pos).change_case(pool, String::CC_UPPER); + const String& string=line->mid(pos+2, line->size()); + + // tables + { + Value *valready=(Value *)tables.get(sname); + bool existed=valready!=0; + Table *table; + if(existed) { + // second+ appearence + table=valready->get_table(); + } else { + // first appearence + Array& columns=*new(pool) Array(pool, 1); + columns+=new(pool) String(pool, "value"); + table=new(pool) Table(pool, 0, &columns); + } + // this string becomes next row + Array& row=*new(pool) Array(pool, 1); + row+=&string; + *table+=&row; + // not existed before? add it + if(!existed) + tables.put(sname, new(pool) VTable(pool, table)); + } + headers.put(sname, new(pool) VString(string)); } else throw Exception("http.response", &connect_string,