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