예제 #1
0
/*
 * @-
 * Access control enforcement. Except for the server owner
 * running a scenario should be explicitly permitted.
 */
static str
runScenarioBody(Client c)
{
	str msg= MAL_SUCCEED;
	lng start;

	c->exception_buf_initialized = 1;
	if (setjmp( c->exception_buf) < 0)
		c->mode = FINISHCLIENT;
	while ((c->mode > FINISHCLIENT || msg != MAL_SUCCEED) && !GDKexiting()) {
		if (msg != MAL_SUCCEED){
/* we should actually show it [postponed]
			mnstr_printf(c->fdout,"!%s\n",msg);
*/
			if (msg != M5OutOfMemory)
				GDKfree(msg);
			msg = MAL_SUCCEED;
		}
		if (!c->state[0] &&
		    (msg = runPhase(c, MAL_SCENARIO_INITCLIENT)) != MAL_SUCCEED)
			continue;
		if (c->mode <= FINISHCLIENT ||
		    (msg = runPhase(c, MAL_SCENARIO_READER)) != MAL_SUCCEED)
			continue;
		c->lastcmd= time(0);
		start= GDKusec();
		if (c->mode <= FINISHCLIENT ||
		    (msg = runPhase(c, MAL_SCENARIO_PARSER)) != MAL_SUCCEED)
			continue;
		if (c->mode <= FINISHCLIENT ||
		    (msg = runPhase(c, MAL_SCENARIO_OPTIMIZE)) != MAL_SUCCEED)
			continue;
		if (c->mode <= FINISHCLIENT ||
                    (msg = runPhase(c, MAL_SCENARIO_SCHEDULER)) != MAL_SUCCEED)
			continue;
		if (c->mode <= FINISHCLIENT ||
		    (msg = runPhase(c, MAL_SCENARIO_ENGINE)) != MAL_SUCCEED)
			continue;
		c->actions++;
		start = GDKusec()-start;
		c->totaltime += start;
	}
	if (c->phase[MAL_SCENARIO_EXITCLIENT])
		(*c->phase[MAL_SCENARIO_EXITCLIENT]) (c);
	c->exception_buf_initialized = 0;
	return msg;
}
예제 #2
0
/*
 * Access control enforcement. Except for the server owner
 * running a scenario should be explicitly permitted.
 */
static str
runScenarioBody(Client c, int once)
{
	str msg= MAL_SUCCEED;

	c->exception_buf_initialized = 1;
	if (setjmp( c->exception_buf) < 0)
		c->mode = FINISHCLIENT;
	while (c->mode > FINISHCLIENT && !GDKexiting()) {
		// be aware that a MAL call  may initialize a different scenario
		if ( !c->state[0] && (msg = runPhase(c, MAL_SCENARIO_INITCLIENT)) ) 
			goto wrapup;
		if ( c->mode <= FINISHCLIENT ||  (msg = runPhase(c, MAL_SCENARIO_READER)) )
			goto wrapup;
		if ( c->mode <= FINISHCLIENT  || (msg = runPhase(c, MAL_SCENARIO_PARSER)) || c->blkmode)
			goto wrapup;
		if ( c->mode <= FINISHCLIENT ||  (msg = runPhase(c, MAL_SCENARIO_OPTIMIZE)) )
			goto wrapup;
		if ( c->mode <= FINISHCLIENT || (msg = runPhase(c, MAL_SCENARIO_SCHEDULER)))
			goto wrapup;
		if ( c->mode <= FINISHCLIENT || (msg = runPhase(c, MAL_SCENARIO_ENGINE)))
			goto wrapup;
	wrapup:
		if (msg != MAL_SUCCEED){
			if(c->phase[MAL_SCENARIO_CALLBACK])
				msg = (str) (*c->phase[MAL_SCENARIO_CALLBACK])(c, msg);
			if (msg) {
				mnstr_printf(c->fdout,"!%s%s", msg, (msg[strlen(msg)-1] == '\n'? "":"\n"));
				freeException(msg);
				msg = MAL_SUCCEED;
			}
		}
		if( GDKerrbuf && GDKerrbuf[0])
			mnstr_printf(c->fdout,"!GDKerror: %s\n",GDKerrbuf);
		assert(c->curprg->def->errors == NULL);
		c->actions++;
		if( once) break;
	}
	c->exception_buf_initialized = 0;
	if (once == 0 && c->phase[MAL_SCENARIO_EXITCLIENT])
		msg = (*c->phase[MAL_SCENARIO_EXITCLIENT]) (c);
	return msg;
}