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

1.1       paf         1: /*
1.32      paf         2:        Parser
                      3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.36      paf         4:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.32      paf         5: 
1.60    ! paf         6:        $Id: pa_request.h,v 1.59 2001/03/18 14:45:26 paf Exp $
1.1       paf         7: */
                      8: 
                      9: #ifndef PA_REQUEST_H
                     10: #define PA_REQUEST_H
                     11: 
                     12: #include "pa_pool.h"
1.5       paf        13: #include "pa_hash.h"
1.7       paf        14: #include "pa_wcontext.h"
1.6       paf        15: #include "pa_value.h"
1.7       paf        16: #include "pa_stack.h"
1.12      paf        17: #include "pa_vclass.h"
1.45      paf        18: #include "pa_vobject.h"
1.47      paf        19: #include "pa_venv.h"
1.48      paf        20: #include "pa_vform.h"
1.56      paf        21: #include "pa_vrequest.h"
1.57      paf        22: #include "pa_vresponse.h"
1.60    ! paf        23: #include "pa_vcookie.h"
1.44      paf        24: 
1.7       paf        25: #ifndef NO_STRING_ORIGIN
1.40      paf        26: #      define COMPILE_PARAMS  \
                     27:                const char *source, \
1.46      paf        28:                VStateless_class *aclass, const String *name, \
                     29:                VStateless_class *base_class, \
1.40      paf        30:                const char *file
                     31: #      define COMPILE(source, aclass, name, base_class, file)  \
                     32:                real_compile(source, aclass, name, base_class, file)
1.7       paf        33: #else
1.40      paf        34: #      define COMPILE_PARAMS  \
                     35:                const char *source, \
1.46      paf        36:                VStateless_class *aclass, const String *name, \
                     37:                VStateless_class *base_class
1.40      paf        38: #      define COMPILE(source, aclass, name, base_class, file)  \
                     39:                real_compile(source, aclass, name, base_class)
