Annotation of parser3/src/include/pa_request.h, revision 1.93
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.93 ! parser 8: $Id: pa_request.h,v 1.92 2001/07/13 12:13:50 parser Exp $
1.1 paf 9: */
10:
11: #ifndef PA_REQUEST_H
12: #define PA_REQUEST_H
13:
1.88 parser 14: #include "pa_config_includes.h"
1.1 paf 15: #include "pa_pool.h"
1.5 paf 16: #include "pa_hash.h"
1.7 paf 17: #include "pa_wcontext.h"
1.6 paf 18: #include "pa_value.h"
1.7 paf 19: #include "pa_stack.h"
1.12 paf 20: #include "pa_vclass.h"
1.45 paf 21: #include "pa_vobject.h"
1.47 paf 22: #include "pa_venv.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.39 paf 52: friend 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.63 paf 71: String::Untaint_lang adefault_lang ///< all tainted data default untainting lang
1.50 paf 72: );
1.3 paf 73: ~Request() {}
1.1 paf 74:
1.61 paf 75: /// global classes
1.6 paf 76: Hash& classes() { return fclasses; }
77:
1.65 paf 78: /**
79: core request processing
80:
81: BEWARE: may throw exception to you: catch it!
82: */
83: void core(
1.66 paf 84: const char *root_auto_path, ///< path to system auto.p file
85: bool root_auto_fail, ///< fail if system auto.p file not found
86: const char *site_auto_path, ///< path to site auto.p file
87: bool site_auto_fail, ///< fail if site auto.p file not found
1.65 paf 88: bool header_only);
1.17 paf 89:
1.61 paf 90: /// executes ops
1.89 parser 91: void execute(const Array& ops); // execute.C
1.40 paf 92:
1.64 paf 93: /// compiles the file, maybe forcing it's class @a name and @a base_class.
1.46 paf 94: VStateless_class *use_file(
1.69 paf 95: const String& file_spec, 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.17 paf 143: public:
1.22 paf 144:
1.61 paf 145: /// info from web server
1.53 paf 146: Info& info;
1.81 paf 147: /// user's post data
148: char *post_data; size_t post_size;
1.53 paf 149:
1.78 paf 150: /// operators are methods of this class
1.84 paf 151: Methoded& OP;
1.86 paf 152: /// $env:fields
1.57 paf 153: VEnv env;
1.86 paf 154: /// $form:elements
1.57 paf 155: VForm form;
1.90 parser 156: /// $math:constants
157: VMath math;
1.86 paf 158: /// $request:elements
1.57 paf 159: VRequest request;
1.86 paf 160: /// $response:elements
1.57 paf 161: VResponse response;
1.86 paf 162: /// $cookie:elements
1.60 paf 163: VCookie cookie;
1.70 paf 164:
1.61 paf 165: /// contexts
1.22 paf 166: Value *self, *root, *rcontext;
1.61 paf 167: /// contexts
1.22 paf 168: WContext *wcontext;
1.85 paf 169:
1.86 paf 170: /// 'MAIN' class conglomerat
1.85 paf 171: VStateless_class *main_class;
1.76 paf 172:
173: /// connection
1.77 paf 174: SQL_Connection *connection;
1.83 paf 175: /// PCRE character tables
176: unsigned char *pcre_tables;
1.87 paf 177:
178: /// classes configured data
179: Hash classes_conf;
180:
1.6 paf 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:
198: private: // compile.C
199:
1.46 paf 200: VStateless_class& real_compile(COMPILE_PARAMS);
1.7 paf 201:
202: private: // execute.C
203:
1.92 parser 204: const String *execute_method(Value& aself,
205: const Method& method, bool return_cstr=true);
206: const String *execute_virtual_method(Value& aself,
207: const String& method_name, bool return_cstr=true);
1.93 ! parser 208: const String *execute_nonvirtual_method(VStateless_class& aclass,
1.92 parser 209: const String& method_name, bool return_cstr=true);
1.9 paf 210:
211: Value *get_element();
1.22 paf 212:
213: private: // lang&raw
214:
1.39 paf 215: String::Untaint_lang flang;
1.58 paf 216:
217: private: // defaults
218:
219: const String::Untaint_lang fdefault_lang;
1.68 paf 220: Value *default_content_type;
1.80 paf 221:
222: private: // mime types
223:
224: /// $MAIN:MIME-TYPES
225: Table *mime_types;
1.22 paf 226:
1.39 paf 227: private: // lang manipulation
1.22 paf 228:
1.39 paf 229: String::Untaint_lang set_lang(String::Untaint_lang alang) {
230: String::Untaint_lang result=flang;
231: flang=alang;
232: return result;
233: }
234: void restore_lang(String::Untaint_lang alang) {
235: flang=alang;
236: }
237:
1.59 paf 238: private:
239:
1.75 paf 240: void output_result(const VFile& body_file, bool header_only);
1.39 paf 241: };
242:
1.61 paf 243: /// Auto-object used for temporary changing Request::flang.
1.39 paf 244: class Temp_lang {
245: Request& frequest;
246: String::Untaint_lang saved_lang;
247: public:
248: Temp_lang(Request& arequest, String::Untaint_lang alang) :
249: frequest(arequest),
250: saved_lang(arequest.set_lang(alang)) {
251: }
252: ~Temp_lang() {
253: frequest.restore_lang(saved_lang);
254: }
1.91 parser 255: };
256:
257: /**
258: @b method parameters passed in this array.
259: contains handy typecast ad junction/not junction ensurers
260:
261: */
262: class MethodParams : public Array {
263: public:
264: MethodParams(Pool& pool, const String& amethod_name) : Array(pool),
265: fmethod_name(amethod_name) {
266: }
267:
268: /// handy typecast. I long for templates
269: Value& get(int index) {
270: return *static_cast<Value *>(Array::get(index));
271: }
272: /// handy is-value-a-junction ensurer
273: Value& as_junction(int index, const char *msg) {
274: return get_as(index, true, msg);
275: }
276: /// handy value-is-not-a-junction ensurer
277: Value& as_no_junction(int index, const char *msg) {
278: return get_as(index, false, msg);
279: }
280: /// handy expression auto-processing to double
281: double as_double(int index, Request& r) {
282: return get_processed(index, r).as_double();
283: }
284: /// handy expression auto-processing to int
285: int as_int(int index, Request& r) {
286: return get_processed(index, r).as_int();
287: }
288: /// handy string ensurer
289: const String& as_string(int index, const char *msg) {
290: return as_no_junction(index, msg).as_string();
291: }
292:
293: private:
294:
295: /// handy value-is/not-a-junction ensurer
296: Value& get_as(int index, bool as_junction, const char *msg) {
297: Value& result=get(index);
298: if((result.get_junction()!=0) ^ as_junction)
299: THROW(0, 0,
300: &fmethod_name,
301: "%s (parameter #%d)", msg, 1+index);
302: return result;
303: }
304:
305: Value& get_processed(int index, Request& r) {
306: return r.process(get(index),
307: 0/*no name*/,
308: false/*don't intercept string*/);
309: }
310:
311: private:
312:
313: const String& fmethod_name;
314:
1.4 paf 315: };
1.1 paf 316:
317: #endif
E-mail: