Esempio n. 1
0
/**
 * Send a plugin-defined event to the plugin.
 * called only from main thread
 * @param channels the channel manager instance
 * @param event an event object created by freerdp_event_new()
 */
FREERDP_API int freerdp_channels_send_event(rdpChannels* chan_man, RDP_EVENT* event)
{
	struct channel_data* lchan_data;
	int index;
	const char* name;

	name = event_class_to_name_table[event->event_class];
	if (name == NULL)
	{
		DEBUG_CHANNELS("unknown event_class %d", event->event_class);
		freerdp_event_free(event);
		return 1;
	}

	lchan_data = freerdp_channels_find_channel_data_by_name(chan_man, name, &index);
	if (lchan_data == NULL)
	{
		DEBUG_CHANNELS("could not find channel name %s", name);
		freerdp_event_free(event);
		return 1;
	}
	if (lchan_data->open_event_proc != NULL)
	{
		lchan_data->open_event_proc(lchan_data->open_handle,
			CHANNEL_EVENT_USER,
			event, sizeof(RDP_EVENT), sizeof(RDP_EVENT), 0);
	}
	return 0;
}
Esempio n. 2
0
/**
 * go through and inform all the libraries that we are initialized
 * called only from main thread
 */
int freerdp_channels_pre_connect(rdpChannels* chan_man, freerdp* instance)
{
	int index;
	struct lib_data* llib;
	CHANNEL_DEF lchannel_def;
	void* dummy;

	DEBUG_CHANNELS("enter");
	chan_man->instance = instance;

	/**
         * If rdpsnd is registered but not rdpdr, it's necessary to register a fake
	 * rdpdr channel to make sound work. This is a workaround for Window 7 and
	 * Windows 2008
	 */
	if (freerdp_channels_find_channel_data_by_name(chan_man, "rdpsnd", 0) != 0 &&
		freerdp_channels_find_channel_data_by_name(chan_man, "rdpdr", 0) == 0)
	{
		lchannel_def.options = CHANNEL_OPTION_INITIALIZED |
			CHANNEL_OPTION_ENCRYPT_RDP;
		strcpy(lchannel_def.name, "rdpdr");
		chan_man->can_call_init = 1;
		chan_man->settings = instance->settings;
		freerdp_mutex_lock(g_mutex_init);
		g_init_chan_man = chan_man;
		MyVirtualChannelInit(&dummy, &lchannel_def, 1,
			VIRTUAL_CHANNEL_VERSION_WIN2000, 0);
		g_init_chan_man = NULL;
		freerdp_mutex_unlock(g_mutex_init);
		chan_man->can_call_init = 0;
		chan_man->settings = 0;
		DEBUG_CHANNELS("registered fake rdpdr for rdpsnd.");
	}

	for (index = 0; index < chan_man->num_libs; index++)
	{
		llib = chan_man->libs + index;
		if (llib->init_event_proc != 0)
		{
			llib->init_event_proc(llib->init_handle, CHANNEL_EVENT_INITIALIZED,
				0, 0);
		}
	}
	return 0;
}
Esempio n. 3
0
/**
 * can be called from any thread
 * thread safe because no 2 threads can have the same channel name registered
 */
static UINT32 FREERDP_CC MyVirtualChannelOpen(void* pInitHandle, UINT32* pOpenHandle,
	char* pChannelName, PCHANNEL_OPEN_EVENT_FN pChannelOpenEventProc)
{
	int index;
	rdpChannels* channels;
	struct channel_data* lchannel_data;

	DEBUG_CHANNELS("enter");

	channels = ((rdpInitHandle*) pInitHandle)->channels;

	if (pOpenHandle == 0)
	{
		DEBUG_CHANNELS("error bad channel handle");
		return CHANNEL_RC_BAD_CHANNEL_HANDLE;
	}

	if (pChannelOpenEventProc == 0)
	{
		DEBUG_CHANNELS("error bad proc");
		return CHANNEL_RC_BAD_PROC;
	}

	if (!channels->is_connected)
	{
		DEBUG_CHANNELS("error not connected");
		return CHANNEL_RC_NOT_CONNECTED;
	}

	lchannel_data = freerdp_channels_find_channel_data_by_name(channels, pChannelName, &index);

	if (lchannel_data == 0)
	{
		DEBUG_CHANNELS("error channel name");
		return CHANNEL_RC_UNKNOWN_CHANNEL_NAME;
	}

	if (lchannel_data->flags == 2)
	{
		DEBUG_CHANNELS("error channel already open");
		return CHANNEL_RC_ALREADY_OPEN;
	}

	lchannel_data->flags = 2; /* open */
	lchannel_data->open_event_proc = pChannelOpenEventProc;
	*pOpenHandle = lchannel_data->open_handle;

	return CHANNEL_RC_OK;
}
Esempio n. 4
0
/**
 * Send a plugin-defined event to the plugin.
 * called only from main thread
 * @param channels the channel manager instance
 * @param event an event object created by freerdp_event_new()
 */
FREERDP_API int freerdp_channels_send_event(rdpChannels* channels, wMessage* event)
{
	int index;
	const char* name = NULL;
	rdpChannelData* lchannel_data;

	switch (GetMessageClass(event->id))
	{
		case DebugChannel_Class:
			name = "rdpdbg";
			break;

		case CliprdrChannel_Class:
			name = "cliprdr";
			break;

		case TsmfChannel_Class:
			name = "tsmf";
			break;

		case RailChannel_Class:
			name = "rail";
			break;
	}

	if (!name)
	{
		DEBUG_CHANNELS("unknown event_class %d", event->event_class);
		freerdp_event_free(event);
		return 1;
	}

	lchannel_data = freerdp_channels_find_channel_data_by_name(channels, name, &index);

	if (!lchannel_data)
	{
		DEBUG_CHANNELS("could not find channel name %s", name);
		freerdp_event_free(event);
		return 1;
	}

	if (lchannel_data->open_event_proc)
	{
		lchannel_data->open_event_proc(lchannel_data->open_handle, CHANNEL_EVENT_USER,
			event, sizeof(wMessage), sizeof(wMessage), 0);
	}

	return 0;
}
Esempio n. 5
0
/**
 * data comming from the server to the client
 * called only from main thread
 */
int freerdp_channels_data(freerdp* instance, int channel_id, void* data, int data_size, int flags, int total_size)
{
	int index;
	rdpChannels* channels;
	rdpChannel* lrdp_channel;
	struct channel_data* lchannel_data;

	channels = freerdp_channels_find_by_instance(instance);

	if (channels == 0)
	{
		DEBUG_CHANNELS("could not find channel manager");
		return 1;
	}

	lrdp_channel = freerdp_channels_find_channel_by_id(channels, instance->settings,
		channel_id, &index);
	if (lrdp_channel == 0)
	{
		DEBUG_CHANNELS("could not find channel id");
		return 1;
	}

	lchannel_data = freerdp_channels_find_channel_data_by_name(channels, lrdp_channel->Name, &index);

	if (lchannel_data == 0)
	{
		DEBUG_CHANNELS("could not find channel name");
		return 1;
	}

	if (lchannel_data->open_event_proc != 0)
	{
		lchannel_data->open_event_proc(lchannel_data->open_handle,
			CHANNEL_EVENT_DATA_RECEIVED, data, data_size, total_size, flags);
	}

	return 0;
}
Esempio n. 6
0
/**
 * must be called by same thread that calls freerdp_chanman_load_plugin
 * according to MS docs
 * only called from main thread
 */
