Esempio n. 1
0
/* Check that using globus_gram_client_get_jobmanager_version() to talk
 * to the resource management contact specified on the command line yields
 * a response that can be parsed out to include the version and toolkit-version
 * attributes.
 */
static
int
version_test(void)
{
    int                                 rc;
    globus_gram_protocol_extension_t *  extension;
    globus_hashtable_t                  extensions;

    rc = globus_gram_client_get_jobmanager_version(
            rm_contact,
            &extensions);
    test_assert(
            rc == GLOBUS_SUCCESS,
            ("globus_gram_client_get_jobmanager_version() failed: %d (%s)",
            rc,
            globus_gram_protocol_error_string(rc)));
    extension = globus_hashtable_lookup(&extensions, "toolkit-version");
    test_assert(
            extension != NULL,
            ("toolkit-version attribute not present in response"));
    extension = globus_hashtable_lookup(&extensions, "version");
    test_assert(
            extension != NULL,
            ("version attribute not present in response"));
    globus_gram_protocol_hash_destroy(&extensions);

    return rc;
}
Esempio n. 2
0
void
globus_i_module_dump(
    FILE *				out_f)
{
    globus_list_t *			module_list;

    globus_libc_fprintf(out_f, "==========\nModule List\n----------\n");
    
    module_list = globus_l_module_list;
    while(!globus_list_empty(module_list))
    {
	globus_list_t *			client_list;
	globus_l_module_entry_t *	module_entry;

	module_entry = globus_list_first(module_list);
	module_list = globus_list_rest(module_list);

	globus_libc_fprintf(out_f, "%s; cnt=%d",
		module_entry->descriptor->module_name,
		module_entry->reference_count);

	client_list = module_entry->clients;

	if (!globus_list_empty(client_list))
	{
	    void *			client_entry;
	    globus_l_module_entry_t *	client_module_entry;
	    
	    client_entry = globus_list_first(client_list);
	    client_list = globus_list_rest(client_list);
	    client_module_entry =
		globus_hashtable_lookup(&globus_l_module_table, client_entry);
	    globus_libc_fprintf(out_f, "; clients=%s",
		    client_module_entry->descriptor->module_name);
	    
	    while(!globus_list_empty(client_list))
	    {
		client_entry = globus_list_first(client_list);
		client_list = globus_list_rest(client_list);
		client_module_entry =
		    globus_hashtable_lookup(&globus_l_module_table,
					    client_entry);
		globus_libc_fprintf(out_f, ",%s",
			client_module_entry->descriptor->module_name);
	    }
	}

	globus_libc_fprintf(out_f, "\n");
    }

    globus_libc_fprintf(out_f, "==========\n");
}
Esempio n. 3
0
/*
 * globus_l_module_decrement()
 */
static globus_l_module_entry_t *
globus_l_module_decrement(
    globus_module_descriptor_t *	module_descriptor,
    globus_l_module_key_t		parent_key)
{
    globus_l_module_entry_t *		entry;
    
    entry =
	globus_hashtable_lookup(
	    &globus_l_module_table,
	    (void *) module_descriptor->activation_func);
    if (entry == GLOBUS_NULL || entry->reference_count <= 0)
    {
	return NULL;
    }

    entry->reference_count--;
    
    if (parent_key != GLOBUS_NULL)
    {
	globus_list_t *			client_entry;

	
	client_entry = globus_list_search(entry->clients,
					  (void *) parent_key);
	if(client_entry != GLOBUS_NULL)
        {
	    globus_list_remove(&entry->clients, client_entry);
	}
	/* else module was activated outside this parent */
    }

    return entry;
}
Esempio n. 4
0
void gw_em_mad_poll_callback(void *arg, const char * job_contact, 
        globus_gram_client_job_info_t *job_info)
{
    globus_gram_protocol_extension_t *entry;
    int *jid;
    
    jid = (int *) arg;

    if (job_info->protocol_error_code == GLOBUS_SUCCESS)
    {
        if (job_info->job_state == GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE)
            if (job_info->extensions)
            {
                entry = globus_hashtable_lookup(&job_info->extensions, "exit-code");

                if (entry != NULL)
                    printf("POLL %d SUCCESS DONE:%s\n", *jid, entry->value);
                else
                    printf("POLL %d SUCCESS DONE\n", *jid);
            }
            else
                printf("POLL %d SUCCESS DONE\n", *jid);
        else
            printf("POLL %d SUCCESS %s\n", *jid, get_job_state_name(job_info->job_state));
    }
    else
        printf("POLL %d FAILURE %s (%i)\n", *jid,
             globus_gram_client_error_string(job_info->protocol_error_code), job_info->protocol_error_code);
    
    free(jid);
}
Esempio n. 5
0
void *
globus_extension_registry_remove(
    globus_extension_registry_t *       registry,
    void *                              symbol)
{
    globus_l_extension_handle_t *       entry;
    void *                              datum = NULL;
    GlobusFuncName(globus_extension_registry_remove);
    
    GlobusExtensionDebugEnterSymbol(registry->user_hashing ? "" : symbol);
    
    globus_rmutex_lock(&globus_l_extension_mutex);
    {
        if(registry->initialized)
        {
            entry = (globus_l_extension_handle_t *)
                globus_hashtable_lookup(&registry->table, (void *) symbol);
            if(entry && entry->datum)
            {
                datum = entry->datum;
                globus_hashtable_remove(&registry->table, (void *) symbol);
                if(--entry->ref == 0)
                {
                    globus_free(entry);
                }
            }
        }
    }
    globus_rmutex_unlock(&globus_l_extension_mutex);
    
    GlobusExtensionDebugExit();
    return datum;
}
/*
 * Test case:
 *
 * PURPOSE:
 *     Check that
 *     globus_gram_protocol_unpack_message()
 *     correctly unpacks standard GRAM2 messages
 *
 * STEPS:
 *     - Creates a message using server-side API.
 *     - Parses message to hash.
 *     - Verifies that all attributes we expect in the message are present in
 *       the parsed values.
 *     - Verifies that the number of attributes in the message match the count
 *       of ones we expect.
 */
static
int
unpack_test(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",
            "job-manager-url",
            "status",
            "failure-code"
    };
    int                                 i;

    rc = globus_gram_protocol_pack_status_update_message(
            job_id,
            GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE,
            0,
            &message,
            &message_size);
    test_assert(
            rc == GLOBUS_SUCCESS,
            ("# Error constructing test message: %d (%s)\n",
            rc,
            globus_gram_protocol_error_string(rc)));

    rc = globus_gram_protocol_unpack_message(
            message,
            message_size,
            &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;
}
/*
 * Test case: 
 *
 * PURPOSE:
 *     Check that
 *     globus_gram_protocol_unpack_job_request_reply_with_extensions()
 *     correctly unpacks standard GRAM2 messages
 *
 * STEPS:
 *     - Creates a message using server-side API.
 *     - Parses message to extensions hash.
 *     - Verifies that all attributes we expect in the message are present in
 *       the parsed values.
 *     - Verifies that the number of attributes in the message match the count
 *       of ones we expect.
 */
int test_unpack_with_extensions(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",
    };
    int                                 status;
    char *                              job_contact;
    int                                 i;

    rc = globus_gram_protocol_pack_job_request_reply(   
            GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE,
            "https://example.org:123/1/2/",
            &message,
            &message_size);
    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;
}
Esempio n. 8
0
char * 
globus_module_getenv(
    const char *                        name)
{
    char * 			entry;

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

        entry =
           globus_hashtable_lookup(
               &globus_l_environ_table,
               (void *) name); 


	if((globus_i_module_initialized == GLOBUS_TRUE)
	    &&(globus_l_environ_mutex_initialized == GLOBUS_TRUE))
	{
	    globus_mutex_unlock(&globus_l_environ_hashtable_mutex);
	}
    }
    else
    {
        entry=GLOBUS_NULL;
    }

    /*
     *  If we have found an entry, return it
     */

    if (entry!=GLOBUS_NULL)
    {
	return(entry);
    }

    /*
     *  otherwise check system environment
     */

    entry=getenv(name);

    if (entry!=NULL)
    {
	return(entry);
    }

    return(GLOBUS_NULL);
}
Esempio n. 9
0
int
globus_extension_deactivate(
    const char *                        extension_name)
{
    globus_l_extension_module_t *       extension;
    globus_l_extension_module_t *       owner = NULL;
    GlobusFuncName(globus_extension_deactivate);
    
    GlobusExtensionDebugEnterSymbol(extension_name);
    
    if(!extension_name)
    {
        goto error_param;
    }
    
    globus_rmutex_lock(&globus_l_extension_mutex);
    {
        extension = (globus_l_extension_module_t *)
            globus_hashtable_lookup(
                &globus_l_extension_loaded, (void *) extension_name);
        if(!extension || extension->module_ref <= 0)
        {
            goto error_lookup;
        }
        
        extension->module_ref--;
        if(--extension->ref == 0)
        {
            if(extension->owner && --extension->owner->ref == 0)
            {
                owner = extension->owner;
            }

            globus_l_extension_shutdown_extension(extension, GLOBUS_FALSE);
            
            if(owner)
            {
                globus_l_extension_shutdown_extension(owner, GLOBUS_FALSE);
            }
        }
    }
    globus_rmutex_unlock(&globus_l_extension_mutex);
    
    GlobusExtensionDebugExit();
    return GLOBUS_SUCCESS;

error_lookup:
    globus_rmutex_unlock(&globus_l_extension_mutex);
error_param:
    GlobusExtensionDebugExitWithError();
    return GLOBUS_FAILURE;
}
Esempio n. 10
0
static
int
globus_l_module_reference_count(
    globus_module_descriptor_t *	module_descriptor)
{
    globus_l_module_entry_t *		entry;
    
    entry =
	globus_hashtable_lookup(
	    &globus_l_module_table,
	    (void *) module_descriptor->activation_func);
    if (entry == GLOBUS_NULL || entry->reference_count <= 0)
    {
	return 0;
    }
    else
    {
        return entry->reference_count;
    }
}
/**
 * Unregister protocol.
 * @ingroup globus_gass_transfer_protocol
 *
 * This function unregisters a protocol module handler from the GASS Transfer
 * library. If this succeeds, then users of the library may no longer
 * user URLs with the protocol scheme implemented by this module descriptor
 * in GASS Transfer operations.
 *
 * @param proto_desc
 *        The protocol module descriptor. See the "@ref
 *        globus_gass_transfer_protocol" section of the manual for information
 *        on this structure.
 *
 * @retval GLOBUS_SUCCESS
 *         The protocol module was successfully registered with GASS.
 * @retval GLOBUS_GASS_TRANSFER_ERROR_NULL_POINTER
 *         The @a proto_desc parameter was @a GLOBUS_NULL.
 * @retval GLOBUS_GASS_TRANSFER_ERROR_INVALID_USE
 *         A protocol module has not been registered with GASS to
 *         handle this URL scheme.
 */
int
globus_gass_transfer_proto_unregister_protocol(
    globus_gass_transfer_proto_descriptor_t *	proto_desc)
{
    globus_gass_transfer_proto_descriptor_t *	tmp;
    
    if(proto_desc == GLOBUS_NULL)
    {
        return GLOBUS_GASS_TRANSFER_ERROR_NULL_POINTER;
    }
    tmp = globus_hashtable_lookup(&globus_i_gass_transfer_protocols,
				  proto_desc->url_scheme);
    if(tmp)
    {
	tmp = globus_hashtable_remove(&globus_i_gass_transfer_protocols,
				      proto_desc->url_scheme);
	return GLOBUS_SUCCESS;
    }
    else
    {
	return GLOBUS_GASS_TRANSFER_ERROR_INVALID_USE;
    }
}
Esempio n. 12
0
/* driver list stuff */
globus_result_t
globus_xio_driver_list_from_string(
    char *                              driver_string,
    globus_list_t **                    driver_list,
    globus_hashtable_t *                safe_table)
{
    globus_result_t                     result;
    globus_bool_t                       done = GLOBUS_FALSE;
    globus_bool_t                       loaded;
    char *                              opts;
    char *                              ptr;
    char *                              driver_str;
    char *                              driver_name;
    char *                              tmp_str;
    globus_xio_driver_t                 driver;
    globus_list_t *                     list = NULL;
    globus_xio_driver_list_ent_t *      list_ent;
    GlobusXIOName(globus_xio_driver_list_from_string);

    *driver_list = NULL;

    if(driver_string == NULL) 
    {
        result = GlobusXIOErrorParameter("driver_string");
        goto error_param;
    }

    driver_str = globus_libc_strdup(driver_string);
    tmp_str = driver_str;
    while(!done)
    {
        loaded = GLOBUS_FALSE;
        driver_name = tmp_str;
        ptr = strchr(driver_name, ',');
        if(ptr != NULL)
        {
            *ptr = '\0';
            tmp_str = ptr+1;
        }
        else
        {
            done = GLOBUS_TRUE;
        }
        opts = strchr(driver_name, ':');
        if(opts != NULL)
        {
            *opts = '\0';
            opts++;

            /* decode the string */
            globus_url_string_hex_decode(opts);
        }

        /* check against the safe list */
        if(safe_table != NULL)
        {
            char *                      err_str;

            list_ent = (globus_xio_driver_list_ent_t *)
                globus_hashtable_lookup(safe_table, driver_name);

            if(list_ent == NULL)
            {
                err_str = globus_common_create_string(
                    "%s driver not whitelisted", driver_name);
                result = GlobusXIOErrorParameter(err_str);
                globus_free(err_str);
                goto error_load;
            }
            driver = list_ent->driver;
        }
        else
        {
            result = globus_xio_driver_load(driver_name, &driver);
            if(result != GLOBUS_SUCCESS)
            {
                goto error_load;
            }

            loaded = GLOBUS_TRUE;
        }

        list_ent = (globus_xio_driver_list_ent_t *)
            globus_calloc(1, sizeof(globus_xio_driver_list_ent_t));
        list_ent->opts = globus_libc_strdup(opts);
        list_ent->driver = driver;
        list_ent->driver_name = globus_libc_strdup(driver_name);
        list_ent->loaded = loaded;

        globus_list_insert(&list, list_ent);
    }

    globus_free(driver_str);

    /* reverse list */
    while(!globus_list_empty(list))
    {
        globus_list_insert(driver_list, globus_list_first(list));
        globus_list_remove(&list, list);
    }

    return GLOBUS_SUCCESS;

error_load:
    globus_free(driver_str);
    while(!globus_list_empty(list))
    {
        list_ent = (globus_xio_driver_list_ent_t *)
            globus_list_remove(&list, list);

        if(list_ent->loaded)
        {
            globus_xio_driver_unload(list_ent->driver);
        }
        globus_free(list_ent->driver_name);
        if(list_ent->opts != NULL)
        {
            globus_free(list_ent->opts);
        }
        globus_free(list_ent);
    }
error_param:
    return result;
}
Esempio n. 13
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;
    }
}
Esempio n. 14
0
void gw_em_mad_state_callback(void *arg, const char *job_contact,
        globus_gram_client_job_info_t *job_info)
{                              
    globus_gram_protocol_extension_t *entry;
    int jid = -1;
    int done = 0;
    int job_state;

    jid = get_jid(job_contact);

    if (jid == -1)
    {
        return;
    }
 
    job_state = job_info->job_state;

    switch (job_state)
    {
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_PENDING:    
            printf("CALLBACK %d SUCCESS PENDING\n", jid);
            if (job_pool.cancel_state[jid] == 1)
            {
                globus_gram_client_job_cancel(job_contact);            
                job_pool.cancel_state[jid] = 0;
            }
        break;
        
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_SUSPENDED:
            printf("CALLBACK %d SUCCESS SUSPENDED\n", jid);
            if (job_pool.cancel_state[jid] == 1)
            {
                globus_gram_client_job_cancel(job_contact);            
                job_pool.cancel_state[jid] = 0;
            }
        break;
        
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE:
            printf("CALLBACK %d SUCCESS ACTIVE\n", jid);
            if (job_pool.cancel_state[jid] == 1)
            {
                globus_gram_client_job_cancel(job_contact);            
                job_pool.cancel_state[jid] = 0;
            }

        break;
        
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED:
            if (job_info->protocol_error_code == GLOBUS_GRAM_PROTOCOL_ERROR_USER_CANCELLED )
                printf("CALLBACK %d SUCCESS FAILED\n", jid);
            else
                printf("CALLBACK %d FAILURE %s (error %d)\n", jid,
                        globus_gram_client_error_string(job_info->protocol_error_code),
                        job_info->protocol_error_code);

            done = 1;            
            job_pool.cancel_state[jid] = 0;
                  
        break;
        
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE:
            if (job_info->extensions)
            {
                entry = globus_hashtable_lookup(&job_info->extensions, "exit-code");

                if (entry != NULL)
                    printf("CALLBACK %d SUCCESS DONE:%s\n", jid, entry->value);
                else
                    printf("CALLBACK %d SUCCESS DONE\n", jid);
            }
            else
                printf("CALLBACK %d SUCCESS DONE\n", jid);

            done = 1;
            job_pool.cancel_state[jid] = 0;            
        break;
    }

    if (done && (jid != -1))
        del_job(jid);
}
/*
 * globus_l_gass_cache_config_get()
 *
 * Retrieves a config entry
 *  
 * Parameters:
 *  - config      the config structure
 *  - key         the config parameter
 *  
 * Returns:
 *  the value associated with 'key', or GLOBUS_NULL
 */
char*
globus_l_gass_cache_config_get(globus_l_gass_cache_config_t *config,
			       char*                        key)
{
    return globus_hashtable_lookup(&config->table, key);
}
/**
 * Set the value of a header in a hashtable
 * @ingroup globus_i_xio_http_header
 *
 * Adds a new header to a header info structure, or updates the value of an
 * existing header. Copies of the name and value will be stored in a
 * #globus_xio_http_header_t in a hashtable in the header info structure.
 *
 * @param headers
 *     Pointer to the header info structure.
 * @param header_name
 *     Name of the header.
 * @param header_value
 *     Value of the header.
 *
 * @retval GLOBUS_SUCCESS
 *     Header successfully added to the hashtable.
 * @retval GLOBUS_XIO_ERROR_MEMORY
 *     Unable to add header due to memory constraints.
 */
globus_result_t
globus_i_xio_http_header_info_set_header(
    globus_i_xio_http_header_info_t *   headers,
    const char *                        header_name,
    const char *                        header_value)
{
    char *                              save_header;
    globus_result_t                     result = GLOBUS_SUCCESS;
    globus_xio_http_header_t *          header;
    int                                 rc;
    unsigned long                       length;
    GlobusXIOName(globus_l_xio_http_header_set);

    /* Special cases for entity-body handling headers */
    if (strcmp(header_name, "Content-Length") == 0)
    {
        rc = sscanf(header_value, "%lu", &length);

        if (rc < 1)
        {
            result = GlobusXIOHttpErrorInvalidHeader(header_name, header_value);

            goto error_exit;
        }
        headers->content_length = length;
        headers->flags |= GLOBUS_I_XIO_HTTP_HEADER_CONTENT_LENGTH_SET;
    }
    else if (strcmp(header_name, "Transfer-Encoding") == 0)
    {
        if (strcmp(header_value, "identity") == 0)
        {
            headers->transfer_encoding =
                GLOBUS_XIO_HTTP_TRANSFER_ENCODING_IDENTITY;
        }
        else if (strcmp(header_value, "chunked") == 0)
        {
            headers->transfer_encoding =
                GLOBUS_XIO_HTTP_TRANSFER_ENCODING_CHUNKED;
        }
        else
        {
            result = GlobusXIOHttpErrorInvalidHeader(header_name, header_value);

            goto error_exit;
        }
    }
    else if (strcmp(header_name, "Connection") == 0)
    {
        if (strcmp(header_value, "close") == 0)
        {
            headers->flags |= GLOBUS_I_XIO_HTTP_HEADER_CONNECTION_CLOSE;
        }
        else if (strcmp(header_value, "keep-alive") == 0)
        {
            headers->flags &= ~GLOBUS_I_XIO_HTTP_HEADER_CONNECTION_CLOSE;
        }
        else
        {
            result = GlobusXIOHttpErrorInvalidHeader(header_name, header_value);

            goto error_exit;
        }
    }
    else
    {
        /*
         * Either modify the header's value in the hashtable, if it's a
         * duplicate, or create a new entry in the hashtable
         */
        header = globus_hashtable_lookup(
                &headers->headers,
                (void *) header_name);

        if (header != NULL)
        {
            /* Replace current header's value */
            save_header = header->value;

            header->value = globus_libc_strdup(header_value);

            if (header->value == NULL)
            {
                header->value = save_header;

                result = GlobusXIOErrorMemory("header");

                goto error_exit;
            }
            globus_libc_free(save_header);
        }
        else
        {
            header = globus_libc_malloc(sizeof(globus_xio_http_header_t));

            if (header == NULL)
            {
                result = GlobusXIOErrorMemory("header");

                goto error_exit;
            }
            header->name = globus_libc_strdup(header_name);

            if (header->name == NULL)
            {
                result = GlobusXIOErrorMemory("header");
                goto free_header_exit;
            }

            header->value = globus_libc_strdup(header_value);

            if (header->value == NULL)
            {
                result = GlobusXIOErrorMemory("header");
                goto free_header_name_exit;
            }

            rc = globus_hashtable_insert(
                    &headers->headers,
                    header->name,
                    header);

            if (rc != GLOBUS_SUCCESS)
            {
                result = GlobusXIOErrorMemory("header");

                goto free_header_value_exit;
            }
        }
    }
    return result;

free_header_value_exit:
    globus_libc_free(header->value);
free_header_name_exit:
    globus_libc_free(header->name);
free_header_exit:
    globus_libc_free(header);
error_exit:
    return result;
}
Esempio n. 17
0
/**
 * Call a callout of specified abstract type
 * @ingroup globus_callout_call
 *
 * This function looks up the callouts corresponding to the given type and
 * invokes them with the passed arguments. If a invoked callout returns an
 * error it will be chained to a error of the type
 * GLOBUS_CALLOUT_ERROR_CALLOUT_ERROR and no more callouts will be called.
 *
 * @param handle
 *        A configured callout handle
 * @param type
 *        The abstract type of the callout that is to be invoked
 * @return
 *        GLOBUS_SUCCESS
 *        A Globus error object on failure:
 *            GLOBUS_CALLOUT_ERROR_TYPE_NOT_REGISTERED
 *            GLOBUS_CALLOUT_ERROR_CALLOUT_ERROR
 *            GLOBUS_CALLOUT_ERROR_WITH_DL
 *            GLOBUS_CALLOUT_ERROR_WITH_HASHTABLE
 *            GLOBUS_CALLOUT_ERROR_OUT_OF_MEMORY
 */
globus_result_t
globus_callout_call_type(
    globus_callout_handle_t             handle,
    char *                              type,
    ...)
{
    globus_i_callout_data_t *           current_datum;
#ifdef BUILD_STATIC_ONLY
    void *                              function;
#else
    lt_ptr                              function;
    lt_dlhandle *                       dlhandle;
#endif
    globus_result_t                     result = GLOBUS_SUCCESS;
    va_list                             ap;
    int                                 rc;
    char *                              dlerror;
    char *                              flavor_start;
    char *                              file;
    char                                library[1024];
    char **                             save_env;
    int                                 i;
    globus_i_callout_data_t *           tmp_datum;
    int                                 mandatory_callouts_remaining = 0;
    static char *                       _function_name_ =
        "globus_callout_handle_call_type";
    GLOBUS_I_CALLOUT_DEBUG_ENTER;

    current_datum = globus_hashtable_lookup(&handle->symbol_htable,
                                            type);
    if(current_datum == NULL)
    {
        GLOBUS_CALLOUT_ERROR_RESULT(
            result,
            GLOBUS_CALLOUT_ERROR_TYPE_NOT_REGISTERED,
            ("unknown type: %s\n", type));
        goto exit;
    }
    
    tmp_datum = current_datum;
    while(tmp_datum)
    {
        if(tmp_datum->mandatory)
        {
            mandatory_callouts_remaining++;
        }
        tmp_datum = tmp_datum->next;
    }
    
    do
    {
#ifdef BUILD_STATIC_ONLY
        GLOBUS_CALLOUT_ERROR_RESULT(
            result,
            GLOBUS_CALLOUT_ERROR_WITH_DL,
            ("couldn't dlopen %s: %s\n",
             current_datum->file,
             "(null)"));
        goto exit;
#else
        dlhandle = globus_hashtable_lookup(&handle->library_htable,
                                           current_datum->file);

        if(dlhandle == NULL)
        {
            dlhandle = malloc(sizeof(lt_dlhandle));
            
            if(dlhandle == NULL)
            {
                GLOBUS_CALLOUT_MALLOC_ERROR(result);
            }
            
            *dlhandle = NULL;
            rc = globus_hashtable_insert(&handle->library_htable,
                                         current_datum->file,
                                         dlhandle);
            if(rc < 0)
            {
                free(dlhandle);
                GLOBUS_CALLOUT_ERROR_RESULT(
                    result,
                    GLOBUS_CALLOUT_ERROR_WITH_HASHTABLE,
                    ("globus_hashtable_insert retuned %d", rc));
                goto exit;
            }            
        }
    
        if(*dlhandle == NULL)
        {
            /* first time a symbol is referenced in this library ->
             * need to open it
             */
            
            *dlhandle = lt_dlopenext(current_datum->file);
            if(*dlhandle == NULL)
            {
                /* older libtools dont search the extensions correctly */
                snprintf(library, 1024, "%s" MY_LIB_EXT, current_datum->file);
                library[1023] = 0;
                *dlhandle = lt_dlopenext(library);
            }
            
            if(*dlhandle == NULL)
            {
                /* try again with flavor string removed */
                flavor_start = strrchr(current_datum->file, '_');
                if (flavor_start) {
                    file = strdup(current_datum->file);
                    if(file == NULL)
                        {
                            GLOBUS_CALLOUT_MALLOC_ERROR(result);
                            goto exit;
                        }
                    file[flavor_start - current_datum->file] = '\0';
                    *dlhandle = lt_dlopenext(file);
                    if(*dlhandle == NULL)
                    {
                        /* older libtools dont search the extensions correctly */
                        snprintf(library, 1024, "%s" MY_LIB_EXT, file);
                        library[1023] = 0;
                        *dlhandle = lt_dlopenext(library);
                    }
                    free(file);
                }
            }
            if(*dlhandle == NULL)
            {
                GLOBUS_CALLOUT_ERROR_RESULT(
                    result,
                    GLOBUS_CALLOUT_ERROR_WITH_DL,
                    ("couldn't dlopen %s: %s\n",
                     library,
                     (dlerror = lt_dlerror()) ? dlerror : 
                        "unknown error, possibly file not found."));
                goto exit;
            }
        }

        function = lt_dlsym(*dlhandle, current_datum->symbol);

        if(function == NULL)
        {
            GLOBUS_CALLOUT_ERROR_RESULT(
                result,
                GLOBUS_CALLOUT_ERROR_WITH_DL,
                ("symbol %s could not be found in %s: %s\n",
                 current_datum->symbol,
                 current_datum->file,
                 (dlerror = lt_dlerror()) ? dlerror : "(null)"));
            goto exit;
        }

        if(current_datum->env_args)
        {            
            save_env = globus_calloc(
                current_datum->num_env_args*2+1, sizeof(char *));

            i = 0;
            while(current_datum->env_args[i] != NULL && 
                current_datum->env_args[i+1] != NULL)
            {
                save_env[i] = current_datum->env_args[i];
                save_env[i+1] = 
                    globus_libc_strdup(getenv(current_datum->env_args[i]));
                setenv(current_datum->env_args[i], current_datum->env_args[i+1], 1);
                i += 2;
            }
            save_env[i] = NULL;
        }

        va_start(ap,type);
    
        result = ((globus_callout_function_t) function)(ap);
        
        va_end(ap);

        if(current_datum->env_args)
        {
            i = 0;            
            while(save_env[i] != NULL)
            {
                if(save_env[i+1] == NULL)
                {
                    unsetenv(save_env[i]);
                }
                else
                {
                    setenv(save_env[i], save_env[i+1], 1);
                    globus_free(save_env[i+1]);
                }
                                
                i += 2;
            }
            globus_free(save_env);
        }

        if(result == GLOBUS_SUCCESS)
        {
            if(current_datum->mandatory)
            {
                mandatory_callouts_remaining--;
            }
            
            if(!mandatory_callouts_remaining)
            {
                goto exit;
            }
        }
        
        if(result != GLOBUS_SUCCESS)
        {
            if(current_datum->mandatory)
            {
                GLOBUS_CALLOUT_ERROR_CHAIN_RESULT(
                    result,
                    GLOBUS_CALLOUT_ERROR_CALLOUT_ERROR);
                goto exit;
            }
            else if(current_datum->next == NULL)
            {
                /* chain error with stored error */
                GLOBUS_CALLOUT_ERROR_CHAIN_RESULT(
                    result,
                    GLOBUS_CALLOUT_ERROR_CALLOUT_ERROR);
                goto exit;
            }
            else
            {
                /* store error */
                result = GLOBUS_SUCCESS;
            }
        }

        current_datum = current_datum->next;
#endif
    }
    while(current_datum);
    
 exit:
    GLOBUS_I_CALLOUT_DEBUG_EXIT;
    return result;
}/*globus_callout_call_type*/
Esempio n. 18
0
/**
 * Read callout configuration from file.
 * @ingroup globus_callout_config
 *
 * This function read a configuration file with the following format:
 *    - Anything after a '#' is assumed to be a comment
 *    - Blanks lines are ignored
 *    - Lines specifying callouts have the format
 *      abstract type           library         symbol
 *      where "abstract type" denotes the type of callout,
 *      e.g. globus_gram_jobmanager_authz, "library" denotes the library the
 *      callout can be found in and "symbol" denotes the function name of the
 *      callout. The library argument can be specified in two forms, libfoo or
 *      libfoo_<flavor>. When using the former version the current flavor will
 *      automatically be added to the library name. 
 *
 * @param handle
 *        The handle that is to be configured
 * @param filename
 *        The file to read configuration from
 * @return
 *        GLOBUS_SUCCESS
 *        A Globus error object on failure:
 *            GLOBUS_CALLOUT_ERROR_OPENING_CONF_FILE
 *            GLOBUS_CALLOUT_ERROR_PARSING_CONF_FILE
 *            GLOBUS_CALLOUT_ERROR_WITH_HASHTABLE
 *            GLOBUS_CALLOUT_ERROR_OUT_OF_MEMORY
 */
globus_result_t
globus_callout_read_config(
    globus_callout_handle_t             handle,
    char *                              filename)
{
    FILE *                              conf_file;
    char                                buffer[GLOBUS_I_CALLOUT_LINEBUF];
    char                                type[128];
    char                                library[256];
    char                                symbol[128];
    char *                              env_argstr;
    char **                             env_args;
    int                                 numpairs = 0;
    char *                              flavor_start;
    char *                              pound;
    int                                 index;
    int                                 rc;
    globus_result_t                     result;
    globus_i_callout_data_t *           datum = NULL;
    globus_i_callout_data_t *           existing_datum;
    

    static char *                       _function_name_ =
        "globus_callout_read_config";

    GLOBUS_I_CALLOUT_DEBUG_ENTER;
    
    conf_file = fopen(filename, "r");

    if(conf_file == NULL)
    {
        GLOBUS_CALLOUT_ERRNO_ERROR_RESULT(
            result,
            GLOBUS_CALLOUT_ERROR_OPENING_CONF_FILE,
            ("filename %s", filename));
        goto error_exit;
    }
    
    while(fgets(buffer,GLOBUS_I_CALLOUT_LINEBUF,conf_file))
    {
        if(!strchr(buffer, '\n'))
        {
            GLOBUS_CALLOUT_ERROR_RESULT(
                result,
                GLOBUS_CALLOUT_ERROR_PARSING_CONF_FILE,
                ("malformed line, line too long or missing newline"));
            goto error_exit;
        }

        /* strip any comments */
        pound = strchr(buffer, '#');

        if(pound != NULL)
        { 
            *pound = '\0';
        }

        /* strip white space from start */
        
        index = 0;

        while(buffer[index] == '\t' || buffer[index] == ' ')
        {
            index++;
        }

        /* if blank line continue */
        
        if(buffer[index] == '\0' || buffer[index] == '\n')
        { 
            continue;
        }
        
        if(sscanf(&buffer[index],"%127s%255s%127s",type,library,symbol) < 3)
        {
            GLOBUS_CALLOUT_ERROR_RESULT(
                result,
                GLOBUS_CALLOUT_ERROR_PARSING_CONF_FILE,
                ("malformed line: %s", &buffer[index]));
            goto error_exit;
        }
        
        /* check for ENV vars to set */
        env_argstr = strstr(buffer, "ENV:");
        if(env_argstr && strchr(env_argstr, '='))
        {
            int                         i;
            char *                      ptr;
            char *                      start;
            
            numpairs = 0;
            ptr = strchr(env_argstr, '=');
            while(ptr)
            {
                numpairs++;
                ptr++;
                if(*ptr == '"')
                {
                    ptr = strchr(ptr + 1, '"');
                    if(!ptr)
                    {
                        GLOBUS_CALLOUT_ERROR_RESULT(
                            result,
                            GLOBUS_CALLOUT_ERROR_PARSING_CONF_FILE,
                            ("malformed line, unmatched quote: %s", buffer));
                        goto error_exit;
                    }
                }
                ptr = strchr(ptr + 1, '=');
            }
            
            if(numpairs > 0)
            {
                env_args = globus_calloc(numpairs*2+1, sizeof(char *));
                
                start = env_argstr + 4;
                
                i = 0;
                while(start)
                {                    
                    /* skip initial space */
                    while(isspace(*start))
                    {
                        start++;
                    }
                    
                    /* find var name */
                    ptr = strchr(start, '=');
                    *ptr = '\0';
                    
                    if(strcspn(start, " \"=") != strlen(start))
                    {
                        GLOBUS_CALLOUT_ERROR_RESULT(
                            result,
                            GLOBUS_CALLOUT_ERROR_PARSING_CONF_FILE,
                            ("malformed line, invalid character in ENV var: %s", start));
                        goto error_exit;
                    }

                    env_args[i] = globus_libc_strdup(start);
                    
                    /* find value in quotes or before a space or end of line */
                    start = ++ptr;
                    
                    if(*start == '"')
                    {
                        start++;
                        ptr = strchr(start, '"');
                        *ptr = '\0';
                    }
                    else
                    {
                        ptr = strchr(start, ' ');
                        if(!ptr)
                        {
                            ptr = strchr(start, '\n');
                        }
                        *ptr = '\0';                        
                    }
                    env_args[i+1] = globus_libc_strdup(start);

                    ptr++;
                    while(*ptr && isspace(*ptr))
                    {
                        ptr++;
                    }
                    if(*ptr && strchr(ptr, '='))
                    {
                        start = ptr;
                    }
                    else
                    {
                        start = NULL;
                    }
                    
                    i += 2; 
                }
                env_args[i] = NULL;
            }
        }
        else
        {
            env_args = NULL;
        }
        
        /* push values into hash */
        datum = malloc(sizeof(globus_i_callout_data_t));

        if(datum == NULL)
        {
            GLOBUS_CALLOUT_MALLOC_ERROR(result);
            goto error_exit;
        }

        memset(datum,'\0',sizeof(globus_i_callout_data_t));

        /* check if library is flavored already */

        if((flavor_start = strrchr(library,'_')) &&
           (strstr(flavor_start, "32") || strstr(flavor_start, "64")))
        {
            datum->file = strdup(library);
            
            if(datum->file == NULL)
            {
                GLOBUS_CALLOUT_MALLOC_ERROR(result);
                goto error_exit;
            }
        }
        else
        { 
            datum->file = malloc(strlen(library) + 2 + strlen(flavor));
            if(datum->file == NULL)
            {
                GLOBUS_CALLOUT_MALLOC_ERROR(result);
                goto error_exit;
            }
            datum->file[0] = '\0';
            strcat(datum->file, library);
            strcat(datum->file, "_");
            strcat(datum->file, flavor);
        }
        
        datum->symbol = strdup(symbol);

        if(datum->symbol == NULL)
        {
            GLOBUS_CALLOUT_MALLOC_ERROR(result);
            goto error_exit;
        }
        
        if(*type == '|')
        {
            datum->mandatory = GLOBUS_FALSE;
            datum->type = strdup(type + 1);
        }
        else
        {
            datum->mandatory = GLOBUS_TRUE;
            datum->type = strdup(type);
        }

        if(datum->type == NULL)
        {
            GLOBUS_CALLOUT_MALLOC_ERROR(result);
            goto error_exit;
        }

        datum->env_args = env_args;
        datum->num_env_args = numpairs;

        if((rc = globus_hashtable_insert(&handle->symbol_htable,
                                         datum->type,
                                         datum)) == -1)
        {
            existing_datum = globus_hashtable_lookup(&handle->symbol_htable,
                                                     datum->type);
            while(existing_datum->next)
            {
                existing_datum = existing_datum->next;
            }
            existing_datum->next = datum;
        }
        else if(rc < 0)
        {
            GLOBUS_CALLOUT_ERROR_RESULT(
                result,
                GLOBUS_CALLOUT_ERROR_WITH_HASHTABLE,
                ("globus_hashtable_insert retuned %d", rc));
            goto error_exit;
        }
    }

    fclose(conf_file);
    
    GLOBUS_I_CALLOUT_DEBUG_EXIT;

    return GLOBUS_SUCCESS;

 error_exit:

    if(datum != NULL)
    {
        globus_l_callout_data_free(datum);
    }

    if(conf_file != NULL)
    {
        fclose(conf_file);
    }

    return result;
}/*globus_callout_read_config*/
Esempio n. 19
0
/**
 * Register callout configuration
 * @ingroup globus_callout_config
 *
 * This function registers a callout type in the given handle.
 *
 * @param handle
 *        The handle that is to be configured
 * @param type
 *        The abstract type of the callout
 * @param library
 *        The location of the library containing the callout
 * @param symbol
 *        The symbol (ie function name) for the callout
 * @return
 *        GLOBUS_SUCCESS
 *        A Globus error object on failure:
 *            GLOBUS_CALLOUT_ERROR_WITH_HASHTABLE
 *            GLOBUS_CALLOUT_ERROR_OUT_OF_MEMORY
 */