1.7       paf        40: #endif
1.4       paf        41: 
1.39      paf        42: class Temp_lang;
1.1       paf        43: 
1.7       paf        44: class Request : public Pooled {
1.39      paf        45:        friend Temp_lang;
1.1       paf        46: public:
                     47:        
1.53      paf        48:        struct Info {
                     49:                const char *document_root;
                     50:                const char *path_translated;
1.56      paf        51:                const char *method;
1.53      paf        52:                const char *query_string;
1.56      paf        53:                const char *uri;
1.53      paf        54:                const char *content_type;
                     55:                size_t content_length;
1.60    ! paf        56:                const char *cookie;
1.53      paf        57:        };
                     58:        
1.50      paf        59:        Request(Pool& apool,
1.53      paf        60:                Info& ainfo,
1.58      paf        61:                String::Untaint_lang adefault_lang
1.50      paf        62:        );
1.3       paf        63:        ~Request() {}
1.1       paf        64: 
1.7       paf        65:        // global classes
1.6       paf        66:        Hash& classes() { return fclasses; }
                     67: 
                     68:        // core request processing
1.57      paf        69:        void core(Exception& system_exception,
1.51      paf        70:                const char *sys_auto_path1,
                     71:                const char *sys_auto_path2);
1.17      paf        72: 
1.40      paf        73:        void execute(const Array& ops);
                     74: 
1.46      paf        75:        VStateless_class *use_file(
1.40      paf        76:                const char *file, bool fail_on_read_problem=true,
1.45      paf        77:                const String *name=0, 
1.46      paf        78:                VStateless_class *base_class=0); // core.C
                     79:        VStateless_class *use_buf(
1.40      paf        80:                const char *source, const char *file,
1.46      paf        81:                VStateless_class *aclass=0, const String *name=0, 
                     82:                VStateless_class *base_class=0); // core.C
1.40      paf        83:        Value& process(
1.33      paf        84:                Value& value, 
1.37      paf        85:                const String *name=0,
1.38      paf        86:                bool intercept_string=true); // execute.C
1.28      paf        87: 
1.55      paf        88:        // write(const) = clean
1.28      paf        89:        void write(const String& astring) {
1.55      paf        90:                wcontext->write(astring, String::Untaint_lang::NO);
1.28      paf        91:        }
1.55      paf        92:        // appending, sure of clean string inside
1.49      paf        93:        void write_no_lang(String& astring) {
                     94:                wcontext->write(astring, String::Untaint_lang::NO);
                     95:        }
1.59      paf        96:        // appending string, passing language built into string being written
                     97:        void write_pass_lang(String& astring) {
1.60    ! paf        98:                wcontext->write(astring, String::Untaint_lang::PASS_APPENDED); 
1.59      paf        99:        }
1.55      paf       100:        // appending possible string, assigning untaint language
1.40      paf       101:        void write_assign_lang(Value& avalue) {
1.39      paf       102:                wcontext->write(avalue, flang); 
1.22      paf       103:        }
1.55      paf       104:        // appending possible string, passing language built into string being written
1.40      paf       105:        void write_pass_lang(Value& avalue) {
1.60    ! paf       106:                wcontext->write(avalue, String::Untaint_lang::PASS_APPENDED); 
1.49      paf       107:        }
1.55      paf       108:        // appending sure value, that would be converted to clean string
1.49      paf       109:        void write_no_lang(Value& avalue) {
1.55      paf       110:                wcontext->write(avalue, String::Untaint_lang::NO);
                    111:        }
                    112:        // appending sure value, not VString
                    113:        void write_expr_result(Value& avalue) {
                    114:                wcontext->write(avalue); 
1.40      paf       115:        }
1.43      paf       116: 
                    117:        void fail_if_junction_(bool is, Value& value, const String& method_name, char *msg);
1.22      paf       118: 
1.42      paf       119:        char *relative(const char *path, const char *file);
                    120:        char *absolute(const char *name);
                    121: 
1.17      paf       122: public:
1.22      paf       123:        
1.53      paf       124:        //
                    125:        Info& info;
                    126: 
1.22      paf       127:        // default base
1.57      paf       128:        VClass ROOT;
1.48      paf       129:        // $env:fields here
1.57      paf       130:        VEnv env;
1.48      paf       131:        // $form:elements here
1.57      paf       132:        VForm form;
1.56      paf       133:        // $request:elements here
1.57      paf       134:        VRequest request;
                    135:        // $response:
                    136:        VResponse response;
1.60    ! paf       137:        // $cookie:
        !           138:        VCookie cookie;
1.17      paf       139: 
1.22      paf       140:        // contexts
                    141:        Value *self, *root, *rcontext;
                    142:        WContext *wcontext;
1.6       paf       143: 
1.7       paf       144: private: // core data
1.6       paf       145: 
                    146:        // classes
                    147:        Hash fclasses;
                    148: 
1.7       paf       149:        // execution stack
                    150:        Stack stack;
                    151: 
                    152: private: // compile.C
                    153: 
1.46      paf       154:        VStateless_class& real_compile(COMPILE_PARAMS);
1.7       paf       155: 
                    156: private: // execute.C
                    157: 
1.57      paf       158:        const String *execute_method(Value& aself, const Method& method, 
                    159:                bool return_cstr=true);
                    160:        const String *execute_method(Value& aself, const String& method_name, 
                    161:                bool return_cstr=true);
1.9       paf       162: 
                    163:        Value *get_element();
1.22      paf       164: 
                    165: private: // lang&raw 
                    166:        
1.39      paf       167:        String::Untaint_lang flang;
1.58      paf       168: 
                    169: private: // defaults
                    170: 
                    171:        const String::Untaint_lang fdefault_lang;
                    172:        Value *fdefault_content_type;
1.22      paf       173: 
1.39      paf       174: private: // lang manipulation
1.22      paf       175: 
1.39      paf       176:        String::Untaint_lang set_lang(String::Untaint_lang alang) {
                    177:                String::Untaint_lang result=flang;
                    178:                flang=alang;
                    179:                return result;
                    180:        }
                    181:        void restore_lang(String::Untaint_lang alang) {
                    182:                flang=alang;
                    183:        }
                    184: 
1.59      paf       185: private:
                    186: 
                    187:        void output_result(const String& body_string);
1.39      paf       188: };
                    189: 
                    190: class Temp_lang {
                    191:        Request& frequest;
                    192:        String::Untaint_lang saved_lang;
                    193: public:
                    194:        Temp_lang(Request& arequest, String::Untaint_lang alang) : 
                    195:                frequest(arequest),
                    196:                saved_lang(arequest.set_lang(alang)) {
                    197:        }
                    198:        ~Temp_lang() { 
                    199:                frequest.restore_lang(saved_lang); 
                    200:        }
1.4       paf       201: };
1.1       paf       202: 
                    203: #endif

E-mail: