示例#1
0
int _delayExec( char *inActionCall, char *recoveryActionCall,
                char *delayCondition,  ruleExecInfo_t *rei ) {

    char *args[MAX_NUM_OF_ARGS_IN_ACTION];
    int i, argc;
    ruleExecSubmitInp_t *ruleSubmitInfo;
    /* char action[MAX_ACTION_SIZE]; */
    char tmpStr[NAME_LEN];
    bytesBuf_t *packedReiAndArgBBuf = NULL;
    char *ruleExecId;
    char *actionCall;


    RE_TEST_MACRO( "    Calling _delayExec" );

    actionCall = inActionCall;
    /* Get Arguments */
    actionCall = ( char * ) malloc( strlen( inActionCall ) + strlen( recoveryActionCall ) + 3 );
    sprintf( actionCall, "%s|%s", inActionCall, recoveryActionCall );
    args[1] = NULL;
    argc = 0;
    /* Pack Rei and Args */
    i = packReiAndArg( rei->rsComm, rei, args, argc, &packedReiAndArgBBuf );
    if ( i < 0 ) {
        if ( actionCall != inActionCall ) {
            free( actionCall );
        }
        return( i );
    }
    /* fill Conditions into Submit Struct */
    ruleSubmitInfo = ( ruleExecSubmitInp_t * ) mallocAndZero( sizeof( ruleExecSubmitInp_t ) );
    i  = fillSubmitConditions( actionCall, delayCondition, packedReiAndArgBBuf, ruleSubmitInfo, rei );
    if ( actionCall != inActionCall ) {
        free( actionCall );
    }
    if ( i < 0 ) {
        free( ruleSubmitInfo );
        return( i );
    }

    /* Store ReiArgs Struct in a File */
    i = rsRuleExecSubmit( rei->rsComm, ruleSubmitInfo, &ruleExecId );
    if ( packedReiAndArgBBuf != NULL ) {
        clearBBuf( packedReiAndArgBBuf );
        free( packedReiAndArgBBuf );
    }

    free( ruleSubmitInfo );
    if ( i < 0 ) {
        return( i );
    }
    free( ruleExecId );
    snprintf( tmpStr, NAME_LEN, "%d", i );
    i = pushStack( &delayStack, tmpStr );
    return( i );
}
示例#2
0
int
sendAndProcApiReply( rsComm_t * rsComm, int apiInx, int status,
                     void * myOutStruct, bytesBuf_t * myOutBsBBuf ) {
    int retval;

    retval = sendApiReply( rsComm, apiInx, status, myOutStruct, myOutBsBBuf );

    clearBBuf( myOutBsBBuf );
    if ( myOutStruct != NULL ) {
        free( myOutStruct );
    }
    freeRErrorContent( &rsComm->rError );

    /* check for portal operation */

    if ( rsComm->portalOpr != NULL ) {
        handlePortalOpr( rsComm );
        clearKeyVal( &rsComm->portalOpr->dataOprInp.condInput );
        free( rsComm->portalOpr );
        rsComm->portalOpr = NULL;
    }

    return retval;
}
示例#3
0
int
readAndProcClientMsg( rsComm_t * rsComm, int flags ) {
    int status = 0;
    msgHeader_t myHeader;
    bytesBuf_t inputStructBBuf, bsBBuf, errorBBuf;

    bzero( &inputStructBBuf, sizeof( inputStructBBuf ) );
    bzero( &bsBBuf, sizeof( bsBBuf ) );
    bzero( &errorBBuf, sizeof( errorBBuf ) );

    svrChkReconnAtReadStart( rsComm );
    /* everything else are set in readMsgBody */

    /* read the header */

    // =-=-=-=-=-=-=-
    // 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 ret.code();
    }

    if ( ( flags & READ_HEADER_TIMEOUT ) != 0 ) {
        int retryCnt = 0;
        struct timeval tv;
        tv.tv_sec = READ_HEADER_TIMEOUT_IN_SEC;
        tv.tv_usec = 0;

        while ( 1 ) {
            ret = readMsgHeader( net_obj, &myHeader, &tv );
            if ( !ret.ok() ) {
                if ( isL1descInuse() && retryCnt < MAX_READ_HEADER_RETRY ) {
                    rodsLogError( LOG_ERROR, status,
                                  "readAndProcClientMsg:readMsgHeader error. status = %d",  ret.code() );
                    retryCnt++;
                    continue;
                }
                if ( ret.code() == USER_SOCK_CONNECT_TIMEDOUT ) {
                    rodsLog( LOG_ERROR,
                             "readAndProcClientMsg: readMsgHeader by pid %d timedout",
                             getpid() );
                    return  ret.code();
                }
            }
            break;
        } // while 1
    }
    else {
        ret = readMsgHeader( net_obj, &myHeader, NULL );
    }

    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        /* attempt to accept reconnect. ENOENT result  from * user cntl-C */
        if ( rsComm->reconnSock > 0 ) {
            int savedStatus = ret.code();
            /* try again. the socket might have changed */
            boost::unique_lock< boost::mutex > boost_lock( *rsComm->thread_ctx->lock );
            rodsLog( LOG_DEBUG,
                     "readAndProcClientMsg: svrSwitchConnect. cliState = %d,agState=%d",
                     rsComm->clientState, rsComm->agentState );
            svrSwitchConnect( rsComm );
            boost_lock.unlock();
            ret = readMsgHeader( net_obj, &myHeader, NULL );
            if ( !ret.ok() ) {
                svrChkReconnAtReadEnd( rsComm );
                return savedStatus;
            }
        }
        else {
            svrChkReconnAtReadEnd( rsComm );
            return ret.code();
        }
    } // if !ret.ok()

