static
globus_result_t
globus_l_seg_register_write(
    globus_byte_t *                     buf)
{
    globus_result_t                     result;
    size_t                              cnt;
    globus_xio_iovec_t *                iov;
    size_t                              nbytes=0;
    int                                 i;

    if (buf)
    {
        globus_fifo_enqueue(&globus_l_seg_buffers, buf);
    }

    cnt = globus_fifo_size(&globus_l_seg_buffers);
    if ((!globus_l_seg_write_registered) && cnt > 0)
    {

        iov = globus_libc_calloc(cnt, sizeof(globus_xio_iovec_t));
        if (iov == NULL)
        {
            result = GLOBUS_SEG_ERROR_OUT_OF_MEMORY;

            goto call_fault_handler;
        }

        for (i = 0; i < cnt; i++)
        {
            iov[i].iov_base = globus_fifo_dequeue(&globus_l_seg_buffers);
            iov[i].iov_len = strlen((char *)iov[i].iov_base);
            nbytes += iov[i].iov_len;
        }

        result = globus_xio_register_writev(
                globus_l_seg_output_handle,
                iov,
                cnt,
                nbytes,
                NULL,
                globus_l_seg_writev_callback,
                NULL);

        if (result != GLOBUS_SUCCESS)
        {
            goto call_fault_handler;
        }
        globus_l_seg_write_registered = GLOBUS_TRUE;
    }

    return GLOBUS_SUCCESS;

call_fault_handler:
    globus_scheduler_event_generator_fault(result);

    return result;
}
Example #2
0
/**
 * Allocate
 */
ngSessionInformation_t *
ngiSessionInformationAllocate(ngLog_t *log, int *error)
{
    ngSessionInformation_t *info;
    static const char fName[] = "ngiSessionInformationAllocate";

    info = globus_libc_calloc(1, sizeof (ngSessionInformation_t));
    if (info == NULL) {
        NGI_SET_ERROR(error, NG_ERROR_MEMORY);
        ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL,
	    "%s: Can't allocate the storage for Session Information.\n", fName);
	return NULL;
    }

    /* Success */
    return info;
}
Example #3
0
/**
 * Allocate
 */
NET_Communicator *
ngiNetCommunicatorAllocate(ngLog_t *log, int *error)
{
    NET_Communicator *netComm;
    static const char fName[] = "ngiNetCommunicatorAllocate";

    netComm = globus_libc_calloc(1, sizeof (NET_Communicator));
    if (netComm == NULL) {
        NGI_SET_ERROR(error, NG_ERROR_MEMORY);
        ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR,
	    NULL, "%s: Can't allocate the storage for Communicator.", fName);
	return NULL;
    }

    /* Success */
    return netComm;
}
Example #4
0
/**
 * Initialize XDR
 */
static int
nglNetCommunicatorInitializeXDR(
    NET_Communicator *netComm,
    int dataType,
    int nElements,
    ngLog_t *log,
    int *error)
{
    size_t xdrNbytes;
    int result;
    static const char fName[] = "nglNetCommunicatorInitializeXDR";

    /* Check tha arguments */
    assert(netComm != NULL);
    assert(netComm->nc_xdrBuffer == NULL);
    assert(nElements > 0);

    /* Get the number of bytes of data */
    result = ngiNetCommunicatorGetDataSize(
    	netComm, dataType, &xdrNbytes, log, error);
    if ((result == 0) || (nBytes < 0)) {
    	ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR,
	    NULL, "%s: Can't get the number of bytes of data.\n", fName);
	return 0;
    }
    netComm->nc_xdrNbytes = xdrNbytes * nElements;

    /* Allocate the data buffer */
    netComm->nc_xdrBuffer = globus_libc_calloc(1, netComm->nc_xdrNbytes);
    if (netComm->nc_xdrBuffer == NULL) {
        NGI_SET_ERROR(error, NG_ERROR_MEMORY);
   	ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR,
	    NULL, "%s: Can't allocate the storage for Data Buffer.\n", fName);
	return 0;
    }

    /* Initialize the XDR stream */
    xdrmem_create(
    	&netComm->nc_xdrStream, netComm->nc_xdrBuffer, nBytes, XDR_FREE);
    xdrmem_create(
    	&netComm->nc_xdrStream, netComm->nc_xdrBuffer, nBytes, XDR_ENCODE);

    /* Success */
    return 1;
}
Example #5
0
/**
 * Start the measurement.
 */
