Exemplo n.º 1
0
/*
 *  Called when the LFS module is activated.
 *  Need to initialize APR ourselves
 */
int lfs_activate(void) {
    globus_extension_registry_add(
                            GLOBUS_GFS_DSI_REGISTRY,
                            "lfs",
                            GlobusExtensionMyModule(globus_gridftp_server_lfs),
                            &globus_l_gfs_lfs_dsi_iface);

    // See if we're configured to write to statsd
    char * local_host = globus_malloc(256);
    if (local_host) {
        memset(local_host, 0, 256);
        if (gethostname(local_host, 255)) {
            strcpy(local_host, "UNKNOWN");
        }
    }

    char statsd_namespace_prefix [] = "lfs.gridftp.";
    char * statsd_namespace = globus_malloc(strlen(statsd_namespace_prefix)+
                                            strlen(local_host)+1);
    strcpy(statsd_namespace, statsd_namespace_prefix);
    char * source = local_host;
    char * dest;
    for (dest = statsd_namespace + strlen(statsd_namespace_prefix);
            *source != '\0';
            ++source, ++dest) {
        if (*source == '.') {
            *dest = '_';
        } else {
            *dest = *source;
        }
    }
    *dest = '\0';

    char * lfs_statsd_link_port = getenv("GRIDFTP_LFS_STATSD_PORT");
    char * lfs_statsd_link_host = getenv("GRIDFTP_LFS_STATSD_HOST");
    if (lfs_statsd_link_host) {
        int lfs_statsd_link_port_conv = 8125;
        if (lfs_statsd_link_port) {
            lfs_statsd_link_port_conv = atoi(lfs_statsd_link_port);
        }
        lfs_statsd_link = statsd_init_with_namespace(lfs_statsd_link_host,
                          lfs_statsd_link_port_conv,
                          statsd_namespace);
        globus_gfs_log_message(GLOBUS_GFS_LOG_INFO,
                               "Sending log data to statsd %s:%i, namespace %s\n",
                               lfs_statsd_link_host,
                               lfs_statsd_link_port_conv,
                               statsd_namespace);
    } else {
        globus_gfs_log_message(GLOBUS_GFS_LOG_INFO,
                               "Not logging to statsd. Set $GRIDFTP_LFS_STATSD_HOST to enable\n");
        lfs_statsd_link = NULL;
    }
    globus_free(statsd_namespace);
    
    globus_gfs_log_message(GLOBUS_GFS_LOG_INFO, "LFS DSI activated.\n");
    STATSD_COUNT("activate",1);
    if (local_host) globus_free(local_host);
    return 0;
}
static
globus_ftp_client_plugin_t *
restart_marker_plugin_copy_cb(
    globus_ftp_client_plugin_t *                plugin_template,
    void *                                      plugin_specific)
{
    restart_marker_plugin_info_t *              old_ps;
    globus_ftp_client_plugin_t *                new_plugin;
    globus_result_t                             result;

    old_ps = (restart_marker_plugin_info_t *) plugin_specific;

    new_plugin = (globus_ftp_client_plugin_t *)
        globus_malloc(sizeof(globus_ftp_client_plugin_t));

    if(new_plugin == GLOBUS_NULL)
    {
        return GLOBUS_NULL;
    }

    result = globus_ftp_client_restart_marker_plugin_init(
        new_plugin,
        old_ps->begin_cb,
        old_ps->marker_cb,
        old_ps->complete_cb,
        old_ps->user_arg);

    if(result != GLOBUS_SUCCESS)
    {
        globus_free(new_plugin);
        new_plugin = GLOBUS_NULL;
    }

    return new_plugin;
}
static
globus_result_t
globus_l_xio_pipe_attr_init(
    void **                             out_attr)
{
    xio_l_pipe_attr_t *                 attr;
    globus_result_t                     result;
    GlobusXIOName(globus_l_xio_pipe_attr_init);

    GlobusXIOPipeDebugEnter();
    /*
     *  create a file attr structure and intialize its values
     */
    attr = (xio_l_pipe_attr_t *) globus_malloc(sizeof(xio_l_pipe_attr_t));
    if(!attr)
    {
        result = GlobusXIOErrorMemory("attr");
        goto error_attr;
    }

    memcpy(attr, &xio_l_pipe_attr_default, sizeof(xio_l_pipe_attr_t));
    *out_attr = attr;

    GlobusXIOPipeDebugExit();
    return GLOBUS_SUCCESS;

error_attr:
    GlobusXIOPipeDebugExitWithError();
    return result;
}
static globus_error_base_instance_t *
s_base_instance_data (globus_object_t * error)
{
  void * instance_data_vp;
  globus_object_t * base;
  globus_error_base_instance_t * instance_data;

  base = globus_object_upcast (error, GLOBUS_ERROR_TYPE_BASE);

  instance_data_vp 
    = globus_object_get_local_instance_data (base);
  
  instance_data = (globus_error_base_instance_t *) instance_data_vp;

  if ( instance_data != NULL ) {
    return instance_data;
  }
  else {
    instance_data = globus_malloc (sizeof(globus_error_base_instance_t));
    if (instance_data != NULL) {
      instance_data->source_module = NULL;
      instance_data->causal_error = NULL;
      
      globus_object_set_local_instance_data (base,
					     (void *) instance_data);
    }
    
    return instance_data;
  }
}
static void
s_base_instance_copy (void *  instance_datavp,
		      void ** copyvp)
{
  globus_error_base_instance_t * instance_data;
  globus_error_base_instance_t * copy;

  instance_data = ((globus_error_base_instance_t *) instance_datavp);

  if (copyvp!=NULL) {
    if (instance_datavp==NULL) {
      (*copyvp) = (void *) NULL;
      return;
    }

    copy = globus_malloc (sizeof(globus_error_base_instance_t));
    if (copy!=NULL) {
      if (instance_data!=NULL) {
	copy->source_module = instance_data->source_module;
	copy->causal_error = globus_object_copy(instance_data->causal_error);
      }
    }
    (*copyvp) = (void *) copy;
  }
}
/******************************************************************************
Function: globus_l_gass_server_ez_tilde_expand()

Description: 

Parameters: 

Returns: 
******************************************************************************/
static int
globus_l_gass_server_ez_tilde_expand(unsigned long options,
			     char *inpath,
			     char **outpath)
{
#ifndef TARGET_ARCH_WIN32   
    /*
     * If this is a relative path, the strip off the leading /./
     */
    if(strlen(inpath) >= 2U)
    {
	if (inpath[1] == '.' && inpath[2] == '/')
	{
	    inpath += 3;
	    goto notilde;
	}
    }

    /* here call the new function globus_tilde_expand()*/
    return globus_tilde_expand(options,
				   GLOBUS_TRUE, /* url form /~[user][/etc]*/
				   inpath,
				   outpath);
#endif /* TARGET_ARCH_WIN32*/

notilde:
    *outpath = globus_malloc(strlen(inpath)+1);
    strcpy(*outpath, inpath);
    return GLOBUS_SUCCESS;
} /* globus_l_gass_server_ez_tilde_expand() */
Exemplo n.º 7
0
globus_fifo_t *
globus_fifo_copy (
    const globus_fifo_t *                                 fifo)
{
    globus_fifo_t *                                 copy;
    struct globus_fifo_s *                          s_copy;
    struct globus_fifo_s *                          s_fifo;

    if (fifo == GLOBUS_NULL) 
		return NULL;
    s_fifo = *fifo;
    if(s_fifo==GLOBUS_NULL) 
		return NULL;

    copy = globus_malloc (sizeof(globus_fifo_t));
    if (copy == NULL) 
		return NULL;

    globus_fifo_init(copy);

    s_copy = *copy;
    s_copy->head = globus_list_copy(s_fifo->head);
    s_copy->tail = s_copy->head;

    while(!globus_list_empty(globus_list_rest(s_copy->tail))) 
    {
        s_copy->tail = globus_list_rest (s_copy->tail);
    }
 
	s_copy->size = s_fifo->size;
	return copy;
}
static
void
globus_l_error_ftp_copy(
    void *                              src,
    void **                             dst)
{
    globus_l_error_ftp_data_t *         copy;
    globus_l_error_ftp_data_t *         source;
    
    if(src && dst)
    {
        copy = (globus_l_error_ftp_data_t *)
            globus_malloc(sizeof(globus_l_error_ftp_data_t));
        if(copy)
        {
            source = (globus_l_error_ftp_data_t *) src;
            
            copy->code = source->code;
            copy->message = source->message 
                ? globus_libc_strdup(source->message) : NULL;
        }
        
        *dst = copy;
    }
}
Exemplo n.º 9
0
/************************************************************************
 *                  stack functions
 ***********************************************************************/
globus_result_t
globus_xio_stack_init(
    globus_xio_stack_t *                stack,
    globus_xio_attr_t                   stack_attr)
{
    globus_i_xio_stack_t *              xio_stack;
    GlobusXIOName(globus_xio_stack_init);

    GlobusXIODebugEnter();
    
    if(stack == NULL)
    {
        GlobusXIODebugExitWithError();
        return GlobusXIOErrorParameter("stack");
    }

    xio_stack = globus_malloc(sizeof(globus_i_xio_stack_t));
    memset(xio_stack, '\0', sizeof(globus_i_xio_stack_t));

    *stack = xio_stack;

    GlobusXIODebugExit();

    return GLOBUS_SUCCESS;
}
/*
 *  copy an attribute structure
 */
static
globus_result_t
globus_l_xio_pipe_attr_copy(
    void **                             dst,
    void *                              src)
{
    xio_l_pipe_attr_t *                 attr;
    xio_l_pipe_attr_t *                 src_attr;
    globus_result_t                     result;
    GlobusXIOName(globus_l_xio_pipe_attr_copy);

    GlobusXIOPipeDebugEnter();

    src_attr = (xio_l_pipe_attr_t *) src;
    attr = (xio_l_pipe_attr_t *) globus_malloc(sizeof(xio_l_pipe_attr_t));
    if(!attr)
    {
        result = GlobusXIOErrorMemory("attr");
        goto error_attr;
    }

    memcpy(attr, src_attr, sizeof(xio_l_pipe_attr_t));
    *dst = attr;

    GlobusXIOPipeDebugExit();
    return GLOBUS_SUCCESS;

error_attr:
    GlobusXIOPipeDebugExitWithError();
    return result;
}
globus_result_t
globus_i_xio_win32_complete(
    globus_callback_func_t              callback,
    void *                              user_arg)
{
    globus_l_xio_win32_poll_entry_t *   entry;
    globus_result_t                     result;
    GlobusXIOName(globus_i_xio_win32_complete);

    GlobusXIOSystemDebugEnter();
    
    if (! globus_i_am_only_thread())
    {
        return globus_callback_register_oneshot(
            0,
            0,
            callback,
            user_arg);
    }

    win32_mutex_lock(&globus_l_xio_win32_poll_lock);
    {
        if(globus_l_xio_win32_poll_free)
        {
            entry = globus_l_xio_win32_poll_free;
            globus_l_xio_win32_poll_free = entry->next;
        }
        else
        {
            entry = (globus_l_xio_win32_poll_entry_t *)
                globus_malloc(sizeof(globus_l_xio_win32_poll_entry_t));
            if(!entry)
            {
                result = GlobusXIOErrorMemory("entry");
                goto error_malloc;
            }
        }
        
        entry->callback = callback;
        entry->user_arg = user_arg;
    
        GlobusLWin32PollQueueEnqueue(entry);
        
        if(globus_l_xio_win32_poll_event_sleeping &&
            !globus_l_xio_win32_poll_event_pending)
        {
            SetEvent(globus_l_xio_win32_poll_event);
            globus_l_xio_win32_poll_event_pending = GLOBUS_TRUE;
        }
    }
    win32_mutex_unlock(&globus_l_xio_win32_poll_lock);
    
    GlobusXIOSystemDebugExit();

    return GLOBUS_SUCCESS;

error_malloc:
    return result;
}
static
char *
globus_l_error_ftp_printable(
    globus_object_t *                   error)
{
    globus_l_error_ftp_data_t *         data;
    char *                              error_string;
    char                                buf[4];
    char *                              message;
    int                                 message_len;
    
    if(!error)
    {
        return NULL;
    }

    data = (globus_l_error_ftp_data_t *)
        globus_object_get_local_instance_data(error);
    message = data->message;
    
    if(message)
    {
        message_len = strlen(message);
        if(message_len > 3 && message[3] == ' ')
        {
            buf[0] = message[0];
            buf[1] = message[1];
            buf[2] = message[2];
            buf[3] = '\0';
            
            if(data->code == atoi(buf))
            {
                message += 4;
                message_len -= 4;
            }
        }
    }
    else
    {
        message_len = 0;
    }
    
    error_string = globus_malloc(sizeof(char) * (15 + message_len));
    if(error_string)
    {
        sprintf(
            error_string,
            "%d %s",
            data->code,
            message ? message : "");
    }
    
    return error_string;
}
/*
 *  copy an attribute structure
 */
