Example #1
0
File: imeta.c Project: UPPMAX/irods
/*
Do a query on AVUs for users and show the results
 */
int queryUser(char *attribute, char *op, char *value) {
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[BIG_STR];
   char v2[BIG_STR];
   int status;
   char *columnNames[]={"user", "zone"};

   printCount=0;
   memset (&genQueryInp, 0, sizeof (genQueryInp_t));

   i1a[0]=COL_USER_NAME;
   i1b[0]=0;  /* (unused) */
   i1a[1]=COL_USER_ZONE;
   i1b[1]=0;  /* (unused) */
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 2;

   i2a[0]=COL_META_USER_ATTR_NAME;
   sprintf(v1,"='%s'",attribute);
   condVal[0]=v1;

   i2a[1]=COL_META_USER_ATTR_VALUE;
   sprintf(v2, "%s '%s'", op, value);
   condVal[1]=v2;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=2;

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);

   printGenQueryResults(Conn, status, genQueryOut, columnNames);

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Example #2
0
/* perform the list data-types command */
int
doListDataTypes(rcComm_t *Conn) {
   
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int select_inx[3];
   int select_value[3]={0,0,0};
   int condition_inx[3];
   char *condition_value[10];
   char value1[MAX_NAME_LEN+10]="='data_type'";
   int i, status;
   int printCount;

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));
   printCount=0;

   printf("Defined data-types:\n");

   i=0;
   select_inx[i++]=COL_TOKEN_NAME;
   
   genQueryInp.selectInp.inx = select_inx;
   genQueryInp.selectInp.value = select_value;
   genQueryInp.selectInp.len = i;

   genQueryInp.sqlCondInp.inx = condition_inx;
   genQueryInp.sqlCondInp.value = condition_value;
   condition_inx[0]=COL_TOKEN_NAMESPACE;
   condition_value[0]=value1;
   genQueryInp.sqlCondInp.len=1;

   genQueryInp.maxRows=50;
   genQueryInp.continueInx=0;
   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      printf("None exist.\n");
      return(0);
   }

   printCount+= printGenQueryResults(Conn, status, genQueryOut, 0, 
				     0);
   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      printCount+= printGenQueryResults(Conn, status, genQueryOut, 
					0, 0);
   }

   return (1);
}
Example #3
0
int
rsGenQuery (rsComm_t *rsComm, genQueryInp_t *genQueryInp, 
genQueryOut_t **genQueryOut)
{
    rodsServerHost_t *rodsServerHost;
    int status;
    char *zoneHint;

    zoneHint = getZoneHintForGenQuery (genQueryInp);
 
    status = getAndConnRcatHost(rsComm, SLAVE_RCAT, zoneHint,
				&rodsServerHost);
    if (status < 0) {
       return(status);
    }

    if (rodsServerHost->localFlag == LOCAL_HOST) {
#ifdef RODS_CAT
       status = _rsGenQuery (rsComm, genQueryInp, genQueryOut);
#else
       rodsLog(LOG_NOTICE, 
	       "rsGenQuery error. RCAT is not configured on this host");
       return (SYS_NO_RCAT_SERVER_ERR);
#endif 
    } else {
        status = rcGenQuery(rodsServerHost->conn,
			   genQueryInp, genQueryOut);
    }
    if (status < 0  && status != CAT_NO_ROWS_FOUND) {
        rodsLog (LOG_NOTICE,
		 "rsGenQuery: rcGenQuery failed, status = %d", status);
    }
    return (status);
}
Example #4
0
int checkCollExists( rcComm_t *conn, rodsArguments_t *myRodsArgs, const char *collPath ) {
    int status;
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    char condStr[MAX_NAME_LEN];

    memset( &genQueryInp, 0, sizeof( genQueryInp ) );
    addInxIval( &genQueryInp.selectInp, COL_COLL_ID, 1 );
    genQueryInp.maxRows = 0;
    genQueryInp.options = AUTO_CLOSE;
    
    snprintf( condStr, MAX_NAME_LEN, "='%s'", collPath );
    addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, condStr );

    status = rcGenQuery( conn, &genQueryInp, &genQueryOut );

    clearGenQueryInp( &genQueryInp );
    freeGenQueryOut( &genQueryOut );

    if ( status == CAT_NO_ROWS_FOUND ) {
        return 0;
    } else {
        return 1;
    }
}
Example #5
0
File: icd.cpp Project: bpow/irods
/* Check to see if a collection exists */
int
checkColl( rcComm_t *Conn, char *path ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut;
    int i1a[10];
    int i1b[10];
    int i2a[10];
    char *condVal[2];
    char v1[MAX_NAME_LEN];
    int status;

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

    i1a[0] = COL_COLL_ID;
    i1b[0] = 0; /* currently unused */
    genQueryInp.selectInp.inx = i1a;
    genQueryInp.selectInp.value = i1b;
    genQueryInp.selectInp.len = 1;

    i2a[0] = COL_COLL_NAME;
    genQueryInp.sqlCondInp.inx = i2a;
    sprintf( v1, "='%s'", path );
    condVal[0] = v1;
    genQueryInp.sqlCondInp.value = condVal;
    genQueryInp.sqlCondInp.len = 1;

    genQueryInp.maxRows = 10;
    genQueryInp.continueInx = 0;
    status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
    return status;
}
Example #6
0
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;
}
Example #7
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 );
}
Example #8
0
int
rsGenQuery( rsComm_t *rsComm, genQueryInp_t *genQueryInp,
            genQueryOut_t **genQueryOut ) {
    rodsServerHost_t *rodsServerHost;
    int status;
    char *zoneHint;
    zoneHint = getZoneHintForGenQuery( genQueryInp );

    std::string zone_hint_str;
    if ( zoneHint ) {
        zone_hint_str = zoneHint;
    }

    status = getAndConnRcatHost( rsComm, SLAVE_RCAT, zoneHint,
                                 &rodsServerHost );

    if ( status < 0 ) {
        return( status );
    }

    // =-=-=-=-=-=-=-
    // handle non-irods connections
    if ( !zone_hint_str.empty() ) {
        irods::error ret = proc_query_terms_for_non_irods_server( zone_hint_str, genQueryInp );
        if ( !ret.ok() ) {
            irods::log( PASS( ret ) );
        }
    }

    if ( rodsServerHost->localFlag == LOCAL_HOST ) {
#ifdef RODS_CAT
        status = _rsGenQuery( rsComm, genQueryInp, genQueryOut );
#else
        rodsLog( LOG_NOTICE,
                 "rsGenQuery error. RCAT is not configured on this host" );
        return ( SYS_NO_RCAT_SERVER_ERR );
#endif
    }
    else {
        status = rcGenQuery( rodsServerHost->conn,
                             genQueryInp, genQueryOut );
    }
    if ( status < 0  && status != CAT_NO_ROWS_FOUND ) {
        rodsLog( LOG_NOTICE,
                 "rsGenQuery: rcGenQuery failed, status = %d", status );
    }
    return ( status );
}
int
lsDataObjUtilLong (rcComm_t *conn, char *srcPath, rodsEnv *myRodsEnv, 
rodsArguments_t *rodsArgs, genQueryInp_t *genQueryInp)
{
    int status;
    genQueryOut_t *genQueryOut = NULL;
    char myColl[MAX_NAME_LEN], myData[MAX_NAME_LEN];
    char condStr[MAX_NAME_LEN];
    int queryFlags;

    queryFlags = setQueryFlag (rodsArgs);
    setQueryInpForData (queryFlags, genQueryInp);
    genQueryInp->maxRows = MAX_SQL_ROWS;

    memset (myColl, 0, MAX_NAME_LEN);
    memset (myData, 0, MAX_NAME_LEN);

    if ((status = splitPathByKey (
      srcPath, myColl, myData, '/')) < 0) {
        rodsLogError (LOG_ERROR, status,
          "setQueryInpForLong: splitPathByKey for %s error, status = %d",
          srcPath, status);
        return (status);
    }

    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);

    status =  rcGenQuery (conn, genQueryInp, &genQueryOut);

    if (status < 0) {
	if (status == CAT_NO_ROWS_FOUND) {
	    rodsLog (LOG_ERROR, "%s does not exist or user lacks access permission",
		     srcPath);
	} else {
            rodsLogError (LOG_ERROR, status,
	      "lsDataObjUtilLong: rcGenQuery error for %s", srcPath);
	}
	return (status);
    }
    printLsLong (conn, rodsArgs, genQueryOut);

    return (0);
}
Example #10
0
/*
  Show the resource groups, if any
*/
int
showRescGroups(int longOption)
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[20];
   int i1b[20]={0,0,0,0,0,0,0,0,0,0,0,0};
   int i2a[20];
   char *condVal[10];
   int i, status;

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

   i=0;
   i1a[i++]=COL_RESC_GROUP_NAME;
   
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = i;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;

   genQueryInp.sqlCondInp.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   genQueryInp.maxRows=50;
   genQueryInp.continueInx=0;
   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      return(0);
   }

   if (status != 0) return(0);

   for (i=0;i<genQueryOut->rowCnt;i++) {
      char *tResult;
      tResult = genQueryOut->sqlResult[0].value;
      tResult += i*genQueryOut->sqlResult[0].len;
      if (longOption==0) {
	 printf("%s (resource group)\n", tResult);
      }
      else {
	 printf("-----\n");
	 showOneRescGroup(tResult, longOption);
      }
   }

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status) {
	 return(0);
      }
      for (i=0;i<genQueryOut->rowCnt;i++) {
	 char *tResult;
	 tResult = genQueryOut->sqlResult[0].value;
	 tResult += i*genQueryOut->sqlResult[0].len;
	 if (longOption==0) {
	    printf("%s (resource group)\n", tResult);
	 }
	 else {
	    printf("-----\n");
	    showOneRescGroup(tResult, longOption);
	 }
      }
   }
   return (0);
}
Example #11
0
/*
Via a general query, show a resource
*/
int
showResc( char *name, int longOption ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut;
    int i1a[20];
    int i1b[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    int i2a[20];
    char *condVal[10];
    char v1[BIG_STR];
    int i, status;
    int printCount;
    char *columnNames[] = {"resource name", "id", "zone", "type", "class",
                           "location",  "vault", "free space", "free space time", "status",
                           "info", "comment", "create time", "modify time", "children",
                           "context", "parent", "object count"
                          };

    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    printCount = 0;

    i = 0;
    i1a[i++] = COL_R_RESC_NAME;
    if ( longOption ) {
        i1a[i++] = COL_R_RESC_ID;
        i1a[i++] = COL_R_ZONE_NAME;
        i1a[i++] = COL_R_TYPE_NAME;
        i1a[i++] = COL_R_CLASS_NAME;
        i1a[i++] = COL_R_LOC;
        i1a[i++] = COL_R_VAULT_PATH;
        i1a[i++] = COL_R_FREE_SPACE;
        i1a[i++] = COL_R_FREE_SPACE_TIME;
        i1a[i++] = COL_R_RESC_STATUS;
        i1a[i++] = COL_R_RESC_INFO;
        i1a[i++] = COL_R_RESC_COMMENT;
        i1a[i++] = COL_R_CREATE_TIME;
        i1a[i++] = COL_R_MODIFY_TIME;
        i1a[i++] = COL_R_RESC_CHILDREN;
        i1a[i++] = COL_R_RESC_CONTEXT;
        i1a[i++] = COL_R_RESC_PARENT;
        i1a[i++] = COL_R_RESC_OBJCOUNT;

    }
    else {
        columnNames[0] = "";
    }

    genQueryInp.selectInp.inx = i1a;
    genQueryInp.selectInp.value = i1b;
    genQueryInp.selectInp.len = i;

    genQueryInp.sqlCondInp.inx = i2a;
    genQueryInp.sqlCondInp.value = condVal;
    if ( name != NULL && *name != '\0' ) {
        // =-=-=-=-=-=-=-
        // JMC - backport 4629
        if ( strncmp( name, BUNDLE_RESC, sizeof( BUNDLE_RESC ) ) == 0 ) {
            printf( "%s is a pseudo resource for system use only.\n",
                    BUNDLE_RESC );
            return 0;
        }
        // =-=-=-=-=-=-=-
        i2a[0] = COL_R_RESC_NAME;
        snprintf( v1, BIG_STR, "='%s'", name );
        condVal[0] = v1;
        genQueryInp.sqlCondInp.len = 1;
    }
    else {
        // =-=-=-=-=-=-=-
        // JMC - backport 4629
        i2a[0] = COL_R_RESC_NAME;
        sprintf( v1, "!='%s'", BUNDLE_RESC ); /* all but bundleResc */
        condVal[0] = v1;
        genQueryInp.sqlCondInp.len = 1;
        // =-=-=-=-=-=-=-
    }

    if ( zoneArgument[0] != '\0' ) {
        addKeyVal( &genQueryInp.condInput, ZONE_KW, zoneArgument );
    }

    genQueryInp.maxRows = 50;
    genQueryInp.continueInx = 0;
    status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
    if ( status == CAT_NO_ROWS_FOUND ) {
        i1a[0] = COL_R_RESC_INFO;
        genQueryInp.selectInp.len = 1;
        status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
        if ( status == 0 ) {
            printf( "None\n" );
            return 0;
        }
        if ( status == CAT_NO_ROWS_FOUND ) {
            if ( name != NULL && name[0] != '\0' ) {
                printf( "Resource %s does not exist.\n", name );
            }
            else {
                printf( "Resource does not exist.\n" );
            }
            return 0;
        }
    }

    printCount += printGenQueryResults( Conn, status, genQueryOut, columnNames,
                                        longOption );
    while ( status == 0 && genQueryOut->continueInx > 0 ) {
        genQueryInp.continueInx = genQueryOut->continueInx;
        status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
        if ( genQueryOut->rowCnt > 0 && longOption ) {
            printf( "----\n" );
        }
        printCount += printGenQueryResults( Conn, status, genQueryOut,
                                            columnNames, longOption );
    }

    return 1;
}
Example #12
0
/*
 Show the resource group
 */
int
showOneRescGroup(char *rescGroupName, int longOption)
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[20];
   int i1b[20]={0,0,0,0,0,0,0,0,0,0,0,0};
   int i2a[20];
   char *condVal[10];
   char v1[BIG_STR];
   int i, status;
   char *tResult;

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));
   i=0;
   i1a[i++]=COL_R_RESC_NAME;
   
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = i;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;

   i2a[0]=COL_RESC_GROUP_NAME;
   snprintf(v1,sizeof(v1),"='%s'",rescGroupName);
   condVal[0]=v1;
   genQueryInp.sqlCondInp.len=1;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   genQueryInp.maxRows=50;
   genQueryInp.continueInx=0;
   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      return(0);
   }

   if (longOption) {
      printf("resource group: %s \n",rescGroupName);
   }
   else {
      printf("%s (resource group), resources: ",rescGroupName);
   }

   for (i=0;i<genQueryOut->rowCnt;i++) {
      tResult = genQueryOut->sqlResult[0].value;
      tResult += i*genQueryOut->sqlResult[0].len;
      if (longOption) {
	 printf("Includes resource: %s\n", tResult);
      }
      else {
	 printf("%s ", tResult);
      }
   }

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      for (i=0;i<genQueryOut->rowCnt;i++) {
	 tResult = genQueryOut->sqlResult[0].value;
	 tResult += i*genQueryOut->sqlResult[0].len;
	 printf("%s ", tResult);
      }
   }
   if (!longOption) {
      printf("\n");
   }

   return (1);
}
Example #13
0
/*
Via a general query, show a resource Access Control List
*/
int
showRescAcl(char *name) 
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[20];
   int i1b[20]={0,0,0,0,0,0,0,0,0,0,0,0};
   int i2a[20];
   char *condVal[10];
   char v1[BIG_STR];
   int i, status;
   int printCount;

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));
   printCount=0;


   i=0;
   i1a[i++]=COL_RESC_USER_NAME;
   i1a[i++]=COL_RESC_USER_ZONE;
   i1a[i++]=COL_RESC_ACCESS_NAME;
   
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = i;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   if (name !=NULL && *name != '\0') {
      i2a[0]=COL_R_RESC_NAME;
      snprintf(v1,sizeof(v1),"='%s'",name);
      condVal[0]=v1;
      genQueryInp.sqlCondInp.len=1;
   }
   else {
      genQueryInp.sqlCondInp.len=0;
   }

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   genQueryInp.maxRows=50;
   genQueryInp.continueInx=0;
   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      i1a[0]=COL_R_RESC_INFO;
      genQueryInp.selectInp.len = 1;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) {
	 printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {
	 if (name!=NULL && name[0]!='\0') {
	    printf("Resource %s does not exist.\n", name);
	 }
	 else {
	    printf("Resource does not exist.\n");
	 }
	 return(0);
      }
   }
   printf("Resource access permissions apply only to Database Resources\n");
   printf("(external databases).  See the Database Resources page on the\n");
   printf("irods web site for more information.\n");

   printf("   %s\n",name);

   printCount+= printGenQueryResultsRescACLs(Conn, status, genQueryOut);
   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      printCount+= printGenQueryResultsRescACLs(Conn, status, genQueryOut);
   }

   return (1);
}
Example #14
0
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;
}
Example #15
0
/*
  Show user quota information
*/
int
showUserUsage( char *userName, char *usersZone ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut;
    int inputInx[20];
    int inputVal[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    int inputCond[20];
    char *condVal[10];
    char v1[BIG_STR];
    int i, j, k, status;
    int printCount;
    char header[] =
        "Resource      User            Data-stored (bytes)";
    char *pad[14] = {"             ",
                     "            ",
                     "           ",
                     "          ",
                     "         ",
                     "        ",
                     "       ",
                     "      ",
                     "     ",
                     "    ",
                     "   ",
                     "  ",
                     " ",
                     ""
                    };

    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    printCount = 0;
    i = 0;
    inputInx[i++] = COL_QUOTA_USAGE_MODIFY_TIME;
    inputInx[i++] = COL_QUOTA_RESC_NAME;
    inputInx[i++] = COL_QUOTA_USER_NAME;
    inputInx[i++] = COL_QUOTA_USER_ZONE;
    inputInx[i++] = COL_QUOTA_USAGE;

    genQueryInp.selectInp.inx = inputInx;
    genQueryInp.selectInp.value = inputVal;
    genQueryInp.selectInp.len = i;

    genQueryInp.sqlCondInp.len = 0;
    if ( userName[0] != '\0' ) {
        inputCond[0] = COL_QUOTA_USER_NAME;
        sprintf( v1, "='%s'", userName );
        condVal[0] = v1;

        genQueryInp.sqlCondInp.inx = inputCond;
        genQueryInp.sqlCondInp.value = condVal;
        genQueryInp.sqlCondInp.len++;
    }

    genQueryInp.condInput.len = 0;

    genQueryInp.maxRows = MAX_SQL_ROWS;
    genQueryInp.continueInx = 0;
    status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
    if ( status == CAT_NO_ROWS_FOUND ) {
        printf( "No records found, run 'iadmin cu' to calculate usage\n" );
        return 0;
    }
    if ( status != 0 ) {
        printError( Conn, status, "rcGenQuery" );
        return status;
    }

    printf( "%s\n", header );
    printCount = 0;
    k = 0;
    for ( i = 0; i < genQueryOut->rowCnt; i++ ) {
        for ( j = 1; j < genQueryOut->attriCnt; j++ ) {
            char *tResult;
            char *tResult2;
            tResult = genQueryOut->sqlResult[j].value;
            tResult += i * genQueryOut->sqlResult[j].len;
            if ( j == 1 ) {
                printf( "%s ", tResult );
                k = strlen( tResult );
            }
            if ( j == 2 ) {
                j++;
                tResult2 = genQueryOut->sqlResult[j].value;
                tResult2 += i * genQueryOut->sqlResult[j].len;
                if ( strncmp( tResult2, usersZone, NAME_LEN ) == 0 ) {
                    printf( "%s", tResult );
                    k = strlen( tResult );
                }
                else {
                    printf( "%s#%s", tResult, tResult2 );
                    k = strlen( tResult ) + 1 + strlen( tResult2 );
                }
            }
            if ( j == 4 ) {
                printNice( tResult, 14, "" );
                k = strlen( tResult );
            }
            if ( k < 14 ) {
                printf( "%s", pad[k] );
            }
            printCount++;
        }
        printf( "\n" );
    }

    const sqlResult_t *quota_usage_modify_time_result = getSqlResultByInx( genQueryOut, COL_QUOTA_USAGE_MODIFY_TIME );
    if ( quota_usage_modify_time_result == NULL ) {
        printf( "Error getting quota usage modify times.\n" );
        return SYS_NULL_INPUT;
    }
    long long localiTime = 0;
    for ( i = 0; i < genQueryOut->rowCnt; i++ ) {
        const char *tResult = quota_usage_modify_time_result->value + i * quota_usage_modify_time_result->len;
        const long long itime = atoll( tResult );
        if ( itime > localiTime ) {
            localiTime = itime;
            getLocalTimeFromRodsTime( tResult, quotaTime );
        }
    }
    return 0;
}
Example #16
0
/*
  Via a general query, show user group membership
*/
int
showUserGroupMembership( char *userNameIn, char *usersZone ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut;
    int i1a[20];
    int i1b[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    int i2a[20];
    char *condVal[10];
    char v1[BIG_STR];
    char v2[BIG_STR];
    int i, j, status;
    int printCount;
    char userName[NAME_LEN];
    char zoneName[NAME_LEN];
    int showUserZone = 1;

    status = parseUserName( userNameIn, userName, zoneName );
    if ( status ) {
        return status;
    }
    if ( zoneName[0] == '\0' ) {
        snprintf( zoneName, sizeof( zoneName ), "%s", usersZone );
        showUserZone = 0;
    }

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

    i1a[0] = COL_USER_GROUP_NAME;
    genQueryInp.selectInp.inx = i1a;
    genQueryInp.selectInp.value = i1b;
    genQueryInp.selectInp.len = 1;

    i2a[0] = COL_USER_NAME;
    snprintf( v1, sizeof v1, "='%s'", userName );
    condVal[0] = v1;

    i2a[1] = COL_USER_ZONE;
    snprintf( v2, sizeof v2, "='%s'", zoneName );
    condVal[1] = v2;

    genQueryInp.sqlCondInp.inx = i2a;
    genQueryInp.sqlCondInp.value = condVal;
    genQueryInp.sqlCondInp.len = 2;

    genQueryInp.condInput.len = 0;

    genQueryInp.maxRows = MAX_SQL_ROWS;
    genQueryInp.continueInx = 0;
    status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
    if ( status == CAT_NO_ROWS_FOUND ) {
        printf( "Not a member of any group\n" );
        return 0;
    }
    if ( status != 0 ) {
        printError( Conn, status, "rcGenQuery" );
        return status;
    }

    printCount = 0;
    if ( showUserZone ) {
        printf( "User %s#%s is a member of groups: ", userName, zoneName );
    }
    else {
        printf( "User %s is a member of groups: ", userName );
    }
    for ( i = 0; i < genQueryOut->rowCnt; i++ ) {
        for ( j = 0; j < genQueryOut->attriCnt; j++ ) {
            char *tResult;
            tResult = genQueryOut->sqlResult[j].value;
            tResult += i * genQueryOut->sqlResult[j].len;
            if ( printCount > 0 ) {
                printf( ", %s", tResult );
            }
            else {
                printf( "%s", tResult );
            }
            printCount++;
        }
    }
    printf( "\n" );
    return 0;
}
Example #17
0
File: imeta.c Project: UPPMAX/irods
/*
Do a query on AVUs for collections and show the results
 */
int queryCollection(char *cmdToken[]) {
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[20];
   int i1b[20];
   int i2a[20];
   char *condVal[20];
   char v1[BIG_STR];
   char v2[BIG_STR];
   char v3[BIG_STR];
   int status;
   char *columnNames[]={"collection"};
   int cmdIx;
   int condIx;
   char vstr[20] [BIG_STR];

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

   printCount=0;
   i1a[0]=COL_COLL_NAME;
   i1b[0]=0;  /* (unused) */
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 1;

   i2a[0]=COL_META_COLL_ATTR_NAME;
   sprintf(v1,"='%s'", cmdToken[2]);
   condVal[0]=v1;

   i2a[1]=COL_META_COLL_ATTR_VALUE;
   sprintf(v2, "%s '%s'", cmdToken[3], cmdToken[4]);
   condVal[1]=v2;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=2;

   if (strcmp(cmdToken[5], "or")==0) {
      sprintf(v3, "|| %s '%s'", cmdToken[6], cmdToken[7]);
      rstrcat(v2, v3, BIG_STR);
   }

   cmdIx = 5;
   condIx = 2;
   while (strcmp(cmdToken[cmdIx], "and")==0) {
      i2a[condIx]=COL_META_COLL_ATTR_NAME;
      cmdIx++;
      sprintf(vstr[condIx],"='%s'", cmdToken[cmdIx]);
      condVal[condIx]=vstr[condIx];
      condIx++;

      i2a[condIx]=COL_META_COLL_ATTR_VALUE;
      sprintf(vstr[condIx], "%s '%s'", cmdToken[cmdIx+1], cmdToken[cmdIx+2]);
      cmdIx+=3;
      condVal[condIx]=vstr[condIx];
      condIx++;
      genQueryInp.sqlCondInp.len+=2;
   }

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);

   printGenQueryResults(Conn, status, genQueryOut, columnNames);

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Example #18
0
File: imeta.c Project: UPPMAX/irods
/*
Via a general query, show the AVUs for a resource group
*/
int
showRescGroup(char *name, char *attrName, int wild) 
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[BIG_STR];
   char v2[BIG_STR];
   int  status;
   char *columnNames[]={"attribute", "value", "units"};

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

   printf("AVUs defined for resource group %s:\n",name);
   printCount=0;
   i1a[0]=COL_META_RESC_GROUP_ATTR_NAME;
   i1b[0]=0; /* currently unused */
   i1a[1]=COL_META_RESC_GROUP_ATTR_VALUE;
   i1b[1]=0;
   i1a[2]=COL_META_RESC_GROUP_ATTR_UNITS;
   i1b[2]=0;
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 3;

   i2a[0]=COL_RESC_GROUP_NAME;
   sprintf(v1,"='%s'",name);
   condVal[0]=v1;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=1;

   if (attrName != NULL && *attrName!='\0') {
      i2a[1]=COL_META_RESC_GROUP_ATTR_NAME;
      if (wild) {
	 sprintf(v2,"like '%s'",attrName);
      }
      else {
	 sprintf(v2,"= '%s'",attrName);
      }
      condVal[1]=v2;
      genQueryInp.sqlCondInp.len++;
   }

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   /*
   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }
   */
   
   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      /* When no AVU found, test the existence of the resource group itself */
      i1a[0]=COL_RESC_GROUP_NAME;
      genQueryInp.selectInp.len = 1;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) {
	 printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {
	 printf("Resource group %s does not exist.\n", name);
	 return(0);
      }
   }

   printGenQueryResults(Conn, status, genQueryOut, columnNames);

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Example #19
0
File: imeta.c Project: UPPMAX/irods
/*
Via a general query, show the AVUs for a collection
*/
int
showColl(char *name, char *attrName, int wild) 
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[BIG_STR];
   char v2[BIG_STR];
   char fullName[MAX_NAME_LEN];
   int  status;
   char *columnNames[]={"attribute", "value", "units"};

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

   printf("AVUs defined for collection %s:\n",name);
   printCount=0;
   i1a[0]=COL_META_COLL_ATTR_NAME;
   i1b[0]=0; /* currently unused */
   i1a[1]=COL_META_COLL_ATTR_VALUE;
   i1b[1]=0;
   i1a[2]=COL_META_COLL_ATTR_UNITS;
   i1b[2]=0;
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 3;

   strncpy(fullName, cwd, MAX_NAME_LEN);
   if (strlen(name)>0) {
      if (*name=='/') {
	 strncpy(fullName, name, MAX_NAME_LEN);
      }
      else {
	 rstrcat(fullName, "/", MAX_NAME_LEN);
	 rstrcat(fullName, name, MAX_NAME_LEN);
      }
   }
   i2a[0]=COL_COLL_NAME;
   sprintf(v1,"='%s'",fullName);
   condVal[0]=v1;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=1;

   if (attrName != NULL && *attrName!='\0') {
      i2a[1]=COL_META_COLL_ATTR_NAME;
      if (wild) {
	 sprintf(v2,"like '%s'",attrName);
      }
      else {
	 sprintf(v2,"= '%s'",attrName);
      }
      condVal[1]=v2;
      genQueryInp.sqlCondInp.len++;
   }

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      i1a[0]=COL_COLL_COMMENTS;
      genQueryInp.selectInp.len = 1;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) {
	 printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {
	 printf("Collection %s does not exist.\n", fullName);
	 return(0);
      }
   }

   printGenQueryResults(Conn, status, genQueryOut, columnNames);

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Example #20
0
void
showRestrictionsByHost( char *inColumn ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut;
    int i1a[10];
    int i1b[10];
    int i2a[10];
    int i;
    char v1[MAX_NAME_LEN];
    char *condVal[10];
    int status;
    char *columnNames[] = {"restricted-to host"};


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

    printCount = 0;

    i = 0;
    i1a[i] = COL_TICKET_ALLOWED_HOST;
    i1b[i++] = 0;

    genQueryInp.selectInp.inx = i1a;
    genQueryInp.selectInp.value = i1b;
    genQueryInp.selectInp.len = i;

    i2a[0] = COL_TICKET_ALLOWED_HOST_TICKET_ID;
    snprintf( v1, sizeof( v1 ), "='%s'", inColumn );
    condVal[0] = v1;
    genQueryInp.sqlCondInp.inx = i2a;
    genQueryInp.sqlCondInp.value = condVal;
    genQueryInp.sqlCondInp.len = 1;

    genQueryInp.maxRows = 10;
    genQueryInp.continueInx = 0;
    genQueryInp.condInput.len = 0;

    status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
    if ( status == CAT_NO_ROWS_FOUND ) {
        i1a[0] = COL_USER_COMMENT;
        genQueryInp.selectInp.len = 1;
        status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
        if ( status == 0 ) {
            printf( "No host restrictions (1)\n" );
            return;
        }
        if ( status == CAT_NO_ROWS_FOUND ) {
            printf( "No host restrictions\n" );
            return;
        }
    }

    printResultsAndSubQuery( Conn, status, genQueryOut, columnNames, -1, 0 );

    while ( status == 0 && genQueryOut->continueInx > 0 ) {
        genQueryInp.continueInx = genQueryOut->continueInx;
        status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
        printResultsAndSubQuery( Conn, status, genQueryOut,
                                 columnNames, 0, 0 );
    }
    return;
}
Example #21
0
File: imeta.c Project: UPPMAX/irods
/*
Via a general query, show the AVUs for a user
*/
int
showUser(char *name, char *attrName, int wild)
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[BIG_STR];
   char v2[BIG_STR];
   char v3[BIG_STR];
   int status;
   char *columnNames[]={"attribute", "value", "units"};

   char userName[NAME_LEN];
   char userZone[NAME_LEN];

   status = parseUserName(name, userName, userZone);
   if (status) {
      printf("Invalid username format\n");
      return(0);
   }
   if (userZone[0]=='\0') {
      strncpy(userZone, myEnv.rodsZone, NAME_LEN);
   }

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

   printf("AVUs defined for user %s#%s:\n",userName, userZone);
   printCount=0;
   i1a[0]=COL_META_USER_ATTR_NAME;
   i1b[0]=0; /* currently unused */
   i1a[1]=COL_META_USER_ATTR_VALUE;
   i1b[1]=0;
   i1a[2]=COL_META_USER_ATTR_UNITS;
   i1b[2]=0;
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 3;

   i2a[0]=COL_USER_NAME;
   sprintf(v1,"='%s'",userName);
   condVal[0]=v1;

   i2a[1]=COL_USER_ZONE;
   sprintf(v2,"='%s'",userZone);
   condVal[1]=v2;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=2;

   if (attrName != NULL && *attrName!='\0') {
      i2a[2]=COL_META_USER_ATTR_NAME;
      if (wild) {
	 sprintf(v3,"like '%s'",attrName);
      }
      else {
	 sprintf(v3,"= '%s'",attrName);
      }
      condVal[2]=v3;
      genQueryInp.sqlCondInp.len++;
   }

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      i1a[0]=COL_USER_COMMENT;
      genQueryInp.selectInp.len = 1;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) {
	 printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {
	 printf("User %s does not exist.\n", name);
	 return(0);
      }
   }

   printGenQueryResults(Conn, status, genQueryOut, columnNames);

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Example #22
0
/**
 * @brief genQuery Query any information from iRODS database. See rodsGenQuery.c.
 * @param conn Connection variable
 * @param inputQuery
 * @param outputQuery
 * @return
 */
int genQuery(rcComm_t * conn, InputQuery *inputQuery, OutputQuery *outputQuery)
{
    genQueryInp_t queryInput;
    genQueryOut_t *queryOutput;
    int status = 0, prevStatus = 0;

    // zero rods api data structures
    memset(&queryInput, 0, sizeof(genQueryInp_t));
    queryOutput = NULL;

    // set rods api select array sizes
    queryInput.selectInp.len = inputQuery->selectSize;
    queryInput.maxRows = 100;

    // allocate new arrays for rods api
    queryInput.selectInp.inx = (int *) malloc(inputQuery->selectSize * sizeof(int));
    queryInput.selectInp.value = (int *) malloc(inputQuery->selectSize * sizeof(int));

    int i;
    // build rods api select arrays
    for (i=0; i <  inputQuery->selectSize; i++)
    {
        queryInput.selectInp.inx[i] = inputQuery->selectsColumns[i];
        queryInput.selectInp.value[i] = 0;
    }

    // set rods api condition array sizes
    queryInput.sqlCondInp.len = inputQuery->condSize;

    // allocate new arrays for rods api
    queryInput.sqlCondInp.inx = (int *) malloc(inputQuery->condSize * sizeof(int));
    queryInput.sqlCondInp.value = malloc( inputQuery->condSize * sizeof(char*));

    for (i = 0; i < inputQuery->condSize; i++)
        queryInput.sqlCondInp.value[i] = malloc((2900) * sizeof(char));

    for (i=0; i < inputQuery->condSize ; i++)
    {
        queryInput.sqlCondInp.inx[i] = inputQuery->condColumns[i];
        queryInput.sqlCondInp.value[i] = inputQuery->condValues[i];
    }

    // try to execute a generic query
    if (!(status = rcGenQuery(conn, &queryInput, &queryOutput)))
    {
        int *resultColumns = (int *) malloc(inputQuery->selectSize * sizeof(int));
        char **resultValues = (char **) malloc(3000*inputQuery->selectSize* sizeof(char));

        // iterate while there are results to process
        do {
            int j;
            for (i = 0; i < queryOutput->rowCnt; i++)
            {
                for (j = 0; j < queryOutput->attriCnt; j++)
                {
                    resultColumns[j] = inputQuery->selectsColumns[j];
                    resultValues[j] = queryOutput->sqlResult[j].value;
                }
            }

            outputQuery->resultCollumns=resultColumns;
            outputQuery->resultValues=resultValues;
            outputQuery->size=inputQuery->selectSize;

            // if there are no more results to query, exit loop
            if (!queryOutput->continueInx)
                break;

            // otherwise continue fetching query results
            queryInput.continueInx = queryOutput->continueInx;
            prevStatus = status;

            status = rcGenQuery(conn, &queryInput, &queryOutput);
        } while (!status);

    }

    //free rods api allocated resources
    free(queryInput.selectInp.inx);
    free(queryInput.selectInp.value);
    free(queryInput.sqlCondInp.inx);
    free(queryInput.sqlCondInp.value);
    free(queryOutput);

    // let's not return no more rows found as an error
    if (status == CAT_NO_ROWS_FOUND)
        status = prevStatus;

    return (status);
}
Example #23
0
int showRescTree( char *name ) {
    int status;
    int offset = 0; // when getting more rows

    // genQuery input and output (camelCase for tradition)
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut;
    char collQCond[MAX_NAME_LEN];


    // start clean
    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );

    // set up query columns
    addInxIval( &genQueryInp.selectInp, COL_R_RESC_NAME, ORDER_BY );
    addInxIval( &genQueryInp.selectInp, COL_R_TYPE_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_R_RESC_CHILDREN, 1 );
    addInxIval( &genQueryInp.selectInp, COL_R_RESC_PARENT, 1 );

    if ( zoneArgument[0] != '\0' ) {
        addKeyVal( &genQueryInp.condInput, ZONE_KW, zoneArgument );
    }

    // set up query condition (resc_name != 'bundleResc')
    snprintf( collQCond, MAX_NAME_LEN, "!='%s'", BUNDLE_RESC );
    addInxVal( &genQueryInp.sqlCondInp, COL_R_RESC_NAME, collQCond );

    // query for resources
    genQueryInp.maxRows = MAX_SQL_ROWS;
    status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );

    // query fail?
    if ( status < 0 ) {
        printError( Conn, status, "rcGenQuery" );
        return status;
    }


    // parse results
    status = parseGenQueryOut( offset, genQueryOut );



    // More rows in the pipeline?
    while ( !status && genQueryOut->continueInx > 0 ) {
        genQueryInp.continueInx = genQueryOut->continueInx;

        // update offset
        offset += genQueryOut->rowCnt;

        // get next batch of rows
        status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );

        // parse results
        status = parseGenQueryOut( offset, genQueryOut );
    }



    // If target resource was specified print tree for that resource
    if ( name && strlen( name ) ) {
        std::string target_resc_name( name );

        // check for invalid resource name
        if ( std::find( resc_names.begin(), resc_names.end(), target_resc_name ) == resc_names.end() ) {
            std::cout << "Resource " << target_resc_name << " does not exist." << std::endl;
            return USER_INVALID_RESC_INPUT;
        }

        // print tree
        printRescTree( target_resc_name, "" );
    }
    else {
        // Otherwise print tree for each root node
        for ( std::vector<std::string>::const_iterator it = roots.begin(); it != roots.end(); ++it ) {
            printRescTree( *it, "" );
        }
    }

    return status;
}
Example #24
0
/* perform the ls command */
int
doLs(rcComm_t *Conn, char *objPath, int longOption) {
   
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[30];
   int i1b[30]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
   int i2a[30];
   char *condVal[10];
   char v1[MAX_NAME_LEN+10];
   char v2[MAX_NAME_LEN+10];
   int i, status;
   int printCount;

   char *columnNames[]={
   "data_name",
   "data_id", "coll_id", "data_repl_num", "data_version",
   "data_type_name", "data_size", "resc_group_name", "resc_name",
   "data_path ", "data_owner_name", "data_owner_zone", 
   "data_repl_status", "data_status",
   "data_checksum ", "data_expiry_ts (expire time)",
   "data_map_id", "r_comment", "create_ts","modify_ts"};

   char logicalEndName[MAX_NAME_LEN];
   char logicalParentDirName[MAX_NAME_LEN];

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));
   printCount=0;

   printf("doing ls of %s\n", objPath);

   status = splitPathByKey(objPath,
			   logicalParentDirName, logicalEndName, '/');

   i=0;
   i1a[i++]=COL_DATA_NAME;
   if (longOption) {   
      i1a[i++]=COL_D_DATA_ID;
      i1a[i++]=COL_D_COLL_ID;
      i1a[i++]=COL_DATA_REPL_NUM;
      i1a[i++]=COL_DATA_VERSION;
      i1a[i++]=COL_DATA_TYPE_NAME;
      i1a[i++]=COL_DATA_SIZE;
      i1a[i++]=COL_D_RESC_GROUP_NAME;
      i1a[i++]=COL_D_RESC_NAME;
      i1a[i++]=COL_D_DATA_PATH;
      i1a[i++]=COL_D_OWNER_NAME;
      i1a[i++]=COL_D_OWNER_ZONE;
      i1a[i++]=COL_D_REPL_STATUS;
      i1a[i++]=COL_D_DATA_STATUS;
      i1a[i++]=COL_D_DATA_CHECKSUM;
      i1a[i++]=COL_D_EXPIRY;
      i1a[i++]=COL_D_MAP_ID;
      i1a[i++]=COL_D_COMMENTS;
      i1a[i++]=COL_D_CREATE_TIME;
      i1a[i++]=COL_D_MODIFY_TIME;
   }
   else {
      columnNames[1]="data_expiry_ts (expire time)";
      i1a[i++]=COL_D_EXPIRY;
   }
   
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = i;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   i2a[0]=COL_COLL_NAME;
   snprintf(v1,sizeof(v1),"='%s'",logicalParentDirName);
   condVal[0]=v1;
   i2a[1]=COL_DATA_NAME;
   snprintf(v2,sizeof(v1),"='%s'",logicalEndName);
   condVal[1]=v2;
   genQueryInp.sqlCondInp.len=2;

   genQueryInp.maxRows=50;
   genQueryInp.continueInx=0;
   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      i1a[0]=COL_R_RESC_INFO;
      genQueryInp.selectInp.len = 1;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) {
	 printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {
	 printf("DataObject %s does not exist.\n", objPath);
	 return(0);
      }
   }

   printCount+= printGenQueryResults(Conn, status, genQueryOut, columnNames, 
				     longOption);
   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt > 0 && longOption) {
	 printf("----\n");
      }
      printCount+= printGenQueryResults(Conn, status, genQueryOut, 
					columnNames, longOption);
   }

   return (1);
}
Example #25
0
/*
Via a general query, show the Tickets for this user
*/
int
showTickets1( char *inOption, char *inName ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut;
    int i1a[20];
    int i1b[20];
    int i2a[20];
    int i;
    char v1[MAX_NAME_LEN];
    char *condVal[20];
    int status;
    char *columnNames[] = {"id", "string", "ticket type", "obj type", "owner name", "owner zone", "uses count", "uses limit", "write file count", "write file limit", "write byte count", "write byte limit", "expire time", "collection name", "data collection"};


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

    printCount = 0;

    i = 0;
    i1a[i] = COL_TICKET_ID;
    i1b[i++] = 0;
    i1a[i] = COL_TICKET_STRING;
    i1b[i++] = 0;
    i1a[i] = COL_TICKET_TYPE;
    i1b[i++] = 0;
    i1a[i] = COL_TICKET_OBJECT_TYPE;
    i1b[i++] = 0;
    i1a[i] = COL_TICKET_OWNER_NAME;
    i1b[i++] = 0;
    i1a[i] = COL_TICKET_OWNER_ZONE;
    i1b[i++] = 0;
    i1a[i] = COL_TICKET_USES_COUNT;
    i1b[i++] = 0;
    i1a[i] = COL_TICKET_USES_LIMIT;
    i1b[i++] = 0;
    i1a[i] = COL_TICKET_WRITE_FILE_COUNT;
    i1b[i++] = 0;
    i1a[i] = COL_TICKET_WRITE_FILE_LIMIT;
    i1b[i++] = 0;
    i1a[i] = COL_TICKET_WRITE_BYTE_COUNT;
    i1b[i++] = 0;
    i1a[i] = COL_TICKET_WRITE_BYTE_LIMIT;
    i1b[i++] = 0;
    i1a[i] = COL_TICKET_EXPIRY_TS;
    i1b[i++] = 0;
    i1a[i] = COL_TICKET_COLL_NAME;
    i1b[i++] = 0;
    if ( strstr( inOption, "data" ) != 0 ) {
        i--;
        i1a[i] = COL_TICKET_DATA_NAME;
        columnNames[i] = "data-object name";
        i1b[i++] = 0;
        i1a[i] = COL_TICKET_DATA_COLL_NAME;
        i1b[i++] = 0;
    }
    if ( strstr( inOption, "basic" ) != 0 ) {
        /* skip the COLL or DATA_NAME so it's just a query on the ticket tables */
        i--;
    }

    genQueryInp.selectInp.inx = i1a;
    genQueryInp.selectInp.value = i1b;
    genQueryInp.selectInp.len = i;

    genQueryInp.condInput.len = 0;

    if ( inName != NULL && *inName != '\0' ) {
        if ( isInteger( inName ) == 1 ) {
            /* Could have an all-integer ticket but in most cases this is a good
            guess */
            i2a[0] = COL_TICKET_ID;
        }
        else {
            i2a[0] = COL_TICKET_STRING;
        }
        snprintf( v1, sizeof( v1 ), "='%s'", inName );
        condVal[0] = v1;
        genQueryInp.sqlCondInp.inx = i2a;
        genQueryInp.sqlCondInp.value = condVal;
        genQueryInp.sqlCondInp.len = 1;
    }

    genQueryInp.maxRows = 10;
    genQueryInp.continueInx = 0;

    if ( zoneArgument[0] != '\0' ) {
        addKeyVal( &genQueryInp.condInput, ZONE_KW, zoneArgument );
    }

    status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
    if ( status == CAT_NO_ROWS_FOUND ) {
        i1a[0] = COL_USER_COMMENT;
        genQueryInp.selectInp.len = 1;
        status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
        if ( status == 0 ) {
            return 0;
        }
        if ( status == CAT_NO_ROWS_FOUND ) {
            return 0;
        }
    }

    printResultsAndSubQuery( Conn, status, genQueryOut, columnNames, 0, 1 );

    while ( status == 0 && genQueryOut->continueInx > 0 ) {
        genQueryInp.continueInx = genQueryOut->continueInx;
        status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
        if ( genQueryOut->rowCnt > 0 ) {
            printf( "----\n" );
        }
        printResultsAndSubQuery( Conn, status, genQueryOut,
                                 columnNames, 0, 1 );
    }

    return 0;
}
Example #26
0
File: imeta.c Project: UPPMAX/irods
/*
 Via a general query and show the AVUs for a dataobject.
 */
int
showDataObj(char *name, char *attrName, int wild) 
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[BIG_STR];
   char v2[BIG_STR];
   char v3[BIG_STR];
   char fullName[MAX_NAME_LEN];
   char myDirName[MAX_NAME_LEN];
   char myFileName[MAX_NAME_LEN];
   int status;
   /* "id" only used in testMode, in longMode id is reset to be 'time set' :*/
   char *columnNames[]={"attribute", "value", "units", "id"};

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

   printf("AVUs defined for dataObj %s:\n",name);
   printCount=0;
   i1a[0]=COL_META_DATA_ATTR_NAME;
   i1b[0]=0;
   i1a[1]=COL_META_DATA_ATTR_VALUE;
   i1b[1]=0;
   i1a[2]=COL_META_DATA_ATTR_UNITS;
   i1b[2]=0;
   if (testMode) {
      i1a[3]=COL_META_DATA_ATTR_ID;
      i1b[3]=0;
   }
   if (longMode) {
      i1a[3]=COL_META_DATA_MODIFY_TIME;
      i1b[3]=0;
      columnNames[3]="time set";
   }
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 3;
   if (testMode) {
      genQueryInp.selectInp.len = 4;
   }
   if (longMode) {
      genQueryInp.selectInp.len = 4;
   }

   i2a[0]=COL_COLL_NAME;
   sprintf(v1,"='%s'",cwd);
   condVal[0]=v1;

   i2a[1]=COL_DATA_NAME;
   sprintf(v2,"='%s'",name);
   condVal[1]=v2;

   strncpy(fullName, cwd, MAX_NAME_LEN);
   rstrcat(fullName, "/", MAX_NAME_LEN);
   rstrcat(fullName, name, MAX_NAME_LEN);
   if (strstr(name, "/") != NULL) {
      /* reset v1 and v2 for when full path or relative path entered */
      if (*name=='/') {
	 strncpy(fullName, name, MAX_NAME_LEN);
      }
      status = splitPathByKey(fullName, 
			      myDirName, myFileName, '/');
      sprintf(v1,"='%s'",myDirName);
      sprintf(v2,"='%s'",myFileName);
   }

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=2;

   if (attrName != NULL && *attrName!='\0') {
      i2a[2]=COL_META_DATA_ATTR_NAME;
      if (wild) {
	 sprintf(v3,"like '%s'",attrName);
      }
      else {
	 sprintf(v3,"= '%s'",attrName);
      }
      condVal[2]=v3;
      genQueryInp.sqlCondInp.len++;
   }

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      i1a[0]=COL_D_DATA_PATH;
      genQueryInp.selectInp.len = 1;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) {
	 printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {
	 printf("Dataobject %s does not exist.\n", fullName);
	 return(0);
      }
      printGenQueryResults(Conn, status, genQueryOut, columnNames);
   }
   else {
      printGenQueryResults(Conn, status, genQueryOut, columnNames);
   }

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Example #27
0
int
rsGenQuery( rsComm_t *rsComm, genQueryInp_t *genQueryInp,
            genQueryOut_t **genQueryOut ) {
    rodsServerHost_t *rodsServerHost;
    int status;
    char *zoneHint;
    zoneHint = getZoneHintForGenQuery( genQueryInp );

    std::string zone_hint_str;
    if ( zoneHint ) {
        zone_hint_str = zoneHint;
    }

    status = getAndConnRcatHost( rsComm, SLAVE_RCAT, zoneHint,
                                 &rodsServerHost );

    if ( status < 0 ) {
        return status;
    }

    // =-=-=-=-=-=-=-
    // handle non-irods connections
    if ( !zone_hint_str.empty() ) {
        irods::error ret = proc_query_terms_for_non_irods_server( zone_hint_str, genQueryInp );
        if ( !ret.ok() ) {
            irods::log( PASS( ret ) );
        }
    }

    if ( rodsServerHost->localFlag == LOCAL_HOST ) {
#ifdef RODS_CAT
        status = _rsGenQuery( rsComm, genQueryInp, genQueryOut );
#else
        rodsLog( LOG_NOTICE,
                 "rsGenQuery error. RCAT is not configured on this host" );
        return SYS_NO_RCAT_SERVER_ERR;
#endif
    }
    else {
        // =-=-=-=-=-=-=-
        // strip disable strict acl flag if the agent conn flag is missing
        char* dis_kw = getValByKey( &genQueryInp->condInput, DISABLE_STRICT_ACL_KW );
        if ( dis_kw ) {
            irods::server_properties& props = irods::server_properties::getInstance();
            props.capture_if_needed();

            std::string svr_sid;
            irods::error err = props.get_property< std::string >( irods::AGENT_CONN_KW, svr_sid );
            if ( !err.ok() ) {
                rmKeyVal( &genQueryInp->condInput, DISABLE_STRICT_ACL_KW );

            }

        } // if dis_kw

        status = rcGenQuery( rodsServerHost->conn,
                             genQueryInp, genQueryOut );
    }
    if ( status < 0  && status != CAT_NO_ROWS_FOUND ) {
        rodsLog( LOG_NOTICE,
                 "rsGenQuery: rcGenQuery failed, status = %d", status );
    }
    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);
}
Example #29
0
/*
 Via a general query, show group information
 */
