예제 #1
0
/**
 * this is called shortly after the application starts and
 * before any other function in the file
 * called only from main thread
 */
int freerdp_channels_global_init(void)
{
	g_init_chan_man = NULL;
	g_channels_list = NULL;
	g_open_handle_sequence = 1;
	g_mutex_init = freerdp_mutex_new();
	g_mutex_list = freerdp_mutex_new();

	return 0;
}
예제 #2
0
void svc_plugin_init(rdpSvcPlugin* plugin, CHANNEL_ENTRY_POINTS* pEntryPoints)
{
	rdpSvcPluginList* list;

	/**
	 * The channel manager will guarantee only one thread can call
	 * VirtualChannelInit at a time. So this should be safe.
	 */
	if (g_mutex == NULL)
		g_mutex = freerdp_mutex_new();

	memcpy(&plugin->channel_entry_points, pEntryPoints, pEntryPoints->cbSize);

	plugin->priv = xnew(rdpSvcPluginPrivate);

	/* Add it to the global list */
	list = xnew(rdpSvcPluginList);
	list->plugin = plugin;

	freerdp_mutex_lock(g_mutex);
	list->next = g_svc_plugin_list;
	g_svc_plugin_list = list;
	freerdp_mutex_unlock(g_mutex);

	plugin->channel_entry_points.pVirtualChannelInit(&plugin->priv->init_handle,
		&plugin->channel_def, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, svc_plugin_init_event);
}
예제 #3
0
파일: test_utils.c 프로젝트: Cyclic/FreeRDP
void test_mutex(void)
{
	freerdp_mutex mutex;

	mutex = freerdp_mutex_new();
	freerdp_mutex_lock(mutex);
	freerdp_mutex_unlock(mutex);
	freerdp_mutex_free(mutex);
}
예제 #4
0
freerdp_thread* freerdp_thread_new(void)
{
	freerdp_thread* thread;

	thread = xnew(freerdp_thread);
	thread->mutex = freerdp_mutex_new();
	thread->signals[0] = wait_obj_new();
	thread->signals[1] = wait_obj_new();
	thread->num_signals = 2;

	return thread;
}
예제 #5
0
파일: wtsvc.c 프로젝트: railmeat/FreeRDP
WTSVirtualChannelManager* WTSCreateVirtualChannelManager(freerdp_peer* client)
{
    WTSVirtualChannelManager* vcm;

    vcm = xnew(WTSVirtualChannelManager);
    if (vcm != NULL)
    {
        vcm->client = client;
        vcm->send_event = wait_obj_new();
        vcm->send_queue = list_new();
        vcm->mutex = freerdp_mutex_new();

        client->ReceiveChannelData = WTSReceiveChannelData;
    }

    return vcm;
}
예제 #6
0
int
DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
{
	SCARD_DEVICE* scard;
	char* name;
	char* path;
	int i, length;

	name = (char *)pEntryPoints->plugin_data->data[1];
	path = (char *)pEntryPoints->plugin_data->data[2];

	if (name)
	{
		/* TODO: check if server supports sc redirect (version 5.1) */

		scard = xnew(SCARD_DEVICE);

		scard->device.type = RDPDR_DTYP_SMARTCARD;
		scard->device.name = "SCARD";
		scard->device.IRPRequest = scard_irp_request;
		scard->device.Free = scard_free;

		length = strlen(scard->device.name);
		scard->device.data = stream_new(length + 1);

		for (i = 0; i <= length; i++)
			stream_write_uint8(scard->device.data, name[i] < 0 ? '_' : name[i]);

		scard->path = path;

		scard->irp_list = list_new();
		scard->thread = freerdp_thread_new();

		scard->CompletionIds = list_new();
		scard->CompletionIdsMutex = freerdp_mutex_new();

		pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE *)scard);

		freerdp_thread_start(scard->thread, scard_thread_func, scard);
	}

	return 0;
}
예제 #7
0
rdpChannels* freerdp_channels_new(void)
{
	rdpChannels* chan_man;
	rdpChannelsList* list;

	chan_man = xnew(rdpChannels);

	chan_man->sync_data_mutex = freerdp_mutex_new();
	chan_man->sync_data_list = list_new();

	chan_man->event_sem = freerdp_sem_new(1);
	chan_man->signal = wait_obj_new();

	/* Add it to the global list */
	list = xnew(rdpChannelsList);
	list->channels = chan_man;

	freerdp_mutex_lock(g_mutex_list);
	list->next = g_channels_list;
	g_channels_list = list;
	freerdp_mutex_unlock(g_mutex_list);

	return chan_man;
}
예제 #8
0
파일: wtsvc.c 프로젝트: railmeat/FreeRDP
void* WTSVirtualChannelOpenEx(
    /* __in */ WTSVirtualChannelManager* vcm,
    /* __in */ const char* pVirtualName,
    /* __in */ uint32 flags)
{
    int i;
    int len;
    rdpPeerChannel* channel;
    const char* channel_name;
    freerdp_peer* client = vcm->client;

    channel_name = ((flags & WTS_CHANNEL_OPTION_DYNAMIC) != 0 ? "drdynvc" : pVirtualName);

    len = strlen(channel_name);
    if (len > 8)
        return NULL;

    for (i = 0; i < client->settings->num_channels; i++)
    {
        if (client->settings->channels[i].joined &&
                strncmp(client->settings->channels[i].name, channel_name, len) == 0)
        {
            break;
        }
    }
    if (i >= client->settings->num_channels)
        return NULL;

    channel = (rdpPeerChannel*) client->settings->channels[i].handle;
    if (channel == NULL)
    {
        channel = xnew(rdpPeerChannel);
        channel->vcm = vcm;
        channel->client = client;
        channel->channel_id = client->settings->channels[i].channel_id;
        channel->index = i;
        channel->receive_data = stream_new(client->settings->vc_chunk_size);
        if ((flags & WTS_CHANNEL_OPTION_DYNAMIC) != 0)
        {
            channel->channel_type = RDP_PEER_CHANNEL_TYPE_DVC;
            vcm->drdynvc_channel = channel;
        }
        else
        {
            channel->channel_type = RDP_PEER_CHANNEL_TYPE_SVC;
            channel->receive_event = wait_obj_new();
            channel->receive_queue = list_new();
            channel->mutex = freerdp_mutex_new();
        }

        client->settings->channels[i].handle = channel;
    }
    if (channel->channel_type == RDP_PEER_CHANNEL_TYPE_DVC)
    {
        /* TODO: do DVC channel initialization here using pVirtualName */
        /* A sub-channel should be created and returned, instead of using the main drdynvc channel */
        /* Set channel->index to num_channels */
    }

    return channel;
}
예제 #9
0
파일: wtsvc.c 프로젝트: celsius/FreeRDP
void* WTSVirtualChannelOpenEx(
	/* __in */ WTSVirtualChannelManager* vcm,
	/* __in */ const char* pVirtualName,
	/* __in */ uint32 flags)
{
	int i;
	int len;
	rdpPeerChannel* channel;
	freerdp_peer* client = vcm->client;
	STREAM* s;

	if ((flags & WTS_CHANNEL_OPTION_DYNAMIC) != 0)
	{
		if (vcm->drdynvc_channel == NULL || vcm->drdynvc_state != DRDYNVC_STATE_READY)
		{
			DEBUG_DVC("Dynamic virtual channel not ready.");
			return NULL;
		}

		channel = xnew(rdpPeerChannel);
		channel->vcm = vcm;
		channel->client = client;
		channel->channel_type = RDP_PEER_CHANNEL_TYPE_DVC;
		channel->receive_data = stream_new(client->settings->vc_chunk_size);
		channel->receive_event = wait_obj_new();
		channel->receive_queue = list_new();
		channel->mutex = freerdp_mutex_new();

		freerdp_mutex_lock(vcm->mutex);
		channel->channel_id = vcm->dvc_channel_id_seq++;
		list_enqueue(vcm->dvc_channel_list, channel);
		freerdp_mutex_unlock(vcm->mutex);

		s = stream_new(64);
		wts_write_drdynvc_create_request(s, channel->channel_id, pVirtualName);
		WTSVirtualChannelWrite(vcm->drdynvc_channel, stream_get_head(s), stream_get_length(s), NULL);
		stream_free(s);

		DEBUG_DVC("ChannelId %d.%s (total %d)", channel->channel_id, pVirtualName, list_size(vcm->dvc_channel_list));
	}
	else
	{
		len = strlen(pVirtualName);
		if (len > 8)
			return NULL;

		for (i = 0; i < client->settings->num_channels; i++)
		{
			if (client->settings->channels[i].joined &&
				strncmp(client->settings->channels[i].name, pVirtualName, len) == 0)
			{
				break;
			}
		}
		if (i >= client->settings->num_channels)
			return NULL;

		channel = (rdpPeerChannel*) client->settings->channels[i].handle;
		if (channel == NULL)
		{
			channel = xnew(rdpPeerChannel);
			channel->vcm = vcm;
			channel->client = client;
			channel->channel_id = client->settings->channels[i].channel_id;
			channel->index = i;
			channel->channel_type = RDP_PEER_CHANNEL_TYPE_SVC;
			channel->receive_data = stream_new(client->settings->vc_chunk_size);
			channel->receive_event = wait_obj_new();
			channel->receive_queue = list_new();
			channel->mutex = freerdp_mutex_new();

			client->settings->channels[i].handle = channel;
		}
	}

	return channel;
}