int parseAndComputeRuleNewEnv( char *rule, ruleExecInfo_t *rei, int reiSaveFlag, msParamArray_t *msParamArray, rError_t *errmsg, Region *r ) { Env *env = defaultEnv( r ); addCmdExecOutToEnv( globalEnv( env ), r ); int rescode = 0; msParamArray_t *orig = NULL; if ( msParamArray != NULL ) { rescode = convertMsParamArrayToEnv( msParamArray, env->previous, r ); RE_ERROR( rescode < 0 ); } orig = rei->msParamArray; rei->msParamArray = NULL; rescode = parseAndComputeRule( rule, env, rei, reiSaveFlag, errmsg, r ); RE_ERROR( rescode < 0 ); if ( orig == NULL ) { rei->msParamArray = newMsParamArray(); } else { rei->msParamArray = orig; } rescode = convertEnvToMsParamArray( rei->msParamArray, env, errmsg, r ); RE_ERROR( rescode < 0 ); /* deleteEnv(env, 3); */ return rescode; error: /* deleteEnv(env, 3); */ return rescode; }
int parseAndComputeRuleAdapter( char *rule, msParamArray_t *msParamArray, ruleExecInfo_t *rei, int reiSaveFlag, Region *r ) { /* set clearDelayed to 0 so that nested calls to this function do not call clearDelay() */ int recclearDelayed = ruleEngineConfig.clearDelayed; ruleEngineConfig.clearDelayed = 0; rError_t errmsgBuf; errmsgBuf.errMsg = NULL; errmsgBuf.len = 0; Env *env = defaultEnv( r ); rei->status = 0; int rescode = 0; if ( msParamArray != NULL ) { if ( strncmp( rule, "@external\n", 10 ) == 0 ) { rescode = parseAndComputeMsParamArrayToEnv( msParamArray, globalEnv( env ), rei, reiSaveFlag, &errmsgBuf, r ); RE_ERROR( rescode < 0 ); rule = rule + 10; } else { rescode = convertMsParamArrayToEnv( msParamArray, globalEnv( env ), r ); RE_ERROR( rescode < 0 ); } } deleteFromHashTable(globalEnv(env)->current, "ruleExecOut"); rei->msParamArray = msParamArray; rescode = parseAndComputeRule( rule, env, rei, reiSaveFlag, &errmsgBuf, r ); RE_ERROR( rescode < 0 ); if ( NULL == rei->msParamArray ) { rei->msParamArray = newMsParamArray(); } rescode = convertEnvToMsParamArray( rei->msParamArray, env, &errmsgBuf, r ); RE_ERROR( rescode < 0 ); freeRErrorContent( &errmsgBuf ); /* deleteEnv(env, 3); */ return rescode; error: logErrMsg( &errmsgBuf, &rei->rsComm->rError ); rei->status = rescode; freeRErrorContent( &errmsgBuf ); /* deleteEnv(env, 3); */ if ( recclearDelayed ) { clearDelayed(); } ruleEngineConfig.clearDelayed = recclearDelayed; return rescode; }
/* * Set retOutParam to 1 if you need to retrieve the output parameters from inMsParamArray and 0 if not */ Res *parseAndComputeExpressionAdapter( char *inAction, msParamArray_t *inMsParamArray, int retOutParams, ruleExecInfo_t *rei, int reiSaveFlag, Region *r ) { // JMC - backport 4540 /* set clearDelayed to 0 so that nested calls to this function do not call clearDelay() */ int recclearDelayed = ruleEngineConfig.clearDelayed; ruleEngineConfig.clearDelayed = 0; int freeRei = 0; if ( rei == NULL ) { rei = ( ruleExecInfo_t * ) malloc( sizeof( ruleExecInfo_t ) ); memset( rei, 0, sizeof( ruleExecInfo_t ) ); freeRei = 1; } rei->status = 0; Env *env = defaultEnv( r ); /* retrieve generated data here as it may be overridden by convertMsParamArrayToEnv */ Res *res; rError_t errmsgBuf; errmsgBuf.errMsg = NULL; errmsgBuf.len = 0; if ( inMsParamArray != NULL ) { convertMsParamArrayToEnv( inMsParamArray, env, r ); deleteFromHashTable(env->current, "ruleExecOut"); } res = parseAndComputeExpression( inAction, env, rei, reiSaveFlag, &errmsgBuf, r ); if ( retOutParams ) { // JMC - backport 4540 if ( inMsParamArray != NULL ) { clearMsParamArray( inMsParamArray, 0 ); convertEnvToMsParamArray( inMsParamArray, env, &errmsgBuf, r ); } } /* deleteEnv(env, 3); */ if ( getNodeType( res ) == N_ERROR && !freeRei ) { logErrMsg( &errmsgBuf, &rei->rsComm->rError ); rei->status = RES_ERR_CODE( res ); } freeRErrorContent( &errmsgBuf ); if ( freeRei ) { free( rei ); } if ( recclearDelayed ) { clearDelayed(); } ruleEngineConfig.clearDelayed = recclearDelayed; return res; }
int parseAndComputeRuleNewEnv( char *rule, ruleExecInfo_t *rei, int reiSaveFlag, msParamArray_t *msParamArray, rError_t *errmsg, Region *r ) { Env *env = defaultEnv( r ); int rescode = 0; if ( msParamArray != NULL ) { rescode = convertMsParamArrayToEnv( msParamArray, env->previous, r ); RE_ERROR( rescode < 0 ); deleteFromHashTable(env->previous->current, "ruleExecOut"); } rescode = parseAndComputeRule( rule, env, rei, reiSaveFlag, errmsg, r ); RE_ERROR( rescode < 0 ); rescode = convertEnvToMsParamArray( rei->msParamArray, env, errmsg, r ); RE_ERROR( rescode < 0 ); /* deleteEnv(env, 3); */ return rescode; error: /* deleteEnv(env, 3); */ return rescode; }
/* call an action with actionName and string parameters */ Res *computeExpressionWithParams( const char *actionName, const char **params, int paramsCount, ruleExecInfo_t *rei, int reiSaveFlag, msParamArray_t *msParamArray, rError_t *errmsg, Region *r ) { #ifdef DEBUG char buf[ERR_MSG_LEN > 1024 ? ERR_MSG_LEN : 1024]; snprintf( buf, 1024, "computExpressionWithParams: %s\n", actionName ); writeToTmp( "entry.log", buf ); #endif /* set clearDelayed to 0 so that nested calls to this function do not call clearDelay() */ int recclearDelayed = ruleEngineConfig.clearDelayed; ruleEngineConfig.clearDelayed = 0; if ( overflow( actionName, MAX_NAME_LEN ) ) { addRErrorMsg( errmsg, RE_BUFFER_OVERFLOW, "error: potential buffer overflow" ); return newErrorRes( r, RE_BUFFER_OVERFLOW ); } int k; for ( k = 0; k < paramsCount; k++ ) { if ( overflow( params[k], MAX_RULE_LEN ) ) { addRErrorMsg( errmsg, RE_BUFFER_OVERFLOW, "error: potential buffer overflow" ); return newErrorRes( r, RE_BUFFER_OVERFLOW ); } } Node** paramNodes = ( Node ** )region_alloc( r, sizeof( Node * ) * paramsCount ); int i; for ( i = 0; i < paramsCount; i++ ) { Node *node; /*Pointer *e = newPointer2(params[i]); if(e == NULL) { addRErrorMsg(errmsg, -1, "error: can not create Pointer."); return newErrorRes(r, -1); } node = parseTermRuleGen(e, 1, errmsg, r);*/ node = newNode( TK_STRING, params[i], 0, r ); /*if(node==NULL) { addRErrorMsg(errmsg, OUT_OF_MEMORY, "error: out of memory."); return newErrorRes(r, OUT_OF_MEMORY); } else if (getNodeType(node) == N_ERROR) { return newErrorRes(r, RES_ERR_CODE(node)); }*/ paramNodes[i] = node; } Node *node = createFunctionNode( actionName, paramNodes, paramsCount, NULL, r ); Env *global = newEnv( newHashTable2( 10, r ), NULL, NULL, r ); Env *env = newEnv( newHashTable2( 10, r ), global, NULL, r ); if ( msParamArray != NULL ) { convertMsParamArrayToEnv( msParamArray, global, r ); deleteFromHashTable(global->current, "ruleExecOut"); } Res *res = computeNode( node, NULL, env, rei, reiSaveFlag, errmsg, r ); /* deleteEnv(env, 3); */ if ( recclearDelayed ) { clearDelayed(); } ruleEngineConfig.clearDelayed = recclearDelayed; return res; }
int parseAndComputeRuleAdapter( char *rule, msParamArray_t *msParamArray, ruleExecInfo_t *rei, int reiSaveFlag, Region *r ) { /* set clearDelayed to 0 so that nested calls to this function do not call clearDelay() */ int recclearDelayed = ruleEngineConfig.clearDelayed; ruleEngineConfig.clearDelayed = 0; rError_t errmsgBuf; errmsgBuf.errMsg = NULL; errmsgBuf.len = 0; Env *env = defaultEnv( r ); rei->status = 0; msParamArray_t *orig = NULL; Res *execOutRes; int rescode = 0; if ( msParamArray != NULL ) { if ( strncmp( rule, "@external\n", 10 ) == 0 ) { rescode = parseAndComputeMsParamArrayToEnv( msParamArray, globalEnv( env ), rei, reiSaveFlag, &errmsgBuf, r ); RE_ERROR( rescode < 0 ); rule = rule + 10; } else { rescode = convertMsParamArrayToEnv( msParamArray, globalEnv( env ), r ); RE_ERROR( rescode < 0 ); } } if ( ( execOutRes = ( Res * )lookupFromEnv( env, "ruleExecOut" ) ) == NULL || TYPE( execOutRes ) == T_UNSPECED ) { /* add cmdExecOut only if ruleExecOut is an output parameter */ deleteFromHashTable( globalEnv( env )->current, "ruleExecOut" ); addCmdExecOutToEnv( globalEnv( env ), r ); } orig = rei->msParamArray; rei->msParamArray = NULL; rescode = parseAndComputeRule( rule, env, rei, reiSaveFlag, &errmsgBuf, r ); if ( orig == NULL ) { rei->msParamArray = newMsParamArray(); } else { rei->msParamArray = orig; } convertEnvToMsParamArray( rei->msParamArray, env, &errmsgBuf, r ); RE_ERROR( rescode < 0 ); freeRErrorContent( &errmsgBuf ); /* deleteEnv(env, 3); */ return rescode; error: logErrMsg( &errmsgBuf, &rei->rsComm->rError ); rei->status = rescode; freeRErrorContent( &errmsgBuf ); /* deleteEnv(env, 3); */ if ( recclearDelayed ) { clearDelayed(); } ruleEngineConfig.clearDelayed = recclearDelayed; return rescode; }