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

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

E-mail: