Exemplo n.º 1
0
int
branchReadAndProcApiReply( rcComm_t *conn, int apiNumber,
                           void **outStruct, bytesBuf_t *outBsBBuf ) {
    int status = 0;
    int apiInx = 0;

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

    apiInx = apiTableLookup( apiNumber );
    if ( apiInx < 0 ) {
        rodsLog( LOG_ERROR,
                 "branchReadAndProcApiReply: apiTableLookup of apiNum %d failed",
                 apiNumber );
        return ( apiInx );
    }

    conn->apiInx = apiInx;

    status = readAndProcApiReply( conn, apiInx, outStruct, outBsBBuf );
    if ( status < 0 ) {
        rodsLogError( LOG_DEBUG, status,
                      "branchReadAndProcApiReply: readAndProcApiReply failed. status = %d",
                      status );
    }
    return ( status );
}
Exemplo n.º 2
0
int
procApiRequest( rcComm_t *conn, int apiNumber, void *inputStruct,
                bytesBuf_t *inputBsBBuf, void **outStruct, bytesBuf_t *outBsBBuf ) {
    int status = 0;
    int apiInx = 0;

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

    freeRError( conn->rError );
    conn->rError = NULL;

    apiInx = apiTableLookup( apiNumber );

    if ( apiInx < 0 ) {
        rodsLog( LOG_ERROR,
                 "procApiRequest: apiTableLookup of apiNumber %d failed", apiNumber );
        return ( apiInx );
    }

    status = sendApiRequest( conn, apiInx, inputStruct, inputBsBBuf );
    if ( status < 0 ) {
        rodsLogError( LOG_DEBUG, status,
                      "procApiRequest: sendApiRequest failed. status = %d", status );
        return ( status );
    }

    conn->apiInx = apiInx;

    status = readAndProcApiReply( conn, apiInx, outStruct, outBsBBuf );
    if ( status < 0 ) {
        rodsLogError( LOG_DEBUG, status,
                      "procApiRequest: readAndProcApiReply failed. status = %d", status );
    }

    return ( status );
}
Exemplo n.º 3
0
int rsApiHandler(
    rsComm_t*   rsComm,
    int         apiNumber,
    bytesBuf_t* inputStructBBuf,
    bytesBuf_t* bsBBuf ) {
    int apiInx;
    int status = 0;
    char *myInStruct = NULL;
    funcPtr myHandler = NULL;
    void *myOutStruct = NULL;
    bytesBuf_t myOutBsBBuf;
    int retVal = 0;
    int numArg = 0;
    void *myArgv[4];
    memset( &myOutBsBBuf, 0, sizeof( bytesBuf_t ) );
    memset( &rsComm->rError, 0, sizeof( rError_t ) );

    apiInx = apiTableLookup( apiNumber );

    // =-=-=-=-=-=-=-
    // create a network object
    irods::network_object_ptr net_obj;
    irods::error ret = irods::network_factory( rsComm, net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return apiInx;
    }

    if ( apiInx < 0 ) {
        rodsLog( LOG_ERROR,
                 "rsApiHandler: apiTableLookup of apiNumber %d failed", apiNumber );
        /* cannot use sendApiReply because it does not know apiInx */
        sendRodsMsg( net_obj, RODS_API_REPLY_T, NULL, NULL, NULL,
                     apiInx, rsComm->irodsProt );
        return apiInx;
    }

    rsComm->apiInx = apiInx;

    status = chkApiVersion( apiInx );
    if ( status < 0 ) {
        sendApiReply( rsComm, apiInx, status, myOutStruct, &myOutBsBBuf );
        return status;
    }

    status = chkApiPermission( rsComm, apiInx );
    if ( status < 0 ) {
        rodsLog( LOG_NOTICE,
                 "rsApiHandler: User has no permission for apiNumber %d", apiNumber );
        sendApiReply( rsComm, apiInx, status, myOutStruct, &myOutBsBBuf );
        return status;
    }

    irods::api_entry_table& RsApiTable = irods::get_server_api_table();

    /* some sanity check */
    if ( inputStructBBuf->len > 0 && RsApiTable[apiInx]->inPackInstruct == NULL ) {
        rodsLog( LOG_NOTICE,
                 "rsApiHandler: input struct error 1 for apiNumber %d", apiNumber );
        sendApiReply( rsComm, apiInx, SYS_API_INPUT_ERR, myOutStruct,
                      &myOutBsBBuf );
        return SYS_API_INPUT_ERR;
    }

    if ( inputStructBBuf->len <= 0 && RsApiTable[apiInx]->inPackInstruct != NULL ) {
        rodsLog( LOG_NOTICE,
                 "rsApiHandler: input struct error 2 for apiNumber %d", apiNumber );
        sendApiReply( rsComm, apiInx, SYS_API_INPUT_ERR, myOutStruct,
                      &myOutBsBBuf );
        return SYS_API_INPUT_ERR;
    }

    if ( bsBBuf->len > 0 && RsApiTable[apiInx]->inBsFlag <= 0 ) {
        rodsLog( LOG_NOTICE,
                 "rsApiHandler: input byte stream error for apiNumber %d", apiNumber );
        sendApiReply( rsComm, apiInx, SYS_API_INPUT_ERR, myOutStruct,
                      &myOutBsBBuf );
        return SYS_API_INPUT_ERR;
    }

    if ( inputStructBBuf->len > 0 ) {
        status = unpackStruct( inputStructBBuf->buf, ( void ** )( static_cast< void * >( &myInStruct ) ),
                               ( char* )RsApiTable[apiInx]->inPackInstruct, RodsPackTable, rsComm->irodsProt );
        if ( status < 0 ) {
            rodsLog( LOG_NOTICE,
                     "rsApiHandler: unpackStruct error for apiNumber %d, status = %d",
                     apiNumber, status );
            sendApiReply( rsComm, apiInx, status, myOutStruct,
                          &myOutBsBBuf );
            return status;
        }
    }

    /* ready to call the handler functions */

    myHandler = RsApiTable[apiInx]->svrHandler;
    if ( !myHandler ) {
        rodsLog( LOG_ERROR, "Null handler encountered for api number %d in rsApiHandler.", apiNumber );
        return SYS_API_INPUT_ERR;
    }

    if ( RsApiTable[apiInx]->inPackInstruct != NULL ) {
        myArgv[numArg] = myInStruct;
        numArg++;
    };

    if ( RsApiTable[apiInx]->inBsFlag != 0 ) {
        myArgv[numArg] = bsBBuf;
        numArg++;
    };

    if ( RsApiTable[apiInx]->outPackInstruct != NULL ) {
        myArgv[numArg] = ( void * ) &myOutStruct;
        numArg++;
    };

    if ( RsApiTable[apiInx]->outBsFlag != 0 ) {
        myArgv[numArg] = ( void * ) &myOutBsBBuf;
        numArg++;
    };

    if ( numArg == 0 ) {
        retVal = ( *myHandler )( rsComm );
    }
    else if ( numArg == 1 ) {
        retVal = ( *myHandler )( rsComm, myArgv[0] );
    }
    else if ( numArg == 2 ) {
        retVal = ( *myHandler )( rsComm, myArgv[0], myArgv[1] );
    }
    else if ( numArg == 3 ) {
        retVal = ( *myHandler )( rsComm, myArgv[0], myArgv[1], myArgv[2] );
    }
    else if ( numArg == 4 ) {
        retVal = ( *myHandler )( rsComm, myArgv[0], myArgv[1], myArgv[2],
                                 myArgv[3] );
    }

    if ( retVal != SYS_NO_HANDLER_REPLY_MSG ) {
        status = sendAndProcApiReply
                 ( rsComm, apiInx, retVal, myOutStruct, &myOutBsBBuf );
    }

    // =-=-=-=-=-=-=-
    // clear the incoming packing instruction
    if ( myInStruct != NULL ) {
        if ( RsApiTable[apiInx]->clearInStruct ) {
            RsApiTable[apiInx]->clearInStruct( myInStruct );
        }

        free( myInStruct );
        myInStruct = NULL;
    }

    if ( retVal >= 0 && status < 0 ) {
        return status;
    }
    else {
        return retVal;
    }
}