Пример #1
0
int checkCollIsEmpty( rcComm_t *conn, rodsArguments_t *myRodsArgs, const char *collPath ) {
    int status;
    genQueryInp_t genQueryInp1, genQueryInp2;
    genQueryOut_t *genQueryOut1 = NULL, *genQueryOut2 = NULL;
    int noDataFound = 0;
    int noCollFound = 0;
    char condStr[MAX_NAME_LEN];

    memset( &genQueryInp1, 0, sizeof( genQueryInp1 ) );
    memset( &genQueryInp2, 0, sizeof( genQueryInp2 ) );

    snprintf( condStr, MAX_NAME_LEN, "select COLL_ID where COLL_NAME like '%s/%%'", collPath );
    fillGenQueryInpFromStrCond( condStr, &genQueryInp1 );

    status = rcGenQuery( conn, &genQueryInp1, &genQueryOut1 );

    clearGenQueryInp( &genQueryInp1 );
    freeGenQueryOut( &genQueryOut1 );

    if ( status == CAT_NO_ROWS_FOUND ) {
        noCollFound = 1;
    }

    snprintf( condStr, MAX_NAME_LEN, "select DATA_ID where COLL_NAME like '%s%%'", collPath );
    fillGenQueryInpFromStrCond( condStr, &genQueryInp2 );

    status = rcGenQuery( conn, &genQueryInp2, &genQueryOut2 );

    clearGenQueryInp( &genQueryInp2 );
    freeGenQueryOut( &genQueryOut2 );

    if ( status == CAT_NO_ROWS_FOUND ) {
        noDataFound = 1;
    }

    return ( noDataFound && noCollFound );
}
Пример #2
0
/**
 * \fn msiExecStrCondQuery(msParam_t* queryParam, msParam_t* genQueryOutParam, ruleExecInfo_t *rei)
 *
 * \brief   This function takes a given condition string, creates an iCAT query, executes it and returns the values
 *
 * \module core
 *
 * \since pre-2.1
 *
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] queryParam - a msParam of type GenQueryInp_MS_T
 * \param[out] genQueryOutParam - a msParam of type GenQueryOut_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 none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
**/
int msiExecStrCondQuery( msParam_t* queryParam, msParam_t* genQueryOutParam, ruleExecInfo_t *rei ) {
    genQueryInp_t genQueryInp;
    int i;
    genQueryOut_t *genQueryOut = NULL;
    char *query;

    query = ( char * ) malloc( strlen( ( const char* )queryParam->inOutStruct ) + 10 + MAX_COND_LEN * 8 );

    strcpy( query, ( const char* )queryParam->inOutStruct );

    /**** Jun 27, 2007
    if (queryParam->inOutStruct == NULL) {
      query = (char *) malloc(strlen(queryParam->label) + MAX_COND_LEN);
      strcpy(query , queryParam->label);
    }
    else {
      query = (char *) malloc(strlen(queryParam->inOutStruct) + MAX_COND_LEN);
      strcpy(query , queryParam->inOutStruct);
    }
    i  = replaceVariablesAndMsParams("",query, rei->msParamArray, rei);
    if (i < 0)
      return i;
    ***/
    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    i = fillGenQueryInpFromStrCond( query, &genQueryInp );
    free( query );
    if ( i < 0 ) {
        return i;
    }
    genQueryInp.maxRows = MAX_SQL_ROWS;
    genQueryInp.continueInx = 0;

    i = rsGenQuery( rei->rsComm, &genQueryInp, &genQueryOut );
    if ( i < 0 ) {
        if ( i == CAT_NO_ROWS_FOUND ) {
            genQueryOutParam->type = strdup( GenQueryOut_MS_T );
            genQueryOut = ( genQueryOut_t * ) malloc( sizeof( genQueryOut_t ) );
            memset( genQueryOut, 0, sizeof( genQueryOut_t ) );
            genQueryOutParam->inOutStruct = genQueryOut;
            return 0;
        }
        else {
            return i;
        }
    }
    genQueryOutParam->type = strdup( GenQueryOut_MS_T );
    genQueryOutParam->inOutStruct = genQueryOut;
    return 0;
}
Пример #3
0
/**
 * \fn msiExecStrCondQuery(msParam_t* queryParam, msParam_t* genQueryOutParam, ruleExecInfo_t *rei)
 *
 * \brief   This function takes a given condition string, creates an iCAT query, executes it and returns the values
 *
 * \module core
 *
 * \since pre-2.1
 *
 *
 * \usage See clients/icommands/test/rules/
 *
 * \param[in] queryParam - a msParam of type GenQueryInp_MS_T
 * \param[out] genQueryOutParam - a msParam of type GenQueryOut_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 none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
**/
int msiExecStrCondQuery( msParam_t* queryParam, msParam_t* genQueryOutParam, ruleExecInfo_t *rei ) {
    genQueryInp_t genQueryInp;
    int i;
    genQueryOut_t *genQueryOut = NULL;
    char *query;

    query = ( char * ) malloc( strlen( ( const char* )queryParam->inOutStruct ) + 10 + MAX_NAME_LEN * 8 );

    strcpy( query, ( const char* )queryParam->inOutStruct );

    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    i = fillGenQueryInpFromStrCond( query, &genQueryInp );
    free( query );
    if ( i < 0 ) {
        return i;
    }
    genQueryInp.maxRows = MAX_SQL_ROWS;
    genQueryInp.continueInx = 0;

    i = rsGenQuery( rei->rsComm, &genQueryInp, &genQueryOut );
    if ( i < 0 ) {
        if ( i == CAT_NO_ROWS_FOUND ) {
            genQueryOutParam->type = strdup( GenQueryOut_MS_T );
            genQueryOut = ( genQueryOut_t * ) malloc( sizeof( genQueryOut_t ) );
            memset( genQueryOut, 0, sizeof( genQueryOut_t ) );
            genQueryOutParam->inOutStruct = genQueryOut;
            return 0;
        }
        else {
            return i;
        }
    }
    genQueryOutParam->type = strdup( GenQueryOut_MS_T );
    genQueryOutParam->inOutStruct = genQueryOut;
    return 0;
}
Пример #4
0
/**
 * \fn msiMakeGenQuery(msParam_t* selectListStr, msParam_t* condStr, msParam_t* genQueryInpParam, ruleExecInfo_t *rei)
 *
 * \brief This microservice sets up a GenQueryInp_MS_T from a list of parameters and conditions
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author  Antoine de Torcy
 * \date    2008-09-19
 *
 * \note This microservice sets up a genQueryInp_t data structure needed by calls to rsGenQuery().
 *    To be used before #msiExecGenQuery and #msiGetMoreRows.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] selectListStr - Required - a STR_MS_T containing the parameters.
 * \param[in] condStr - Required - a STR_MS_T containing the conditions
 * \param[out] genQueryInpParam - a GenQueryInp_MS_T containing the parameters and conditions.
 * \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 none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
**/
int
msiMakeGenQuery( msParam_t* selectListStr, msParam_t* condStr, msParam_t* genQueryInpParam, ruleExecInfo_t *rei ) {
    genQueryInp_t *genQueryInp;
    char *sel, *cond, *rawQuery, *query;


    RE_TEST_MACRO( "    Calling msiMakeGenQuery" )

    if ( rei == NULL || rei->rsComm == NULL ) {
        rodsLog( LOG_ERROR, "msiMakeGenQuery: input rei or rsComm is NULL." );
        return ( SYS_INTERNAL_NULL_INPUT_ERR );
    }


    /* parse selectListStr */
    if ( ( sel = parseMspForStr( selectListStr ) ) == NULL ) {
        rodsLog( LOG_ERROR, "msiMakeGenQuery: input selectListStr is NULL." );
        return ( USER__NULL_INPUT_ERR );
    }


    /* parse condStr */
    if ( ( cond = parseMspForStr( condStr ) ) == NULL ) {
        rodsLog( LOG_ERROR, "msiMakeGenQuery: input condStr is NULL." );
        return ( USER__NULL_INPUT_ERR );
    }


    /* The code below is partly taken from msiMakeQuery and msiExecStrCondQuery. There may be a better way to do this. */

    /* Generate raw SQL query string */
    rei->status = _makeQuery( sel, cond, &rawQuery );

    /* allocate more memory for query string with expanded variable names */
    query = ( char * )malloc( strlen( rawQuery ) + 10 + MAX_COND_LEN * 8 );
    strcpy( query, rawQuery );

    /* allocate memory for genQueryInp */
    genQueryInp = ( genQueryInp_t* )malloc( sizeof( genQueryInp_t ) );
    memset( genQueryInp, 0, sizeof( genQueryInp_t ) );

    /* set up GenQueryInp */
    genQueryInp->maxRows = MAX_SQL_ROWS;
    genQueryInp->continueInx = 0;
    rei->status = fillGenQueryInpFromStrCond( query, genQueryInp );
    if ( rei->status < 0 ) {
        rodsLog( LOG_ERROR, "msiMakeGenQuery: fillGenQueryInpFromStrCond failed." );
        free( rawQuery ); // cppcheck - Memory leak: rawQuery
        return( rei->status );
    }


    /* return genQueryInp through GenQueryInpParam */
    genQueryInpParam->type = strdup( GenQueryInp_MS_T );
    genQueryInpParam->inOutStruct = genQueryInp;


    /* cleanup */
    free( rawQuery );
    free( query );

    return( rei->status );
}
Пример #5
0
/**
 * \fn msiExecStrCondQueryWithOptionsNew(msParam_t* queryParam,
 *        msParam_t* zeroResultsIsOK,
 *        msParam_t* maxReturnedRowsParam,
 *        msParam_t* genQueryOutParam,
 *        ruleExecInfo_t *rei)
 *
 * \brief   This function takes a given condition string and options, creates an iCAT query, executes it and returns the values
 * 			This function returns an empty result set if "zeroOK" instead of a string "emptySet".
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author  Romain Guinot
 * \date    2007
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] queryParam - a msParam of type GenQueryInp_MS_T
 * \param[in] zeroResultsIsOK - Optional - a msParam of type STR_MS_T - must equal "zeroOK"
 * \param[in] maxReturnedRowsParam - Optional - a msParam of type STR_MS_T - as integer
 * \param[out] genQueryOutParam - a msParam of type GenQueryOut_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 none
 * \DolVarModified  none
 * \iCatAttrDependence  none
 * \iCatAttrModified  none
 * \sideeffect  none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa  msiExecStrCondQuery
**/
int msiExecStrCondQueryWithOptionsNew( msParam_t* queryParam,
                                       msParam_t* zeroResultsIsOK,
                                       msParam_t* maxReturnedRowsParam,
                                       msParam_t* genQueryOutParam,
                                       ruleExecInfo_t *rei ) {
    genQueryInp_t genQueryInp;
    int i;
    genQueryOut_t *genQueryOut = NULL;
    char *query;
    char *maxReturnedRowsStr;
    int maxReturnedRows;

    query = ( char * ) malloc( strlen( ( const char* )queryParam->inOutStruct ) + 10 + MAX_COND_LEN * 8 );
    strcpy( query, ( const char* ) queryParam->inOutStruct );

    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    i = fillGenQueryInpFromStrCond( query, &genQueryInp );
    if ( i < 0 ) {
        return( i );
    }

    if ( maxReturnedRowsParam != NULL ) {
        maxReturnedRowsStr = ( char * ) maxReturnedRowsParam->inOutStruct;
        if ( strcmp( maxReturnedRowsStr, "NULL" ) != 0 ) {
            maxReturnedRows = atoi( maxReturnedRowsStr );
            genQueryInp.maxRows = maxReturnedRows;
        }
        else {
            genQueryInp.maxRows = MAX_SQL_ROWS;
        }
    }
    else {
        genQueryInp.maxRows = MAX_SQL_ROWS;
    }

    genQueryInp.continueInx = 0;

    i = rsGenQuery( rei->rsComm, &genQueryInp, &genQueryOut );
    if ( zeroResultsIsOK != NULL &&
            strcmp( ( const char* )zeroResultsIsOK->inOutStruct, "zeroOK" ) == 0 ) {
        if ( i < 0 && i != CAT_NO_ROWS_FOUND ) {
            return( i );
        }
        else if ( i == CAT_NO_ROWS_FOUND ) {
            /* genQueryOutParam->type = strdup(STR_MS_T);
            fillStrInMsParam (genQueryOutParam,"emptySet"); */
            genQueryOutParam->type = strdup( GenQueryOut_MS_T );
            genQueryOut = ( genQueryOut_t * ) malloc( sizeof( genQueryOut_t ) );
            memset( genQueryOut, 0, sizeof( genQueryOut_t ) );
            genQueryOutParam->inOutStruct = genQueryOut;

            return( 0 );
        }
    }
    else {
        if ( i < 0 ) {
            return( i );
        }
    }
    if ( i < 0 ) {
        return( i );
    }
    genQueryOutParam->type = strdup( GenQueryOut_MS_T );
    genQueryOutParam->inOutStruct = genQueryOut;
    return( 0 );
}
Пример #6
0
int
queryAndShowStrCond( rcComm_t *conn, char *hint, char *format,
                     char *selectConditionString, int noDistinctFlag,
                     int upperCaseFlag, char *zoneArgument, int noPageFlag ) {
    /*
      NoDistinctFlag is 1 if the user is requesting 'distinct' to be skipped.
     */

    genQueryInp_t genQueryInp;
    int i;
    genQueryOut_t *genQueryOut = NULL;

    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    i = fillGenQueryInpFromStrCond( selectConditionString, &genQueryInp );
    if ( i < 0 ) {
        return i;
    }

    if ( noDistinctFlag ) {
        genQueryInp.options = NO_DISTINCT;
    }
    if ( upperCaseFlag ) {
        genQueryInp.options = UPPER_CASE_WHERE;
    }

    if ( zoneArgument != 0 && zoneArgument[0] != '\0' ) {
        addKeyVal( &genQueryInp.condInput, ZONE_KW, zoneArgument );
        printf( "Zone is %s\n", zoneArgument );
    }

    genQueryInp.maxRows = MAX_SQL_ROWS;
    genQueryInp.continueInx = 0;
    i = rcGenQuery( conn, &genQueryInp, &genQueryOut );
    if ( i < 0 ) {
        return i;
    }

    i = printGenQueryOut( stdout, format, hint,  genQueryOut );
    if ( i < 0 ) {
        return i;
    }


    while ( i == 0 && genQueryOut->continueInx > 0 ) {
        if ( noPageFlag == 0 ) {
            char inbuf[100];
            printf( "Continue? [Y/n]" );
            std::string response = "";
            getline( std::cin, response );
            strncpy( inbuf, response.c_str(), 90 );
            if ( strncmp( inbuf, "n", 1 ) == 0 ) {
                break;
            }
        }
        genQueryInp.continueInx = genQueryOut->continueInx;
        i = rcGenQuery( conn, &genQueryInp, &genQueryOut );
        if ( i < 0 ) {
            if (i==CAT_NO_ROWS_FOUND) {
                return 0;
            } else {
                return i;
            }
        }
        i = printGenQueryOut( stdout, format, hint,  genQueryOut );
        if ( i < 0 ) {
            return i;
        }
    }

    return 0;

}
Пример #7
0
/**
 * \fn msiDataObjAutoMove(msParam_t *inpParam1, msParam_t *inpParam2, msParam_t *inpParam3,
 *                      msParam_t *inpParam4, msParam_t *inpParam5, ruleExecInfo_t *rei)
 *
 * \brief This microservice is used to automatically move the newly created file into a destination collection.
 *
 * \module core
 *
 * \since 2.2
 *
 * \author  Bing Zhu
 * \date    2009-07
 *
 * \note This microservice changes the ownership for the dataset(s) being moved.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] inpParam1 - a STR_MS_T containing the object name with path. It usually comes from query as "$objPat
 *                          like /zone/../%" in the deployed microservice
 * \param[in] inpParam2 - a STR_MS_T containing the leading collection name to be truncated
 * \param[in] inpParam3 - a STR_MS_T containing the destination collection
 * \param[in] inpParam4 - a STR_MS_T containing the new owner
 * \param[in] inpParam5 - a STR_MS_T containing a flag for whether the checksum should be computed
                        \li true - default - will compute the checksum
                        \li false - will not compute the checksum
 * \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 none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 upon success
 * \pre none
 * \post none
 * \sa none
**/
int msiDataObjAutoMove( msParam_t *inpParam1, msParam_t *inpParam2, msParam_t *inpParam3,
                        msParam_t *inpParam4, msParam_t *inpParam5, ruleExecInfo_t *rei ) {
    char *obj_path, *truct_path, *dest_coll, *new_owner;
    char *new_truct_path;
    char *new_obj_path;
    int  t;
    int  new_truct_path_len;
    rsComm_t *rsconn;
    char  mdest_coll[MAX_NAME_LEN];

    char  query_str[2048];
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;

    char new_obj_parent[MAX_NAME_LEN];
    char obj_name[MAX_NAME_LEN];

    collInp_t collCreateInp;
    dataObjCopyInp_t dataObjRenameInp;
    modAccessControlInp_t myModAccessCntlInp;

    dataObjInp_t myDataObjInp;
    char own_perm[20], null_perm[20];
    char user_name[NAME_LEN], zone_name[NAME_LEN];

    char *sTmpstr;
    int compute_checksum = 0;
    char *chksum_str = NULL;
    char tmpstr[1024];

    strcpy( own_perm, "own" );
    strcpy( null_perm, "null" );

    if ( rei == NULL || rei->rsComm == NULL ) {
        rodsLog( LOG_ERROR,
                 "msiDataObjAutoMove: input rei or rei->rsComm is NULL" );
        return ( SYS_INTERNAL_NULL_INPUT_ERR );
    }

    rsconn = rei->rsComm;

    if ( inpParam1 == NULL ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input objpath (inpParam1) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }
    obj_path = ( char * )inpParam1->inOutStruct;
    if ( ( obj_path == NULL ) || ( strlen( obj_path ) == 0 ) ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input objpath (inpParam1->inOutStruct) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    if ( inpParam2 == NULL ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input truct_path (inpParam2) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }
    truct_path = ( char * )inpParam2->inOutStruct;
    if ( ( truct_path == NULL ) || ( strlen( truct_path ) == 0 ) ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input truct_path (inpParam2->inOutStruct) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    if ( inpParam3 == NULL ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input dest_coll (inpParam3) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }
    dest_coll = ( char * )inpParam3->inOutStruct;
    if ( ( dest_coll == NULL ) || ( strlen( dest_coll ) == 0 ) ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input dest_coll (inpParam3->inOutStruct) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    if ( inpParam4 == NULL ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input new_owner (inpParam4) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }
    new_owner = ( char * )inpParam4->inOutStruct;
    if ( new_owner != NULL ) {
        if ( strlen( new_owner ) == 0 ) {
            new_owner = NULL;
        }
        else if ( strcmp( new_owner, "null" ) == 0 ) {
            new_owner = NULL;
        }
    }
    if ( new_owner != NULL ) {
        user_name[0] = '\0';
        zone_name[0] = '\0';
        t = parseUserName( new_owner, user_name, zone_name );
        if ( t < 0 ) {
            rodsLog( LOG_ERROR, "msiDataObjAutoMove: parseUserName() failed. errStatus=%d.", t );
            return t;
        }
        if ( strlen( zone_name ) == 0 ) {
            strcpy( zone_name, rei->uoip->rodsZone );
        }
    }

    if ( inpParam5 == NULL ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input compute_checksum (inpParam5) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }
    sTmpstr = ( char * )inpParam5->inOutStruct;
    compute_checksum = 1;   /* default to true */
    if ( ( sTmpstr != NULL ) && ( strlen( sTmpstr ) >= 0 ) ) {
        if ( strcmp( sTmpstr, "false" ) == 0 ) {
            compute_checksum = 0;
        }
    }

    if ( compute_checksum == 1 ) {
        chksum_str =  NULL;
        memset( &myDataObjInp, 0, sizeof( dataObjInp_t ) );
        strncpy( myDataObjInp.objPath, obj_path, MAX_NAME_LEN );
        addKeyVal( &myDataObjInp.condInput, VERIFY_CHKSUM_KW, "" );
        sprintf( tmpstr, "%d", 0 );
        addKeyVal( &myDataObjInp.condInput, REPL_NUM_KW, tmpstr );
        t = rsDataObjChksum( rsconn, &myDataObjInp, &chksum_str );
        if ( t < 0 ) {
            rodsLog( LOG_ERROR, "msiDataObjAutoMove: rsDataObjChksum() for '%s' failed. errStatus=%d.", obj_path, t );
            return t;
        }
    }

    if ( new_owner != NULL ) {
        /* add ownership */
        memset( &myModAccessCntlInp, 0, sizeof( modAccessControlInp_t ) );
        myModAccessCntlInp.recursiveFlag = False;
        myModAccessCntlInp.accessLevel = own_perm;
        myModAccessCntlInp.userName = user_name;
        myModAccessCntlInp.zone = zone_name;
        myModAccessCntlInp.path = obj_path;
        t = rsModAccessControl( rsconn, &myModAccessCntlInp );
        if ( t < 0 ) {
            rodsLog( LOG_ERROR, "msiDataObjAutoMove: rsModAccessControl() add new owner for '%s' failed. errStatus=%d.", obj_path, t );
            return t;
        }

    }

    t = strlen( truct_path );
    new_truct_path = ( char * )calloc( t + 2, sizeof( char ) );
    if ( truct_path[t - 1] != '/' ) {
        strcpy( new_truct_path, truct_path );
        new_truct_path_len = t;
    }
    else {
        strcpy( new_truct_path, truct_path );
        new_truct_path[t] = '/';
        new_truct_path[t + 1] = '\0';
        new_truct_path_len = t + 1;
    }
    if ( strncmp( new_truct_path, obj_path, t ) != 0 ) {
        /* when the object is not match, we don't move */
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: The object path, %s, is not in the specified collection, %s.", obj_path, new_truct_path );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    t = strlen( dest_coll );
    new_obj_path = ( char * )calloc( t + strlen( obj_path ), sizeof( char ) );
    strcpy( mdest_coll, dest_coll );
    if ( dest_coll[t - 1] == '/' ) {
        mdest_coll[t - 1] = '\0';
    }
    sprintf( new_obj_path, "%s/%s", mdest_coll, &( obj_path[new_truct_path_len + 1] ) );
    sprintf( query_str, "SELECT COLL_NAME WHERE COLL_NAME like '%s%%'", mdest_coll );

    /* check if the dest_coll exists */
    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    t = fillGenQueryInpFromStrCond( query_str, &genQueryInp );
    if ( t < 0 ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: fillGenQueryInpFromStrCond() failed. errStatus=%d", t );
        free( new_obj_path ); // JMC cppcheck - leak
        free( new_truct_path ); // JMC cppcheck - leak
        return t;
    }
    genQueryInp.maxRows = MAX_SQL_ROWS;
    genQueryInp.continueInx = 0;
    t = rsGenQuery( rsconn, &genQueryInp, &genQueryOut );
    if ( t < 0 ) {
        if ( t == CAT_NO_ROWS_FOUND ) {
            rodsLog( LOG_ERROR, "msiDataObjAutoMove: The destination collection '%s' does not exist.", dest_coll );
        }
        else {
            rodsLog( LOG_ERROR, "msiDataObjAutoMove: rsGenQuery() failed. errStatus=%d", t );
        }
        free( new_obj_path ); // JMC cppcheck - leak
        free( new_truct_path ); // JMC cppcheck - leak
        return t;
    }

    /* separate new_obj_path with path and name */
    t = splitPathByKey( new_obj_path, new_obj_parent, obj_name, '/' );
    if ( t < 0 ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: splitPathByKey() failed for splitting '%s'. errStatus=%d.", new_obj_path, t );
        free( new_obj_path ); // JMC cppcheck - leak
        free( new_truct_path ); // JMC cppcheck - leak
        return t;
    }

    /* fprintf(stderr,"msiDataObjAutoMove: newpar=%s, obj_name=%s, from=%s\n", new_obj_parent, obj_name, obj_path); */

    /* create the dires in new_obj_path 'imkidr -p'*/
    if ( strlen( new_obj_parent ) > strlen( mdest_coll ) ) {
        memset( &collCreateInp, 0, sizeof( collCreateInp ) );
        rstrcpy( collCreateInp.collName, new_obj_parent, MAX_NAME_LEN );
        addKeyVal( &collCreateInp.condInput, RECURSIVE_OPR__KW, "" );   /* always have '-p' option. */
        t = rsCollCreate( rsconn, &collCreateInp );
        if ( t < 0 ) {
            rodsLog( LOG_ERROR, "msiDataObjAutoMove: rsCollCreate() failed for %s. errStatus=%d.", new_obj_parent, t );
            free( new_obj_path ); // JMC cppcheck - leak
            free( new_truct_path ); // JMC cppcheck - leak
            return t;
        }
    }

    fprintf( stderr, "new_obj_path=%s, obj_path=%s\n", new_obj_path, obj_path );
    /* renamed the obj_path to new_obj_path */
    memset( &dataObjRenameInp, 0, sizeof( dataObjCopyInp_t ) );
    rstrcpy( dataObjRenameInp.destDataObjInp.objPath, new_obj_path, MAX_NAME_LEN );
    rstrcpy( dataObjRenameInp.srcDataObjInp.objPath, obj_path, MAX_NAME_LEN );
    t = rsDataObjRename( rsconn, &dataObjRenameInp );
    if ( t < 0 ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: rsDataObjRename() failed. errStatus=%d.", t );
        free( new_obj_path ); // JMC cppcheck - leak
        free( new_truct_path ); // JMC cppcheck - leak
        return t;
    }

    memset( &myModAccessCntlInp, 0, sizeof( modAccessControlInp_t ) );
    myModAccessCntlInp.recursiveFlag = False;
    myModAccessCntlInp.accessLevel = null_perm;
    myModAccessCntlInp.userName = rei->uoic->userName;
    myModAccessCntlInp.zone = zone_name;
    myModAccessCntlInp.path = new_obj_path;
    t = rsModAccessControl( rsconn, &myModAccessCntlInp );
    if ( t < 0 ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: rsModAccessControl() remove user for '%s' failed. errStatus=%d.", obj_path, t );
    }

    free( new_truct_path ); // JMC cppcheck - leak
    return 0;
}
Пример #8
0
static int  _myAutoReplicateService( rsComm_t *conn, char *topColl, int recursiveFlag,
                                     int requiredNumReplicas, char *rescGroup,
                                     char *emailToNotify ) {
    /* query the collection. and go through each object and process each copy. */
    genQueryInp_t genQueryInp;
    int i;
    genQueryOut_t *genQueryOut = NULL;
    char query_str[2048];
    sqlResult_t *collNameStruct, *dataNameStruct;
    char *collName, *dataName;
    int t;
    int loop_stop;

    rodsLog( LOG_NOTICE, "_myAutoReplicateService(): topColl=%s, recursiveFlag=%d, requiredNumReplicas=%d, rescGroup=%s, emailToNotify=NULL\n",
             topColl, recursiveFlag, requiredNumReplicas, rescGroup );

    if ( ( emailToNotify != NULL ) && ( strlen( emailToNotify ) > 0 ) ) {
        fprintf( stderr, "_myAutoReplicateService(): topColl=%s, recursiveFlag=%d, requiredNumReplicas=%d, rescGroup=%s, emailToNotify=%s\n",
                 topColl, recursiveFlag, requiredNumReplicas, rescGroup, emailToNotify );
    }

    if ( recursiveFlag ) {
        sprintf( query_str, "select COLL_NAME, DATA_NAME where COLL_NAME like '%s%%'", topColl );
    }
    else {
        sprintf( query_str, "select COLL_NAME, DATA_NAME where COLL_NAME = '%s'", topColl );
    }

    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    t = fillGenQueryInpFromStrCond( query_str, &genQueryInp );
    if ( t < 0 ) {
        rodsLog( LOG_ERROR, "_myAutoReplicateService(): fillGenQueryInpFromStrCond() failed. err code=%d", t );
        return( t );
    }

    genQueryInp.maxRows = MAX_SQL_ROWS;
    genQueryInp.continueInx = 0;
    t = rsGenQuery( conn, &genQueryInp, &genQueryOut );
    if ( t < 0 ) {
        if ( t == CAT_NO_ROWS_FOUND ) { /* no data is found */
            rodsLog( LOG_ERROR, "_myAutoReplicateService():rsGenQuery(): no data is found. The service ended." );
            return 0;
        }
        rodsLog( LOG_ERROR, "_myAutoReplicateService():rsGenQuery(): failed. err code=%d. The service quit.", t );
        return( t );
    }

    repl_storage_error = 0;
    loop_stop = 0;
    do {
        /* fprintf(stderr, "rowCnt=%d\n", genQueryOut->rowCnt); */
        for ( i = 0; i < genQueryOut->rowCnt; i++ ) {
            collNameStruct = getSqlResultByInx( genQueryOut, COL_COLL_NAME );
            dataNameStruct = getSqlResultByInx( genQueryOut, COL_DATA_NAME );

            collName = &collNameStruct->value[collNameStruct->len * i];
            dataName = &dataNameStruct->value[dataNameStruct->len * i];

            t = process_single_obj( conn, collName, dataName, requiredNumReplicas, rescGroup, emailToNotify );
            rodsLog( LOG_DEBUG, "_myAutoReplicateService(): finished processing obj %s/%s\n", collName, dataName );

            if ( t == SYS_OUT_OF_FILE_DESC ) { /* this is an fatal error. the service quit. */
                rodsLog( LOG_ERROR, "_myAutoReplicateService():process_single_obj() returned SYS_OUT_OF_FILE_DESC. The service quit." );
                return t;
            }

            if ( ( t < 0 ) && ( repl_storage_error == 1 ) ) {
                rodsLog( LOG_ERROR, "_myAutoReplicateService():process_single_obj() returned a storage eror. The service quit." );
                loop_stop = 1;
            }
        }

        if ( loop_stop == 0 ) {
            /* fprintf(stderr, "t=%d, continueInx=%d\n", t, genQueryOut->continueInx); */
            if ( genQueryOut->continueInx == 0 ) {
                loop_stop = 1;
            }
            else {
                genQueryInp.continueInx = genQueryOut->continueInx;
                t = rsGenQuery( conn, &genQueryInp, &genQueryOut );
                loop_stop = 0;
            }
        }
    }
    while ( ( t == 0 ) && ( loop_stop == 0 ) );

    freeGenQueryOut( &genQueryOut );

    rodsLog( LOG_NOTICE, "_myAutoReplicateService(): topColl=%s ended.\n", topColl );

    return 0;
}