コード例 #1
0
ファイル: reStruct.c プロジェクト: DICE-UNC/iRODS-FUSE-Mod
int
unpackReiAndArg (rsComm_t *rsComm, ruleExecInfoAndArg_t **reiAndArg,
bytesBuf_t *packedReiAndArgBBuf)
{
    int status;
    /*ruleExecInfo_t *myRei;*/

    if (packedReiAndArgBBuf == NULL || reiAndArg == NULL) {
	return (SYS_INTERNAL_NULL_INPUT_ERR);
    }

    /* unpack the reiAndArg */

    status = unpackStruct (packedReiAndArgBBuf->buf, (void **) reiAndArg, 
      "ReiAndArg_PI", RodsPackTable, NATIVE_PROT);

    if (status < 0) {
        rodsLog (LOG_ERROR,
          "unpackReiAndArg: unpackStruct error. status = %d", status);
        return (status);
    }

    /* try to touch up the unpacked rei */

    status = touchupPackedRei (rsComm, (*reiAndArg)->rei);

    return (status);
}
コード例 #2
0
ファイル: reStruct.c プロジェクト: DICE-UNC/iRODS-FUSE-Mod
int
unpackRei (rsComm_t *rsComm, ruleExecInfo_t **rei, 
bytesBuf_t *packedReiBBuf)
{
    int status;

    if (packedReiBBuf == NULL || rei == NULL) {
	return (SYS_INTERNAL_NULL_INPUT_ERR);
    }

    /* unpack the rei */

    /* alway use NATIVE_PROT for rei */
    status = unpackStruct (packedReiBBuf->buf, (void **) rei, 
      "Rei_PI", RodsPackTable, NATIVE_PROT);

    if (status < 0) {
        rodsLog (LOG_ERROR,
          "unpackRei: unpackStruct error. status = %d", status);
        return (status);
    }

    /* try to touch up the unpacked rei */

    status = touchupPackedRei (rsComm, *rei);

    return (status);
}
コード例 #3
0
ファイル: sockComm.cpp プロジェクト: hurngchunlee/irods
// =-=-=-=-=-=-=-
//
irods::error readMsgHeader(
    irods::network_object_ptr _ptr,
    msgHeader_t*               _header,
    struct timeval*            _time_val ) {
    // =-=-=-=-=-=-=-
    // resolve a network interface plugin from the
    // network object
    irods::plugin_ptr p_ptr;
    irods::error ret_err = _ptr->resolve( irods::NETWORK_INTERFACE, p_ptr );
    if ( !ret_err.ok() ) {
        return PASSMSG( "failed to resolve network interface", ret_err );
    }

    // =-=-=-=-=-=-=-
    // make the call to the "read" interface
    char tmp_buf[ MAX_NAME_LEN ];
    irods::first_class_object_ptr ptr = boost::dynamic_pointer_cast< irods::first_class_object >( _ptr );
    irods::network_ptr            net = boost::dynamic_pointer_cast< irods::network >( p_ptr );
    ret_err = net->call< void*, struct timeval* >(
                  irods::NETWORK_OP_READ_HEADER,
                  ptr,
                  tmp_buf,
                  _time_val );

    // =-=-=-=-=-=-=-
    // pass along an error from the interface or return SUCCESS
    if ( !ret_err.ok() ) {
        return PASSMSG( "failed to call 'read header'", ret_err );
    }

    // =-=-=-=-=-=-=-
    // unpack the header message, always use XML_PROT for the header
    msgHeader_t* out_header = 0;
    int status = unpackStruct(
                     static_cast<void*>( tmp_buf ),
                     ( void ** )( static_cast< void * >( &out_header ) ),
                     "MsgHeader_PI",
                     RodsPackTable,
                     XML_PROT );
    if ( status < 0 ) {
        return ERROR( status, "unpackStruct error" );
    }

    if ( !out_header ) {
        return ERROR( -1, "" );
    }

    // =-=-=-=-=-=-=-
    // need to do an assignment due to something potentially going out
    // of scope from unpackStruct.
    // NOTE :: look into why this is necessary
    *_header = *out_header;
    free( out_header );

    // =-=-=-=-=-=-=-
    // win!
    return SUCCESS();

} // readMsgHeader
コード例 #4
0
int
readAggInfo (rsComm_t *rsComm, char *aggColl, keyValPair_t *condInput,
ncAggInfo_t **ncAggInfo)
{
    int status;
    dataObjInp_t dataObjInp;
    bytesBuf_t packedBBuf;
    portalOprOut_t *portalOprOut = NULL;

    bzero (&dataObjInp, sizeof (dataObjInp));
    bzero (&packedBBuf, sizeof (packedBBuf));
    if (condInput != NULL)
        replKeyVal (condInput, &dataObjInp.condInput);
    snprintf (dataObjInp.objPath, MAX_NAME_LEN, "%s/%s",
      aggColl, NC_AGG_INFO_FILE_NAME);
    dataObjInp.oprType = GET_OPR;
    status = rsDataObjGet (rsComm, &dataObjInp, &portalOprOut, &packedBBuf);
    clearKeyVal (&dataObjInp.condInput);
    if (portalOprOut != NULL) free (portalOprOut);
    if (status < 0) {
        if (status == CAT_NO_ROWS_FOUND) status = NETCDF_AGG_INFO_FILE_ERR;
        rodsLogError (LOG_ERROR, status,
          "readAggInfo: rsDataObjGet error for %s", dataObjInp.objPath);
        return status;
    }
    status = unpackStruct (packedBBuf.buf, (void **) ncAggInfo,
      "NcAggInfo_PI", RodsPackTable, XML_PROT);

    if (status < 0) {
        rodsLogError (LOG_ERROR, status,
          "readAggInfo: unpackStruct error for %s", dataObjInp.objPath);
        return NETCDF_AGG_INFO_FILE_ERR;
    }
    if (*ncAggInfo == NULL || (*ncAggInfo)->numFiles == 0) {
        rodsLog (LOG_ERROR,
          "readAggInfo: No ncAggInfo for %s", dataObjInp.objPath);
        return NETCDF_AGG_INFO_FILE_ERR;
    }
    return status;
}
コード例 #5
0
ファイル: rsApiHandler.cpp プロジェクト: hurngchunlee/irods
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;
    }
}
コード例 #6
0
ファイル: sockComm.cpp プロジェクト: hurngchunlee/irods
// =-=-=-=-=-=-=-
//
irods::error readVersion(
    irods::network_object_ptr _ptr,
    version_t**         _version ) {
    // =-=-=-=-=-=-=-
    // init timval struct for header call
    struct timeval tv;
    tv.tv_sec = READ_VERSION_TOUT_SEC;
    tv.tv_usec = 0;

    // =-=-=-=-=-=-=-
    // call interface to read message header
    msgHeader_t myHeader;
    irods::error ret = readMsgHeader( _ptr, &myHeader, &tv );
    if ( !ret.ok() ) {
        return PASS( ret );
    }

    // =-=-=-=-=-=-=-
    // call interface to read message body
    bytesBuf_t inputStructBBuf, bsBBuf, errorBBuf;
    memset( &bsBBuf, 0, sizeof( bytesBuf_t ) );
    ret = readMsgBody( _ptr, &myHeader, &inputStructBBuf, &bsBBuf,
                       &errorBBuf, XML_PROT, NULL );
    if ( !ret.ok() ) {
        return PASS( ret );
    }

    // =-=-=-=-=-=-=-
    // basic error checking of message type
    if ( strcmp( myHeader.type, RODS_VERSION_T ) != 0 ) {
        if ( inputStructBBuf.buf != NULL ) {
            free( inputStructBBuf.buf );
        }
        if ( bsBBuf.buf != NULL ) {
            free( bsBBuf.buf );
        }
        if ( errorBBuf.buf != NULL ) {
            free( errorBBuf.buf );
        }
        std::stringstream msg;
        msg << "wrong msg type ["
            << myHeader.type
            << " expected ["
            << RODS_VERSION_T
            << "]";
        return ERROR( SYS_HEADER_TYPE_LEN_ERR, msg.str() );
    }

    // =-=-=-=-=-=-=-
    // check length of byte stream buffer, should be 0
    if ( myHeader.bsLen != 0 ) {
        if ( bsBBuf.buf != NULL ) {
            free( bsBBuf.buf );
        }
        rodsLog( LOG_NOTICE, "readVersion: myHeader.bsLen = %d is not 0",
                 myHeader.bsLen );
    }

    // =-=-=-=-=-=-=-
    // check length of error buffer, should be 0
    if ( myHeader.errorLen != 0 ) {
        if ( errorBBuf.buf != NULL ) {
            free( errorBBuf.buf );
        }
        rodsLog( LOG_NOTICE, "readVersion: myHeader.errorLen = %d is not 0",
                 myHeader.errorLen );
    }

    // =-=-=-=-=-=-=-
    // bounds check message size
    if ( myHeader.msgLen > ( int ) sizeof( version_t ) * 2 || myHeader.msgLen <= 0 ) {
        if ( inputStructBBuf.buf != NULL ) {
            free( inputStructBBuf.buf );
        }
        std::stringstream msg;
        msg << "header length is not within bounds: "
            << myHeader.msgLen;
        return ERROR( SYS_HEADER_READ_LEN_ERR, msg.str() );
    }

    // =-=-=-=-=-=-=-
    // unpack the message, always use XML for this message type
    int status = unpackStruct(
                     inputStructBBuf.buf,
                     ( void** )( _version ),
                     "Version_PI",
                     RodsPackTable,
                     XML_PROT );
    free( inputStructBBuf.buf );
    if ( status < 0 ) {
        rodsLogError( LOG_NOTICE, status,
                      "readVersion:unpackStruct error. status = %d",
                      status );
    }

    return CODE( status );

} // readVersion
コード例 #7
0
ファイル: sockComm.cpp プロジェクト: hurngchunlee/irods
// =-=-=-=-=-=-=-
//
irods::error readReconMsg(
    irods::network_object_ptr _ptr,
    reconnMsg_t**       _msg ) {
    int status;
    msgHeader_t myHeader;
    bytesBuf_t inputStructBBuf, bsBBuf, errorBBuf;
    // =-=-=-=-=-=-=-
    //
    irods::error ret = readMsgHeader( _ptr, &myHeader, NULL );
    if ( !ret.ok() ) {
        return PASSMSG( "read msg header error", ret );
    }

    memset( &bsBBuf, 0, sizeof( bytesBuf_t ) );
    ret = readMsgBody(
              _ptr,
              &myHeader,
              &inputStructBBuf,
              &bsBBuf,
              &errorBBuf,
              XML_PROT,
              NULL );
    if ( !ret.ok() ) {
        return PASS( ret );
    }

    /* some sanity check */

    if ( strcmp( myHeader.type, RODS_RECONNECT_T ) != 0 ) {
        if ( inputStructBBuf.buf != NULL ) {
            free( inputStructBBuf.buf );
        }
        if ( bsBBuf.buf != NULL ) {
            free( bsBBuf.buf );
        }
        if ( errorBBuf.buf != NULL ) {
            free( errorBBuf.buf );
        }
        std::stringstream msg;
        msg << "wrong msg type ["
            << myHeader.type
            << "] expected ["
            << RODS_CONNECT_T
            << "]";
        return ERROR( SYS_HEADER_TYPE_LEN_ERR, msg.str() );
    }

    if ( myHeader.bsLen != 0 ) {
        if ( bsBBuf.buf != NULL ) {
            free( bsBBuf.buf );
        }
        rodsLog( LOG_NOTICE, "readReconMsg: myHeader.bsLen = %d is not 0",
                 myHeader.bsLen );
    }

    if ( myHeader.errorLen != 0 ) {
        if ( errorBBuf.buf != NULL ) {
            free( errorBBuf.buf );
        }
        rodsLog( LOG_NOTICE,
                 "readReconMsg: myHeader.errorLen = %d is not 0",
                 myHeader.errorLen );
    }

    if ( myHeader.msgLen <= 0 ) {
        if ( inputStructBBuf.buf != NULL ) {
            free( inputStructBBuf.buf );
        }
        rodsLog( LOG_NOTICE,
                 "readReconMsg: problem with myHeader.msgLen = %d",
                 myHeader.msgLen );
        std::stringstream msg;
        msg << "message length is invalid: "
            << myHeader.msgLen;
        return ERROR( SYS_HEADER_READ_LEN_ERR, msg.str() );
    }

    /* always use XML_PROT for the startup pack */
    status = unpackStruct(
                 inputStructBBuf.buf,
                 ( void** )( _msg ),
                 "ReconnMsg_PI",
                 RodsPackTable,
                 XML_PROT );
    clearBBuf( &inputStructBBuf );
    if ( status < 0 ) {
        rodsLogError( LOG_NOTICE,  status,
                      "readReconMsg:unpackStruct error. status = %d",
                      status );
    }

    return CODE( status );
}
コード例 #8
0
ファイル: packtest.c プロジェクト: UPPMAX/irods
int
main(int argc, char **argv)
{
    int status;
    packItem_t *packItemHead = NULL;
    startupPack_t myStartupPack, *outStartupPack;
    rError_t myError, *outError;
    bytesBuf_t *packedResult;
    genQueryOut_t myQueryOut, *outQueryOut;
    char *tmpValue;
    int i;
    modDataObjMeta_t modDataObjMetaInp, *outModDataObjMeta;
    dataObjInfo_t dataObjInfo;
    keyValPair_t regParam;
    authCheckInp_t authCheckInp, *outAuthCheckInp;
    genQueryInp_t genQueryInp, *outGenQueryInp;
    irodsProt_t irodsProt = XML_PROT;

    memset (&genQueryInp, 0, sizeof (genQueryInp));
    addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, "=xyz");
    addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
    genQueryInp.maxRows = 1234567890;
    status = packStruct (&genQueryInp, &packedResult, "GenQueryInp_PI",
      NULL, 0, irodsProt);

    printf ("packStruct GenQueryInp_PI, status = %d\n", status);
    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "queryInp.out");

    status = unpackStruct (packedResult->buf, (void **) &outGenQueryInp,
      "GenQueryInp_PI", NULL, irodsProt);

    printf ("unpackStruct of empty GenQueryInp_PI, status = %d\n", status);


    memset (&authCheckInp, 0, sizeof (authCheckInp));
    status = packStruct (&authCheckInp, &packedResult, "authCheckInp_PI",
      NULL, 0, irodsProt);

    printf ("packStruct of empty authCheckInp_PI, status = %d\n", status);
    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "auth.out");

    status = unpackStruct (packedResult->buf, (void **) &outAuthCheckInp,
      "authCheckInp_PI", NULL, irodsProt);

    printf ("unpackStruct of empty authCheckInp_PI, status = %d\n", status);

    memset (&dataObjInfo, 0, sizeof (dataObjInfo_t));
    memset (&regParam, 0, sizeof (keyValPair_t));

    strcpy (dataObjInfo.objPath, "/tmp/thisIsATest");
    modDataObjMetaInp.dataObjInfo = &dataObjInfo;
    modDataObjMetaInp.regParam = &regParam;

    status = packStruct (&modDataObjMetaInp, &packedResult, "ModDataObjMeta_PI",
      NULL, 0, irodsProt);

    printf ("packStruct of ModDataObjMeta_PI, status = %d\n", status);
    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "modeData.out");

    status = unpackStruct (packedResult->buf, (void **) &outModDataObjMeta, 
      "ModDataObjMeta_PI", NULL, irodsProt);

    printf ("unpackStruct of ModDataObjMeta_PI, status = %d\n", status);
    
    memset (&myQueryOut, 0, sizeof (myQueryOut));
    /* pack and unpack empty struct */

    status = packStruct (&myQueryOut, &packedResult, "GenQueryOut_PI",
      NULL, 0, irodsProt);
    printf ("packStruct empty myQueryOut status = %d\n", status);
    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "genq.out");

    status = unpackStruct (packedResult->buf, (void **) &outQueryOut,
      "GenQueryOut_PI", NULL, irodsProt);

    printf ("unpackStruct empty myQueryOut status = %d\n", status);

    memset (&myQueryOut, 0, sizeof (myQueryOut));
    myQueryOut.rowCnt = 2;
    myQueryOut.attriCnt = 4;

    myQueryOut.sqlResult[0].attriInx = 10;
    myQueryOut.sqlResult[0].len = 20;
    myQueryOut.sqlResult[0].value = tmpValue = (char *) malloc (20*2);
    sprintf (tmpValue, "value 0,1");
    tmpValue += 20;
    sprintf (tmpValue, "value 0,2");

    myQueryOut.sqlResult[1].attriInx = 20;
    myQueryOut.sqlResult[1].len = 30;
    myQueryOut.sqlResult[1].value = tmpValue = (char *) malloc (30*2);
    sprintf (tmpValue, "value 1,1");
    tmpValue += 30;
    sprintf (tmpValue, "value 1,2");

    myQueryOut.sqlResult[2].attriInx = 30;
    myQueryOut.sqlResult[2].len = 40;
    myQueryOut.sqlResult[2].value = tmpValue = (char *) malloc (40*2);
    sprintf (tmpValue, "value 2,1");
    tmpValue += 40;
    sprintf (tmpValue, "value 2,2");

    myQueryOut.sqlResult[3].attriInx = 40;
    myQueryOut.sqlResult[3].len = 50;
    myQueryOut.sqlResult[3].value = tmpValue = (char *) malloc (50*2);
    memset (tmpValue, 0, 50*2);

    status = packStruct (&myQueryOut, &packedResult, "GenQueryOut_PI",
      NULL, 0, irodsProt);
    printf ("packStruct status = %d\n", status);
    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "genq.out"); 

    status = unpackStruct (packedResult->buf, (void **) &outQueryOut,
      "GenQueryOut_PI", NULL, irodsProt);

    printf ("unpackStruct status = %d\n", status);

    status = parsePackInstruct (TEST_PI, &packItemHead);

    printf ("parsePackInstruct status = %d\n", status);

    myStartupPack.connectCnt = 11;
    myStartupPack.irodsProt = XML_PROT;
    strcpy (myStartupPack.proxyUser, "proxyUser"); 
    strcpy (myStartupPack.proxyRodsZone, "proxyRodsZone"); 
    strcpy (myStartupPack.clientUser, "myclientUser"); 
    strcpy (myStartupPack.clientRodsZone, "clientRodsZone"); 
    strcpy (myStartupPack.relVersion, "relVersion"); 
    strcpy (myStartupPack.apiVersion, "apiVersion"); 
    strcpy (myStartupPack.option, "option"); 
    status = packStruct (&myStartupPack, &packedResult, "StartupPack_PI",
      NULL, 0, XML_PROT);
    printf ("packStruct of StartupPack_PI status = %d\n", status);

    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "startup.out"); 
    status = unpackStruct (packedResult->buf, (void **) &outStartupPack, 
      "StartupPack_PI", NULL, irodsProt);
    printf ("unpackStruct of StartupPack_PI status = %d\n", status);

    myError.len = 3;

    myError.errMsg = (rErrMsg_t **) malloc (sizeof (void *) * 3);
    for (i = 0; i < 3; i++) {
	myError.errMsg[i] = (rErrMsg_t *) malloc (sizeof (rErrMsg_t));  
	sprintf (myError.errMsg[i]->msg, "error %d\n", i);
	myError.errMsg[i]->status = i;
    }

    status = packStruct (&myError, &packedResult, "RError_PI",
      NULL, 0, irodsProt);
    printf ("packStruct of RErrMsg_PI status = %d\n", status);
    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "error.out");

    status = unpackStruct (packedResult->buf, (void **) &outError, "RError_PI",
      NULL, irodsProt);
    printf ("unpackStruct of RErrMsg_PI status = %d\n", status);
    
} 
コード例 #9
0
int
procApiReply( rcComm_t *conn, int apiInx, void **outStruct,
              bytesBuf_t *outBsBBuf,
              msgHeader_t *myHeader, bytesBuf_t *outStructBBuf, bytesBuf_t *myOutBsBBuf,
              bytesBuf_t *errorBBuf ) {
    int status;
    int retVal;

    if ( errorBBuf->len > 0 ) {
        status = unpackStruct( errorBBuf->buf, ( void ** )( static_cast< void * >( &conn->rError ) ),
                               "RError_PI", RodsPackTable, conn->irodsProt );
        if ( status < 0 ) {
            rodsLogError( LOG_ERROR, status,
                          "readAndProcApiReply:unpackStruct error. status = %d",
                          status );
        }
    }

    retVal = myHeader->intInfo;

    /* some sanity check */

    irods::api_entry_table& RcApiTable = irods::get_client_api_table();
    if ( RcApiTable[apiInx]->outPackInstruct != NULL && outStruct == NULL ) {
        rodsLog( LOG_ERROR,
                 "readAndProcApiReply: outStruct error for C apiNumber %d",
                 RcApiTable[apiInx]->apiNumber );
        if ( retVal < 0 ) {
            return retVal;
        }
        else {
            return ( USER_API_INPUT_ERR );
        }
    }

    if ( RcApiTable[apiInx]->outBsFlag > 0 && outBsBBuf == NULL ) {
        rodsLog( LOG_ERROR,
                 "readAndProcApiReply: outBsBBuf error for D apiNumber %d",
                 RcApiTable[apiInx]->apiNumber );
        if ( retVal < 0 ) {
            return retVal;
        }
        else {
            return ( USER_API_INPUT_ERR );
        }
    }

    /* handle outStruct */
    if ( outStructBBuf->len > 0 ) {
        if ( outStruct != NULL ) {
            status = unpackStruct( outStructBBuf->buf, ( void ** ) outStruct,
                                   ( char* )RcApiTable[apiInx]->outPackInstruct, RodsPackTable,
                                   conn->irodsProt );
            if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "readAndProcApiReply:unpackStruct error. status = %d",
                              status );
                if ( retVal < 0 ) {
                    return retVal;
                }
                else {
                    return ( status );
                }
            }
        }
        else {
            rodsLog( LOG_ERROR,
                     "readAndProcApiReply: got unneeded outStruct for apiNumber %d",
                     RcApiTable[apiInx]->apiNumber );
        }
    }

    if ( myOutBsBBuf != NULL && myOutBsBBuf->len > 0 ) {
        if ( outBsBBuf != NULL ) {
            /* copy to out */
            *outBsBBuf = *myOutBsBBuf;
            memset( myOutBsBBuf, 0, sizeof( bytesBuf_t ) );
        }
        else {
            rodsLog( LOG_ERROR,
                     "readAndProcApiReply: got unneeded outBsBBuf for apiNumber %d",
                     RcApiTable[apiInx]->apiNumber );
        }
    }

    return retVal;
}
コード例 #10
0
/// =-=-=-=-=-=-=-
/// @brief function which sends the negotiation message
    error read_client_server_negotiation_message(
        irods::network_object_ptr      _ptr,
        boost::shared_ptr< cs_neg_t >&  _cs_neg_msg ) {
        // =-=-=-=-=-=-=-
        // read the message header
        struct timeval tv;
        tv.tv_sec = READ_VERSION_TOUT_SEC;
        tv.tv_usec = 0;

        msgHeader_t msg_header;
        irods::error ret = readMsgHeader( _ptr, &msg_header, &tv );
        if ( !ret.ok() ) {
            return PASSMSG( "read message header failed", ret );
        }

        // =-=-=-=-=-=-=-
        // read the message body
        bytesBuf_t struct_buf, data_buf, error_buf;
        memset( &data_buf, 0, sizeof( bytesBuf_t ) );
        ret = readMsgBody(
                  _ptr,
                  &msg_header,
                  &struct_buf,
                  &data_buf,
                  &error_buf,
                  XML_PROT, 0 );
        if ( !ret.ok() ) {
            return PASS( ret );

        }

        // =-=-=-=-=-=-=-
        // check that we did in fact get the right type of message
        if ( strcmp( msg_header.type, RODS_CS_NEG_T ) != 0 ) {
            // =-=-=-=-=-=-=-
            // trap potential case where server does not support
            // advanced negotiation.  a version msg would be sent
            // back instead.
            if ( strcmp( msg_header.type, RODS_VERSION_T ) == 0 ) {
                // =-=-=-=-=-=-=-
                // unpack the version struct to check the status
                version_t* version = 0;
                int status = unpackStruct(
                                 struct_buf.buf,
                                 ( void ** )( static_cast<void *>( &version ) ),
                                 "Version_PI",
                                 RodsPackTable,
                                 XML_PROT );

                if ( struct_buf.buf ) {
                    free( struct_buf.buf );
                }
                if ( data_buf.buf ) {
                    free( data_buf.buf );
                }
                if ( error_buf.buf ) {
                    free( error_buf.buf );
                }

                if ( status < 0 ) {
                    rodsLog( LOG_ERROR, "read_client_server_negotiation_message :: unpackStruct FAILED" );
                    return ERROR( status, "unpackStruct failed" );

                }

                if ( version->status < 0 ) {
                    rodsLog( LOG_ERROR, "read_client_server_negotiation_message :: received error message %d", version->status );
                    return ERROR( version->status, "negotiation failed" );

                }
                else {
                    // =-=-=-=-=-=-=-
                    // if no negoation is allowed then provide a readable
                    // error for the client
                    std::stringstream msg;
                    msg << "received [" << msg_header.type << "] ";
                    msg << "but expected [" << RODS_CS_NEG_T << "]\n\n";
                    msg << "\t*** Advanced negotiation is enabled in this iRODS environment   ***\n";
                    msg << "\t*** which is most likely not supported by the server.           ***\n";
                    msg << "\t*** Comment out irodsClientServerNegotiation in the irodsEnv    ***\n";
                    msg << "\t*** file to disable.                                            ***\n";
                    return ERROR( ADVANCED_NEGOTIATION_NOT_SUPPORTED, msg.str() );
                }

            }
            else {
                // =-=-=-=-=-=-=-
                // something entirely unexpected happened
                std::stringstream msg;
                msg << "wrong message type [" << msg_header.type << "] ";
                msg << "expected [" << RODS_CS_NEG_T << "]";
                return ERROR( SYS_HEADER_TYPE_LEN_ERR, msg.str() );
            }
        }

        // =-=-=-=-=-=-=-
        // check that we did not get any data with the message
        if ( msg_header.bsLen != 0 ) {
            if ( data_buf.buf != NULL ) {
                free( data_buf.buf );
            }
            rodsLog( LOG_NOTICE,
                     "read_client_server_negotiation_message: msg_header.bsLen = %d is not 0",
                     msg_header.bsLen );
        }

        // =-=-=-=-=-=-=-
        // check that we did not get anything in the error buffer
        if ( msg_header.errorLen != 0 ) {
            if ( error_buf.buf ) {
                free( error_buf.buf );
            }
            rodsLog( LOG_NOTICE,
                     "read_client_server_negotiation_message: msg_header.errorLen = %d is not 0",
                     msg_header.errorLen );
        }

        // =-=-=-=-=-=-=-
        // check that we did get an appropriately sized message
        if ( msg_header.msgLen > ( int ) sizeof( irods::cs_neg_t ) * 2 ||
                msg_header.msgLen <= 0 ) {
            if ( struct_buf.buf != NULL ) {
                free( struct_buf.buf );
            }
            std::stringstream msg;
            msg << "message length is invalid: " << msg_header.msgLen << " vs " << sizeof( irods::cs_neg_t );
            return ERROR( SYS_HEADER_READ_LEN_ERR, msg.str() );
        }

        // =-=-=-=-=-=-=-
        // do an unpack into our out variable using the xml protocol
        cs_neg_t* tmp_cs_neg = 0;
        int status = unpackStruct( struct_buf.buf,
                                   ( void ** )( static_cast<void *>( &tmp_cs_neg ) ),
                                   "CS_NEG_PI",
                                   RodsPackTable,
                                   XML_PROT );
        free( struct_buf.buf );
        if ( status < 0 ) {
            rodsLog( LOG_ERROR, "read_client_server_negotiation_message :: unpackStruct FAILED" );
            return ERROR( status, "unpackStruct failed" );

        }

        _cs_neg_msg.reset( tmp_cs_neg, free );

        // =-=-=-=-=-=-=-
        // win!!!111one
        return SUCCESS();

    } // read_client_server_negotiation_message