--- parser3/src/include/pa_request.h 2001/03/14 17:15:06 1.54 +++ parser3/src/include/pa_request.h 2001/04/06 10:32:18 1.78 @@ -1,9 +1,11 @@ -/* - Parser +/** @file + Parser: request class decl. + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_request.h,v 1.54 2001/03/14 17:15:06 paf Exp $ + $Id: pa_request.h,v 1.78 2001/04/06 10:32:18 paf Exp $ */ #ifndef PA_REQUEST_H @@ -18,6 +20,10 @@ #include "pa_vobject.h" #include "pa_venv.h" #include "pa_vform.h" +#include "pa_vrequest.h" +#include "pa_vresponse.h" +#include "pa_vcookie.h" +#include "pa_sql_driver_manager.h" #ifndef NO_STRING_ORIGIN # define COMPILE_PARAMS \ @@ -38,96 +44,139 @@ class Temp_lang; +/// Main workhorse. class Request : public Pooled { friend Temp_lang; public: - - struct Info { + + /// some information from web server + class Info { + public: const char *document_root; const char *path_translated; - const char *request_method; + const char *method; const char *query_string; - const char *request_uri; + const char *uri; const char *content_type; size_t content_length; + const char *cookie; + const char *user_agent; }; Request(Pool& apool, Info& ainfo, - String::Untaint_lang alang + String::Untaint_lang adefault_lang ///< all tainted data default untainting lang ); ~Request() {} - // global classes + /// global classes Hash& classes() { return fclasses; } - // core request processing - char *core( - const char *sys_auto_path1, - const char *sys_auto_path2); + /** + core request processing + BEWARE: may throw exception to you: catch it! + */ + void core( + const char *root_auto_path, ///< path to system auto.p file + bool root_auto_fail, ///< fail if system auto.p file not found + const char *site_auto_path, ///< path to site auto.p file + bool site_auto_fail, ///< fail if site auto.p file not found + bool header_only); + + /// executes ops void execute(const Array& ops); + /// compiles the file, maybe forcing it's class @a name and @a base_class. VStateless_class *use_file( - const char *file, bool fail_on_read_problem=true, + const String& file_spec, bool fail_on_read_problem=true, const String *name=0, VStateless_class *base_class=0); // core.C + /// compiles a @a source buffer VStateless_class *use_buf( const char *source, const char *file, VStateless_class *aclass=0, const String *name=0, VStateless_class *base_class=0); // core.C + /// processes any code-junction there may be inside of @a value Value& process( Value& value, const String *name=0, bool intercept_string=true); // execute.C - void write(const String& astring) { - wcontext->write(astring, String::Untaint_lang::NO); // write(const) = clean - } - void write_no_lang(String& astring) { - // appending, sure of clean string inside - wcontext->write(astring, String::Untaint_lang::NO); + /// appending, sure of clean string inside + void write_no_lang(const String& astring) { + wcontext->write(astring, String::UL_CLEAN); + } + /// appending string, passing language built into string being written + void write_pass_lang(const String& astring) { + wcontext->write(astring, String::UL_PASS_APPENDED); } - + /// appending possible string, assigning untaint language void write_assign_lang(Value& avalue) { - // appending possible string, assigning untaint language wcontext->write(avalue, flang); } + /// appending possible string, passing language built into string being written void write_pass_lang(Value& avalue) { - // appending possible string, passing language built into string being written - wcontext->write(avalue, String::Untaint_lang::PASS_APPENDED); + wcontext->write(avalue, String::UL_PASS_APPENDED); } + /// appending sure value, that would be converted to clean string void write_no_lang(Value& avalue) { - // appending sure value, no strings inside - wcontext->write(avalue, String::Untaint_lang::NO); + wcontext->write(avalue, String::UL_CLEAN); + } + /// appending sure value, not VString + void write_expr_result(Value& avalue) { + wcontext->write(avalue); } - void fail_if_junction_(bool is, Value& value, const String& method_name, char *msg); + /// handy is-value-a-junction ensurer + void fail_if_junction_(bool is, Value& value, + const String& method_name, const char *msg); - char *relative(const char *path, const char *file); - char *absolute(const char *name); + /// returns relative to @a path path to @a file + const String& relative(const char *apath, const String& relative_name); + + /// returns an absolute @a path to relative @a name + const String& absolute(const String& relative_name); public: - // + /// info from web server Info& info; - // default base - VClass root_class; - // $env:fields here - VEnv env_class; - // $form:elements here - VForm form_class; + /// operators are methods of this class + VClass OP; + /// $env:fields here + VEnv env; + /// $form:elements here + VForm form; + /// $request:elements here + VRequest request; + /// $response: + VResponse response; + /// $cookie: + VCookie cookie; + + /// $MAIN:MIME-TYPES + Table *mime_types; - // contexts + /// contexts Value *self, *root, *rcontext; + /// contexts WContext *wcontext; + /// connection + SQL_Connection *connection; + /// table of protocol's libraries. read from $SQL:drivers + Table *protocol2library; + private: // core data // classes Hash fclasses; + // already used files to avoid cyclic uses + Hash used_files; + // execution stack Stack stack; @@ -137,8 +186,10 @@ private: // compile.C private: // execute.C - char *execute_method(Value& aself, const Method& method, bool return_cstr=true); - char *execute_method(Value& aself, const String& method_name, bool return_cstr=true); + const String *execute_method(Value& aself, const Method& method, + bool return_cstr=true); + const String *execute_method(Value& aself, const String& method_name, + bool return_cstr=true); Value *get_element(); @@ -146,6 +197,11 @@ private: // lang&raw String::Untaint_lang flang; +private: // defaults + + const String::Untaint_lang fdefault_lang; + Value *default_content_type; + private: // lang manipulation String::Untaint_lang set_lang(String::Untaint_lang alang) { @@ -157,8 +213,12 @@ private: // lang manipulation flang=alang; } +private: + + void output_result(const VFile& body_file, bool header_only); }; +/// Auto-object used for temporary changing Request::flang. class Temp_lang { Request& frequest; String::Untaint_lang saved_lang;