static
globus_result_t
globus_l_xio_popen_attr_copy(
    void **                             dst,
    void *                              src)
{
    xio_l_popen_attr_t *                attr;
    xio_l_popen_attr_t *                src_attr;
    globus_result_t                     result;
    int                                 i;
    GlobusXIOName(globus_l_xio_popen_attr_copy);

    GlobusXIOPOpenDebugEnter();

    src_attr = (xio_l_popen_attr_t *) src;
    attr = (xio_l_popen_attr_t *) globus_malloc(sizeof(xio_l_popen_attr_t));
    if(!attr)
    {
        result = GlobusXIOErrorMemory("attr");
        goto error_attr;
    }

    memcpy(attr, src_attr, sizeof(xio_l_popen_attr_t));
    if(src_attr->program_name != NULL)
    {
        attr->program_name = strdup(src_attr->program_name);
    }
    if(src_attr->argc > 0)
    {
        attr->argv = (char **)globus_calloc(attr->argc+1, sizeof(char*));
        for(i = 0; i < attr->argc; i++)
        {
            attr->argv[i] = strdup(src_attr->argv[i]);
        }
        attr->argv[i] = NULL;
    }
    if(src_attr->env_count > 0)
    {
        attr->env = (char **)globus_calloc(attr->env_count+1, sizeof(char*));
        for(i = 0; i < attr->env_count; i++)
        {
            attr->env[i] = strdup(src_attr->env[i]);
        }
        attr->env[i] = NULL;
    }
    *dst = attr;

    GlobusXIOPOpenDebugExit();
    return GLOBUS_SUCCESS;

error_attr:
    GlobusXIOPOpenDebugExitWithError();
    return result;
}
Exemplo n.º 14
0
globus_result_t
globus_l_xio_bounce_open(
    const globus_xio_contact_t *        contact_info,
    void *                              driver_link,
    void *                              driver_attr,
    globus_xio_operation_t              op)
{
    bounce_info_t *                     info;
    globus_result_t                     res;
    GlobusXIOName(globus_l_xio_bounce_open);

    GlobusXIOTestDebugInternalEnter();
    info = (bounce_info_t *)
                globus_malloc(sizeof(bounce_info_t));
    memset(info, '\0', sizeof(bounce_info_t));
    info->next_op = TEST_READ;
    info->bounce_count = 0;
    info->max_count = MAX_COUNT;
    info->start_op = TEST_OPEN;
    info->handle = (bounce_handle_t *) globus_malloc(sizeof(bounce_handle_t));  
    globus_mutex_init(&info->handle->mutex, NULL);
    info->handle->closed_iface = GLOBUS_FALSE;
    info->handle->closed_cb = GLOBUS_FALSE;
    info->handle->open_cb = GLOBUS_FALSE;

    res = globus_xio_driver_pass_open(
        op, contact_info, open_bounce_cb, (void*)info);
    if(res != GLOBUS_SUCCESS)
    {
        bounce_handle_destroy(info->handle);
        globus_free(info);
        goto err;
    }

    GlobusXIOTestDebugInternalExit();
    return GLOBUS_SUCCESS;

  err:
    GlobusXIOTestDebugInternalExitWithError();
    return res;
}
Exemplo n.º 15
0
int
globus_extension_register_builtin(
    const char *                        extension_name,
    globus_module_descriptor_t *        module_descriptor)
{
    globus_l_extension_builtin_t *      builtin;
    GlobusFuncName(globus_extension_register_builtin);
    
    GlobusExtensionDebugEnterSymbol(extension_name);
    
    builtin = (globus_l_extension_builtin_t *)
        globus_malloc(sizeof(globus_l_extension_builtin_t));
    if(!builtin)
    {
        goto error_alloc;
    }
    
    builtin->owner = (globus_l_extension_module_t *)
        globus_thread_getspecific(globus_l_extension_owner_key);
    builtin->module = module_descriptor;
    builtin->extension_name = globus_libc_strdup(extension_name);
    if(!builtin->extension_name)
    {
        goto error_strdup;
    }
    
    globus_rmutex_lock(&globus_l_extension_mutex);
    {
        int                             rc;
        
        rc = globus_hashtable_insert(
            &globus_l_extension_builtins, builtin->extension_name, builtin);
        if(rc != 0)
        {
            goto error_insert;
        }
    }
    globus_rmutex_unlock(&globus_l_extension_mutex);
    
    GlobusExtensionDebugExit();
    return GLOBUS_SUCCESS;

error_insert:
    globus_rmutex_unlock(&globus_l_extension_mutex);
    globus_free(builtin->extension_name);
error_strdup:
    globus_free(builtin);
error_alloc:
    GlobusExtensionDebugExitWithError();
    return GLOBUS_FAILURE;
}
globus_result_t
globus_gridftp_server_control_attr_copy(
    globus_gridftp_server_control_attr_t *  dst,
    globus_gridftp_server_control_attr_t    src)
{
    globus_result_t                         res;
    globus_i_gsc_attr_t *                   attr;
    GlobusGridFTPServerName(globus_gridftp_server_control_attr_copy);

    if(dst == NULL)
    {
        res = GlobusGridFTPServerErrorParameter("dst");
        goto err;
    }
    if(src == NULL)
    {
        res = GlobusGridFTPServerErrorParameter("src");
        goto err;
    }
    if(src->version_ctl != GLOBUS_GRIDFTP_VERSION_CTL)
    {
        res = GlobusGridFTPServerErrorParameter("in_attr");
        goto err;
    }

    attr = (globus_i_gsc_attr_t *) globus_malloc(
                sizeof(globus_i_gsc_attr_t));
    if(attr == NULL)
    {
        res = GlobusGridFTPServerControlErrorSytem();
        goto err;
    }
    attr->version_ctl = src->version_ctl;
    attr->funcs.resource_cb = src->funcs.resource_cb;
    globus_hashtable_copy(
	    &attr->funcs.send_cb_table, &src->funcs.send_cb_table, NULL);
    globus_hashtable_copy(
        &attr->funcs.recv_cb_table, &src->funcs.recv_cb_table, NULL);
    attr->modes = globus_libc_strdup(src->modes);
    attr->types = globus_libc_strdup(src->types);

    *dst = attr;

    return GLOBUS_SUCCESS;

  err:

    GlobusGridFTPServerDebugExitWithError();

    return res;
}
void
globus_i_gass_transfer_keyvalue_insert(
    globus_list_t **				list,
    char *					key,
    char *					value)
{
    globus_gass_transfer_keyvalue_t *	kv;

    kv = globus_malloc(sizeof(globus_gass_transfer_keyvalue_t));
    kv->key = key;
    kv->value = value;

    globus_list_insert(list,
		       kv);
}
Exemplo n.º 18
0
l_smtp_info_t *
l_smtp_create_new_info()
{
    l_smtp_info_t *                     info;

    info = (l_smtp_info_t *) globus_malloc(sizeof(l_smtp_info_t));
    info->state = SMTP_HELO;
    info->read_offset = 0;
    info->buf_len = 1024;
    info->iovec.iov_base = info->message;
    info->iovec.iov_len = info->buf_len;
    sprintf(info->return_address, "%s", globus_l_return_address);

    return info;
}
Exemplo n.º 19
0
int
globus_fifo_init (globus_fifo_t * fifo)
{
    struct globus_fifo_s *                      s_fifo;
    
    if (fifo==GLOBUS_NULL) return -1;

    s_fifo = (struct globus_fifo_s *)globus_malloc(sizeof(struct globus_fifo_s));
    *fifo = s_fifo;
    
    s_fifo->head = GLOBUS_NULL;
    s_fifo->tail = GLOBUS_NULL;
	s_fifo->size = 0;

    return 0;
}
Exemplo n.º 20
0
static globus_result_t
globus_l_xio_bounce_close(
    void *                              driver_handle,
    void *                              attr,
    globus_xio_operation_t              op)
{
    bounce_info_t *                     info;
    globus_result_t                     res;
    GlobusXIOName(globus_l_xio_bounce_close);

    GlobusXIOTestDebugInternalEnter();

    info = (bounce_info_t *)
                globus_malloc(sizeof(bounce_info_t));
    memset(info, '\0', sizeof(bounce_info_t));
    info->next_op = TEST_READ;
    info->bounce_count = 0;
    info->max_count = MAX_COUNT;
    info->start_op = TEST_CLOSE;
    info->wait_for = 1024;
    info->iovec = &info->tmp_iovec;
    info->iovec->iov_base = (globus_byte_t *)0x100;
    info->iovec->iov_len = 1024;
    info->iovec_count = 1;

    info->handle = driver_handle;

    /* verify close isn't called twice */
    globus_assert(info->handle->closed_iface == GLOBUS_FALSE);

    info->handle->closed_iface = GLOBUS_TRUE;

    res = test_bounce_next_op(info, op);
    if(res != GLOBUS_SUCCESS)
    {
        bounce_handle_destroy(info->handle);
        goto err;
    }
    GlobusXIOTestDebugInternalExit();
    return GLOBUS_SUCCESS;    

  err:

    GlobusXIOTestDebugInternalExitWithError();
    return res;
}
Exemplo n.º 21
0
static globus_result_t
globus_l_xio_bounce_write(
    void *                              driver_handle,
    const globus_xio_iovec_t *          iovec,
    int                                 iovec_count,
    globus_xio_operation_t              op)
{
    bounce_info_t *                     info;
    globus_result_t                     res = GLOBUS_SUCCESS;
    globus_size_t                       wait_for;
    GlobusXIOName(globus_l_xio_bounce_write);

    GlobusXIOTestDebugInternalEnter();
    wait_for = globus_xio_operation_get_wait_for(op);

    info = (bounce_info_t *)
                globus_malloc(sizeof(bounce_info_t));
    memset(info, '\0', sizeof(bounce_info_t));
    info->next_op = TEST_WRITE;
    info->bounce_count = 0;
    info->max_count = MAX_COUNT;
    info->start_op = TEST_WRITE;
    info->wait_for = wait_for;
    info->iovec = (globus_xio_iovec_t *)iovec;
    info->iovec_count = iovec_count;
    info->nbytes = 0;

    info->handle = driver_handle;

    res = test_bounce_next_op(info, op);
    if(res != GLOBUS_SUCCESS)
    {
        goto err;
    }

    GlobusXIOTestDebugInternalExit();

    return GLOBUS_SUCCESS;

  err:

    GlobusXIOTestDebugInternalExitWithError();
    return res;
}
/**
 * Extract referral information from a request handle.
 * @ingroup globus_gass_transfer_request
 *
 * This function queries the request handle to determine any referral
 * information that it contains. This function should only be called
 * on request handles in the GLOBUS_GASS_TRANSFER_REQUEST_REFERRED
 * state. If no referral information is stored in the request handle,
 * then the referral will be initialized to an empty referral.
 * The referral must be destroyed by calling
 * globus_gass_transfer_referral_destroy() by the caller.
 *
 * @param request
 *        The request handle to query.
 * @param referral
 *        A pointer to an uninitialized referral structure. It will be
 *        populated by calling this function.
 *
 * @retval GLOBUS_SUCCESS
 *         The referral was successfully extracted from the request
 *         handle.
 * @retval GLOBUS_GASS_TRANSFER_ERROR_NULL_POINTER
 *         The referral pointer was GLOBUS_NULL;
 */
int
globus_gass_transfer_request_get_referral(
    globus_gass_transfer_request_t		request,
    globus_gass_transfer_referral_t *		referral)
{
    globus_gass_transfer_request_struct_t *	req;

    /* Sanity check of arguments */
    if(referral == GLOBUS_NULL)
    {
	return GLOBUS_GASS_TRANSFER_ERROR_NULL_POINTER;
    }
    /* Check for illegal handle */
    req =
	globus_handle_table_lookup(&globus_i_gass_transfer_request_handles,
				   request);
    if(req == GLOBUS_NULL)
    {
	return GLOBUS_GASS_TRANSFER_ERROR_INVALID_USE;
    }
    else if(req->referral_count == 0)
    {
	referral->url = GLOBUS_NULL;
	referral->count = 0;

	return GLOBUS_SUCCESS;
    }
    else
    {
	globus_size_t				i;

	referral->url =
	    globus_malloc(sizeof(char *) * req->referral_count);

	for(i = 0; i < req->referral_count; i++)
	{
	    referral->url[i] = globus_libc_strdup(req->referral_url[i]);
	}
	referral->count = req->referral_count;

	return GLOBUS_SUCCESS;
    }
}
static char *
s_string_copy (char * string)
{
  char * ns;
  int i, l;

  if ( string == NULL ) return NULL;

  l = strlen (string);

  ns = globus_malloc (sizeof(char *) * (l + 1));
  if ( ns == NULL ) return NULL;

  for (i=0; i<l; i++) {
    ns[i] = string[i];
  }
  ns[l] = '\00';

  return ns;
}
Exemplo n.º 24
0
/**
 * Copy the instance data of a Globus GSSAPI Error object.
 * @ingroup globus_gssapi_error_object 
 * 
 * @param src
 *        The source instance data
 * @param dst
 *        The destination instance data
 * @return
 *        void
 */
static
void
globus_l_error_copy_gssapi(
    void *                              src,
    void **                             dst)
{
    globus_l_gssapi_error_data_t *      copy;
    globus_l_gssapi_error_data_t *      data;
    
    if(src == NULL || dst == NULL) return;
    
    data = (globus_l_gssapi_error_data_t *) src;
    copy = (globus_l_gssapi_error_data_t *)
        globus_malloc(sizeof(globus_l_gssapi_error_data_t));
    if(copy)
    {
        copy->major_status = data->major_status;
        copy->minor_status = data->minor_status;
        copy->is_globus_gsi = data->is_globus_gsi;
    }
    
    *dst = copy;
}/* globus_l_error_copy_gssapi */
Exemplo n.º 25
0
/*
 * globus_l_module_increment()
 */
static globus_bool_t
globus_l_module_increment(
    globus_module_descriptor_t *	module_descriptor,
    globus_l_module_key_t		parent_key,
    globus_module_deactivate_proxy_cb_t deactivate_cb,
    void *                              user_arg)
{
    globus_l_module_entry_t *		entry;
    
    entry =
	globus_hashtable_lookup(
	    &globus_l_module_table,
	    (void *) module_descriptor->activation_func);

    if (entry != GLOBUS_NULL)
    {
	/*
	 * The module has already been registered.  Increment its reference
	 * counter and add any new clients to the dependency list
	 */
	entry->reference_count++;
	if (parent_key != GLOBUS_NULL
	    && globus_list_search(entry->clients,
				  (void *) parent_key) == GLOBUS_NULL)
	{
	    globus_list_insert(&entry->clients, (void *) parent_key);
	}

	if(entry->reference_count == 1)
	{
	    entry->deactivate_cb = deactivate_cb;
	    entry->user_arg = user_arg;
	    return GLOBUS_TRUE;
	}
	else
	{
    	    return GLOBUS_FALSE;
	}
    }
    else
    {
	/*
	 * This is the first time this module has been registered.  Create a
	 * new entry in the modules table.
	 */
	entry = (globus_l_module_entry_t *)
	    globus_malloc(sizeof(globus_l_module_entry_t));
	globus_assert(entry != GLOBUS_NULL);

	entry->descriptor = module_descriptor;
	entry->reference_count = 1;
	entry->clients = GLOBUS_NULL;
	entry->deactivate_cb = deactivate_cb;
	entry->user_arg = user_arg;
	if (parent_key != GLOBUS_NULL)
	{
	    globus_list_insert(&entry->clients, (void *) parent_key);
	}
	
	globus_hashtable_insert(
	    &globus_l_module_table,
	    (void *) module_descriptor->activation_func,
	    entry);

	globus_list_insert(&globus_l_module_list, entry);
	
	return GLOBUS_TRUE;
    }
}
Exemplo n.º 26
0
int
main(
    int                                 argc,
    char *                              argv[])
{
    int                                 rc;
    globus_bool_t                       server = GLOBUS_FALSE;
    char                                gets_buffer[1024];
    http_test_info_t *			info;
    performance_t                       perf;

    info = (http_test_info_t *) globus_malloc(sizeof(http_test_info_t));
    info->version = GLOBUS_XIO_HTTP_VERSION_UNSET;
    info->transfer_encoding = NULL;
    info->iterations = 100;
    info->temp_iterations = 100;
    info->size = 0;
    info->contact = NULL;
    while ((rc = getopt(argc, argv, "h:cst:b:v:i:")) != EOF)
    {
        switch (rc)
        {
            case 'h':
                usage(argv[0]);
                exit(0);
            case 'c':
                server = GLOBUS_FALSE;
                info->contact = fgets(gets_buffer, sizeof(gets_buffer), stdin);
                break;
            case 's':
                server = GLOBUS_TRUE;
                info->contact = NULL;
                break;
            case 't':
                if ((strcmp(optarg, CHUNKED) == 0)
                        || (strcmp(optarg, IDENTITY) == 0))
                {
                    info->transfer_encoding = optarg;
                }
                else
                {
                    usage(argv[0]);
                    exit(1);
                }
                break;
            case 'b':
                sscanf(optarg, "%zd", &info->size);

                if (rc != 1)
                {
                    usage(argv[0]);
                    exit(1);
                }
                break;
            case 'v':
                if (strcmp(optarg, HTTP_1_0) == 0)
                {
                    info->version = GLOBUS_XIO_HTTP_VERSION_1_0;
                }
                else if (strcmp(optarg, HTTP_1_1) == 0)
                {
                    info->version = GLOBUS_XIO_HTTP_VERSION_1_1;
                }
                else
                {
                    usage(argv[0]);
                    exit(1);
                }
                break;
            case 'i':
                info->iterations = atoi(optarg);

                if (info->iterations <= 0)
                {
                    usage(argv[0]);
                    exit(1);
                }
		info->temp_iterations = info->iterations;
                break;
            default:
                usage(argv[0]);
                exit(1);
        }
    }
    if ((!server) && (info->contact == NULL))
    {
        usage(argv[0]);
        exit(1);
    }

    if (info->iterations > 1 && info->version == GLOBUS_XIO_HTTP_VERSION_1_0)
    {
        fprintf(stderr,
                "Can't have multiple iterations with HTTP/1.0 server\n");
        usage(argv[0]);
        exit(1);
    }

    rc = http_test_initialize(
		&info->tcp_driver, &info->http_driver, &info->stack);

    if (rc != 0)
    {
        goto error_exit;
    }

    if (server)
    {
	performance_init(
	    &perf,
	    server_test,
	    throughput_next_size,
	    info->iterations,
	    "throughput-globus-xio-http",
	    info->size);
	performance_start_slave(&perf, info);
    }
    else
    {
	performance_init(
	    &perf,
	    client_test,
	    throughput_next_size,
	    info->iterations,
	    "throughput-globus-xio-http",
	    info->size);
	rc = performance_start_master(&perf, info);
	if (rc != 0)
	{
	    goto error_exit;
	}
	performance_write_timers(&perf);
    }

    globus_xio_stack_destroy(info->stack);
    globus_xio_driver_unload(info->tcp_driver);
    globus_xio_driver_unload(info->http_driver);

    globus_module_deactivate_all();

error_exit:
    if (rc == 0)
    {
        printf("Success\n");
    }
    else
    {
        printf("Error\n");
    }
    return rc;
}
Exemplo n.º 27
0
static globus_result_t
globus_l_xio_telnet_open(
    const globus_xio_contact_t *        contact_info,
    void *                              driver_link,
    void *                              driver_attr,
    globus_xio_operation_t              op)
{
    globus_result_t                     res;
    globus_l_xio_telnet_attr_t *       attr;
    globus_l_xio_telnet_handle_t *     handle;
    GlobusXIOName(globus_l_xio_telnet_open);

    /* decide what attr to use */
    if(driver_attr != NULL)
    {
        attr = (globus_l_xio_telnet_attr_t *) driver_attr;
    }
    else if(driver_link != NULL)
    {
        attr = (globus_l_xio_telnet_attr_t *) driver_link;
    }
    else
    {
        /* default */
        attr = NULL;
    }

    handle = (globus_l_xio_telnet_handle_t *) globus_calloc(
        sizeof(globus_l_xio_telnet_handle_t), 1);
    if(handle == NULL)
    {
        res = GlobusXIOErrorMemory("handle");
        goto error_handle_alloc;
    }

    if(attr != NULL && attr->force_server)
    {
        handle->client = GLOBUS_FALSE;
    }
    else
    {       
        handle->client = driver_link ? GLOBUS_FALSE : GLOBUS_TRUE;
    }

    handle->read_buffer_length = GLOBUS_L_XIO_TELNET_DEFAULT_BUFFER_SIZE;
    handle->read_buffer = globus_malloc(handle->read_buffer_length);
    if(handle->read_buffer == NULL)
    {
        res = GlobusXIOErrorMemory("buffer");
        goto error_buffer_alloc;
    }
    globus_mutex_init(&handle->mutex, NULL);
    globus_fifo_init(&handle->write_q);

    handle->create_buffer_mode = attr 
        ? attr->create_buffer_mode : GLOBUS_FALSE;

    res = globus_xio_driver_pass_open(
        op,
        contact_info,
        globus_l_xio_telnet_open_cb,
        handle);
    if(res != GLOBUS_SUCCESS)
    {
        goto error_pass;
    }

    return GLOBUS_SUCCESS;
error_pass:
    globus_free(handle->read_buffer);
    globus_mutex_destroy(&handle->mutex);
    globus_fifo_destroy(&handle->write_q);
error_buffer_alloc:
    globus_free(handle);
error_handle_alloc:
    return res;
}
Exemplo n.º 28
0
static void
globus_l_xio_telnet_request_data(
    globus_l_xio_telnet_handle_t *      handle,
    globus_xio_operation_t              op)
{
    globus_bool_t                       complete;
    globus_size_t                       end;
    globus_size_t                       len;
    globus_result_t                     res = GLOBUS_SUCCESS;
    globus_size_t                       remainder;
    globus_size_t                       diff;

    if(!globus_fifo_empty(&handle->write_q))
    {
        handle->write_iovec.iov_base = globus_fifo_dequeue(&handle->write_q);
        handle->write_iovec.iov_len = 3; 
        res = globus_xio_driver_pass_write(
            op,
            &handle->write_iovec,
            1,
            3,
            globus_l_xio_telnet_cmd_write_cb,
            handle);
        if(res != GLOBUS_SUCCESS)
        {
            goto err;
        }
        return;
    }

    /* is there a full command in there, updates read_buffer_ndx */
    complete = globus_l_xio_telnet_check_data(handle, &end);
    if(complete)
    {
        remainder = handle->read_buffer_ndx - end;
        if(handle->create_buffer_mode)
        {
            len = end;
            handle->user_read_iovec->iov_base = globus_malloc(len);
            memcpy(handle->user_read_iovec->iov_base, handle->read_buffer, len);
            handle->user_read_iovec->iov_len = len;
        }
        else
        {
            if(handle->user_read_iovec->iov_len >= end)
            {
                len = end;
            }
            else
            {
                diff = end - handle->user_read_iovec->iov_len;
                len = handle->user_read_iovec->iov_len;
                end -= diff;
                remainder += diff;
            }
            memcpy(handle->user_read_iovec->iov_base, handle->read_buffer, len);
        }

        /* move remainder to the begining of the buffer */
        if(remainder > 0)
        {
            memmove(handle->read_buffer, &handle->read_buffer[end], remainder);
        }
        handle->read_buffer_ndx = remainder;

        handle->finish = GLOBUS_TRUE;
        handle->finish_len = len;
        handle->finish_res = GLOBUS_SUCCESS;
    }
    else
    {
        if(handle->read_buffer_ndx + 1 >= handle->read_buffer_length)
        {
            handle->read_buffer_length *= 2;
            handle->read_buffer = globus_libc_realloc(
                handle->read_buffer, handle->read_buffer_length);
        }
        handle->read_iovec.iov_base = 
            &handle->read_buffer[handle->read_buffer_ndx];
        handle->read_iovec.iov_len = 
            handle->read_buffer_length - handle->read_buffer_ndx;
        res = globus_xio_driver_pass_read(
            op,
            &handle->read_iovec,
            1,
            1,
            globus_l_xio_telnet_read_cb,
            handle);
        if(res != GLOBUS_SUCCESS)
        {
            goto err;
        }
    }

    return;

  err:
    handle->finish = GLOBUS_TRUE;
    handle->finish_len = 0;
    handle->finish_res = res;
}
Exemplo n.º 29
0
/*
 *  In coming buffer may shrink, if there are telnet commands in the
 *  buffer write commands are added to the write queue.
 */ 
static globus_bool_t
globus_l_xio_telnet_check_data(
    globus_l_xio_telnet_handle_t *      handle,
    globus_size_t *                     length)
{
    globus_bool_t                       done = GLOBUS_FALSE;
    globus_size_t                       len;
    int                                 ndx;
    globus_byte_t *                     buffer;

    len = handle->read_buffer_ndx;
    buffer = handle->read_buffer;

    ndx = 0;
    while(ndx < len && !done)
    {
        if(handle->last_char == GLOBUS_XIO_TELNET_IAC)
        {
            switch(buffer[ndx])
            {
                case GLOBUS_XIO_TELNET_WILL:
                    handle->write_buffer = globus_malloc(3);
                    handle->write_buffer[0] = GLOBUS_XIO_TELNET_IAC;
                    handle->write_buffer[1] = GLOBUS_XIO_TELNET_DONT;
                    break;

                case GLOBUS_XIO_TELNET_DO:
                    handle->write_buffer = globus_malloc(3);
                    handle->write_buffer[0] = GLOBUS_XIO_TELNET_IAC;
                    handle->write_buffer[1] = GLOBUS_XIO_TELNET_WONT;
                    break;

                /* 2 byte commands */
                default:
                    /* do not copy a byte */
                    break;
            }
            handle->last_char = buffer[ndx];
            len--;
            if(ndx < len)
            {
                memmove(&buffer[ndx], &buffer[ndx + 1], len - ndx);
            }
        }
        else if(handle->last_char == GLOBUS_XIO_TELNET_WILL ||
            handle->last_char == GLOBUS_XIO_TELNET_DO)
        {
            if(handle->write_buffer != NULL)
            {
                handle->write_buffer[2] = buffer[ndx];
                globus_fifo_enqueue(&handle->write_q, handle->write_buffer);
                handle->write_buffer = NULL;
            }
            handle->last_char = buffer[ndx];
            len--;
            if(ndx < len)
            {
                memmove(&buffer[ndx], &buffer[ndx + 1], len - ndx);
            }
        }
        else if(handle->last_char == GLOBUS_XIO_TELNET_WONT ||
            handle->last_char == GLOBUS_XIO_TELNET_DO)
        {
            handle->last_char = buffer[ndx];
            len--;
            if(ndx < len)
            {
                memmove(&buffer[ndx], &buffer[ndx + 1], len - ndx);
            }
        }
        else if((buffer[ndx] >= 32 && buffer[ndx] <= 126) || 
            buffer[ndx] == GLOBUS_XIO_TELNET_NULL ||
            buffer[ndx] == GLOBUS_XIO_TELNET_BELL ||
            buffer[ndx] == GLOBUS_XIO_TELNET_BS ||
            buffer[ndx] == GLOBUS_XIO_TELNET_HT ||
            buffer[ndx] == GLOBUS_XIO_TELNET_CR ||
            buffer[ndx] == GLOBUS_XIO_TELNET_VT ||
            buffer[ndx] == GLOBUS_XIO_TELNET_FF)
        {
            handle->last_char = buffer[ndx];
            ndx++;
        }
        else if(buffer[ndx] == GLOBUS_XIO_TELNET_LF &&
            handle->last_char == GLOBUS_XIO_TELNET_CR)
        {
            if(handle->client) /* do special ftp checking here */
            {
                if(ndx < handle->line_start_ndx + 5 || 
                    handle->read_buffer[handle->line_start_ndx+3] == ' ')
                {
                    handle->line_start_ndx = 0;
                    handle->last_char = '\0';
                    done = GLOBUS_TRUE;
                }
                else
                {
                    handle->line_start_ndx = ndx+1;
                    handle->last_char = buffer[ndx];
                }
            }
            else
            {
                handle->last_char = '\0';
                done = GLOBUS_TRUE;
            }
            ndx++;
        }
        else
        {
            handle->last_char = buffer[ndx];
            len--;
            if(ndx < len)
            {
                memmove(&buffer[ndx], &buffer[ndx + 1], len - ndx);
            }
        }
    }
    handle->read_buffer_ndx = len;
    *length = ndx;

    return done;
}
globus_object_t *
globus_i_ftp_client_wrap_ftp_error(
    globus_module_descriptor_t *        base_source,
    int                                 code,
    const char *                        message,
    int                                 error_type,
    const char *                        source_file,
    const char *                        source_func,
    int                                 source_line,
    const char *                        format,
    ...)
{
    va_list                             ap;
    globus_object_t *                   error;
    globus_object_t *                   causal_error;
    globus_l_error_ftp_data_t *         data;

    causal_error = globus_object_construct(GLOBUS_ERROR_TYPE_FTP);
    if(!causal_error)
    {
        goto error_object;
    }
    
    data = (globus_l_error_ftp_data_t *)
        globus_malloc(sizeof(globus_l_error_ftp_data_t));
    if(!data)
    {
        goto error_data;
    }
    
    data->code = code;
    data->message = globus_libc_strdup(message);
    globus_object_set_local_instance_data(causal_error, data);
    globus_error_initialize_base(causal_error, base_source, NULL);

    va_start(ap, format);

    error = globus_error_v_construct_error(
        base_source,
        causal_error,
        error_type,
        source_file,
        source_func,
        source_line,
        format,
        ap);

    va_end(ap);

    if(!error)
    {
        goto error_construct;
    }

    return error;

error_construct:
error_data:
    globus_object_free(causal_error);

error_object:
    return NULL;
}