static uint32 FREERDP_CC MyVirtualChannelInit(void** ppInitHandle, PCHANNEL_DEF pChannel,
	int channelCount, uint32 versionRequested,
	PCHANNEL_INIT_EVENT_FN pChannelInitEventProc)
{
	rdpChannels* chan_man;
	int index;
	struct lib_data* llib;
	struct channel_data* lchan;
	rdpChannel* lrdp_chan;
	PCHANNEL_DEF lchan_def;

	chan_man = g_init_chan_man;
	chan_man->init_handles[chan_man->num_init_handles].chan_man = chan_man;
	*ppInitHandle = &chan_man->init_handles[chan_man->num_init_handles];
	chan_man->num_init_handles++;

	DEBUG_CHANNELS("enter");
	if (!chan_man->can_call_init)
	{
		DEBUG_CHANNELS("error not in entry");
		return CHANNEL_RC_NOT_IN_VIRTUALCHANNELENTRY;
	}
	if (ppInitHandle == 0)
	{
		DEBUG_CHANNELS("error bad pphan");
		return CHANNEL_RC_BAD_INIT_HANDLE;
	}
	if (chan_man->num_chans + channelCount >= CHANNEL_MAX_COUNT)
	{
		DEBUG_CHANNELS("error too many channels");
		return CHANNEL_RC_TOO_MANY_CHANNELS;
	}
	if (pChannel == 0)
	{
		DEBUG_CHANNELS("error bad pchan");
		return CHANNEL_RC_BAD_CHANNEL;
	}
	if (chan_man->is_connected)
	{
		DEBUG_CHANNELS("error already connected");
		return CHANNEL_RC_ALREADY_CONNECTED;
	}
	if (versionRequested != VIRTUAL_CHANNEL_VERSION_WIN2000)
	{
		DEBUG_CHANNELS("warning version");
	}
	for (index = 0; index < channelCount; index++)
	{
		lchan_def = pChannel + index;
		if (freerdp_channels_find_channel_data_by_name(chan_man, lchan_def->name, 0) != 0)
		{
			DEBUG_CHANNELS("error channel already used");
			return CHANNEL_RC_BAD_CHANNEL;
		}
	}
	llib = chan_man->libs + chan_man->num_libs;
	llib->init_event_proc = pChannelInitEventProc;
	llib->init_handle = *ppInitHandle;
	chan_man->num_libs++;
	for (index = 0; index < channelCount; index++)
	{
		lchan_def = pChannel + index;
		lchan = chan_man->chans + chan_man->num_chans;

		freerdp_mutex_lock(g_mutex_list);
		lchan->open_handle = g_open_handle_sequence++;
		freerdp_mutex_unlock(g_mutex_list);

		lchan->flags = 1; /* init */
		strncpy(lchan->name, lchan_def->name, CHANNEL_NAME_LEN);
		lchan->options = lchan_def->options;
		if (chan_man->settings->num_channels < 16)
		{
			lrdp_chan = chan_man->settings->channels + chan_man->settings->num_channels;
			strncpy(lrdp_chan->name, lchan_def->name, 7);
			lrdp_chan->options = lchan_def->options;
			chan_man->settings->num_channels++;
		}
		else
		{
			DEBUG_CHANNELS("warning more than 16 channels");
		}
		chan_man->num_chans++;
	}
	return CHANNEL_RC_OK;
}
Esempio n. 7
0
/**
 * must be called by same thread that calls freerdp_chanman_load_plugin
 * according to MS docs
 * only called from main thread
 */
static UINT32 FREERDP_CC MyVirtualChannelInit(void** ppInitHandle, PCHANNEL_DEF pChannel,
	int channelCount, UINT32 versionRequested, PCHANNEL_INIT_EVENT_FN pChannelInitEventProc)
{
	int index;
	rdpChannels* channels;
	struct lib_data* llib;
	rdpChannel* lrdp_channel;
	PCHANNEL_DEF lchannel_def;
	struct channel_data* lchannel_data;

	if (ppInitHandle == NULL)
	{
		DEBUG_CHANNELS("error bad init handle");
		return CHANNEL_RC_BAD_INIT_HANDLE;
	}

	channels = g_init_channels;
	channels->init_handles[channels->num_init_handles].channels = channels;
	*ppInitHandle = &channels->init_handles[channels->num_init_handles];
	channels->num_init_handles++;

	DEBUG_CHANNELS("enter");

	if (!channels->can_call_init)
	{
		DEBUG_CHANNELS("error not in entry");
		return CHANNEL_RC_NOT_IN_VIRTUALCHANNELENTRY;
	}

	if (channels->num_channels_data + channelCount >= CHANNEL_MAX_COUNT)
	{
		DEBUG_CHANNELS("error too many channels");
		return CHANNEL_RC_TOO_MANY_CHANNELS;
	}

	if (pChannel == 0)
	{
		DEBUG_CHANNELS("error bad channel");
		return CHANNEL_RC_BAD_CHANNEL;
	}

	if (channels->is_connected)
	{
		DEBUG_CHANNELS("error already connected");
		return CHANNEL_RC_ALREADY_CONNECTED;
	}

	if (versionRequested != VIRTUAL_CHANNEL_VERSION_WIN2000)
	{
		DEBUG_CHANNELS("warning version");
	}

	for (index = 0; index < channelCount; index++)
	{
		lchannel_def = pChannel + index;

		if (freerdp_channels_find_channel_data_by_name(channels, lchannel_def->name, 0) != 0)
		{
			DEBUG_CHANNELS("error channel already used");
			return CHANNEL_RC_BAD_CHANNEL;
		}
	}

	llib = channels->libs_data + channels->num_libs_data;
	llib->init_event_proc = pChannelInitEventProc;
	llib->init_handle = *ppInitHandle;
	channels->num_libs_data++;

	for (index = 0; index < channelCount; index++)
	{
		lchannel_def = pChannel + index;
		lchannel_data = channels->channels_data + channels->num_channels_data;

		WaitForSingleObject(g_mutex_list, INFINITE);
		lchannel_data->open_handle = g_open_handle_sequence++;
		ReleaseMutex(g_mutex_list);

		lchannel_data->flags = 1; /* init */
		strncpy(lchannel_data->name, lchannel_def->name, CHANNEL_NAME_LEN);
		lchannel_data->options = lchannel_def->options;

		if (channels->settings->ChannelCount < 16)
		{
			lrdp_channel = channels->settings->ChannelDefArray + channels->settings->ChannelCount;
			strncpy(lrdp_channel->Name, lchannel_def->name, 7);
			lrdp_channel->options = lchannel_def->options;
			channels->settings->ChannelCount++;
		}
		else
		{
			DEBUG_CHANNELS("warning more than 16 channels");
		}

		channels->num_channels_data++;
	}

	return CHANNEL_RC_OK;
}
Esempio n. 8
0
/**
 * must be called by same thread that calls freerdp_chanman_load_plugin
 * according to MS docs
 * only called from main thread
 */