int
ngiSessionInformationStartMeasurement(
    ngSessionInformation_t *info,
    int nArguments,
    ngLog_t *log,
    int *error)
{
    int result;
    static const char fName[] = "ngiSessionInformationStartMeasurement";

    /* Check tha arguments */
    assert(info != NULL);
    assert(nArguments >= 0);
    assert(info->ngsi_compressionInformation == NULL);

    /* Initialize */
    result = ngiSessionInformationInitialize(info, log, error);
    if (result == 0) {
        ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL,
	    "%s: Can't initialize the Session Information.\n", fName);
	return 0;
    }

    /* Allocate the storage for Compression Information */
    info->ngsi_nCompressionInformations = nArguments;
    if (nArguments > 0) {
	info->ngsi_compressionInformation = globus_libc_calloc(
	    nArguments, sizeof (*info->ngsi_compressionInformation));
	if (info->ngsi_compressionInformation == NULL) {
	    NGI_SET_ERROR(error, NG_ERROR_MEMORY);
	    ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR,
		NULL,
		"%s: Can't allocate the storage for Session Information.\n",
		fName);
	    return 0;
	}
    }

    /* Success */
    return 1;
}
Example #6
0
/**
 * ObserveItem: Allocate
 */
static ngcliObserveItem_t *
ngcllObserveItemAllocate(
    ngclContext_t *context,
    int *error)
{
    ngcliObserveItem_t *observeItem;
    static const char fName[] = "ngcllObserveItemAllocate";

    /* Allocate */
    observeItem = globus_libc_calloc(1, sizeof(ngcliObserveItem_t));
    if (observeItem == NULL) {
        NGI_SET_ERROR(error, NG_ERROR_MEMORY);
        ngclLogPrintfContext(context,
            NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL,
            "%s: Can't allocate the storage for ObserveItem.\n", fName);
        return NULL;
    }

    /* Success */
    return observeItem;
}
/**
 * @brief Initialize a GRAM client attribute
 * @ingroup globus_gram_client_attr
 *
 * @details
 * The globus_gram_client_attr_init() function creates a new opaque
 * structure that can be used to specify custom attributes for performing
 * GRAM client operations.
 * 
 * @param attr
 *     An output parameter which will be set to the newly initialized 
 *     attribute.
 *
 * @return
 *     Upon success, globus_gram_client_attr_init() modifies the @a attr
 *     parameter to point to a new GRAM client attribute and returns
 *     @a GLOBUS_SUCCESS. If an error occurs, globus_gram_client_attr_init()
 *     returns an integer error code and value of @a attr is undefined.
 *
 * @retval GLOBUS_SUCCESS
 *     Success
 * @retval GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_ATTR
 *     Invalid attribute
 * @retval GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED
 *     Out of memory
 *
 * @see globus_gram_client_attr_destroy()
 */
int
globus_gram_client_attr_init(
    globus_gram_client_attr_t *     attr)
{
    globus_i_gram_client_attr_t *   iattr;

    if (attr == NULL)
    {
        return GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_ATTR;
    }
    iattr = globus_libc_calloc(1, sizeof(globus_i_gram_client_attr_t));

    if(iattr == NULL)
    {
        return GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED;
    }
    iattr->delegation_mode = GLOBUS_IO_SECURE_DELEGATION_MODE_LIMITED_PROXY;

    *attr = (void*) iattr;

    return GLOBUS_SUCCESS;
}
Example #8
0
/**
 * Request Attributes Read
 */
static int
ngislRequestAttributesRead(
    ngisiContext_t *context,
    FILE *readFp,
    ngisiReadBuffer_t *readBuffer,
    ngisiCreateAttr_t **attrs,
    int *error)
{
    static const char fName[] = "ngislRequestAttributesRead";
    char attrNameBuf[NGISI_CREATE_ATTR_STR_MAX];
    ngisiCreateAttr_t *newAttr;
    int result, finish, cur;
    char *p, *strStart;

    /* Check the arguments */
    assert(context != NULL);
    assert(readFp != NULL);
    assert(readBuffer != NULL);
    assert(attrs != NULL);

    *attrs = NULL;

    newAttr = (ngisiCreateAttr_t *)globus_libc_calloc(
        1, sizeof(ngisiCreateAttr_t));
    if (newAttr == NULL) {
        ngisiLogPrintf(context, NGISI_LOG_LEVEL_ERROR, fName,
            "Allocate the Create Attr failed.\n");
        return 0;
    }

    result = ngislCreateAttrInitialize(context, newAttr, error);
    if (result == 0) {
        ngisiLogPrintf(context, NGISI_LOG_LEVEL_ERROR, fName,
            "Initialize the Create Attr failed.\n");
        return 0;
    }

    *attrs = newAttr;

    finish = 0;
    do {
        result = ngisiReadLine(
            context, NGISI_FP_REQUEST, readBuffer, error);
        if (result == 0) {
            ngisiLogPrintf(context, NGISI_LOG_LEVEL_ERROR, fName,
                "Read line failed.\n");
            return 0;
        }

        /* log */
        ngisiLogPrintf(context, NGISI_LOG_LEVEL_DEBUG, fName,
        "Read Attr \"%s\".\n", readBuffer->ngisrb_buf);


        strStart = readBuffer->ngisrb_buf;
        p = strStart;
        cur = 0;

        /* Get attribute name */
        while (isgraph((int)*p)) {
            attrNameBuf[cur] = *p;
            p++;
            cur++;
        }
        attrNameBuf[cur] = '\0';
        cur = 0;
     
        if (strlen(attrNameBuf) == 0) {
            ngisiLogPrintf(context, NGISI_LOG_LEVEL_ERROR, fName,
                "Attr name is 0.\n");
            return 0;
        }

        /* Find the value */
        while (isspace((int)*p)) {
            p++;
        }

        if (strcmp(attrNameBuf, NGISI_CREATE_ATTR_END) == 0) {
            finish = 1;
        } else {
            ngislCheckAttribute(context, attrNameBuf);
            result = ngislCreateAttrAdd(
                context, newAttr, attrNameBuf, p, error);
            if (result == 0) {
                ngisiLogPrintf(context, NGISI_LOG_LEVEL_ERROR, fName,
                    "Add the Create Attr failed.\n");
                return 0;
            }
        }

    } while (finish == 0);

    /* Success */
    return 1;
}
Example #9
0
/**
 * Create Attr Get Remain
 * Returns attribute names which is not treated.
 */
int
ngisiCreateAttrGetRemain(
    ngisiContext_t *context,
    ngisiCreateAttr_t *attr,
    int *remainCount,
    char ***remainTable,
    int *error)
{
    static const char fName[] = "ngisiCreateAttrGetRemain";
    int size, i, cur;
    char **newTable, *name; 

    /* Check the arguments */
    assert(context != NULL);
    assert(attr != NULL);
    assert(remainCount != NULL);
    assert(remainTable != NULL);

    *remainCount = 0;
    *remainTable = NULL;

    /* Count the remain */
    size = 0;
    for (i = 0; i < attr->ngisca_nAttrs; i++) {
        assert(attr->ngisca_attrs[i].ngisce_name != NULL);
        if (attr->ngisca_attrs[i].ngisce_treated == 0) {
            size++;
        }
    }

    if (size == 0) {
        *remainCount = 0;
        *remainTable = NULL;

        /* Success */
        return 1;
    }

    newTable = (char **)globus_libc_calloc(size, sizeof(char *));
    if (newTable == NULL) {
        ngisiLogPrintf(context, NGISI_LOG_LEVEL_ERROR, fName,
            "Allocate the string table failed.\n");
        return 0;
    }

    cur = 0;
    for (i = 0; i < attr->ngisca_nAttrs; i++) {
        assert(attr->ngisca_attrs[i].ngisce_name != NULL);
        if (attr->ngisca_attrs[i].ngisce_treated == 0) {
            name = strdup(attr->ngisca_attrs[i].ngisce_name);
            if (name == NULL) {
                ngisiLogPrintf(context, NGISI_LOG_LEVEL_ERROR, fName,
                    "strdup() failed.\n");
                return 0;
            }
            newTable[cur] = name;
            cur++;
            assert(cur <= size);
        }
    }

    *remainCount = size;
    *remainTable = newTable;

    /* Success */
    return 1;
}
Example #10
0
/**
 * Create Attr Add
 */
static int
ngislCreateAttrAdd(
    ngisiContext_t *context,
    ngisiCreateAttr_t *attr,
    char *name,
    char *value,
    int *error)
{
    static const char fName[] = "ngislCreateAttrAdd";
    ngisiCreateAttrElement_t *newArray, *oldArray;
    int i, newArraySize;
    char *newName, *newValue;

    /* Check the arguments */
    assert(context != NULL);
    assert(attr != NULL);
    assert(name != NULL);

    /* Check and renew size */
    if (attr->ngisca_nAttrs >= attr->ngisca_arraySize) {
        oldArray = attr->ngisca_attrs;

        if (attr->ngisca_arraySize <= 0) {
            newArraySize = NGISI_CREATE_ATTR_INITIAL_SIZE;
        } else {
            newArraySize = attr->ngisca_arraySize * 2;
        }

        newArray = (ngisiCreateAttrElement_t *)globus_libc_calloc(
            newArraySize, sizeof(ngisiCreateAttrElement_t));
        if (newArray == NULL) {
            ngisiLogPrintf(context, NGISI_LOG_LEVEL_ERROR, fName,
                "Allocate the Create Attr failed.\n");
            return 0;
        }

        for (i = 0; i < newArraySize; i++) {
            newArray[i].ngisce_name    = NULL;
            newArray[i].ngisce_value   = NULL;
            newArray[i].ngisce_treated = 0;
        }

        for (i = 0; i < attr->ngisca_arraySize; i++) {
            newArray[i].ngisce_name    = oldArray[i].ngisce_name;
            newArray[i].ngisce_value   = oldArray[i].ngisce_value;
            newArray[i].ngisce_treated = oldArray[i].ngisce_treated;
        }

        attr->ngisca_arraySize = newArraySize;
        attr->ngisca_attrs = newArray;

        if (oldArray != NULL) {
            globus_libc_free(oldArray);
        }
    }
    assert(attr->ngisca_nAttrs < attr->ngisca_arraySize);

    /* Add to tail */
    i = attr->ngisca_nAttrs;

    newName = strdup(name);
    if (newName == NULL) {
        ngisiLogPrintf(context, NGISI_LOG_LEVEL_ERROR, fName,
            "strdup(new name) failed.\n");
        return 0;
    }

    if (value != NULL) {
        newValue = strdup(value);
        if (newValue == NULL) {
        ngisiLogPrintf(context, NGISI_LOG_LEVEL_ERROR, fName,
            "strdup(new value) failed.\n");
        return 0;
        }
    } else {
        newValue = NULL;
    }

    attr->ngisca_attrs[i].ngisce_name = newName;
    attr->ngisca_attrs[i].ngisce_value = newValue;

    attr->ngisca_nAttrs++;
    
    /* Success */
    return 1;
}
/**
 * Initialize an instance of the GridFTP restart plugin
 * @ingroup globus_ftp_client_restart_plugin
 *
 * This function will initialize the plugin-specific instance data
 * for this plugin, and will make the plugin usable for ftp
 * client handle attribute and handle creation.
 *
 * @param plugin
 *        A pointer to an uninitialized plugin. The plugin will be
 *        configured as a restart plugin.
 * @param max_retries
 *        The maximum number of times to retry the operation before giving
 *        up on the transfer. If this value is less than or equal to 0,
 *        then the restart plugin will keep trying to restart the operation
 *        until it completes or the deadline is reached with an unsuccessful
 *        operation.
 * @param interval
 *        The interval to wait after a failures before retrying the transfer.
 *        If the interval is 0 seconds or GLOBUS_NULL, then an exponential 
 *        backoff will be used.
 * @param deadline
 *        An absolute timeout.  If the deadline is GLOBUS_NULL then the retry
 *        will never timeout.
 *
 * @return This function returns an error if
 * - plugin is null
 *
 * @see globus_ftp_client_restart_plugin_destroy(),
 *      globus_ftp_client_handleattr_add_plugin(),
 *      globus_ftp_client_handleattr_remove_plugin(),
 *      globus_ftp_client_handle_init()
 */
