int queRescQuota( rescQuota_t **rescQuotaHead, genQueryOut_t *genQueryOut ) { sqlResult_t *quotaLimit, *quotaOver, *rescName, *quotaRescId, *quotaUserId; char *tmpQuotaLimit, *tmpQuotaOver, *tmpRescName, *tmpQuotaRescId, *tmpQuotaUserId; int i; rescQuota_t *tmpRescQuota; if ( ( quotaLimit = getSqlResultByInx( genQueryOut, COL_QUOTA_LIMIT ) ) == NULL ) { rodsLog( LOG_ERROR, "queRescQuota: getSqlResultByInx for COL_QUOTA_LIMIT failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( quotaOver = getSqlResultByInx( genQueryOut, COL_QUOTA_OVER ) ) == NULL ) { rodsLog( LOG_ERROR, "queRescQuota: getSqlResultByInx for COL_QUOTA_OVER failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( rescName = getSqlResultByInx( genQueryOut, COL_R_RESC_NAME ) ) == NULL ) { rodsLog( LOG_ERROR, "queRescQuota: getSqlResultByInx for COL_R_RESC_NAME failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( quotaRescId = getSqlResultByInx( genQueryOut, COL_QUOTA_RESC_ID ) ) == NULL ) { rodsLog( LOG_ERROR, "queRescQuota: getSqlResultByInx for COL_QUOTA_RESC_ID failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( quotaUserId = getSqlResultByInx( genQueryOut, COL_QUOTA_USER_ID ) ) == NULL ) { rodsLog( LOG_ERROR, "queRescQuota: getSqlResultByInx for COL_QUOTA_USER_ID failed" ); return UNMATCHED_KEY_OR_INDEX; } for ( i = 0; i < genQueryOut->rowCnt; i++ ) { tmpQuotaLimit = "aLimit->value[quotaLimit->len * i]; tmpQuotaOver = "aOver->value[quotaOver->len * i]; tmpRescName = &rescName->value[rescName->len * i]; tmpQuotaRescId = "aRescId->value[quotaRescId->len * i]; tmpQuotaUserId = "aUserId->value[quotaUserId->len * i]; tmpRescQuota = ( rescQuota_t* )malloc( sizeof( rescQuota_t ) ); fillRescQuotaStruct( tmpRescQuota, tmpQuotaLimit, tmpQuotaOver, tmpRescName, tmpQuotaRescId, tmpQuotaUserId ); tmpRescQuota->next = *rescQuotaHead; *rescQuotaHead = tmpRescQuota; } return 0; }
int printDataAcl (rcComm_t *conn, char *dataId) { genQueryOut_t *genQueryOut = NULL; int status; int i; sqlResult_t *userName, *userZone, *dataAccess; char *userNameStr, *userZoneStr, *dataAccessStr; status = queryDataObjAcl (conn, dataId, zoneHint, &genQueryOut); printf (" ACL - "); if (status < 0) { printf ("\n"); return (status); } if ((userName = getSqlResultByInx (genQueryOut, COL_USER_NAME)) == NULL) { rodsLog (LOG_ERROR, "printDataAcl: getSqlResultByInx for COL_USER_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((userZone = getSqlResultByInx (genQueryOut, COL_USER_ZONE)) == NULL) { rodsLog (LOG_ERROR, "printDataAcl: getSqlResultByInx for COL_USER_ZONE failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((dataAccess = getSqlResultByInx (genQueryOut, COL_DATA_ACCESS_NAME)) == NULL) { rodsLog (LOG_ERROR, "printDataAcl: getSqlResultByInx for COL_DATA_ACCESS_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } for (i = 0; i < genQueryOut->rowCnt; i++) { userNameStr = &userName->value[userName->len * i]; userZoneStr = &userZone->value[userZone->len * i]; dataAccessStr = &dataAccess->value[dataAccess->len * i]; printf ("%s#%s:%s ", userNameStr, userZoneStr, dataAccessStr); } printf ("\n"); freeGenQueryOut (&genQueryOut); return (status); }
int getUserId( rsComm_t *rsComm, char *userName, char *zoneName ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; char tmpStr2[MAX_NAME_LEN]; int status; memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); snprintf( tmpStr, NAME_LEN, "='%s'", userName ); snprintf( tmpStr2, NAME_LEN, "='%s'", zoneName ); addInxVal( &genQueryInp.sqlCondInp, COL_USER_NAME, tmpStr ); addInxVal( &genQueryInp.sqlCondInp, COL_USER_ZONE, tmpStr2 ); addInxIval( &genQueryInp.selectInp, COL_USER_ID, 1 ); genQueryInp.maxRows = 2; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); clearGenQueryInp( &genQueryInp ); if ( status >= 0 ) { sqlResult_t *userIdRes; if ( ( userIdRes = getSqlResultByInx( genQueryOut, COL_USER_ID ) ) == NULL ) { rodsLog( LOG_ERROR, "getUserId: getSqlResultByInx for COL_USER_ID failed" ); freeGenQueryOut( &genQueryOut ); return UNMATCHED_KEY_OR_INDEX; } status = atoi( userIdRes->value ); freeGenQueryOut( &genQueryOut ); } return status; }
int printCollInheritance (rcComm_t *conn, char *collName) { genQueryOut_t *genQueryOut = NULL; int status; sqlResult_t *inheritResult; char *inheritStr; status = queryCollInheritance (conn, collName, &genQueryOut); if (status < 0) { return (status); } if ((inheritResult = getSqlResultByInx (genQueryOut, COL_COLL_INHERITANCE)) == NULL) { rodsLog (LOG_ERROR, "printCollInheritance: getSqlResultByInx for COL_COLL_INHERITANCE failed"); return (UNMATCHED_KEY_OR_INDEX); } inheritStr = &inheritResult->value[0]; printf (" Inheritance - "); if (*inheritStr=='1') { printf("Enabled\n"); } else { printf("Disabled\n"); } freeGenQueryOut (&genQueryOut); return (status); }
int readICatUserInfo( char *userName, char *attr, char userInfo[MAX_NAME_LEN], rsComm_t *rsComm ) { int status; genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char condstr[MAX_NAME_LEN]; memset( &genQueryInp, 0, sizeof( genQueryInp ) ); genQueryInp.maxRows = MAX_SQL_ROWS; snprintf( condstr, MAX_NAME_LEN, "= '%s'", userName ); addInxVal( &genQueryInp.sqlCondInp, COL_USER_NAME, condstr ); snprintf( condstr, MAX_NAME_LEN, "= '%s'", attr ); addInxVal( &genQueryInp.sqlCondInp, COL_META_USER_ATTR_NAME, condstr ); addInxIval( &genQueryInp.selectInp, COL_META_USER_ATTR_VALUE, 1 ); status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); userInfo[0] = '\0'; if ( status >= 0 && genQueryOut->rowCnt > 0 ) { if ( sqlResult_t *r = getSqlResultByInx( genQueryOut, COL_META_USER_ATTR_VALUE ) ) { rstrcpy( userInfo, &r->value[0], MAX_NAME_LEN ); } genQueryInp.continueInx = genQueryOut->continueInx; } clearGenQueryInp( &genQueryInp ); freeGenQueryOut( &genQueryOut ); return status; }
int getTokenId(rsComm_t *rsComm, char *tokenNameSpace, char *tokenName) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; char tmpStr2[MAX_NAME_LEN]; int status; memset (&genQueryInp, 0, sizeof (genQueryInp_t)); snprintf (tmpStr, NAME_LEN, "='%s'", tokenNameSpace); snprintf (tmpStr2, NAME_LEN, "='%s'", tokenName); addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_NAMESPACE, tmpStr); addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_NAME, tmpStr2); addInxIval (&genQueryInp.selectInp, COL_TOKEN_ID, 1); genQueryInp.maxRows = 2; status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut); clearGenQueryInp (&genQueryInp); if (status >= 0) { sqlResult_t *tokenIdRes; if ((tokenIdRes = getSqlResultByInx (genQueryOut, COL_TOKEN_ID)) == NULL) { rodsLog (LOG_ERROR, "getTokenId: getSqlResultByInx for COL_TOKEN_ID failed"); freeGenQueryOut (&genQueryOut); return (UNMATCHED_KEY_OR_INDEX); } status = atoi(tokenIdRes->value); freeGenQueryOut (&genQueryOut); } return(status); }
int isColl( rsComm_t *rsComm, char *objName, rodsLong_t *collId ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; int status; memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); snprintf( tmpStr, MAX_NAME_LEN, "='%s'", objName ); addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr ); addInxIval( &genQueryInp.selectInp, COL_COLL_ID, 1 ); genQueryInp.maxRows = 2; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); if ( status >= 0 ) { sqlResult_t *collIdRes; if ( ( collIdRes = getSqlResultByInx( genQueryOut, COL_COLL_ID ) ) == NULL ) { rodsLog( LOG_ERROR, "isColl: getSqlResultByInx for COL_D_DATA_ID failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( collId != NULL ) { *collId = strtoll( collIdRes->value, 0, 0 ); } freeGenQueryOut( &genQueryOut ); } clearGenQueryInp( &genQueryInp ); return status; }
int qdelUtil( rcComm_t *conn, char *userName, int allFlag, rodsArguments_t *myRodsArgs ) { genQueryInp_t genQueryInp; int status, i, continueInx; char tmpStr[MAX_NAME_LEN]; sqlResult_t *execId; char *execIdStr; genQueryOut_t *genQueryOut = NULL; int savedStatus = 0; if ( allFlag == 1 && userName != NULL ) { rodsLog( LOG_ERROR, "qdelUtil: all(-a) and user(-u) cannot be used together" ); return USER_INPUT_OPTION_ERR; } memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); if ( userName != NULL ) { snprintf( tmpStr, MAX_NAME_LEN, " = '%s'", userName ); addInxVal( &genQueryInp.sqlCondInp, COL_RULE_EXEC_USER_NAME, tmpStr ); } addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_ID, 1 ); genQueryInp.maxRows = MAX_SQL_ROWS; continueInx = 1; /* a fake one so it will do the first query */ while ( continueInx > 0 ) { status = rcGenQuery( conn, &genQueryInp, &genQueryOut ); if ( status < 0 ) { if ( status != CAT_NO_ROWS_FOUND ) { savedStatus = status; } break; } if ( ( execId = getSqlResultByInx( genQueryOut, COL_RULE_EXEC_ID ) ) == NULL ) { rodsLog( LOG_ERROR, "qdelUtil: getSqlResultByInx for COL_RULE_EXEC_ID failed" ); return UNMATCHED_KEY_OR_INDEX; } for ( i = 0; i < genQueryOut->rowCnt; i++ ) { execIdStr = &execId->value[execId->len * i]; if ( myRodsArgs->verbose ) { printf( "Deleting %s\n", execIdStr ); } status = rmDelayedRule( execIdStr ); if ( status < 0 ) { rodsLog( LOG_ERROR, "qdelUtil: rmDelayedRule %s error. status = %d", execIdStr, status ); savedStatus = status; } } continueInx = genQueryInp.continueInx = genQueryOut->continueInx; freeGenQueryOut( &genQueryOut ); } clearGenQueryInp( &genQueryInp ); return savedStatus; }
static int get_resource_path( rsComm_t *conn, char *rescName, char *rescPath ) { genQueryInp_t genQueryInp; int i1a[10]; int i1b[10]; int i2a[10]; char *condVal[2]; char v1[200]; genQueryOut_t *genQueryOut = NULL; sqlResult_t *vaultPathSTruct; char *vaultPath; int t; memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); i1a[0] = COL_R_VAULT_PATH; i1b[0] = 0; genQueryInp.selectInp.inx = i1a; genQueryInp.selectInp.value = i1b; genQueryInp.selectInp.len = 1; i2a[0] = COL_R_RESC_NAME; genQueryInp.sqlCondInp.inx = i2a; sprintf( v1, "='%s'", rescName ); condVal[0] = v1; genQueryInp.sqlCondInp.value = condVal; genQueryInp.sqlCondInp.len = 1; genQueryInp.maxRows = 2; genQueryInp.continueInx = 0; t = rsGenQuery( conn, &genQueryInp, &genQueryOut ); if ( NULL == genQueryOut ) { // JMC cppecheck - nullptr rodsLog( LOG_ERROR, "get_resource_path :: genQueryOut is NULL" ); return 0; } if ( t < 0 ) { if ( t == CAT_NO_ROWS_FOUND ) { /* no data is found */ return 0; } return( t ); } if ( genQueryOut->rowCnt < 0 ) { return -1; } vaultPathSTruct = getSqlResultByInx( genQueryOut, COL_R_VAULT_PATH ); vaultPath = &vaultPathSTruct->value[0]; strcpy( rescPath, vaultPath ); freeGenQueryOut( &genQueryOut ); return 0; }
/* checkDupReplica - Check if a given object with a given rescName * and physical path already exist. If it does, returns the replNum. * JMC - backport 4497 */ int checkDupReplica( rsComm_t *rsComm, rodsLong_t dataId, char *rescName, char *filePath ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; int status; if ( rsComm == NULL || rescName == NULL || filePath == NULL ) { return USER__NULL_INPUT_ERR; } bzero( &genQueryInp, sizeof( genQueryInp_t ) ); rodsLong_t resc_id; irods::error ret = resc_mgr.hier_to_leaf_id(rescName,resc_id); if(!ret.ok()) { irods::log(PASS(ret)); return ret.code(); } std::string resc_id_str = boost::lexical_cast<std::string>(resc_id); snprintf( tmpStr, MAX_NAME_LEN, "='%s'", resc_id_str.c_str() ); addInxVal( &genQueryInp.sqlCondInp, COL_D_RESC_ID, tmpStr ); snprintf( tmpStr, MAX_NAME_LEN, "='%s'", filePath ); addInxVal( &genQueryInp.sqlCondInp, COL_D_DATA_PATH, tmpStr ); snprintf( tmpStr, MAX_NAME_LEN, "='%lld'", dataId ); addInxVal( &genQueryInp.sqlCondInp, COL_D_DATA_ID, tmpStr ); addInxIval( &genQueryInp.selectInp, COL_DATA_REPL_NUM, 1 ); genQueryInp.maxRows = 2; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); clearGenQueryInp( &genQueryInp ); if ( status >= 0 ) { int intReplNum; sqlResult_t *replNum; if ( ( replNum = getSqlResultByInx( genQueryOut, COL_DATA_REPL_NUM ) ) == NULL ) { freeGenQueryOut( &genQueryOut ); rodsLog( LOG_ERROR, "checkDupReplica: getSqlResultByInx COL_DATA_REPL_NUM failed" ); return UNMATCHED_KEY_OR_INDEX; } intReplNum = atoi( replNum->value ); freeGenQueryOut( &genQueryOut ); return intReplNum; } else { freeGenQueryOut( &genQueryOut ); return status; } }
int printLsShort (rcComm_t *conn, rodsArguments_t *rodsArgs, genQueryOut_t *genQueryOut) { int i; sqlResult_t *dataName, *dataId; char *tmpDataName, *tmpDataId; if (genQueryOut == NULL) { return (USER__NULL_INPUT_ERR); } if ((dataId = getSqlResultByInx (genQueryOut, COL_D_DATA_ID)) == NULL) { rodsLog (LOG_ERROR, "printLsShort: getSqlResultByInx for COL_D_DATA_ID failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((dataName = getSqlResultByInx (genQueryOut, COL_DATA_NAME)) == NULL) { rodsLog (LOG_ERROR, "printLsShort: getSqlResultByInx for COL_DATA_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } for (i = 0;i < genQueryOut->rowCnt; i++) { tmpDataName = &dataName->value[dataName->len * i]; printLsStrShort (tmpDataName); if (rodsArgs->accessControl == True) { tmpDataId = &dataId->value[dataId->len * i]; printDataAcl (conn, tmpDataId); } } return (0); }
int isData(rsComm_t *rsComm, char *objName, rodsLong_t *dataId) { char logicalEndName[MAX_NAME_LEN]{}; char logicalParentDirName[MAX_NAME_LEN]{}; auto status{splitPathByKey(objName, logicalParentDirName, MAX_NAME_LEN, logicalEndName, MAX_NAME_LEN, '/')}; if (status < 0) { const auto err{ERROR(status, (boost::format("splitPathByKey failed for [%s]") % objName).str().c_str())}; irods::log(err); return err.code(); } genQueryInp_t genQueryInp{}; genQueryOut_t *genQueryOut{}; char tmpStr[MAX_NAME_LEN]{}; memset(&genQueryInp, 0, sizeof(genQueryInp_t)); snprintf(tmpStr, MAX_NAME_LEN, "='%s'", logicalEndName); addInxVal(&genQueryInp.sqlCondInp, COL_DATA_NAME, tmpStr); addInxIval(&genQueryInp.selectInp, COL_D_DATA_ID, 1); snprintf(tmpStr, MAX_NAME_LEN, "='%s'", logicalParentDirName); addInxVal(&genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr); addInxIval(&genQueryInp.selectInp, COL_COLL_ID, 1); genQueryInp.maxRows = 2; status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut); if (status < 0) { freeGenQueryOut(&genQueryOut); clearGenQueryInp(&genQueryInp); return status; } sqlResult_t *dataIdRes{getSqlResultByInx(genQueryOut, COL_D_DATA_ID)}; if (NULL == dataIdRes) { const auto err{ERROR(UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_D_DATA_ID failed")}; irods::log(err); return err.code(); } if (NULL != dataId) { *dataId = strtoll(dataIdRes->value, 0, 0); } freeGenQueryOut(&genQueryOut); clearGenQueryInp(&genQueryInp); return status; }
/* checkDupReplica - Check if a given object with a given rescName * and physical path already exist. If it does, returns the replNum. * JMC - backport 4497 */ int checkDupReplica( rsComm_t *rsComm, rodsLong_t dataId, char *rescName, char *filePath ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; int status; if ( rsComm == NULL || rescName == NULL || filePath == NULL ) { return USER__NULL_INPUT_ERR; } bzero( &genQueryInp, sizeof( genQueryInp_t ) ); snprintf( tmpStr, MAX_NAME_LEN, "='%s'", rescName ); addInxVal( &genQueryInp.sqlCondInp, COL_D_RESC_NAME, tmpStr ); snprintf( tmpStr, MAX_NAME_LEN, "='%s'", filePath ); addInxVal( &genQueryInp.sqlCondInp, COL_D_DATA_PATH, tmpStr ); snprintf( tmpStr, MAX_NAME_LEN, "='%lld'", dataId ); addInxVal( &genQueryInp.sqlCondInp, COL_D_DATA_ID, tmpStr ); addInxIval( &genQueryInp.selectInp, COL_DATA_REPL_NUM, 1 ); genQueryInp.maxRows = 2; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); clearGenQueryInp( &genQueryInp ); if ( status >= 0 ) { int intReplNum; sqlResult_t *replNum; if ( ( replNum = getSqlResultByInx( genQueryOut, COL_DATA_REPL_NUM ) ) == NULL ) { rodsLog( LOG_ERROR, "checkDupReplica: getSqlResultByInx COL_DATA_REPL_NUM failed" ); return UNMATCHED_KEY_OR_INDEX; } intReplNum = atoi( replNum->value ); freeGenQueryOut( &genQueryOut ); return intReplNum; } else { return status; } }
int isData (rsComm_t *rsComm, char *objName, rodsLong_t *dataId) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; char logicalEndName[MAX_NAME_LEN]; char logicalParentDirName[MAX_NAME_LEN]; int status; status = splitPathByKey(objName, logicalParentDirName, logicalEndName, '/'); memset (&genQueryInp, 0, sizeof (genQueryInp_t)); snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalEndName); addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, tmpStr); addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, 1); snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalParentDirName); addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr); addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1); genQueryInp.maxRows = 2; status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut); if (status >= 0) { sqlResult_t *dataIdRes; if ((dataIdRes = getSqlResultByInx (genQueryOut, COL_D_DATA_ID)) == NULL) { rodsLog (LOG_ERROR, "isData: getSqlResultByInx for COL_D_DATA_ID failed"); return (UNMATCHED_KEY_OR_INDEX); } if (dataId != NULL) { *dataId = strtoll (dataIdRes->value, 0, 0); } freeGenQueryOut (&genQueryOut); } clearGenQueryInp (&genQueryInp); return(status); }
int getPhyPath (rsComm_t *rsComm, char *objName, char *resource, char *phyPath) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; char logicalEndName[MAX_NAME_LEN]; char logicalParentDirName[MAX_NAME_LEN]; int status; status = splitPathByKey(objName, logicalParentDirName, logicalEndName, '/'); memset (&genQueryInp, 0, sizeof (genQueryInp_t)); snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalEndName); addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, tmpStr); snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalParentDirName); addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr); addInxIval (&genQueryInp.selectInp, COL_D_DATA_PATH, 1); genQueryInp.maxRows = 2; status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut); if (status >= 0) { sqlResult_t *phyPathRes = NULL; if ((phyPathRes = getSqlResultByInx (genQueryOut, COL_D_DATA_PATH)) == NULL) { rodsLog (LOG_ERROR, "getPhyPath: getSqlResultByInx for COL_D_DATA_PATH failed"); return (UNMATCHED_KEY_OR_INDEX); } if (phyPath != NULL) { rstrcpy (phyPath, phyPathRes->value, MAX_NAME_LEN); } freeGenQueryOut (&genQueryOut); } clearGenQueryInp (&genQueryInp); return(status); }
int queueSpecCollCache( rsComm_t *rsComm, genQueryOut_t *genQueryOut, char *objPath ) { // JMC - backport 4680 int status; int i; sqlResult_t *dataId; sqlResult_t *ownerName; sqlResult_t *ownerZone; sqlResult_t *createTime; sqlResult_t *modifyTime; sqlResult_t *collType; sqlResult_t *collection; sqlResult_t *collInfo1; sqlResult_t *collInfo2; char *tmpDataId, *tmpOwnerName, *tmpOwnerZone, *tmpCreateTime, *tmpModifyTime, *tmpCollType, *tmpCollection, *tmpCollInfo1, *tmpCollInfo2; specColl_t *specColl; if ( ( dataId = getSqlResultByInx( genQueryOut, COL_COLL_ID ) ) == NULL ) { rodsLog( LOG_ERROR, "queueSpecCollCache: getSqlResultByInx for COL_COLL_ID failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( ownerName = getSqlResultByInx( genQueryOut, COL_COLL_OWNER_NAME ) ) == NULL ) { rodsLog( LOG_ERROR, "queueSpecCollCache:getSqlResultByInx for COL_COLL_OWNER_NAME failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( ownerZone = getSqlResultByInx( genQueryOut, COL_COLL_OWNER_ZONE ) ) == NULL ) { rodsLog( LOG_ERROR, "queueSpecCollCache:getSqlResultByInx for COL_COLL_OWNER_ZONE failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( createTime = getSqlResultByInx( genQueryOut, COL_COLL_CREATE_TIME ) ) == NULL ) { rodsLog( LOG_ERROR, "queueSpecCollCache:getSqlResultByInx for COL_COLL_CREATE_TIME failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( modifyTime = getSqlResultByInx( genQueryOut, COL_COLL_MODIFY_TIME ) ) == NULL ) { rodsLog( LOG_ERROR, "queueSpecCollCache:getSqlResultByInx for COL_COLL_MODIFY_TIME failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( collType = getSqlResultByInx( genQueryOut, COL_COLL_TYPE ) ) == NULL ) { rodsLog( LOG_ERROR, "queueSpecCollCache:getSqlResultByInx for COL_COLL_TYPE failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( collection = getSqlResultByInx( genQueryOut, COL_COLL_NAME ) ) == NULL ) { rodsLog( LOG_ERROR, "queueSpecCollCache:getSqlResultByInx for COL_COLL_NAME failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( collInfo1 = getSqlResultByInx( genQueryOut, COL_COLL_INFO1 ) ) == NULL ) { rodsLog( LOG_ERROR, "queueSpecCollCache:getSqlResultByInx for COL_COLL_INFO1 failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( collInfo2 = getSqlResultByInx( genQueryOut, COL_COLL_INFO2 ) ) == NULL ) { rodsLog( LOG_ERROR, "queueSpecCollCache:getSqlResultByInx for COL_COLL_INFO2 failed" ); return UNMATCHED_KEY_OR_INDEX; } for ( i = 0; i <= genQueryOut->rowCnt; i++ ) { int len; char *tmpPtr; tmpCollection = &collection->value[collection->len * i]; len = strlen( tmpCollection ); tmpPtr = objPath + len; if ( *tmpPtr == '\0' || *tmpPtr == '/' ) { specCollCache_t * tmpSpecCollCache = ( specCollCache_t* )malloc( sizeof( specCollCache_t ) ); memset( tmpSpecCollCache, 0, sizeof( specCollCache_t ) ); tmpDataId = &dataId->value[dataId->len * i]; tmpOwnerName = &ownerName->value[ownerName->len * i]; tmpOwnerZone = &ownerZone->value[ownerZone->len * i]; tmpCreateTime = &createTime->value[createTime->len * i]; tmpModifyTime = &modifyTime->value[modifyTime->len * i]; tmpCollType = &collType->value[collType->len * i]; tmpCollInfo1 = &collInfo1->value[collInfo1->len * i]; tmpCollInfo2 = &collInfo2->value[collInfo2->len * i]; specColl = &tmpSpecCollCache->specColl; status = resolveSpecCollType( tmpCollType, tmpCollection, tmpCollInfo1, tmpCollInfo2, specColl ); if ( status < 0 ) { free( tmpSpecCollCache ); return status; } // =-=-=-=-=-=-=- // JMC - backport 4680 if ( specColl->collClass == STRUCT_FILE_COLL && specColl->type == TAR_STRUCT_FILE_T ) { /* tar struct file. need to get phyPath */ status = getPhyPath( rsComm, specColl->objPath, specColl->resource, specColl->phyPath, specColl->rescHier ); if ( status < 0 ) { rodsLog( LOG_ERROR, "queueSpecCollCache - getPhyPath failed for [%s] on resource [%s] with cache dir [%s] and collection [%s]", specColl->objPath, specColl->resource, specColl->cacheDir, specColl->collection ); free( tmpSpecCollCache ); return status; } } // =-=-=-=-=-=-=- rstrcpy( tmpSpecCollCache->collId, tmpDataId, NAME_LEN ); rstrcpy( tmpSpecCollCache->ownerName, tmpOwnerName, NAME_LEN ); rstrcpy( tmpSpecCollCache->ownerZone, tmpOwnerZone, NAME_LEN ); rstrcpy( tmpSpecCollCache->createTime, tmpCreateTime, TIME_LEN ); rstrcpy( tmpSpecCollCache->modifyTime, tmpModifyTime, TIME_LEN ); tmpSpecCollCache->next = SpecCollCacheHead; SpecCollCacheHead = tmpSpecCollCache; return 0; } } return CAT_NO_ROWS_FOUND; }
int _rsRuleExecDel( rsComm_t *rsComm, ruleExecDelInp_t *ruleExecDelInp ) { genQueryOut_t *genQueryOut = NULL; int status; sqlResult_t *reiFilePath; sqlResult_t *ruleUserName; char reiDir[MAX_NAME_LEN]; std::string svc_role; irods::error ret = get_catalog_service_role(svc_role); if(!ret.ok()) { irods::log(PASS(ret)); return ret.code(); } status = getReInfoById( rsComm, ruleExecDelInp->ruleExecId, &genQueryOut ); if ( status < 0 ) { rodsLog( LOG_ERROR, "_rsRuleExecDel: getReInfoById failed, status = %d", status ); /* unregister it anyway */ if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) { status = chlDelRuleExec( rsComm, ruleExecDelInp->ruleExecId ); if ( status < 0 ) { rodsLog( LOG_ERROR, "_rsRuleExecDel: chlDelRuleExec for %s error, status = %d", ruleExecDelInp->ruleExecId, status ); } return status; } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) { rodsLog( LOG_ERROR, "_rsRuleExecDel: chlDelRuleExec only in ICAT host" ); return SYS_NO_RCAT_SERVER_ERR; } else { const auto err{ERROR(SYS_SERVICE_ROLE_NOT_SUPPORTED, (boost::format("role not supported [%s]") % svc_role.c_str()).str().c_str())}; irods::log(err); return err.code(); } } if ( ( reiFilePath = getSqlResultByInx( genQueryOut, COL_RULE_EXEC_REI_FILE_PATH ) ) == NULL ) { rodsLog( LOG_NOTICE, "_rsRuleExecDel: getSqlResultByInx for REI_FILE_PATH failed" ); return UNMATCHED_KEY_OR_INDEX; } /* First check permission (now that API is allowed for non-admin users) */ if ( rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH ) { if ( rsComm->proxyUser.authInfo.authFlag == LOCAL_USER_AUTH ) { if ( ( ruleUserName = getSqlResultByInx( genQueryOut, COL_RULE_EXEC_USER_NAME ) ) == NULL ) { rodsLog( LOG_NOTICE, "_rsRuleExecDel: getSqlResultByInx for COL_RULE_EXEC_USER_NAME failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( strncmp( ruleUserName->value, rsComm->clientUser.userName, MAX_NAME_LEN ) != 0 ) { return USER_ACCESS_DENIED; } } else { return USER_ACCESS_DENIED; } } /* some sanity check */ snprintf( reiDir, MAX_NAME_LEN, "/%-s/%-s.", PACKED_REI_DIR, REI_FILE_NAME ); if ( strstr( reiFilePath->value, reiDir ) == NULL ) { if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) { int i; char errMsg[105]; rodsLog( LOG_NOTICE, "_rsRuleExecDel: reiFilePath: %s is not a proper rei path", reiFilePath->value ); /* Try to unregister it anyway */ status = chlDelRuleExec( rsComm, ruleExecDelInp->ruleExecId ); if ( status ) { return ( status ); /* that failed too, report it */ } /* Add a message to the error stack for the client user */ snprintf( errMsg, sizeof errMsg, "Rule was removed but reiPath was invalid: %s", reiFilePath->value ); i = addRErrorMsg( &rsComm->rError, 0, errMsg ); if ( i < 0 ) { irods::log( ERROR( i, "addRErrorMsg failed" ) ); } freeGenQueryOut( &genQueryOut ); return SYS_INVALID_FILE_PATH; } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) { rodsLog( LOG_ERROR, "_rsRuleExecDel: chlDelRuleExec only in ICAT host" ); return SYS_NO_RCAT_SERVER_ERR; } else { const auto err{ERROR(SYS_SERVICE_ROLE_NOT_SUPPORTED, (boost::format("role not supported [%s]") % svc_role.c_str()).str().c_str())}; irods::log(err); return err.code(); } } status = unlink( reiFilePath->value ); if ( status < 0 ) { status = UNIX_FILE_UNLINK_ERR - errno; rodsLog( LOG_ERROR, "_rsRuleExecDel: unlink of %s error, status = %d", reiFilePath->value, status ); if ( errno != ENOENT ) { freeGenQueryOut( &genQueryOut ); return status; } } if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) { int unlinkStatus = status; /* unregister it */ status = chlDelRuleExec( rsComm, ruleExecDelInp->ruleExecId ); if ( status < 0 ) { rodsLog( LOG_ERROR, "_rsRuleExecDel: chlDelRuleExec for %s error, status = %d", ruleExecDelInp->ruleExecId, status ); } if ( unlinkStatus ) { int i; char errMsg[105]; /* Add a message to the error stack for the client user */ snprintf( errMsg, sizeof errMsg, "Rule was removed but unlink of rei file failed" ); i = addRErrorMsg( &rsComm->rError, 0, errMsg ); if ( i < 0 ) { irods::log( ERROR( i, "addRErrorMsg failed" ) ); } snprintf( errMsg, sizeof errMsg, "rei file: %s", reiFilePath->value ); i = addRErrorMsg( &rsComm->rError, 1, errMsg ); if (i < 0) { irods::log(ERROR(i, "addRErrorMsg failed")); } if ( status == 0 ) { /* return this error if no other error occurred */ status = unlinkStatus; } } freeGenQueryOut( &genQueryOut ); return status; } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) { rodsLog( LOG_ERROR, "_rsRuleExecDel: chlDelRuleExec only in ICAT host" ); return SYS_NO_RCAT_SERVER_ERR; } else { const auto err{ERROR(SYS_SERVICE_ROLE_NOT_SUPPORTED, (boost::format("role not supported [%s]") % svc_role.c_str()).str().c_str())}; irods::log(err); return err.code(); } }
// =-=-=-=-=-=-=- // public - take results from genQuery, extract values and create resources error resource_manager::process_init_results( genQueryOut_t* _result ) { // =-=-=-=-=-=-=- // extract results from query if ( !_result ) { return ERROR( SYS_INVALID_INPUT_PARAM, "_result parameter is null" ); } // =-=-=-=-=-=-=- // values to extract from query sqlResult_t *rescId = 0, *rescName = 0, *zoneName = 0, *rescType = 0, *rescClass = 0; sqlResult_t *rescLoc = 0, *rescVaultPath = 0, *freeSpace = 0, *rescInfo = 0; sqlResult_t *rescComments = 0, *rescCreate = 0, *rescModify = 0, *rescStatus = 0; sqlResult_t *rescChildren = 0, *rescContext = 0, *rescParent = 0, *rescObjCount = 0; // =-=-=-=-=-=-=- // extract results from query if ( ( rescId = getSqlResultByInx( _result, COL_R_RESC_ID ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_ID failed" ); } if ( ( rescName = getSqlResultByInx( _result, COL_R_RESC_NAME ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_NAME failed" ); } if ( ( zoneName = getSqlResultByInx( _result, COL_R_ZONE_NAME ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_ZONE_NAME failed" ); } if ( ( rescType = getSqlResultByInx( _result, COL_R_TYPE_NAME ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_TYPE_NAME failed" ); } if ( ( rescClass = getSqlResultByInx( _result, COL_R_CLASS_NAME ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_CLASS_NAME failed" ); } if ( ( rescLoc = getSqlResultByInx( _result, COL_R_LOC ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_LOC failed" ); } if ( ( rescVaultPath = getSqlResultByInx( _result, COL_R_VAULT_PATH ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_VAULT_PATH failed" ); } if ( ( freeSpace = getSqlResultByInx( _result, COL_R_FREE_SPACE ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_FREE_SPACE failed" ); } if ( ( rescInfo = getSqlResultByInx( _result, COL_R_RESC_INFO ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_INFO failed" ); } if ( ( rescComments = getSqlResultByInx( _result, COL_R_RESC_COMMENT ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_COMMENT failed" ); } if ( ( rescCreate = getSqlResultByInx( _result, COL_R_CREATE_TIME ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_CREATE_TIME failed" ); } if ( ( rescModify = getSqlResultByInx( _result, COL_R_MODIFY_TIME ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_MODIFY_TIME failed" ); } if ( ( rescStatus = getSqlResultByInx( _result, COL_R_RESC_STATUS ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_STATUS failed" ); } if ( ( rescChildren = getSqlResultByInx( _result, COL_R_RESC_CHILDREN ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_CHILDREN failed" ); } if ( ( rescContext = getSqlResultByInx( _result, COL_R_RESC_CONTEXT ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_CONTEXT failed" ); } if ( ( rescParent = getSqlResultByInx( _result, COL_R_RESC_PARENT ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_PARENT failed" ); } if ( ( rescObjCount = getSqlResultByInx( _result, COL_R_RESC_OBJCOUNT ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_OBJCOUNT failed" ); } // =-=-=-=-=-=-=- // iterate through the rows, initialize a resource for each entry for ( int i = 0; i < _result->rowCnt; ++i ) { // =-=-=-=-=-=-=- // extract row values std::string tmpRescId = &rescId->value[ rescId->len * i ]; std::string tmpRescLoc = &rescLoc->value[ rescLoc->len * i ]; std::string tmpRescName = &rescName->value[ rescName->len * i ]; std::string tmpZoneName = &zoneName->value[ zoneName->len * i ]; std::string tmpRescType = &rescType->value[ rescType->len * i ]; std::string tmpRescInfo = &rescInfo->value[ rescInfo->len * i ]; std::string tmpFreeSpace = &freeSpace->value[ freeSpace->len * i ]; std::string tmpRescClass = &rescClass->value[ rescClass->len * i ]; std::string tmpRescCreate = &rescCreate->value[ rescCreate->len * i ]; std::string tmpRescModify = &rescModify->value[ rescModify->len * i ]; std::string tmpRescStatus = &rescStatus->value[ rescStatus->len * i ]; std::string tmpRescComments = &rescComments->value[ rescComments->len * i ]; std::string tmpRescVaultPath = &rescVaultPath->value[ rescVaultPath->len * i ]; std::string tmpRescChildren = &rescChildren->value[ rescChildren->len * i ]; std::string tmpRescContext = &rescContext->value[ rescContext->len * i ]; std::string tmpRescParent = &rescParent->value[ rescParent->len * i ]; std::string tmpRescObjCount = &rescObjCount->value[ rescObjCount->len * i ]; // =-=-=-=-=-=-=- // create the resource and add properties for column values resource_ptr resc; error ret = load_resource_plugin( resc, tmpRescType, tmpRescName, tmpRescContext ); if ( !ret.ok() ) { return PASSMSG( "Failed to load Resource Plugin", ret ); } // =-=-=-=-=-=-=- // resolve the host name into a rods server host structure if ( tmpRescLoc != irods::EMPTY_RESC_HOST ) { rodsHostAddr_t addr; rstrcpy( addr.hostAddr, const_cast<char*>( tmpRescLoc.c_str() ), LONG_NAME_LEN ); rstrcpy( addr.zoneName, const_cast<char*>( tmpZoneName.c_str() ), NAME_LEN ); rodsServerHost_t* tmpRodsServerHost = 0; if ( resolveHost( &addr, &tmpRodsServerHost ) < 0 ) { rodsLog( LOG_NOTICE, "procAndQueRescResult: resolveHost error for %s", addr.hostAddr ); } resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, tmpRodsServerHost ); } else { resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, 0 ); } resc->set_property<long>( RESOURCE_ID, strtoll( tmpRescId.c_str(), 0, 0 ) ); resc->set_property<long>( RESOURCE_FREESPACE, strtoll( tmpFreeSpace.c_str(), 0, 0 ) ); resc->set_property<long>( RESOURCE_QUOTA, RESC_QUOTA_UNINIT ); resc->set_property<std::string>( RESOURCE_ZONE, tmpZoneName ); resc->set_property<std::string>( RESOURCE_NAME, tmpRescName ); resc->set_property<std::string>( RESOURCE_LOCATION, tmpRescLoc ); resc->set_property<std::string>( RESOURCE_TYPE, tmpRescType ); resc->set_property<std::string>( RESOURCE_CLASS, tmpRescClass ); resc->set_property<std::string>( RESOURCE_PATH, tmpRescVaultPath ); resc->set_property<std::string>( RESOURCE_INFO, tmpRescInfo ); resc->set_property<std::string>( RESOURCE_COMMENTS, tmpRescComments ); resc->set_property<std::string>( RESOURCE_CREATE_TS, tmpRescCreate ); resc->set_property<std::string>( RESOURCE_MODIFY_TS, tmpRescModify ); resc->set_property<std::string>( RESOURCE_CHILDREN, tmpRescChildren ); resc->set_property<std::string>( RESOURCE_PARENT, tmpRescParent ); resc->set_property<std::string>( RESOURCE_CONTEXT, tmpRescContext ); resc->set_property<std::string>( RESOURCE_OBJCOUNT, tmpRescObjCount ); if ( tmpRescStatus == std::string( RESC_DOWN ) ) { resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_DOWN ); } else { resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_UP ); } // =-=-=-=-=-=-=- // add new resource to the map resources_[ tmpRescName ] = resc; } // for i return SUCCESS(); } // process_init_results
int irods_reli_getdir( const char *host, const char *path, void (*callback) ( const char *path, void *arg ), void *arg ) { int i; int result; int keepgoing; queryHandle_t query_handle; genQueryInp_t query_in; genQueryOut_t *query_out = 0; sqlResult_t *value; /* Special case: /irods looks like an empty dir */ if(!host[0]) { callback(".",arg); callback("..",arg); return 0; } struct irods_server *server = connect_to_host(host); if(!server) return -1; /* First we set up a query for file names */ memset(&query_in,0,sizeof(query_in)); query_out = 0; rclInitQueryHandle(&query_handle,server->conn); debug(D_IRODS,"queryDataObjInColl %s %s",host,path); result = queryDataObjInColl(&query_handle,(char*)path,0,&query_in,&query_out,0); debug(D_IRODS,"= %d",result); if(result<0 && result!=CAT_NO_ROWS_FOUND) { errno = ENOTDIR; return -1; } callback(".",arg); callback("..",arg); while(result>=0) { value = getSqlResultByInx(query_out,COL_DATA_NAME); if(!value) break; char *subname = value->value; for(i=0;i<query_out->rowCnt;i++) { callback(subname,arg); subname += value->len; } keepgoing = query_out->continueInx; freeGenQueryOut(&query_out); if(keepgoing>0) { query_in.continueInx = keepgoing; debug(D_IRODS,"rcGenQuery %s",host); result = rcGenQuery(server->conn,&query_in,&query_out); debug(D_IRODS,"= %d",result); } else { break; } } /* Now we set up a SECOND query for directory names */ memset(&query_in,0,sizeof(query_in)); query_out = 0; rclInitQueryHandle(&query_handle,server->conn); debug(D_IRODS,"queryCollInColl %s %s",host,path); result = queryCollInColl(&query_handle,(char*)path,0,&query_in,&query_out); debug(D_IRODS,"= %d",result); if(result<0 && result!=CAT_NO_ROWS_FOUND) { return 0; } while(result>=0) { value = getSqlResultByInx(query_out,COL_COLL_NAME); if(!value) break; char *subname = value->value; for(i=0;i<query_out->rowCnt;i++) { callback(subname,arg); subname += value->len; } keepgoing = query_out->continueInx; freeGenQueryOut(&query_out); if(keepgoing>0) { query_in.continueInx = keepgoing; debug(D_IRODS,"rcGenQuery %s",host); result = rcGenQuery(server->conn,&query_in,&query_out); debug(D_IRODS,"= %d",result); } else { break; } } return 0; }
int initZone( rsComm_t *rsComm ) { rodsServerHost_t *tmpRodsServerHost; rodsServerHost_t *masterServerHost = NULL; rodsServerHost_t *slaveServerHost = NULL; genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; int status, i; sqlResult_t *zoneName, *zoneType, *zoneConn, *zoneComment; char *tmpZoneName, *tmpZoneType, *tmpZoneConn;//, *tmpZoneComment; irods::server_properties& props = irods::server_properties::getInstance(); irods::error ret = props.capture_if_needed(); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return ret.code(); } std::string zone_name; ret = props.get_property < std::string > ( irods::CFG_ZONE_NAME, zone_name ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return ret.code(); } /* configure the local zone first or rsGenQuery would not work */ tmpRodsServerHost = ServerHostHead; while ( tmpRodsServerHost != NULL ) { if ( tmpRodsServerHost->rcatEnabled == LOCAL_ICAT ) { tmpRodsServerHost->zoneInfo = ZoneInfoHead; masterServerHost = tmpRodsServerHost; } else if ( tmpRodsServerHost->rcatEnabled == LOCAL_SLAVE_ICAT ) { tmpRodsServerHost->zoneInfo = ZoneInfoHead; slaveServerHost = tmpRodsServerHost; } tmpRodsServerHost = tmpRodsServerHost->next; } ZoneInfoHead->masterServerHost = masterServerHost; ZoneInfoHead->slaveServerHost = slaveServerHost; memset( &genQueryInp, 0, sizeof( genQueryInp ) ); addInxIval( &genQueryInp.selectInp, COL_ZONE_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_ZONE_TYPE, 1 ); addInxIval( &genQueryInp.selectInp, COL_ZONE_CONNECTION, 1 ); addInxIval( &genQueryInp.selectInp, COL_ZONE_COMMENT, 1 ); genQueryInp.maxRows = MAX_SQL_ROWS; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); clearGenQueryInp( &genQueryInp ); if ( status < 0 ) { freeGenQueryOut( &genQueryOut ); rodsLog( LOG_NOTICE, "initZone: rsGenQuery error, status = %d", status ); return status; } if ( genQueryOut == NULL ) { rodsLog( LOG_NOTICE, "initZone: NULL genQueryOut" ); return CAT_NO_ROWS_FOUND; } if ( ( zoneName = getSqlResultByInx( genQueryOut, COL_ZONE_NAME ) ) == NULL ) { rodsLog( LOG_NOTICE, "initZone: getSqlResultByInx for COL_ZONE_NAME failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( zoneType = getSqlResultByInx( genQueryOut, COL_ZONE_TYPE ) ) == NULL ) { rodsLog( LOG_NOTICE, "initZone: getSqlResultByInx for COL_ZONE_TYPE failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( zoneConn = getSqlResultByInx( genQueryOut, COL_ZONE_CONNECTION ) ) == NULL ) { rodsLog( LOG_NOTICE, "initZone: getSqlResultByInx for COL_ZONE_CONNECTION failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( zoneComment = getSqlResultByInx( genQueryOut, COL_ZONE_COMMENT ) ) == NULL ) { rodsLog( LOG_NOTICE, "initZone: getSqlResultByInx for COL_ZONE_COMMENT failed" ); return UNMATCHED_KEY_OR_INDEX; } for ( i = 0; i < genQueryOut->rowCnt; i++ ) { rodsHostAddr_t addr; tmpZoneName = &zoneName->value[zoneName->len * i]; tmpZoneType = &zoneType->value[zoneType->len * i]; tmpZoneConn = &zoneConn->value[zoneConn->len * i]; //tmpZoneComment = &zoneComment->value[zoneComment->len * i]; if ( strcmp( tmpZoneType, "local" ) == 0 ) { if ( strcmp( zone_name.c_str(), tmpZoneName ) != 0 ) { rodsLog( LOG_ERROR, "initZone: zoneName in env %s does not match %s in icat ", zone_name.c_str(), tmpZoneName ); } /* fillin rodsZone if it is not defined */ if ( strlen( rsComm->proxyUser.rodsZone ) == 0 ) { rstrcpy( rsComm->proxyUser.rodsZone, tmpZoneName, NAME_LEN ); } if ( strlen( rsComm->clientUser.rodsZone ) == 0 ) { rstrcpy( rsComm->clientUser.rodsZone, tmpZoneName, NAME_LEN ); } continue; } else if ( strlen( tmpZoneConn ) <= 0 ) { rodsLog( LOG_ERROR, "initZone: connection info for zone %s not configured", tmpZoneName ); continue; } memset( &addr, 0, sizeof( addr ) ); /* assume address:port */ parseHostAddrStr( tmpZoneConn, &addr ); if ( addr.portNum == 0 ) { addr.portNum = ZoneInfoHead->portNum; } rstrcpy( addr.zoneName, tmpZoneName, NAME_LEN ); // JMC - bacport 4562 status = resolveHost( &addr, &tmpRodsServerHost ); if ( status < 0 ) { rodsLog( LOG_ERROR, "initZone: resolveHost error for %s for zone %s. status = %d", addr.hostAddr, tmpZoneName, status ); continue; } if ( tmpRodsServerHost->rcatEnabled == LOCAL_ICAT ) { rodsLog( LOG_ERROR, "initZone: address %s for remote zone %s already in use", tmpZoneConn, tmpZoneName ); continue; } tmpRodsServerHost->rcatEnabled = REMOTE_ICAT; /* REMOTE_ICAT is always on a remote host even if it is one the same * host, but will be on different port */ tmpRodsServerHost->localFlag = REMOTE_HOST; // JMC - bacport 4562 queZone( tmpZoneName, addr.portNum, tmpRodsServerHost, NULL ); } freeGenQueryOut( &genQueryOut ); return 0; }
int dataObjStat (rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsObjStat_t **rodsObjStatOut) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; int status; char myColl[MAX_NAME_LEN], myData[MAX_NAME_LEN]; char condStr[MAX_NAME_LEN]; sqlResult_t *dataSize; sqlResult_t *dataMode; sqlResult_t *replStatus; sqlResult_t *dataId; sqlResult_t *chksum; sqlResult_t *ownerName; sqlResult_t *ownerZone; sqlResult_t *createTime; sqlResult_t *modifyTime; /* see if objPath is a dataObj */ memset (myColl, 0, MAX_NAME_LEN); memset (myData, 0, MAX_NAME_LEN); if ((status = splitPathByKey ( dataObjInp->objPath, myColl, myData, '/')) < 0) { return (OBJ_PATH_DOES_NOT_EXIST); } memset (&genQueryInp, 0, sizeof (genQueryInp)); snprintf (condStr, MAX_NAME_LEN, "='%s'", myColl); addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, condStr); snprintf (condStr, MAX_NAME_LEN, "='%s'", myData); addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, condStr); addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, 1); addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, 1); addInxIval (&genQueryInp.selectInp, COL_DATA_MODE, 1); addInxIval (&genQueryInp.selectInp, COL_D_REPL_STATUS, 1); addInxIval (&genQueryInp.selectInp, COL_D_DATA_CHECKSUM, 1); addInxIval (&genQueryInp.selectInp, COL_D_OWNER_NAME, 1); addInxIval (&genQueryInp.selectInp, COL_D_OWNER_ZONE, 1); addInxIval (&genQueryInp.selectInp, COL_D_CREATE_TIME, 1); addInxIval (&genQueryInp.selectInp, COL_D_MODIFY_TIME, 1); genQueryInp.maxRows = MAX_SQL_ROWS; status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut); clearGenQueryInp (&genQueryInp); if (status >= 0) { if ((dataSize = getSqlResultByInx (genQueryOut, COL_DATA_SIZE)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat: getSqlResultByInx for COL_DATA_SIZE failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((dataMode = getSqlResultByInx (genQueryOut, COL_DATA_MODE)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat: getSqlResultByInx for COL_DATA_MODE failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((replStatus = getSqlResultByInx (genQueryOut, COL_D_REPL_STATUS)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat: getSqlResultByInx for COL_D_REPL_STATUS failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((dataId = getSqlResultByInx (genQueryOut, COL_D_DATA_ID)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat: getSqlResultByInx for COL_D_DATA_ID failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((chksum = getSqlResultByInx (genQueryOut, COL_D_DATA_CHECKSUM)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_D_DATA_CHECKSUM failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((ownerName = getSqlResultByInx (genQueryOut, COL_D_OWNER_NAME)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_D_OWNER_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((ownerZone = getSqlResultByInx (genQueryOut, COL_D_OWNER_ZONE)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_D_OWNER_ZONE failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((createTime = getSqlResultByInx (genQueryOut, COL_D_CREATE_TIME)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_D_CREATE_TIME failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((modifyTime = getSqlResultByInx (genQueryOut, COL_D_MODIFY_TIME)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_D_MODIFY_TIME failed"); return (UNMATCHED_KEY_OR_INDEX); } else { int i; *rodsObjStatOut = (rodsObjStat_t *) malloc (sizeof (rodsObjStat_t)); memset (*rodsObjStatOut, 0, sizeof (rodsObjStat_t)); (*rodsObjStatOut)->objType = DATA_OBJ_T; status = (int)DATA_OBJ_T; /* XXXXXX . dont have numCopies anymore. Replaced by dataMode * (*rodsObjStatOut)->numCopies = genQueryOut->rowCnt; */ for (i = 0;i < genQueryOut->rowCnt; i++) { if (atoi (&replStatus->value[replStatus->len * i]) > 0) { rstrcpy ((*rodsObjStatOut)->dataId, &dataId->value[dataId->len * i], NAME_LEN); (*rodsObjStatOut)->objSize = strtoll (&dataSize->value[dataSize->len * i], 0, 0); (*rodsObjStatOut)->dataMode = atoi (&dataMode->value[dataMode->len * i]); rstrcpy ((*rodsObjStatOut)->chksum, &chksum->value[chksum->len * i], NAME_LEN); rstrcpy ((*rodsObjStatOut)->ownerName, &ownerName->value[ownerName->len * i], NAME_LEN); rstrcpy ((*rodsObjStatOut)->ownerZone, &ownerZone->value[ownerZone->len * i], NAME_LEN); rstrcpy ((*rodsObjStatOut)->createTime, &createTime->value[createTime->len * i], TIME_LEN); rstrcpy ((*rodsObjStatOut)->modifyTime, &modifyTime->value[modifyTime->len * i], TIME_LEN); break; } } if (strlen ((*rodsObjStatOut)->dataId) == 0) { /* just use the first one */ rstrcpy ((*rodsObjStatOut)->dataId, dataId->value, NAME_LEN); (*rodsObjStatOut)->objSize = strtoll (dataSize->value, 0, 0); rstrcpy ((*rodsObjStatOut)->chksum, chksum->value, NAME_LEN); rstrcpy ((*rodsObjStatOut)->ownerName, ownerName->value, NAME_LEN); rstrcpy ((*rodsObjStatOut)->ownerZone, ownerZone->value, NAME_LEN); rstrcpy ((*rodsObjStatOut)->createTime, createTime->value, NAME_LEN); rstrcpy ((*rodsObjStatOut)->modifyTime, modifyTime->value, NAME_LEN); } } freeGenQueryOut (&genQueryOut); } return (status); }
int printCollAcl (rcComm_t *conn, char *collName) { genQueryOut_t *genQueryOut = NULL; int status; int i; sqlResult_t *userName, *userZone, *dataAccess ; char *userNameStr, *userZoneStr, *dataAccessStr; printf (" ACL - "); /* First try a specific-query. If this is defined, it should be used as it returns the group names without expanding them to individual users and this is important to some sites (iPlant, in particular). If this fails, go on the the general-query. */ status = queryCollAclSpecific (conn, collName, zoneHint, &genQueryOut); if (status >= 0) { int i, j; for (i=0;i<genQueryOut->rowCnt;i++) { char *tResult[10]; char typeStr[8]; tResult[3]=0; for (j=0;j<genQueryOut->attriCnt && j<10;j++) { tResult[j] = genQueryOut->sqlResult[j].value; tResult[j] += i*genQueryOut->sqlResult[j].len; } typeStr[0]='\0'; if (tResult[3]!=0 && strncmp(tResult[3],"rodsgroup",9)==0) { strncpy(typeStr,"g:",3); } printf ("%s%s#%s:%s ", typeStr, tResult[0], tResult[1], tResult[2]); } printf ("\n"); return(status); } status = queryCollAcl (conn, collName, zoneHint, &genQueryOut); if (status < 0) { printf ("\n"); return (status); } if ((userName = getSqlResultByInx (genQueryOut, COL_COLL_USER_NAME)) == NULL) { rodsLog (LOG_ERROR, "printCollAcl: getSqlResultByInx for COL_COLL_USER_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((userZone = getSqlResultByInx (genQueryOut, COL_COLL_USER_ZONE)) == NULL) { rodsLog (LOG_ERROR, "printCollAcl: getSqlResultByInx for COL_COLL_USER_ZONE failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((dataAccess = getSqlResultByInx (genQueryOut, COL_COLL_ACCESS_NAME)) == NULL) { rodsLog (LOG_ERROR, "printCollAcl: getSqlResultByInx for COL_COLL_ACCESS_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } for (i = 0; i < genQueryOut->rowCnt; i++) { userNameStr = &userName->value[userName->len * i]; userZoneStr = &userZone->value[userZone->len * i]; dataAccessStr = &dataAccess->value[dataAccess->len * i]; printf ("%s#%s:%s ", userNameStr, userZoneStr, dataAccessStr); } printf ("\n"); freeGenQueryOut (&genQueryOut); return (status); }
int rsQueryDirectoryMeta( rsComm_t *rsComm, char *collection, keyValPair_t *condInput ) { static char fname[] = "rsQueryDirectoryMeta"; genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; int status; char condStr[MAX_NAME_LEN]; sqlResult_t *objectId; sqlResult_t *fileUid; sqlResult_t *fileGid; sqlResult_t *fileOwner; sqlResult_t *fileGroup; sqlResult_t *fileMode; sqlResult_t *fileCtime; sqlResult_t *fileMtime; sqlResult_t *fileSourcePath; if ( collection == NULL || condInput == NULL ) { return USER__NULL_INPUT_ERR; } memset( &genQueryInp, 0, sizeof( genQueryInp ) ); snprintf( condStr, MAX_NAME_LEN, "='%s'", collection ); addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, condStr ); addInxIval( &genQueryInp.selectInp, COL_COLL_FILEMETA_OBJ_ID, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_FILEMETA_UID, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_FILEMETA_GID, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_FILEMETA_OWNER, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_FILEMETA_GROUP, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_FILEMETA_MODE, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_FILEMETA_CTIME, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_FILEMETA_MTIME, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_FILEMETA_SOURCE_PATH, 1 ); genQueryInp.maxRows = MAX_SQL_ROWS; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); if ( status >= 0 ) { if ( ( objectId = getSqlResultByInx( genQueryOut, COL_COLL_FILEMETA_OBJ_ID ) ) == NULL ) { rodsLog( LOG_ERROR, "%s: getSqlResultByInx for COL_COLL_FILEMETA_OBJ_ID failed", fname ); return ( UNMATCHED_KEY_OR_INDEX ); } if ( ( fileUid = getSqlResultByInx( genQueryOut, COL_COLL_FILEMETA_UID ) ) == NULL ) { rodsLog( LOG_ERROR, "%s: getSqlResultByInx for COL_COLL_FILEMETA_UID failed", fname ); return ( UNMATCHED_KEY_OR_INDEX ); } if ( ( fileGid = getSqlResultByInx( genQueryOut, COL_COLL_FILEMETA_GID ) ) == NULL ) { rodsLog( LOG_ERROR, "%s: getSqlResultByInx for COL_COLL_FILEMETA_GID failed", fname ); return ( UNMATCHED_KEY_OR_INDEX ); } if ( ( fileOwner = getSqlResultByInx( genQueryOut, COL_COLL_FILEMETA_OWNER ) ) == NULL ) { rodsLog( LOG_ERROR, "%s: getSqlResultByInx for COL_COLL_FILEMETA_OWNER failed", fname ); return ( UNMATCHED_KEY_OR_INDEX ); } if ( ( fileGroup = getSqlResultByInx( genQueryOut, COL_COLL_FILEMETA_GROUP ) ) == NULL ) { rodsLog( LOG_ERROR, "%s: getSqlResultByInx for COL_COLL_FILEMETA_GROUP failed", fname ); return ( UNMATCHED_KEY_OR_INDEX ); } if ( ( fileMode = getSqlResultByInx( genQueryOut, COL_COLL_FILEMETA_MODE ) ) == NULL ) { rodsLog( LOG_ERROR, "%s: getSqlResultByInx for COL_COLL_FILEMETA_MODE failed", fname ); return ( UNMATCHED_KEY_OR_INDEX ); } if ( ( fileCtime = getSqlResultByInx( genQueryOut, COL_COLL_FILEMETA_CTIME ) ) == NULL ) { rodsLog( LOG_ERROR, "%s: getSqlResultByInx for COL_COLL_FILEMETA_CTIME failed", fname ); return ( UNMATCHED_KEY_OR_INDEX ); } if ( ( fileMtime = getSqlResultByInx( genQueryOut, COL_COLL_FILEMETA_MTIME ) ) == NULL ) { rodsLog( LOG_ERROR, "%s: getSqlResultByInx for COL_COLL_FILEMETA_MTIME failed", fname ); return ( UNMATCHED_KEY_OR_INDEX ); } if ( ( fileSourcePath = getSqlResultByInx( genQueryOut, COL_COLL_FILEMETA_SOURCE_PATH ) ) == NULL ) { rodsLog( LOG_ERROR, "%s: getSqlResultByInx for COL_COLL_FILEMETA_SOURCE_PATH failed", fname ); return ( UNMATCHED_KEY_OR_INDEX ); } addKeyVal( condInput, FILE_UID_KW, fileUid->value ); addKeyVal( condInput, FILE_GID_KW, fileGid->value ); addKeyVal( condInput, FILE_OWNER_KW, fileOwner->value ); addKeyVal( condInput, FILE_GROUP_KW, fileGroup->value ); addKeyVal( condInput, FILE_MODE_KW, fileMode->value ); addKeyVal( condInput, FILE_CTIME_KW, fileCtime->value ); addKeyVal( condInput, FILE_MTIME_KW, fileMtime->value ); addKeyVal( condInput, FILE_SOURCE_PATH_KW, fileSourcePath->value ); } clearGenQueryInp( &genQueryInp ); freeGenQueryOut( &genQueryOut ); return status; }
int printLsLong( rcComm_t *conn, rodsArguments_t *rodsArgs, genQueryOut_t *genQueryOut ) { int i = 0; sqlResult_t *dataName = 0, *replNum = 0, *dataSize = 0, *rescName = 0, *rescHier = 0, *replStatus = 0, *dataModify = 0, *dataOwnerName = 0, *dataId = 0; sqlResult_t *chksumStr = 0, *dataPath = 0, *dataType = 0; // JMC - backport 4636 char *tmpDataId = 0; int queryFlags = 0; if ( genQueryOut == NULL ) { return USER__NULL_INPUT_ERR; } queryFlags = setQueryFlag( rodsArgs ); if ( rodsArgs->veryLongOption == True ) { if ( ( chksumStr = getSqlResultByInx( genQueryOut, COL_D_DATA_CHECKSUM ) ) == NULL ) { rodsLog( LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_DATA_CHECKSUM failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( dataPath = getSqlResultByInx( genQueryOut, COL_D_DATA_PATH ) ) == NULL ) { rodsLog( LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_DATA_PATH failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( dataType = getSqlResultByInx( genQueryOut, COL_DATA_TYPE_NAME ) ) == NULL ) { // JMC - backport 4636 rodsLog( LOG_ERROR, "printLsLong: getSqlResultByInx for COL_DATA_TYPE_NAME failed" ); return UNMATCHED_KEY_OR_INDEX; } } if ( ( dataId = getSqlResultByInx( genQueryOut, COL_D_DATA_ID ) ) == NULL ) { rodsLog( LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_DATA_ID failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( dataName = getSqlResultByInx( genQueryOut, COL_DATA_NAME ) ) == NULL ) { rodsLog( LOG_ERROR, "printLsLong: getSqlResultByInx for COL_DATA_NAME failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( replNum = getSqlResultByInx( genQueryOut, COL_DATA_REPL_NUM ) ) == NULL ) { rodsLog( LOG_ERROR, "printLsLong: getSqlResultByInx for COL_DATA_REPL_NUM failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( dataSize = getSqlResultByInx( genQueryOut, COL_DATA_SIZE ) ) == NULL ) { rodsLog( LOG_ERROR, "printLsLong: getSqlResultByInx for COL_DATA_SIZE failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( rescName = getSqlResultByInx( genQueryOut, COL_D_RESC_NAME ) ) == NULL ) { rodsLog( LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_RESC_NAME failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( rescHier = getSqlResultByInx( genQueryOut, COL_D_RESC_HIER ) ) == NULL ) { // If the index is not found then COL_D_RESC_HIER was most likely stripped // from the query input to talk to an older zone. // use resource name instead rescHier = rescName; } if ( ( replStatus = getSqlResultByInx( genQueryOut, COL_D_REPL_STATUS ) ) == NULL ) { rodsLog( LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_REPL_STATUS failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( dataModify = getSqlResultByInx( genQueryOut, COL_D_MODIFY_TIME ) ) == NULL ) { rodsLog( LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_MODIFY_TIME failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( dataOwnerName = getSqlResultByInx( genQueryOut, COL_D_OWNER_NAME ) ) == NULL ) { rodsLog( LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_OWNER_NAME failed" ); return UNMATCHED_KEY_OR_INDEX; } for ( i = 0; i < genQueryOut->rowCnt; i++ ) { collEnt_t collEnt; bzero( &collEnt, sizeof( collEnt ) ); collEnt.dataName = &dataName->value[dataName->len * i]; collEnt.replNum = atoi( &replNum->value[replNum->len * i] ); collEnt.dataSize = strtoll( &dataSize->value[dataSize->len * i], 0, 0 ); collEnt.resource = &rescName->value[rescName->len * i]; collEnt.resc_hier = &rescHier->value[rescHier->len * i]; collEnt.ownerName = &dataOwnerName->value[dataOwnerName->len * i]; collEnt.replStatus = atoi( &replStatus->value[replStatus->len * i] ); collEnt.modifyTime = &dataModify->value[dataModify->len * i]; if ( rodsArgs->veryLongOption == True ) { collEnt.chksum = &chksumStr->value[chksumStr->len * i]; collEnt.phyPath = &dataPath->value[dataPath->len * i]; collEnt.dataType = &dataType->value[dataType->len * i]; // JMC - backport 4636 } printDataCollEntLong( &collEnt, queryFlags ); if ( rodsArgs->accessControl == True ) { tmpDataId = &dataId->value[dataId->len * i]; printDataAcl( conn, tmpDataId ); } } return 0; }
int printLsLong (rcComm_t *conn, rodsArguments_t *rodsArgs, genQueryOut_t *genQueryOut) { int i; sqlResult_t *dataName, *replNum, *dataSize, *rescName, *replStatus, *dataModify, *dataOwnerName, *dataId; sqlResult_t *chksumStr, *dataPath, *rescGrp, *dataType; char *tmpDataId; int queryFlags; if (genQueryOut == NULL) { return (USER__NULL_INPUT_ERR); } queryFlags = setQueryFlag (rodsArgs); if (rodsArgs->veryLongOption == True) { if ((chksumStr = getSqlResultByInx (genQueryOut, COL_D_DATA_CHECKSUM)) == NULL) { rodsLog (LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_DATA_CHECKSUM failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((dataPath = getSqlResultByInx (genQueryOut, COL_D_DATA_PATH)) == NULL) { rodsLog (LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_DATA_PATH failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((rescGrp = getSqlResultByInx (genQueryOut, COL_D_RESC_GROUP_NAME)) == NULL) { rodsLog (LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_RESC_GROUP_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((dataType = getSqlResultByInx (genQueryOut, COL_DATA_TYPE_NAME)) == NULL) { rodsLog (LOG_ERROR, "printLsLong: getSqlResultByInx for COL_DATA_TYPE_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } } if ((dataId = getSqlResultByInx (genQueryOut, COL_D_DATA_ID)) == NULL) { rodsLog (LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_DATA_ID failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((dataName = getSqlResultByInx (genQueryOut, COL_DATA_NAME)) == NULL) { rodsLog (LOG_ERROR, "printLsLong: getSqlResultByInx for COL_DATA_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((replNum = getSqlResultByInx (genQueryOut, COL_DATA_REPL_NUM)) == NULL) { rodsLog (LOG_ERROR, "printLsLong: getSqlResultByInx for COL_DATA_REPL_NUM failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((dataSize = getSqlResultByInx (genQueryOut, COL_DATA_SIZE)) == NULL) { rodsLog (LOG_ERROR, "printLsLong: getSqlResultByInx for COL_DATA_SIZE failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((rescName = getSqlResultByInx (genQueryOut, COL_D_RESC_NAME)) == NULL) { rodsLog (LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_RESC_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((replStatus = getSqlResultByInx (genQueryOut, COL_D_REPL_STATUS)) == NULL) { rodsLog (LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_REPL_STATUS failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((dataModify = getSqlResultByInx (genQueryOut, COL_D_MODIFY_TIME)) == NULL) { rodsLog (LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_MODIFY_TIME failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((dataOwnerName = getSqlResultByInx (genQueryOut, COL_D_OWNER_NAME)) == NULL) { rodsLog (LOG_ERROR, "printLsLong: getSqlResultByInx for COL_D_OWNER_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } for (i = 0;i < genQueryOut->rowCnt; i++) { collEnt_t collEnt; bzero (&collEnt, sizeof (collEnt)); collEnt.dataName = &dataName->value[dataName->len * i]; collEnt.replNum = atoi (&replNum->value[replNum->len * i]); collEnt.dataSize = strtoll (&dataSize->value[dataSize->len * i], 0, 0); collEnt.resource = &rescName->value[rescName->len * i]; collEnt.ownerName = &dataOwnerName->value[dataOwnerName->len * i]; collEnt.replStatus = atoi (&replStatus->value[replStatus->len * i]); collEnt.modifyTime = &dataModify->value[dataModify->len * i]; if (rodsArgs->veryLongOption == True) { collEnt.chksum = &chksumStr->value[chksumStr->len * i]; collEnt.phyPath = &dataPath->value[dataPath->len * i]; collEnt.rescGrp = &rescGrp->value[rescGrp->len * i]; collEnt.dataType = &dataType->value[dataType->len * i]; } printDataCollEntLong (&collEnt, queryFlags); if (rodsArgs->accessControl == True) { tmpDataId = &dataId->value[dataId->len * i]; printDataAcl (conn, tmpDataId); } } return (0); }
/// =-=-=-=-=-=-=- /// @brief error get_source_data_object_attributes( const int _data_id, const std::string& _parent, rsComm_t* _comm, std::string& _obj_path, std::string& _resc_hier, int& _data_mode ) { // =-=-=-=-=-=-=- // param check if ( _data_id <= 0 ) { return ERROR( SYS_INVALID_INPUT_PARAM, "invalid data id" ); } else if ( !_comm ) { return ERROR( SYS_INVALID_INPUT_PARAM, "null comm pointer" ); } // =-=-=-=-=-=-=- // gen query objects genQueryOut_t* gen_out = 0; genQueryInp_t gen_inp; memset( &gen_inp, 0, sizeof( genQueryInp_t ) ); gen_inp.maxRows = MAX_SQL_ROWS; // =-=-=-=-=-=-=- // add condition string matching data id std::stringstream id_str; id_str << _data_id; std::string cond_str = "='" + id_str.str() + "'"; addInxVal( &gen_inp.sqlCondInp, COL_D_DATA_ID, cond_str.c_str() ); // =-=-=-=-=-=-=- // add condition string matching resc hier parent cond_str = "like '" + _parent + ";%' || like '%;" + _parent + ";%' || like '%;" + _parent + "'"; //cond_str = "like '%"+_parent+"%'"; addInxVal( &gen_inp.sqlCondInp, COL_D_RESC_HIER, cond_str.c_str() ); // =-=-=-=-=-=-=- // request the data name, coll name, resc hier, mode addInxIval( &gen_inp.selectInp, COL_DATA_NAME, 1 ); addInxIval( &gen_inp.selectInp, COL_COLL_NAME, 1 ); addInxIval( &gen_inp.selectInp, COL_D_RESC_HIER, 1 ); addInxIval( &gen_inp.selectInp, COL_DATA_MODE, 1 ); // =-=-=-=-=-=-=- // execute the query int status = rsGenQuery( _comm, &gen_inp, &gen_out ); clearGenQueryInp( &gen_inp ); if ( status < 0 || 0 == gen_out ) { return ERROR( status, "genQuery failed." ); } // =-=-=-=-=-=-=- // extract result sqlResult_t* data_name_result = getSqlResultByInx( gen_out, COL_DATA_NAME ); if ( !data_name_result ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "null data_name sql result" ); } // =-=-=-=-=-=-=- // get its value char* data_name_ptr = &data_name_result->value[ 0 ];//data_name_result->len ]; if ( !data_name_ptr ) { return ERROR( SYS_INTERNAL_NULL_INPUT_ERR, "null data_name_ptr result" ); } std::string data_name = data_name_ptr; // =-=-=-=-=-=-=- // extract result sqlResult_t* coll_name_result = getSqlResultByInx( gen_out, COL_COLL_NAME ); if ( !coll_name_result ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "null coll_name sql result" ); } // =-=-=-=-=-=-=- // get its value char* coll_name_ptr = &coll_name_result->value[ 0 ];//coll_name_result->len ]; if ( !coll_name_ptr ) { return ERROR( SYS_INTERNAL_NULL_INPUT_ERR, "null coll_name_ptr result" ); } std::string coll_name = coll_name_ptr; // =-=-=-=-=-=-=- // extract result sqlResult_t* resc_hier_result = getSqlResultByInx( gen_out, COL_D_RESC_HIER ); if ( !resc_hier_result ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "null resc_hier sql result" ); } // =-=-=-=-=-=-=- // get its value char* resc_hier_ptr = &resc_hier_result->value[ 0 ];//resc_hier_result->len ]; if ( !resc_hier_ptr ) { return ERROR( SYS_INTERNAL_NULL_INPUT_ERR, "null resc_hier_ptr result" ); } // =-=-=-=-=-=-=- // extract result sqlResult_t* data_mode_result = getSqlResultByInx( gen_out, COL_DATA_MODE ); if ( !data_mode_result ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "null data_mode sql result" ); } // =-=-=-=-=-=-=- // get its value char* data_mode_ptr = &data_mode_result->value[ 0 ];//data_mode_result->len ]; if ( !resc_hier_ptr ) { return ERROR( SYS_INTERNAL_NULL_INPUT_ERR, "null data_mode_ptr result" ); } // =-=-=-=-=-=-=- // set the out variables _obj_path = coll_name + get_virtual_path_separator() + data_name; _resc_hier = resc_hier_ptr; _data_mode = atoi( data_mode_ptr ); return SUCCESS(); } // get_source_data_object_attributes
int // JMC - backport 4680 getPhyPath( rsComm_t* _comm, char* _obj_name, char* _resource, char* _phy_path, char* _resc_hier ) { // =-=-=-=-=-=-=- // if no resc hier is specified, call resolve on the object to // ask the resource composition to pick a valid hier for open std::string resc_hier; if ( 0 == strlen( _resc_hier ) ) { dataObjInp_t data_inp; memset( &data_inp, 0, sizeof( data_inp ) ); strncpy( data_inp.objPath, _obj_name, MAX_NAME_LEN ); irods::error ret = irods::resolve_resource_hierarchy( irods::OPEN_OPERATION, _comm, &data_inp, resc_hier ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return SYS_INVALID_INPUT_PARAM; } } else { resc_hier = _resc_hier; } std::string root_resc; irods::hierarchy_parser parser; parser.set_string( resc_hier ); parser.first_resc( root_resc ); // =-=-=-=-=-=-=- // perform a genquery to get the physical path of the data object // as the hier reolve does not do that for us genQueryOut_t* gen_out = NULL; char tmp_str [ MAX_NAME_LEN ]; char logical_end_name [ MAX_NAME_LEN ]; char logical_parent_dir_name[ MAX_NAME_LEN ]; // =-=-=-=-=-=-=- // split the object path by the last delimiter / int status = splitPathByKey( _obj_name, logical_parent_dir_name, MAX_NAME_LEN, logical_end_name, MAX_NAME_LEN, '/' ); genQueryInp_t gen_inp; memset( &gen_inp, 0, sizeof( genQueryInp_t ) ); // =-=-=-=-=-=-=- // add query to the struct for the data object name snprintf( tmp_str, MAX_NAME_LEN, "='%s'", logical_end_name ); addInxVal( &gen_inp.sqlCondInp, COL_DATA_NAME, tmp_str ); // =-=-=-=-=-=-=- // add query to the struct for the collection name snprintf( tmp_str, MAX_NAME_LEN, "='%s'", logical_parent_dir_name ); addInxVal( &gen_inp.sqlCondInp, COL_COLL_NAME, tmp_str ); // =-=-=-=-=-=-=- // add query to the struct for the resource hierarchy snprintf( tmp_str, MAX_NAME_LEN, "='%s'", resc_hier.c_str() ); addInxVal( &gen_inp.sqlCondInp, COL_D_RESC_HIER, tmp_str ); // =-=-=-=-=-=-=- // include request for data path and resource hierarchy addInxIval( &gen_inp.selectInp, COL_D_DATA_PATH, 1 ); // =-=-=-=-=-=-=- // request only 2 results in the set gen_inp.maxRows = 2; status = rsGenQuery( _comm, &gen_inp, &gen_out ); if ( status >= 0 ) { // =-=-=-=-=-=-=- // extract the physical path from the query sqlResult_t* phy_path_res = getSqlResultByInx( gen_out, COL_D_DATA_PATH ); if ( !phy_path_res ) { rodsLog( LOG_ERROR, "getPhyPath: getSqlResultByInx for COL_D_DATA_PATH failed" ); return UNMATCHED_KEY_OR_INDEX; } // =-=-=-=-=-=-=- // copy the results to the out variables strncpy( _phy_path, phy_path_res->value, MAX_NAME_LEN ); strncpy( _resource, root_resc.c_str(), root_resc.size() ); strncpy( _resc_hier, resc_hier.c_str(), resc_hier.size() ); freeGenQueryOut( &gen_out ); } clearGenQueryInp( &gen_inp ); return status; }
int lsSubfilesInBundle (rcComm_t *conn, char *srcPath, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs) { int i, status; genQueryOut_t *genQueryOut = NULL; genQueryInp_t genQueryInp; char condStr[MAX_NAME_LEN]; sqlResult_t *dataName, *collection, *dataSize; char *dataNameStr, *collectionStr, *dataSizeStr; int continueInx = 1; fprintf (stdout, "Bundle file: %s\n", srcPath); fprintf (stdout, "Subfiles:\n"); bzero (&genQueryInp, sizeof (genQueryInp)); genQueryInp.maxRows = MAX_SQL_ROWS; snprintf (condStr, MAX_NAME_LEN, "='%s'", srcPath); addInxVal (&genQueryInp.sqlCondInp, COL_D_DATA_PATH, condStr); snprintf (condStr, MAX_NAME_LEN, "='%s'", BUNDLE_RESC_CLASS); addInxVal (&genQueryInp.sqlCondInp, COL_R_CLASS_NAME, condStr); addKeyVal (&genQueryInp.condInput, ZONE_KW, srcPath); addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1); addInxIval (&genQueryInp.selectInp, COL_DATA_NAME, 1); addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, 1); while (continueInx > 0) { status = rcGenQuery (conn, &genQueryInp, &genQueryOut); if (status < 0) { if (status != CAT_NO_ROWS_FOUND) { rodsLogError (LOG_ERROR, status, "lsSubfilesInBundle: rsGenQuery error for %s", srcPath); } clearGenQueryInp (&genQueryInp); return (status); } if ((collection = getSqlResultByInx (genQueryOut, COL_COLL_NAME)) == NULL) { rodsLog (LOG_ERROR, "lsSubfilesInBundle: getSqlResultByInx for COL_COLL_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((dataName = getSqlResultByInx (genQueryOut, COL_DATA_NAME)) == NULL) { rodsLog (LOG_ERROR, "lsSubfilesInBundle: getSqlResultByInx for COL_DATA_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((dataSize = getSqlResultByInx (genQueryOut, COL_DATA_SIZE)) == NULL) { rodsLog (LOG_ERROR, "lsSubfilesInBundle: getSqlResultByInx for COL_DATA_SIZE failed"); return (UNMATCHED_KEY_OR_INDEX); } for (i = 0;i < genQueryOut->rowCnt; i++) { collectionStr = &collection->value[collection->len * i]; dataNameStr = &dataName->value[dataName->len * i]; dataSizeStr = &dataSize->value[dataSize->len * i]; fprintf (stdout, " %s/%s %s\n", collectionStr, dataNameStr, dataSizeStr); } if (genQueryOut != NULL) { continueInx = genQueryInp.continueInx = genQueryOut->continueInx; freeGenQueryOut (&genQueryOut); } else { continueInx = 0; } } clearGenQueryInp (&genQueryInp); return (status); }
int collStat( rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsObjStat_t **rodsObjStatOut ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; int status; char condStr[MAX_NAME_LEN]; sqlResult_t *dataId; sqlResult_t *ownerName; sqlResult_t *ownerZone; sqlResult_t *createTime; sqlResult_t *modifyTime; sqlResult_t *collType; sqlResult_t *collInfo1; sqlResult_t *collInfo2; /* see if objPath is a collection */ memset( &genQueryInp, 0, sizeof( genQueryInp ) ); snprintf( condStr, MAX_NAME_LEN, "='%s'", dataObjInp->objPath ); addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, condStr ); addInxIval( &genQueryInp.selectInp, COL_COLL_ID, 1 ); /* XXXX COL_COLL_NAME added for queueSpecColl */ addInxIval( &genQueryInp.selectInp, COL_COLL_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_OWNER_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_OWNER_ZONE, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_CREATE_TIME, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_MODIFY_TIME, 1 ); /* XXXX may want to do this if spec coll is supported */ addInxIval( &genQueryInp.selectInp, COL_COLL_TYPE, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_INFO1, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_INFO2, 1 ); genQueryInp.maxRows = MAX_SQL_ROWS; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); if ( status >= 0 ) { *rodsObjStatOut = ( rodsObjStat_t * ) malloc( sizeof( rodsObjStat_t ) ); memset( *rodsObjStatOut, 0, sizeof( rodsObjStat_t ) ); ( *rodsObjStatOut )->objType = COLL_OBJ_T; status = ( int )COLL_OBJ_T; if ( ( dataId = getSqlResultByInx( genQueryOut, COL_COLL_ID ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat: getSqlResultByInx for COL_COLL_ID failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( ownerName = getSqlResultByInx( genQueryOut, COL_COLL_OWNER_NAME ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_OWNER_NAME failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( ownerZone = getSqlResultByInx( genQueryOut, COL_COLL_OWNER_ZONE ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_OWNER_ZONE failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( createTime = getSqlResultByInx( genQueryOut, COL_COLL_CREATE_TIME ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_CREATE_TIME failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( modifyTime = getSqlResultByInx( genQueryOut, COL_COLL_MODIFY_TIME ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_MODIFY_TIME failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( collType = getSqlResultByInx( genQueryOut, COL_COLL_TYPE ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_TYPE failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( collInfo1 = getSqlResultByInx( genQueryOut, COL_COLL_INFO1 ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_INFO1 failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( collInfo2 = getSqlResultByInx( genQueryOut, COL_COLL_INFO2 ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_INFO2 failed" ); return UNMATCHED_KEY_OR_INDEX; } else { rstrcpy( ( *rodsObjStatOut )->dataId, dataId->value, NAME_LEN ); rstrcpy( ( *rodsObjStatOut )->ownerName, ownerName->value, NAME_LEN ); rstrcpy( ( *rodsObjStatOut )->ownerZone, ownerZone->value, NAME_LEN ); rstrcpy( ( *rodsObjStatOut )->createTime, createTime->value, TIME_LEN ); rstrcpy( ( *rodsObjStatOut )->modifyTime, modifyTime->value, TIME_LEN ); if ( strlen( collType->value ) > 0 ) { specCollCache_t *specCollCache = 0; if ( ( specCollCache = matchSpecCollCache( dataObjInp->objPath ) ) != NULL ) { replSpecColl( &specCollCache->specColl, &( *rodsObjStatOut )->specColl ); } else { status = queueSpecCollCache( rsComm, genQueryOut, // JMC - backport 4680? dataObjInp->objPath ); if ( status < 0 ) { return status; } replSpecColl( &SpecCollCacheHead->specColl, &( *rodsObjStatOut )->specColl ); } } } } clearGenQueryInp( &genQueryInp ); freeGenQueryOut( &genQueryOut ); return status; }
/// =-=-=-=-=-=-=- /// @brief error gather_dirty_replicas_for_child( rsComm_t* _comm, const std::string& _parent_resc, const std::string& _child_resc, const int _limit, dist_child_result_t& _results ) { // =-=-=-=-=-=-=- // trap bad input if ( !_comm ) { return ERROR( SYS_INVALID_INPUT_PARAM, "null comm pointer" ); } else if ( _parent_resc.empty() ) { return ERROR( SYS_INVALID_INPUT_PARAM, "parent hier string is empty" ); } else if ( _child_resc.empty() ) { return ERROR( SYS_INVALID_INPUT_PARAM, "child hier string is empty" ); } else if ( _limit <= 0 ) { return ERROR( SYS_INVALID_INPUT_PARAM, "limit is less than or equal to zero" ); } // =-=-=-=-=-=-=- // build a general query genQueryOut_t* gen_out = 0; genQueryInp_t gen_inp; memset( &gen_inp, 0, sizeof( gen_inp ) ); gen_inp.maxRows = _limit; // =-=-=-=-=-=-=- // build the condition string, child is either a leaf // or an internal node so test for both std::string root_cond = _parent_resc + hierarchy_parser::delimiter() + _child_resc; std::string root2_cond = _parent_resc + hierarchy_parser::delimiter() + _child_resc + hierarchy_parser::delimiter(); std::string leaf_cond = hierarchy_parser::delimiter() + root_cond; std::string mid_cond = hierarchy_parser::delimiter() + root_cond + hierarchy_parser::delimiter(); std::string cond_str = "like '%" + mid_cond + "%' || like '%" + leaf_cond + "' || like '" + root_cond + "' || like '" + root2_cond + "%'"; // =-=-=-=-=-=-=- // add condition string matching above madness addInxVal( &gen_inp.sqlCondInp, COL_D_RESC_HIER, cond_str.c_str() ); // =-=-=-=-=-=-=- // add condition string stating dirty status only addInxVal( &gen_inp.sqlCondInp, COL_D_REPL_STATUS, "= '0'" ); // =-=-=-=-=-=-=- // request the resc hier addInxIval( &gen_inp.selectInp, COL_D_DATA_ID, 1 ); // =-=-=-=-=-=-=- // execute the query int status = rsGenQuery( _comm, &gen_inp, &gen_out ); clearGenQueryInp( &gen_inp ); if ( CAT_NO_ROWS_FOUND == status ) { // =-=-=-=-=-=-=- // hopefully there are no dirty data objects // and this is the typical code path return SUCCESS(); } else if ( status < 0 || 0 == gen_out ) { return ERROR( status, "genQuery failed." ); } // =-=-=-=-=-=-=- // extract result sqlResult_t* data_id_results = getSqlResultByInx( gen_out, COL_D_DATA_ID ); if ( !data_id_results ) { return ERROR( SYS_INTERNAL_NULL_INPUT_ERR, "null resc_hier result" ); } // =-=-=-=-=-=-=- // iterate over the rows and capture the data ids for ( int i = 0; i < gen_out->rowCnt; i++ ) { // =-=-=-=-=-=-=- // get its value char* data_id_ptr = &data_id_results->value[ data_id_results->len * i ]; if ( !data_id_ptr ) { std::stringstream msg; msg << "data_id_ptr null for result index " << i; return ERROR( SYS_INTERNAL_NULL_INPUT_ERR, msg.str() ); } int data_id = atoi( data_id_ptr ); // =-=-=-=-=-=-=- // capture the result _results.push_back( data_id ); } // for i return SUCCESS(); } // gather_dirty_replicas_for_child