Annotation of parser3/src/include/pa_request.h, revision 1.83.2.1

1.61      paf         1: /** @file
1.62      paf         2:        Parser: request class decl.
                      3: 
1.32      paf         4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.62      paf         5: 
1.36      paf         6:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.32      paf         7: 
1.83.2.1! paf         8:        $Id: pa_request.h,v 1.83 2001/04/20 14:18:36 paf Exp $
1.1       paf         9: */
                     10: 
                     11: #ifndef PA_REQUEST_H
                     12: #define PA_REQUEST_H
                     13: 
                     14: #include "pa_pool.h"
1.5       paf        15: #include "pa_hash.h"
1.7       paf        16: #include "pa_wcontext.h"
1.6       paf        17: #include "pa_value.h"
1.7       paf        18: #include "pa_stack.h"
1.12      paf        19: #include "pa_vclass.h"
1.45      paf        20: #include "pa_vobject.h"
1.47      paf        21: #include "pa_venv.h"
1.48      paf        22: #include "pa_vform.h"
1.56      paf        23: #include "pa_vrequest.h"
1.57      paf        24: #include "pa_vresponse.h"
1.60      paf        25: #include "pa_vcookie.h"
1.77      paf        26: #include "pa_sql_driver_manager.h"
1.44      paf        27: 
1.7       paf        28: #ifndef NO_STRING_ORIGIN
1.40      paf        29: #      define COMPILE_PARAMS  \
                     30:                const char *source, \
1.46      paf        31:                VStateless_class *aclass, const String *name, \
                     32:                VStateless_class *base_class, \
1.40      paf        33:                const char *file
                     34: #      define COMPILE(source, aclass, name, base_class, file)  \
                     35:                real_compile(source, aclass, name, base_class, file)
1.7       paf        36: #else
1.40      paf        37: #      define COMPILE_PARAMS  \
                     38:                const char *source, \
1.46      paf        39:                VStateless_class *aclass, const String *name, \
                     40:                VStateless_class *base_class
1.40      paf        41: #      define COMPILE(source, aclass, name, base_class, file)  \
                     42:                real_compile(source, aclass, name, base_class)
1.7       paf        43: #endif
1.4       paf        44: 
1.39      paf        45: class Temp_lang;
1.83.2.1! paf        46: class Methoded;
1.1       paf        47: 
1.61      paf        48: /// Main workhorse.
1.7       paf        49: class Request : public Pooled {
1.39      paf        50:        friend Temp_lang;
1.1       paf        51: public:
1.61      paf        52: 
                     53:        /// some information from web server
1.65      paf        54:        class Info {
                     55:        public:
1.53      paf        56:                const char *document_root;
                     57:                const char *path_translated;
1.56      paf        58:                const char *method;
1.53      paf        59:                const char *query_string;
1.56      paf        60:                const char *uri;
1.53      paf        61:                const char *content_type;
                     62:                size_t content_length;
1.60      paf        63:                const char *cookie;
1.71      paf        64:                const char *user_agent;
1.53      paf        65:        };
                     66:        
1.50      paf        67:        Request(Pool& apool,
1.53      paf        68:                Info& ainfo,
1.63      paf        69:                String::Untaint_lang adefault_lang ///< all tainted data default untainting lang
1.50      paf        70:        );
1.3       paf        71:        ~Request() {}
1.1       paf        72: 
1.61      paf        73:        /// global classes
1.6       paf        74:        Hash& classes() { return fclasses; }
                     75: 
1.65      paf        76:        /**
                     77:                core request processing
                     78: 
                     79:                BEWARE: may throw exception to you: catch it!
                     80:        */
                     81:        void core(
1.66      paf        82:                const char *root_auto_path, ///< path to system auto.p file
                     83:                bool root_auto_fail, ///< fail if system auto.p file not found
                     84:                const char *site_auto_path, ///< path to site auto.p file
                     85:                bool site_auto_fail, ///< fail if site auto.p file not found
1.65      paf        86:                bool header_only);
1.17      paf        87: 
1.61      paf        88:        /// executes ops
1.40      paf        89:        void execute(const Array& ops);
                     90: 
1.64      paf        91:        /// compiles the file, maybe forcing it's class @a name and @a base_class.
1.46      paf        92:        VStateless_class *use_file(
1.69      paf        93:                const String& file_spec, bool fail_on_read_problem=true,
1.45      paf        94:                const String *name=0, 
1.46      paf        95:                VStateless_class *base_class=0); // core.C
1.64      paf        96:        /// compiles a @a source buffer
1.46      paf        97:        VStateless_class *use_buf(
1.40      paf        98:                const char *source, const char *file,
1.46      paf        99:                VStateless_class *aclass=0, const String *name=0, 
                    100:                VStateless_class *base_class=0); // core.C
1.64      paf       101:        /// processes any code-junction there may be inside of @a value
1.40      paf       102:        Value& process(
1.33      paf       103:                Value& value, 
1.37      paf       104:                const String *name=0,
1.38      paf       105:                bool intercept_string=true); // execute.C
1.28      paf       106: 
1.61      paf       107:        /// appending, sure of clean string inside
1.65      paf       108:        void write_no_lang(const String& astring) {
1.74      paf       109:                wcontext->write(astring, String::UL_CLEAN);
1.49      paf       110:        }
1.61      paf       111:        /// appending string, passing language built into string being written
1.65      paf       112:        void write_pass_lang(const String& astring) {
                    113:                wcontext->write(astring, String::UL_PASS_APPENDED); 
1.59      paf       114:        }
1.61      paf       115:        /// appending possible string, assigning untaint language
1.40      paf       116:        void write_assign_lang(Value& avalue) {
1.39      paf       117:                wcontext->write(avalue, flang); 
1.22      paf       118:        }
1.61      paf       119:        /// appending possible string, passing language built into string being written
1.40      paf       120:        void write_pass_lang(Value& avalue) {
1.65      paf       121:                wcontext->write(avalue, String::UL_PASS_APPENDED); 
1.49      paf       122:        }
1.61      paf       123:        /// appending sure value, that would be converted to clean string
1.49      paf       124:        void write_no_lang(Value& avalue) {
1.74      paf       125:                wcontext->write(avalue, String::UL_CLEAN);
1.55      paf       126:        }
1.61      paf       127:        /// appending sure value, not VString
1.55      paf       128:        void write_expr_result(Value& avalue) {
                    129:                wcontext->write(avalue); 
1.40      paf       130:        }
1.22      paf       131: 
1.64      paf       132:        /// returns relative to @a path  path to @a file 
1.69      paf       133:        const String& relative(const char *apath, const String& relative_name);
1.61      paf       134: 
1.64      paf       135:        /// returns an absolute @a path to relative @a name
1.69      paf       136:        const String& absolute(const String& relative_name);
1.42      paf       137: 
1.80      paf       138:        /// returns the mime type of 'user_file_name_cstr'
                    139:        const String& mime_type_of(const char *user_file_name_cstr);
                    140: 
1.17      paf       141: public:
1.22      paf       142:        
1.61      paf       143:        /// info from web server
1.53      paf       144:        Info& info;
1.81      paf       145:        /// user's post data
                    146:        char *post_data;  size_t post_size;
1.53      paf       147: 
1.78      paf       148:        /// operators are methods of this class
1.83.2.1! paf       149:        Methoded& OP;
1.61      paf       150:        /// $env:fields here
1.57      paf       151:        VEnv env;
1.61      paf       152:        /// $form:elements here
1.57      paf       153:        VForm form;
1.61      paf       154:        /// $request:elements here
1.57      paf       155:        VRequest request;
1.61      paf       156:        /// $response:
1.57      paf       157:        VResponse response;
1.61      paf       158:        /// $cookie:
1.60      paf       159:        VCookie cookie;
1.70      paf       160: 
1.61      paf       161:        /// contexts
1.22      paf       162:        Value *self, *root, *rcontext;
1.61      paf       163:        /// contexts
1.22      paf       164:        WContext *wcontext;
1.76      paf       165: 
                    166:        /// connection
1.77      paf       167:        SQL_Connection *connection;
                    168:        /// table of protocol's libraries. read from $SQL:drivers
                    169:        Table *protocol2library;
1.79      paf       170:        /// mail options
                    171:        Hash *mail;
1.83      paf       172:        /// PCRE character tables
                    173:        unsigned char *pcre_tables;
1.6       paf       174: 
1.7       paf       175: private: // core data
1.6       paf       176: 
                    177:        // classes
                    178:        Hash fclasses;
1.67      paf       179: 
                    180:        // already used files to avoid cyclic uses
                    181:        Hash used_files;
1.6       paf       182: 
1.7       paf       183:        // execution stack
                    184:        Stack stack;
                    185: 
                    186: private: // compile.C
                    187: 
1.46      paf       188:        VStateless_class& real_compile(COMPILE_PARAMS);
1.7       paf       189: 
                    190: private: // execute.C
                    191: 
1.57      paf       192:        const String *execute_method(Value& aself, const Method& method, 
                    193:                bool return_cstr=true);
                    194:        const String *execute_method(Value& aself, const String& method_name, 
                    195:                bool return_cstr=true);
1.9       paf       196: 
                    197:        Value *get_element();
1.22      paf       198: 
                    199: private: // lang&raw 
                    200:        
1.39      paf       201:        String::Untaint_lang flang;
1.58      paf       202: 
                    203: private: // defaults
                    204: 
                    205:        const String::Untaint_lang fdefault_lang;
1.68      paf       206:        Value *default_content_type;
1.80      paf       207: 
                    208: private: // mime types
                    209: 
                    210:        /// $MAIN:MIME-TYPES
                    211:        Table *mime_types;
1.22      paf       212: 
1.39      paf       213: private: // lang manipulation
1.22      paf       214: 
1.39      paf       215:        String::Untaint_lang set_lang(String::Untaint_lang alang) {
                    216:                String::Untaint_lang result=flang;
                    217:                flang=alang;
                    218:                return result;
                    219:        }
                    220:        void restore_lang(String::Untaint_lang alang) {
                    221:                flang=alang;
                    222:        }
                    223: 
1.59      paf       224: private:
                    225: 
1.75      paf       226:        void output_result(const VFile& body_file, bool header_only);
1.39      paf       227: };
                    228: 
1.61      paf       229: ///    Auto-object used for temporary changing Request::flang.
1.39      paf       230: class Temp_lang {
                    231:        Request& frequest;
                    232:        String::Untaint_lang saved_lang;
                    233: public:
                    234:        Temp_lang(Request& arequest, String::Untaint_lang alang) : 
                    235:                frequest(arequest),
                    236:                saved_lang(arequest.set_lang(alang)) {
                    237:        }
                    238:        ~Temp_lang() { 
                    239:                frequest.restore_lang(saved_lang); 
                    240:        }
1.4       paf       241: };
1.1       paf       242: 
                    243: #endif

E-mail: