Ejemplo n.º 1
0
zrtp_status_t zrtp_test_endpoint_create(zrtp_test_endpoint_cfg_t* cfg,
										const char *name,
										zrtp_test_id_t* id) {
	zrtp_status_t s;
	unsigned i;
	char cache_file_path[ZRTP_TEST_STR_LEN];
	zrtp_endpoint_t *new_endpoint;

	if (g_test_endpoints_count >= K_ZRTP_TEST_MAX_ENDPOINTS)
		return zrtp_status_alloc_fail;

	new_endpoint = &g_test_endpoints[g_test_endpoints_count++];
	zrtp_memset(new_endpoint, 0, sizeof(zrtp_endpoint_t));

	/* Copy configuration, we will use it later to clean up after ourselves */
	zrtp_memcpy(&new_endpoint->cfg, cfg, sizeof(zrtp_test_endpoint_cfg_t));

	/* Remember endpoint name */
	strcpy(new_endpoint->name, name);

	new_endpoint->id = g_endpoints_counter++;

	/* Adjust cache file path so each endpoint will use it's own file. */
	sprintf(cache_file_path, "./%s_cache.dat", name);
	zrtp_zstrcpyc(ZSTR_GV(new_endpoint->cfg.zrtp.def_cache_path), cache_file_path);

	/* Initialize libzrtp engine for this endpoint */
	s = zrtp_init(&new_endpoint->cfg.zrtp, &new_endpoint->zrtp);
	if (zrtp_status_ok == s) {
		*id = new_endpoint->id;

		/* Generate random ZID */
		zrtp_randstr(new_endpoint->zrtp, new_endpoint->zid, sizeof(new_endpoint->zid));
	}

	/* Create Input queue*/
	s = zrtp_test_queue_create(&new_endpoint->input_queue);
	if (zrtp_status_ok != s) {
		return s;
	}

	/* Start processing loop */
	new_endpoint->is_running = 1;

	for (i = 0; i<K_ZRTP_TEST_PROCESSORS_COUNT; i++) {
		if (0 != zrtp_thread_create(process_incoming, new_endpoint)) {
			return zrtp_status_fail;
		}

		if (cfg->generate_traffic) {
			if (0 != zrtp_thread_create(process_outgoing, new_endpoint)) {
				return zrtp_status_fail;
			}
		}
	}

	return s;
}
static void do_action()
{
	switch (action_id)
	{
		case 0:
		{
			int status;

			zrtp_log_set_log_engine((zrtp_log_engine*)print_log_ce); 
			status = zrtp_test_zrtp_init();
			if (0 != status) {
				return;
			}

			zrtp_test_crypto(zrtp_global);

			{
				zrtp_test_channel_id_t id;
				zrtp_test_channel_config_t sconfig;
				
				sconfig.is_autosecure = 0;
				sconfig.is_preshared  = 0;
				sconfig.streams_count = 1;
				
				status = zrtp_test_channel_create(&sconfig, &id);
				
				if (0 == status) {
					zrtp_test_channel_start(id);
				}
			}
			break;
		}
		case 1:
		{
			zrtp_thread_create(destroy_func, NULL);
			break;
		}
		case 2:
		{
			DeleteObject(font);
			if (log_file) fclose(log_file);
#ifdef WIN32_PLATFORM_WFSP
            DestroyWindow(g_hWnd);
#endif
#ifdef WIN32_PLATFORM_PSPC
			SendMessage(g_hWnd, WM_CLOSE, 0, 0);				
#endif // WIN32_PLATFORM_PSPC
			break;
		}
	}

	action_id++;
}