#ifdef SYS_TIMING
    if ( strcmp( myHeader.type, RODS_API_REQ_T ) == 0 ) {
        /* Get the total time of AUTH_REQUEST_AN and AUTH_RESPONSE_AN */
        if ( myHeader.intInfo != AUTH_RESPONSE_AN ) {
            initSysTiming( "irodsAgent", "recv request", 0 );
        }
    }
#endif
    ret = readMsgBody( net_obj, &myHeader, &inputStructBBuf,
                       &bsBBuf, &errorBBuf, rsComm->irodsProt, NULL );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        svrChkReconnAtReadEnd( rsComm );
        return ret.code();
    }

    svrChkReconnAtReadEnd( rsComm );

    /* handler switch by msg type */

    if ( strcmp( myHeader.type, RODS_API_REQ_T ) == 0 ) {
        status = rsApiHandler( rsComm, myHeader.intInfo, &inputStructBBuf,
                               &bsBBuf );
#ifdef SYS_TIMING
        char tmpStr[NAME_LEN];
        snprintf( tmpStr, NAME_LEN, "handle API %d", myHeader.intInfo );
        printSysTiming( "irodsAgent", tmpStr, 0 );
#endif
        clearBBuf( &inputStructBBuf );
        clearBBuf( &bsBBuf );
        clearBBuf( &errorBBuf );

        if ( ( flags & RET_API_STATUS ) != 0 ) {
            return status;
        }
        else {
            return 0;
        }
    }
    else if ( strcmp( myHeader.type, RODS_DISCONNECT_T ) == 0 ) {
        rodsLog( LOG_NOTICE,
                 "readAndProcClientMsg: received disconnect msg from client" );

        return DISCONN_STATUS;
    }
    else if ( strcmp( myHeader.type, RODS_RECONNECT_T ) == 0 ) {
        rodsLog( LOG_NOTICE,
                 "readAndProcClientMsg: received reconnect msg from client" );
        /* call itself again. be careful */
        status = readAndProcClientMsg( rsComm, flags );
        return status;
    }
    else {
        rodsLog( LOG_NOTICE,
                 "agentMain: msg type %s not support by server",
                 myHeader.type );
        return USER_MSG_TYPE_NO_SUPPORT;
    }
}
示例#4
0
    int
    rsNcGetAggInfo( rsComm_t *rsComm, ncOpenInp_t *ncOpenInp,
                    ncAggInfo_t **ncAggInfo ) {
        specCollCache_t *specCollCache = NULL;
        collInp_t collInp;
        int handleInx;
        collEnt_t *collEnt;
        int status = 0;
        int status2 = 0;
        int savedStatus = 0;
        ncOpenInp_t childNcOpenInp;
        ncAggElement_t *ncAggElement = NULL;
        bytesBuf_t *packedBBuf = NULL;

        bzero( &collInp, sizeof( collInp ) );
        rstrcpy( collInp.collName, ncOpenInp->objPath, MAX_NAME_LEN );
        resolveLinkedPath( rsComm, collInp.collName, &specCollCache,
                           &ncOpenInp->condInput );
        collInp.flags = VERY_LONG_METADATA_FG;
        handleInx = irods::server_api_call ( OPEN_COLLECTION_AN, rsComm, &collInp );
        if ( handleInx < 0 ) {
            rodsLog( LOG_ERROR,
                     "rsNcGetAggInfo: rsOpenCollection of %s error. status = %d",
                     collInp.collName, handleInx );
            return ( handleInx );
        }
        bzero( &childNcOpenInp, sizeof( childNcOpenInp ) );
        *ncAggInfo = ( ncAggInfo_t * ) calloc( 1, sizeof( ncAggInfo_t ) );
        rstrcpy( ( *ncAggInfo )->ncObjectName, ncOpenInp->objPath, MAX_NAME_LEN );
        while ( ( status2 = irods::server_api_call ( READ_COLLECTION_AN, rsComm, &handleInx, &collEnt ) ) >= 0 ) {
            if ( collEnt->objType != DATA_OBJ_T ) {
                free( collEnt );
                continue;
            }
            else if ( strcmp( collEnt->dataType, "netcdf" ) != 0 ) {
                if ( strcmp( collEnt->dataName, NC_AGG_INFO_FILE_NAME ) != 0 ) {
                    rodsLog( LOG_NOTICE,
                             "rsNcGetAggInfo: dataType of %s in %s is not 'netcdf' type",
                             collEnt->dataName, collInp.collName );
                    savedStatus = NETCDF_INVALID_DATA_TYPE;
                }
                free( collEnt );
                continue;
            }
            snprintf( childNcOpenInp.objPath, MAX_NAME_LEN, "%s/%s",
                      collInp.collName, collEnt->dataName );
            status = irods::server_api_call ( NC_GET_AGG_ELEMENT_AN, rsComm, &childNcOpenInp, &ncAggElement );
            if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "rsNcGetAggInfo: rsNcGetAggElement of %s error.",
                              childNcOpenInp.objPath );
                free( collEnt );
                break;
            }
            else {
                status = addNcAggElement( ncAggElement, *ncAggInfo );
                free( ncAggElement );
                if ( status < 0 ) {
                    free( collEnt );
                    break;
                }
            }
            free( collEnt );
        }
        irods::server_api_call ( CLOSE_COLLECTION_AN, rsComm, &handleInx );
        if ( status2 < 0 && status2 != CAT_NO_ROWS_FOUND && status >= 0 ) {
            status = status2;
        }
        if ( status >= 0 && ( ncOpenInp->mode & NC_WRITE ) != 0 ) {
            dataObjInp_t dataObjInp;
            portalOprOut_t *portalOprOut = NULL;
            status = packStruct( ( void * ) * ncAggInfo, &packedBBuf, "NcAggInfo_PI",
                                 RodsPackTable, 0, XML_PROT );
            if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "rsNcGetAggInfo: packStruct error for %s",
                              childNcOpenInp.objPath );
                return status;
            }
            /* write it */
            bzero( &dataObjInp, sizeof( dataObjInp ) );
            replKeyVal( &ncOpenInp->condInput, &dataObjInp.condInput );
            snprintf( dataObjInp.objPath, MAX_NAME_LEN, "%s/%s",
                      collInp.collName, NC_AGG_INFO_FILE_NAME );
            dataObjInp.dataSize = packedBBuf->len;
            dataObjInp.oprType = PUT_OPR;
            addKeyVal( &dataObjInp.condInput, DATA_INCLUDED_KW, "" );
            addKeyVal( &dataObjInp.condInput, FORCE_FLAG_KW, "" );
            status = irods::server_api_call ( DATA_OBJ_PUT_AN, rsComm, &dataObjInp, packedBBuf, &portalOprOut );
            clearBBuf( packedBBuf );
            clearKeyVal( &dataObjInp.condInput );
            if ( portalOprOut != NULL ) {
                free( portalOprOut );
            }
            if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "rsNcGetAggInfo: rsDataObjPut error for %s", dataObjInp.objPath );
            }
        }
        if ( status < 0 ) {
            return status;
        }
        else {
            return savedStatus;
        }
    }
示例#5
0
// =-=-=-=-=-=-=-
//
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 );
}
示例#6
0
文件: xmlMS.c 项目: 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);
}
int
readAndProcApiReply( rcComm_t *conn, int apiInx, void **outStruct,
                     bytesBuf_t *outBsBBuf ) {
    int status = 0;
    msgHeader_t myHeader;
    /* bytesBuf_t outStructBBuf, errorBBuf, myOutBsBBuf; */
    bytesBuf_t outStructBBuf, errorBBuf;

    cliChkReconnAtReadStart( conn );

    memset( &outStructBBuf, 0, sizeof( bytesBuf_t ) );
    memset( &outStructBBuf, 0, sizeof( bytesBuf_t ) );
    /* memset (&myOutBsBBuf, 0, sizeof (bytesBuf_t)); */

    /* 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 A apiNumber %d",
                 RcApiTable[apiInx]->apiNumber );
        cliChkReconnAtReadEnd( conn );
        return ( USER_API_INPUT_ERR );
    }

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

    irods::network_object_ptr net_obj;
    irods::error ret = irods::network_factory( conn, net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();
    }

    ret = readMsgHeader( net_obj, &myHeader, NULL );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        if ( conn->svrVersion != NULL && conn->svrVersion->reconnPort > 0 ) {
            int savedStatus = ret.code();
            /* try again. the socket might have changed */
            conn->thread_ctx->lock->lock();
            rodsLog( LOG_DEBUG,
                     "readAndProcClientMsg:svrSwitchConnect.cliState = %d,agState=%d",
                     conn->clientState, conn->agentState );
            cliSwitchConnect( conn );
            conn->thread_ctx->lock->unlock();
            irods::error ret = readMsgHeader( net_obj, &myHeader, NULL );

            if ( !ret.ok() ) {
                cliChkReconnAtReadEnd( conn );
                return ( savedStatus );
            }
        }
        else {
            cliChkReconnAtReadEnd( conn );
            return ( ret.code() );
        }

    } // if !ret.ok

    ret = readMsgBody( net_obj, &myHeader, &outStructBBuf, outBsBBuf,
                       &errorBBuf, conn->irodsProt, NULL );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        cliChkReconnAtReadEnd( conn );
        return ( status );
    } // if !ret.ok

    cliChkReconnAtReadEnd( conn );

    if ( strcmp( myHeader.type, RODS_API_REPLY_T ) == 0 ) {
        status = procApiReply( conn, apiInx, outStruct, outBsBBuf,
                               &myHeader, &outStructBBuf, NULL, &errorBBuf );
    }

    clearBBuf( &outStructBBuf );
    /* clearBBuf (&myOutBsBBuf); */
    clearBBuf( &errorBBuf );

    return ( status );
}
示例#8
0
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;
}