/** * \fn rcExecMyRule( rcComm_t *conn, execMyRuleInp_t *execMyRuleInp, msParamArray_t **outParamArray ) * * \brief Execute my rule. * * \user client * * \ingroup rules * * \since 1.0 * * * \remark none * * \note none * * \param[in] conn - A rcComm_t connection handle to the server. * \param[in] execMyRuleInp * \param[out] outParamArray * * \return integer * \retval 0 on success. * \sideeffect none * \pre none * \post none * \sa none **/ int rcExecMyRule( rcComm_t *conn, execMyRuleInp_t *execMyRuleInp, msParamArray_t **outParamArray ) { int status = procApiRequest( conn, EXEC_MY_RULE_AN, execMyRuleInp, NULL, ( void ** )outParamArray, NULL ); while ( status == SYS_SVR_TO_CLI_MSI_REQUEST ) { /* it is a server request */ msParam_t *myParam = NULL, *putParam = NULL; if ( ( myParam = putParam = getMsParamByLabel( *outParamArray, CL_PUT_ACTION ) ) || ( myParam = getMsParamByLabel( *outParamArray, CL_GET_ACTION ) ) ) { //putParam is non-null if it's a put, null if it's a get dataObjInp_t * dataObjInp = ( dataObjInp_t * ) myParam->inOutStruct; char * locFilePath; char myDir[MAX_NAME_LEN], myFile[MAX_NAME_LEN]; // locFilePath should be the return of getValByKey if it exists, // otherwise use the filename from splitPathByKey if ( ( locFilePath = getValByKey( &dataObjInp->condInput, LOCAL_PATH_KW ) ) || ( ( status = splitPathByKey( dataObjInp->objPath, myDir, MAX_NAME_LEN, myFile, MAX_NAME_LEN, '/' ) ) >= 0 && ( locFilePath = ( char * ) myFile ) ) ) { status = putParam ? rcDataObjPut( conn, dataObjInp, locFilePath ) : rcDataObjGet( conn, dataObjInp, locFilePath ); rcOprComplete( conn, status ); } else { rodsLogError( LOG_ERROR, status, "rcExecMyRule: splitPathByKey for %s error", dataObjInp->objPath ); rcOprComplete( conn, USER_FILE_DOES_NOT_EXIST ); } clearKeyVal( &dataObjInp->condInput ); } else { rcOprComplete( conn, SYS_SVR_TO_CLI_MSI_NO_EXIST ); } /* free outParamArray */ clearMsParamArray( *outParamArray, 1 ); free( *outParamArray ); *outParamArray = NULL; /* read the reply from the earlier call */ status = branchReadAndProcApiReply( conn, EXEC_MY_RULE_AN, ( void ** )outParamArray, NULL ); if ( status < 0 ) { rodsLogError( LOG_DEBUG, status, "rcExecMyRule: readAndProcApiReply failed. status = %d", status ); } } return status; }
int rcDataObjGet( rcComm_t *conn, dataObjInp_t *dataObjInp, char *locFilePath ) { int status; portalOprOut_t *portalOprOut = NULL; bytesBuf_t dataObjOutBBuf; #ifndef windows_platform struct stat statbuf; #else struct irodsntstat statbuf; #endif if ( strcmp( locFilePath, STDOUT_FILE_NAME ) == 0 ) { /* no parallel I/O if pipe to stdout */ dataObjInp->numThreads = NO_THREADING; } #ifndef windows_platform else if ( stat( locFilePath, &statbuf ) >= 0 ) #else else if ( iRODSNt_stat( locFilePath, &statbuf ) >= 0 ) #endif { /* local file exists */ if ( getValByKey( &dataObjInp->condInput, FORCE_FLAG_KW ) == NULL ) { return ( OVERWRITE_WITHOUT_FORCE_FLAG ); } } status = _rcDataObjGet( conn, dataObjInp, &portalOprOut, &dataObjOutBBuf ); if ( status < 0 ) { if ( portalOprOut != NULL ) { free( portalOprOut ); } return ( status ); } if ( status == 0 || dataObjOutBBuf.len > 0 ) { /* data included */ /**** Removed by Raja as this can cause problems when the data sizes are different - say when post processing is done....Dec 2 2010 if (dataObjInp->dataSize > 0 && dataObjInp->dataSize != dataObjOutBBuf.len) { rodsLog (LOG_NOTICE, "putFile: totalWritten %lld dataSize %lld mismatch", dataObjOutBBuf.len, dataObjInp->dataSize); return (SYS_COPY_LEN_ERR); } ****/ status = getIncludeFile( conn, &dataObjOutBBuf, locFilePath ); free( dataObjOutBBuf.buf ); } else if ( getUdpPortFromPortList( &portalOprOut->portList ) != 0 ) { int veryVerbose; /* rbudp transfer */ /* some sanity check */ if ( portalOprOut->numThreads != 1 ) { rcOprComplete( conn, SYS_INVALID_PORTAL_OPR ); free( portalOprOut ); return ( SYS_INVALID_PORTAL_OPR ); } conn->transStat.numThreads = portalOprOut->numThreads; if ( getValByKey( &dataObjInp->condInput, VERY_VERBOSE_KW ) != NULL ) { printf( "From server: NumThreads=%d, addr:%s, port:%d, cookie=%d\n", portalOprOut->numThreads, portalOprOut->portList.hostAddr, portalOprOut->portList.portNum, portalOprOut->portList.cookie ); veryVerbose = 2; } else { veryVerbose = 0; } // =-=-=-=-=-=-=- // if a secret has been negotiated then we must be using // encryption. given that RBUDP is not supported in an // encrypted capacity this is considered an error if ( irods::CS_NEG_USE_SSL == conn->negotiation_results ) { rodsLog( LOG_ERROR, "getFileToPortal: Encryption is not supported with RBUDP" ); return SYS_INVALID_PORTAL_OPR; } status = getFileToPortalRbudp( portalOprOut, locFilePath, 0, dataObjInp->dataSize, veryVerbose, 0 ); /* just send a complete msg */ if ( status < 0 ) { rcOprComplete( conn, status ); } else { status = rcOprComplete( conn, portalOprOut->l1descInx ); } } else { if ( portalOprOut->numThreads <= 0 ) { status = getFile( conn, portalOprOut->l1descInx, locFilePath, dataObjInp->objPath, dataObjInp->dataSize ); } else { if ( getValByKey( &dataObjInp->condInput, VERY_VERBOSE_KW ) != NULL ) { printf( "From server: NumThreads=%d, addr:%s, port:%d, cookie=%d\n", portalOprOut->numThreads, portalOprOut->portList.hostAddr, portalOprOut->portList.portNum, portalOprOut->portList.cookie ); } /* some sanity check */ if ( portalOprOut->numThreads >= 20 * DEF_NUM_TRAN_THR ) { rcOprComplete( conn, SYS_INVALID_PORTAL_OPR ); free( portalOprOut ); return ( SYS_INVALID_PORTAL_OPR ); } conn->transStat.numThreads = portalOprOut->numThreads; status = getFileFromPortal( conn, portalOprOut, locFilePath, dataObjInp->objPath, dataObjInp->dataSize ); } /* just send a complete msg */ if ( status < 0 ) { rcOprComplete( conn, status ); } else { status = rcOprComplete( conn, portalOprOut->l1descInx ); } } if ( status >= 0 && conn->fileRestart.info.numSeg > 0 ) { /* file restart */ clearLfRestartFile( &conn->fileRestart ); } if ( getValByKey( &dataObjInp->condInput, VERIFY_CHKSUM_KW ) != NULL ) { if ( portalOprOut == NULL || strlen( portalOprOut->chksum ) == 0 ) { rodsLog( LOG_ERROR, "rcDataObjGet: VERIFY_CHKSUM_KW set but no chksum from server" ); } else { status = verifyChksumLocFile( locFilePath, portalOprOut->chksum, NULL ); if ( status == USER_CHKSUM_MISMATCH ) { rodsLogError( LOG_ERROR, status, "rcDataObjGet: chksum mismatch error for %s, status = %d", locFilePath, status ); if ( portalOprOut != NULL ) { free( portalOprOut ); } return ( status ); } else if ( status < 0 ) { rodsLogError( LOG_ERROR, status, "rcDataObjGet: chksumLocFile error for %s, status = %d", locFilePath, status ); if ( portalOprOut != NULL ) { free( portalOprOut ); } return ( status ); } } } if ( portalOprOut != NULL ) { free( portalOprOut ); } return ( status ); }
int rcDataObjRsync (rcComm_t *conn, dataObjInp_t *dataObjInp) { int status; msParamArray_t *outParamArray = NULL; char *locFilePath; status = _rcDataObjRsync (conn, dataObjInp, &outParamArray); if (status == SYS_SVR_TO_CLI_PUT_ACTION) { if ((locFilePath = getValByKey (&dataObjInp->condInput, RSYNC_DEST_PATH_KW)) == NULL) { return USER_INPUT_PATH_ERR; } else { status = rcDataObjPut (conn, dataObjInp, locFilePath); if (status >= 0) { return SYS_RSYNC_TARGET_MODIFIED; } else { return status; } } } else if (status == SYS_SVR_TO_CLI_GET_ACTION) { if ((locFilePath = getValByKey (&dataObjInp->condInput, RSYNC_DEST_PATH_KW)) == NULL) { return USER_INPUT_PATH_ERR; } else { status = rcDataObjGet (conn, dataObjInp, locFilePath); if (status >= 0) { return SYS_RSYNC_TARGET_MODIFIED; } else { return status; } } } /* below is for backward compatibility */ while (status == SYS_SVR_TO_CLI_MSI_REQUEST) { /* it is a server request */ msParam_t *myMsParam; dataObjInp_t *dataObjInp = NULL; int l1descInx; myMsParam = getMsParamByLabel (outParamArray, CL_ZONE_OPR_INX); if (myMsParam == NULL) { l1descInx = -1; } else { l1descInx = *(int*) myMsParam->inOutStruct; } if ((myMsParam = getMsParamByLabel (outParamArray, CL_PUT_ACTION)) != NULL) { dataObjInp = (dataObjInp_t *) myMsParam->inOutStruct; if ((locFilePath = getValByKey (&dataObjInp->condInput, RSYNC_DEST_PATH_KW)) == NULL) { if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, USER_FILE_DOES_NOT_EXIST); } } else { status = rcDataObjPut (conn, dataObjInp, locFilePath); if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, status); } } } else if ((myMsParam = getMsParamByLabel (outParamArray, CL_GET_ACTION)) != NULL) { dataObjInp = (dataObjInp_t *) myMsParam->inOutStruct; if ((locFilePath = getValByKey (&dataObjInp->condInput, RSYNC_DEST_PATH_KW)) == NULL) { if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, USER_FILE_DOES_NOT_EXIST); } } else { status = rcDataObjGet (conn, dataObjInp, locFilePath); if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, status); } } } else { if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, SYS_SVR_TO_CLI_MSI_NO_EXIST); } } /* free outParamArray */ if (dataObjInp != NULL) { clearKeyVal (&dataObjInp->condInput); } clearMsParamArray (outParamArray, 1); free (outParamArray); /* read the reply from the eariler call */ status = branchReadAndProcApiReply (conn, DATA_OBJ_RSYNC_AN, (void **)&outParamArray, NULL); if (status < 0) { rodsLogError (LOG_DEBUG, status, "rcDataObjRsync: readAndProcApiReply failed. status = %d", status); } } return (status); }
int rcDataObjPut( rcComm_t *conn, dataObjInp_t *dataObjInp, char *locFilePath ) { int status; portalOprOut_t *portalOprOut = NULL; bytesBuf_t dataObjInpBBuf; if ( dataObjInp->dataSize <= 0 ) { dataObjInp->dataSize = getFileSize( locFilePath ); if ( dataObjInp->dataSize < 0 ) { return USER_FILE_DOES_NOT_EXIST; } } memset( &conn->transStat, 0, sizeof( transStat_t ) ); memset( &dataObjInpBBuf, 0, sizeof( dataObjInpBBuf ) ); rodsEnv env; getRodsEnv( &env ); int single_buff_sz = env.irodsMaxSizeForSingleBuffer * 1024 * 1024; if ( getValByKey( &dataObjInp->condInput, DATA_INCLUDED_KW ) != NULL ) { if ( dataObjInp->dataSize > single_buff_sz ) { rmKeyVal( &dataObjInp->condInput, DATA_INCLUDED_KW ); } else { status = fillBBufWithFile( conn, &dataObjInpBBuf, locFilePath, dataObjInp->dataSize ); if ( status < 0 ) { rodsLog( LOG_NOTICE, "rcDataObjPut: fileBBufWithFile error for %s", locFilePath ); return status; } } } else if ( dataObjInp->dataSize < single_buff_sz ) { addKeyVal( &dataObjInp->condInput, DATA_INCLUDED_KW, "" ); status = fillBBufWithFile( conn, &dataObjInpBBuf, locFilePath, dataObjInp->dataSize ); if ( status < 0 ) { rodsLog( LOG_NOTICE, "rcDataObjPut: fileBBufWithFile error for %s", locFilePath ); return status; } } dataObjInp->oprType = PUT_OPR; status = _rcDataObjPut( conn, dataObjInp, &dataObjInpBBuf, &portalOprOut ); clearBBuf( &dataObjInpBBuf ); if ( status < 0 || getValByKey( &dataObjInp->condInput, DATA_INCLUDED_KW ) != NULL ) { if ( portalOprOut != NULL ) { free( portalOprOut ); } return status; } if ( portalOprOut->numThreads <= 0 ) { status = putFile( conn, portalOprOut->l1descInx, locFilePath, dataObjInp->objPath, dataObjInp->dataSize ); } else if ( getUdpPortFromPortList( &portalOprOut->portList ) != 0 ) { int veryVerbose; /* rbudp transfer */ /* some sanity check */ if ( portalOprOut->numThreads != 1 ) { rcOprComplete( conn, SYS_INVALID_PORTAL_OPR ); free( portalOprOut ); return SYS_INVALID_PORTAL_OPR; } conn->transStat.numThreads = portalOprOut->numThreads; if ( getValByKey( &dataObjInp->condInput, VERY_VERBOSE_KW ) != NULL ) { printf( "From server: NumThreads=%d, addr:%s, port:%d, cookie=%d\n", portalOprOut->numThreads, portalOprOut->portList.hostAddr, portalOprOut->portList.portNum, portalOprOut->portList.cookie ); veryVerbose = 2; } else { veryVerbose = 0; } if ( irods::CS_NEG_USE_SSL == conn->negotiation_results ) { // =-=-=-=-=-=-=- // if a secret has been negotiated then we must be using // encryption. given that RBUDP is not supported in an // encrypted capacity this is considered an error rodsLog( LOG_ERROR, "putFileToPortal: Encryption is not supported with RBUDP" ); return SYS_INVALID_PORTAL_OPR; } else { status = putFileToPortalRbudp( portalOprOut, locFilePath, -1, veryVerbose, 0, 0 ); } } else { if ( getValByKey( &dataObjInp->condInput, VERY_VERBOSE_KW ) != NULL ) { printf( "From server: NumThreads=%d, addr:%s, port:%d, cookie=%d\n", portalOprOut->numThreads, portalOprOut->portList.hostAddr, portalOprOut->portList.portNum, portalOprOut->portList.cookie ); } /* some sanity check */ rodsEnv env; getRodsEnv( &env ); if ( portalOprOut->numThreads >= 20 * env.irodsDefaultNumberTransferThreads ) { rcOprComplete( conn, SYS_INVALID_PORTAL_OPR ); free( portalOprOut ); return SYS_INVALID_PORTAL_OPR; } conn->transStat.numThreads = portalOprOut->numThreads; status = putFileToPortal( conn, portalOprOut, locFilePath, dataObjInp->objPath, dataObjInp->dataSize ); } /* just send a complete msg */ if ( status < 0 ) { rcOprComplete( conn, status ); } else { status = rcOprComplete( conn, portalOprOut->l1descInx ); } free( portalOprOut ); if ( status >= 0 && conn->fileRestart.info.numSeg > 0 ) { /* file restart */ clearLfRestartFile( &conn->fileRestart ); } return status; }