globus_result_t
globus_callout_register(
    globus_callout_handle_t             handle,
    char *                              type,
    char *                              library,
    char *                              symbol)
{
    int                                 rc;
    globus_result_t                     result;
    globus_i_callout_data_t *           datum = NULL;
    globus_i_callout_data_t *           existing_datum;
    char *                              flavor_start;
    
    static char *                       _function_name_ =
        "globus_callout_register";

    GLOBUS_I_CALLOUT_DEBUG_ENTER;
    
    
    /* push values into hash */

    datum = malloc(sizeof(globus_i_callout_data_t));
    
    if(datum == NULL)
    {
        GLOBUS_CALLOUT_MALLOC_ERROR(result);
        goto error_exit;
    }
    
    memset(datum,'\0',sizeof(globus_i_callout_data_t));

    if((flavor_start = strrchr(library,'_')) &&
       (strstr(flavor_start, "32") || strstr(flavor_start, "64")))
    {
        datum->file = strdup(library);
        
        if(datum->file == NULL)
        {
            GLOBUS_CALLOUT_MALLOC_ERROR(result);
            goto error_exit;
        }
    }
    else
    { 
        datum->file = malloc(strlen(library) + 2 + strlen(flavor));
        if(datum->file == NULL)
        {
            GLOBUS_CALLOUT_MALLOC_ERROR(result);
            goto error_exit;
        }
        datum->file[0] = '\0';
        strcat(datum->file, library);
        strcat(datum->file, "_");            
        strcat(datum->file, flavor);
    }
    
    datum->symbol = strdup(symbol);
    
    if(datum->symbol == NULL)
    {
        GLOBUS_CALLOUT_MALLOC_ERROR(result);
        goto error_exit;
    }
    
    datum->type = strdup(type);
    
    if(datum->type == NULL)
    {
        GLOBUS_CALLOUT_MALLOC_ERROR(result);
        goto error_exit;
    }
    
    if((rc = globus_hashtable_insert(&handle->symbol_htable,
                                     datum->type,
                                     datum)) == -1)
    {
        existing_datum = globus_hashtable_lookup(&handle->symbol_htable,
                                                 datum->type);
        while(existing_datum->next)
        {
            existing_datum = existing_datum->next;
        }
        existing_datum->next = datum;
    }
    else if(rc < 0)
    {
        GLOBUS_CALLOUT_ERROR_RESULT(
            result,
            GLOBUS_CALLOUT_ERROR_WITH_HASHTABLE,
            ("globus_hashtable_insert retuned %d", rc));
        goto error_exit;
    }
    
    GLOBUS_I_CALLOUT_DEBUG_EXIT;

    return GLOBUS_SUCCESS;

 error_exit:

    GLOBUS_I_CALLOUT_DEBUG_EXIT;
    
    if(datum != NULL)
    {
        globus_l_callout_data_free(datum);
    }
 
    return result;
}/*globus_callout_register*/
Esempio n. 20
0
int
globus_extension_activate(
    const char *                        extension_name)
{
    globus_l_extension_module_t *       extension;
    globus_l_extension_module_t *       last_extension;
    globus_l_extension_builtin_t *      builtin;
    int                                 rc;
    globus_result_t                     result = GLOBUS_FAILURE;
    GlobusFuncName(globus_extension_activate);
    
    GlobusExtensionDebugEnterSymbol(extension_name);
    
    if(!extension_name)
    {
        goto error_param;
    }
    
    globus_rmutex_lock(&globus_l_extension_mutex);
    {
        extension = (globus_l_extension_module_t *)
            globus_hashtable_lookup(
                &globus_l_extension_loaded, (void *) extension_name);
        if(!extension)
        {
            extension = (globus_l_extension_module_t *)
                globus_malloc(sizeof(globus_l_extension_module_t));
            if(!extension)
            {
                goto error_alloc;
            }
            
            extension->module_ref = 1;
            extension->ref = 1;
            extension->name = globus_libc_strdup(extension_name);
            if(!extension->name)
            {
                goto error_strdup;
            }
            
            builtin = (globus_l_extension_builtin_t *)
                globus_hashtable_lookup(
                    &globus_l_extension_builtins, (void *) extension_name);
            if(builtin && (!builtin->owner || builtin->owner->module_ref > 0))
            {
#               if !defined(BUILD_STATIC_ONLY)
                {

                    extension->dlhandle = NULL;
                }
#               endif
                extension->module = builtin->module;
                extension->owner = builtin->owner;
                if(extension->owner)
                {
                    extension->owner->ref++;
                }
            }
            else
            {
                extension->owner = NULL;

#               if !defined(BUILD_STATIC_ONLY)
                {

                    result =   
                        globus_l_extension_dlopen(
                            extension->name,
                            &extension->dlhandle);
                    if(result != GLOBUS_SUCCESS)
                    {
                        goto error_dll;
                    }
                    
                    result =
                       globus_l_extension_get_module(
                           extension->dlhandle,
                           extension_name,
                           &extension->module);

                }
#               else
                {
                    globus_assert(BUILD_STATIC_ONLY == 0);
                    result = globus_error_put(
                        globus_error_construct_error(
                            GLOBUS_EXTENSION_MODULE,
                            NULL,
                            GLOBUS_EXTENSION_ERROR_OPEN_FAILED,
                            __FILE__,
                            _globus_func_name,
                            __LINE__,
                            "No support for dynamically loading %s\n",
                            extension->name));
                }
#               endif /* !defined(BUILD_STATIC_ONLY) */

                if(result != GLOBUS_SUCCESS)
                {
                    goto error_module;
                }
            }
            
            globus_hashtable_insert(
                &globus_l_extension_loaded,
                extension->name,
                extension);
                
            last_extension = (globus_l_extension_module_t *)
                globus_thread_getspecific(globus_l_extension_owner_key);
            globus_thread_setspecific(globus_l_extension_owner_key, extension);
            
#if USE_SYMBOL_LABELS
            {
                int pre_warned = WARNING_USING_MIXED_THREAD_MODELS;
#endif
            rc = globus_module_activate_proxy(
                extension->module,
                globus_l_extension_deactivate_proxy,
                extension);
#if USE_SYMBOL_LABELS
                if ((!pre_warned) && WARNING_USING_MIXED_THREAD_MODELS)
                {
                    GlobusExtensionDebugPrintf(
                        GLOBUS_L_EXTENSION_DEBUG_VERBOSE,
                        (_GCSL("[%s] Warning: extension %s was compiled with pthreads for GT 5.0.x and may not work correctly\n"),
                            _globus_func_name,
                            extension->name));

                }
            }
#endif
            
            globus_thread_setspecific(
                globus_l_extension_owner_key, last_extension);
            if(rc != GLOBUS_SUCCESS)
            {
                goto error_activate;
            }
        }
        else
        {
            extension->module_ref++;
            extension->ref++;
        }
    }
    globus_rmutex_unlock(&globus_l_extension_mutex);
    
    GlobusExtensionDebugExit();
    return GLOBUS_SUCCESS;

error_activate:
    globus_hashtable_remove(
        &globus_l_extension_loaded, extension->name);
    if(builtin && builtin->owner)
    {
        builtin->owner->ref--;
    }
error_module:
#ifndef BUILD_STATIC_ONLY
    if(extension->dlhandle)
    {
        lt_dlclose(extension->dlhandle);
    }
error_dll:
#endif /* !BUILD_STATIC_ONLY */
    globus_free(extension->name);
error_strdup:
    globus_free(extension);
error_alloc:
    globus_rmutex_unlock(&globus_l_extension_mutex);
error_param:
    GlobusExtensionDebugExitWithError();
    return result;
}
Esempio n. 21
0
void *
globus_extension_lookup(
    globus_extension_handle_t *         handle,
    globus_extension_registry_t *       registry,
    void *                              symbol)
{
    globus_l_extension_handle_t *       entry;
    void *                              datum = NULL;
    GlobusFuncName(globus_extension_lookup);
    
    GlobusExtensionDebugEnterSymbol(registry->user_hashing ? "" : symbol);
    
    if(!handle)
    {
        goto error_param;
    }
    
    *handle = NULL;
    if(!registry || !symbol)
    {
        goto error_param;
    }
    
    globus_rmutex_lock(&globus_l_extension_mutex);
    {
        if(registry->initialized)
        {
            entry = (globus_l_extension_handle_t *)
                globus_hashtable_lookup(&registry->table, (void *) symbol);
            if(entry && (!entry->owner || entry->owner->module_ref > 0))
            {
                datum = entry->datum;
                entry->ref++;
                if(entry->owner)
                {
                    entry->owner->ref++;
                    
                    globus_assert(
                        (entry->owner != (globus_l_extension_module_t *)
                            globus_thread_getspecific(
                                globus_l_extension_owner_key)) &&
                   "You can not lookup something owned by the calling module");
                        
                    GlobusExtensionDebugPrintf(
                        GLOBUS_L_EXTENSION_DEBUG_VERBOSE,
                        (_GCSL("[%s] Accessing entry %s within %s\n"),
                            _globus_func_name,
                            registry->user_hashing ? "" : symbol,
                            entry->owner->name));
                }
                
                *handle = entry;
            }
        }
    }
    globus_rmutex_unlock(&globus_l_extension_mutex);
    
    GlobusExtensionDebugExit();
    return datum;

error_param:
    GlobusExtensionDebugExitWithError();
    return NULL;
}
int
main(int argc, char *argv[])
{
    int rc;
    globus_hashtable_t extensions = NULL;
    globus_gram_protocol_extension_t * extension_value;

    if (argc != 2)
    {
        fprintf(stderr, "Usage: %s RESOURCE-MANAGER-CONTACT\n", argv[0]);
        rc = 1;

        goto out;
    }

    printf("Checking version of GRAM resource: %s\n", argv[1]);

    /*
     * Always activate the GLOBUS_GRAM_CLIENT_MODULE prior to using any
     * functions from the GRAM Client API or behavior is undefined.
     */
    rc = globus_module_activate(GLOBUS_GRAM_CLIENT_MODULE);
    if (rc != GLOBUS_SUCCESS)
    {
        fprintf(stderr, "Error activating %s because %s (Error %d)\n",
                GLOBUS_GRAM_CLIENT_MODULE->module_name,
                globus_gram_client_error_string(rc),
                rc);
        goto out;
    }
    /*
     * Contact the service passed as our first command-line option and perform
     * a version check. If successful,
     * this function will return GLOBUS_SUCCESS, otherwise an integer
     * error code. Old versions of the job manager will return 
     * GLOBUS_GRAM_PROTOCOL_ERROR_HTTP_UNPACK_FAILED as they do not support
     * the version operation.
     */
    rc = globus_gram_client_get_jobmanager_version(argv[1], &extensions);
    if (rc != GLOBUS_SUCCESS)
    {
        fprintf(stderr, "Unable to get service version from %s because %s "
                "(Error %d)\n",
                argv[1], globus_gram_client_error_string(rc), rc);
    }
    else
    {
        /* The version information is returned in the extensions hash table */
        extension_value = globus_hashtable_lookup(
                &extensions,
                "toolkit-version");

        if (extension_value == NULL)
        {
            printf("Unknown toolkit version\n");
        }
        else
        {
            printf("Toolkit Version: %s\n", extension_value->value);
        }

        extension_value = globus_hashtable_lookup(
                &extensions,
                "version");
        if (extension_value == NULL)
        {
            printf("Unknown package version\n");
        }
        else
        {
            printf("Package Version: %s\n", extension_value->value);
        }
        /* Free the extensions hash and its values */
        globus_gram_protocol_hash_destroy(&extensions);
    }

    /*
     * Deactivating the module allows it to free memory and close network
     * connections.
     */
    rc = globus_module_deactivate(GLOBUS_GRAM_CLIENT_MODULE);
out:
    return rc;
}
static void
globus_l_gass_server_ez_register_accept_callback(
					void * listener,
					globus_gass_transfer_request_t request 
					)
{
    int rc;
    char * subjectname;
    char * path=GLOBUS_NULL;
    char * url;
    globus_url_t parsed_url;
    globus_l_gass_server_ez_t * s;
    globus_gass_server_ez_request_t *r;
    struct stat	statstruct;
    globus_byte_t * buf;
    int amt;
    int flags=0;

    
    subjectname=globus_gass_transfer_request_get_subject(request);

    /* lookup our options */
    s=(globus_l_gass_server_ez_t *)globus_hashtable_lookup(
                                &globus_l_gass_server_ez_listeners,
                                listener);

    /* Check for valid URL */
    url=globus_gass_transfer_request_get_url(request);
    rc = globus_url_parse(url, &parsed_url);
    if(rc != GLOBUS_SUCCESS ||
       parsed_url.url_path == GLOBUS_NULL || strlen(parsed_url.url_path) == 0U)
    {
        globus_gass_transfer_deny(request, 404, "File Not Found");
        globus_gass_transfer_request_destroy(request);
        if (rc == GLOBUS_SUCCESS)
            globus_url_destroy(&parsed_url);
	goto reregister_nourl;
    }

    if(globus_gass_transfer_request_get_type(request) ==
       GLOBUS_GASS_TRANSFER_REQUEST_TYPE_APPEND)
    {
        flags = O_CREAT | O_WRONLY | O_APPEND;
    }
    else if(globus_gass_transfer_request_get_type(request) ==
            GLOBUS_GASS_TRANSFER_REQUEST_TYPE_PUT)
    {
        flags = O_CREAT | O_WRONLY | O_TRUNC;
    }
    switch(globus_gass_transfer_request_get_type(request))
        {
          case GLOBUS_GASS_TRANSFER_REQUEST_TYPE_APPEND:
          case GLOBUS_GASS_TRANSFER_REQUEST_TYPE_PUT:

	    /* Check to see if this is a request we are allowed to handle */

            if(((s->options & GLOBUS_GASS_SERVER_EZ_WRITE_ENABLE) == 0UL) &&
              ((s->options & GLOBUS_GASS_SERVER_EZ_STDOUT_ENABLE) == 0UL) &&
              ((s->options & GLOBUS_GASS_SERVER_EZ_STDERR_ENABLE) == 0UL) &&
              ((s->options & GLOBUS_GASS_SERVER_EZ_CLIENT_SHUTDOWN_ENABLE) ==
									 0UL))
    	    {
		goto deny;
            }
	
	    /* Expand ~ and ~user prefix if enaabled in options */
    	    rc = globus_l_gass_server_ez_tilde_expand(s->options,
                                              parsed_url.url_path,
                                              &path);
              
            if(strncmp(path, "/dev/saga", 9) == 0 && 
                    (s->options & GLOBUS_GASS_SERVER_EZ_STDOUT_ENABLE))
            {
                rc = s->fd; // the pipe handle!
            
                goto authorize;
            }
            else if(strncmp(path, "/dev/saga/", 9) == 0)
            {
                goto deny;
            }
                
    	    else if(strcmp(path, "/dev/globus_gass_client_shutdown") == 0)
    	    {
        	if(s->options & GLOBUS_GASS_SERVER_EZ_CLIENT_SHUTDOWN_ENABLE &&
           	   s->callback != GLOBUS_NULL)
        	{
            	    s->callback();
        	}

		goto deny;
    	    }
#ifdef TARGET_ARCH_WIN32
			// The call to open() in Windows defaults to text mode, so
			// we to override it.
			flags |= O_BINARY;
#endif
            rc = globus_libc_open(path, flags, 0600);

            if(rc < 0)
            {
                goto deny;
            }
	
	    authorize:
            globus_gass_transfer_authorize(request, 0);
	    if(s->options & GLOBUS_GASS_SERVER_EZ_LINE_BUFFER)
	    {
	        r=(globus_gass_server_ez_request_t *)globus_malloc(
				sizeof(globus_gass_server_ez_request_t));
		r->fd=rc;
		r->line_buffer=globus_malloc(80);
                r->line_buffer_used= 0UL;
        	r->line_buffer_length = 80UL;
        	r->linebuffer = GLOBUS_TRUE;

		globus_gass_transfer_receive_bytes(request,
						globus_malloc(1024),
						1024,
						1,
						globus_gass_server_ez_put_memory_done,
						r);
	    }
	    else
	    {
                globus_gass_transfer_receive_bytes(request,
                                               globus_malloc(1024),
                                               1024,
                                               1,
                                               globus_l_gass_server_ez_put_callback,
                                               (void *) rc);
	    }
            break;

          case GLOBUS_GASS_TRANSFER_REQUEST_TYPE_GET:
            flags = O_RDONLY;

			/* Expand ~ and ~user prefix if enaabled in options */
            rc = globus_l_gass_server_ez_tilde_expand(s->options,
                                              parsed_url.url_path,
                                              &path);

   	    if((s->options & GLOBUS_GASS_SERVER_EZ_READ_ENABLE) == 0UL)
    	    {
		goto deny;
    	    }
	   
	    if(stat(path, &statstruct)==0)
	    {
#ifdef TARGET_ARCH_WIN32
				// The call to open() in Windows defaults to text mode, 
				// so we to override it.
				flags |= O_BINARY;
#endif
                rc = globus_libc_open(path, flags, 0600);
		fstat(rc, &statstruct);
	    }
	    else
	    {
		globus_gass_transfer_deny(request, 404, "File Not Found");
		globus_gass_transfer_request_destroy(request);
		goto reregister;
	    }

            buf = globus_malloc(1024);
            amt = read(rc, buf, 1024);
            if(amt == -1)
            {
                globus_free(buf);
                goto deny;
            }
            globus_gass_transfer_authorize(request,
                                           statstruct.st_size);

            globus_gass_transfer_send_bytes(request,
                                            buf,
                                            amt,
                                            GLOBUS_FALSE,
                                            globus_l_gass_server_ez_get_callback,
                                            (void *) rc);
	  break;
	default:
	deny:
	  globus_gass_transfer_deny(request, 400, "Bad Request");
	  globus_gass_transfer_request_destroy(request);

	}

  reregister:
    globus_url_destroy(&parsed_url);

  reregister_nourl:
    globus_gass_transfer_register_listen(
				(globus_gass_transfer_listener_t) listener,
				globus_l_gass_server_ez_listen_callback,
				s->reqattr);

    if (path != GLOBUS_NULL) globus_free(path);

} /*globus_l_gass_server_ez_register_accept_callback*/
/*
 * 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;
}
static
globus_result_t
globus_l_python_module(
    const globus_net_manager_attr_t    *attrs,
    globus_l_python_modref_t          **pymod)
{
    globus_result_t                     result = GLOBUS_SUCCESS;
    int                                 rc = 0;
    globus_l_python_modref_t           *modref = NULL;
    PyObject                           *pymodname = NULL;

    for (int i = 0; attrs != NULL && attrs[i].scope != NULL; i++)
    {
        if (strcmp(attrs[i].scope, "python") == 0)
        {
            if (strcmp(attrs[i].name, "pymod") == 0)
            {
                modref = globus_hashtable_lookup(
                    &globus_l_python_modules, attrs[i].value);
                if (!modref)
                {
                    modref = malloc(sizeof(globus_l_python_modref_t));
                    if (!modref)
                    {
                        result = GLOBUS_FAILURE;
                        goto modref_malloc_fail;
                    }
                    modref->key = strdup(attrs[i].value);
                    if (!modref->key)
                    {
                        result = GLOBUS_FAILURE;
                        goto strdup_modref_key_fail;
                    }
                    pymodname = PyString_FromString(modref->key);
                    if (!pymodname)
                    {
                        result = GLOBUS_FAILURE;
                        goto modref_key_to_pystring_fail;
                    }
                    modref->module = PyImport_Import(pymodname);
                    if (!modref->module)
                    {
                        result = GLOBUS_FAILURE;
                        goto module_import_fail;
                    }
                    modref->pre_listen = globus_l_python_resolve_func(
                            modref->module, "pre_listen");
                    modref->post_listen = globus_l_python_resolve_func(
                            modref->module, "post_listen"); 
                    modref->end_listen = globus_l_python_resolve_func(
                            modref->module, "end_listen"); 
                    modref->pre_accept = globus_l_python_resolve_func(
                            modref->module, "pre_accept"); 
                    modref->post_accept = globus_l_python_resolve_func(
                            modref->module, "post_accept"); 
                    modref->pre_connect = globus_l_python_resolve_func(
                            modref->module, "pre_connect"); 
                    modref->post_connect = globus_l_python_resolve_func(
                            modref->module, "post_connect"); 
                    modref->pre_close = globus_l_python_resolve_func(
                            modref->module, "pre_close"); 
                    modref->post_close = globus_l_python_resolve_func(
                            modref->module, "post_close"); 

                    rc = globus_hashtable_insert(
                            &globus_l_python_modules,
                            modref->key,
                            modref);
                    if (rc != GLOBUS_SUCCESS)
                    {
                        result = GLOBUS_FAILURE;
                        goto hashtable_insert_fail;
                    }
                }
                Py_XDECREF(pymodname);
                break;
            }
        }
    }
hashtable_insert_fail:
    if (result != GLOBUS_SUCCESS)
    {
        Py_XDECREF(modref->pre_listen);
        Py_XDECREF(modref->post_listen);
        Py_XDECREF(modref->end_listen);
        Py_XDECREF(modref->pre_accept);
        Py_XDECREF(modref->post_accept);
        Py_XDECREF(modref->pre_connect);
        Py_XDECREF(modref->post_connect);
        Py_XDECREF(modref->pre_close);
        Py_XDECREF(modref->post_close);
        Py_XDECREF(modref->module);
    }
module_import_fail:
modref_key_to_pystring_fail:
    if (result != GLOBUS_SUCCESS)
    {
        free(modref->key);
strdup_modref_key_fail:
        free(modref);
        modref = NULL;
    }
modref_malloc_fail:
    *pymod = modref;
    return result;
}
static
FILE *
globus_l_net_manager_logging_get_logfile(
    const globus_net_manager_attr_t    *attrs)
{
    int                                 rc = 0;
    FILE *                              handle = NULL;
    globus_l_nm_logging_logref_t *      logref = NULL;

    for (int i = 0; attrs != NULL && attrs[i].scope != NULL; i++)
    {
        if (strcmp(attrs[i].scope, "logging") == 0)
        {
            if (strcmp(attrs[i].name, "file") == 0)
            {
                logref = globus_hashtable_lookup(
                    &globus_l_nm_logging_logfiles, attrs[i].value);
                if (!logref)
                {
                    handle = fopen(attrs[i].value, "a");
                    if (!handle)
                    {
                        goto fopen_fail;
                    }
                    logref = malloc(sizeof(globus_l_nm_logging_logref_t));
                    if (logref == NULL)
                    {
                        goto logref_malloc_fail;
                    }
                    logref->key = strdup(attrs[i].value);
                    if (logref->key == NULL)
                    {
                        goto logref_key_fail;
                    }
                    logref->handle = handle;
                    handle = NULL;
                    rc = globus_hashtable_insert(
                            &globus_l_nm_logging_logfiles,
                            logref->key,
                            logref);
                    if (rc != GLOBUS_SUCCESS)
                    {
                        goto hashtable_insert_fail;
                    }
                }
                break;
            }
        }
    }

    return logref ? logref->handle : stdout;

hashtable_insert_fail:
logref_key_fail:
logref_malloc_fail:
    if (handle)
    {
        fclose(handle);
        handle = NULL;
    }
fopen_fail:
    if (logref)
    {
        free(logref->key);
        free(logref);
        logref = NULL;
    }
    return stdout;
}