Annotation of parser3/src/main/pa_request.C, revision 1.349

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

E-mail: