View | Details | Raw Unified | Return to bug 57501
Collapse All | Expand All

(-)src/apache-2/mod_rivet.c (-26 / +71 lines)
Lines 299-304 Link Here
299
    }
299
    }
300
}
300
}
301
301
302
/* -- Rivet_ExecuteErrorHandler
303
 *
304
 * 
305
 *
306
 */
307
308
static int 
309
Rivet_ExecuteErrorHandler (Tcl_Interp* interp,Tcl_Obj* tcl_script_obj, request_rec* req)
310
{
311
    int                     result;
312
    rivet_server_conf*      conf = Rivet_GetConf(req);
313
    Tcl_Obj*                errscript;
314
315
    /* We extract information from the errorOutbuf variable. Notice that tcl_script_obj
316
     * can either be the request processing script or conf->rivet_abort_script
317
     */
318
319
    Tcl_SetVar( interp, "errorOutbuf",Tcl_GetStringFromObj( tcl_script_obj, NULL ),TCL_GLOBAL_ONLY );
320
321
    /* If we don't have an error script, use the default error handler. */
322
    if (conf->rivet_error_script) {
323
        errscript = conf->rivet_error_script;
324
    } else {
325
        errscript = conf->rivet_default_error_script;
326
    }
327
328
    Tcl_IncrRefCount(errscript);
329
    result = Tcl_EvalObjEx(interp, errscript, 0);
330
    if (result == TCL_ERROR) {
331
        rivet_interp_globals*   globals   = Tcl_GetAssocData(interp, "rivet", NULL);
332
        CONST84 char*           errorinfo = Tcl_GetVar( interp, "errorInfo", 0 );
333
334
        TclWeb_PrintError("<b>Rivet ErrorScript failed!</b>",1,globals->req);
335
        TclWeb_PrintError( errorinfo, 0, globals->req );
336
    }
337
338
    /* This shouldn't make the default_error_script go away,
339
     * because it gets a Tcl_IncrRefCount when it is created.
340
     */
341
    Tcl_DecrRefCount(errscript);
342
343
    return result;
344
}
345
346
302
/* -- Rivet_ExecuteAndCheck
347
/* -- Rivet_ExecuteAndCheck
303
 * 
348
 * 
304
 * Tcl script execution central procedure. The script stored
349
 * Tcl script execution central procedure. The script stored
Lines 316-322 Link Here
316
 *
361
 *
317
 *   Returned value:
362
 *   Returned value:
318
 *
363
 *
319
 *      - invariably TCL_OK
364
 *      - One of the Tcl defined returned value of Tcl_EvelObjExe (TCL_OK, 
365
 *        TCL_ERROR, TCL_BREAK etc.)
320
 *
366
 *
321
 *   Side effects:
367
 *   Side effects:
322
 *
368
 *
Lines 330-336 Link Here
330
{
376
{
331
    int                     result;
377
    int                     result;
332
    rivet_server_conf*      conf = Rivet_GetConf(req);
378
    rivet_server_conf*      conf = Rivet_GetConf(req);
333
    rivet_interp_globals*   globals = Tcl_GetAssocData(interp, "rivet", NULL);
334
379
335
    Tcl_Preserve (interp);
380
    Tcl_Preserve (interp);
336
    result = Tcl_EvalObjEx(interp, tcl_script_obj, 0);
381
    result = Tcl_EvalObjEx(interp, tcl_script_obj, 0);
Lines 337-343 Link Here
337
382
338
    if (result == TCL_ERROR) {
383
    if (result == TCL_ERROR) {
339
384
340
        Tcl_Obj*    errscript;
341
        Tcl_Obj*    errorCodeListObj;
385
        Tcl_Obj*    errorCodeListObj;
342
        Tcl_Obj*    errorCodeElementObj;
386
        Tcl_Obj*    errorCodeElementObj;
343
        char*       errorCodeSubString;
387
        char*       errorCodeSubString;
Lines 376-414 Link Here
376
            {
420
            {
377
                if (conf->rivet_abort_script) 
421
                if (conf->rivet_abort_script) 
378
                {
422
                {
379
                    if (Tcl_EvalObjEx(interp,conf->rivet_abort_script,0) == TCL_ERROR)
423
424
                    /* Ideally an AbortScript should be fail safe, but in case
425
                     * it fails we give a chance to the subsequent ErrorScript
426
                     * to catch this error.
427
                     */
428
429
                    result = Tcl_EvalObjEx(interp,conf->rivet_abort_script,0);
430
                    if (result == TCL_ERROR)
380
                    {
431
                    {
381
                        CONST84 char *errorinfo = Tcl_GetVar( interp, "errorInfo", 0 );
432
                        //CONST84 char *errorinfo = Tcl_GetVar( interp, "errorInfo", 0 );
382
                        TclWeb_PrintError("<b>Rivet AbortScript failed!</b>",1,globals->req);
433
                        //TclWeb_PrintError("<b>Rivet AbortScript failed!</b>",1,globals->req);
383
                        TclWeb_PrintError(errorinfo,0,globals->req);
434
                        //TclWeb_PrintError(errorinfo,0,globals->req);
435
                        
436
                        result = Rivet_ExecuteErrorHandler(interp,conf->rivet_abort_script,req);
437
384
                    }
438
                    }
385
                }
439
                }
386
                goto good;
387
            }
440
            }
388
        }
441
        }
442
        else
443
        {
444
            /* Invoke Tcl error handler */
389
445
390
        Tcl_SetVar( interp, "errorOutbuf",Tcl_GetStringFromObj( tcl_script_obj, NULL ),TCL_GLOBAL_ONLY );
446
            result = Rivet_ExecuteErrorHandler(interp,tcl_script_obj,req);
391
447
392
        /* If we don't have an error script, use the default error handler. */
393
        if (conf->rivet_error_script) {
394
            errscript = conf->rivet_error_script;
395
        } else {
396
            errscript = conf->rivet_default_error_script;
397
        }
448
        }
398
449
399
        Tcl_IncrRefCount(errscript);
400
        if (Tcl_EvalObjEx(interp, errscript, 0) == TCL_ERROR) {
401
            CONST84 char *errorinfo = Tcl_GetVar( interp, "errorInfo", 0 );
402
            TclWeb_PrintError("<b>Rivet ErrorScript failed!</b>",1,globals->req);
403
            TclWeb_PrintError( errorinfo, 0, globals->req );
404
        }
405
450
406
        /* This shouldn't make the default_error_script go away,
407
         * because it gets a Tcl_IncrRefCount when it is created. */
408
        Tcl_DecrRefCount(errscript);
409
    }
451
    }
410
411
good:
412
    
452
    
413
    /* Tcl_Flush moved to the end of Rivet_SendContent */
453
    /* Tcl_Flush moved to the end of Rivet_SendContent */
414
454
Lines 425-431 Link Here
425
 * if a Tcl script.
465
 * if a Tcl script.
426
 *
466
 *
427
 * This is a separate function so that it may be called from command 'parse'
467
 * This is a separate function so that it may be called from command 'parse'
468
 * 
469
 * Returned value:
428
 *
470
 *
471
 *   - One of the Tcl defined values returned by Rivet_ExecuteAndCheck (TCL_OK, 
472
 *     TCL_ERROR, TCL_BREAK etc.)
473
 *
429
 * Arguments:
474
 * Arguments:
430
 *
475
 *
431
 *   - TclWebRequest: pointer to the structure collecting Tcl and Apache data
476
 *   - TclWebRequest: pointer to the structure collecting Tcl and Apache data
Lines 1477-1483 Link Here
1477
    if (Rivet_ParseExecFile(globals->req, r->filename, 1) != TCL_OK)
1522
    if (Rivet_ParseExecFile(globals->req, r->filename, 1) != TCL_OK)
1478
    {
1523
    {
1479
        ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, r->server, 
1524
        ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, r->server, 
1480
                     MODNAME ": Error parsing exec file '%s': %s",
1525
                     MODNAME ": Error in Rivet_ParseExecFile exec file '%s': %s",
1481
                     r->filename,
1526
                     r->filename,
1482
                     Tcl_GetVar(interp, "errorInfo", 0));
1527
                     Tcl_GetVar(interp, "errorInfo", 0));
1483
    }
1528
    }

Return to bug 57501