Annotation of parser3/src/include/pa_request.h, revision 1.160.2.37.2.3
1.61 paf 1: /** @file
1.62 paf 2: Parser: request class decl.
3:
1.160.2.9 paf 4: Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
1.121 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 paf 6: */
7:
8: #ifndef PA_REQUEST_H
9: #define PA_REQUEST_H
1.141 paf 10:
1.160.2.37.2. (paf 11:): static const char* IDENT_REQUEST_H="$Date: 2003/03/20 08:11:13 $";
1.1 paf 12:
1.160.2.5 paf 13: #include "pa_request_info.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.160.2.6 paf 18: #include "pa_request_info.h"
19: #include "pa_request_charsets.h"
1.160.2.8 paf 20: #include "pa_sapi.h"
1.44 paf 21:
1.112 paf 22: #ifdef RESOURCES_DEBUG
23: #include <sys/resource.h>
24: #endif
25:
1.128 paf 26: // consts
27:
1.160.2.35 paf 28: const uint ANTI_ENDLESS_EXECUTE_RECOURSION=1000;
1.128 paf 29:
1.160.2.8 paf 30: // forwards
31:
1.39 paf 32: class Temp_lang;
1.84 paf 33: class Methoded;
1.116 paf 34: class VMethodFrame;
1.160.2.30 paf 35: class GdomeDOMString_auto_ptr;
1.160.2.32 paf 36: class VMail; DECLARE_OBJECT_PTR(VMail);
1.160.2.33 paf 37: class VForm; DECLARE_OBJECT_PTR(VForm);
38: class VResponse; DECLARE_OBJECT_PTR(VResponse);
39: class VCookie; DECLARE_OBJECT_PTR(VCookie);
1.160.2.34 paf 40: class VStateless_class; DECLARE_OBJECT_PTR(VStateless_class);
1.1 paf 41:
1.61 paf 42: /// Main workhorse.
1.160.2.6 paf 43: class Request: public PA_Object {
1.107 paf 44: friend class Temp_lang;
1.117 paf 45: friend class Temp_connection;
1.148 paf 46: friend class Request_context_saver;
1.155 paf 47: friend class Temp_request_self;
1.160.2.6 paf 48:
1.160.2.7 paf 49: ///@{ core data
50:
51: /// classes
1.160.2.8 paf 52: HashStringValue fclasses;
1.160.2.7 paf 53:
54: /// already used files to avoid cyclic uses
1.160.2.37.2. (paf 55:): Hash<String* , bool> used_files;
1.160.2.7 paf 56:
57: /** endless execute(execute(... preventing counter
58: @see ANTI_ENDLESS_EXECUTE_RECOURSION
59: */
60: uint anti_endless_execute_recoursion;
61:
62: ///@}
63:
64: public:
1.160.2.12 paf 65:
1.160.2.37.2. (paf 66:): union StackItem {
67:): const String& string() const { return *value->get_string(); }
68:): Value* value;
69:): ArrayOperation* ops;
70:): // void *ptr;
1.160.2.12 paf 71:
72: /// needed to fill unused Array entries
73: StackItem() {}
1.160.2.37.2. (paf 74:): StackItem(Value* avalue): value(avalue) {}
75:): StackItem(ArrayOperation* aops): ops(aops) {}
76:): // StackItem(void *aptr): ptr(aptr) {}
1.160.2.12 paf 77: };
78:
1.160.2.6 paf 79: //@{ request processing status
80: /// exception stack trace
1.160.2.37.2. (paf 81:): Stack<String*> exception_trace;
1.160.2.6 paf 82: /// execution stack
1.160.2.12 paf 83: Stack<StackItem> stack;
1.160.2.6 paf 84: /// contexts
1.160.2.37.2. (paf 85:): VMethodFrame* method_frame;
86:): Value* rcontext;
87:): WContext* wcontext;
1.160.2.6 paf 88: /// current language
1.160.2.37.2. (paf 89:): String::Language flang;
1.160.2.6 paf 90: /// current connection
1.160.2.37.2. (paf 91:): SQL_Connection* fconnection;
1.160.2.6 paf 92: //@}
93: /// interrupted flag, raised on signals [SIGPIPE]
94: bool finterrupted;
95:
1.1 paf 96: public:
1.112 paf 97:
98: #ifdef RESOURCES_DEBUG
99: /// measures
100: double sql_connect_time;
101: double sql_request_time;
102: #endif
1.61 paf 103:
1.160.2.37.2. (paf 104:): Request(SAPI_Info& asapi_info, Request_info& arequest_info,
105:): String::Language adefault_lang, ///< all tainted data default untainting lang
1.110 paf 106: bool status_allowed ///< status class allowed
1.50 paf 107: );
1.118 paf 108: ~Request();
1.1 paf 109:
1.61 paf 110: /// global classes
1.160.2.8 paf 111: HashStringValue& classes() { return fclasses; }
1.6 paf 112:
1.65 paf 113: /**
114: core request processing
115:
116: BEWARE: may throw exception to you: catch it!
117: */
118: void core(
1.160.2.9 paf 119: const char* config_filespec, ///< system config filespec
1.138 paf 120: bool config_fail_on_read_problem, ///< fail if system config file not found
1.65 paf 121: bool header_only);
1.17 paf 122:
1.61 paf 123: /// executes ops
1.160.2.12 paf 124: void execute(ArrayOperation& ops); // execute.C
1.127 paf 125: /// execute ops with anti-recoursion check
1.160.2.37.2. (paf 126:): void recoursion_checked_execute(const String& name, ArrayOperation& ops) {
1.128 paf 127: // anti_endless_execute_recoursion
128: if(++anti_endless_execute_recoursion==ANTI_ENDLESS_EXECUTE_RECOURSION) {
129: anti_endless_execute_recoursion=0; // give @exception a chance
130: throw Exception("parser.runtime",
1.160.2.37.2. (paf 131:): &name,
1.128 paf 132: "call canceled - endless recursion detected");
133: }
1.147 paf 134: execute(ops); // execute it
1.128 paf 135: anti_endless_execute_recoursion--;
136: }
1.40 paf 137:
1.64 paf 138: /// compiles the file, maybe forcing it's class @a name and @a base_class.
1.160.2.37 paf 139: void use_file(VStateless_class& aclass,
1.160.2.37.2. (paf 140:): const String& file_name,
1.149 paf 141: bool ignore_class_path=false,
1.160.2.8 paf 142: bool fail_on_read_problem=true, bool fail_on_file_absence=true); // pa_request.C
1.64 paf 143: /// compiles a @a source buffer
1.160.2.37 paf 144: void use_buf(VStateless_class& aclass,
1.160.2.9 paf 145: const char* source,
1.160.2.37.2. (paf 146:): const String& filespec, const char* filespec_cstr); // pa_request.C
1.28 paf 147:
1.129 paf 148: /// processes any code-junction there may be inside of @a value
1.160.2.37.2. (paf 149:): StringOrValue process(Value* input_value, bool intercept_string=true); // execute.C
1.129 paf 150: //@{ convinient helpers
1.160.2.37.2. (paf 151:): const String& process_to_string(Value* input_value) {
152:): return process(input_value, true/*intercept_string*/).as_string();
1.129 paf 153: }
1.160.2.37.2. (paf 154:): Value& process_to_value(Value* input_value, bool intercept_string=true) {
1.129 paf 155: return process(input_value, intercept_string).as_value();
1.126 paf 156: }
157: //@}
1.131 paf 158:
1.126 paf 159:
1.131 paf 160: #define DEFINE_DUAL(modification) \
161: void write_##modification##_lang(StringOrValue dual) { \
1.160.2.37.2. (paf 162:): if(const String* string=dual.get_string()) \
1.132 paf 163: write_##modification##_lang(*string); \
164: else \
1.160.2.37.2. (paf 165:): write_##modification##_lang(*dual.get_value()); \
1.132 paf 166: }
1.131 paf 167:
1.61 paf 168: /// appending, sure of clean string inside
1.65 paf 169: void write_no_lang(const String& astring) {
1.111 paf 170: wcontext->write(astring,
1.160.2.37.2. (paf 171:): (String::Language)(String::L_CLEAN | flang&String::L_OPTIMIZE_BIT));
1.49 paf 172: }
1.131 paf 173: /// appending sure value, that would be converted to clean string
1.160.2.37.2. (paf 174:): void write_no_lang(Value& avalue) {
1.131 paf 175: if(wcontext->get_in_expression())
1.160.2.37.2. (paf 176:): wcontext->write(avalue);
1.131 paf 177: else
1.160.2.37.2. (paf 178:): wcontext->write(avalue,
179:): (String::Language)(String::L_CLEAN | flang&String::L_OPTIMIZE_BIT));
1.131 paf 180: }
181:
1.61 paf 182: /// appending string, passing language built into string being written
1.65 paf 183: void write_pass_lang(const String& astring) {
1.160.2.37.2. (paf 184:): wcontext->write(astring, String::L_PASS_APPENDED);
1.59 paf 185: }
1.131 paf 186: /// appending possible string, passing language built into string being written
1.160.2.37.2. (paf 187:): void write_pass_lang(Value& avalue) {
188:): wcontext->write(avalue, String::L_PASS_APPENDED);
1.131 paf 189: }
190: DEFINE_DUAL(pass)
191:
1.61 paf 192: /// appending possible string, assigning untaint language
1.160.2.37.2. (paf 193:): void write_assign_lang(Value& avalue) {
194:): wcontext->write(avalue, flang);
1.132 paf 195: }
1.106 parser 196: /// appending string, assigning untaint language
197: void write_assign_lang(const String& astring) {
198: wcontext->write(astring, flang);
1.22 paf 199: }
1.131 paf 200: DEFINE_DUAL(assign)
1.22 paf 201:
1.64 paf 202: /// returns relative to @a path path to @a file
1.160.2.37.2. (paf 203:): const String& relative(const char* apath, const String& relative_name);
1.61 paf 204:
1.64 paf 205: /// returns an absolute @a path to relative @a name
1.160.2.37.2. (paf 206:): const String& absolute(const String& relative_name);
1.42 paf 207:
1.80 paf 208: /// returns the mime type of 'user_file_name_cstr'
1.160.2.37.2. (paf 209:): const String& mime_type_of(const char* user_file_name_cstr);
1.80 paf 210:
1.117 paf 211: /// returns current SQL connection if any
1.160.2.37.2. (paf 212:): SQL_Connection* connection(const String* source) {
1.117 paf 213: if(!fconnection && source)
1.125 paf 214: throw Exception("parser.runtime",
1.117 paf 215: source,
216: "outside of 'connect' operator");
217:
218: return fconnection;
1.133 paf 219: }
220:
1.160.2.36 paf 221: void set_interrupted(bool ainterrupted) { finterrupted=ainterrupted; }
222: bool get_interrupted() { return finterrupted; }
1.158 paf 223:
1.17 paf 224: public:
1.22 paf 225:
1.61 paf 226: /// info from web server
1.160.2.8 paf 227: Request_info& request_info;
228:
229: /// info about ServerAPI
230: SAPI_Info& sapi_info;
1.160.2.2 paf 231:
232: /// source, client, mail charsets
1.160.2.6 paf 233: Request_charsets charsets;
1.53 paf 234:
1.154 paf 235: /// 'MAIN' class conglomerat & operators are methods of this class
1.160.2.37.2. (paf 236:): VStateless_class& main_class;
1.86 paf 237: /// $form:elements
1.160.2.37.2. (paf 238:): VForm& form;
1.140 paf 239: /// $mail
1.160.2.37.2. (paf 240:): VMail& mail;
1.86 paf 241: /// $response:elements
1.160.2.37.2. (paf 242:): VResponse& response;
1.86 paf 243: /// $cookie:elements
1.160.2.37.2. (paf 244:): VCookie& cookie;
1.70 paf 245:
1.148 paf 246: /// classes configured data
1.160.2.20 paf 247: HashStringObject classes_conf;
1.85 paf 248:
1.148 paf 249: public: // status read methods
1.76 paf 250:
1.148 paf 251: VMethodFrame *get_method_frame() { return method_frame; }
1.160.2.37.2. (paf 252:): Value* get_self();
1.160.2.18 paf 253: #define GET_SELF(request, type) (*static_cast<type *>(request.get_self().get()))
254: /* for strange reason call to this:
255: r.get_self<VHash>()
256: refuses to compile
257:
258: template<typename T> T& get_self() {
259: return *static_cast<T*>(get_self().get());
260: }
261: */
1.160.2.30 paf 262:
263: #ifdef XML
264: public: // charset helpers
265:
266: /// @see Charset::transcode
1.160.2.37.2. (paf 267:): GdomeDOMString_auto_ptr transcode(const String& s);
1.160.2.30 paf 268: /// @see Charset::transcode
1.160.2.37.2. (paf 269:): const String& transcode(GdomeDOMString* s
1.160.2.30 paf 270: #ifndef NO_STRING_ORIGIN
1.160.2.37.2. (paf 271:): , const String& origin
1.160.2.30 paf 272: #endif
273: );
1.160.2.31 paf 274: /// @see Charset::transcode
1.160.2.37.2. (paf 275:): const String& transcode(xmlChar* s
1.160.2.31 paf 276: #ifndef NO_STRING_ORIGIN
1.160.2.37.2. (paf 277:): , const String& origin
1.160.2.31 paf 278: #endif
279: );
280:
1.160.2.30 paf 281: #endif
1.87 paf 282:
1.136 paf 283: private:
284:
285: /// already executed some @conf method
286: bool configure_admin_done;
287:
1.160.2.37.2. (paf 288:): void configure_admin(VStateless_class& conf_class, const String* source);
1.99 parser 289:
1.7 paf 290: private: // compile.C
291:
1.160.2.37.2. (paf 292:): VStateless_class& real_compile(VStateless_class* aclass, const char* source, const char* file);
1.7 paf 293:
294: private: // execute.C
295:
1.139 paf 296: /// for @postprocess[body]
1.160.2.37.2. (paf 297:): const String& execute_method(VMethodFrame& amethodFrame, const Method& method);
1.139 paf 298: //{ for @conf[filespec] and @auto[filespec]
1.160.2.37.2. (paf 299:): const String& execute_method(Value* aself,
300:): const Method& method, const VString& optional_param,
1.160.2.10 paf 301: bool do_return_string);
1.160.2.25 paf 302: struct Execute_nonvirtual_method_result {
1.160.2.37.2. (paf 303:): const String& string;
304:): Method* method;
1.160.2.25 paf 305: };
306: Execute_nonvirtual_method_result execute_nonvirtual_method(VStateless_class& aclass,
1.160.2.37.2. (paf 307:): const String& method_name, const VString& optional_param,
1.160.2.25 paf 308: bool do_return_string);
1.139 paf 309: //}
310: /// for @main[]
1.160.2.37.2. (paf 311:): const String& execute_virtual_method(Value* aself, const String& method_name);
1.9 paf 312:
1.160.2.37.2. (paf 313:): Value* get_element(String* & remember_name, bool can_call_operator);
1.22 paf 314:
1.58 paf 315: private: // defaults
316:
1.160.2.37.2. (paf 317:): const String::Language fdefault_lang;
1.80 paf 318:
319: private: // mime types
320:
321: /// $MAIN:MIME-TYPES
322: Table *mime_types;
1.22 paf 323:
1.39 paf 324: private: // lang manipulation
1.22 paf 325:
1.160.2.37.2. (paf 326:): String::Language set_lang(String::Language alang) {
327:): String::Language result=flang;
1.39 paf 328: flang=alang;
329: return result;
330: }
1.160.2.37.2. (paf 331:): void restore_lang(String::Language alang) {
1.39 paf 332: flang=alang;
333: }
334:
1.117 paf 335: private: // connection manipulation
336:
1.160.2.37.2. (paf 337:): SQL_Connection* set_connection(SQL_Connection* aconnection) {
338:): SQL_Connection* result=fconnection;
1.117 paf 339: fconnection=aconnection;
340: return result;
341: }
1.160.2.37.2. (paf 342:): void restore_connection(SQL_Connection* aconnection) {
1.117 paf 343: fconnection=aconnection;
344: }
345:
346: private:
347:
1.160.2.37.2. (paf 348:): void output_result(VFile* body_file, bool header_only, bool as_attachment);
1.148 paf 349: };
350:
351: /// Auto-object used to save request context across ^try body
352: class Request_context_saver {
353: Request& fr;
354:
355: /// exception stack trace
356: int exception_trace;
357: /// execution stack
358: int stack;
359: /// contexts
360: VMethodFrame *method_frame;
361: Value *rcontext;
362: WContext *wcontext;
363: /// current language
1.160.2.37.2. (paf 364:): String::Language flang;
1.148 paf 365: /// current connection
1.160.2.37.2. (paf 366:): SQL_Connection* fconnection;
1.126 paf 367:
1.148 paf 368: public:
369: Request_context_saver(Request& ar) :
370: exception_trace(ar.exception_trace.top_index()),
371: stack(ar.stack.top_index()),
372: method_frame(ar.method_frame),
373: rcontext(ar.rcontext),
374: wcontext(ar.wcontext),
375: flang(ar.flang),
376: fconnection(ar.fconnection),
377: fr(ar) {}
1.153 paf 378: void restore() {
1.148 paf 379: fr.exception_trace.top_index(exception_trace);
380: fr.stack.top_index(stack);
1.157 paf 381: fr.method_frame=method_frame, fr.rcontext=rcontext; fr.wcontext=wcontext;
1.148 paf 382: fr.flang=flang;
383: fr.fconnection=fconnection;
384: }
1.39 paf 385: };
386:
1.61 paf 387: /// Auto-object used for temporary changing Request::flang.
1.39 paf 388: class Temp_lang {
389: Request& frequest;
1.160.2.37.2. (paf 390:): String::Language saved_lang;
1.39 paf 391: public:
1.160.2.37.2. (paf 392:): Temp_lang(Request& arequest, String::Language alang) :
1.39 paf 393: frequest(arequest),
394: saved_lang(arequest.set_lang(alang)) {
395: }
396: ~Temp_lang() {
397: frequest.restore_lang(saved_lang);
1.117 paf 398: }
399: };
400:
401: /// Auto-object used for temporary changing Request::fconnection.
402: class Temp_connection {
403: Request& frequest;
1.160.2.37.2. (paf 404:): SQL_Connection* saved_connection;
1.117 paf 405: public:
1.160.2.37.2. (paf 406:): Temp_connection(Request& arequest, SQL_Connection* aconnection) :
1.117 paf 407: frequest(arequest),
408: saved_connection(arequest.set_connection(aconnection)) {
409: }
410: ~Temp_connection() {
411: frequest.restore_connection(saved_connection);
1.39 paf 412: }
1.4 paf 413: };
1.160.2.7 paf 414:
1.160.2.15 paf 415:
416: // defines for externs
417:
418: #define CONTENT_DISPOSITION_NAME "content-disposition"
419: #define CONTENT_DISPOSITION_VALUE "attachment"
420: #define CONTENT_DISPOSITION_FILENAME_NAME "filename"
421:
1.160.2.7 paf 422: // externs
423:
1.160.2.37.2. (paf 424:): extern const String& main_method_name;
425:): extern const String& auto_method_name;
426:): extern const String& body_name;
427:): extern const String& content_disposition_name;
428:): extern const String& content_disposition_value;
429:): extern const String& content_disposition_filename_name;
1.160.2.19 paf 430:
431: // defines for statics
432:
433: #define MAIN_CLASS_NAME "MAIN"
1.160.2.21 paf 434: #define AUTO_FILE_NAME "auto.p"
1.1 paf 435:
436: #endif
E-mail: