Annotation of parser3/src/include/pa_request.h, revision 1.99
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.99 ! parser 7: $Id: pa_request.h,v 1.98 2001/09/26 10:32:25 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.99 ! parser 29: #ifdef XML
! 30: # include <util/XercesDefs.hpp>
! 31: # include <util/PlatformUtils.hpp>
! 32: # include <util/TransENameMap.hpp>
! 33: # include <util/XML256TableTranscoder.hpp>
! 34: #endif
! 35:
1.7 paf 36: #ifndef NO_STRING_ORIGIN
1.40 paf 37: # define COMPILE_PARAMS \
38: const char *source, \
1.46 paf 39: VStateless_class *aclass, const String *name, \
40: VStateless_class *base_class, \
1.40 paf 41: const char *file
42: # define COMPILE(source, aclass, name, base_class, file) \
43: real_compile(source, aclass, name, base_class, file)
1.7 paf 44: #else
1.40 paf 45: # define COMPILE_PARAMS \
46: const char *source, \
1.46 paf 47: VStateless_class *aclass, const String *name, \
48: VStateless_class *base_class
1.40 paf 49: # define COMPILE(source, aclass, name, base_class, file) \
50: real_compile(source, aclass, name, base_class)
1.7 paf 51: #endif
1.4 paf 52:
1.39 paf 53: class Temp_lang;
1.84 paf 54: class Methoded;
1.1 paf 55:
1.61 paf 56: /// Main workhorse.
1.7 paf 57: class Request : public Pooled {
1.39 paf 58: friend Temp_lang;
1.1 paf 59: public:
1.61 paf 60:
61: /// some information from web server
1.65 paf 62: class Info {
63: public:
1.53 paf 64: const char *document_root;
65: const char *path_translated;
1.56 paf 66: const char *method;
1.53 paf 67: const char *query_string;
1.56 paf 68: const char *uri;
1.53 paf 69: const char *content_type;
70: size_t content_length;
1.60 paf 71: const char *cookie;
1.71 paf 72: const char *user_agent;
1.53 paf 73: };
74:
1.50 paf 75: Request(Pool& apool,
1.53 paf 76: Info& ainfo,
1.63 paf 77: String::Untaint_lang adefault_lang ///< all tainted data default untainting lang
1.50 paf 78: );
1.3 paf 79: ~Request() {}
1.1 paf 80:
1.61 paf 81: /// global classes
1.6 paf 82: Hash& classes() { return fclasses; }
83:
1.65 paf 84: /**
85: core request processing
86:
87: BEWARE: may throw exception to you: catch it!
88: */
89: void core(
1.95 parser 90: const char *root_config_filespec, ///< system config filespec
91: bool root_config_fail_on_read_problem, ///< fail if system config file not found
92: const char *site_config_filespec, ///< site config filespec
93: bool site_config_fail_on_read_problem, ///< fail if site config file not found
1.65 paf 94: bool header_only);
1.17 paf 95:
1.61 paf 96: /// executes ops
1.89 parser 97: void execute(const Array& ops); // execute.C
1.40 paf 98:
1.64 paf 99: /// compiles the file, maybe forcing it's class @a name and @a base_class.
1.46 paf 100: VStateless_class *use_file(
1.94 parser 101: const String& file_name,
102: bool ignore_class_path=false, bool fail_on_read_problem=true,
1.45 paf 103: const String *name=0,
1.46 paf 104: VStateless_class *base_class=0); // core.C
1.64 paf 105: /// compiles a @a source buffer
1.46 paf 106: VStateless_class *use_buf(
1.40 paf 107: const char *source, const char *file,
1.46 paf 108: VStateless_class *aclass=0, const String *name=0,
109: VStateless_class *base_class=0); // core.C
1.64 paf 110: /// processes any code-junction there may be inside of @a value
1.40 paf 111: Value& process(
1.33 paf 112: Value& value,
1.37 paf 113: const String *name=0,
1.38 paf 114: bool intercept_string=true); // execute.C
1.28 paf 115:
1.61 paf 116: /// appending, sure of clean string inside
1.65 paf 117: void write_no_lang(const String& astring) {
1.74 paf 118: wcontext->write(astring, String::UL_CLEAN);
1.49 paf 119: }
1.61 paf 120: /// appending string, passing language built into string being written
1.65 paf 121: void write_pass_lang(const String& astring) {
122: wcontext->write(astring, String::UL_PASS_APPENDED);
1.59 paf 123: }
1.61 paf 124: /// appending possible string, assigning untaint language
1.40 paf 125: void write_assign_lang(Value& avalue) {
1.39 paf 126: wcontext->write(avalue, flang);
1.22 paf 127: }
1.61 paf 128: /// appending possible string, passing language built into string being written
1.40 paf 129: void write_pass_lang(Value& avalue) {
1.65 paf 130: wcontext->write(avalue, String::UL_PASS_APPENDED);
1.49 paf 131: }
1.61 paf 132: /// appending sure value, that would be converted to clean string
1.49 paf 133: void write_no_lang(Value& avalue) {
1.74 paf 134: wcontext->write(avalue, String::UL_CLEAN);
1.55 paf 135: }
1.61 paf 136: /// appending sure value, not VString
1.55 paf 137: void write_expr_result(Value& avalue) {
138: wcontext->write(avalue);
1.40 paf 139: }
1.22 paf 140:
1.64 paf 141: /// returns relative to @a path path to @a file
1.69 paf 142: const String& relative(const char *apath, const String& relative_name);
1.61 paf 143:
1.64 paf 144: /// returns an absolute @a path to relative @a name
1.69 paf 145: const String& absolute(const String& relative_name);
1.42 paf 146:
1.80 paf 147: /// returns the mime type of 'user_file_name_cstr'
148: const String& mime_type_of(const char *user_file_name_cstr);
149:
1.99 ! parser 150: /// PCRE character tables
! 151: unsigned char *pcre_tables();
! 152:
1.17 paf 153: public:
1.22 paf 154:
1.61 paf 155: /// info from web server
1.53 paf 156: Info& info;
1.81 paf 157: /// user's post data
158: char *post_data; size_t post_size;
1.53 paf 159:
1.78 paf 160: /// operators are methods of this class
1.84 paf 161: Methoded& OP;
1.86 paf 162: /// $env:fields
1.57 paf 163: VEnv env;
1.86 paf 164: /// $form:elements
1.57 paf 165: VForm form;
1.90 parser 166: /// $math:constants
167: VMath math;
1.86 paf 168: /// $request:elements
1.57 paf 169: VRequest request;
1.86 paf 170: /// $response:elements
1.57 paf 171: VResponse response;
1.86 paf 172: /// $cookie:elements
1.60 paf 173: VCookie cookie;
1.70 paf 174:
1.61 paf 175: /// contexts
1.22 paf 176: Value *self, *root, *rcontext;
1.61 paf 177: /// contexts
1.22 paf 178: WContext *wcontext;
1.85 paf 179:
1.86 paf 180: /// 'MAIN' class conglomerat
1.85 paf 181: VStateless_class *main_class;
1.76 paf 182:
183: /// connection
1.77 paf 184: SQL_Connection *connection;
1.87 paf 185:
186: /// classes configured data
187: Hash classes_conf;
188:
1.7 paf 189: private: // core data
1.6 paf 190:
1.89 parser 191: /// classes
1.6 paf 192: Hash fclasses;
1.67 paf 193:
1.89 parser 194: /// already used files to avoid cyclic uses
1.67 paf 195: Hash used_files;
1.6 paf 196:
1.89 parser 197: /// execution stack
1.7 paf 198: Stack stack;
1.89 parser 199:
200: /** endless execute(execute(... preventing counter
201: @see ANTI_ENDLESS_EXECUTE_RECOURSION
202: */
203: uint anti_endless_execute_recoursion;
1.7 paf 204:
1.99 ! parser 205: /// charset->pcre_tables+XML256TableTranscoder [Request_CTYPE_value]
! 206: Hash CTYPE;
! 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.99 ! parser 251: };
! 252:
! 253: /// Request::CTYPE hash value
! 254: class Request_CTYPE_value : public Pooled {
! 255: public:
! 256: /// PCRE character tables
! 257: unsigned char *pcre_tables;
! 258: #ifdef XML
! 259: /// Xalan transformer for this charset
! 260: XML256TableTranscoder *transcoder;
! 261: #endif
! 262:
! 263: Request_CTYPE_value(Pool& apool,
! 264: unsigned char * apcre_tables, XML256TableTranscoder *atranscoder) : Pooled(apool),
! 265: pcre_tables(apcre_tables), transcoder(atranscoder) {
! 266: }
1.39 paf 267: };
268:
1.61 paf 269: /// Auto-object used for temporary changing Request::flang.
1.39 paf 270: class Temp_lang {
271: Request& frequest;
272: String::Untaint_lang saved_lang;
273: public:
274: Temp_lang(Request& arequest, String::Untaint_lang alang) :
275: frequest(arequest),
276: saved_lang(arequest.set_lang(alang)) {
277: }
278: ~Temp_lang() {
279: frequest.restore_lang(saved_lang);
280: }
1.91 parser 281: };
282:
283: /**
284: @b method parameters passed in this array.
285: contains handy typecast ad junction/not junction ensurers
286:
287: */
288: class MethodParams : public Array {
289: public:
290: MethodParams(Pool& pool, const String& amethod_name) : Array(pool),
291: fmethod_name(amethod_name) {
292: }
293:
294: /// handy typecast. I long for templates
295: Value& get(int index) {
296: return *static_cast<Value *>(Array::get(index));
297: }
298: /// handy is-value-a-junction ensurer
299: Value& as_junction(int index, const char *msg) {
300: return get_as(index, true, msg);
301: }
302: /// handy value-is-not-a-junction ensurer
303: Value& as_no_junction(int index, const char *msg) {
304: return get_as(index, false, msg);
305: }
306: /// handy expression auto-processing to double
307: double as_double(int index, Request& r) {
308: return get_processed(index, r).as_double();
309: }
310: /// handy expression auto-processing to int
311: int as_int(int index, Request& r) {
312: return get_processed(index, r).as_int();
313: }
314: /// handy string ensurer
315: const String& as_string(int index, const char *msg) {
316: return as_no_junction(index, msg).as_string();
317: }
318:
319: private:
320:
321: /// handy value-is/not-a-junction ensurer
322: Value& get_as(int index, bool as_junction, const char *msg) {
323: Value& result=get(index);
324: if((result.get_junction()!=0) ^ as_junction)
325: THROW(0, 0,
326: &fmethod_name,
327: "%s (parameter #%d)", msg, 1+index);
328: return result;
329: }
330:
331: Value& get_processed(int index, Request& r) {
332: return r.process(get(index),
333: 0/*no name*/,
334: false/*don't intercept string*/);
335: }
336:
337: private:
338:
339: const String& fmethod_name;
340:
1.4 paf 341: };
1.1 paf 342:
343: #endif
E-mail: