Ejemplo n.º 1
0
/**
 * \fn msiCloseGenQuery(msParam_t *genQueryInp_msp, msParam_t *genQueryOut_msp, ruleExecInfo_t *rei)
 *
 * \brief This microservice closes an unfinished query. This is based on the code from #msiGetMoreRows.
 *
 * \module core
 *
 * \since 3.1
 *
 *
 * \usage None
 *
 * \param[in] genQueryInp_msp - Required - a GenQueryInp_MS_T containing the query parameters and conditions.
 * \param[in] genQueryOut_msp - Required - a GenQueryOut_MS_T to write results to. If its continuation index is 0 the query will be closed.
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
**/
int
msiCloseGenQuery( msParam_t *genQueryInp_msp, msParam_t *genQueryOut_msp, ruleExecInfo_t *rei ) {

    genQueryInp_t *genQueryInp;
    genQueryOut_t *genQueryOut;

    RE_TEST_MACRO( "    Calling msiCloseGenQuery" )

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

    /* check for non null parameters */
    if ( genQueryInp_msp == NULL || genQueryOut_msp == NULL ) {
        rodsLog( LOG_ERROR, "msiCloseGenQuery: Missing parameter(s)" );
        return USER__NULL_INPUT_ERR;
    }

    /* no double close */
    if ( genQueryOut_msp->type == NULL ) {
        return 0;
    }

    /* check for proper input types */
    if ( strcmp( genQueryOut_msp->type, GenQueryOut_MS_T ) ) {
        rodsLog( LOG_ERROR, "msiCloseGenQuery: genQueryOut_msp type is %s, should be GenQueryOut_MS_T", genQueryOut_msp->type );
        return USER_PARAM_TYPE_ERR;
    }

    if ( strcmp( genQueryInp_msp->type, GenQueryInp_MS_T ) ) {
        rodsLog( LOG_ERROR, "msiCloseGenQuery: query_msp type is %s, should be GenQueryInp_MS_T", genQueryInp_msp->type );
        return USER_PARAM_TYPE_ERR;
    }

    /* retrieve genQueryXXX data structures */
    genQueryOut = ( genQueryOut_t* )genQueryOut_msp->inOutStruct;
    genQueryInp = ( genQueryInp_t* )genQueryInp_msp->inOutStruct;

    /* set contiuation index so icat know which statement to free */
    genQueryInp->continueInx = genQueryOut->continueInx;
    genQueryInp->maxRows = -1;

    /* free memory allocated for previous results */
    freeGenQueryOut( &genQueryOut );

    if ( genQueryInp->continueInx == 0 ) {
        /* query already closed */
        rei->status = 0;
        return rei->status;
    }

    /* close query */
    rei->status = rsGenQuery( rei->rsComm, genQueryInp, &genQueryOut );

    /* free memory allocated */
    freeGenQueryOut( &genQueryOut );

    if ( rei->status == 0 ) {
        /* clear output parameter */
        genQueryOut_msp->type = NULL;
        genQueryOut_msp->inOutStruct = NULL;
    }

    return rei->status;
}
Ejemplo n.º 2
0
int _rsStructFileBundle( rsComm_t*                 rsComm,
                         structFileExtAndRegInp_t* structFileBundleInp ) {
    int status;
    int handleInx;
    char phyBunDir[MAX_NAME_LEN];
    char tmpPath[MAX_NAME_LEN];
    int l1descInx;
    char* dataType = 0; // JMC - backport 4664
    openedDataObjInp_t dataObjCloseInp;

    // =-=-=-=-=-=-=-
    // create an empty data obj
    dataObjInp_t dataObjInp;
    memset( &dataObjInp, 0, sizeof( dataObjInp ) );
    dataObjInp.openFlags = O_WRONLY;

    // =-=-=-=-=-=-=-
    // get the data type of the structured file
    dataType = getValByKey( &structFileBundleInp->condInput, DATA_TYPE_KW );

    // =-=-=-=-=-=-=-
    // ensure that the file name will end in .zip, if necessary
    if ( dataType != NULL && strstr( dataType, ZIP_DT_STR ) != NULL ) {
        int len = strlen( structFileBundleInp->objPath );
        if ( strcmp( &structFileBundleInp->objPath[len - 4], ".zip" ) != 0 ) {
            strcat( structFileBundleInp->objPath, ".zip" );
        }
    }

    // =-=-=-=-=-=-=-
    // capture the object path in the data obj struct
    rstrcpy( dataObjInp.objPath, structFileBundleInp->objPath, MAX_NAME_LEN );

    // =-=-=-=-=-=-=-
    // replicate the condInput. may have resource input
    replKeyVal( &structFileBundleInp->condInput, &dataObjInp.condInput );

    // =-=-=-=-=-=-=-
    // open the file if we are in an add operation, otherwise create the new file
    if ( ( structFileBundleInp->oprType & ADD_TO_TAR_OPR ) != 0 ) { // JMC - backport 4643
        l1descInx = rsDataObjOpen( rsComm, &dataObjInp );

    }
    else {
        l1descInx = rsDataObjCreate( rsComm, &dataObjInp );

    }

    // =-=-=-=-=-=-=-
    // error check create / open
    if ( l1descInx < 0 ) {
        rodsLog( LOG_ERROR, "rsStructFileBundle: rsDataObjCreate of %s error. status = %d",
                 dataObjInp.objPath, l1descInx );
        return l1descInx;
    }

    // =-=-=-=-=-=-=-
    // FIXME :: Why, when we replicate them above?
    clearKeyVal( &dataObjInp.condInput ); // JMC - backport 4637
    // ???? l3Close (rsComm, l1descInx);

    // =-=-=-=-=-=-=-
    // zip does not like a zero length file as target
    //L1desc[ l1descInx ].l3descInx = 0;
    //if( dataType != NULL && strstr( dataType, ZIP_DT_STR ) != NULL ) {
    //    if( ( structFileBundleInp->oprType & ADD_TO_TAR_OPR) == 0 ) { // JMC - backport 4643
    //        l3Unlink( rsComm, L1desc[l1descInx].dataObjInfo );
    //    }
    //}

    // =-=-=-=-=-=-=-
    // check object permissions / stat
    chkObjPermAndStat_t chkObjPermAndStatInp;
    memset( &chkObjPermAndStatInp, 0, sizeof( chkObjPermAndStatInp ) );
    rstrcpy( chkObjPermAndStatInp.objPath, structFileBundleInp->collection, MAX_NAME_LEN );
    chkObjPermAndStatInp.flags = CHK_COLL_FOR_BUNDLE_OPR;
    addKeyVal( &chkObjPermAndStatInp.condInput, RESC_NAME_KW,     L1desc[l1descInx].dataObjInfo->rescName );

    // =-=-=-=-=-=-=-
    // get the resc hier string
    std::string resc_hier;
    char* resc_hier_ptr = getValByKey( &structFileBundleInp->condInput, RESC_HIER_STR_KW );
    if ( !resc_hier_ptr ) {
        rodsLog( LOG_NOTICE, "_rsStructFileBundle :: RESC_HIER_STR_KW is NULL" );
    }
    else {
        addKeyVal( &chkObjPermAndStatInp.condInput, RESC_HIER_STR_KW, resc_hier_ptr );
        resc_hier = resc_hier_ptr;
    }

    status = rsChkObjPermAndStat( rsComm, &chkObjPermAndStatInp );
    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "rsStructFileBundle: rsChkObjPermAndStat of %s error. stat = %d",
                 chkObjPermAndStatInp.objPath, status );
        dataObjCloseInp.l1descInx = l1descInx;
        rsDataObjClose( rsComm, &dataObjCloseInp );
        return status;
    }

    clearKeyVal( &chkObjPermAndStatInp.condInput );

    // =-=-=-=-=-=-=-
    // create the special hidden directory where the bundling happens
    createPhyBundleDir( rsComm, L1desc[ l1descInx ].dataObjInfo->filePath, phyBunDir, L1desc[ l1descInx ].dataObjInfo->rescHier );

    // =-=-=-=-=-=-=-
    // build a collection open input structure
    collInp_t collInp;
    bzero( &collInp, sizeof( collInp ) );
    collInp.flags = RECUR_QUERY_FG | VERY_LONG_METADATA_FG | NO_TRIM_REPL_FG | INCLUDE_CONDINPUT_IN_QUERY;
    rstrcpy( collInp.collName, structFileBundleInp->collection, MAX_NAME_LEN );
    addKeyVal( &collInp.condInput, RESC_NAME_KW, L1desc[ l1descInx ].dataObjInfo->rescName );

    rodsLog( LOG_DEBUG, "rsStructFileBundle: calling rsOpenCollection for [%s]", structFileBundleInp->collection );

    // =-=-=-=-=-=-=-
    // open the collection from which we will bundle
    handleInx = rsOpenCollection( rsComm, &collInp );
    if ( handleInx < 0 ) {
        rodsLog( LOG_ERROR, "rsStructFileBundle: rsOpenCollection of %s error. status = %d",
                 collInp.collName, handleInx );
        rmdir( phyBunDir );
        return handleInx;
    }

    // =-=-=-=-=-=-=-
    // preserve the collection path?
    int collLen = 0;
    if ( ( structFileBundleInp->oprType & PRESERVE_COLL_PATH ) != 0 ) {
        // =-=-=-=-=-=-=-
        // preserve the last entry of the coll path
        char* tmpPtr = collInp.collName;
        int   tmpLen = 0;
        collLen = 0;

        // =-=-=-=-=-=-=-
        // find length to the last '/'
        while ( *tmpPtr != '\0' ) {
            if ( *tmpPtr == '/' ) {
                collLen = tmpLen;
            }

            tmpLen++;
            tmpPtr++;
        }

    }
    else {
        collLen = strlen( collInp.collName );

    }

    // =-=-=-=-=-=-=-
    // preserve the collection path?
    collEnt_t* collEnt = NULL;
    while ( ( status = rsReadCollection( rsComm, &handleInx, &collEnt ) ) >= 0 ) {
        if ( NULL == collEnt ) { // JMC cppcheck - nullptr
            rodsLog( LOG_ERROR, "rsStructFileBundle: collEnt is NULL" );
            continue;
        }

        // =-=-=-=-=-=-=-
        // entry is a data object
        if ( collEnt->objType == DATA_OBJ_T ) {
            if ( collEnt->collName[collLen] == '\0' ) {
                snprintf(
                    tmpPath,
                    MAX_NAME_LEN,
                    "%s/%s",
                    phyBunDir,
                    collEnt->dataName );
            }
            else {
                snprintf(
                    tmpPath,
                    MAX_NAME_LEN, "%s/%s/%s",
                    phyBunDir,
                    collEnt->collName + collLen + 1,
                    collEnt->dataName );
                mkDirForFilePath(
                    rsComm,
                    strlen( phyBunDir ),
                    tmpPath,
                    collEnt->resc_hier,
                    getDefDirMode() );
            }

            // =-=-=-=-=-=-=-
            // filter out any possible replicas that are not on this resource
            if ( resc_hier == collEnt->resc_hier ) {
                // =-=-=-=-=-=-=-
                // add a link
                status = link( collEnt->phyPath, tmpPath );
                if ( status < 0 ) {
                    rodsLog( LOG_ERROR, "rsStructFileBundle: link error %s to %s. errno = %d",
                             collEnt->phyPath, tmpPath, errno );
                    rmLinkedFilesInUnixDir( phyBunDir );
                    rmdir( phyBunDir );
                    return UNIX_FILE_LINK_ERR - errno;
                }
                else {
                    //rodsLog( LOG_NOTICE, "_rsStructFileBundle - LINK  [%s] on resc [%s]", collEnt->phyPath, collEnt->resc_hier );
                }
            }
            else {
                //rodsLog( LOG_NOTICE, "_rsStructFileBundle - skipping [%s] on resc [%s]", collEnt->phyPath, collEnt->resc_hier );
            }
        }
        else {
            // =-=-=-=-=-=-=-
            // entry is a collection
            if ( ( int ) strlen( collEnt->collName ) + 1 <= collLen ) {
                free( collEnt );
                continue;
            }
            snprintf( tmpPath, MAX_NAME_LEN, "%s/%s", phyBunDir, collEnt->collName + collLen );
            mkFileDirR( rsComm, strlen( phyBunDir ), tmpPath, resc_hier.c_str(), getDefDirMode() );
        } // else

        if ( collEnt != NULL ) {
            free( collEnt );
            collEnt = NULL;
        }

    } // while

    // =-=-=-=-=-=-=-
    // clean up key vals and close the collection
    clearKeyVal( &collInp.condInput );
    rsCloseCollection( rsComm, &handleInx );

    // =-=-=-=-=-=-=-
    // call the helper function to do the actual bundling
    status = phyBundle( rsComm, L1desc[l1descInx].dataObjInfo, phyBunDir,
                        collInp.collName, structFileBundleInp->oprType ); // JMC - backport 4643

    int savedStatus = 0;
    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "rsStructFileBundle: phyBundle of %s error. stat = %d",
                 L1desc[ l1descInx ].dataObjInfo->objPath, status );
        L1desc[ l1descInx ].bytesWritten = 0;
        savedStatus = status;
    }
    else {
        // mark it was written so the size would be adjusted
        L1desc[ l1descInx ].bytesWritten = 1;
    }

    // =-=-=-=-=-=-=-
    // clean up after the bundle directory
    rmLinkedFilesInUnixDir( phyBunDir );
    rmdir( phyBunDir );

    dataObjCloseInp.l1descInx = l1descInx;
    status = rsDataObjClose( rsComm, &dataObjCloseInp );
    if ( status >= 0 ) {
        return savedStatus;
    }

    return status;
}
Ejemplo n.º 3
0
int _ifuseFileCacheWrite( fileCache_t *fileCache, char *buf, size_t size, off_t offset ) {
    int status, myError;
    openedDataObjInp_t dataObjWriteInp;
    bytesBuf_t dataObjWriteInpBBuf;
    iFuseConn_t *conn;

    bzero( &dataObjWriteInp, sizeof( dataObjWriteInp ) );
    /* lseek to the right offset in case this cache is share by multiple descs */
    status = _iFuseFileCacheLseek( fileCache, offset );
    if ( status < 0 ) {
        if ( ( myError = getErrno( status ) ) > 0 ) {
            return -myError;
        }
        else {
            return -ENOENT;
        }
    }


    if ( fileCache->state == NO_FILE_CACHE ) {
        /* no file cache */
        dataObjWriteInpBBuf.buf = ( void * ) buf;
        dataObjWriteInpBBuf.len = size;
        dataObjWriteInp.l1descInx = fileCache->iFd;
        dataObjWriteInp.len = size;

        conn = getAndUseConnByPath( fileCache->localPath, &status );
        status = rcDataObjWrite( conn->conn, &dataObjWriteInp, &dataObjWriteInpBBuf );
        unuseIFuseConn( conn );
        if ( status < 0 ) {
            if ( ( myError = getErrno( status ) ) > 0 ) {
                return -myError;
            }
            else {
                return -ENOENT;
            }
        }
        else if ( status != ( int ) size ) {
            rodsLog( LOG_ERROR,
                     "ifuseWrite: IFuseDesc[descInx].conn for %s is NULL", fileCache->localPath );
            return -ENOENT;
        }
        fileCache->offset += status;
        if ( fileCache->offset > fileCache->fileSize ) {
            fileCache->fileSize = fileCache->offset;
        }
    }
    else {
        status = write( fileCache->iFd, buf, size );
        if ( status < 0 ) {
            return errno ? ( -1 * errno ) : -1;
        }
        fileCache->offset += status;
        if ( fileCache->offset > fileCache->fileSize ) {
            fileCache->fileSize = fileCache->offset;
        }
        if ( fileCache->offset >= MAX_NEWLY_CREATED_CACHE_SIZE ) {
            _iFuseFileCacheFlush( fileCache );
            fileCache->iFd = 0;
            /* reopen file */
            dataObjInp_t dataObjOpenInp;
            memset( &dataObjOpenInp, 0, sizeof( dataObjOpenInp ) );
            rstrcpy( dataObjOpenInp.objPath, fileCache->objPath, MAX_NAME_LEN );
            dataObjOpenInp.openFlags = O_RDWR;

            int status;
            conn = getAndUseConnByPath( fileCache->localPath, &status );
            status = rcDataObjOpen( conn->conn, &dataObjOpenInp );
            unuseIFuseConn( conn );

            if ( status < 0 ) {
                rodsLog( LOG_ERROR, "iFuseWrite: rcDataObjOpen of %s error. status = %d", fileCache->objPath, status );
                return -ENOENT;
            }

            fileCache->iFd = status;
        }
    }
    return status;
}
Ejemplo n.º 4
0
Archivo: xmlMS.c Proyecto: UPPMAX/irods
int 
msiLoadMetadataFromXml(msParam_t *targetObj, msParam_t *xmlObj, ruleExecInfo_t *rei) 
{
	/* for parsing msParams and to open iRODS objects */
	dataObjInp_t xmlDataObjInp, *myXmlDataObjInp;
	dataObjInp_t targetObjInp, *myTargetObjInp;
	int xmlObjID;

	/* for getting size of objects to read from */
	rodsObjStat_t *rodsObjStatOut = NULL;

	/* for reading from iRODS objects */
	openedDataObjInp_t openedDataObjInp;
	bytesBuf_t *xmlBuf;

	/* misc. to avoid repeating rei->rsComm */
	rsComm_t *rsComm;

	/* for xml parsing */
	xmlDocPtr doc;

	/* for XPath evaluation */
	xmlXPathContextPtr xpathCtx;
	xmlXPathObjectPtr xpathObj;
	xmlChar xpathExpr[] = "//AVU";
	xmlNodeSetPtr nodes;
	int avuNbr, i;
	
	/* for new AVU creation */
	modAVUMetadataInp_t modAVUMetadataInp;
	int max_attr_len = 2700;
	char attrStr[max_attr_len];



	/*********************************  USUAL INIT PROCEDURE **********************************/
	
	/* For testing mode when used with irule --test */
	RE_TEST_MACRO ("    Calling msiLoadMetadataFromXml")


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

	rsComm = rei->rsComm;


	
	/********************************** RETRIEVE INPUT PARAMS **************************************/

	/* Get path of target object */
	rei->status = parseMspForDataObjInp (targetObj, &targetObjInp, &myTargetObjInp, 0);
	if (rei->status < 0)
	{
		rodsLog (LOG_ERROR, "msiLoadMetadataFromXml: input targetObj error. status = %d", rei->status);
		return (rei->status);
	}


	/* Get path of XML document */
	rei->status = parseMspForDataObjInp (xmlObj, &xmlDataObjInp, &myXmlDataObjInp, 0);
	if (rei->status < 0)
	{
		rodsLog (LOG_ERROR, "msiLoadMetadataFromXml: input xmlObj error. status = %d", rei->status);
		return (rei->status);
	}



	/******************************** OPEN AND READ FROM XML OBJECT ********************************/

	/* Open XML file */
	if ((xmlObjID = rsDataObjOpen(rsComm, &xmlDataObjInp)) < 0) 
	{
		rodsLog (LOG_ERROR, "msiLoadMetadataFromXml: Cannot open XML data object. status = %d", xmlObjID);
		return (xmlObjID);
	}


	/* Get size of XML file */
	rei->status = rsObjStat (rsComm, &xmlDataObjInp, &rodsObjStatOut);
	if (rei->status < 0 || !rodsObjStatOut)
	{
		rodsLog (LOG_ERROR, "msiLoadMetadataFromXml: Cannot stat XML data object. status = %d", rei->status);
		return (rei->status);
	}


	/* xmlBuf init */
	/* memory for xmlBuf->buf is allocated in rsFileRead() */
	xmlBuf = (bytesBuf_t *) malloc (sizeof (bytesBuf_t));
	memset (xmlBuf, 0, sizeof (bytesBuf_t));


	/* Read XML file */
	memset (&openedDataObjInp, 0, sizeof (openedDataObjInp_t));
	openedDataObjInp.l1descInx = xmlObjID;
	openedDataObjInp.len = (int)rodsObjStatOut->objSize;

	rei->status = rsDataObjRead (rsComm, &openedDataObjInp, xmlBuf);
	
	/* Make sure that the result is null terminated */
	if (strlen((char*)xmlBuf->buf) > (size_t)openedDataObjInp.len)
	{
		((char*)xmlBuf->buf)[openedDataObjInp.len-1]='\0';
	}


	/* Close XML file */
	rei->status = rsDataObjClose (rsComm, &openedDataObjInp);

	/* cleanup */
	freeRodsObjStat (rodsObjStatOut);



	/******************************** PARSE XML DOCUMENT ********************************/

	xmlSubstituteEntitiesDefault(1);
	xmlLoadExtDtdDefaultValue = 1;


	/* Parse xmlBuf.buf into an xmlDocPtr */
	doc = xmlParseDoc((xmlChar*)xmlBuf->buf);


	/* Create xpath evaluation context */
	xpathCtx = xmlXPathNewContext(doc);
	if(xpathCtx == NULL) 
	{
		rodsLog (LOG_ERROR, "msiLoadMetadataFromXml: Unable to create new XPath context.");
		xmlFreeDoc(doc); 
		return(-1);
	}


	/* Evaluate xpath expression */
	xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
	if(xpathObj == NULL) 
	{
		rodsLog (LOG_ERROR, "msiLoadMetadataFromXml: Unable to evaluate XPath expression \"%s\".", xpathExpr);
		xmlXPathFreeContext(xpathCtx); 
		xmlFreeDoc(doc); 
		return(-1);
	}

	/* How many AVU nodes did we get? */
	if ((nodes = xpathObj->nodesetval) != NULL)
	{
		avuNbr = nodes->nodeNr;
	}
	else 
	{
		avuNbr = 0;
	}



	/******************************** CREATE AVU TRIPLETS ********************************/

	/* Add a new AVU for each node. It's ok to process the nodes in forward order since we're not modifying them */
	for(i = 0; i < avuNbr; i++) 
	{
		if (nodes->nodeTab[i])
		{
//			/* temporary: Add index number to avoid duplicating attribute names */
//			memset(attrStr, '\0', MAX_NAME_LEN);
//			snprintf(attrStr, MAX_NAME_LEN - 1, "%04d: %s", i+1, (char*)xmlNodeGetContent(getChildNodeByName(nodes->nodeTab[i], "Attribute")) );

			/* Truncate if needed. No prefix. */
			memset(attrStr, '\0', max_attr_len);
			snprintf(attrStr, max_attr_len - 1, "%s", (char*)xmlNodeGetContent(getChildNodeByName(nodes->nodeTab[i], "Attribute")) );

			/* init modAVU input */
			memset (&modAVUMetadataInp, 0, sizeof(modAVUMetadataInp_t));
			modAVUMetadataInp.arg0 = "add";
			modAVUMetadataInp.arg1 = "-d";

			/* Use target object if one was provided, otherwise look for it in the XML doc */
			if (myTargetObjInp->objPath != NULL && strlen(myTargetObjInp->objPath) > 0)
			{
				modAVUMetadataInp.arg2 = myTargetObjInp->objPath;
			}
			else
			{
				modAVUMetadataInp.arg2 = xmlURIUnescapeString((char*)xmlNodeGetContent(getChildNodeByName(nodes->nodeTab[i], "Target")),
						MAX_NAME_LEN, NULL);
			}

			modAVUMetadataInp.arg3 = attrStr;
			modAVUMetadataInp.arg4 = (char*)xmlNodeGetContent(getChildNodeByName(nodes->nodeTab[i], "Value"));
			modAVUMetadataInp.arg5 = (char*)xmlNodeGetContent(getChildNodeByName(nodes->nodeTab[i], "Unit"));
			
			/* invoke rsModAVUMetadata() */
			rei->status = rsModAVUMetadata (rsComm, &modAVUMetadataInp);
		}
	}



	/************************************** WE'RE DONE **************************************/

	/* cleanup of all xml parsing stuff */
	xmlFreeDoc(doc);
        xmlCleanupParser();

	return (rei->status);
}
// =-=-=-=-=-=-=-
// private - execute rule for pre operation
    error operation_rule_execution_manager::exec_op(
        rsComm_t*          _comm,
        keyValPair_t&      _kvp,
        const std::string& _name,
        std::string&       _res ) {
        // =-=-=-=-=-=-=-
        // determine if rule exists
        RuleIndexListNode* re_node = 0;
        if ( findNextRule2( const_cast<char*>( _name.c_str() ), 0, &re_node ) < 0 ) {
            return ERROR( SYS_RULE_NOT_FOUND, "no rule found" );
        }

        // =-=-=-=-=-=-=-
        // debug message for creating dynPEP rules
        rodsLog(
            LOG_DEBUG,
            "operation_rule_execution_manager exec_op [%s]",
            _name.c_str() );

        // =-=-=-=-=-=-=-
        // add additional global re params
        error err = add_global_re_params_to_kvp_for_dynpep( _kvp );
        if ( !err.ok() ) {
            return PASS( err );
        }

        // =-=-=-=-=-=-=-
        // manufacture an rei for the applyRule
        ruleExecInfo_t rei;
        memset( ( char* )&rei, 0, sizeof( ruleExecInfo_t ) );
        rei.rsComm        = _comm;
        rei.condInputData = &_kvp; // give rule scope to our key value pairs
        rstrcpy( rei.pluginInstanceName, instance_.c_str(), MAX_NAME_LEN );

        // =-=-=-=-=-=-=-
        // add the output parameter
        msParamArray_t params;
        memset( &params, 0, sizeof( msParamArray_t ) );
        char out_param[ MAX_NAME_LEN ] = {"EMPTY_PARAM"};
        if ( _res.empty() ) {
            addMsParamToArray( &params, "*OUT", STR_MS_T, out_param, NULL, 0 );
        }
        else {
            addMsParamToArray( &params, "*OUT", STR_MS_T, const_cast<char*>( _res.c_str() ), NULL, 0 );
        }

        // =-=-=-=-=-=-=-
        // rule exists, param array is build.  call the rule.
        std::string arg_name = _name + "(*OUT)";
        int ret = applyRuleUpdateParams(
                      const_cast<char*>( arg_name.c_str() ),
                      &params,
                      &rei,
                      NO_SAVE_REI );
        if ( 0 != ret ) {
            return ERROR( ret, "failed in call to applyRuleUpdateParams" );
        }

        // =-=-=-=-=-=-=-
        // extract the value from the outgoing param to pass out to the operation
        msParam_t* out_ms_param = getMsParamByLabel( &params, "*OUT" );
        if ( out_ms_param ) {
            _res = reinterpret_cast< char* >( out_ms_param->inOutStruct );

        }
        else {
            return ERROR( SYS_INVALID_INPUT_PARAM, "null out parameter" );

        }

        return SUCCESS();

    } // exec_op
Ejemplo n.º 6
0
int initializeReDebug( rsComm_t *svrComm ) {
    char condRead[NAME_LEN];
    int i, s, m, status;
    char *readhdr = NULL;
    char *readmsg = NULL;
    char *user = NULL;
    char *addr = NULL;

    if ( svrComm == NULL ) {
        return 0;
    }
    if ( GlobalREDebugFlag != 4 ) {
        return 0;
    }

    s = 0;
    m = 0;
    myPID = ( int ) getpid();
    myHostName[0] = '\0';
    gethostname( myHostName, MAX_NAME_LEN );
    sprintf( condRead, "(*XUSER  == \"%s@%s\") && (*XHDR == \"STARTDEBUG\")",
             svrComm->clientUser.userName, svrComm->clientUser.rodsZone );
    status = _readXMsg( GlobalREDebugFlag, condRead, &m, &s, &readhdr, &readmsg, &user, &addr );
    if ( status >= 0 ) {
        if ( ( readmsg != NULL )  && strlen( readmsg ) > 0 ) {
            GlobalREDebugFlag = atoi( readmsg );
        }
        if ( readhdr != NULL ) {
            free( readhdr );
        }
        if ( readmsg != NULL ) {
            free( readmsg );
        }
        if ( user != NULL ) {
            free( user );
        }
        if ( addr != NULL ) {
            free( addr );
        }
        /* initialize reDebug stack space*/
        for ( i = 0; i < REDEBUG_STACK_SIZE_FULL; i++ ) {
            reDebugStackFull[i] = NULL;
        }
        for ( i = 0; i < REDEBUG_STACK_SIZE_CURR; i++ ) {
            reDebugStackCurr[i].label = -1;
            reDebugStackCurr[i].step = NULL;
        }
        memset( breakPoints, 0, sizeof( struct Breakpoint ) * 100 );

        reDebugStackFullPtr = 0;
        reDebugStackCurrPtr = 0;
        snprintf( waitHdr, HEADER_TYPE_LEN - 1,   "idbug:" );

        rodsLog( LOG_NOTICE, "reDebugInitialization: Got Debug StreamId:%i\n", GlobalREDebugFlag );
        snprintf( waitMsg, MAX_NAME_LEN, "PROCESS BEGIN at %s:%i. Client connected from %s at port %i\n",
                  myHostName, myPID, svrComm->clientAddr, ntohs( svrComm->localAddr.sin_port ) );
        _writeXMsg( GlobalREDebugFlag, "idbug", waitMsg );
        snprintf( waitMsg, MAX_NAME_LEN, "%s:%i is waiting\n", myHostName, myPID );
    }
    return 0;
}
Ejemplo n.º 7
0
Archivo: xmlMS.c Proyecto: UPPMAX/irods
/**
 * \fn msiLoadMetadataFromXml (msParam_t *targetObj, msParam_t *xmlObj, ruleExecInfo_t *rei)
**/
int 
msiLoadMetadataFromXml(msParam_t *targetObj, msParam_t *xmlObj, ruleExecInfo_t *rei) 
{
	rodsLog (LOG_ERROR, "msiLoadMetadataFromXml: XPath support not compiled in.");
	return (SYS_NOT_SUPPORTED);
}
Ejemplo n.º 8
0
int
_rsModDataObjMeta (rsComm_t *rsComm, modDataObjMeta_t *modDataObjMetaInp)
{
#ifdef RODS_CAT
    int status;
    dataObjInfo_t *dataObjInfo;
    keyValPair_t *regParam;
    int i;
    ruleExecInfo_t rei2;

    memset ((char*)&rei2, 0, sizeof (ruleExecInfo_t));
    rei2.rsComm = rsComm;
    if (rsComm != NULL) {
      rei2.uoic = &rsComm->clientUser;
      rei2.uoip = &rsComm->proxyUser;
    }
    rei2.doi = modDataObjMetaInp->dataObjInfo;
    rei2.condInputData = modDataObjMetaInp->regParam;
    regParam = modDataObjMetaInp->regParam;
    dataObjInfo = modDataObjMetaInp->dataObjInfo;

    if (regParam->len == 0) {
        rodsLog(LOG_NOTICE, "Warning, _rsModDataObjMeta called with empty regParam, returning success");
        return (0);
    }

    /* In dataObjInfo, need just dataId. But it will accept objPath too,
     * but less efficient 
     */

    /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/
    rei2.doi = dataObjInfo;
    i =  applyRule("acPreProcForModifyDataObjMeta",NULL, &rei2, NO_SAVE_REI);
    if (i < 0) {
      if (rei2.status < 0) {
        i = rei2.status;
      }
      rodsLog (LOG_ERROR,
               "_rsModDataObjMeta:acPreProcForModifyDataObjMeta error stat=%d", i);
      return i;
    }
    /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/

    if (getValByKey (regParam, ALL_KW) != NULL) {
	/* all copies */
	dataObjInfo_t *dataObjInfoHead = NULL;
	dataObjInfo_t *tmpDataObjInfo;
	dataObjInp_t dataObjInp;

	bzero (&dataObjInp, sizeof (dataObjInp));
	rstrcpy (dataObjInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN);
        status = getDataObjInfoIncSpecColl (rsComm, &dataObjInp,
          &dataObjInfoHead);
	if (status < 0) return status;
	tmpDataObjInfo = dataObjInfoHead;
        while (tmpDataObjInfo != NULL) {
	    if (tmpDataObjInfo->specColl != NULL) break;
            status = chlModDataObjMeta (rsComm, tmpDataObjInfo, regParam);
	    if (status < 0) {
                rodsLog (LOG_ERROR,
                  "_rsModDataObjMeta:chlModDataObjMeta %s error stat=%d",
	          tmpDataObjInfo->objPath, status);
	    }
	    tmpDataObjInfo = tmpDataObjInfo->next;
	}
	freeAllDataObjInfo (dataObjInfoHead);
    } else {
        status = chlModDataObjMeta (rsComm, dataObjInfo, regParam);
    }

    /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/
    if (status >= 0) {
      i =  applyRule("acPostProcForModifyDataObjMeta",NULL, &rei2, NO_SAVE_REI);
      if (i < 0) {
        if (rei2.status < 0) {
          i = rei2.status;
        }
        rodsLog (LOG_ERROR,
           "_rsModDataObjMeta:acPostProcForModifyDataObjMeta error stat=%d",i);
        return i;
      }
    }
    /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/

    return (status);
#else
    return (SYS_NO_RCAT_SERVER_ERR);
#endif

}
Ejemplo n.º 9
0
int
chksumUtil (rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs,
rodsPathInp_t *rodsPathInp)
{
    int i;
    int status; 
    int savedStatus = 0;
    collInp_t collInp;
    dataObjInp_t dataObjInp;


    if (rodsPathInp == NULL) {
	return (USER__NULL_INPUT_ERR);
    }

    status = initCondForChksum (myRodsEnv, myRodsArgs, &dataObjInp, &collInp);

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

    for (i = 0; i < rodsPathInp->numSrc; i++) {
	if (rodsPathInp->srcPath[i].objType == UNKNOWN_OBJ_T) {
	    getRodsObjType (conn, &rodsPathInp->srcPath[i]);
	    if (rodsPathInp->srcPath[i].objState == NOT_EXIST_ST) {
                rodsLog (LOG_ERROR,
                  "chksumUtil: srcPath %s does not exist",
                  rodsPathInp->srcPath[i].outPath);
		savedStatus = USER_INPUT_PATH_ERR;
		continue;
	    }
	}

	if (rodsPathInp->srcPath[i].objType == DATA_OBJ_T) {
	    rmKeyVal (&dataObjInp.condInput, TRANSLATED_PATH_KW);
	    status = chksumDataObjUtil (conn, rodsPathInp->srcPath[i].outPath, 
	     myRodsEnv, myRodsArgs, &dataObjInp);
	} else if (rodsPathInp->srcPath[i].objType ==  COLL_OBJ_T) {
            /* The path given by collEnt.collName from rclReadCollection
             * has already been translated */
            addKeyVal (&dataObjInp.condInput, TRANSLATED_PATH_KW, "");
	    status = chksumCollUtil (conn, rodsPathInp->srcPath[i].outPath,
              myRodsEnv, myRodsArgs, &dataObjInp, &collInp);
	} else {
	    /* should not be here */
	    rodsLog (LOG_ERROR,
	     "chksumUtil: invalid chksum objType %d for %s", 
	     rodsPathInp->srcPath[i].objType, rodsPathInp->srcPath[i].outPath);
	    return (USER_INPUT_PATH_ERR);
	}
	/* XXXX may need to return a global status */
	if (status < 0) {
	    rodsLogError (LOG_ERROR, status,
             "chksumUtil: chksum error for %s, status = %d", 
	      rodsPathInp->srcPath[i].outPath, status);
	    savedStatus = status;
	} 
    }
    printf ("Total checksum performed = %d, Failed checksum = %d\n",
      ChksumCnt, FailedChksumCnt);

    if (savedStatus < 0) {
        return (savedStatus);
    } else if (status == CAT_NO_ROWS_FOUND) {
        return (0);
    } else {
        return (status);
    }
}
Ejemplo n.º 10
0
/**
 * \fn msiAddConditionToGenQuery(msParam_t *attribute, msParam_t *opr, msParam_t *value, msParam_t *queryInput, ruleExecInfo_t *rei)
 *
 * \brief Adds a condition to a genQueryInp_t
 *
 * \module core
 *
 *
 * \note This microservice adds a condition to an existing genQueryInp_t, from three parameters.
 *       One is an iCAT attribute index given without its 'COL_' prefix.
 *       The second one is the SQL operator. The third one is the value and may contain wildcards.
 *       To be used with #msiAddSelectFieldToGenQuery and #msiExecGenQuery to build queries from the
 *       results of other microservices or actions within an iRODS rule.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] attribute - Required - A STR_MS_T with the iCAT attribute name (see wiki.irods.org/index.php/icatAttributes).
 * \param[in] opr - Required - A STR_MS_T with the operator.
 * \param[in] value - Required - A STR_MS_T with the value.
 * \param[in,out] queryInput - Required - A GenQueryInp_MS_T.
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
**/
int
msiAddConditionToGenQuery( msParam_t *attribute, msParam_t *opr, msParam_t *value, msParam_t *queryInput, ruleExecInfo_t *rei ) {
    genQueryInp_t *genQueryInp;
    char condStr[MAX_NAME_LEN];
    char *att_str, *op_str, *val_str;
    int att_inx;

    /*************************************  INIT **********************************/

    /* For testing mode when used with irule --test */
    RE_TEST_MACRO( "    Calling msiAddConditionToGenQuery" )

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


    /********************************** PARAM PARSING  *********************************/

    /* Parse attribute */
    if ( ( att_str = parseMspForStr( attribute ) ) == NULL ) {
        rodsLog( LOG_ERROR, "msiAddConditionToGenQuery: input attribute is NULL." );
        return USER__NULL_INPUT_ERR;
    }

    /* Parse operator */
    if ( ( op_str = parseMspForStr( opr ) ) == NULL ) {
        rodsLog( LOG_ERROR, "msiAddConditionToGenQuery: input opr is NULL." );
        return USER__NULL_INPUT_ERR;
    }

    /* Parse value */
    if ( ( val_str = parseMspForStr( value ) ) == NULL ) {
        rodsLog( LOG_ERROR, "msiAddConditionToGenQuery: input value is NULL." );
        return USER__NULL_INPUT_ERR;
    }

    /* Check for proper parameter type for queryInput */
    if ( queryInput->type && strcmp( queryInput->type, GenQueryInp_MS_T ) ) {
        rodsLog( LOG_ERROR, "msiAddConditionToGenQuery: queryInput is not of type GenQueryInp_MS_T." );
        return USER_PARAM_TYPE_ERR;
    }

    /* Parse queryInput. Must not be empty. */
    if ( !queryInput->inOutStruct ) {
        rodsLog( LOG_ERROR, "msiAddConditionToGenQuery: input queryInput is NULL." );
        return USER__NULL_INPUT_ERR;
    }
    else {
        genQueryInp = ( genQueryInp_t* )queryInput->inOutStruct;
    }


    /***************************** ADD CONDITION TO QUERY INPUT  *****************************/

    /* Get attribute index */
    att_inx = getAttrIdFromAttrName( att_str );

    /* Error? */
    if ( att_inx < 0 ) {
        rodsLog( LOG_ERROR, "msiAddConditionToGenQuery: Unable to get valid ICAT column index." );
        return att_inx;
    }

    /* Make the condition */
    snprintf( condStr, MAX_NAME_LEN, " %s '%s'", op_str, val_str );

    /* Add condition to genQueryInput */
    addInxVal( &genQueryInp->sqlCondInp, att_inx, condStr );  /* condStr gets strdup'ed */


    /*********************************** DONE *********************************************/
    return 0;
}
Ejemplo n.º 11
0
/**
 * \fn msiPrintGenQueryOutToBuffer(msParam_t *queryOut, msParam_t *format, msParam_t *buffer, ruleExecInfo_t *rei)
 *
 * \brief  Writes the contents of a GenQueryOut_MS_T into a BUF_LEN_MS_T.
 *
 * \module core
 *
 *
 * \note This microservice writes the contents of a GenQueryOut_MS_T into a BUF_LEN_MS_T.
 *       The results can be formatted with an optional C-style format string the same way it is done in iquest.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] queryOut - Required - A GenQueryOut_MS_T.
 * \param[in] format - Optional - A STR_MS_T with a C-style format string, like in iquest.
 * \param[out] buffer - A BUF_LEN_MS_T
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
**/
int
msiPrintGenQueryOutToBuffer( msParam_t *queryOut, msParam_t *format, msParam_t *buffer, ruleExecInfo_t *rei ) {
    genQueryOut_t *genQueryOut;
    char *format_str;
    bytesBuf_t *bytesBuf;
    FILE *stream;
    char readbuffer[MAX_NAME_LEN];

    /*************************************  INIT **********************************/

    /* For testing mode when used with irule --test */
    RE_TEST_MACRO( "    Calling msiPrintGenQueryOutToBuffer" )

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


    /********************************** PARAM PARSING  *********************************/

    /* Check for proper param type */
    if ( !queryOut || !queryOut->inOutStruct || !queryOut->type || strcmp( queryOut->type, GenQueryOut_MS_T ) ) {
        rodsLog( LOG_ERROR, "msiPrintGenQueryOutToBuffer: Invalid input for queryOut." );
        return USER_PARAM_TYPE_ERR;
    }
    genQueryOut = ( genQueryOut_t * )queryOut->inOutStruct;


    /* Parse format */
    format_str = parseMspForStr( format );


    /********************************** EXTRACT SQL RESULTS  *********************************/

    /* Let's use printGenQueryOut() here for the sake of consistency over efficiency (somewhat). It needs a stream. */
    char filename[7];
    memset( filename, 'X', sizeof( filename ) );
    filename[sizeof( filename ) - 1] = '\0';
    umask( S_IRUSR | S_IWUSR );
    int fd = mkstemp( filename );
    if ( fd < 0 ) { /* Since it won't be caught by printGenQueryOut */
        rodsLog( LOG_ERROR, "msiPrintGenQueryOutToBuffer: mkstemp() failed." );
        return ( FILE_OPEN_ERR ); /* accurate enough */
    }
    stream = fdopen( fd, "w" );
    if ( !stream ) { /* Since it won't be caught by printGenQueryOut */
        rodsLog( LOG_ERROR, "msiPrintGenQueryOutToBuffer: fdopen() failed." );
        return ( FILE_OPEN_ERR ); /* accurate enough */
    }

    /* Write results to temp file */
    rei->status = printGenQueryOut( stream, format_str, NULL, genQueryOut );
    if ( rei->status < 0 ) {
        rodsLog( LOG_ERROR, "msiPrintGenQueryOutToBuffer: printGenQueryOut() failed, status = %d", rei->status );
        fclose( stream );
        return rei->status;
    }

    /* bytesBuf init */
    bytesBuf = ( bytesBuf_t * )malloc( sizeof( bytesBuf_t ) );
    memset( bytesBuf, 0, sizeof( bytesBuf_t ) );

    /* Read from temp file and write to bytesBuf */
    rewind( stream );
    while ( fgets( readbuffer, MAX_NAME_LEN, stream ) != NULL ) {
        appendToByteBuf( bytesBuf, readbuffer );
    }


    /********************************* RETURN AND DONE **********************************/

    /* Free memory previously allocated for previous result batches (when used in loop). */
    resetMsParam( buffer );

    /* Fill bytesBuf in our buffer output */
    fillBufLenInMsParam( buffer, bytesBuf->len, bytesBuf );
    fclose( stream );

    return 0;

}
Ejemplo n.º 12
0
/**
 * \fn msiAddSelectFieldToGenQuery(msParam_t *select, msParam_t *function, msParam_t *queryInput, ruleExecInfo_t *rei)
 *
 * \brief  Sets a select field in a genQueryInp_t
 *
 * \module core
 *
 *
 *
 * \note This microservice sets a select field in a genQueryInp_t, from two parameters.
 *       One is an iCAT attribute index given without its 'COL_' prefix.
 *       The second one is the optional SQL operator.
 *       A new genQueryInp_t is created if queryInput is NULL.
 *       Followed with #msiExecGenQuery, #msiAddSelectFieldToGenQuery allows to take the
 *       results of other microservices to build and execute queries within a rule.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] select - Required - A STR_MS_T with the select field.
 * \param[in] function - Optional - A STR_MS_T with the function. Valid values are [MIN|MAX|SUM|AVG|COUNT]
 * \param[in,out] queryInput - Optional - A GenQueryInp_MS_T.
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
**/
int
msiAddSelectFieldToGenQuery( msParam_t *select, msParam_t *function, msParam_t *queryInput, ruleExecInfo_t *rei ) {
    char *column_str;
    int column_inx, function_inx;
    genQueryInp_t *genQueryInp;

    /*************************************  INIT **********************************/

    /* For testing mode when used with irule --test */
    RE_TEST_MACRO( "    Calling msiAddSelectFieldToGenQuery" )

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


    /********************************** PARAM PARSING  *********************************/

    /* Parse select */
    if ( ( column_str = parseMspForStr( select ) ) == NULL ) {
        rodsLog( LOG_ERROR, "msiAddSelectFieldToGenQuery: input select is NULL." );
        return USER__NULL_INPUT_ERR;
    }

    /* Parse function and convert to index directly, getSelVal() returns 1 if string is NULL or empty. */
    function_inx = getSelVal( parseMspForStr( function ) );

    /* Check for proper parameter type for queryInput */
    if ( queryInput->type && strcmp( queryInput->type, GenQueryInp_MS_T ) ) {
        rodsLog( LOG_ERROR, "msiAddSelectfieldToGenQuery: queryInput is not of type GenQueryInp_MS_T." );
        return USER_PARAM_TYPE_ERR;
    }

    /* Parse queryInput. Create new structure if empty. */
    if ( !queryInput->inOutStruct ) {
        /* Set content */
        genQueryInp = ( genQueryInp_t* )malloc( sizeof( genQueryInp_t ) );
        memset( genQueryInp, 0, sizeof( genQueryInp_t ) );
        genQueryInp->maxRows = MAX_SQL_ROWS;
        queryInput->inOutStruct = ( void* )genQueryInp;

        /* Set type */
        if ( !queryInput->type ) {
            queryInput->type = strdup( GenQueryInp_MS_T );
        }
    }
    else {
        genQueryInp = ( genQueryInp_t* )queryInput->inOutStruct;
    }


    /***************************** ADD INDEXES TO QUERY INPUT  *****************************/

    /* Get column index */
    column_inx = getAttrIdFromAttrName( column_str );

    /* Error? */
    if ( column_inx < 0 ) {
        rodsLog( LOG_ERROR, "msiAddSelectfieldToGenQuery: Unable to get valid ICAT column index." );
        return column_inx;
    }

    /* Add column and function to genQueryInput */
    addInxIval( &genQueryInp->selectInp, column_inx, function_inx );


    /*********************************** DONE *********************************************/
    return 0;
}
Ejemplo n.º 13
0
/**
 * \fn msiPrintGenQueryInp( msParam_t *where, msParam_t* genQueryInpParam, ruleExecInfo_t *rei)
 *
 * \brief This microservice prints the given GenQueryInp_MS_T to the given target buffer
 *
 * \module core
 *
 * \since pre-2.1
 *
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] where - Required - a STR_MS_T containing the parameters.
 * \param[in] genQueryInpParam - Required - a GenQueryInp_MS_T containing the parameters and conditions.
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa writeString
**/
int
msiPrintGenQueryInp( msParam_t *where, msParam_t* genQueryInpParam, ruleExecInfo_t *rei ) {
    genQueryInp_t *genQueryInp;
    int i, j;
    char *writeId;
    char writeStr[MAX_NAME_LEN * 2];
    int len;
    int *ip1, *ip2;
    char *cp;
    char **cpp;

    RE_TEST_MACRO( "    Calling msiPrintGenQueryInp" );

    if ( rei == NULL || rei->rsComm == NULL ) {
        rodsLog( LOG_ERROR, "msiPrintGenQueryInp: input rei or rsComm is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }
    if ( !where ) {
        rodsLog( LOG_ERROR, "msiPrintGenQueryInp: No destination provided for writing." );
        return USER__NULL_INPUT_ERR;
    }
    /* where are we writing to? */
    if ( where->inOutStruct != NULL ) {
        writeId = ( char* )where->inOutStruct;
    }
    else {
        writeId = where->label;
    }

    /*  genQueryInp = (genQueryInp_t *)  strtol((char *)genQueryInpParam->inOutStruct,
        (char **) NULL,0); */

    genQueryInp = ( genQueryInp_t * )  genQueryInpParam->inOutStruct;


    /* print each selection pair to writeStr */
    len = genQueryInp->selectInp.len;
    ip1 = genQueryInp->selectInp.inx;
    ip2 = genQueryInp->selectInp.value;
    for ( i = 0; i < len; i++ ) {
        sprintf( writeStr, "Selected Column %d With Option %d\n", *ip1, *ip2 );
        j = _writeString( writeId, writeStr, rei );
        if ( j < 0 ) {
            return j;
        }
        ip1++;
        ip2++;
    }

    len = genQueryInp->sqlCondInp.len;
    ip1 = genQueryInp->sqlCondInp.inx;
    cpp = genQueryInp->sqlCondInp.value;
    cp = *cpp;
    for ( i = 0; i < len; i++ ) {
        sprintf( writeStr, "Condition Column %d %s\n", *ip1, cp );
        j = _writeString( writeId, writeStr, rei );
        if ( j < 0 ) {
            return j;
        }
        ip1++;
        cpp++;
        cp = *cpp;
    }
    return 0;
}
Ejemplo n.º 14
0
/**
 * \fn msiMakeGenQuery(msParam_t* selectListStr, msParam_t* condStr, msParam_t* genQueryInpParam, ruleExecInfo_t *rei)
 *
 * \brief This microservice sets up a GenQueryInp_MS_T from a list of parameters and conditions
 *
 * \module core
 *
 * \since pre-2.1
 *
 *
 * \note This microservice sets up a genQueryInp_t data structure needed by calls to rsGenQuery().
 *    To be used before #msiExecGenQuery and #msiGetMoreRows.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] selectListStr - Required - a STR_MS_T containing the parameters.
 * \param[in] condStr - Required - a STR_MS_T containing the conditions
 * \param[out] genQueryInpParam - a GenQueryInp_MS_T containing the parameters and conditions.
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
**/
int
msiMakeGenQuery( msParam_t* selectListStr, msParam_t* condStr, msParam_t* genQueryInpParam, ruleExecInfo_t *rei ) {
    char *sel, *cond, *rawQuery, *query;


    RE_TEST_MACRO( "    Calling msiMakeGenQuery" )

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


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


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


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

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

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

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

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


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


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

    return rei->status;
}
Ejemplo n.º 15
0
int _rsClientHints(
    rsComm_t*    _comm,
    bytesBuf_t** _bbuf ) {

    if ( !_comm || !_bbuf ) {
        rodsLog(
            LOG_ERROR,
            "_rsServerReport: null comm or bbuf" );
        return SYS_INVALID_INPUT_PARAM;
    }

    ( *_bbuf ) = ( bytesBuf_t* ) malloc( sizeof( bytesBuf_t ) );
    if ( !( *_bbuf ) ) {
        rodsLog(
            LOG_ERROR,
            "_rsClientHints: failed to allocate _bbuf" );
        return SYS_MALLOC_ERR;

    }

    bytesBuf_t* ies_buf = 0;
    int status = rsIESClientHints(
                     _comm,
                     &ies_buf );
    if( status < 0 ) {
        rodsLog(
            LOG_ERROR,
            "_rsClientHints: rsIESClientHints failed %d",
            status );
        return status;
    }

    json_error_t j_err;
    json_t* client_hints = json_loads(
                               ( char* )ies_buf->buf,
                               ies_buf->len, &j_err );
    freeBBuf( ies_buf );
    if ( !client_hints ) {
        rodsLog(
            LOG_ERROR,
            "_rsClientHints - json_loads failed [%s]",
            j_err.text );
        return ACTION_FAILED_ERR;
    }

    std::string hash, hash_policy;
    irods::error ret = get_hash_and_policy( _comm, hash, hash_policy );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
    }

    json_object_set(
        client_hints,
        "hash_scheme",
        json_string( hash.c_str() ) );
    json_object_set(
        client_hints,
        "match_hash_policy",
        json_string( hash_policy.c_str() ) );


    char* tmp_buf = json_dumps(
                        client_hints,
                        JSON_INDENT( 4 ) );

    // *SHOULD* free All The Things...
    json_decref( client_hints );

    ( *_bbuf )->buf = tmp_buf;
    ( *_bbuf )->len = strlen( tmp_buf );

    return 0;

} // _rsClientHints
Ejemplo n.º 16
0
int
initCondForChksum (rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, 
dataObjInp_t *dataObjInp, collInp_t *collInp)
{
    if (dataObjInp == NULL) {
       rodsLog (LOG_ERROR,
          "initCondForChksum: NULL dataObjInp input");
        return (USER__NULL_INPUT_ERR);
    }

    memset (dataObjInp, 0, sizeof (dataObjInp_t));
    memset (collInp, 0, sizeof (collInp_t));

    if (rodsArgs == NULL) {
	return (0);
    }

    if(rodsArgs->hash == True && rodsArgs->hashValue != NULL) {
        addKeyVal (&dataObjInp->condInput, HASH_KW, rodsArgs->hashValue);
        addKeyVal (&collInp->condInput, HASH_KW, rodsArgs->hashValue);
    }

    if (rodsArgs->force == True && rodsArgs->verifyChecksum) {
	rodsLog (LOG_ERROR,
	  "initCondForChksum: the 'K' and 'f' option cannot be used together");
	return (USER_OPTION_INPUT_ERR);
    }
	
    if (rodsArgs->all == True && rodsArgs->replNum == True) {
        rodsLog (LOG_ERROR,
          "initCondForChksum: the 'N' and 'a' option cannot be used together"); 
        return (USER_OPTION_INPUT_ERR);
    }

    if (rodsArgs->force == True) { 
        addKeyVal (&dataObjInp->condInput, FORCE_CHKSUM_KW, "");
        addKeyVal (&collInp->condInput, FORCE_CHKSUM_KW, "");
    }

    if (rodsArgs->all == True) {
        addKeyVal (&dataObjInp->condInput, CHKSUM_ALL_KW, "");
        addKeyVal (&collInp->condInput, CHKSUM_ALL_KW, "");
    }

    if (rodsArgs->verifyChecksum == True) {
        addKeyVal (&dataObjInp->condInput, VERIFY_CHKSUM_KW, "");
        addKeyVal (&collInp->condInput, VERIFY_CHKSUM_KW, "");
    }

    if (rodsArgs->replNum == True) {
        addKeyVal (&dataObjInp->condInput, REPL_NUM_KW, 
	  rodsArgs->replNumValue);
    }

    if (rodsArgs->resource == True) {
        addKeyVal (&dataObjInp->condInput, RESC_NAME_KW,
          rodsArgs->resourceString);
    }

    /* XXXXX need to add -u register cond */

    dataObjInp->openFlags = O_RDONLY;

    return (0);
}
Ejemplo n.º 17
0
/**
 * \fn msiSetQuota(msParam_t *type, msParam_t *name, msParam_t *resource, msParam_t *value, ruleExecInfo_t *rei)
 *
 * \brief Sets disk usage quota for a user or group
 *
 * \module core
 *
 * \since 3.0.x
 *
 * \author  Antoine de Torcy
 * \date    2011-07-07
 *
 *
 * \note  This microservice sets a disk usage quota for a given user or group.
 *          If no resource name is provided the quota will apply across all resources.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] type - a STR_MS_T - Can be either "user" or "group"
 * \param[in] name - a STR_MS_T with the name of the user or group
 * \param[in] resource - Optional - a STR_MS_T with the name of the resource where
 *      the quota will apply, or "total" for the quota to be system-wide.
 * \param[in] value - an INT_MST_T or DOUBLE_MS_T or STR_MS_T with the quota (in bytes)
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence rei->uoic->authInfo.authFlag must be >= 5 (local admin)
 * \DolVarModified None
 * \iCatAttrDependence None
 * \iCatAttrModified Updates r_quota_main
 * \sideeffect None
 *
 * \return integer
 * \retval 0 on success
 * \pre None
 * \post None
 * \sa None
 **/
int
msiSetQuota( msParam_t *type, msParam_t *name, msParam_t *resource, msParam_t *value, ruleExecInfo_t *rei ) {
    generalAdminInp_t generalAdminInp;              /* Input for rsGeneralAdmin */
    char quota[21];
    int status;


    /* For testing mode when used with irule --test */
    RE_TEST_MACRO( "    Calling msiSetQuota" )

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


    /* Must be called from an admin account */
    if ( rei->uoic->authInfo.authFlag < LOCAL_PRIV_USER_AUTH ) {
        status = CAT_INSUFFICIENT_PRIVILEGE_LEVEL;
        rodsLog( LOG_ERROR, "msiSetQuota: User %s is not local admin. Status = %d",
                 rei->uoic->userName, status );
        return ( status );
    }


    /* Prepare generalAdminInp. It needs to be set up as follows:
     *    generalAdminInp.arg0: "set-quota"
     *    generalAdminInp.arg1: type ("user" or "group")
     *    generalAdminInp.arg2: name of user/group
     *    generalAdminInp.arg3: resource name or "total"
     *    generalAdminInp.arg4: quota value
     *    generalAdminInp.arg5: ""
     *    generalAdminInp.arg6: ""
     *    generalAdminInp.arg7: ""
     *    generalAdminInp.arg8: ""
     *    generalAdminInp.arg9: ""
     */
    memset( &generalAdminInp, 0, sizeof( generalAdminInp_t ) );
    generalAdminInp.arg0 = "set-quota";

    /* Parse type */
    generalAdminInp.arg1 = parseMspForStr( type );
    if ( strcmp( generalAdminInp.arg1, "user" ) && strcmp( generalAdminInp.arg1, "group" ) ) {
        status = USER_BAD_KEYWORD_ERR;
        rodsLog( LOG_ERROR, "msiSetQuota: Invalid user type: %s. Valid types are \"user\" and \"group\"",
                 generalAdminInp.arg1 );
        return ( status );
    }

    /* Parse user/group name */
    generalAdminInp.arg2 = parseMspForStr( name );

    /* parse resource name */
    if ( ( generalAdminInp.arg3 = parseMspForStr( resource ) ) == NULL ) {
        generalAdminInp.arg3 = "total";
    }

    /* Parse value */
    if ( value->type && !strcmp( value->type, STR_MS_T ) ) {
        generalAdminInp.arg4 = ( char * )value->inOutStruct;
    }
    else if ( value->type && !strcmp( value->type, INT_MS_T ) ) {
        snprintf( quota, 11, "%d", *( int * )value->inOutStruct );
        generalAdminInp.arg4 = quota;
    }
    else if ( value->type && !strcmp( value->type, DOUBLE_MS_T ) ) {
        snprintf( quota, 21, "%lld", *( rodsLong_t * )value->inOutStruct );
        generalAdminInp.arg4 = quota;
    }
    else {
        status = USER_PARAM_TYPE_ERR;
        rodsLog( LOG_ERROR, "msiSetQuota: Invalid type for param value. Status = %d", status );
        return ( status );
    }

    /* Fill up the rest of generalAdminInp */
    generalAdminInp.arg5 = "";
    generalAdminInp.arg6 = "";
    generalAdminInp.arg7 = "";
    generalAdminInp.arg8 = "";
    generalAdminInp.arg9 = "";


    /* Call rsGeneralAdmin */
    status = rsGeneralAdmin( rei->rsComm, &generalAdminInp );


    /* Done */
    return status;
}
Ejemplo n.º 18
0
int
chksumCollUtil (rcComm_t *conn, char *srcColl, rodsEnv *myRodsEnv, 
rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp, collInp_t *collInp)
{
    int status;
    int savedStatus = 0;
    char srcChildPath[MAX_NAME_LEN];
    collHandle_t collHandle;
    collEnt_t collEnt;
    int queryFlags;

    if (srcColl == NULL) {
       rodsLog (LOG_ERROR,
          "chksumCollUtil: NULL srcColl input");
        return (USER__NULL_INPUT_ERR);
    }

    fprintf (stdout, "C- %s:\n", srcColl);

    if (rodsArgs->resource == True) {
#if 0
	queryFlags = LONG_METADATA_FG | NO_TRIM_REPL_FG;
#else
	queryFlags = INCLUDE_CONDINPUT_IN_QUERY;
	bzero (&collHandle, sizeof (collHandle));
	replKeyVal (&dataObjInp->condInput, &collHandle.dataObjInp.condInput);
#endif
    } else {
	queryFlags = 0;
    }
    status = rclOpenCollection (conn, srcColl, queryFlags, &collHandle);
    if (status < 0) {
        rodsLog (LOG_ERROR,
          "chksumCollUtil: rclOpenCollection of %s error. status = %d",
          srcColl, status);
        return status;
    }
    if (collHandle.rodsObjStat->specColl != NULL &&
      collHandle.rodsObjStat->specColl->collClass != LINKED_COLL) {
        /* no trim for mounted coll */
        rclCloseCollection (&collHandle);
        return 0;
    }
    while ((status = rclReadCollection (conn, &collHandle, &collEnt)) >= 0) {
        if (collEnt.objType == DATA_OBJ_T) {
            snprintf (srcChildPath, MAX_NAME_LEN, "%s/%s",
              collEnt.collName, collEnt.dataName);
	    /* screen unnecessary call to chksumDataObjUtil if user input a 
	     * resource. */
#if 0
            if (rodsArgs->resource != True || 
	      rodsArgs->resourceString == NULL ||
	      strcmp (rodsArgs->resourceString, collEnt.resource) == 0) {
#endif
                status = chksumDataObjUtil (conn, srcChildPath, myRodsEnv, 
	          rodsArgs, dataObjInp);
                if (status < 0) {
                    rodsLogError (LOG_ERROR, status,
                      "chksumCollUtil:chksumDataObjU failed for %s.stat = %d",
                      srcChildPath, status);
                    /* need to set global error here */
                    savedStatus = status;
                    status = 0;
		}
#if 0
	    } else {
		status = 0;
            }
#endif
        } else if (collEnt.objType == COLL_OBJ_T) {
            dataObjInp_t childDataObjInp;
            childDataObjInp = *dataObjInp;
	    if (collEnt.specColl.collClass != NO_SPEC_COLL)
                childDataObjInp.specColl = &collEnt.specColl;
            else 
                childDataObjInp.specColl = NULL;
            status = chksumCollUtil (conn, collEnt.collName, myRodsEnv,
              rodsArgs, &childDataObjInp, collInp);
            if (status < 0 && status != CAT_NO_ROWS_FOUND) {
                return (status);
            }
        }
    }
    rclCloseCollection (&collHandle);
    if (savedStatus < 0) {
	return (savedStatus);
    } else if (status == CAT_NO_ROWS_FOUND) {
	return (0);
    } else {
        return (status);
    }
}
Ejemplo n.º 19
0
/*
 * label type of rule engine event
 * flag -4 log rei
 *      otherwise do not log rei
 * action
 *
 */
int
reDebug( RuleEngineEvent label, int flag, RuleEngineEventParam *param, Node *node, Env *env, ruleExecInfo_t *rei ) {
    /* do not log anything if logging is turned off */
    if ( ruleEngineConfig.logging == 0 ) {
        return 0;
    }
    int i, m, s, status, sleepT, j;
    int processedBreakPoint = 0;
    char hdr[HEADER_TYPE_LEN];
    char *readhdr = NULL;
    char *readmsg = NULL;
    char *user = NULL;
    char *addr = NULL;
    static int mNum = 0;
    static int sNum = 0;
    static int curStat = 0;
    static int reDebugStackPtr = -1;
    static int reDebugStopAt = 1;
    char condRead[MAX_NAME_LEN];
    char myActionStr[10][MAX_NAME_LEN + 10];
    int aNum = 0;
    char seActionStr[10 * MAX_NAME_LEN + 100];
    char timestamp[TIME_LEN];
    rsComm_t *svrComm;
    int waitCnt = 0;
    sleepT = 1;
    char buf[HEADER_TYPE_LEN - 1];

    svrComm = rei->rsComm;

    if ( svrComm == NULL ) {
        rodsLog( LOG_ERROR, "Empty svrComm in REI structure for actionStr=%s\n",
                 param->actionName );
        return 0;
    }

    generateLogTimestamp( timestamp, TIME_LEN );
    printRuleEngineEventLabel( buf, HEADER_TYPE_LEN - 1, label, param );
    snprintf( hdr, HEADER_TYPE_LEN - 1,   "iaudit:%s", timestamp );
    condRead[0] = '\0';
    /* rodsLog (LOG_NOTICE,"PPP:%s\n",hdr); */
    snprintf( seActionStr, MAX_NAME_LEN + 10, "%s", buf );
    if ( GlobalREAuditFlag > 0 ) {
        if ( flag == -4 ) {
            if ( rei->uoic != NULL && strlen( rei->uoic->userName ) > 0 && strlen( rei->uoic->rodsZone ) > 0 ) {
                snprintf( myActionStr[aNum], MAX_NAME_LEN + 10 , "  USER:%s@%s", rei->uoic->userName, rei->uoic->rodsZone );
                aNum++;
            }
            if ( rei->doi != NULL && strlen( rei->doi->objPath ) > 0 ) {
                snprintf( myActionStr[aNum], MAX_NAME_LEN + 10 , "  DATA:%s", rei->doi->objPath );
                aNum++;
            }
            if ( rei->doi != NULL && strlen( rei->doi->filePath ) > 0 ) {
                snprintf( myActionStr[aNum], MAX_NAME_LEN + 10 , "  FILE:%s", rei->doi->filePath );
                aNum++;
            }
            if ( rei->doinp != NULL && strlen( rei->doinp->objPath ) > 0 ) {
                snprintf( myActionStr[aNum], MAX_NAME_LEN + 10 , "  DATAIN:%s", rei->doinp->objPath );
                aNum++;
            }
            if ( rei->doi != NULL && strlen( rei->doi->rescName ) > 0 ) {
                snprintf( myActionStr[aNum], MAX_NAME_LEN + 10 , "  RESC:%s", rei->doi->rescName );
                aNum++;
            }
            if ( rei->coi != NULL && strlen( rei->coi->collName ) > 0 ) {
                snprintf( myActionStr[aNum], MAX_NAME_LEN + 10 , "  COLL:%s", rei->coi->collName );
                aNum++;
            }
            for ( j = 0; j < aNum; j++ ) {
                strncat( seActionStr, myActionStr[j], 10 * MAX_NAME_LEN + 100 - strlen( seActionStr ) );
            }
        }
    }

    /* Write audit trail */
    if ( GlobalREAuditFlag == 3 ) {
        i = _writeXMsg( GlobalREAuditFlag, hdr, seActionStr );
        if ( i < 0 ) {
            irods::log( ERROR( i, "_writeXMsg failed." ) );
        }
    }


    /* Send current position for debugging */
    if ( GlobalREDebugFlag > 5 ) {
        /* modify stack */
        int pcType = reDebugPCType( label );
        if ( ( pcType & 1 ) != 0 ) {
            pushReStack( label, param->actionName );
        }
        else if ( ( pcType & 2 ) != 0 ) {
            popReStack( label, param->actionName );
        }

        if ( curStat == REDEBUG_CONTINUE && reDebugStackCurrPtr <= reDebugStackPtr && ( reDebugPCType( label ) & reDebugStopAt ) != 0 ) {
            curStat = REDEBUG_WAIT;
        }
        if ( curStat != REDEBUG_CONTINUE ) {
            snprintf( hdr, HEADER_TYPE_LEN - 1,   "idbug:%s", param->actionName );
            i = _writeXMsg( GlobalREDebugFlag, hdr, buf );
            if ( i < 0 ) {
                irods::log( ERROR( i, "_writeXMsg failed." ) );
            }
        }

        while ( GlobalREDebugFlag > 5 ) {
            s = sNum;
            m = mNum;
            /* what should be the condition */
            sprintf( condRead, "(*XSEQNUM >= %d) && (*XADDR != \"%s:%i\") && (*XUSER  == \"%s@%s\") && ((*XHDR == \"CMSG:ALL\") %%%% (*XHDR == \"CMSG:%s:%i\"))",
                     s, myHostName, myPID, svrComm->clientUser.userName, svrComm->clientUser.rodsZone, myHostName, myPID );

            /*
            sprintf(condRead, "(*XSEQNUM >= %d)  && ((*XHDR == CMSG:ALL) %%%% (*XHDR == CMSG:%s:%i))",
            	s,  myHostName, getpid());
            */
            status = _readXMsg( GlobalREDebugFlag, condRead, &m, &s, &readhdr, &readmsg, &user, &addr );
            if ( status == SYS_UNMATCHED_XMSG_TICKET ) {
                cleanUpDebug();
                return 0;
            }
            if ( status  >= 0 ) {
                rodsLog( LOG_NOTICE, "Getting XMsg:%i:%s:%s\n", s, readhdr, readmsg );
                curStat = processXMsg( GlobalREDebugFlag, readmsg,
                                       param, node, env, rei );
                if ( readhdr != NULL ) {
                    free( readhdr );
                }
                if ( readmsg != NULL ) {
                    free( readmsg );
                }
                if ( user != NULL ) {
                    free( user );
                }
                if ( addr != NULL ) {
                    free( addr );
                }

                mNum = m;
                sNum = s + 1;
                if ( curStat == REDEBUG_WAIT ) {
                    sendWaitXMsg( GlobalREDebugFlag );
                }
                else if ( curStat == REDEBUG_STEP_OVER ) {
                    reDebugStackPtr = reDebugStackCurrPtr;
                    reDebugStopAt = 1;
                    curStat = REDEBUG_CONTINUE;
                    break;
                }
                else if ( curStat == REDEBUG_STEP_OUT ) {
                    reDebugStackPtr = reDebugStackCurrPtr - 1;
                    reDebugStopAt = 2;
                    curStat = REDEBUG_CONTINUE;
                    break;
                }
                else if ( curStat == REDEBUG_STEP_CONTINUE ) {
                    reDebugStackPtr = -1;
                    curStat = REDEBUG_CONTINUE;
                    break;
                }
                else if ( curStat == REDEBUG_NEXT ) {
                    break;
                }
            }
            else {
                if ( !( curStat == REDEBUG_CONTINUE || curStat == REDEBUG_CONTINUE_VERBOSE ) ) {

                    /*#if _POSIX_C_SOURCE >= 199309L
                    					struct timespec time = {0, 100000000}, rem;
                    					nanosleep(&time, &rem);
                    					waitCnt+=10;
                    #else*/
                    sleep( sleepT );
                    waitCnt += 100;
                    /*#endif*/
                    if ( waitCnt > 6000 ) {
                        sendWaitXMsg( GlobalREDebugFlag );
                        waitCnt = 0;
                    }
                }
            }
            if ( curStat == REDEBUG_CONTINUE || curStat == REDEBUG_CONTINUE_VERBOSE ) {
                if ( processedBreakPoint == 1 ) {
                    break;
                }
                curStat = processBreakPoint( GlobalREDebugFlag,
                                             param, node, curStat );
                processedBreakPoint = 1;
                if ( curStat == REDEBUG_WAIT ) {
                    sendWaitXMsg( GlobalREDebugFlag );
                    continue;
                }
                else {
                    break;
                }
            }
        }
    }


    return 0;
}
Ejemplo n.º 20
0
int
initCondForPhybunOpr (rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, 
structFileExtAndRegInp_t *phyBundleCollInp, 
rodsPathInp_t *rodsPathInp)
{
	char tmpStr[NAME_LEN];
	
    if (phyBundleCollInp == NULL) {
       rodsLog (LOG_ERROR,
          "initCondForPhybunOpr: NULL phyBundleCollInp input");
        return (USER__NULL_INPUT_ERR);
    }

    memset (phyBundleCollInp, 0, sizeof (structFileExtAndRegInp_t));

    if (rodsArgs == NULL) {
	return (0);
    }

    if (rodsArgs->resource == True) {
        if (rodsArgs->resourceString == NULL) {
            rodsLog (LOG_ERROR,
              "initCondForPhybunOpr: NULL resourceString error");
            return (USER__NULL_INPUT_ERR);
        } else {
            addKeyVal (&phyBundleCollInp->condInput, 
	      DEST_RESC_NAME_KW, rodsArgs->resourceString);
            addKeyVal (&phyBundleCollInp->condInput, RESC_NAME_KW,
              rodsArgs->resourceString);
        }
    } else {
       rodsLog (LOG_ERROR,
          "initCondForPhybunOpr: A -Rresource must be input");
        return (USER__NULL_INPUT_ERR);
    }

    if (rodsArgs->verifyChecksum == True) {
        addKeyVal (&phyBundleCollInp->condInput, VERIFY_CHKSUM_KW, "");
    }

    if (rodsArgs->dataTypeString != NULL) {
        if (strcmp (rodsArgs->dataTypeString, "t") == 0 ||
          strcmp (rodsArgs->dataTypeString, TAR_DT_STR) == 0 ||
          strcmp (rodsArgs->dataTypeString, "tar") == 0) {
            addKeyVal (&phyBundleCollInp->condInput, DATA_TYPE_KW,
              TAR_BUNDLE_DT_STR);
        } else if (strcmp (rodsArgs->dataTypeString, "g") == 0 ||
          strcmp (rodsArgs->dataTypeString, GZIP_TAR_DT_STR) == 0 ||
          strcmp (rodsArgs->dataTypeString, "gzip") == 0) {
            addKeyVal (&phyBundleCollInp->condInput, DATA_TYPE_KW,
              GZIP_TAR_BUNDLE_DT_STR);
        } else if (strcmp (rodsArgs->dataTypeString, "b") == 0 ||
          strcmp (rodsArgs->dataTypeString, BZIP2_TAR_DT_STR) == 0 ||
          strcmp (rodsArgs->dataTypeString, "bzip") == 0) {
            addKeyVal (&phyBundleCollInp->condInput, DATA_TYPE_KW,
              BZIP2_TAR_BUNDLE_DT_STR);
        } else if (strcmp (rodsArgs->dataTypeString, "z") == 0 ||
          strcmp (rodsArgs->dataTypeString, ZIP_DT_STR) == 0 ||
          strcmp (rodsArgs->dataTypeString, "zip") == 0) {
            addKeyVal (&phyBundleCollInp->condInput, DATA_TYPE_KW,
              ZIP_BUNDLE_DT_STR);
        } else {
            addKeyVal (&phyBundleCollInp->condInput, DATA_TYPE_KW,
              rodsArgs->dataTypeString);
        }
    }
	
	if (rodsArgs->number == True) {
		snprintf (tmpStr, NAME_LEN, "%d", rodsArgs->numberValue);
		addKeyVal (&phyBundleCollInp->condInput, MAX_SUB_FILE_KW, tmpStr);
	}

    return (0);
}
Ejemplo n.º 21
0
Archivo: xmlMS.c Proyecto: UPPMAX/irods
/**
 * \fn msiXmlDocSchemaValidate(msParam_t *xmlObj, msParam_t *xsdObj, msParam_t *status, ruleExecInfo_t *rei)
 *
 * \brief  This microservice validates an XML file against an XSD schema, both iRODS objects.
 * 
 * \module xml
 * 
 * \since pre-2.1
 * 
 * \author  Antoine de Torcy
 * \date    2008/05/29
 * 
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] xmlObj - a msParam of type DataObjInp_MS_T or STR_MS_T which is irods path of the XML object.
 * \param[in] xsdObj - a msParam of type DataObjInp_MS_T or STR_MS_T which is irods path of the XSD object.
 * \param[out] status - a msParam of type INT_MS_T which is a validation result.
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence None
 * \DolVarModified None
 * \iCatAttrDependence None
 * \iCatAttrModified None
 * \sideeffect None
 *
 * \return integer
 * \retval 0 on success
 * \pre None
 * \post None
 * \sa None
**/
int 
msiXmlDocSchemaValidate(msParam_t *xmlObj, msParam_t *xsdObj, msParam_t *status, ruleExecInfo_t *rei) 
{
	/* for parsing msParams and to open iRODS objects */
	dataObjInp_t xmlObjInp, *myXmlObjInp;
	dataObjInp_t xsdObjInp, *myXsdObjInp;
	int xmlObjID, xsdObjID;

	/* for getting size of objects to read from */
	rodsObjStat_t *rodsObjStatOut = NULL;

	/* for reading from iRODS objects */
	openedDataObjInp_t openedDataObjInp;
	bytesBuf_t *xmlBuf = NULL;
	char *tail;

	/* for xml parsing and validating */
	xmlDocPtr doc, xsd_doc;
	xmlSchemaParserCtxtPtr parser_ctxt;
	xmlSchemaPtr schema;
	xmlSchemaValidCtxtPtr valid_ctxt;
	bytesBuf_t *errBuf;

	/* misc. to avoid repeating rei->rsComm */
	rsComm_t *rsComm;



	/*************************************  USUAL INIT PROCEDURE **********************************/
	
	/* For testing mode when used with irule --test */
	RE_TEST_MACRO ("    Calling msiXmlDocSchemaValidate")


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

	rsComm = rei->rsComm;



	/************************************ ADDITIONAL INIT SETTINGS *********************************/

	/* XML constants */
	xmlSubstituteEntitiesDefault(1);
	xmlLoadExtDtdDefaultValue = 1;


	/* allocate memory for output error buffer */
	errBuf = (bytesBuf_t *)malloc(sizeof(bytesBuf_t));
	errBuf->buf = strdup("");
	errBuf->len = strlen((char*)errBuf->buf);

	/* Default status is failure, overwrite if success */
	fillBufLenInMsParam (status, -1, NULL);

	
	/********************************** RETRIEVE INPUT PARAMS **************************************/

	/* Get path of XML document */
	rei->status = parseMspForDataObjInp (xmlObj, &xmlObjInp, &myXmlObjInp, 0);
	if (rei->status < 0)
	{
		rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: input xmlObj error. status = %d", rei->status);
		free(errBuf);
		return (rei->status);
	}


	/* Get path of schema */
	rei->status = parseMspForDataObjInp (xsdObj, &xsdObjInp, &myXsdObjInp, 0);
	if (rei->status < 0)
	{
		rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: input xsdObj error. status = %d", rei->status);
		free(errBuf);
		return (rei->status);
	}


	/******************************** OPEN AND READ FROM XML OBJECT ********************************/

	/* Open XML file */
	if ((xmlObjID = rsDataObjOpen(rsComm, &xmlObjInp)) < 0) 
	{
		rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: Cannot open XML data object. status = %d", xmlObjID);
		free(errBuf);
		return (xmlObjID);
	}


	/* Get size of XML file */
	rei->status = rsObjStat (rsComm, &xmlObjInp, &rodsObjStatOut);
	if (rei->status < 0 || !rodsObjStatOut)
	{
		rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: Cannot stat XML data object. status = %d", rei->status);
		free(errBuf);
		return (rei->status);
	}


	/* xmlBuf init */
	/* memory for xmlBuf->buf is allocated in rsFileRead() */
	xmlBuf = (bytesBuf_t *) malloc (sizeof (bytesBuf_t));
	memset (xmlBuf, 0, sizeof (bytesBuf_t));


	/* Read content of XML file */
	memset (&openedDataObjInp, 0, sizeof (openedDataObjInp_t));
	openedDataObjInp.l1descInx = xmlObjID;
	openedDataObjInp.len = (int)rodsObjStatOut->objSize + 1;	/* extra byte to add a null char */

	rei->status = rsDataObjRead (rsComm, &openedDataObjInp, xmlBuf);

	/* add terminating null character */
	tail = (char*)xmlBuf->buf;
	tail[openedDataObjInp.len - 1] = '\0';


	/* Close XML file */
	rei->status = rsDataObjClose (rsComm, &openedDataObjInp);

	/* cleanup */
	freeRodsObjStat (rodsObjStatOut);



	/*************************************** PARSE XML DOCUMENT **************************************/

	/* Parse xmlBuf.buf into an xmlDocPtr */
	doc = xmlParseDoc((xmlChar*)xmlBuf->buf);
	clearBBuf(xmlBuf);

	if (doc == NULL)
	{
		rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: XML document cannot be loaded or is not well-formed.");
		free(errBuf);
	    xmlCleanupParser();

	    return (USER_INPUT_FORMAT_ERR);
	}



	/******************************** OPEN AND READ FROM XSD OBJECT ********************************/

	/* Open schema file */
	if ((xsdObjID = rsDataObjOpen(rsComm, &xsdObjInp)) < 0) 
	{
		rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: Cannot open XSD data object. status = %d", xsdObjID);
		free(errBuf);
		xmlFreeDoc(doc);
	    xmlCleanupParser();

		return (xsdObjID);
	}


	/* Get size of schema file */
	rei->status = rsObjStat (rsComm, &xsdObjInp, &rodsObjStatOut);


	/* Read entire schema file */
	memset (&openedDataObjInp, 0, sizeof (openedDataObjInp_t));
	openedDataObjInp.l1descInx = xsdObjID;
	openedDataObjInp.len = (int)rodsObjStatOut->objSize + 1;	/* to add null char */

	rei->status = rsDataObjRead (rsComm, &openedDataObjInp, xmlBuf);

	/* add terminating null character */
	tail = (char*)xmlBuf->buf;
	tail[openedDataObjInp.len - 1] = '\0';


	/* Close schema file */
	rei->status = rsDataObjClose (rsComm, &openedDataObjInp);

	/* cleanup */
	freeRodsObjStat (rodsObjStatOut);



	/*************************************** PARSE XSD DOCUMENT **************************************/

	/* Parse xmlBuf.buf into an xmlDocPtr */
	xsd_doc = xmlParseDoc((xmlChar*)xmlBuf->buf);
	clearBBuf(xmlBuf);

	if (xsd_doc == NULL)
	{
		rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: XML Schema cannot be loaded or is not well-formed.");
		free(errBuf);
		xmlFreeDoc(doc);
		xmlCleanupParser();

	    return (USER_INPUT_FORMAT_ERR);
	}



	/**************************************** VALIDATE DOCUMENT **************************************/

	/* Create a parser context */
	parser_ctxt = xmlSchemaNewDocParserCtxt(xsd_doc);
	if (parser_ctxt == NULL)
	{
		rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: Unable to create a parser context for the schema.");
		free(errBuf);
		xmlFreeDoc(xsd_doc);
		xmlFreeDoc(doc);
	    xmlCleanupParser();

	    return (USER_INPUT_FORMAT_ERR);
	}


	/* Parse the XML schema */
	schema = xmlSchemaParse(parser_ctxt);
	if (schema == NULL) 
	{
		rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: Invalid schema.");
		free(errBuf);
		xmlSchemaFreeParserCtxt(parser_ctxt);
		xmlFreeDoc(doc);
		xmlFreeDoc(xsd_doc);
        xmlCleanupParser();

	    return (USER_INPUT_FORMAT_ERR);
	}


	/* Create a validation context */
	valid_ctxt = xmlSchemaNewValidCtxt(schema);
	if (valid_ctxt == NULL) 
	{
		rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: Unable to create a validation context for the schema.");
		free(errBuf);
		xmlSchemaFree(schema);
		xmlSchemaFreeParserCtxt(parser_ctxt);
		xmlFreeDoc(xsd_doc);
		xmlFreeDoc(doc);
	    xmlCleanupParser();

	    return (USER_INPUT_FORMAT_ERR);
	}


	/* Set myErrorCallback() as the default handler for error messages and warnings */
	xmlSchemaSetValidErrors(valid_ctxt, (xmlSchemaValidityErrorFunc)myErrorCallback, (xmlSchemaValidityWarningFunc)myErrorCallback, errBuf);


	/* Validate XML doc */
	rei->status = xmlSchemaValidateDoc(valid_ctxt, doc);



	/******************************************* WE'RE DONE ******************************************/

	/* return both error code and messages through status */
	resetMsParam (status);
	fillBufLenInMsParam (status, rei->status, errBuf);


	/* cleanup of all xml parsing stuff */
	xmlSchemaFreeValidCtxt(valid_ctxt);
	xmlSchemaFree(schema);
	xmlSchemaFreeParserCtxt(parser_ctxt);
	xmlFreeDoc(doc);
	xmlFreeDoc(xsd_doc);
	xmlCleanupParser();

	return (rei->status);
}
Ejemplo n.º 22
0
int
parseCmdLinePath( int argc, char **argv, int optInd, rodsEnv *myRodsEnv,
                  int srcFileType, int destFileType, int flag, rodsPathInp_t *rodsPathInp ) {
    int nInput;
    int i, status;
    int numSrc;

    nInput = argc - optInd;

    if ( rodsPathInp == NULL ) {
        rodsLog( LOG_ERROR, "parseCmdLinePath: NULL rodsPathInp input" );
        return ( USER__NULL_INPUT_ERR );
    }

    memset( rodsPathInp, 0, sizeof( rodsPathInp_t ) );

    if ( nInput <= 0 ) {
        if ( ( flag & ALLOW_NO_SRC_FLAG ) == 0 ) {
            return ( USER__NULL_INPUT_ERR );
        }
        else {
            numSrc = 1;
        }
    }
    else if ( nInput == 1 ) {
        numSrc = 1;
    }
    else if ( destFileType == NO_INPUT_T ) {            /* no dest input */
        numSrc = nInput;
    }
    else {
        numSrc = nInput - 1;
    }

    for ( i = 0; i < numSrc; i++ ) {
        if ( nInput <= 0 ) {
            /* just add cwd */
            addSrcInPath( rodsPathInp, "." );
        }
        else {
            addSrcInPath( rodsPathInp, argv[optInd + i] );
        }
        if ( srcFileType <= COLL_OBJ_T ) {
            status = parseRodsPath( &rodsPathInp->srcPath[i], myRodsEnv );
        }
        else {
            status = parseLocalPath( &rodsPathInp->srcPath[i] );
        }
        if ( status < 0 ) {
            return ( status );
        }
    }

    if ( destFileType != NO_INPUT_T ) {
        rodsPathInp->destPath = ( rodsPath_t* )malloc( sizeof( rodsPath_t ) );
        memset( rodsPathInp->destPath, 0, sizeof( rodsPath_t ) );
        if ( nInput > 1 ) {
            rstrcpy( rodsPathInp->destPath->inPath, argv[argc - 1],
                     MAX_NAME_LEN );
        }
        else {
            rstrcpy( rodsPathInp->destPath->inPath, ".", MAX_NAME_LEN );
        }

        if ( destFileType <= COLL_OBJ_T ) {
            status = parseRodsPath( rodsPathInp->destPath, myRodsEnv );
        }
        else {
            status = parseLocalPath( rodsPathInp->destPath );
        }
    }

    return ( status );
}
Ejemplo n.º 23
0
/**
 * \fn msiListEnabledMS(msParam_t *outKVPairs, ruleExecInfo_t *rei)
 *
 * \brief Returns the list of compiled microservices on the local iRODS server
 *
 * \module framework
 *
 * \since 2.1
 *
 * \author  Antoine de Torcy
 * \date    2009-02-12
 *
 * \note This microservice looks at reAction.hpp and returns the list of compiled
 *  microservices on the local iRODS server.
 *      The results are written to a KeyValPair_MS_T. For each pair the keyword is the MS name
 *  while the value is the module where the microservice belongs.
 *  Standard non-module microservices are listed as "core".
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[out] outKVPairs - A KeyValPair_MS_T containing the results.
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
**/
int
msiListEnabledMS( msParam_t *outKVPairs, ruleExecInfo_t *rei ) {
    FILE *radhpp = 0;			/* reAction(dot)hpp */

    keyValPair_t *results;		/* the output data structure */

    char lineStr[LONG_NAME_LEN];	/* for line and string parsing */
    char modName[NAME_LEN];
    char *begPtr, *endPtr;


    /* For testing mode when used with irule --test */
    RE_TEST_MACRO( "    Calling msiEnabledMS" )


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


    /* Open reAction.hpp for reading */
    radhpp = fopen( "../re/include/reAction.hpp", "r" );
    if ( !radhpp ) {
        rodsLog( LOG_ERROR, "msiListEnabledMS: unable to open reAction.hpp for reading." );
        return ( UNIX_FILE_READ_ERR );
    }


    /* Skip the first part of the file */
    while ( fgets( lineStr, LONG_NAME_LEN, radhpp ) != NULL ) {
        if ( strstr( lineStr, "microsdef_t MicrosTable[]" ) == lineStr ) {
            break;
        }
    }


    /* Default microservices come first, will be listed are "core" */
    strncpy( modName, "core", NAME_LEN ); /* Pad with null chars in the process */


    /* Allocate memory for our result struct */
    results = ( keyValPair_t* )malloc( sizeof( keyValPair_t ) );
    memset( results, 0, sizeof( keyValPair_t ) );


    /* Scan microservice table one line at a time*/
    while ( fgets( lineStr, LONG_NAME_LEN, radhpp ) != NULL ) {
        /* End of the table? */
        if ( strstr( lineStr, "};" ) == lineStr ) {
            break;
        }

        /* Get microservice name */
        if ( ( begPtr = strchr( lineStr, '\"' ) ) && ( endPtr = strrchr( lineStr, '\"' ) ) ) {
            endPtr[0] = '\0';
            addKeyVal( results, &begPtr[1], modName );
        }
        else {
            /* New Module? */
            if ( strstr( lineStr, "module microservices" ) ) {
                /* Get name of module (between the first two spaces) */
                begPtr = strchr( lineStr, ' ' );
                endPtr = strchr( ++begPtr, ' ' );
                endPtr[0] = '\0';

                strncpy( modName, begPtr, NAME_LEN - 1 );
            }
        }
    }


    /* Done */
    fclose( radhpp );


    /* Send results out to outKVPairs */
    fillMsParam( outKVPairs, NULL, KeyValPair_MS_T, results, NULL );


    return 0;
}
Ejemplo n.º 24
0
/* resolveRodsTarget - based on srcPath and destPath, fill in targPath.
 * oprType -
 *      MOVE_OPR - do not create the target coll or dir because rename will
 *        take care of it.
 *      RSYNC_OPR - udes the destPath and the targPath if the src is a
 *        collection
 *      All other oprType will be treated as normal.
 */
int
resolveRodsTarget( rcComm_t *conn, rodsEnv *myRodsEnv,
                   rodsPathInp_t *rodsPathInp, int oprType ) {
    rodsPath_t *srcPath, *destPath;
    char srcElement[MAX_NAME_LEN], destElement[MAX_NAME_LEN];
    int status;
    int srcInx;
    rodsPath_t *targPath;

    if ( rodsPathInp == NULL ) {
        rodsLog( LOG_ERROR,
                 "resolveRodsTarget: NULL rodsPathInp or targPath input" );
        return ( USER__NULL_INPUT_ERR );
    }

    destPath = rodsPathInp->destPath;
    if ( destPath != NULL && destPath->objState == UNKNOWN_ST ) {
        getRodsObjType( conn, destPath );
    }

    for ( srcInx = 0; srcInx < rodsPathInp->numSrc; srcInx++ ) {
        srcPath = &rodsPathInp->srcPath[srcInx];
        targPath = &rodsPathInp->targPath[srcInx];

        /* we don't do wild card yet */

        if ( srcPath->objState == UNKNOWN_ST ) {
            getRodsObjType( conn, srcPath );
            if ( srcPath->objState == NOT_EXIST_ST ) {
                rodsLog( LOG_ERROR,
                         "resolveRodsTarget: srcPath %s does not exist",
                         srcPath->outPath );
                return ( USER_INPUT_PATH_ERR );
            }
        }

        if ( destPath->objType >= UNKNOWN_FILE_T &&
                strcmp( destPath->outPath, STDOUT_FILE_NAME ) == 0 ) {
            /* pipe to stdout */
            if ( srcPath->objType != DATA_OBJ_T ) {
                rodsLog( LOG_ERROR,
                         "resolveRodsTarget: src %s is the wrong type for dest -",
                         srcPath->outPath );
                return ( USER_INPUT_PATH_ERR );
            }
            *targPath = *destPath;
            targPath->objType = LOCAL_FILE_T;
        }
        else if ( srcPath->objType == DATA_OBJ_T ||
                  srcPath->objType == LOCAL_FILE_T ) {
            /* file type source */

            if ( ( destPath->objType == COLL_OBJ_T ||
                    destPath->objType == LOCAL_DIR_T ) &&
                    destPath->objState == EXIST_ST ) {
                if ( destPath->objType <= COLL_OBJ_T ) {
                    targPath->objType = DATA_OBJ_T;
                }
                else {
                    targPath->objType = LOCAL_FILE_T;
                }

                /* collection */
                getLastPathElement( srcPath->inPath, srcElement );
                if ( strlen( srcElement ) > 0 ) {
                    snprintf( targPath->outPath, MAX_NAME_LEN, "%s/%s",
                              destPath->outPath, srcElement );
                    if ( destPath->objType <= COLL_OBJ_T ) {
                        getRodsObjType( conn, destPath );
                    }
                }
                else {
                    rstrcpy( targPath->outPath, destPath->outPath,
                             MAX_NAME_LEN );
                }
            }
            else if ( destPath->objType == DATA_OBJ_T ||
                      destPath->objType == LOCAL_FILE_T || rodsPathInp->numSrc == 1 ) {
                *targPath = *destPath;
                if ( destPath->objType <= COLL_OBJ_T ) {
                    targPath->objType = DATA_OBJ_T;
                }
                else {
                    targPath->objType = LOCAL_FILE_T;
                }
            }
            else {
                rodsLogError( LOG_ERROR, USER_FILE_DOES_NOT_EXIST,
                              "resolveRodsTarget: target %s does not exist",
                              destPath->outPath );
                return ( USER_FILE_DOES_NOT_EXIST );
            }
        }
        else if ( srcPath->objType == COLL_OBJ_T ||
                  srcPath->objType == LOCAL_DIR_T ) {
            /* directory type source */

            if ( destPath->objType <= COLL_OBJ_T ) {
                targPath->objType = COLL_OBJ_T;
            }
            else {
                targPath->objType = LOCAL_DIR_T;
            }

            if ( destPath->objType == DATA_OBJ_T ||
                    destPath->objType == LOCAL_FILE_T ) {
                rodsLog( LOG_ERROR,
                         "resolveRodsTarget: input destPath %s is a datapath",
                         destPath->outPath );
                return ( USER_INPUT_PATH_ERR );
            }
            else if ( ( destPath->objType == COLL_OBJ_T ||
                        destPath->objType == LOCAL_DIR_T ) &&
                      destPath->objState == EXIST_ST ) {
                /* the collection exist */
                getLastPathElement( srcPath->inPath, srcElement );
                if ( strlen( srcElement ) > 0 ) {
                    if ( rodsPathInp->numSrc == 1 && oprType == RSYNC_OPR ) {
                        getLastPathElement( destPath->inPath, destElement );
                        /* RSYNC_OPR. Just use the same path */
                        if ( strlen( destElement ) > 0 ) {
                            rstrcpy( targPath->outPath, destPath->outPath,
                                     MAX_NAME_LEN );
                        }
                    }
                    if ( targPath->outPath[0] == '\0' ) {
                        snprintf( targPath->outPath, MAX_NAME_LEN, "%s/%s",
                                  destPath->outPath, srcElement );
                        /* make the collection */
                        if ( destPath->objType == COLL_OBJ_T ) {
                            if ( oprType != MOVE_OPR ) {
                                /* rename does not need to mkColl */
                                if ( srcPath->objType <= COLL_OBJ_T ) {
                                    status = mkCollWithSrcCollMeta( conn, destPath->outPath, srcPath->outPath );
                                }
                                else {
                                    status = mkCollWithDirMeta( conn, targPath->outPath, srcPath->inPath );
                                }
                            }
                            else {
                                status = 0;
                            }
                        }
                        else {
#ifdef windows_platform
                            status = iRODSNt_mkdir( targPath->outPath, 0750 );
#else
                            status = mkdir( targPath->outPath, 0750 );
#endif
                            if ( status < 0 && errno == EEXIST ) {
                                status = 0;
                            }
                        }
                        if ( status < 0 ) {
                            rodsLogError( LOG_ERROR, status,
                                          "resolveRodsTarget: mkColl/mkdir for %s,status=%d",
                                          targPath->outPath, status );
                            return ( status );
                        }
                    }
                }
                else {
                    rstrcpy( targPath->outPath, destPath->outPath,
                             MAX_NAME_LEN );
                }
            }
            else {
                /* dest coll does not exist */
                if ( destPath->objType <= COLL_OBJ_T ) {
                    if ( oprType != MOVE_OPR ) {
                        /* rename does not need to mkColl */
                        if ( srcPath->objType <= COLL_OBJ_T ) {
                            status = mkCollWithSrcCollMeta( conn, destPath->outPath, srcPath->outPath );
                        }
                        else {
                            status = mkCollWithDirMeta( conn, destPath->outPath, srcPath->inPath );
                        }
                    }
                    else {
                        status = 0;
                    }
                }
                else {
                    /* use destPath. targPath->outPath not defined.
                     *  status = mkdir (targPath->outPath, 0750); */
#ifdef windows_platform
                    status = iRODSNt_mkdir( destPath->outPath, 0750 );
#else
                    status = mkdir( destPath->outPath, 0750 );
#endif
                }
                if ( status < 0 ) {
                    return ( status );
                }

                if ( rodsPathInp->numSrc == 1 ) {
                    rstrcpy( targPath->outPath, destPath->outPath,
                             MAX_NAME_LEN );
                }
                else {
                    rodsLogError( LOG_ERROR, USER_FILE_DOES_NOT_EXIST,
                                  "resolveRodsTarget: target %s does not exist",
                                  destPath->outPath );
                    return ( USER_FILE_DOES_NOT_EXIST );
                }
            }
            targPath->objState = EXIST_ST;
        }
        else {          /* should not be here */
            if ( srcPath->objState == NOT_EXIST_ST ) {
                rodsLog( LOG_ERROR,
                         "resolveRodsTarget: source %s does not exist",
                         srcPath->outPath );
            }
            else {
                rodsLog( LOG_ERROR,
                         "resolveRodsTarget: cannot handle objType %d for srcPath %s",
                         srcPath->objType, srcPath->outPath );
            }
            return ( USER_INPUT_PATH_ERR );
        }
    }
    return ( 0 );
}
Ejemplo n.º 25
0
int
rsNcGetVarsByTypeForColl (rsComm_t *rsComm, ncGetVarInp_t *ncGetVarInp,
ncGetVarOut_t **ncGetVarOut)
{
    int i, j, status;
    int l1descInx;
    openedAggInfo_t *openedAggInfo;
    ncInqInp_t ncInqInp;
    ncGetVarInp_t myNcGetVarInp;
    rodsLong_t timeStart0, timeEnd0, curPos; 
    rodsLong_t eleStart, eleEnd; 
    int timeInxInVar0; 
    rodsLong_t start[NC_MAX_DIMS], stride[NC_MAX_DIMS], count[NC_MAX_DIMS];
    char *buf, *bufPos;
    int len, eleLen, curLen;
    ncGetVarOut_t *myNcGetVarOut = NULL;
    char dataType_PI[NAME_LEN];
    int dataTypeSize;

    *ncGetVarOut = NULL;
    *dataType_PI = '\0';
    l1descInx = ncGetVarInp->ncid;
    openedAggInfo = &L1desc[l1descInx].openedAggInfo;
    if (openedAggInfo->objNcid0 == -1) {
        return NETCDF_AGG_ELE_FILE_NOT_OPENED;
    }
    if (openedAggInfo->ncInqOut0 == NULL) {
        bzero (&ncInqInp, sizeof (ncInqInp));
        ncInqInp.ncid = openedAggInfo->objNcid0;
        ncInqInp.paramType = NC_ALL_TYPE;
        ncInqInp.flags = NC_ALL_FLAG;
        status = rsNcInqDataObj (rsComm, &ncInqInp, &openedAggInfo->ncInqOut0);
        if (status < 0) {
            rodsLogError (LOG_ERROR, status,
              "rsNcGetVarsByTypeForColl: rsNcInqDataObj for %s error",
              openedAggInfo->ncAggInfo->ncObjectName);
            return status;
        }
    }
    timeInxInVar0 = getTimeInxInVar (openedAggInfo->ncInqOut0, 
      ncGetVarInp->varid);

    if (timeInxInVar0 < 0) {
        /* no time dim */
        timeStart0 = curPos = timeEnd0 = 0;
    } else if (timeInxInVar0 >= ncGetVarInp->ndim) {
        rodsLog (LOG_ERROR, 
          "rsNcGetVarsByTypeForColl: timeInxInVar0 %d >= ndim %d",
          timeInxInVar0, ncGetVarInp->ndim);
        return NETCDF_DIM_MISMATCH_ERR;
    } else {
        timeStart0 = curPos = ncGetVarInp->start[timeInxInVar0];
        timeEnd0 = timeStart0 + ncGetVarInp->count[timeInxInVar0] - 1;
    }
    eleStart = 0;
    myNcGetVarInp = *ncGetVarInp;
    bzero (start, sizeof (char) * NC_MAX_DIMS);
    bzero (count, sizeof (char) * NC_MAX_DIMS);
    bzero (stride, sizeof (char) * NC_MAX_DIMS);
    myNcGetVarInp.start = start;
    myNcGetVarInp.count = count;
    myNcGetVarInp.stride = stride;
    for (i = 0; i < ncGetVarInp->ndim; i++) {
         myNcGetVarInp.start[i] = ncGetVarInp->start[i];
         myNcGetVarInp.stride[i] = ncGetVarInp->stride[i];
         myNcGetVarInp.count[i] = ncGetVarInp->count[i];
    }
    len = getSizeForGetVars (ncGetVarInp);
    if (len <= 0) return len;
    dataTypeSize = getDataTypeSize (ncGetVarInp->dataType);
    if (dataTypeSize < 0) return dataTypeSize;
    buf = bufPos = (char *) calloc (len, dataTypeSize);
    curLen = 0;
    for (i = 0; i < openedAggInfo->ncAggInfo->numFiles; i++) {
        eleEnd = eleStart + 
          openedAggInfo->ncAggInfo->ncAggElement[i].arraylen - 1;
        if (curPos >= eleStart && curPos <= eleEnd) {
            /* in range */
            if (i != 0 && i != openedAggInfo->aggElemetInx) {
                status = openAggrFile (rsComm, l1descInx, i);
                if (status < 0) {
                    free (buf);
                    return status;
                }
                bzero (&ncInqInp, sizeof (ncInqInp));
                ncInqInp.ncid = openedAggInfo->objNcid;
                ncInqInp.paramType = NC_ALL_TYPE;
                ncInqInp.flags = NC_ALL_FLAG;
                status = rsNcInqDataObj (rsComm, &ncInqInp, 
                  &openedAggInfo->ncInqOut);
                if (status < 0) {
                    rodsLogError (LOG_ERROR, status,
                      "rsNcGetVarsByTypeForColl: rsNcInqDataObj error for %s",
                      openedAggInfo->ncAggInfo->ncObjectName);
                    free (buf);
                    return status;
                }
            }
            if (i != 0) {
                char *varName0 = NULL;
                myNcGetVarInp.ncid =  openedAggInfo->objNcid;
                /* varid can be different than ele 0 */
                for (j = 0; j < openedAggInfo->ncInqOut0->nvars; j++) {
                    if (openedAggInfo->ncInqOut0->var[j].id == 
                      ncGetVarInp->varid) {
                        varName0 = openedAggInfo->ncInqOut0->var[j].name;
                        break;
                    }
                } 
                if (varName0 == NULL) {
                    free (buf);
                    return NETCDF_DEF_VAR_ERR;
                }
                myNcGetVarInp.varid = -1;
                for (j = 0; j < openedAggInfo->ncInqOut0->nvars; j++) {
                    if (strcmp (varName0, 
                      openedAggInfo->ncInqOut0->var[j].name) == 0) {
                        myNcGetVarInp.varid = 
                          openedAggInfo->ncInqOut0->var[j].id;
                        break;
                    }
                }
                if (myNcGetVarInp.varid == -1) {
                    free (buf);
                    return NETCDF_DEF_VAR_ERR;
                }
            } else {
                myNcGetVarInp.ncid =  openedAggInfo->objNcid0;
            }
            /* adjust the start, count */ 
            if (timeInxInVar0 >= 0) {
                myNcGetVarInp.start[timeInxInVar0] = curPos - eleStart;
                if (timeEnd0 >= eleEnd) {
                    myNcGetVarInp.count[timeInxInVar0] = eleEnd - curPos + 1;
                } else {
                    myNcGetVarInp.count[timeInxInVar0] = timeEnd0 - curPos + 1;
                }
                /* adjust curPos. need to take stride into account */
                curPos += myNcGetVarInp.count[timeInxInVar0];
                if (myNcGetVarInp.stride[timeInxInVar0] > 0) { 
                    int mystride = myNcGetVarInp.stride[timeInxInVar0];
                    int remaine = curPos % mystride;
                    if (remaine > 0) {
                        curPos = (curPos / mystride) * (mystride + 1);
                    }
                }
            }
            eleLen = getSizeForGetVars (&myNcGetVarInp);
            status = rsNcGetVarsByTypeForObj (rsComm, &myNcGetVarInp,
             &myNcGetVarOut);
            if (status < 0) {
                rodsLogError (LOG_ERROR, status,
                "rsNcGetVarsByTypeForColl: rsNcGetVarsByTypeForObj %s err",
                  openedAggInfo->ncAggInfo->ncObjectName);
                free (buf);
                return status;
            }
            if (myNcGetVarOut->dataArray->len > 0) {
                curLen += myNcGetVarOut->dataArray->len;
                if (curLen > len) {
                    rodsLog (LOG_ERROR,
                      "rsNcGetVarsByTypeForColl: curLen %d > total len %d",
                      curLen, len);
                    free (buf);
                    return NETCDF_VARS_DATA_TOO_BIG;
                }
                memcpy (bufPos, myNcGetVarOut->dataArray->buf,
                 myNcGetVarOut->dataArray->len * dataTypeSize);
                bufPos += myNcGetVarOut->dataArray->len * dataTypeSize;
                rstrcpy (dataType_PI, myNcGetVarOut->dataType_PI, NAME_LEN);
                freeNcGetVarOut (&myNcGetVarOut);
            }
        }
        if (curPos > timeEnd0) break;
        eleStart = eleEnd + 1;
    }
    if (status >= 0) {
        if (strlen (dataType_PI) == 0) return status;
        *ncGetVarOut = (ncGetVarOut_t *) calloc (1, sizeof (ncGetVarOut_t));
        (*ncGetVarOut)->dataArray = (dataArray_t *) 
          calloc (1, sizeof (dataArray_t));
        rstrcpy ((*ncGetVarOut)->dataType_PI, dataType_PI, NAME_LEN);
        (*ncGetVarOut)->dataArray->len = len;
        (*ncGetVarOut)->dataArray->type = ncGetVarInp->dataType;
        (*ncGetVarOut)->dataArray->buf = buf;
    } else {
        free (buf);
    }
    return status;
}
Ejemplo n.º 26
0
int
parseRodsPath( rodsPath_t *rodsPath, rodsEnv *myRodsEnv ) {
    int len;
    char *tmpPtr1, *tmpPtr2;
    char tmpStr[MAX_NAME_LEN];


    if ( rodsPath == NULL ) {
        fprintf( stderr, "parseRodsPath: NULL rodsPath input\n" );
        return ( USER__NULL_INPUT_ERR );
    }

    rodsPath->objType = UNKNOWN_OBJ_T;
    rodsPath->objState = UNKNOWN_ST;

    if ( rodsPath->inPath == NULL ) {
        fprintf( stderr, "parseRodsPath: NULL rodsPath->inPath input\n" );
        return ( USER__NULL_INPUT_ERR );
    }

    if ( myRodsEnv == NULL && rodsPath->inPath[0] != '/' ) {
        fprintf( stderr, "parseRodsPath: NULL myRodsEnv input\n" );
        return ( USER__NULL_INPUT_ERR );
    }

    len = strlen( rodsPath->inPath );

    if ( len == 0 ) {
        /* just copy rodsCwd */
        rstrcpy( rodsPath->outPath, myRodsEnv->rodsCwd, MAX_NAME_LEN );
        rodsPath->objType = COLL_OBJ_T;
        return ( 0 );
    }
    else if ( strcmp( rodsPath->inPath, "." ) == 0 ||
              strcmp( rodsPath->inPath, "./" ) == 0 ) {
        /* '.' or './' */
        rstrcpy( rodsPath->outPath, myRodsEnv->rodsCwd, MAX_NAME_LEN );
        rodsPath->objType = COLL_OBJ_T;
        return ( 0 );
    }
    else if ( strcmp( rodsPath->inPath, "~" ) == 0 ||
              strcmp( rodsPath->inPath, "~/" ) == 0 ||
              strcmp( rodsPath->inPath, "^" ) == 0 ||
              strcmp( rodsPath->inPath, "^/" ) == 0 ) {
        /* ~ or ~/ */
        rstrcpy( rodsPath->outPath, myRodsEnv->rodsHome, MAX_NAME_LEN );
        rodsPath->objType = COLL_OBJ_T;
        return ( 0 );
    }
    else if ( rodsPath->inPath[0] == '~' || rodsPath->inPath[0] == '^' ) {
        if ( rodsPath->inPath[1] == '/' ) {
            snprintf( rodsPath->outPath, MAX_NAME_LEN, "%s/%s",
                      myRodsEnv->rodsHome, rodsPath->inPath + 2 );
        }
        else {
            /* treat it like a relative path */
            snprintf( rodsPath->outPath, MAX_NAME_LEN, "%s/%s",
                      myRodsEnv->rodsCwd, rodsPath->inPath + 2 );
        }
    }
    else if ( rodsPath->inPath[0] == '/' ) {
        /* full path */
        rstrcpy( rodsPath->outPath, rodsPath->inPath, MAX_NAME_LEN );
    }
    else {
        /* a relative path */
        snprintf( rodsPath->outPath, MAX_NAME_LEN, "%s/%s",
                  myRodsEnv->rodsCwd, rodsPath->inPath );
    }

    /* take out any "//" */

    while ( ( tmpPtr1 = strstr( rodsPath->outPath, "//" ) ) != NULL ) {
        //    rstrcpy (tmpPtr1 + 1, tmpPtr1 + 2, MAX_NAME_LEN);
        rstrcpy( tmpStr, tmpPtr1 + 2, MAX_NAME_LEN );
        rstrcpy( tmpPtr1 + 1, tmpStr, MAX_NAME_LEN );
    }

    /* take out any "/./" */

    while ( ( tmpPtr1 = strstr( rodsPath->outPath, "/./" ) ) != NULL ) {
        //    rstrcpy (tmpPtr1 + 1, tmpPtr1 + 3, MAX_NAME_LEN);
        rstrcpy( tmpStr, tmpPtr1 + 3, MAX_NAME_LEN );
        rstrcpy( tmpPtr1 + 1, tmpStr, MAX_NAME_LEN );
    }

    /* take out any /../ */

    while ( ( tmpPtr1 = strstr( rodsPath->outPath, "/../" ) ) != NULL ) {
        /* go back */
        tmpPtr2 = tmpPtr1 - 1;
        while ( *tmpPtr2 != '/' ) {
            tmpPtr2 --;
            if ( tmpPtr2 < rodsPath->outPath ) {
                rodsLog( LOG_ERROR,
                         "parseRodsPath: parsing error for %s",
                         rodsPath->outPath );
                return ( USER_INPUT_PATH_ERR );
            }
        }
        //    rstrcpy (tmpPtr2 + 1, tmpPtr1 + 4, MAX_NAME_LEN);
        rstrcpy( tmpStr, tmpPtr1 + 4, MAX_NAME_LEN );
        rstrcpy( tmpPtr2 + 1, tmpStr, MAX_NAME_LEN );
    }

    /* handle "/.", "/.." and "/" at the end */

    len = strlen( rodsPath->outPath );

    tmpPtr1 = rodsPath->outPath + len;

    if ( ( tmpPtr2 = strstr( tmpPtr1 - 3, "/.." ) ) != NULL ) {
        /* go back */
        tmpPtr2 -= 1;
        while ( *tmpPtr2 != '/' ) {
            tmpPtr2 --;
            if ( tmpPtr2 < rodsPath->outPath ) {
                rodsLog( LOG_ERROR,
                         "parseRodsPath: parsing error for %s",
                         rodsPath->outPath );
                return ( USER_INPUT_PATH_ERR );
            }
        }
        *tmpPtr2 = '\0';
        if ( tmpPtr2 == rodsPath->outPath ) { /* nothing, special case */
            *tmpPtr2++ = '/'; /* root */
            *tmpPtr2 = '\0';
        }
        rodsPath->objType = COLL_OBJ_T;
        if ( strlen( rodsPath->outPath ) >= MAX_PATH_ALLOWED - 1 ) {
            return ( USER_PATH_EXCEEDS_MAX );
        }
        return ( 0 );
    }

    /* take out "/." */

    if ( ( tmpPtr2 = strstr( tmpPtr1 - 2, "/." ) ) != NULL ) {
        *tmpPtr2 = '\0';
        rodsPath->objType = COLL_OBJ_T;
        if ( strlen( rodsPath->outPath ) >= MAX_PATH_ALLOWED - 1 ) {
            return ( USER_PATH_EXCEEDS_MAX );
        }
        return ( 0 );
    }

    if ( *( tmpPtr1 - 1 ) == '/' && len > 1 ) {
        *( tmpPtr1 - 1 ) = '\0';
        rodsPath->objType = COLL_OBJ_T;
        if ( strlen( rodsPath->outPath ) >= MAX_PATH_ALLOWED - 1 ) {
            return ( USER_PATH_EXCEEDS_MAX );
        }
        return ( 0 );
    }
    if ( strlen( rodsPath->outPath ) >= MAX_PATH_ALLOWED - 1 ) {
        return ( USER_PATH_EXCEEDS_MAX );
    }
    return ( 0 );
}
Ejemplo n.º 27
0
int
main(int argc, char **argv)
{
    rcComm_t *conn;
    rodsEnv myEnv;
    char *optStr;
    rErrMsg_t errMsg;
    int status;
    rodsArguments_t rodsArgs;
    int flag = 0;
    int nativeAPI = 0;

    optStr = "alL";

    status = parseCmdLineOpt (argc, argv, optStr, 1, &rodsArgs);

    if (status < 0) {
        printf("parseCmdLineOpt error, status = %d.\n", status);
        exit (1);
    }

    if (argc - optind <= 0) {
        rodsLog (LOG_ERROR, "no input");
        exit (2);
    }

    memset (&errMsg, 0, sizeof (rErrMsg_t));

    status = getRodsEnv (&myEnv);

    if (status < 0) {
	fprintf (stderr, "getRodsEnv error, status = %d\n", status);
	exit (1);
    }


    conn = rcConnect (myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName,
      myEnv.rodsZone, 1, &errMsg);

    if (conn == NULL) {
        fprintf (stderr, "rcConnect error\n");
        exit (1);
    }

    status = clientLogin(conn);
    if (status != 0) {
        rcDisconnect(conn);
        exit (7);
    }

    flag = setQueryFlag (&rodsArgs);

    if (rodsArgs.all == True) nativeAPI = 1;

    if (nativeAPI == 1) {
	status = printCollectionNat (conn, argv[optind], flag);
    } else {
        status = printCollection (conn, argv[optind], flag);
    }

    rcDisconnect (conn);

    exit (0);
} 
Ejemplo n.º 28
0
int
getNumThreads( rsComm_t *rsComm, rodsLong_t dataSize, int inpNumThr,
               keyValPair_t *condInput, char *destRescHier, char *srcRescHier, int oprType ) {
    ruleExecInfo_t rei;
    dataObjInp_t doinp;
    int status;
    int numDestThr = -1;
    int numSrcThr = -1;


    if ( inpNumThr == NO_THREADING ) {
        return 0;
    }

    if ( dataSize < 0 ) {
        return 0;
    }

    if ( dataSize <= MIN_SZ_FOR_PARA_TRAN ) {
        if ( inpNumThr > 0 ) {
            inpNumThr = 1;
        }
        else {
            return 0;
        }
    }

    if ( getValByKey( condInput, NO_PARA_OP_KW ) != NULL ) {
        /* client specify no para opr */
        return 1;
    }

    memset( &doinp, 0, sizeof( doinp ) );
    doinp.numThreads = inpNumThr;

    doinp.dataSize = dataSize;
    doinp.oprType = oprType;

    initReiWithDataObjInp( &rei, rsComm, &doinp );

    if (destRescHier && strlen(destRescHier)) {

        // get resource (hierarchy) location
        std::string location;
        irods::error ret = irods::get_loc_for_hier_string( destRescHier, location );
        if ( !ret.ok() ) {
            irods::log( PASSMSG( "getNumThreads - failed in get_loc_for_hier_string", ret ) );
            return -1;
        }

        irods::hierarchy_parser parser;
        parser.set_string( destRescHier );

        std::string last_resc;
        parser.last_resc( last_resc );

        irods::error err = irods::is_resc_live( last_resc.c_str() );
        if ( err.ok() ) {
            status = applyRule( "acSetNumThreads", NULL, &rei, NO_SAVE_REI );

            if ( status < 0 ) {
                rodsLog( LOG_ERROR,
                         "getNumThreads: acGetNumThreads error, status = %d",
                         status );
            }
            else {
                numDestThr = rei.status;
                if ( numDestThr == 0 ) {
                    return 0;
                }
                else if ( numDestThr == 1 && srcRescHier == NULL &&
                          isLocalHost( location.c_str() ) ) {
                    /* one thread and resource on local host */
                    return 0;
                }
            }
        }
    }

    if (destRescHier && strlen(destRescHier) && srcRescHier && strlen(srcRescHier)) {
        if ( numDestThr > 0 && strcmp( destRescHier, srcRescHier ) == 0 ) {
            return numDestThr;
        }

        // get resource (hierarchy) location
        std::string location;
        irods::error ret = irods::get_loc_for_hier_string( destRescHier, location );
        if ( !ret.ok() ) {
            irods::log( PASSMSG( "getNumThreads - failed in get_loc_for_hier_string", ret ) );
            return -1;
        }

        irods::hierarchy_parser parser;
        parser.set_string( srcRescHier );

        std::string last_resc;
        parser.last_resc( last_resc );

        irods::error err = irods::is_resc_live( last_resc.c_str() );

        if ( err.ok() ) {
            status = applyRule( "acSetNumThreads", NULL, &rei, NO_SAVE_REI );
            if ( status < 0 ) {
                rodsLog( LOG_ERROR,
                         "getNumThreads: acGetNumThreads error, status = %d",
                         status );
            }
            else {
                numSrcThr = rei.status;
                if ( numSrcThr == 0 ) {
                    return 0;
                }
            }
        }
    }

    if ( numDestThr > 0 ) {
        if ( getValByKey( condInput, RBUDP_TRANSFER_KW ) != NULL ) {
            return 1;
        }
        else {
            return numDestThr;
        }
    }
    if ( numSrcThr > 0 ) {
        if ( getValByKey( condInput, RBUDP_TRANSFER_KW ) != NULL ) {
            return 1;
        }
        else {
            return numSrcThr;
        }
    }
    /* should not be here. do one with no resource */
    status = applyRule( "acSetNumThreads", NULL, &rei, NO_SAVE_REI );
    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "getNumThreads: acGetNumThreads error, status = %d",
                 status );
        return 0;
    }
    else {
        if ( rei.status > 0 ) {
            return rei.status;
        }
        else {
            return 0;
        }
    }
}
Ejemplo n.º 29
0
int _iFuseFileCacheFlush( fileCache_t *fileCache ) {
    int status = 0;
    int objFd;
    /* simply return if no file cache or the file cache hasn't been updated */
    if ( fileCache->state != HAVE_NEWLY_CREATED_CACHE ) {
        //UNLOCK_STRUCT( *fileCache );
        return 0;
    }

    /* no need to flush cache file as we are using low-level io */
    /*status = fsync (fileCache->iFd);
    if (status < 0) {
    	status = (errno ? (-1 * errno) : -1);
    	rodsLog (LOG_ERROR,
    			"ifuseFlush: flush of cache file for %s error, status = %d",
    			fileCache->localPath, status);
    	return -EBADF;
    }*/

    struct stat stbuf;
    int error_code = stat( fileCache->fileCachePath, &stbuf );
    if ( error_code != 0 ) {
        rodsLog( LOG_ERROR, "stat failed in _iFuseFileCacheFlush with status %d", error_code );
    }
    /* put cache file to server */
    //UNLOCK_STRUCT( *fileCache );
    iFuseConn_t *conn = getAndUseConnByPath( fileCache->localPath, &status );
    //LOCK_STRUCT( *fileCache );

    RECONNECT_IF_NECESSARY( status, conn, ifusePut( conn->conn, fileCache->objPath, fileCache->fileCachePath, fileCache->mode, stbuf.st_size ) );
    unuseIFuseConn( conn );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "ifuseClose: ifusePut of %s error, status = %d",
                 fileCache->localPath, status );
        status = -EBADF;
        return status;
    }

    objFd = status;

    if ( stbuf.st_size > MAX_READ_CACHE_SIZE ) {
        /* too big to keep */
        /* close cache file */
        status = close( fileCache->iFd );
        if ( status < 0 ) {
            status = ( errno ? ( -1 * errno ) : -1 );
            rodsLog( LOG_ERROR,
                     "ifuseClose: close of cache file for %s error, status = %d",
                     fileCache->localPath, status );
            return -EBADF;
        }
        fileCache->iFd = objFd;
        fileCache->state = NO_FILE_CACHE;
        fileCache->offset = 0;
        status = objFd;
    }
    else {
        fileCache->state = HAVE_READ_CACHE;
    }

    return status;
}
Ejemplo n.º 30
0
/**
 * \fn msiGetMoreRows(msParam_t *genQueryInp_msp, msParam_t *genQueryOut_msp, msParam_t *continueInx, ruleExecInfo_t *rei)
 *
 * \brief This microservice continues an unfinished query.
 *
 * \module core
 *
 * \since pre-2.1
 *
 *
 * \note This microservice gets the next batch of rows for an open iCAT query. Likely to follow #msiMakeGenQuery and #msiExecGenQuery.
 *
 * \usage None
 *
 * \param[in] genQueryInp_msp - Required - a GenQueryInp_MS_T containing the query parameters and conditions.
 * \param[in] genQueryOut_msp - Required - a GenQueryOut_MS_T to write results to. If its continuation index is 0 the query will be closed.
 * \param[out] continueInx - a INT_MS_T containing the new continuation index (after the query).
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
**/
int
msiGetMoreRows( msParam_t *genQueryInp_msp, msParam_t *genQueryOut_msp, msParam_t *continueInx, ruleExecInfo_t *rei ) {
    genQueryInp_t *genQueryInp;
    genQueryOut_t *genQueryOut;


    RE_TEST_MACRO( "    Calling msiGetMoreRows" )

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


    /* check for non null parameters */
    if ( !genQueryInp_msp || !genQueryOut_msp ) {
        rodsLog( LOG_ERROR, "msiGetMoreRows: Missing parameter(s)" );
        return USER__NULL_INPUT_ERR;
    }


    /* check for proper input types */
    if ( strcmp( genQueryOut_msp->type, GenQueryOut_MS_T ) ) {
        rodsLog( LOG_ERROR, "msiGetMoreRows: genQueryOut_msp type is %s, should be GenQueryOut_MS_T", genQueryOut_msp->type );
        return USER_PARAM_TYPE_ERR;
    }

    if ( strcmp( genQueryInp_msp->type, GenQueryInp_MS_T ) ) {
        rodsLog( LOG_ERROR, "msiGetMoreRows: query_msp type is %s, should be GenQueryInp_MS_T", genQueryInp_msp->type );
        return USER_PARAM_TYPE_ERR;
    }


    /* retrieve genQueryXXX data structures */
    genQueryOut = ( genQueryOut_t* )genQueryOut_msp->inOutStruct;
    genQueryInp = ( genQueryInp_t* )genQueryInp_msp->inOutStruct;


    /* match continuation indexes */
    genQueryInp->continueInx = genQueryOut->continueInx;

    if ( genQueryInp->continueInx > 0 ) {
        /* get the next batch */
        genQueryInp->maxRows = MAX_SQL_ROWS;
    }
    else {
        /* close query */
        genQueryInp->maxRows = -1;
    }


    /* free memory allocated for previous results */
    freeGenQueryOut( &genQueryOut );


    /* query */
    rei->status = rsGenQuery( rei->rsComm, genQueryInp, &genQueryOut );


    if ( rei->status == 0 ) {
        /* return query results */
        genQueryOut_msp->inOutStruct = genQueryOut;

        /* return continuation index separately in case it is needed in conditional expressions */
        resetMsParam( continueInx );
        fillIntInMsParam( continueInx, genQueryOut->continueInx );
    }

    return rei->status;
}