void
showGroup(char *groupName)
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int selectIndexes[10];
   int selectValues[10];
   int conditionIndexes[10];
   char *conditionValues[10];
   char conditionString1[200];
   char conditionString2[200];
   int status;

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

   if (groupName != NULL && *groupName!='\0') {
      printf("Members of group %s:\n",groupName);
   }
   selectIndexes[0]=COL_USER_NAME;
   selectValues[0]=0;
   selectIndexes[1]=COL_USER_ZONE;
   selectValues[1]=0;
   genQueryInp.selectInp.inx = selectIndexes;
   genQueryInp.selectInp.value = selectValues;
   if (groupName != NULL && *groupName!='\0') {
      genQueryInp.selectInp.len = 2;
   }
   else {
      genQueryInp.selectInp.len = 1;
   }

   conditionIndexes[0]=COL_USER_TYPE;
   snprintf(conditionString1,sizeof(conditionString1), "='rodsgroup'");
   conditionValues[0]=conditionString1;

   genQueryInp.sqlCondInp.inx = conditionIndexes;
   genQueryInp.sqlCondInp.value = conditionValues;
   genQueryInp.sqlCondInp.len=1;

   if (groupName != NULL && *groupName!='\0') {

      snprintf(conditionString1,sizeof(conditionString1),"!='rodsgroup'");

      conditionIndexes[1]=COL_USER_GROUP_NAME;
      snprintf(conditionString2,sizeof(conditionString2),"='%s'",groupName);
      conditionValues[1]=conditionString2;
      genQueryInp.sqlCondInp.len=2;
   }

   genQueryInp.maxRows=50;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      printf("No rows found\n");
      return;
   }
   else {
      printGenQueryResultsForGroup(genQueryOut);
   }

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) printGenQueryResultsForGroup(genQueryOut);
   }
   return;
}
Example #30
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;

}