Annotation of parser3/src/main/pa_request.C, revision 1.417
1.54 paf 1: /** @file
1.55 paf 2: Parser: request class main part. @see compile.C and execute.C.
3:
1.405 moko 4: Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com)
1.194 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.218 paf 6: */
1.55 paf 7:
1.69 paf 8: #include "pa_sapi.h"
1.53 paf 9: #include "pa_common.h"
1.372 moko 10: #include "pa_os.h"
1.1 paf 11: #include "pa_request.h"
1.3 paf 12: #include "pa_wwrapper.h"
13: #include "pa_vclass.h"
1.31 paf 14: #include "pa_globals.h"
1.30 paf 15: #include "pa_vint.h"
1.297 misha 16: #include "pa_vmethod_frame.h"
1.32 paf 17: #include "pa_types.h"
1.248 paf 18: #include "pa_venv.h"
19: #include "pa_vmath.h"
20: #include "pa_vstatus.h"
21: #include "pa_vrequest.h"
1.78 paf 22: #include "pa_vtable.h"
1.90 paf 23: #include "pa_vfile.h"
1.147 parser 24: #include "pa_dictionary.h"
1.208 paf 25: #include "pa_charset.h"
1.186 paf 26: #include "pa_charsets.h"
1.248 paf 27: #include "pa_cache_managers.h"
1.402 moko 28: #include "pa_http.h"
1.248 paf 29: #include "pa_vmail.h"
30: #include "pa_vform.h"
31: #include "pa_vcookie.h"
32: #include "pa_vresponse.h"
33: #include "pa_vmemory.h"
1.253 paf 34: #include "pa_vconsole.h"
1.267 paf 35: #include "pa_vdate.h"
1.159 parser 36:
1.417 ! moko 37: volatile const char * IDENT_PA_REQUEST_C="$Id: pa_request.C,v 1.416 2021/12/22 21:59:50 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H;
1.329 moko 38:
1.248 paf 39: // consts
40:
1.269 paf 41: #define UNHANDLED_EXCEPTION_METHOD_NAME "unhandled_exception"
1.207 paf 42:
1.82 paf 43: /// content type of response when no $MAIN:defaults.content-type defined
1.248 paf 44: const char* DEFAULT_CONTENT_TYPE="text/html";
45:
1.369 moko 46: const uint LOOP_LIMIT=20000;
1.361 moko 47: const uint EXECUTE_RECOURSION_LIMIT=1000;
1.390 moko 48: const uint HTTPD_TIMEOUT=4;
1.369 moko 49: const size_t FILE_SIZE_LIMIT=512*1024*1024;
1.361 moko 50:
1.248 paf 51: // defines for globals
52:
53: #define MAIN_METHOD_NAME "main"
54: #define AUTO_METHOD_NAME "auto"
1.364 moko 55: #define USE_METHOD_NAME "use"
1.309 misha 56: #define AUTOUSE_METHOD_NAME "autouse"
1.364 moko 57:
1.248 paf 58: #define EXCEPTION_TYPE_PART_NAME "type"
59: #define EXCEPTION_SOURCE_PART_NAME "source"
60: #define EXCEPTION_COMMENT_PART_NAME "comment"
61:
1.364 moko 62: #define ORIGIN_KEY "origin"
63:
1.248 paf 64: // globals
65:
66: const String main_method_name(MAIN_METHOD_NAME);
67: const String auto_method_name(AUTO_METHOD_NAME);
1.364 moko 68: static const String use_method_name(USE_METHOD_NAME);
69: static const String autouse_method_name(AUTOUSE_METHOD_NAME);
1.311 misha 70:
1.248 paf 71: const String exception_type_part_name(EXCEPTION_TYPE_PART_NAME);
72: const String exception_source_part_name(EXCEPTION_SOURCE_PART_NAME);
73: const String exception_comment_part_name(EXCEPTION_COMMENT_PART_NAME);
74: const String exception_handled_part_name(EXCEPTION_HANDLED_PART_NAME);
75:
1.364 moko 76: static const String origin_key(ORIGIN_KEY);
77:
1.369 moko 78: int pa_loop_limit=LOOP_LIMIT;
1.361 moko 79: int pa_execute_recoursion_limit=EXECUTE_RECOURSION_LIMIT;
1.390 moko 80: int pa_httpd_timeout=HTTPD_TIMEOUT;
1.369 moko 81: size_t pa_file_size_limit=FILE_SIZE_LIMIT;
1.361 moko 82:
1.248 paf 83: // defines for statics
84:
85: #define MIME_TYPES_NAME "MIME-TYPES"
86: #define CLASS_PATH_NAME "CLASS_PATH"
87:
1.344 moko 88: #define DOWNLOAD_NAME_UPPER "DOWNLOAD"
89: #define BODY_NAME_UPPER "BODY"
90:
1.248 paf 91: // statics
92:
93: static const String main_class_name(MAIN_CLASS_NAME);
94: static const String mime_types_name(MIME_TYPES_NAME);
1.395 moko 95: static const String class_path_name(CLASS_PATH_NAME);
1.361 moko 96:
1.395 moko 97: static const String charsets_name("CHARSETS");
98: static const String strict_vars_name("STRICT-VARS");
99: static const String prototype_name("OBJECT-PROTOTYPE");
1.415 moko 100: static const String getter_protected_name("CLASS-GETTER-PROTECTED");
101: static const String locals_name("LOCALS");
1.395 moko 102: static const String limits_name("LIMITS");
103: static const String loop_limit_name("max_loop");
104: static const String recoursion_limit_name("max_recoursion");
105: static const String file_size_limit_name("max_file_size");
106: static const String lock_wait_timeout_name("lock_wait_timeout");
107: static const String httpd_name("HTTPD");
108: static const String httpd_timeout_name("timeout");
1.402 moko 109: static const String httpd_mode_name("mode");
1.395 moko 110:
111: static const String conf_method_name("conf");
112: static const String post_process_method_name("postprocess");
113: static const String response_body_file_name("file");
1.248 paf 114:
1.344 moko 115: static const String download_name_upper(DOWNLOAD_NAME_UPPER);
116: static const String body_name_upper(BODY_NAME_UPPER);
117:
118: // more static
119:
120: static const String content_type_name_upper(HTTP_CONTENT_TYPE_UPPER);
121: static const String content_disposition_name_upper(CONTENT_DISPOSITION_UPPER);
1.392 moko 122: static const String content_disposition_inline(CONTENT_DISPOSITION_INLINE);
1.344 moko 123: static const String content_disposition_attachment(CONTENT_DISPOSITION_ATTACHMENT);
124:
1.248 paf 125: // defines
1.82 paf 126:
1.344 moko 127: #define CHARSET_NAME_UPPER "CHARSET"
128: #define LAST_MODIFIED_NAME_UPPER "LAST-MODIFIED"
129:
1.233 paf 130: // op.C
1.248 paf 131: VStateless_class& VClassMAIN_create();
1.123 paf 132:
1.157 parser 133: //
1.408 moko 134: Request::Request(SAPI_Info& asapi_info, Request_info& arequest_info, String::Language adefault_lang):
1.248 paf 135: // private
136: anti_endless_execute_recoursion(0),
137:
138: // public
1.335 moko 139: allow_class_replace(false),
1.248 paf 140: method_frame(0),
141: rcontext(0),
142: wcontext(0),
143: flang(adefault_lang),
1.191 paf 144: fconnection(0),
1.371 moko 145: fin_cycle(0),
1.307 misha 146: fskip(SKIP_NOTHING),
1.248 paf 147:
148: // public
1.257 paf 149: request_info(arequest_info),
1.248 paf 150: sapi_info(asapi_info),
1.359 moko 151: charsets(pa_UTF8_charset, pa_UTF8_charset, pa_UTF8_charset), // default charsets
1.248 paf 152:
153: main_class(VClassMAIN_create()),
1.260 paf 154: form(*new VForm(charsets, arequest_info)),
1.248 paf 155: mail(*new VMail),
156: response(*new VResponse(arequest_info, charsets)),
1.298 misha 157: cookie(*new VCookie(charsets, arequest_info)),
1.285 misha 158: console(*new VConsole),
1.248 paf 159:
160: // private
161: configure_admin_done(false),
162:
163: // private defaults
164: fdefault_lang(adefault_lang),
165: // private mime types
166: mime_types(0)
1.157 parser 167: {
1.261 paf 168: pa_register_thread_request(*this);
169:
1.248 paf 170: // file_no=0 => unknown
1.347 moko 171: file_list+="UNKNOWN";
172: file_list+="-body of process-"; // pseudo_file_no__process
1.186 paf 173:
1.178 paf 174: // maybe expire old caches
1.264 paf 175: cache_managers->maybe_expire();
1.178 paf 176:
1.157 parser 177: /// directly used
1.233 paf 178: // MAIN class, operators
1.353 moko 179: put_class(&main_class);
1.157 parser 180: // classes:
181: // table, file, random, mail, image, ...
1.248 paf 182: methoded_array().register_directly_used(*this);
1.157 parser 183:
184: /// methodless
1.354 moko 185:
1.157 parser 186: // env class
1.353 moko 187: put_class(new VEnv(asapi_info));
1.175 paf 188: // status class
1.353 moko 189: put_class(new VStatus());
1.157 parser 190: // request class
1.353 moko 191: put_class(new VRequest(arequest_info, charsets, form, asapi_info));
1.157 parser 192: // cookie class
1.353 moko 193: put_class(&cookie);
1.253 paf 194: // console class
1.353 moko 195: put_class(&console);
1.354 moko 196:
1.157 parser 197: /// methoded
1.354 moko 198:
1.157 parser 199: // response class
1.353 moko 200: put_class(&response);
1.157 parser 201: // form class
1.353 moko 202: put_class(&form);
1.213 paf 203: // mail class
1.353 moko 204: put_class(&mail);
1.157 parser 205: // math class
1.353 moko 206: put_class(new VMath);
1.248 paf 207: // memory class
1.353 moko 208: put_class(new VMemory);
1.117 paf 209: }
1.192 paf 210:
211: Request::~Request() {
212: #ifdef XML
213: // if for some strange reason xml generic errors failed to be reported, free them up
1.248 paf 214: if(const char* xml_generic_errors=xmlGenericErrors()) {
215: SAPI::log(sapi_info, "warning: unreported xmlGenericErrors: %s", xml_generic_errors);
1.341 moko 216: pa_free((void *)xml_generic_errors);
1.192 paf 217: }
218: #endif
219: }
1.236 paf 220:
1.248 paf 221: Value& Request::get_self() { return method_frame/*always have!*/->self(); }
1.192 paf 222:
1.355 moko 223: VStateless_class* Request::get_class(const String& name){
224: VStateless_class* result=classes().get(name);
1.313 misha 225: if(!result)
1.375 moko 226: if(const Method *method=main_class.get_element_method(autouse_method_name)){
1.364 moko 227: Value *vname=new VString(name);
228: CONSTRUCTOR_FRAME_ACTION(*method, 0 /*no parent*/, main_class, {
229: frame.store_params(&vname, 1);
230: // we don't need the result
231: call(frame);
232: });
233: result=classes().get(name);
234: }
1.309 misha 235: return result;
236: }
237:
1.411 moko 238: VStateless_class& Request::get_class_ref(const String& name){
239: VStateless_class* result=get_class(name);
240: if(!result)
241: throw Exception(PARSER_RUNTIME, &name, "class is undefined");
242: return *result;
243: }
244:
1.356 moko 245: static void load_charset(HashStringValue::key_type akey, HashStringValue::value_type avalue, Request_charsets* charsets) {
1.359 moko 246: pa_charsets.load_charset(*charsets, akey, avalue->as_string());
1.208 paf 247: }
1.356 moko 248:
1.395 moko 249:
250: #define CONF_OPTION(config, name, code, exception_name) \
251: if(config) \
252: if(Value* option=config->get_element(name)) { \
253: if(option->is_evaluated_expr()) { \
254: code; \
255: } else \
1.415 moko 256: throw Exception(PARSER_RUNTIME, 0, "$MAIN:" exception_name, name.cstr()); \
1.395 moko 257: }
258:
1.248 paf 259: void Request::configure_admin(VStateless_class& conf_class) {
1.208 paf 260: if(configure_admin_done)
1.356 moko 261: throw Exception(PARSER_RUNTIME, 0, "parser already configured");
1.208 paf 262: configure_admin_done=true;
263:
1.227 paf 264: // charsets must only be specified in method_frame config
1.208 paf 265: // so that users would not interfere
266:
267: /* $MAIN:CHARSETS[
268: $.charsetname1[/full/path/to/charset/file.cfg]
269: ...
270: ]
271: */
1.308 misha 272: if(Value* vcharsets=conf_class.get_element(charsets_name)) {
1.342 moko 273: if(!vcharsets->is_string()) {
1.248 paf 274: if(HashStringValue* charsets=vcharsets->get_hash())
1.281 paf 275: charsets->for_each<Request_charsets*>(load_charset, &this->charsets);
1.240 paf 276: else
1.415 moko 277: throw Exception(PARSER_RUNTIME, 0, "$MAIN:%s must be hash", charsets_name.cstr());
1.342 moko 278: }
1.208 paf 279: }
280:
1.330 moko 281: #ifdef STRICT_VARS
1.332 moko 282: VVoid::strict_vars=false;
1.330 moko 283: if(Value* strict_vars=conf_class.get_element(strict_vars_name)) {
284: if(strict_vars->is_bool())
285: VVoid::strict_vars=strict_vars->as_bool();
1.357 moko 286: else
1.415 moko 287: throw Exception(PARSER_RUNTIME, 0, "$MAIN:%s must be bool", strict_vars_name.cstr());
1.357 moko 288: }
289: #endif
290:
291: #ifdef OBJECT_PROTOTYPE
292: VClass::prototype=true;
293: if(Value* prototype=conf_class.get_element(prototype_name)) {
294: if(prototype->is_bool())
295: VClass::prototype=prototype->as_bool();
296: else
1.415 moko 297: throw Exception(PARSER_RUNTIME, 0, "$MAIN:%s must be bool", prototype_name.cstr());
1.330 moko 298: }
299: #endif
300:
1.415 moko 301: #ifdef CLASS_GETTER_UNPROTECTED
302: VClass::getter_protected=true;
303: if(Value* getter_protected=conf_class.get_element(getter_protected_name)) {
304: if(getter_protected->is_bool())
305: VClass::getter_protected=getter_protected->as_bool();
306: else
307: throw Exception(PARSER_RUNTIME, 0, "$MAIN:%s must be bool", getter_protected_name.cstr());
308: }
309: #endif
310:
311: VStateless_class::gall_vars_local=false;
312: if(Value* locals=conf_class.get_element(locals_name)) {
313: if(locals->is_bool()){
314: VStateless_class::gall_vars_local=locals->as_bool();
315: main_class.set_all_vars_local();
316: } else
317: throw Exception(PARSER_RUNTIME, 0, "$MAIN:%s must be bool", locals_name.cstr());
318: }
319:
1.362 moko 320: Value* limits=conf_class.get_element(limits_name);
321:
1.361 moko 322: pa_loop_limit=LOOP_LIMIT;
1.395 moko 323: CONF_OPTION(limits, loop_limit_name, {
324: pa_loop_limit=option->as_int();
325: if(pa_loop_limit==0) pa_loop_limit=INT_MAX;
326: }, "LIMITS.%s must be int");
1.361 moko 327:
328: pa_execute_recoursion_limit=EXECUTE_RECOURSION_LIMIT;
1.395 moko 329: CONF_OPTION(limits, recoursion_limit_name, {
330: pa_execute_recoursion_limit=option->as_int();
331: if(pa_execute_recoursion_limit==0) pa_execute_recoursion_limit=INT_MAX;
332: }, "LIMITS.%s must be int");
1.390 moko 333:
1.369 moko 334: pa_file_size_limit=FILE_SIZE_LIMIT;
1.395 moko 335: CONF_OPTION(limits, file_size_limit_name, {
336: double limit=option->as_double();
337: if(limit >= (double)SSIZE_MAX)
1.415 moko 338: throw Exception(PARSER_RUNTIME, 0, "$MAIN:LIMITS.%s must be less then %.15g", file_size_limit_name.cstr(), (double)SSIZE_MAX);
1.395 moko 339: pa_file_size_limit=(size_t)limit;
340: if(pa_file_size_limit==0)
341: pa_file_size_limit=SSIZE_MAX;
342: }, "LIMITS.%s must be number");
1.361 moko 343:
1.372 moko 344: pa_lock_attempts=PA_LOCK_ATTEMPTS;
1.395 moko 345: CONF_OPTION(limits, lock_wait_timeout_name, {
346: double limit=option->as_double();
347: if(limit >= 3600*24)
1.415 moko 348: throw Exception(PARSER_RUNTIME, 0, "$MAIN:LIMITS.%s must be less then %d", lock_wait_timeout_name.cstr(), 3600*24);
1.395 moko 349: pa_lock_attempts=(unsigned int)(limit*2)+1;
350: }, "LIMITS.%s must be number");
351:
352: Value* httpd=conf_class.get_element(httpd_name);
353:
354: pa_httpd_timeout=HTTPD_TIMEOUT;
355: CONF_OPTION(httpd, httpd_timeout_name, {
356: pa_httpd_timeout=option->as_int();
357: if(pa_httpd_timeout==0) pa_httpd_timeout=INT_MAX;
358: }, "HTTPD.%s must be int");
1.372 moko 359:
1.403 moko 360: if(httpd)
361: if(Value* option=httpd->get_element( httpd_mode_name)) {
362: if(option->get_junction())
1.415 moko 363: throw Exception(PARSER_RUNTIME, 0, "$MAIN:HTTPD:mode must be string");
1.403 moko 364: HTTPD_Server::set_mode(option->as_string());
365: }
1.402 moko 366:
1.227 paf 367: // configure method_frame options
1.208 paf 368: // until someone with less privileges have overriden them
1.248 paf 369: methoded_array().configure_admin(*this);
1.208 paf 370: }
1.150 parser 371:
1.349 moko 372: const char* Request::get_exception_cstr(const Exception& e, Request::Exception_details& details) {
373:
1.269 paf 374: #define PA_URI_FORMAT "%s: "
1.349 moko 375: #define PA_COMMENT_TYPE_FORMAT "%s [%s]"
376:
1.269 paf 377: #define PA_ORIGIN_FILE_POS_FORMAT "%s(%d:%d): "
378: #define PA_SOURCE_FORMAT "'%s' "
1.349 moko 379:
380: #define PA_ORIGIN_FILE_POS_VALUE file_list[details.origin.file_no].cstr(), 1+details.origin.line, 1+details.origin.col,
381: #define PA_SOURCE_VALUE details.problem_source->cstr(),
382:
383: #define EXCEPTION_CSTR(f1,v1,f2,v2) \
384: snprintf(result, MAX_STRING, \
385: PA_URI_FORMAT \
386: f1 f2 \
387: PA_COMMENT_TYPE_FORMAT, \
388: request_info.uri, \
389: v1 v2 \
390: e.comment(), e.type() \
391: );
392:
1.269 paf 393: char* result=new(PointerFreeGC) char[MAX_STRING];
394:
395: if(details.problem_source) { // do we know the guy?
1.349 moko 396: if(details.origin.file_no) // do whe know where he came from?
397: EXCEPTION_CSTR(PA_ORIGIN_FILE_POS_FORMAT, PA_ORIGIN_FILE_POS_VALUE, PA_SOURCE_FORMAT, PA_SOURCE_VALUE)
398: else
399: EXCEPTION_CSTR(PA_SOURCE_FORMAT, PA_SOURCE_VALUE,,)
400: } else {
401: if(details.origin.file_no) // do whe know where he came from?
402: EXCEPTION_CSTR(PA_ORIGIN_FILE_POS_FORMAT, PA_ORIGIN_FILE_POS_VALUE,,)
403: else
404: EXCEPTION_CSTR(,,,)
405: }
1.269 paf 406:
407: return result;
408: }
1.272 paf 409:
1.407 moko 410: Table &Request::Exception_trace::table(Request &r){
411: // $stack[^table::create{name file lineno colno}]
412: Table::columns_type stack_trace_columns(new ArrayString);
413: *stack_trace_columns+=new String("name");
414: *stack_trace_columns+=new String("file");
415: *stack_trace_columns+=new String("lineno");
416: *stack_trace_columns+=new String("colno");
417: Table& stack_trace=*new Table(stack_trace_columns);
418:
419: if(!is_empty()/*signed!*/)
420: for(size_t i=bottom_index(); i<top_index(); i++) {
421: Trace trace=get(i);
422: Table::element_type row(new ArrayString);
423:
424: *row+=trace.name(); // name column
425: Operation::Origin origin=trace.origin();
426: if(origin.file_no) {
427: *row+=new String(r.file_list[origin.file_no], String::L_TAINTED); // 'file' column
428: *row+=new String(String::Body::Format(1+origin.line), String::L_CLEAN); // 'lineno' column
429: *row+=new String(String::Body::Format(1+origin.col), String::L_CLEAN); // 'colno' column
430: }
431: stack_trace+=row;
432: }
433:
434: return stack_trace;
435: }
436:
1.272 paf 437: void Request::configure() {
438: // configure admin options if not configured yet
439: if(!configure_admin_done)
440: configure_admin(main_class);
441:
442: // configure not-admin=user options
443: methoded_array().configure_user(*this);
444:
445: // $MAIN:MIME-TYPES
1.308 misha 446: if(Value* element=main_class.get_element(mime_types_name))
1.272 paf 447: if(Table *table=element->get_table())
1.395 moko 448: mime_types=table;
1.272 paf 449: }
1.408 moko 450:
1.64 paf 451: /**
452: load MAIN class, execute @main.
453: MAIN class consists of all the auto.p files we'd manage to find
454: plus
455: the file user requested us to process
456: all located classes become children of one another,
457: composing class we name 'MAIN'
1.180 paf 458:
459: @test log stack trace
460:
1.64 paf 461: */
1.412 moko 462: void Request::core(const char* config_filespec, bool header_only, const String &amain_method_name, const String* amain_class_name) {
1.406 moko 463: VFile* body_file=NULL;
464: bool as_attachment=false;
465:
1.169 parser 466: try {
1.211 paf 467: // loading config
1.384 moko 468: if(config_filespec)
1.387 moko 469: use_file_directly(*new String(config_filespec));
1.8 paf 470:
1.338 moko 471: // filling mail received
472: mail.fill_received(*this);
473:
1.272 paf 474: try {
475: // compile requested file
1.389 moko 476: if(request_info.path_translated)
477: use_file_directly(*new String(request_info.path_translated, String::L_TAINTED), true, true /* load auto.p files */);
1.272 paf 478: configure();
479: } catch(...) {
480: configure(); // configure anyway, useful in @unhandled_exception [say, if they would want to mail by SMTP something]
481: rethrow;
482: }
1.25 paf 483:
1.412 moko 484: VStateless_class& main = amain_class_name ? get_class_ref(*amain_class_name) : main_class;
1.25 paf 485: // execute @main[]
1.412 moko 486: const String* body_string=amain_method_name.is_empty() ? &String::Empty : execute_method(main, amain_method_name);
1.41 paf 487: if(!body_string)
1.412 moko 488: throw Exception(PARSER_RUNTIME, &amain_method_name, "method not found in class %s", main.type());
1.79 paf 489:
1.250 paf 490: // extract response body
1.344 moko 491: Value* body_value=response.fields().get(download_name_upper); // $response:download?
1.406 moko 492: as_attachment=body_value!=0;
1.250 paf 493: if(!body_value)
1.344 moko 494: body_value=response.fields().get(body_name_upper); // $response:body
1.250 paf 495: if(!body_value)
496: body_value=new VString(*body_string); // just result of ^main[]
497:
1.119 paf 498: // @postprocess
1.383 moko 499: if(const Method *method=main_class.get_method(post_process_method_name)) {
500: METHOD_FRAME_ACTION(*method, 0 /*no parent*/, main_class, {
501: frame.store_params(&body_value, 1);
502: call(frame);
503: body_value=&frame.result();
504: });
505: }
1.90 paf 506:
1.406 moko 507: body_file=body_value->as_vfile(flang, &charsets);
1.183 paf 508:
1.171 parser 509: } catch(const Exception& e) { // request handling problem
1.268 paf 510: try {
1.407 moko 511: // we're returning not result, but error explanation
1.269 paf 512:
1.407 moko 513: Request::Exception_details details=get_details(e);
514: const char* exception_cstr=get_exception_cstr(e, details);
1.258 paf 515:
1.407 moko 516: // reset language to default
517: flang=fdefault_lang;
518: // reset response
519: response.fields().clear();
520:
521: // this is what we'd return in $response:body
522: const String* body_string=0;
523:
524: // maybe we'd be lucky enough as to report an error in a gracefull way...
525: if(const Method *method=main_class.get_method(*new String(UNHANDLED_EXCEPTION_METHOD_NAME))) {
526: // preparing parameters to @unhandled_exception[exception;stack]
527:
528: Table& stack_trace=exception_trace.table(*this);
529: exception_trace.clear(); // forget all about previous life, in case there would be error inside of this method, error handled would not be mislead by old stack contents (see extract_origin)
530:
531: Value *params[]={&details.vhash, new VTable(&stack_trace)};
532: METHOD_FRAME_ACTION(*method, 0 /*no caller*/, main_class, {
533: frame.store_params(params, 2);
534: call(frame);
535: body_string=&frame.result().as_string();
536: });
537: }
1.383 moko 538:
1.407 moko 539: // conditionally log it
540: Value* vhandled=details.vhash.hash().get(exception_handled_part_name);
541: if(!vhandled || !vhandled->as_bool()) {
542: SAPI::log(sapi_info, "%s", exception_cstr);
543: }
1.383 moko 544:
1.407 moko 545: if(body_string) { // could report an error beautifully?
546: VString body_vstring(*body_string);
1.273 paf 547:
1.407 moko 548: body_file=body_vstring.as_vfile(flang, &charsets);
549: as_attachment=false;
550: } else {
551: // doing that ugly
552: SAPI::send_error(sapi_info, exception_cstr, !strcmp(e.type(), "file.missing") ? "404" : "500");
553: return;
554: }
1.287 misha 555:
1.273 paf 556: } catch(const Exception& e) { // exception in unhandled exception
1.269 paf 557: Request::Exception_details details=get_details(e);
1.380 moko 558: // unconditionally log the beast in exception handler
1.407 moko 559: throw Exception(0, 0, "Unhandled exception in %s", get_exception_cstr(e, details));
1.268 paf 560: }
1.1 paf 561: }
1.406 moko 562:
563: // write out the result outside of try as network exceptions should not be handled by parser code.
564: output_result(body_file, header_only, as_attachment);
1.1 paf 565: }
566:
1.266 paf 567: uint Request::register_file(String::Body file_spec) {
1.248 paf 568: file_list+=file_spec;
569: return file_list.count()-1;
570: }
571:
1.387 moko 572: void Request::use_file_directly(const String& file_spec, bool fail_on_file_absence, bool with_auto_p) {
1.73 paf 573: // cyclic dependence check
1.318 misha 574: if(used_files.get(file_spec))
1.248 paf 575: return;
1.318 misha 576: used_files.put(file_spec, true);
577:
1.385 moko 578: if(!fail_on_file_absence && !entry_exists(file_spec)) // ignore file absence if asked for
579: return;
1.318 misha 580:
1.386 moko 581: if(with_auto_p) {
582: // loading auto.p files from document_root/..
583: // to the one beside requested file.
584: // all assigned bases from upper dir
585: const char* target=file_spec.cstr();
586:
587: // all relative paths are calculated from main document
588: request_info.path_translated=target;
589:
590: const char* after=target;
591: size_t drlen=strlen(request_info.document_root);
592: if(memcmp(after, request_info.document_root, drlen)==0) {
593: after+=drlen;
594: if(after[-1]=='/')
595: --after;
596: }
597:
598: while(const char* before=strchr(after, '/')) {
599: String& sfile_spec=*new String;
600: if(after!=target) {
601: sfile_spec.append_strdup(target, before-target, String::L_CLEAN);
602: sfile_spec << "/" AUTO_FILE_NAME;
603:
1.387 moko 604: use_file_directly(sfile_spec, false /*ignore absence, sole user*/);
1.386 moko 605: }
606: for(after=before+1;*after=='/';after++);
607: }
608: }
609:
1.385 moko 610: if(const char* source=file_read_text(charsets, file_spec, true))
1.387 moko 611: use_buf(main_class, source, 0, register_file(file_spec));
1.318 misha 612: }
613:
614:
1.387 moko 615: void Request::use_file(const String& file_name, const String* use_filespec/*absolute*/, bool with_auto_p) {
1.326 misha 616: if(file_name.is_empty())
1.366 moko 617: throw Exception(PARSER_RUNTIME, 0, "usage failed - no filename was specified");
1.326 misha 618:
1.318 misha 619: const String* filespec=0;
620:
621: if(file_name.first_char()=='/') //absolute path? [no need to scan MAIN:CLASS_PATH]
1.388 moko 622: filespec=&full_disk_path(file_name);
1.318 misha 623: else if(use_filespec){ // search in current dir first
1.331 misha 624: size_t last_slash_pos=use_filespec->strrpbrk("/");
625: if(last_slash_pos!=STRING_NOT_FOUND)
626: filespec=file_exist(use_filespec->mid(0, last_slash_pos), file_name); // found in current dir?
1.318 misha 627: }
628:
629: if(!filespec){
630: // prevent multiple scan CLASS_PATH for searching one file
631: if(searched_along_class_path.get(file_name))
632: return;
633: searched_along_class_path.put(file_name, true);
1.308 misha 634: if(Value* element=main_class.get_element(class_path_name)) {
1.233 paf 635: if(element->is_string()) {
1.388 moko 636: filespec=file_exist(full_disk_path(element->as_string()), file_name); // found at class_path?
1.233 paf 637: } else if(Table *table=element->get_table()) {
1.318 misha 638: for(size_t i=table->count(); i--; ) {
1.248 paf 639: const String& path=*(*table->get(i))[0];
1.388 moko 640: if(filespec=file_exist(full_disk_path(path), file_name))
1.233 paf 641: break; // found along class_path
642: }
643: } else
1.366 moko 644: throw Exception(PARSER_RUNTIME, 0, "$" CLASS_PATH_NAME " must be string or table");
1.318 misha 645: if(!filespec)
1.415 moko 646: throw Exception(PARSER_RUNTIME, &file_name, "not found along $MAIN:" CLASS_PATH_NAME);
1.318 misha 647: } else
1.415 moko 648: throw Exception(PARSER_RUNTIME, &file_name, "usage failed - no $MAIN:" CLASS_PATH_NAME " were specified");
1.148 parser 649: }
1.230 paf 650:
1.387 moko 651: use_file_directly(*filespec, true, with_auto_p);
1.16 paf 652: }
653:
1.364 moko 654: void Request::use_file(const String& file_name, const String* use_filespec/*absolute*/, Operation::Origin origin) {
1.349 moko 655: static String use("USE");
656: try {
1.364 moko 657: static VHash* voptions=new VHash();
1.376 moko 658: if(const Method *method=main_class.get_method(use_method_name)){
1.364 moko 659: Value *params[]={new VString(file_name), voptions};
660: voptions->hash().put(origin_key, new VString(*use_filespec));
661:
662: CONSTRUCTOR_FRAME_ACTION(*method, 0 /*no parent*/, main_class, {
663: frame.store_params(params, 2);
664: // we don't need the result
665: call(frame);
666: });
667: }
1.349 moko 668: } catch (...) {
669: exception_trace.push(Trace(&use, origin));
670: rethrow;
671: }
672: }
1.208 paf 673:
1.358 moko 674: void Request::use_buf(VStateless_class& aclass, const char* source, const String* main_alias, uint file_no, int line_no_offset) {
675: // temporary zero @conf to avoid it second execution
1.248 paf 676: Temp_method temp_method_conf(aclass, conf_method_name, 0);
1.358 moko 677: // temporary zero @auto to avoid it second execution
1.248 paf 678: Temp_method temp_method_auto(aclass, auto_method_name, 0);
1.233 paf 679:
1.295 misha 680: // compile loaded classes
681: ArrayClass& cclasses=compile(&aclass, source, main_alias, file_no, line_no_offset);
1.212 paf 682:
1.248 paf 683: VString* vfilespec=
684: new VString(*new String(file_list[file_no], String::L_TAINTED));
1.295 misha 685:
686: for(size_t i=0; i<cclasses.count(); i++){
687: VStateless_class& cclass=*cclasses.get(i);
1.296 misha 688:
689: // locate and execute possible @conf[] static
1.382 moko 690: if(execute_method_if_exists(cclass, conf_method_name, vfilespec))
1.295 misha 691: configure_admin(cclass/*, executed.method->name*/);
692:
693: // locate and execute possible @auto[] static
1.382 moko 694: execute_method_if_exists(cclass, auto_method_name, vfilespec);
1.336 moko 695:
696: cclass.enable_default_setter();
1.295 misha 697: }
1.19 paf 698: }
699:
1.248 paf 700: const String& Request::relative(const char* apath, const String& relative_name) {
1.341 moko 701: char *hpath=pa_strdup(apath);
1.248 paf 702: String& result=*new String;
703: if(rsplit(hpath, '/')) // if something/splitted
1.217 paf 704: result << hpath << "/";
1.248 paf 705: result << relative_name;
706: return result;
1.19 paf 707: }
708:
1.388 moko 709: const String& Request::full_disk_path(const String& relative_name) {
1.217 paf 710: if(relative_name.first_char()=='/') {
1.341 moko 711: String& result=*new String(pa_strdup(request_info.document_root));
1.104 paf 712: result << relative_name;
1.19 paf 713: return result;
1.389 moko 714: }
715: if(relative_name.pos("://")!=STRING_NOT_FOUND // something like "http://xxx"
1.247 paf 716: #ifdef WIN32
1.389 moko 717: || relative_name.pos(":")==1 // DRIVE:
718: || relative_name.starts_with("\\\\") // UNC1
719: || relative_name.starts_with("//") // UNC2
1.247 paf 720: #endif
1.389 moko 721: )
722: return relative_name;
723:
724: return relative(request_info.path_translated ? request_info.path_translated : request_info.document_root, relative_name);
1.1 paf 725: }
1.45 paf 726:
1.267 paf 727: #ifndef DOXYGEN
728: class Add_header_attribute_info
729: {
730: public:
731: Add_header_attribute_info(Request& ar) : r(ar), add_last_modified(true) {}
732: Request& r;
733: bool add_last_modified;
734: };
735: #endif
1.344 moko 736: static void add_header_attribute(HashStringValue::key_type name, HashStringValue::value_type value, Add_header_attribute_info* info) {
737: if(name==BODY_NAME_UPPER || name==DOWNLOAD_NAME_UPPER || name==CHARSET_NAME_UPPER)
1.101 paf 738: return;
1.290 misha 739:
1.345 moko 740: if(name==LAST_MODIFIED_NAME_UPPER)
741: info->add_last_modified=false;
742:
1.316 misha 743: const char* aname=String(name, String::L_URI).untaint_and_transcode_cstr(String::L_URI, &info->r.charsets);
1.101 paf 744:
1.267 paf 745: SAPI::add_header_attribute(info->r.sapi_info,
1.345 moko 746: aname,
1.316 misha 747: attributed_meaning_to_string(*value, String::L_URI, false).untaint_and_transcode_cstr(String::L_URI, &info->r.charsets)
1.303 misha 748: );
1.267 paf 749: }
750:
1.366 moko 751: static void output_sole_piece(Request& r, bool header_only, VFile& body_file, Value* body_file_content_type) {
1.267 paf 752: // transcode text body when "text/*" or simple result
753: String::C output(body_file.value_ptr(), body_file.value_size());
754: if(!body_file_content_type/*vstring.as_vfile*/ || body_file_content_type->as_string().pos("text/")==0)
1.366 moko 755: output=Charset::transcode(output, r.charsets.source(), r.charsets.client());
1.267 paf 756:
1.311 misha 757: // prepare header: Content-Length
758: SAPI::add_header_attribute(r.sapi_info, HTTP_CONTENT_LENGTH, format(output.length, "%u"));
1.267 paf 759:
760: // send header
761: SAPI::send_header(r.sapi_info);
762:
763: // send body
764: if(!header_only)
765: SAPI::send_body(r.sapi_info, output.str, output.length);
766: }
767:
768: #ifndef DOXYGEN
769: struct Range
770: {
1.396 moko 771: uint64_t start;
772: uint64_t end;
1.267 paf 773: };
774: #endif
1.396 moko 775:
776: #define UNSET ((uint64_t)-1)
777:
1.313 misha 778: static void parse_range(const String* s, Array<Range> &ar) {
1.267 paf 779: const char *p = s->cstr();
780: if(s->starts_with("bytes="))
781: p += 6;
782: Range r;
783: while(*p){
1.396 moko 784: r.start = UNSET;
785: r.end = UNSET;
1.401 moko 786:
787: while(*p==' ' || *p=='\t') p++;
788:
1.267 paf 789: if(*p >= '0' && *p <= '9'){
1.416 moko 790: const char *n=p;
1.401 moko 791: while(*p>='0' && *p<='9') p++;
1.416 moko 792: r.start = pa_atoul(pa_strdup(n, p-n));
1.267 paf 793: }
1.401 moko 794:
795: while(*p==' ' || *p=='\t') p++;
796:
1.267 paf 797: if(*p++ != '-') break;
1.401 moko 798:
799: while(*p==' ' || *p=='\t') p++;
800:
1.267 paf 801: if(*p >= '0' && *p <= '9'){
1.416 moko 802: const char *n=p;
1.401 moko 803: while(*p>='0' && *p<='9') p++;
1.416 moko 804: r.end = pa_atoul(pa_strdup(n, p-n));
1.267 paf 805: }
1.401 moko 806:
807: while(*p==' ' || *p=='\t') p++;
808:
809: if(*p)
810: if(*p++ != ',') break;
811:
1.267 paf 812: ar += r;
813: }
1.101 paf 814: }
1.267 paf 815:
1.400 moko 816: struct Send_range_action_info {
817: Request *r;
818: uint64_t offset;
819: uint64_t part_length;
820: };
821:
822: static void send_range(struct stat& /*finfo*/, int f, const String& /*file_spec*/, void *context){
823: Send_range_action_info &info = *(Send_range_action_info*)context;
824:
1.414 moko 825: SAPI::send_header(info.r->sapi_info);
1.400 moko 826: pa_lseek(f, info.offset, SEEK_SET);
827:
828: const size_t BUFSIZE = 128*0x400;
829: char buf[BUFSIZE];
830: do{
831: size_t to_read = info.part_length < BUFSIZE ? (size_t)info.part_length : BUFSIZE;
832: size_t to_write = file_block_read(f, buf, to_read);
833:
834: if(to_write == 0)
835: break;
836:
837: size_t size = SAPI::send_body(info.r->sapi_info, buf, to_write);
838: if(size != to_write)
839: break;
840:
841: info.part_length -= to_write;
842: } while (info.part_length);
843: }
844:
1.396 moko 845: static void output_pieces(Request& r, bool header_only, const String& filename, uint64_t content_length, Value& date, bool add_last_modified) {
1.315 misha 846: SAPI::add_header_attribute(r.sapi_info, "accept-ranges", "bytes");
1.270 paf 847:
1.339 moko 848: const char *range = SAPI::Env::get(r.sapi_info, "HTTP_RANGE");
1.396 moko 849: uint64_t offset=0;
850: uint64_t part_length=content_length;
1.401 moko 851:
852: if(range && content_length){
1.267 paf 853: Array<Range> ar;
854: parse_range(new String(range), ar);
1.396 moko 855: int count = ar.count();
1.267 paf 856: if(count == 1){
857: Range &rg = ar.get_ref(0);
1.401 moko 858:
859: if(rg.start == UNSET && rg.end == UNSET)
860: return SAPI::send_error(r.sapi_info, "", "416");
861:
1.396 moko 862: if(rg.start == UNSET && rg.end != UNSET){
1.401 moko 863: if(rg.end > content_length)
864: rg.end = content_length;
1.404 moko 865: rg.start = content_length - rg.end;
866: rg.end = content_length-1;
1.401 moko 867: } else if(rg.start != UNSET && rg.end == UNSET){
868: if(rg.start >= content_length)
869: return SAPI::send_error(r.sapi_info, "", "416");
1.267 paf 870: rg.end = content_length-1;
1.401 moko 871: } else {
872: if(rg.start >= content_length || rg.start > rg.end)
873: return SAPI::send_error(r.sapi_info, "", "416");
874: if(rg.end >= content_length)
875: rg.end = content_length-1;
1.267 paf 876: }
1.401 moko 877:
878: offset = rg.start;
879: part_length = rg.end-rg.start+1;
880:
1.400 moko 881: char buf[MAX_STRING];
882: snprintf(buf, MAX_STRING, "bytes %.15g-%.15g/%.15g", (double)rg.start, (double)rg.end, (double)content_length);
1.401 moko 883: SAPI::add_header_attribute(r.sapi_info, HTTP_STATUS, "206");
1.315 misha 884: SAPI::add_header_attribute(r.sapi_info, "content-range", buf);
1.401 moko 885: } else {
1.410 moko 886: return SAPI::send_error(r.sapi_info, count ? "Multiple ranges are not supported" : "Invalid range", count ? "501" : "400");
1.267 paf 887: }
888: }
889:
1.398 moko 890: SAPI::add_header_attribute(r.sapi_info, HTTP_CONTENT_LENGTH, format((double)part_length, "%.15g"));
1.267 paf 891:
1.314 misha 892: if(add_last_modified)
1.315 misha 893: SAPI::add_header_attribute(r.sapi_info, "last-modified", attributed_meaning_to_string(date, String::L_AS_IS, true).cstr());
1.314 misha 894:
1.414 moko 895: if(header_only){
896: SAPI::send_header(r.sapi_info);
897: } else {
1.400 moko 898: Send_range_action_info info = { &r, offset, part_length};
899: file_read_action_under_lock(r.full_disk_path(filename), "send", send_range, &info);
1.267 paf 900: }
901: }
902:
1.248 paf 903: void Request::output_result(VFile* body_file, bool header_only, bool as_attachment) {
1.51 paf 904: // header: cookies
1.248 paf 905: cookie.output_result(sapi_info);
1.51 paf 906:
1.394 moko 907: // $.file and $.name (when body is real vfile)
908: Value* vfile = body_file->fields().get(response_body_file_name);
909: Value* vname = body_file->fields().get(name_name);
910:
911: const String* sfile = vfile ? &vfile->as_string() : NULL;
912: const String* sname = vname ? &vname->as_string() : NULL;
913:
914: if(sname && *sname == NONAME_DAT)
915: sname = NULL;
1.92 paf 916:
1.409 moko 917: // Content-Disposition, use $.name[<empty>] to avoid
1.394 moko 918: const String* disposition_name = sname ? sname->is_empty() ? NULL : sname : sfile;
919: if(disposition_name) {
920: VHash& hash=*new VHash();
921: hash.hash().put(value_name, new VString(as_attachment ? content_disposition_attachment : content_disposition_inline));
1.417 ! moko 922: hash.hash().put(content_disposition_filename_name, new VString(*new String(pa_filename(disposition_name->cstr()), String::L_URI)));
1.394 moko 923: response.fields().put(content_disposition_name_upper, &hash);
924: }
1.267 paf 925:
1.394 moko 926: // _file_ content-type might be specified
927: Value* body_file_content_type = body_file->fields().get(content_type_name);
928: if(!body_file_content_type){
929: const String* scontent_name = sname && !sname->is_empty() ? sname : sfile;
930: if(scontent_name)
931: body_file_content_type = new VString(mime_type_of(scontent_name->cstr()));
1.267 paf 932: }
933:
1.312 misha 934: // set Content-Type
1.314 misha 935: if(body_file_content_type) {
936: // body file content type
1.344 moko 937: response.fields().put(content_type_name_upper, body_file_content_type);
1.314 misha 938: } else {
939: // default content type
1.344 moko 940: response.fields().put_dont_replace(content_type_name_upper, new VString(*new String(DEFAULT_CONTENT_TYPE)));
1.314 misha 941: }
1.312 misha 942:
1.314 misha 943: // prepare header: $response:fields without :body, :download and :charset
1.267 paf 944: Add_header_attribute_info info(*this);
1.281 paf 945: response.fields().for_each<Add_header_attribute_info*>(add_header_attribute, &info);
1.50 paf 946:
1.394 moko 947: if(sfile) {
1.314 misha 948: // $response:[download|body][$.file[filespec]] -- optput specified file
1.367 moko 949: uint64_t content_length=0;
1.267 paf 950: time_t atime=0, mtime=0, ctime=0;
1.394 moko 951: file_stat(full_disk_path(*sfile), content_length, atime, mtime, ctime);
1.267 paf 952:
953: VDate* vdate=0;
954: if(Value* v=body_file->fields().get("mdate")) {
1.308 misha 955: if(Value* vdatep=v->as(VDATE_TYPE))
1.267 paf 956: vdate=static_cast<VDate*>(vdatep);
957: else
1.286 misha 958: throw Exception(PARSER_RUNTIME, 0, "mdate must be a date");
1.267 paf 959: }
960: if(!vdate)
1.346 moko 961: vdate=new VDate((pa_time_t)mtime);
1.62 paf 962:
1.399 moko 963: output_pieces(*this, header_only, *sfile, content_length, *vdate, info.add_last_modified);
1.267 paf 964: } else {
1.314 misha 965: if(body_file_content_type)
966: if(HashStringValue *hash=body_file_content_type->get_hash())
967: body_file_content_type=hash->get(value_name);
968:
1.366 moko 969: output_sole_piece(*this, header_only, *body_file, body_file_content_type);
1.267 paf 970: }
1.50 paf 971: }
1.104 paf 972:
1.328 misha 973: const String& Request::mime_type_of(const String* file_name) {
974: return mime_type_of(file_name?file_name->taint_cstr(String::L_FILE_SPEC):0);
975: }
976:
1.248 paf 977: const String& Request::mime_type_of(const char* user_file_name_cstr) {
1.104 paf 978: if(mime_types)
1.248 paf 979: if(const char* cext=strrchr(user_file_name_cstr, '.')) {
980: String sext(++cext);
1.246 paf 981: Table::Action_options options;
1.342 moko 982: if(mime_types->locate(0, sext.change_case(charsets.source(), String::CC_LOWER), options)) {
1.313 misha 983: if(const String* result=mime_types->item(1))
984: return *result;
1.104 paf 985: else
1.395 moko 986: throw Exception(PARSER_RUNTIME, 0, MIME_TYPES_NAME " table column elements must not be empty");
1.342 moko 987: }
1.104 paf 988: }
1.248 paf 989:
990: return *new String("application/octet-stream");
991: }
992:
1.365 moko 993: const String* Request::get_used_filespec(uint file_no){
1.318 misha 994: if(file_no < file_list.count())
995: return new String(file_list[file_no], String::L_TAINTED);
996: return 0;
997: }
998:
1.248 paf 999: #ifdef XML
1.280 paf 1000: xmlChar* Request::transcode(const String& s) {
1.248 paf 1001: return charsets.source().transcode(s);
1002: }
1003:
1.280 paf 1004: xmlChar* Request::transcode(const String::Body s) {
1.248 paf 1005: return charsets.source().transcode(s);
1006: }
1007:
1.280 paf 1008: const String& Request::transcode(const xmlChar* s) {
1.248 paf 1009: return charsets.source().transcode(s);
1.233 paf 1010: }
1.248 paf 1011: #endif
1012:
1.349 moko 1013: Request::Exception_details Request::get_details(const Exception& e) {
1014: const String* problem_source=e.problem_source();
1015: VHash& vhash=*new VHash; HashStringValue& hash=vhash.hash();
1016: Operation::Origin origin={0, 0, 0};
1.248 paf 1017:
1.349 moko 1018: if(!exception_trace.is_empty()) {
1019: Trace bottom=exception_trace.bottom_value();
1.350 moko 1020: origin=bottom.origin();
1021: if(!problem_source) { // we don't know who trigged the bug
1022: problem_source=bottom.name(); // we usually know source of next-from-throw-point exception did that
1023: exception_trace.set_bottom_index(exception_trace.bottom_index()+1);
1024: } else if (bottom.name()==problem_source) { // it is that same guy?
1.349 moko 1025: exception_trace.set_bottom_index(exception_trace.bottom_index()+1); // throw away that trace
1026: } else {
1027: // stack top contains not us, leaving intact to help ^throw
1.279 paf 1028: }
1.248 paf 1029: }
1030:
1031: // $.type
1032: if(const char* type=e.type(true))
1033: hash.put(exception_type_part_name, new VString(*new String(type)));
1034:
1035: // $.source
1.349 moko 1036: if(problem_source)
1037: hash.put(exception_source_part_name, new VString(*new String(*problem_source, String::L_TAINTED)));
1.248 paf 1038:
1.349 moko 1039: // $.file $.lineno $.colno
1040: if(origin.file_no){
1.347 moko 1041: hash.put("file", new VString(*new String(file_list[origin.file_no], String::L_TAINTED)));
1042: hash.put("lineno", new VInt(1+origin.line));
1043: hash.put("colno", new VInt(1+origin.col));
1.248 paf 1044: }
1045:
1046: // $.comment
1047: if(const char* comment=e.comment(true))
1.349 moko 1048: hash.put(exception_comment_part_name, new VString(*new String(comment, String::L_TAINTED)));
1.248 paf 1049:
1050: // $.handled(0)
1.299 misha 1051: hash.put(exception_handled_part_name, &VBool::get(false));
1.233 paf 1052:
1.349 moko 1053: return Request::Exception_details(origin, problem_source, vhash);
1.133 parser 1054: }
1.337 moko 1055:
1056: Temp_value_element::Temp_value_element(Request& arequest, Value& awhere, const String& aname, Value* awhat) :
1057: frequest(arequest),
1058: fwhere(awhere),
1059: fname(aname),
1060: saved(awhere.get_element(aname))
1061: {
1062: Junction* junction;
1063: if(saved && (junction=saved->get_junction()) && junction->is_getter)
1064: saved=0;
1065: frequest.put_element(fwhere, aname, awhat);
1066: }
1067:
1068: Temp_value_element::~Temp_value_element() {
1069: frequest.put_element(fwhere, fname, saved ? saved : VVoid::get());
1070: }
E-mail: