Annotation of parser3/src/include/pa_request.h, revision 1.94.4.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.94.4.1! parser      8:        $Id: pa_request.h,v 1.94 2001/08/06 16:18:26 parser Exp $
1.1       paf         9: */
                     10: 
                     11: #ifndef PA_REQUEST_H
                     12: #define PA_REQUEST_H
                     13: 
1.88      parser     14: #include "pa_config_includes.h"
1.1       paf        15: #include "pa_pool.h"
1.5       paf        16: #include "pa_hash.h"
1.7       paf        17: #include "pa_wcontext.h"
1.6       paf        18: #include "pa_value.h"
1.7       paf        19: #include "pa_stack.h"
1.12      paf        20: #include "pa_vclass.h"
1.45      paf        21: #include "pa_vobject.h"
1.47      paf        22: #include "pa_venv.h"
1.48      paf        23: #include "pa_vform.h"
1.90      parser     24: #include "pa_vmath.h"
1.56      paf        25: #include "pa_vrequest.h"
1.57      paf        26: #include "pa_vresponse.h"
1.60      paf        27: #include "pa_vcookie.h"
1.77      paf        28: #include "pa_sql_driver_manager.h"
1.44      paf        29: 
1.7       paf        30: #ifndef NO_STRING_ORIGIN
1.40      paf        31: #      define COMPILE_PARAMS  \
                     32:                const char *source, \
1.46      paf        33:                VStateless_class *aclass, const String *name, \
                     34:                VStateless_class *base_class, \
1.40      paf        35:                const char *file
                     36: #      define COMPILE(source, aclass, name, base_class, file)  \
                     37:                real_compile(source, aclass, name, base_class, file)
1.7       paf        38: #else
1.40      paf        39: #      define COMPILE_PARAMS  \
                     40:                const char *source, \
1.46      paf        41:                VStateless_class *aclass, const String *name, \
                     42:                VStateless_class *base_class
1.40      paf        43: #      define COMPILE(source, aclass, name, base_class, file)  \
                     44:                real_compile(source, aclass, name, base_class)
1.7       paf        45: #endif
1.4       paf        46: 
1.39      paf        47: class Temp_lang;
1.84      paf        48: class Methoded;
1.1       paf        49: 
1.61      paf        50: /// Main workhorse.
1.7       paf        51: class Request : public Pooled {
1.39      paf        52:        friend Temp_lang;
1.1       paf        53: public:
1.61      paf        54: 
                     55:        /// some information from web server
1.65      paf        56:        class Info {
                     57:        public:
1.53      paf        58:                const char *document_root;
                     59:                const char *path_translated;
1.56      paf        60:                const char *method;
1.53      paf        61:                const char *query_string;
1.56      paf        62:                const char *uri;
1.53      paf        63:                const char *content_type;
                     64:                size_t content_length;
1.60      paf        65:                const char *cookie;
1.71      paf        66:                const char *user_agent;
1.53      paf        67:        };
                     68:        
1.50      paf        69:        Request(Pool& apool,
1.53      paf        70:                Info& ainfo,
1.63      paf        71:                String::Untaint_lang adefault_lang ///< all tainted data default untainting lang
1.50      paf        72:        );
1.3       paf        73:        ~Request() {}
1.1       paf        74: 
1.61      paf        75:        /// global classes
1.6       paf        76:        Hash& classes() { return fclasses; }
                     77: 
1.65      paf        78:        /**
                     79:                core request processing
                     80: 
                     81:                BEWARE: may throw exception to you: catch it!
                     82:        */
                     83:        void core(
1.94.4.1! parser     84:                const char *root_config_filespec, ///< system config filespec
        !            85:                bool root_config_fail_on_read_problem, ///< fail if system config file not found
        !            86:                const char *site_config_filespec, ///< site config filespec
        !            87:                bool site_config_fail_on_read_problem, ///< fail if site config file not found
1.65      paf        88:                bool header_only);
1.17      paf        89: 
1.61      paf        90:        /// executes ops
1.89      parser     91:        void execute(const Array& ops); // execute.C
1.40      paf        92: 
1.64      paf        93:        /// compiles the file, maybe forcing it's class @a name and @a base_class.
1.46      paf        94:        VStateless_class *use_file(
1.94      parser     95:                const String& file_name, 
                     96:                bool ignore_class_path=false, bool fail_on_read_problem=true,
1.45      paf        97:                const String *name=0, 
1.46      paf        98:                VStateless_class *base_class=0); // core.C
1.64      paf        99:        /// compiles a @a source buffer
1.46      paf       100:        VStateless_class *use_buf(
1.40      paf       101:                const char *source, const char *file,
1.46      paf       102:                VStateless_class *aclass=0, const String *name=0, 
                    103:                VStateless_class *base_class=0); // core.C
1.64      paf       104:        /// processes any code-junction there may be inside of @a value
1.40      paf       105:        Value& process(
1.33      paf       106:                Value& value, 
1.37      paf       107:                const String *name=0,
1.38      paf       108:                bool intercept_string=true); // execute.C
1.28      paf       109: 
1.61      paf       110:        /// appending, sure of clean string inside
1.65      paf       111:        void write_no_lang(const String& astring) {
1.74      paf       112:                wcontext->write(astring, String::UL_CLEAN);
1.49      paf       113:        }
1.61      paf       114:        /// appending string, passing language built into string being written
1.65      paf       115:        void write_pass_lang(const String& astring) {
                    116:                wcontext->write(astring, String::UL_PASS_APPENDED); 
1.59      paf       117:        }
1.61      paf       118:        /// appending possible string, assigning untaint language
1.40      paf       119:        void write_assign_lang(Value& avalue) {
1.39      paf       120:                wcontext->write(avalue, flang); 
1.22      paf       121:        }
1.61      paf       122:        /// appending possible string, passing language built into string being written
1.40      paf       123:        void write_pass_lang(Value& avalue) {
1.65      paf       124:                wcontext->write(avalue, String::UL_PASS_APPENDED); 
1.49      paf       125:        }
1.61      paf       126:        /// appending sure value, that would be converted to clean string
1.49      paf       127:        void write_no_lang(Value& avalue) {
1.74      paf       128:                wcontext->write(avalue, String::UL_CLEAN);
1.55      paf       129:        }
1.61      paf       130:        /// appending sure value, not VString
1.55      paf       131:        void write_expr_result(Value& avalue) {
                    132:                wcontext->write(avalue); 
1.40      paf       133:        }
1.22      paf       134: 
1.64      paf       135:        /// returns relative to @a path  path to @a file 
1.69      paf       136:        const String& relative(const char *apath, const String& relative_name);
1.61      paf       137: 
1.64      paf       138:        /// returns an absolute @a path to relative @a name
1.69      paf       139:        const String& absolute(const String& relative_name);
1.42      paf       140: 
1.80      paf       141:        /// returns the mime type of 'user_file_name_cstr'
                    142:        const String& mime_type_of(const char *user_file_name_cstr);
                    143: 
1.17      paf       144: public:
1.22      paf       145:        
1.61      paf       146:        /// info from web server
1.53      paf       147:        Info& info;
1.81      paf       148:        /// user's post data
                    149:        char *post_data;  size_t post_size;
1.53      paf       150: 
1.78      paf       151:        /// operators are methods of this class
1.84      paf       152:        Methoded& OP;
1.86      paf       153:        /// $env:fields
1.57      paf       154:        VEnv env;
1.86      paf       155:        /// $form:elements
1.57      paf       156:        VForm form;
1.90      parser    157:        /// $math:constants
                    158:        VMath math;
1.86      paf       159:        /// $request:elements
1.57      paf       160:        VRequest request;
1.86      paf       161:        /// $response:elements
1.57      paf       162:        VResponse response;
1.86      paf       163:        /// $cookie:elements
1.60      paf       164:        VCookie cookie;
1.70      paf       165: 
1.61      paf       166:        /// contexts
1.22      paf       167:        Value *self, *root, *rcontext;
1.61      paf       168:        /// contexts
1.22      paf       169:        WContext *wcontext;
1.85      paf       170: 
1.86      paf       171:        /// 'MAIN' class conglomerat
1.85      paf       172:        VStateless_class *main_class;
1.76      paf       173: 
                    174:        /// connection
1.77      paf       175:        SQL_Connection *connection;
1.83      paf       176:        /// PCRE character tables
                    177:        unsigned char *pcre_tables;
1.87      paf       178: 
                    179:        /// classes configured data
                    180:        Hash classes_conf;
                    181: 
1.6       paf       182: 
1.7       paf       183: private: // core data
1.6       paf       184: 
1.89      parser    185:        /// classes
1.6       paf       186:        Hash fclasses;
1.67      paf       187: 
1.89      parser    188:        /// already used files to avoid cyclic uses
1.67      paf       189:        Hash used_files;
1.6       paf       190: 
1.89      parser    191:        /// execution stack
1.7       paf       192:        Stack stack;
1.89      parser    193: 
                    194:        /**     endless execute(execute(... preventing counter 
                    195:                @see ANTI_ENDLESS_EXECUTE_RECOURSION
                    196:        */
                    197:        uint anti_endless_execute_recoursion;
1.7       paf       198: 
                    199: private: // compile.C
                    200: 
1.46      paf       201:        VStateless_class& real_compile(COMPILE_PARAMS);
1.7       paf       202: 
                    203: private: // execute.C
                    204: 
1.92      parser    205:        const String *execute_method(Value& aself, 
                    206:                const Method& method, bool return_cstr=true);
                    207:        const String *execute_virtual_method(Value& aself, 
                    208:                const String& method_name, bool return_cstr=true);
1.93      parser    209:        const String *execute_nonvirtual_method(VStateless_class& aclass, 
1.92      parser    210:                const String& method_name, bool return_cstr=true);
1.9       paf       211: 
                    212:        Value *get_element();
1.22      paf       213: 
                    214: private: // lang&raw 
                    215:        
1.39      paf       216:        String::Untaint_lang flang;
1.58      paf       217: 
                    218: private: // defaults
                    219: 
                    220:        const String::Untaint_lang fdefault_lang;
1.68      paf       221:        Value *default_content_type;
1.80      paf       222: 
                    223: private: // mime types
                    224: 
                    225:        /// $MAIN:MIME-TYPES
                    226:        Table *mime_types;
1.22      paf       227: 
1.39      paf       228: private: // lang manipulation
1.22      paf       229: 
1.39      paf       230:        String::Untaint_lang set_lang(String::Untaint_lang alang) {
                    231:                String::Untaint_lang result=flang;
                    232:                flang=alang;
                    233:                return result;
                    234:        }
                    235:        void restore_lang(String::Untaint_lang alang) {
                    236:                flang=alang;
                    237:        }
                    238: 
1.59      paf       239: private:
                    240: 
1.75      paf       241:        void output_result(const VFile& body_file, bool header_only);
1.39      paf       242: };
                    243: 
1.61      paf       244: ///    Auto-object used for temporary changing Request::flang.
1.39      paf       245: class Temp_lang {
                    246:        Request& frequest;
                    247:        String::Untaint_lang saved_lang;
                    248: public:
                    249:        Temp_lang(Request& arequest, String::Untaint_lang alang) : 
                    250:                frequest(arequest),
                    251:                saved_lang(arequest.set_lang(alang)) {
                    252:        }
                    253:        ~Temp_lang() { 
                    254:                frequest.restore_lang(saved_lang); 
                    255:        }
1.91      parser    256: };
                    257: 
                    258: /**
                    259:        @b method parameters passed in this array.
                    260:        contains handy typecast ad junction/not junction ensurers
                    261: 
                    262: */
                    263: class MethodParams : public Array {
                    264: public:
                    265:        MethodParams(Pool& pool, const String& amethod_name) : Array(pool),
                    266:                fmethod_name(amethod_name) {
                    267:        }
                    268: 
                    269:        /// handy typecast. I long for templates
                    270:        Value& get(int index) { 
                    271:                return *static_cast<Value *>(Array::get(index)); 
                    272:        }
                    273:        /// handy is-value-a-junction ensurer
                    274:        Value& as_junction(int index, const char *msg) { 
                    275:                return get_as(index, true, msg); 
                    276:        }
                    277:        /// handy value-is-not-a-junction ensurer
                    278:        Value& as_no_junction(int index, const char *msg) { 
                    279:                return get_as(index, false, msg); 
                    280:        }
                    281:        /// handy expression auto-processing to double
                    282:        double as_double(int index, Request& r) { 
                    283:                return get_processed(index, r).as_double(); 
                    284:        }
                    285:        /// handy expression auto-processing to int
                    286:        int as_int(int index, Request& r) { 
                    287:                return get_processed(index, r).as_int(); 
                    288:        }
                    289:        /// handy string ensurer
                    290:        const String& as_string(int index, const char *msg) { 
                    291:                return as_no_junction(index, msg).as_string(); 
                    292:        }
                    293: 
                    294: private:
                    295: 
                    296:        /// handy value-is/not-a-junction ensurer
                    297:        Value& get_as(int index, bool as_junction, const char *msg) { 
                    298:                Value& result=get(index);
                    299:                if((result.get_junction()!=0) ^ as_junction)
                    300:                        THROW(0, 0,
                    301:                                &fmethod_name,
                    302:                                "%s (parameter #%d)", msg, 1+index);
                    303:                return result;
                    304:        }
                    305: 
                    306:        Value& get_processed(int index, Request& r) {
                    307:                return r.process(get(index),
                    308:                        0/*no name*/,
                    309:                        false/*don't intercept string*/);
                    310:        }
                    311: 
                    312: private:
                    313: 
                    314:        const String& fmethod_name;
                    315: 
1.4       paf       316: };
1.1       paf       317: 
                    318: #endif

E-mail: