Пример #1
0
/**
 * \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;
}
Пример #2
0
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);
}