--- parser3/src/main/pa_request.C 2001/03/18 17:39:29 1.49 +++ parser3/src/main/pa_request.C 2001/03/19 17:42:16 1.55 @@ -1,16 +1,18 @@ -/* - Parser +/** @file + Parser: request class main part. @see compile.C and execute.C. + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_request.C,v 1.49 2001/03/18 17:39:29 paf Exp $ + $Id: pa_request.C,v 1.55 2001/03/19 17:42:16 paf Exp $ */ #include +#include "pa_common.h" #include "pa_request.h" #include "pa_wwrapper.h" -#include "pa_common.h" #include "pa_vclass.h" #include "_root.h" #include "_env.h" @@ -29,6 +31,7 @@ Request::Request(Pool& apool, form(apool), request(apool, *this), response(apool), + cookie(apool), fclasses(apool), fdefault_lang(adefault_lang), flang(adefault_lang), info(ainfo), @@ -51,24 +54,10 @@ Request::Request(Pool& apool, classes().put(*request_class_name, &request); // response class classes().put(*response_class_name, &response); + // cookie class + classes().put(*cookie_class_name, &cookie); } -static void append_attribute_subattribute(const Hash::Key& akey, Hash::Value *avalue, - void *info) { - if(akey==VALUE_NAME) - return; - - // ...; charset=windows1251 - String *string=static_cast(info); - string->APPEND_CONST("; "); - - string->append(akey, String::Untaint_lang::URI, true); - - string->APPEND_CONST("="); - - Value *value=static_cast(avalue); - string->append(value->as_string(), String::Untaint_lang::URI, true); -} static void output_response_attribute(const Hash::Key& aattribute, Hash::Value *ameaning, void *info) { String *attribute_to_exclude=static_cast(info); @@ -76,23 +65,11 @@ static void output_response_attribute(co return; String attribute(aattribute.pool()); - attribute.append(aattribute, String::Untaint_lang::URI, true); - - Value *meaning=static_cast(ameaning); - String string(meaning->pool()); - if(Hash *hash=meaning->get_hash()) { - // $value(value) $subattribute(subattribute value) - Value *value=static_cast(hash->get(*value_name)); - if(value) - string.append(value->as_string(), String::Untaint_lang::URI, true); - - hash->foreach(append_attribute_subattribute, &string); - } else // string value - string.append(meaning->as_string(), String::Untaint_lang::URI, true); + attribute.append(aattribute, String::Untaint_lang::HEADER, true); (*service_funcs.output_header_attribute)( attribute.cstr(), - string.cstr()); + attributed_meaning_string(static_cast(ameaning)).cstr()); } void Request::core(Exception& system_exception, @@ -138,6 +115,7 @@ void Request::core(Exception& system_exc int post_max_size=value?value:10*0x400*400; form.fill_fields(*this, post_max_size); + cookie.fill_fields(*this); // TODO: load site auto.p files, all assigned bases from upper dir /*char *site_auto_file="Y:\\parser3\\src\\auto.p"; @@ -322,11 +300,11 @@ void Request::core(Exception& system_exc } +/// \todo find|solve cyclic dependences VStateless_class *Request::use_file( const char *file, bool fail_on_read_problem, const String *name, VStateless_class *base_class) { - // TODO: обнаружить|решить cyclic dependences char *source=file_read(pool(), file, fail_on_read_problem); if(!source) return base_class; @@ -346,11 +324,13 @@ VStateless_class *Request::use_buf( return &cclass; } +/** + - fail_if_junction(true, junction = fail + - fail_if_junction(false, not junction = fail +*/ void Request::fail_if_junction_(bool is, Value& value, const String& method_name, char *msg) { - // fail_if_junction(true, junction = fail - // fail_if_junction(false, not junction = fail if((value.get_junction()!=0) ^ !is) THROW(0, 0, &method_name, @@ -377,19 +357,24 @@ char *Request::absolute(const char *name } void Request::output_result(const String& body_string) { + // header: cookies + cookie.output_result(); + // set default content-type - response.fields().put_dont_replace(*content_type_name, fdefault_content_type); + if(fdefault_content_type) + response.fields().put_dont_replace(*content_type_name, fdefault_content_type); - // header: response fields + // header: $response:fields without :body response.fields().foreach(output_response_attribute, /*excluding*/ body_name); + + // prepare const char *body=body_string.cstr(); - if(size_t content_length=strlen(body)) { - // header: content-length - char content_length_cstr[MAX_NUMBER]; - snprintf(content_length_cstr, MAX_NUMBER, "%d", content_length); - (*service_funcs.output_header_attribute)("content-length", - content_length_cstr); - // body - (*service_funcs.output_body)(body, content_length); - } -} \ No newline at end of file + size_t content_length=strlen(body); + + // header: content-length + char content_length_cstr[MAX_NUMBER]; + snprintf(content_length_cstr, MAX_NUMBER, "%d", content_length); + (*service_funcs.output_header_attribute)("content-length", content_length_cstr); + // body + (*service_funcs.output_body)(body, content_length); +}