globus_result_t
globus_ftp_client_restart_plugin_init(
    globus_ftp_client_plugin_t *		plugin,
    int						max_retries,
    globus_reltime_t *				interval,
    globus_abstime_t *				deadline)
{
    char *                              env_str;
    globus_l_ftp_client_restart_plugin_t *	d;
    globus_result_t				result;
    GlobusFuncName(globus_ftp_client_restart_plugin_init);

    if(plugin == GLOBUS_NULL)
    {
	return globus_error_put(globus_error_construct_string(
		GLOBUS_FTP_CLIENT_MODULE,
		GLOBUS_NULL,
		"[%s] NULL plugin at %s\n",
		GLOBUS_FTP_CLIENT_MODULE->module_name,
		_globus_func_name));
    }
        
    d =
	globus_libc_calloc(1, sizeof(globus_l_ftp_client_restart_plugin_t));

    if(! d)
    {
	return globus_error_put(globus_error_construct_string(
		                GLOBUS_FTP_CLIENT_MODULE,
				GLOBUS_NULL,
				"[%s] Out of memory at %s\n",
				 GLOBUS_FTP_CLIENT_MODULE->module_name,
				 _globus_func_name));
    }

    result = globus_ftp_client_plugin_init(plugin,
				  GLOBUS_L_FTP_CLIENT_RESTART_PLUGIN_NAME,
				  GLOBUS_FTP_CLIENT_CMD_MASK_ALL,
				  d);
    if(result != GLOBUS_SUCCESS)
    {
	globus_libc_free(d);

	return result;
    }

    d->max_retries = max_retries > 0 ? max_retries : -1;

    if(interval)
    {
	GlobusTimeReltimeCopy(d->interval, *interval);
    }
    if((!interval) || (interval->tv_sec == 0 && interval->tv_usec == 0))
    {
	d->backoff = GLOBUS_TRUE;
	d->interval.tv_sec = 1;
	d->interval.tv_usec = 0;
    }
    else
    {
        d->backoff = GLOBUS_FALSE;
    }

    if(deadline)
    {
	GlobusTimeAbstimeCopy(d->deadline, *deadline);
    }
    else
    {
	GlobusTimeAbstimeCopy(d->deadline, globus_i_abstime_infinity);
    }

    d->dest_url = GLOBUS_NULL;
    d->source_url = GLOBUS_NULL;

    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, copy);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, destroy);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, chmod);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, cksm);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, delete);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, modification_time);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, size);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, feat);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, mkdir);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, rmdir);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, move);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, verbose_list);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, machine_list);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, mlst);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, stat);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, list);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, get);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, put);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, third_party_transfer);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, fault);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, abort);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, complete);
    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin, data);

    GLOBUS_FTP_CLIENT_RESTART_PLUGIN_SET_FUNC(plugin,
        response);

    env_str = globus_libc_getenv("GUC_STALL_TIMEOUT");
    if(env_str != NULL)
    {
        int                             sc;
        int                             to_secs;

        sc = sscanf(env_str, "%d", &to_secs);
        if(sc == 1)
        {
            globus_ftp_client_restart_plugin_set_stall_timeout(
                plugin, to_secs);
        }
    }

    return GLOBUS_SUCCESS;

result_exit:
    globus_ftp_client_plugin_destroy(plugin);
    return result;
}