globus_result_t
globus_gridftp_server_control_attr_init(
    globus_gridftp_server_control_attr_t *  in_attr)
{
    globus_i_gsc_attr_t *                   attr;
    globus_result_t                         res;
    GlobusGridFTPServerName(globus_gridftp_server_control_attr_init);

    GlobusGridFTPServerDebugEnter();

    if(in_attr == NULL)
    {
        res = GlobusGridFTPServerErrorParameter("in_attr");
        goto err;
    }

    attr = (globus_i_gsc_attr_t *) globus_calloc(
                1, sizeof(globus_i_gsc_attr_t));
    if(attr == NULL)
    {
        res = GlobusGridFTPServerControlErrorSytem();
        goto err;
    }

    globus_hashtable_init(
        &attr->funcs.send_cb_table,
        GLOBUS_GRIDFTP_SERVER_HASHTABLE_SIZE,
        globus_hashtable_string_hash,
        globus_hashtable_string_keyeq);

    globus_hashtable_init(
        &attr->funcs.recv_cb_table,
        GLOBUS_GRIDFTP_SERVER_HASHTABLE_SIZE,
        globus_hashtable_string_hash,
        globus_hashtable_string_keyeq);

    attr->funcs.resource_cb = NULL;
    attr->version_ctl = GLOBUS_GRIDFTP_VERSION_CTL;
    attr->modes = globus_libc_strdup("ES");
    attr->types = globus_libc_strdup("AI");
    attr->base_dir = globus_libc_strdup("/");

    *in_attr = attr;

    GlobusGridFTPServerDebugExit();

    return GLOBUS_SUCCESS;

  err:

    GlobusGridFTPServerDebugExitWithError();

    return res;
}
/**
 * Initialize a Globus Callout Handle
 * @ingroup globus_callout_handle
 *
 * @param handle
 *        Pointer to the handle that is to be initialized
 * @return
 *        GLOBUS_SUCCESS if successful
 *        A Globus error object on failure:
 *            GLOBUS_CALLOUT_ERROR_WITH_HASHTABLE
 */
globus_result_t
globus_callout_handle_init(
    globus_callout_handle_t *           handle)
{
    int                                 rc;
    globus_result_t                     result = GLOBUS_SUCCESS;

    static char *                       _function_name_ =
        "globus_callout_handle_init";

    GLOBUS_I_CALLOUT_DEBUG_ENTER;

    *handle = malloc(sizeof(globus_i_callout_handle_t));

    if(*handle == NULL)
    {
        GLOBUS_CALLOUT_MALLOC_ERROR(result);
        goto exit;
    }
    
    if((rc = globus_hashtable_init(&((*handle)->symbol_htable),
                                   GLOBUS_I_CALLOUT_HASH_SIZE,
                                   globus_hashtable_string_hash,
                                   globus_hashtable_string_keyeq)) < 0)
    {
        free(*handle);
        GLOBUS_CALLOUT_ERROR_RESULT(
            result,
            GLOBUS_CALLOUT_ERROR_WITH_HASHTABLE,
            ("globus_hashtable_init retuned %d", rc));
        goto exit;
    }    

    if((rc = globus_hashtable_init(&((*handle)->library_htable),
                                   GLOBUS_I_CALLOUT_HASH_SIZE,
                                   globus_hashtable_string_hash,
                                   globus_hashtable_string_keyeq)) < 0)
    {
        globus_hashtable_destroy(&((*handle)->symbol_htable));
        free(*handle);
        GLOBUS_CALLOUT_ERROR_RESULT(
            result,
            GLOBUS_CALLOUT_ERROR_WITH_HASHTABLE,
            ("globus_hashtable_init retuned %d", rc));
        goto exit;
    }    

    GLOBUS_I_CALLOUT_DEBUG_EXIT;

 exit:
    
    return result;
}/*globus_callout_handle_init*/
/*
 * globus_l_module_initialize()
 */
