static int run_websh_script()

in src/generic/mod_websh.c [227:344]


static int run_websh_script(request_rec * r)
{

    WebInterp *webInterp = NULL;
    websh_server_conf *conf =
	(websh_server_conf *) ap_get_module_config(r->server->module_config,
						   &websh_module);

    /* checkme: check type of timeout in MP case */
    /* ap_soft_timeout("!!! timeout for run_websh_script expired", r); */

#ifndef APACHE2

    /* ap_log_printf(r->server,"mtime of %s: %ld",r->filename,r->finfo.st_mtime); */
    webInterp = poolGetWebInterp(conf, r->filename, r->finfo.st_mtime, r);
    if (webInterp == NULL || webInterp->interp == NULL) {
	ap_log_printf(r->server, "mod_websh - no interp!");
	return 0;
    }

#else /* APACHE2 */

    /* ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r, "mtime of %s: %ld",r->filename,r->finfo.mtime); */
    webInterp = poolGetWebInterp(conf, r->filename, (long) r->finfo.mtime, r);
    /* ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r, "got pool %p", webInterp); */
    if (webInterp == NULL || webInterp->interp == NULL) {
	ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0, r,
		      "mod_websh - no interp!");
	return 0;
    }

#endif /* APACHE2 */

    if (Tcl_InterpDeleted(webInterp->interp)) {
#ifndef APACHE2
	ap_log_printf(r->server,
		      "mod_websh - hey, somebody is deleting the interp!");
#else /* APACHE2 */
	ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0, r,
		      "mod_websh - hey, somebody is deleting the interp!");
#endif /* APACHE2 */
	return 0;
    }

    Tcl_SetAssocData(webInterp->interp, WEB_AP_ASSOC_DATA, NULL,
		     (ClientData) r);

    Tcl_SetAssocData(webInterp->interp, WEB_INTERP_ASSOC_DATA, NULL,
		     (ClientData) webInterp);

    if (createApchannel(webInterp->interp, r) != TCL_OK) {
#ifndef APACHE2
	ap_log_printf(r->server, "mod_websh - cannot create apchannel");
#else /* APACHE2 */
	ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0, r,
		      "mod_websh - cannot create apchannel");
#endif /* APACHE2 */
	return 0;
    }

    if (Tcl_Eval(webInterp->interp, "web::ap::perReqInit") != TCL_OK) {
#ifndef APACHE2
	ap_log_printf(r->server,
		      "mod_websh - cannot init per-request Websh code: %s", Tcl_GetStringResult(webInterp->interp));
#else /* APACHE2 */
	ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0, r,
		      "mod_websh - cannot init per-request Websh code: %s", Tcl_GetStringResult(webInterp->interp));
#endif /* APACHE2 */
	return 0;
    }

    if (webInterp->code != NULL) {
	int res = 0;

	Tcl_IncrRefCount(webInterp->code);
	res = Tcl_EvalObjEx(webInterp->interp, webInterp->code, 0);
	Tcl_DecrRefCount(webInterp->code);

	if (res != TCL_OK) {

	    char *errorInfo = NULL;
	    errorInfo =
		(char *) Tcl_GetVar(webInterp->interp, "errorInfo", TCL_GLOBAL_ONLY);
	    logToAp(webInterp->interp, NULL, errorInfo);
	}

	Tcl_ResetResult(webInterp->interp);
    }

    if (Tcl_Eval(webInterp->interp, "web::ap::perReqCleanup") != TCL_OK) {
#ifndef APACHE2
	ap_log_printf(r->server, "mod_websh - error while cleaning-up: %s", Tcl_GetStringResult(webInterp->interp));
#else /* APACHE2 */
	ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0, r,
		      "mod_websh - error while cleaning-up: %s", Tcl_GetStringResult(webInterp->interp));
#endif /* APACHE2 */
	return 0;
    }

    if (destroyApchannel(webInterp->interp) != TCL_OK) {
#ifndef APACHE2
	ap_log_printf(r->server, "mod_websh - error closing ap-channel");
#else /* APACHE2 */
	ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0, r,
		      "mod_websh - error closing ap-channel");
#endif /* APACHE2 */
	return 0;
    }

    Tcl_DeleteAssocData(webInterp->interp, WEB_AP_ASSOC_DATA);
    Tcl_DeleteAssocData(webInterp->interp, WEB_INTERP_ASSOC_DATA);

    poolReleaseWebInterp(webInterp);

    /* ap_kill_timeout(r); */

    return 1;
}