static UINT32 FREERDP_CC MyVirtualChannelInit(void** ppInitHandle, PCHANNEL_DEF pChannel,
	int channelCount, UINT32 versionRequested, PCHANNEL_INIT_EVENT_FN pChannelInitEventProc)
{
	int index;
	rdpChannel* channel;
	rdpChannels* channels;
	rdpLibraryData* llib;
	PCHANNEL_DEF lchannel_def;
	rdpChannelData* lchannel_data;

	if (!ppInitHandle)
	{
		DEBUG_CHANNELS("error bad init handle");
		return CHANNEL_RC_BAD_INIT_HANDLE;
	}

	channels = g_init_channels;

	channels->initHandleList[channels->initHandleCount].channels = channels;
	*ppInitHandle = &channels->initHandleList[channels->initHandleCount];

	channels->initHandleCount++;

	DEBUG_CHANNELS("enter");

	if (!channels->can_call_init)
	{
		DEBUG_CHANNELS("error not in entry");
		return CHANNEL_RC_NOT_IN_VIRTUALCHANNELENTRY;
	}

	if (channels->channelDataCount + channelCount >= CHANNEL_MAX_COUNT)
	{
		DEBUG_CHANNELS("error too many channels");
		return CHANNEL_RC_TOO_MANY_CHANNELS;
	}

	if (!pChannel)
	{
		DEBUG_CHANNELS("error bad channel");
		return CHANNEL_RC_BAD_CHANNEL;
	}

	if (channels->is_connected)
	{
		DEBUG_CHANNELS("error already connected");
		return CHANNEL_RC_ALREADY_CONNECTED;
	}

	if (versionRequested != VIRTUAL_CHANNEL_VERSION_WIN2000)
	{
		DEBUG_CHANNELS("warning version");
	}

	for (index = 0; index < channelCount; index++)
	{
		lchannel_def = &pChannel[index];

		if (freerdp_channels_find_channel_data_by_name(channels, lchannel_def->name, 0) != 0)
		{
			DEBUG_CHANNELS("error channel already used");
			return CHANNEL_RC_BAD_CHANNEL;
		}
	}

	llib = &channels->libraryDataList[channels->libraryDataCount];
	llib->init_event_proc = pChannelInitEventProc;
	llib->init_handle = *ppInitHandle;
	channels->libraryDataCount++;

	for (index = 0; index < channelCount; index++)
	{
		lchannel_def = &pChannel[index];
		lchannel_data = &channels->channelDataList[channels->channelDataCount];

		lchannel_data->open_handle = g_open_handle_sequence++;

		lchannel_data->flags = 1; /* init */
		strncpy(lchannel_data->name, lchannel_def->name, CHANNEL_NAME_LEN);
		lchannel_data->options = lchannel_def->options;

		if (channels->settings->ChannelCount < 16)
		{
			channel = channels->settings->ChannelDefArray + channels->settings->ChannelCount;
			strncpy(channel->Name, lchannel_def->name, 7);
			channel->options = lchannel_def->options;
			channels->settings->ChannelCount++;
		}
		else
		{
			DEBUG_CHANNELS("warning more than 16 channels");
		}

		channels->channelDataCount++;
	}

	return CHANNEL_RC_OK;
}