static void
globus_l_module_initialize()
{
    /*
     * Initialize the threads package (can't use the standard interface since
     * it depends on threads)
     */
    globus_i_thread_pre_activate();
    globus_i_memory_pre_activate();
    /*
     * Initialize the registered module table and list
     */
    globus_hashtable_init(&globus_l_module_table,
			  GLOBUS_L_MODULE_TABLE_SIZE,
			  globus_hashtable_voidp_hash,
			  globus_hashtable_voidp_keyeq);

    globus_l_module_list = GLOBUS_NULL;
    
    /*
     * Initialize the recursive mutex
     */
    globus_l_module_mutex_init(&globus_l_module_mutex);
    
    globus_thread_key_create(&globus_l_activate_parent_key, NULL);
    globus_thread_key_create(&globus_l_deactivate_parent_key, NULL);
    
    /*
     * Now finish initializing the threads package
     */
    globus_module_activate(GLOBUS_THREAD_MODULE);
}
/******************************************************************************
Function: globus_l_gass_server_ez_activate()

Description: 

Parameters: 

Returns: 
******************************************************************************/
static int
globus_l_gass_server_ez_activate(void)
{
     int rc;
   
    rc = globus_module_activate(GLOBUS_COMMON_MODULE); 
    if(rc != GLOBUS_SUCCESS)
    {
        return rc;
    }
	
    rc = globus_module_activate(GLOBUS_GASS_TRANSFER_MODULE);
    if(rc != GLOBUS_SUCCESS)
    {
        return rc;
    }

    globus_mutex_init(&globus_l_gass_server_ez_mutex,
		      GLOBUS_NULL);

    globus_hashtable_init(&globus_l_gass_server_ez_listeners,
                          16,
                          globus_hashtable_int_hash,
                          globus_hashtable_int_keyeq);

    return GLOBUS_SUCCESS;
} /* globus_l_gass_server_ez_activate() */
globus_result_t
globus_dsi_rest_test_server_init(
    char                              **contact)
{
    globus_result_t                     result = GLOBUS_SUCCESS;
    globus_thread_t                     thread;
    globus_xio_attr_t                   xio_attr;

    server_done = false;
    globus_mutex_init(&server_done_mutex, NULL);
    globus_cond_init(&server_done_cond, NULL);
    result = globus_hashtable_init(
            &server_routes,
            43,
            globus_hashtable_string_hash,
            globus_hashtable_string_keyeq);
    if (result != GLOBUS_SUCCESS)
    {
        goto hashtable_init_fail;
    }

    result = globus_xio_driver_load("tcp", &tcp_driver);
    if (result != GLOBUS_SUCCESS)
    {
        goto tcp_load_fail;
    }
    result = globus_xio_driver_load("http", &http_driver);
    if (result != GLOBUS_SUCCESS)
    {
        goto http_load_fail;
    }
    result = globus_xio_stack_init(&xio_stack, NULL);
    if (result != GLOBUS_SUCCESS)
    {
        goto stack_init_fail;
    }
    result = globus_xio_stack_push_driver(xio_stack, tcp_driver);
    if (result != GLOBUS_SUCCESS)
    {
        goto stack_push_fail;
    }
    result = globus_xio_stack_push_driver(xio_stack, http_driver);
    if (result != GLOBUS_SUCCESS)
    {
        goto stack_push_fail;
    }
    result = globus_xio_attr_init(
            &xio_attr);

    result = globus_xio_attr_cntl(
            xio_attr,
            NULL,
            GLOBUS_XIO_ATTR_SET_TIMEOUT_ACCEPT,
            NULL,
            &(globus_reltime_t) { .tv_sec = 1 },
static
int
globus_l_net_manager_python_activate(void)
{
    Py_Initialize();
    globus_mutex_init(&globus_l_python_modules_lock, NULL);
    globus_hashtable_init(
            &globus_l_python_modules,
            7,
            globus_hashtable_string_hash, 
            globus_hashtable_string_keyeq); 
    globus_module_activate(GLOBUS_NET_MANAGER_MODULE);
    return globus_net_manager_register(
        &globus_l_net_manager_python,
        GlobusExtensionMyModule(globus_net_manager_python));
}
//! [Module Descriptor and Activation]
static
int
globus_l_net_manager_logging_activate(void)
{
    globus_hashtable_init(
        &globus_l_nm_logging_logfiles,
        7,
        globus_hashtable_string_hash, 
        globus_hashtable_string_keyeq);
    int rc = globus_module_activate(GLOBUS_NET_MANAGER_MODULE);
    if (rc == 0)
    {
        rc = globus_net_manager_register(
            &globus_l_net_manager_logging, 
            GlobusExtensionMyModule(globus_net_manager_logging));
    }
    return rc;
}
/**
 * Initialize an HTTP header info structure
 * @ingroup globus_i_xio_http_header_info
 *
 * All fields of the @a header_info structure will be initialized to their
 * default values. If this function returns a failre, the header_info
 * should be considered uninitialized.
 *
 * @param header_info
 *     Header information structure to initialize.
 *
 * @retval GLOBUS_SUCCESS
 *     Header initialized successfully.
 * @retval GLOBUS_XIO_ERROR_MEMORY
 *     Initialization failed due to memory constraints.
 */
globus_result_t
globus_i_xio_http_header_info_init(
    globus_i_xio_http_header_info_t *   header_info)
{
    int                                 rc;
    globus_result_t                     result = GLOBUS_SUCCESS;
    GlobusXIOName(globus_i_xio_http_header_info_init);

    memset(header_info, '\0', sizeof(globus_i_xio_http_header_info_t));

    rc = globus_hashtable_init(
            &header_info->headers,
            16,
            globus_hashtable_string_hash,
            globus_hashtable_string_keyeq);

    if (rc != GLOBUS_SUCCESS)
    {
        result = GlobusXIOErrorMemory("hashtable");
    }
    return result;
}
int
globus_extension_registry_set_hashing(
    globus_extension_registry_t *       registry,
    globus_hashtable_hash_func_t        hash_func,
    globus_hashtable_keyeq_func_t       keyeq_func)
{
    int                                 rc = GLOBUS_SUCCESS;
    GlobusFuncName(globus_extension_registry_remove);
    
    GlobusExtensionDebugEnter();
    
    globus_rmutex_lock(&globus_l_extension_mutex);
    {
        /* if registry->initialized == true,
         * can't detect if this is misuse or just the result of being
         * activated after a deactivate, so just return success
         */
        if(!registry->initialized)
        {
            rc = globus_hashtable_init(
                &registry->table,
                20,
                hash_func,
                keyeq_func);
            if(rc == GLOBUS_SUCCESS)
            {
                registry->initialized = GLOBUS_TRUE;
                registry->user_hashing = GLOBUS_TRUE;
            }
        }
    }
    globus_rmutex_unlock(&globus_l_extension_mutex);
    
    GlobusExtensionDebugExit();
    
    return rc;
}
Beispiel #10
0
void
globus_module_setenv(
    const char *                        name,
    const char *                        value)
{
    int				rc;

    /*
     *  First, check to see if the environment mutex has been initialized
     */

    if(globus_l_environ_mutex_initialized == GLOBUS_FALSE)
    {
	if(globus_i_module_initialized == GLOBUS_TRUE)
	{
	    rc = globus_mutex_init(&globus_l_environ_hashtable_mutex,
                           (globus_mutexattr_t *) GLOBUS_NULL);
            globus_assert (rc == 0);
	    globus_l_environ_mutex_initialized = GLOBUS_TRUE;
	}
    }
   
    /*
     *  then, check to see if the environment hash table has been initialized
     */
 

    if((globus_l_environ_initialized == GLOBUS_FALSE))
    {
	if(globus_i_module_initialized==GLOBUS_TRUE)
	{
	    globus_mutex_lock(&globus_l_environ_hashtable_mutex);
	}

        globus_hashtable_init(&globus_l_environ_table,
                          GLOBUS_L_ENVIRON_TABLE_SIZE,
                          globus_hashtable_string_hash,
                          globus_hashtable_string_keyeq);

	globus_l_environ_initialized = GLOBUS_TRUE;

	if(globus_i_module_initialized == GLOBUS_TRUE)
	{
	    globus_mutex_unlock(&globus_l_environ_hashtable_mutex);
	}
    }

    /*
     *  Then actually put the name and value into the hash table
     */

    if(globus_i_module_initialized == GLOBUS_TRUE)
    {
	globus_mutex_lock(&globus_l_environ_hashtable_mutex);
    }

    globus_hashtable_remove(
	&globus_l_environ_table,
	(void *) name);
    globus_hashtable_insert(
         &globus_l_environ_table,
         (void *) name,
         (void *) value);

    if(globus_i_module_initialized == GLOBUS_TRUE)
    {
	globus_mutex_unlock(&globus_l_environ_hashtable_mutex);
    }

}
/*
 * PURPOSE:
 *     Verify that
 *     globus_gram_protocol_unpack_job_request_reply_with_extensions()
 *     deals with messages containing extension attributes not defined in the
 *     GRAM2
 *     protocol.
 * TEST STEPS:
 *   - Construct a status update message with the
 *     globus_gram_protocol_pack_job_request_reply_with_extensions()
 *     function.
 *   - Call globus_gram_protocol_unpack_job_request_reply_with_extensions() and
 *     expect a GLOBUS_SUCCESS
 *   - Check that our new attribute is in the hash
 */
int
test_extra_attributes(void)
{
    globus_byte_t *                     message;
    globus_size_t                       message_size;
    globus_hashtable_t                  hashtable;
    globus_gram_protocol_extension_t *  entry;
    int                                 rc;
    char *                              expected[] =
    {
            "protocol-version",
            "status",
            "job-manager-url",
            "attribute"
    };
    int                                 i;
    int                                 status;
    char *                              job_contact;

    rc = globus_hashtable_init(
            &hashtable,
            89,
            globus_hashtable_string_hash,
            globus_hashtable_string_keyeq);
    test_assert(
            rc == GLOBUS_SUCCESS,
            ("Error initializing hashtable (out of memory?)\n"));
    entry = malloc(sizeof(globus_gram_protocol_extension_t));
    test_assert(entry != NULL,
            ("Error allocating hash entry (out of memory?)\n"));
    entry->attribute = "attribute";
    entry->value = "value";
    rc = globus_hashtable_insert(&hashtable, entry->attribute, entry);

    rc = globus_gram_protocol_pack_job_request_reply_with_extensions(
            GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE,
            "https://example.org:123/12/34",
            &hashtable,
            &message,
            &message_size);
    test_assert(rc == GLOBUS_SUCCESS,
            ("Error packing status message: %d (%s)\n",
            rc, globus_gram_protocol_error_string(rc)));

    globus_hashtable_destroy(&hashtable);
    free(entry);
    hashtable = NULL;

    test_assert(
            rc == GLOBUS_SUCCESS,
            ("Error constructing test message: %d (%s)\n",
            rc,
            globus_gram_protocol_error_string(rc)));

    rc = globus_gram_protocol_unpack_job_request_reply_with_extensions(
            message,
            message_size,
            &status,
            &job_contact,
            &hashtable);
    test_assert(
            rc == GLOBUS_SUCCESS,
            ("Error parsing test message: %d (%s)\n",
            rc,
            globus_gram_protocol_error_string(rc)));

    /* check that expected attributes were parsed */
    for (i = 0; i < ARRAY_LEN(expected); i++)
    {
        entry = globus_hashtable_lookup(&hashtable, expected[i]);
        test_assert(
                entry != NULL,
                ("Missing expected attribute %s\n", expected[i]));
    }

    test_assert(ARRAY_LEN(expected) == globus_hashtable_size(&hashtable),
            ("Hash table contains %d entries, expected %d",
             globus_hashtable_size(&hashtable),
             ARRAY_LEN(expected)));

    globus_gram_protocol_hash_destroy(&hashtable);

    free(message);

    return 0;
}
int
globus_extension_registry_add(
    globus_extension_registry_t *       registry,
    void *                              symbol,
    globus_module_descriptor_t *        module,
    void *                              data)
{
    globus_l_extension_handle_t *       entry;
    GlobusFuncName(globus_extension_registry_add);
    
    GlobusExtensionDebugEnterSymbol(registry->user_hashing ? "" : symbol);
    
    if(!data || !symbol || !registry)
    {
        goto error_params;
    }
    
    entry = (globus_l_extension_handle_t *)
        globus_malloc(sizeof(globus_l_extension_handle_t));
    if(!entry)
    {
        goto error_malloc;
    }
    
    entry->owner = (globus_l_extension_module_t *)
        globus_thread_getspecific(globus_l_extension_owner_key);
    entry->module = module;
    entry->datum = data;
    entry->ref = 1;
    entry->symbol = symbol;
    entry->user_hashing = registry->user_hashing;
    
    globus_rmutex_lock(&globus_l_extension_mutex);
    {
        if(!registry->initialized)
        {
            if(globus_hashtable_init(
                &registry->table,
                20,
                globus_hashtable_string_hash,
                globus_hashtable_string_keyeq) != GLOBUS_SUCCESS)
            {
                goto error_init;
            }
            
            registry->initialized = GLOBUS_TRUE;
        }
        
        if(globus_hashtable_insert(
            &registry->table, entry->symbol, entry) != GLOBUS_SUCCESS)
        {
            goto error_insert;
        }
    }
    globus_rmutex_unlock(&globus_l_extension_mutex);
    
    GlobusExtensionDebugExit();
    return GLOBUS_SUCCESS;

error_insert:
error_init:
    globus_rmutex_unlock(&globus_l_extension_mutex);
    globus_free(entry);
error_malloc:
error_params:
    GlobusExtensionDebugExitWithError();
    return GLOBUS_FAILURE;
}
/**
 * load config file.  substitute $BUILD_FLAVOR for build_flavor,
 */
static
int
globus_l_extension_activate(void)
{
    static globus_bool_t                initialized = GLOBUS_FALSE;
    globus_result_t                     result = GLOBUS_SUCCESS;
    GlobusFuncName(globus_l_extension_activate);
    
    if(!initialized)
    {
        GlobusDebugInit(GLOBUS_EXTENSION, TRACE VERBOSE DLL);
        GlobusExtensionDebugEnter();
    
        globus_rmutex_init(&globus_l_libtool_mutex, NULL);
        globus_thread_key_create(&globus_l_libtool_key, NULL);

#       ifndef BUILD_STATIC_ONLY
        if(lt_dlinit() != 0)
        {
            goto error_dlinit;
        }
#       if HAVE_LT_DLMUTEX_REGISTER
        if(lt_dlmutex_register(
            globus_l_libtool_mutex_lock,
            globus_l_libtool_mutex_unlock,
            globus_l_libtool_set_error,
            globus_l_libtool_get_error) != 0)
        {
            goto error_dlmutex;
        }
#       endif
#       endif /* !BUILD_STATIC_ONLY */
        
        globus_hashtable_init(
            &globus_l_extension_loaded,
            32,
            globus_hashtable_string_hash,
            globus_hashtable_string_keyeq);
        globus_hashtable_init(
            &globus_l_extension_builtins,
            32,
            globus_hashtable_string_hash,
            globus_hashtable_string_keyeq);
            
        globus_rmutex_init(&globus_l_extension_mutex, NULL);
        globus_thread_key_create(&globus_l_extension_owner_key, NULL);
        
        result = globus_eval_path("${libdir}", &globus_l_globus_location);
        if(result != GLOBUS_SUCCESS)
        {
            goto error_path;
        }

        initialized = GLOBUS_TRUE;
        GlobusExtensionDebugExit();
    }
    
    return GLOBUS_SUCCESS;

error_path:
    globus_hashtable_destroy(&globus_l_extension_builtins);
    globus_hashtable_destroy(&globus_l_extension_loaded);
#   ifndef BUILD_STATIC_ONLY
#   if HAVE_LT_DLMUTEX_REGISTER
error_dlmutex:
#   endif
    lt_dlexit();
error_dlinit:
    GlobusExtensionDebugExitWithError();
    return GLOBUS_FAILURE;
#   endif /* !BUILD_STATIC_ONLY */
}
/*
 * globus_l_gass_cache_config_init()
 *
 * Inits the config structure by reading from a file.
 *  
 * Parameters:
 *  - directory   the GASS cache directory 
 *  - config      the config structure
 *  
 * Returns:
 *  - GLOBUS_SUCCESS upon success
 */
int
globus_l_gass_cache_config_init(
    char *                          file,
    globus_l_gass_cache_config_t *  config)
{
    globus_off_t                    length;
    struct stat                     st;
    int                             i, n, fd, rc, status;
    char                            *p, *q, *r;
    char                            *key, *value;

    memset(config, '\0', sizeof(globus_l_gass_cache_config_t));

    status = GLOBUS_SUCCESS;

    config->buf = GLOBUS_NULL;

    /* open the config file, figure out size, then read the file into
       a buffer */
    fd = open(file, O_RDONLY);

    if (fd < 0)
    {
        status = GLOBUS_L_ERROR_CONFIG_FILE_NOT_FOUND;
        goto cleanup;
    }

    rc = fstat(fd, &st);
    if (rc < 0)
    {
        status = GLOBUS_L_ERROR_CONFIG_FILE_READ;
        goto cleanup;
    }

    length = st.st_size;

    config->buf = malloc(length+1);
    if (config->buf == NULL)
    {
        status = GLOBUS_GASS_CACHE_ERROR_NO_MEMORY;
        goto cleanup;
    }

    for (i=0; i<length; i+=n)
    {
        n = read(fd, config->buf+i, length-i);

        if (n <= 0)
        {
            status = GLOBUS_L_ERROR_CONFIG_FILE_READ;
            goto free_config_buf;
        }
    }
    *(config->buf+length) = '\0';
    
    rc = globus_hashtable_init(&config->table, 16, 
			       globus_hashtable_string_hash,
			       globus_hashtable_string_keyeq);
    if (rc != GLOBUS_SUCCESS)
    {
        status = GLOBUS_GASS_CACHE_ERROR_NO_MEMORY;
        goto free_config_buf;
    }

    for (p=config->buf; (p-config->buf)<length; p=q+1)
    {
	if (!(q = strchr(p, '\n')))
	    q = config->buf+length;

        *q = 0;

	strtrimhead(&p);
	strtrimtail(p);
	if (*p=='#' || !strlen(p))     /* a comment or empty line */
	    continue;

	r = strchr(p, '=');
        if (r == NULL)
        {
            status = GLOBUS_L_ERROR_CONFIG_FILE_PARSE_ERROR;

            goto destroy_hashtable;
        }

	*r = 0;
	key = p;
	value = r+1;
	
	strtrimtail(key);
	strtrimhead(&value);

	globus_hashtable_insert(&config->table,
				(void *) key,
				(void *) value);
    }
    if (fd >= 0)
    {
        close(fd);
    }

    return status;

destroy_hashtable:
    globus_hashtable_destroy(&config->table);
free_config_buf:
    free(config->buf);
    config->buf = NULL;
cleanup:
    if (fd >= 0)
    {
        close(fd);
    }
    return status;
}