--- parser3/src/main/pa_request.C 2001/03/18 17:24:55 1.48 +++ parser3/src/main/pa_request.C 2001/03/19 17:56:28 1.56 @@ -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.48 2001/03/18 17:24:55 paf Exp $ + $Id: pa_request.C,v 1.56 2001/03/19 17:56:28 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,50 +54,22 @@ 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, +static void output_response_attribute(const Hash::Key& aattribute, Hash::Val *ameaning, void *info) { String *attribute_to_exclude=static_cast(info); if(aattribute==*attribute_to_exclude) return; String attribute(aattribute.pool()); - attribute.append(aattribute, String::Untaint_lang::URI, true); - - Value *meaning=static_cast(ameaning); - String string(meaning->pool()); - if(VHash *vhash=meaning->get_hash()) { - // $value(value) $subattribute(subattribute value) - Hash& hash=vhash->hash(); - - 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, @@ -140,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"; @@ -149,9 +125,7 @@ void Request::core(Exception& system_exc // $MAIN:defaults Value *defaults=main_class?main_class->get_element(*defaults_name):0; - // $defaults.content-type - if(fdefault_content_type=defaults?defaults->get_element(*content_type_name):0) - response.fields().put(*content_type_name, fdefault_content_type); + fdefault_content_type=defaults?defaults->get_element(*content_type_name):0; // there must be some auto.p if(!main_class) @@ -189,9 +163,6 @@ void Request::core(Exception& system_exc // reset response response.fields().clear(); - // this is what we'd return in $response:content-type - Value *content_type; - // this is what we'd return in $response:body const String *body_string=0; @@ -267,9 +238,6 @@ void Request::core(Exception& system_exc code_value=NEW VUnknown(pool()); frame.store_param(code_name, code_value); - // future $response:content-type= - // content-type from any auto.p - content_type=fdefault_content_type; // future $response:body= // execute ^exception[origin;source;comment;type;code] body_string=execute_method(frame, *method); @@ -306,16 +274,12 @@ void Request::core(Exception& system_exc } // future $response:content-type - String &content_type_value=*NEW String(pool(), "text/plain"); - content_type=NEW VString(content_type_value); + response.fields().put(*content_type_name, + NEW VString(*NEW String(pool(), "text/plain"))); // future $response:body body_string=NEW String(pool(), buf); } - // set $response:content-type - if(content_type) - response.fields().put(*content_type_name, content_type); - // ERROR. write it out output_result(*body_string); } @@ -336,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; @@ -360,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, @@ -391,16 +357,24 @@ char *Request::absolute(const char *name } void Request::output_result(const String& body_string) { - // header: response fields + // header: cookies + cookie.output_result(); + + // set default content-type + if(fdefault_content_type) + response.fields().put_dont_replace(*content_type_name, fdefault_content_type); + + // 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); +}