예제 #1
0
파일: rules.cpp 프로젝트: irods/irods
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;


}
예제 #2
0
파일: rules.cpp 프로젝트: irods/irods
/*
 * 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;

}
예제 #3
0
/**
 * \fn msiDeleteCollByAdmin (msParam_t *xparColl, msParam_t *xchildName, ruleExecInfo_t *rei)
 *
 * \brief   This microservice deletes a collection by administrator
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author  Wayne Schroeder
 * \date  2008 or before
 *
 * \note Should not be used outside of the rules defined in core.irb.
 * This is called via an 'iadmin' command.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] xparColl - a msParam of type STR_MS_T
 * \param[in] xchildName - a msParam of type STR_MS_T
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence rei->rsComm->clientUser.authFlag (must be admin)
 * \DolVarModified none
 * \iCatAttrDependence checks various tables
 * \iCatAttrModified updates various tables
 * \sideeffect none
 *
 * \return integer
 * \retval (i)
 * \pre none
 * \post none
 * \sa none
 **/
int msiDeleteCollByAdmin( msParam_t* xparColl, msParam_t* xchildName, ruleExecInfo_t *rei ) {
    int i;
    collInfo_t collInfo;
    char *parColl;
    char *childName;

    parColl = ( char * ) xparColl->inOutStruct;
    childName = ( char * ) xchildName->inOutStruct;
    /**** This is Just a Test Stub  ****/
    if ( reTestFlag > 0 ) {
        if ( reTestFlag == COMMAND_TEST_1 || reTestFlag == HTML_TEST_1 ) {
            fprintf( stdout, "  NewCollection =%s/%s\n",
                     parColl, childName );
        }
        else {
            rodsLog( LOG_NOTICE, "   Calling msiDeleteCallByAdmin Coll: %s/%s\n",
                     parColl, childName );
        }
        rodsLog( LOG_NOTICE,
                 "   Test mode, returning without performing normal operations (chlDelCollByAdmin)" );
        return ( 0 );
    }
    /**** End of Test Stub  ****/

    snprintf( collInfo.collName, sizeof( collInfo.collName ),
              "%s/%s", parColl, childName );
    snprintf( collInfo.collOwnerName, sizeof( collInfo.collOwnerName ),
              "%s", rei->uoio->userName );
    snprintf( collInfo.collOwnerZone, sizeof( collInfo.collOwnerZone ),
              "%s", rei->uoio->rodsZone );

#ifdef RODS_CAT
    i = chlDelCollByAdmin( rei->rsComm, &collInfo );
#else
    i = SYS_NO_RCAT_SERVER_ERR;
#endif
    if ( i == CAT_UNKNOWN_COLLECTION ) {
        /* Not sure where this kind of logic belongs, chl, rules,
           or here; but for now it's here.  */
        /* If the error is that it does not exist, return OK. */
        freeRErrorContent( &rei->rsComm->rError ); /* remove suberrors if any */
        return ( 0 );
    }
    return ( i );
}
예제 #4
0
int
sendAndProcApiReply( rsComm_t * rsComm, int apiInx, int status,
                     void * myOutStruct, bytesBuf_t * myOutBsBBuf ) {
    int retval;

    retval = sendApiReply( rsComm, apiInx, status, myOutStruct, myOutBsBBuf );

    clearBBuf( myOutBsBBuf );
    if ( myOutStruct != NULL ) {
        free( myOutStruct );
    }
    freeRErrorContent( &rsComm->rError );

    /* check for portal operation */

    if ( rsComm->portalOpr != NULL ) {
        handlePortalOpr( rsComm );
        clearKeyVal( &rsComm->portalOpr->dataOprInp.condInput );
        free( rsComm->portalOpr );
        rsComm->portalOpr = NULL;
    }

    return retval;
}
예제 #5
0
파일: collection.cpp 프로젝트: bpow/irods
int
rsQueryDataObjInCollReCur( rsComm_t *rsComm, char *collection,
                           genQueryInp_t *genQueryInp, genQueryOut_t **genQueryOut, char *accessPerm,
                           int singleFlag ) {
    char collQCond[MAX_NAME_LEN * 2];
    int status = 0;
    char accStr[LONG_NAME_LEN];

    if ( genQueryInp == NULL ||
            collection  == NULL ||
            genQueryOut == NULL ) {
        return USER__NULL_INPUT_ERR;
    }

    memset( genQueryInp, 0, sizeof( genQueryInp_t ) );

    genAllInCollQCond( collection, collQCond );

    addInxVal( &genQueryInp->sqlCondInp, COL_COLL_NAME, collQCond );

    addInxIval( &genQueryInp->selectInp, COL_D_DATA_ID, 1 );
    addInxIval( &genQueryInp->selectInp, COL_COLL_NAME, 1 );
    addInxIval( &genQueryInp->selectInp, COL_DATA_NAME, 1 );

    if ( singleFlag == 0 ) {
        addInxIval( &genQueryInp->selectInp, COL_DATA_REPL_NUM, 1 );
        addInxIval( &genQueryInp->selectInp, COL_D_RESC_NAME, 1 );
        addInxIval( &genQueryInp->selectInp, COL_D_DATA_PATH, 1 );
    }

    addInxIval( &genQueryInp->selectInp, COL_D_RESC_HIER, 1 );

    if ( accessPerm != NULL ) {
        snprintf( accStr, LONG_NAME_LEN, "%s", rsComm->clientUser.userName );
        addKeyVal( &genQueryInp->condInput, USER_NAME_CLIENT_KW, accStr );

        snprintf( accStr, LONG_NAME_LEN, "%s", rsComm->clientUser.rodsZone );
        addKeyVal( &genQueryInp->condInput, RODS_ZONE_CLIENT_KW, accStr );

        snprintf( accStr, LONG_NAME_LEN, "%s", accessPerm );
        addKeyVal( &genQueryInp->condInput, ACCESS_PERMISSION_KW, accStr );
        /* have to set it to 1 because it only check the first one */
        genQueryInp->maxRows = 1;
        status =  rsGenQuery( rsComm, genQueryInp, genQueryOut );
        rmKeyVal( &genQueryInp->condInput, USER_NAME_CLIENT_KW );
        rmKeyVal( &genQueryInp->condInput, RODS_ZONE_CLIENT_KW );
        rmKeyVal( &genQueryInp->condInput, ACCESS_PERMISSION_KW );
    }
    else {
        genQueryInp->maxRows = MAX_SQL_ROWS;
        status = trySpecificQueryDataObjInCollReCur(
                     rsComm,
                     collection,
                     genQueryOut );
        if ( status < 0 && status != CAT_NO_ROWS_FOUND ) {
            rodsLog(
                LOG_NOTICE,
                "Note: DataObjInCollReCur specific-Query failed (not defined?), running standard query, status=%d",
                status );
            /* remove the level 0 error msg added by the specific-query failure */
            status = freeRErrorContent( &rsComm->rError );
            /* fall back to the general-query call which used before this
               specific-query was added (post 3.3.1) */
            genQueryInp->maxRows = MAX_SQL_ROWS;
            status =  rsGenQuery( rsComm, genQueryInp, genQueryOut );
        }

    }

    return status;

}
예제 #6
0
int readRuleStructAndRuleSetFromFile( char *ruleBaseName, ruleStruct_t *inRuleStrct ) {
    /*  int i; */
    /*  char l0[MAX_RULE_LENGTH]; */
    /*  char l1[MAX_RULE_LENGTH]; */
    /*  char l2[MAX_RULE_LENGTH]; */
    /*  char l3[MAX_RULE_LENGTH]; */
    char rulesFileName[MAX_NAME_LEN];
    /*   FILE *file; */
    /*   char buf[MAX_RULE_LENGTH]; */
    //char *configDir;
    /*   char *t; */
    /*   i = inRuleStrct->MaxNumOfRules; */

    if ( ruleBaseName[0] == '/' || ruleBaseName[0] == '\\' ||
            ruleBaseName[1] == ':' ) {
        snprintf( rulesFileName, MAX_NAME_LEN, "%s", ruleBaseName );
    }
    else {
        //configDir = getConfigDir();
        //snprintf( rulesFileName, MAX_NAME_LEN, "%s/reConfigs/%s.re", configDir, ruleBaseName );
        std::string cfg_file, fn( ruleBaseName );
        fn += ".re";
        irods::error ret = irods::get_full_path_for_config_file( fn, cfg_file );
        if ( !ret.ok() ) {
            irods::log( PASS( ret ) );
            return ret.code();
        }
        strncpy( rulesFileName, cfg_file.c_str(), MAX_NAME_LEN );
    }
    /*file = fopen(rulesFileName, "r");
    if (file == NULL) {
    #ifndef DEBUG
        rodsLog(LOG_NOTICE,
         "readRuleStructFromFile() could not open rules file %s\n",
         rulesFileName);
    #endif
      return RULES_FILE_READ_ERROR;
    }
    buf[MAX_RULE_LENGTH-1]='\0';
    while (fgets (buf, MAX_RULE_LENGTH-1, file) != NULL) {
      if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
      if (buf[0] == '#' || strlen(buf) < 4)
        continue;
    	char *l0, *l2, *l3;
    	// rSplitStr(buf, l1, MAX_RULE_LENGTH, l0, MAX_RULE_LENGTH, '|');
    	l0 = nextRuleSection(buf, l1);
      inRuleStrct->action[i] = strdup(l1);
      inRuleStrct->ruleHead[i] = strdup(l1);
      if ((t = strstr(inRuleStrct->action[i],"(")) != NULL) {
        *t = '\0';
      }
      inRuleStrct->ruleBase[i] = strdup(ruleBaseName);
    	// rSplitStr(l0, l1, MAX_RULE_LENGTH, l3, MAX_RULE_LENGTH,'|');
    	l3 = nextRuleSection(l0, l1);
      inRuleStrct->ruleCondition[i] = strdup(l1);
    	// rSplitStr(l3, l1, MAX_RULE_LENGTH, l2, MAX_RULE_LENGTH, '|');
    	l2 = nextRuleSection(l3, l1);
      inRuleStrct->ruleAction[i] = strdup(l1);
      inRuleStrct->ruleRecovery[i] = strdup(l2);
      i++;
    }
    fclose (file);
    inRuleStrct->MaxNumOfRules = i;*/
    int errloc;
    rError_t errmsgBuf;
    errmsgBuf.errMsg = NULL;
    errmsgBuf.len = 0;

    char *buf = ( char * ) malloc( ERR_MSG_LEN * 1024 * sizeof( char ) );
    int res = 0;
    if ( inRuleStrct == &coreRuleStrct ) {
        if ( ( res = readRuleSetFromFile( ruleBaseName, ruleEngineConfig.coreRuleSet, ruleEngineConfig.coreFuncDescIndex, &errloc, &errmsgBuf, ruleEngineConfig.coreRegion ) ) == 0 ) {
        }
        else {
            errMsgToString( &errmsgBuf, buf, ERR_MSG_LEN * 1024 );
            rodsLog( LOG_ERROR, "%s", buf );
        }
    }
    else if ( inRuleStrct == &appRuleStrct ) {
        if ( ( res = readRuleSetFromFile( ruleBaseName, ruleEngineConfig.appRuleSet, ruleEngineConfig.appFuncDescIndex, &errloc, &errmsgBuf, ruleEngineConfig.appRegion ) ) == 0 ) {
        }
        else {
            errMsgToString( &errmsgBuf, buf, ERR_MSG_LEN * 1024 );
            rodsLog( LOG_ERROR, "%s", buf );
        }
    }
    free( buf );
    freeRErrorContent( &errmsgBuf );
    return res;
}
예제 #7
0
int processXMsg( int streamId, char *readmsg,
                 RuleEngineEventParam *param, Node *node,
                 Env *env, ruleExecInfo_t *rei ) {

    char myhdr[HEADER_TYPE_LEN];
    char mymsg[MAX_NAME_LEN];
    char *outStr = NULL;
    int i, n;
    int iLevel, wCnt;
    int  ruleInx = 0;
    Region *r;
    Res *res;
    rError_t errmsg;
    errmsg.len = 0;
    errmsg.errMsg = NULL;
    r = make_region( 0, NULL );
    ParserContext *context = newParserContext( &errmsg, r );
    Pointer *e = newPointer2( readmsg );
    int rulegen = 1;
    int found;
    int grdf[2];
    int cmd = 0;
    int smallW;

    snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug:%s", param->actionName );
    memset( mymsg, 0, sizeof( mymsg ) );

    PARSER_BEGIN( DbgCmd )
    TRY( DbgCmd )
    TTEXT2( "n", "next" );
    cmd = REDEBUG_STEP_OVER;
    OR( DbgCmd )
    TTEXT2( "s", "step" );
    cmd = REDEBUG_NEXT;
    OR( DbgCmd )
    TTEXT2( "f", "finish" );
    cmd = REDEBUG_STEP_OUT;
    OR( DbgCmd )
    TTEXT2( "b", "break" );
    TRY( Param )
    TTYPE( TK_TEXT );
    int breakPointsInx2;
    for ( breakPointsInx2 = 0; breakPointsInx2 < 100; breakPointsInx2++ ) {
        if ( breakPoints[breakPointsInx2].actionName == NULL ) {
            break;
        }
    }
    if ( breakPointsInx2 == 100 ) {
        _writeXMsg( streamId, myhdr, "Maximum breakpoint count reached. Breakpoint not set.\n" );
        cmd = REDEBUG_WAIT;
    }
    else {
        breakPoints[breakPointsInx2].actionName = strdup( token->text );
        char * base_ptr = NULL;
        TRY( loc )
        TTYPE( TK_TEXT );
        base_ptr = ( char * ) malloc( sizeof( token->text ) + 2 );
        base_ptr[0] = 'f';
        strcpy( base_ptr + 1, token->text );
        TTEXT( ":" );
        TTYPE( TK_INT );
        breakPoints[breakPointsInx2].base = strdup( base_ptr );
        breakPoints[breakPointsInx2].line = atoi( token->text );
        rodsLong_t range[2];
        char rulesFileName[MAX_NAME_LEN];
        getRuleBasePath( base_ptr, rulesFileName );

        FILE *file;
        /* char errbuf[ERR_MSG_LEN]; */
        file = fopen( rulesFileName, "r" );
        if ( file == NULL ) {
            free( context );
            deletePointer( e );
            free( base_ptr );
            return RULES_FILE_READ_ERROR;
        }
        Pointer *p = newPointer( file, base_ptr );


        if ( getLineRange( p, breakPoints[breakPointsInx2].line, range ) == 0 ) {
            breakPoints[breakPointsInx2].start = range[0];
            breakPoints[breakPointsInx2].finish = range[1];
        }
        else {
            breakPoints[breakPointsInx2].actionName = NULL;
        }
        deletePointer( p );
        OR( loc )
        TTYPE( TK_INT );
        if ( node != NULL ) {
            breakPoints[breakPointsInx2].base = strdup( node->base );
            breakPoints[breakPointsInx2].line = atoi( token->text );
            rodsLong_t range[2];
            Pointer *p = newPointer2( breakPoints[breakPointsInx2].base );
            if ( getLineRange( p, breakPoints[breakPointsInx2].line, range ) == 0 ) {
                breakPoints[breakPointsInx2].start = range[0];
                breakPoints[breakPointsInx2].finish = range[1];
            }
            else {
                breakPoints[breakPointsInx2].actionName = NULL;
            }
            deletePointer( p );
        }
        else {
            breakPoints[breakPointsInx2].actionName = NULL;
        }
        OR( loc )
        /* breakPoints[breakPointsInx].base = NULL; */
        END_TRY( loc )

        free( base_ptr );
        if ( breakPoints[breakPointsInx2].actionName != NULL )
            snprintf( mymsg, MAX_NAME_LEN, "Breakpoint %i  set at %s\n", breakPointsInx2,
                      breakPoints[breakPointsInx2].actionName );
        else {
            snprintf( mymsg, MAX_NAME_LEN, "Cannot set breakpoint, source not available\n" );
        }
        _writeXMsg( streamId, myhdr, mymsg );
        if ( breakPointsInx <= breakPointsInx2 ) {
            breakPointsInx = breakPointsInx2 + 1;
        }
        cmd = REDEBUG_WAIT;
    }
    OR( Param )
    NEXT_TOKEN_BASIC;
    _writeXMsg( streamId, myhdr, "Unknown parameter type.\n" );
    cmd = REDEBUG_WAIT;
    OR( Param )
    _writeXMsg( streamId, myhdr, "Debugger command \'break\' requires at least one argument.\n" );
    cmd = REDEBUG_WAIT;
    END_TRY( Param )

    OR( DbgCmd )
    TRY( Where )
    TTEXT2( "w", "where" );
    smallW = 1;
    OR( Where )
    TTEXT2( "W", "Where" );
    smallW = 0;
    END_TRY( Where )
    wCnt = 20;
    OPTIONAL_BEGIN( Param )
    TTYPE( TK_INT );
    wCnt = atoi( token->text );
    OPTIONAL_END( Param )
    iLevel = 0;

    i = reDebugStackCurrPtr - 1;
    while ( i >= 0 && wCnt > 0 ) {
        if ( !smallW || ( reDebugPCType( ( RuleEngineEvent ) reDebugStackCurr[i].label ) & 1 ) != 0 ) {
            snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug: Level %3i", iLevel );
            char msg[HEADER_TYPE_LEN - 1];
            RuleEngineEventParam param;
            param.ruleIndex = 0;
            param.actionName = reDebugStackCurr[i].step;
            printRuleEngineEventLabel( msg, HEADER_TYPE_LEN - 1, ( RuleEngineEvent ) reDebugStackCurr[i].label, &param );
            _writeXMsg( streamId,  myhdr, msg );
            if ( reDebugStackCurr[i].label != EXEC_ACTION_BEGIN ) {
                iLevel++;
            }
            wCnt--;
        }
        i--;
    }
    OR( DbgCmd )
    TTEXT2( "l", "list" );
    TRY( Param )
    TTEXT2( "r", "rule" );
    TRY( ParamParam )
    TTYPE( TK_TEXT );

    mymsg[0] = '\n';
    mymsg[1] = '\0';
    snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug: Listing %s", token->text );
    RuleIndexListNode *node;
    found = 0;
    while ( findNextRule2( token->text, ruleInx, &node ) != NO_MORE_RULES_ERR ) {
        found = 1;
        if ( node->secondaryIndex ) {
            n = node->condIndex->valIndex->len;
            int i;
            for ( i = 0; i < n; i++ ) {
                Bucket *b = node->condIndex->valIndex->buckets[i];
                while ( b != NULL ) {
                    RuleDesc *rd = getRuleDesc( *( int * )b->value );
                    char buf[MAX_RULE_LEN];
                    ruleToString( buf, MAX_RULE_LEN, rd );
                    snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "%i: %s\n%s\n", node->ruleIndex, rd->node->base[0] == 's' ? "<source>" : rd->node->base + 1, buf );
                    b = b->next;
                }
            }
        }
        else {
            RuleDesc *rd = getRuleDesc( node->ruleIndex );
            char buf[MAX_RULE_LEN];
            ruleToString( buf, MAX_RULE_LEN, rd );
            snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "\n  %i: %s\n%s\n", node->ruleIndex, rd->node->base[0] == 's' ? "<source>" : rd->node->base + 1, buf );
        }
        ruleInx ++;
    }
    if ( !found ) {
        snprintf( mymsg, MAX_NAME_LEN, "Rule %s not found\n", token->text );
    }
    _writeXMsg( streamId, myhdr, mymsg );
    cmd = REDEBUG_WAIT;
    OR( ParamParam )
    _writeXMsg( streamId, myhdr, "Debugger command \'list rule\' requires one argument.\n" );
    cmd = REDEBUG_WAIT;
    END_TRY( ParamParam )
    OR( Param )
    TTEXT2( "b", "breakpoints" );
    snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug: Listing %s", token->text );
    mymsg[0] = '\n';
    mymsg[1] = '\0';
    for ( i = 0; i < breakPointsInx; i++ ) {
        if ( breakPoints[i].actionName != NULL ) {
            if ( breakPoints[i].base != NULL ) {
                snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "Breaking at BreakPoint %i:%s %s:%d\n", i , breakPoints[i].actionName, breakPoints[i].base[0] == 's' ? "<source>" : breakPoints[i].base + 1, breakPoints[i].line );
            }
            else {
                snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "Breaking at BreakPoint %i:%s\n", i , breakPoints[i].actionName );
            }
        }
    }
    _writeXMsg( streamId, myhdr, mymsg );
    cmd = REDEBUG_WAIT;
    OR( Param )
    TTEXT( "*" );
    snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug: Listing %s", token->text );
    Env *cenv = env;
    mymsg[0] = '\n';
    mymsg[1] = '\0';
    found = 0;
    while ( cenv != NULL ) {
        n = cenv->current->size;
        for ( i = 0; i < n; i++ ) {
            Bucket *b = cenv->current->buckets[i];
            while ( b != NULL ) {
                if ( b->key[0] == '*' ) { /* skip none * variables */
                    found = 1;
                    char typeString[128];
                    typeToString( ( ( Res * )b->value )->exprType, NULL, typeString, 128 );
                    snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "%s of type %s\n", b->key, typeString );
                }
                b = b->next;
            }
        }
        cenv = cenv->previous;
    }
    if ( !found ) {
        snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "<empty>\n" );
    }
    _writeXMsg( streamId, myhdr, mymsg );
    cmd = REDEBUG_WAIT;
    OR( Param )
    syncTokenQueue( e, context );
    skipWhitespace( e );
    ABORT( lookAhead( e, 0 ) != '$' );
    snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug: Listing %s", token->text );
    mymsg[0] = '\n';
    mymsg[1] = '\0';
    Hashtable *vars = newHashTable( 100 );
    for ( i = 0; i < coreRuleVarDef .MaxNumOfDVars; i++ ) {
        if ( lookupFromHashTable( vars, coreRuleVarDef.varName[i] ) == NULL ) {
            snprintf( &mymsg[strlen( mymsg )], MAX_NAME_LEN - strlen( mymsg ), "$%s\n", coreRuleVarDef.varName[i] );
            insertIntoHashTable( vars, coreRuleVarDef.varName[i], coreRuleVarDef.varName[i] );
        }
    }
    deleteHashTable( vars, NULL );
    _writeXMsg( streamId, myhdr, mymsg );
    cmd = REDEBUG_WAIT;
    OR( Param )
    NEXT_TOKEN_BASIC;
    _writeXMsg( streamId, myhdr, "Unknown parameter type.\n" );
    cmd = REDEBUG_WAIT;
    OR( Param )
    _writeXMsg( streamId, myhdr, "Debugger command \'list\' requires at least one argument.\n" );
    cmd = REDEBUG_WAIT;
    END_TRY( Param )
    OR( DbgCmd )
    TTEXT2( "c", "continue" );
    cmd = REDEBUG_STEP_CONTINUE;
    OR( DbgCmd )
    TTEXT2( "C", "Continue" );
    cmd = REDEBUG_CONTINUE_VERBOSE;
    OR( DbgCmd )
    TTEXT2( "del", "delete" );
    TRY( Param )
    TTYPE( TK_INT );
    n = atoi( token->text );
    if ( breakPoints[n].actionName != NULL ) {
        free( breakPoints[n].actionName );
        if ( breakPoints[n].base != NULL ) {
            free( breakPoints[n].base );
        }
        breakPoints[n].actionName = NULL;
        breakPoints[n].base = NULL;
        snprintf( mymsg, MAX_NAME_LEN, "Breakpoint %i  deleted\n", n );
    }
    else {
        snprintf( mymsg, MAX_NAME_LEN, "Breakpoint %i  has not been defined\n", n );
    }
    _writeXMsg( streamId, myhdr, mymsg );
    cmd = REDEBUG_WAIT;
    OR( Param )
    _writeXMsg( streamId, myhdr, "Debugger command \'delete\' requires one argument.\n" );
    cmd = REDEBUG_WAIT;
    END_TRY( Param )
    OR( DbgCmd )
    TTEXT2( "p", "print" );
    Node *n = parseTermRuleGen( e, 1, context );
    if ( getNodeType( n ) == N_ERROR ) {
        errMsgToString( context->errmsg, mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ) );
    }
    else {
        snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug: Printing " );
        char * ptr = myhdr + strlen( myhdr );
        i = HEADER_TYPE_LEN - 1 - strlen( myhdr );
        termToString( &ptr, &i, 0, MIN_PREC, n, 0 );
        snprintf( ptr, i, "\n" );
        if ( env != NULL ) {
            disableReDebugger( grdf );
            res = computeNode( n, NULL, regionRegionCpEnv( env, r, ( RegionRegionCopyFuncType * ) regionRegionCpNode ), rei, 0, &errmsg, r );
            enableReDebugger( grdf );
            outStr = convertResToString( res );
            snprintf( mymsg, MAX_NAME_LEN, "%s\n", outStr );
            free( outStr );
            if ( getNodeType( res ) == N_ERROR ) {
                errMsgToString( &errmsg, mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ) );
            }
        }
        else {
            snprintf( mymsg, MAX_NAME_LEN, "Runtime environment: <empty>\n" );
        }
    }
    _writeXMsg( streamId, myhdr, mymsg );

    cmd = REDEBUG_WAIT;
    OR( DbgCmd )
    TTEXT2( "d", "discontinue" );
    cmd = REDEBUG_WAIT;
    OR( DbgCmd )
    snprintf( mymsg, MAX_NAME_LEN, "Unknown Action: %s", readmsg );
    _writeXMsg( streamId, myhdr, mymsg );
    cmd = REDEBUG_WAIT;
    END_TRY( DbgCmd )
    PARSER_END( DbgCmd )
    freeRErrorContent( &errmsg );
    region_free( r );
    deletePointer( e );
    free( context );
    return cmd;
}
예제 #8
0
파일: rules.cpp 프로젝트: irods/irods
ExprType *typeRuleSet( RuleSet *ruleset, rError_t *errmsg, Node **errnode, Region *r ) {
    Env *funcDesc = ruleEngineConfig.extFuncDescIndex;
    Hashtable *ruleType = newHashTable2( MAX_NUM_RULES * 2, r );
    ExprType *res;
    int i;
    for ( i = 0; i < ruleset->len; i++ ) {
        RuleDesc *rule = ruleset->rules[i];
        if ( rule->ruleType == RK_REL || rule->ruleType == RK_FUNC ) {
            List *typingConstraints = newList( r );
            Hashtable *varTypes = newHashTable2( 100, r );
            ExprType *restype = typeRule( rule, funcDesc, varTypes, typingConstraints, errmsg, errnode, r );
            /*char buf[1024]; */
            /*typingConstraintsToString(typingConstraints, buf, 1024); */
            /*printf("rule %s, typing constraints: %s\n", ruleset->rules[i]->subtrees[0]->text, buf); */
            if ( getNodeType( restype ) == T_ERROR ) {
                res = restype;
                char *errbuf = ( char * ) malloc( ERR_MSG_LEN * 1024 * sizeof( char ) );
                errMsgToString( errmsg, errbuf, ERR_MSG_LEN * 1024 );
#ifdef DEBUG
                writeToTmp( "ruleerr.log", errbuf );
                writeToTmp( "ruleerr.log", "\n" );
#endif
                rodsLog( LOG_ERROR, "%s", errbuf );
                free( errbuf );
                freeRErrorContent( errmsg );
                RETURN;
            }
            /* check that function names are unique and do not conflict with system msis */
            char errbuf[ERR_MSG_LEN];
            char *ruleName = rule->node->subtrees[0]->text;
            FunctionDesc *fd;
            if ( ( fd = ( FunctionDesc * )lookupFromEnv( funcDesc, ruleName ) ) != NULL ) {
                if ( getNodeType( fd ) != N_FD_EXTERNAL && getNodeType( fd ) != N_FD_RULE_INDEX_LIST ) {
                    char *err;
                    switch ( getNodeType( fd ) ) {
                    case N_FD_CONSTRUCTOR:
                        err = "redefinition of constructor";
                        break;
                    case N_FD_DECONSTRUCTOR:
                        err = "redefinition of deconstructor";
                        break;
                    case N_FD_FUNCTION:
                        err = "redefinition of system microservice";
                        break;
                    default:
                        err = "redefinition of system symbol";
                        break;
                    }

                    generateErrMsg( err, NODE_EXPR_POS( rule->node ), rule->node->base, errbuf );
                    addRErrorMsg( errmsg, RE_FUNCTION_REDEFINITION, errbuf );
                    res = newErrorType( RE_FUNCTION_REDEFINITION, r );
                    *errnode = rule->node;
                    RETURN;
                }
            }

            RuleDesc *rd = ( RuleDesc * )lookupFromHashTable( ruleType, ruleName );
            if ( rd != NULL ) {
                if ( rule->ruleType == RK_FUNC || rd ->ruleType == RK_FUNC ) {
                    generateErrMsg( "redefinition of function", NODE_EXPR_POS( rule->node ), rule->node->base, errbuf );
                    addRErrorMsg( errmsg, RE_FUNCTION_REDEFINITION, errbuf );
                    generateErrMsg( "previous definition", NODE_EXPR_POS( rd->node ), rd->node->base, errbuf );
                    addRErrorMsg( errmsg, RE_FUNCTION_REDEFINITION, errbuf );
                    res = newErrorType( RE_FUNCTION_REDEFINITION, r );
                    *errnode = rule->node;
                    RETURN;
                }
            }
            else {
                insertIntoHashTable( ruleType, ruleName, rule );
            }
        }
    }
    res = newSimpType( T_INT, r ); /* Although a rule set does not have type T_INT, return T_INT to indicate success. */

ret:
    return res;
}
예제 #9
0
파일: rules.cpp 프로젝트: bpow/irods
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;


}