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

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.64.2.2! paf         8:        $Id: pa_request.h,v 1.64.2.1 2001/03/20 17:21:51 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.44      paf        26: 
1.7       paf        27: #ifndef NO_STRING_ORIGIN
1.40      paf        28: #      define COMPILE_PARAMS  \
                     29:                const char *source, \
1.46      paf        30:                VStateless_class *aclass, const String *name, \
                     31:                VStateless_class *base_class, \
1.40      paf        32:                const char *file
                     33: #      define COMPILE(source, aclass, name, base_class, file)  \
                     34:                real_compile(source, aclass, name, base_class, file)
1.7       paf        35: #else
1.40      paf        36: #      define COMPILE_PARAMS  \
                     37:                const char *source, \
1.46      paf        38:                VStateless_class *aclass, const String *name, \
                     39:                VStateless_class *base_class
1.40      paf        40: #      define COMPILE(source, aclass, name, base_class, file)  \
                     41:                real_compile(source, aclass, name, base_class)
1.7       paf        42: #endif
1.4       paf        43: 
1.39      paf        44: class Temp_lang;
1.1       paf        45: 
1.61      paf        46: /// Main workhorse.
1.7       paf        47: class Request : public Pooled {
1.39      paf        48:        friend Temp_lang;
1.1       paf        49: public:
1.61      paf        50: 
                     51:        /// some information from web server
1.53      paf        52:        struct Info {
                     53:                const char *document_root;
                     54:                const char *path_translated;
1.56      paf        55:                const char *method;
1.53      paf        56:                const char *query_string;
1.56      paf        57:                const char *uri;
1.53      paf        58:                const char *content_type;
                     59:                size_t content_length;
1.60      paf        60:                const char *cookie;
1.53      paf        61:        };
                     62:        
1.50      paf        63:        Request(Pool& apool,
1.53      paf        64:                Info& ainfo,
1.63      paf        65:                String::Untaint_lang adefault_lang ///< all tainted data default untainting lang
1.50      paf        66:        );
1.3       paf        67:        ~Request() {}
1.1       paf        68: 
1.61      paf        69:        /// global classes
1.6       paf        70:        Hash& classes() { return fclasses; }
                     71: 
1.61      paf        72:        /// core request processing
1.57      paf        73:        void core(Exception& system_exception,
1.51      paf        74:                const char *sys_auto_path1,
                     75:                const char *sys_auto_path2);
1.17      paf        76: 
1.61      paf        77:        /// executes ops
1.40      paf        78:        void execute(const Array& ops);
                     79: 
1.64      paf        80:        /// compiles the file, maybe forcing it's class @a name and @a base_class.
1.46      paf        81:        VStateless_class *use_file(
1.40      paf        82:                const char *file, bool fail_on_read_problem=true,
1.45      paf        83:                const String *name=0, 
1.46      paf        84:                VStateless_class *base_class=0); // core.C
1.64      paf        85:        /// compiles a @a source buffer
1.46      paf        86:        VStateless_class *use_buf(
1.40      paf        87:                const char *source, const char *file,
1.46      paf        88:                VStateless_class *aclass=0, const String *name=0, 
                     89:                VStateless_class *base_class=0); // core.C
1.64      paf        90:        /// processes any code-junction there may be inside of @a value
1.40      paf        91:        Value& process(
1.33      paf        92:                Value& value, 
1.37      paf        93:                const String *name=0,
1.38      paf        94:                bool intercept_string=true); // execute.C
1.28      paf        95: 
1.61      paf        96:        /// appending, sure of clean string inside
1.64.2.2! paf        97:        void write_no_lang(const String& astring) {
1.64.2.1  paf        98:                wcontext->write(astring, String::UL_NO);
1.49      paf        99:        }
1.61      paf       100:        /// appending string, passing language built into string being written
1.64.2.2! paf       101:        void write_pass_lang(const String& astring) {
1.64.2.1  paf       102:                wcontext->write(astring, String::UL_PASS_APPENDED); 
1.59      paf       103:        }
1.61      paf       104:        /// appending possible string, assigning untaint language
1.40      paf       105:        void write_assign_lang(Value& avalue) {
1.39      paf       106:                wcontext->write(avalue, flang); 
1.22      paf       107:        }
1.61      paf       108:        /// appending possible string, passing language built into string being written
1.40      paf       109:        void write_pass_lang(Value& avalue) {
1.64.2.1  paf       110:                wcontext->write(avalue, String::UL_PASS_APPENDED); 
1.49      paf       111:        }
1.61      paf       112:        /// appending sure value, that would be converted to clean string
1.49      paf       113:        void write_no_lang(Value& avalue) {
1.64.2.1  paf       114:                wcontext->write(avalue, String::UL_NO);
1.55      paf       115:        }
1.61      paf       116:        /// appending sure value, not VString
1.55      paf       117:        void write_expr_result(Value& avalue) {
                    118:                wcontext->write(avalue); 
1.40      paf       119:        }
1.43      paf       120: 
1.61      paf       121:        /// handy is-value-a-junction ensurer
1.64.2.2! paf       122:        void fail_if_junction_(bool is, Value& value, 
        !           123:                const String& method_name, const char *msg);
1.22      paf       124: 
1.64      paf       125:        /// returns relative to @a path  path to @a file 
1.42      paf       126:        char *relative(const char *path, const char *file);
1.61      paf       127: 
1.64      paf       128:        /// returns an absolute @a path to relative @a name
1.42      paf       129:        char *absolute(const char *name);
                    130: 
1.17      paf       131: public:
1.22      paf       132:        
1.61      paf       133:        /// info from web server
1.53      paf       134:        Info& info;
                    135: 
1.61      paf       136:        /// default base
1.57      paf       137:        VClass ROOT;
1.61      paf       138:        /// $env:fields here
1.57      paf       139:        VEnv env;
1.61      paf       140:        /// $form:elements here
1.57      paf       141:        VForm form;
1.61      paf       142:        /// $request:elements here
1.57      paf       143:        VRequest request;
1.61      paf       144:        /// $response:
1.57      paf       145:        VResponse response;
1.61      paf       146:        /// $cookie:
1.60      paf       147:        VCookie cookie;
1.17      paf       148: 
1.61      paf       149:        /// contexts
1.22      paf       150:        Value *self, *root, *rcontext;
1.61      paf       151:        /// contexts
1.22      paf       152:        WContext *wcontext;
1.6       paf       153: 
1.7       paf       154: private: // core data
1.6       paf       155: 
                    156:        // classes
                    157:        Hash fclasses;
                    158: 
1.7       paf       159:        // execution stack
                    160:        Stack stack;
                    161: 
                    162: private: // compile.C
                    163: 
1.46      paf       164:        VStateless_class& real_compile(COMPILE_PARAMS);
1.7       paf       165: 
                    166: private: // execute.C
                    167: 
1.57      paf       168:        const String *execute_method(Value& aself, const Method& method, 
                    169:                bool return_cstr=true);
                    170:        const String *execute_method(Value& aself, const String& method_name, 
                    171:                bool return_cstr=true);
1.9       paf       172: 
                    173:        Value *get_element();
1.22      paf       174: 
                    175: private: // lang&raw 
                    176:        
1.39      paf       177:        String::Untaint_lang flang;
1.58      paf       178: 
                    179: private: // defaults
                    180: 
                    181:        const String::Untaint_lang fdefault_lang;
                    182:        Value *fdefault_content_type;
1.22      paf       183: 
1.39      paf       184: private: // lang manipulation
1.22      paf       185: 
1.39      paf       186:        String::Untaint_lang set_lang(String::Untaint_lang alang) {
                    187:                String::Untaint_lang result=flang;
                    188:                flang=alang;
                    189:                return result;
                    190:        }
                    191:        void restore_lang(String::Untaint_lang alang) {
                    192:                flang=alang;
                    193:        }
                    194: 
1.59      paf       195: private:
                    196: 
                    197:        void output_result(const String& body_string);
1.39      paf       198: };
                    199: 
1.61      paf       200: ///    Auto-object used for temporary changing Request::flang.
1.39      paf       201: class Temp_lang {
                    202:        Request& frequest;
                    203:        String::Untaint_lang saved_lang;
                    204: public:
                    205:        Temp_lang(Request& arequest, String::Untaint_lang alang) : 
                    206:                frequest(arequest),
                    207:                saved_lang(arequest.set_lang(alang)) {
                    208:        }
                    209:        ~Temp_lang() { 
                    210:                frequest.restore_lang(saved_lang); 
                    211:        }
1.4       paf       212: };
1.1       paf       213: 
                    214: #endif

E-mail: