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