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