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

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

E-mail: