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