2011-08-02 22:03:02 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2014-02-12 00:42:28 +04:00
|
|
|
* Client Channels
|
2011-08-02 22:03:02 +04:00
|
|
|
*
|
2014-02-12 00:42:28 +04:00
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2015-07-15 10:50:35 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2011-08-02 22:03:02 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2021-08-25 11:02:46 +03:00
|
|
|
#include <freerdp/channels/drdynvc.h>
|
2014-09-12 16:36:29 +04:00
|
|
|
|
2014-02-16 01:32:38 +04:00
|
|
|
#include "rdp.h"
|
|
|
|
|
2014-02-12 00:42:28 +04:00
|
|
|
#include "client.h"
|
2014-02-11 08:13:29 +04:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("core.client")
|
|
|
|
|
2020-10-16 10:16:15 +03:00
|
|
|
/* Use this instance to get access to channels in VirtualChannelInit. It is set during
|
|
|
|
* freerdp_connect so channels that use VirtualChannelInit must be initialized from the same thread
|
|
|
|
* as freerdp_connect was called */
|
|
|
|
static WINPR_TLS freerdp* g_Instance = NULL;
|
2016-11-14 23:23:05 +03:00
|
|
|
|
2020-10-16 10:16:15 +03:00
|
|
|
/* use global counter to ensure uniqueness across channel manager instances */
|
|
|
|
static volatile LONG g_OpenHandleSeq = 1;
|
|
|
|
|
|
|
|
/* HashTable mapping channel handles to CHANNEL_OPEN_DATA */
|
|
|
|
static INIT_ONCE g_ChannelHandlesOnce = INIT_ONCE_STATIC_INIT;
|
|
|
|
static wHashTable* g_ChannelHandles = NULL;
|
2014-02-11 08:13:29 +04:00
|
|
|
|
2019-10-28 17:13:42 +03:00
|
|
|
static BOOL freerdp_channels_process_message_free(wMessage* message, DWORD type);
|
2019-10-28 16:57:39 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static CHANNEL_OPEN_DATA* freerdp_channels_find_channel_open_data_by_name(rdpChannels* channels,
|
|
|
|
const char* name)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
|
|
|
|
|
|
|
for (index = 0; index < channels->openDataCount; index++)
|
|
|
|
{
|
|
|
|
pChannelOpenData = &channels->openDataList[index];
|
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
if (strncmp(name, pChannelOpenData->name, CHANNEL_NAME_LEN + 1) == 0)
|
2014-02-11 08:13:29 +04:00
|
|
|
return pChannelOpenData;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns rdpChannel for the channel name passed in */
|
2019-11-06 17:24:51 +03:00
|
|
|
static rdpMcsChannel* freerdp_channels_find_channel_by_name(rdpRdp* rdp, const char* name)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2014-05-10 17:50:36 +04:00
|
|
|
UINT32 index;
|
2020-02-02 16:01:38 +03:00
|
|
|
rdpMcs* mcs = NULL;
|
|
|
|
|
|
|
|
if (!rdp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
mcs = rdp->mcs;
|
2014-02-11 08:13:29 +04:00
|
|
|
|
2014-02-16 01:32:38 +04:00
|
|
|
for (index = 0; index < mcs->channelCount; index++)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
rdpMcsChannel* channel = &mcs->channels[index];
|
2014-02-11 08:13:29 +04:00
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
if (strncmp(name, channel->Name, CHANNEL_NAME_LEN + 1) == 0)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-02-02 16:01:38 +03:00
|
|
|
static rdpMcsChannel* freerdp_channels_find_channel_by_id(rdpRdp* rdp, UINT16 channel_id)
|
|
|
|
{
|
|
|
|
UINT32 index;
|
|
|
|
rdpMcsChannel* channel = NULL;
|
|
|
|
rdpMcs* mcs = NULL;
|
|
|
|
|
|
|
|
if (!rdp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
mcs = rdp->mcs;
|
|
|
|
|
|
|
|
for (index = 0; index < mcs->channelCount; index++)
|
|
|
|
{
|
|
|
|
channel = &mcs->channels[index];
|
|
|
|
|
|
|
|
if (channel->ChannelId == channel_id)
|
|
|
|
{
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-07-18 16:16:50 +03:00
|
|
|
static void channel_queue_message_free(wMessage* msg)
|
2018-02-09 12:39:46 +03:00
|
|
|
{
|
|
|
|
CHANNEL_OPEN_EVENT* ev;
|
|
|
|
|
|
|
|
if (!msg || (msg->id != 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ev = (CHANNEL_OPEN_EVENT*)msg->wParam;
|
2019-10-28 16:57:39 +03:00
|
|
|
free(ev);
|
2018-02-09 12:39:46 +03:00
|
|
|
}
|
|
|
|
|
2018-07-18 16:16:50 +03:00
|
|
|
static void channel_queue_free(void* obj)
|
|
|
|
{
|
|
|
|
wMessage* msg = (wMessage*)obj;
|
2019-10-28 18:43:47 +03:00
|
|
|
freerdp_channels_process_message_free(msg, CHANNEL_EVENT_WRITE_CANCELLED);
|
2018-07-18 16:16:50 +03:00
|
|
|
channel_queue_message_free(msg);
|
|
|
|
}
|
|
|
|
|
2020-10-16 10:16:15 +03:00
|
|
|
static BOOL CALLBACK init_channel_handles_table(PINIT_ONCE once, PVOID param, PVOID* context)
|
|
|
|
{
|
|
|
|
g_ChannelHandles = HashTable_New(TRUE);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
rdpChannels* freerdp_channels_new(freerdp* instance)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2020-05-12 18:16:14 +03:00
|
|
|
wObject* obj;
|
2014-02-11 08:13:29 +04:00
|
|
|
rdpChannels* channels;
|
2019-11-06 17:24:51 +03:00
|
|
|
channels = (rdpChannels*)calloc(1, sizeof(rdpChannels));
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2014-06-12 00:27:31 +04:00
|
|
|
if (!channels)
|
|
|
|
return NULL;
|
2014-02-11 08:13:29 +04:00
|
|
|
|
2020-10-16 10:16:15 +03:00
|
|
|
InitOnceExecuteOnce(&g_ChannelHandlesOnce, init_channel_handles_table, NULL, NULL);
|
|
|
|
|
|
|
|
if (!g_ChannelHandles)
|
|
|
|
goto error;
|
2016-08-09 13:04:06 +03:00
|
|
|
if (!InitializeCriticalSectionAndSpinCount(&channels->channelsLock, 4000))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
channels->instance = instance;
|
2014-12-27 23:20:29 +03:00
|
|
|
channels->queue = MessageQueue_New(NULL);
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!channels->queue)
|
2016-08-09 13:04:06 +03:00
|
|
|
goto error;
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
obj = MessageQueue_Object(channels->queue);
|
|
|
|
obj->fnObjectFree = channel_queue_free;
|
|
|
|
|
2014-02-11 08:13:29 +04:00
|
|
|
return channels;
|
2016-08-09 13:04:06 +03:00
|
|
|
error:
|
|
|
|
freerdp_channels_free(channels);
|
2015-05-18 12:28:00 +03:00
|
|
|
return NULL;
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void freerdp_channels_free(rdpChannels* channels)
|
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!channels)
|
|
|
|
return;
|
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
DeleteCriticalSection(&channels->channelsLock);
|
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
if (channels->queue)
|
2014-12-03 22:17:27 +03:00
|
|
|
{
|
2014-12-27 23:20:29 +03:00
|
|
|
MessageQueue_Free(channels->queue);
|
|
|
|
channels->queue = NULL;
|
2014-12-03 22:17:27 +03:00
|
|
|
}
|
|
|
|
|
2014-02-11 08:13:29 +04:00
|
|
|
free(channels);
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT freerdp_drdynvc_on_channel_connected(DrdynvcClientContext* context, const char* name,
|
|
|
|
void* pInterface)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status = CHANNEL_RC_OK;
|
2014-02-11 08:13:29 +04:00
|
|
|
ChannelConnectedEventArgs e;
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpChannels* channels = (rdpChannels*)context->custom;
|
2014-02-11 08:13:29 +04:00
|
|
|
freerdp* instance = channels->instance;
|
|
|
|
EventArgsInit(&e, "freerdp");
|
|
|
|
e.name = name;
|
|
|
|
e.pInterface = pInterface;
|
|
|
|
PubSub_OnChannelConnected(instance->context->pubSub, instance->context, &e);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT freerdp_drdynvc_on_channel_disconnected(DrdynvcClientContext* context, const char* name,
|
|
|
|
void* pInterface)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status = CHANNEL_RC_OK;
|
2014-02-11 08:13:29 +04:00
|
|
|
ChannelDisconnectedEventArgs e;
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpChannels* channels = (rdpChannels*)context->custom;
|
2014-02-11 08:13:29 +04:00
|
|
|
freerdp* instance = channels->instance;
|
|
|
|
EventArgsInit(&e, "freerdp");
|
|
|
|
e.name = name;
|
|
|
|
e.pInterface = pInterface;
|
|
|
|
PubSub_OnChannelDisconnected(instance->context->pubSub, instance->context, &e);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT freerdp_drdynvc_on_channel_attached(DrdynvcClientContext* context, const char* name,
|
|
|
|
void* pInterface)
|
2016-12-19 19:07:01 +03:00
|
|
|
{
|
|
|
|
UINT status = CHANNEL_RC_OK;
|
|
|
|
ChannelAttachedEventArgs e;
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpChannels* channels = (rdpChannels*)context->custom;
|
2016-12-19 19:07:01 +03:00
|
|
|
freerdp* instance = channels->instance;
|
|
|
|
EventArgsInit(&e, "freerdp");
|
|
|
|
e.name = name;
|
|
|
|
e.pInterface = pInterface;
|
|
|
|
PubSub_OnChannelAttached(instance->context->pubSub, instance->context, &e);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT freerdp_drdynvc_on_channel_detached(DrdynvcClientContext* context, const char* name,
|
|
|
|
void* pInterface)
|
2016-12-19 19:07:01 +03:00
|
|
|
{
|
|
|
|
UINT status = CHANNEL_RC_OK;
|
|
|
|
ChannelDetachedEventArgs e;
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpChannels* channels = (rdpChannels*)context->custom;
|
2016-12-19 19:07:01 +03:00
|
|
|
freerdp* instance = channels->instance;
|
|
|
|
EventArgsInit(&e, "freerdp");
|
|
|
|
e.name = name;
|
|
|
|
e.pInterface = pInterface;
|
|
|
|
PubSub_OnChannelDetached(instance->context->pubSub, instance->context, &e);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2020-10-16 10:16:15 +03:00
|
|
|
void freerdp_channels_register_instance(rdpChannels* channels, freerdp* instance)
|
|
|
|
{
|
|
|
|
/* store instance in TLS so future VirtualChannelInit calls can use it */
|
|
|
|
g_Instance = instance;
|
|
|
|
}
|
|
|
|
|
2014-02-11 08:13:29 +04:00
|
|
|
/**
|
|
|
|
* go through and inform all the libraries that we are initialized
|
|
|
|
* called only from main thread
|
|
|
|
*/
|
2016-03-07 14:54:49 +03:00
|
|
|
UINT freerdp_channels_pre_connect(rdpChannels* channels, freerdp* instance)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2016-03-07 14:54:49 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-02-11 08:13:29 +04:00
|
|
|
int index;
|
|
|
|
CHANNEL_CLIENT_DATA* pChannelClientData;
|
|
|
|
|
2021-04-08 14:42:06 +03:00
|
|
|
MessageQueue_Clear(channels->queue);
|
|
|
|
|
2014-02-11 08:13:29 +04:00
|
|
|
for (index = 0; index < channels->clientDataCount; index++)
|
|
|
|
{
|
|
|
|
pChannelClientData = &channels->clientDataList[index];
|
|
|
|
|
|
|
|
if (pChannelClientData->pChannelInitEventProc)
|
2016-11-15 00:44:45 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelClientData->pChannelInitEventProc(pChannelClientData->pInitHandle,
|
|
|
|
CHANNEL_EVENT_INITIALIZED, 0, 0);
|
2016-11-15 17:09:30 +03:00
|
|
|
}
|
|
|
|
else if (pChannelClientData->pChannelInitEventProcEx)
|
|
|
|
{
|
|
|
|
pChannelClientData->pChannelInitEventProcEx(pChannelClientData->lpUserParam,
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelClientData->pInitHandle,
|
|
|
|
CHANNEL_EVENT_INITIALIZED, 0, 0);
|
2016-11-15 00:44:45 +03:00
|
|
|
}
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2016-03-14 15:19:08 +03:00
|
|
|
if (CHANNEL_RC_OK != getChannelError(instance->context))
|
2016-03-07 14:54:49 +03:00
|
|
|
break;
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
2016-03-07 14:54:49 +03:00
|
|
|
return error;
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
2016-12-19 19:07:01 +03:00
|
|
|
UINT freerdp_channels_attach(freerdp* instance)
|
|
|
|
{
|
|
|
|
UINT error = CHANNEL_RC_OK;
|
|
|
|
int index;
|
2020-11-18 09:51:45 +03:00
|
|
|
const char* hostname;
|
2019-10-29 12:18:09 +03:00
|
|
|
size_t hostnameLength;
|
2016-12-19 19:07:01 +03:00
|
|
|
rdpChannels* channels;
|
|
|
|
CHANNEL_CLIENT_DATA* pChannelClientData;
|
|
|
|
channels = instance->context->channels;
|
|
|
|
hostname = instance->settings->ServerHostname;
|
2019-10-29 12:18:09 +03:00
|
|
|
hostnameLength = strlen(hostname);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
|
|
|
for (index = 0; index < channels->clientDataCount; index++)
|
|
|
|
{
|
2017-01-10 11:17:14 +03:00
|
|
|
ChannelAttachedEventArgs e;
|
2016-12-19 19:07:01 +03:00
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData = NULL;
|
|
|
|
pChannelClientData = &channels->clientDataList[index];
|
|
|
|
|
|
|
|
if (pChannelClientData->pChannelInitEventProc)
|
|
|
|
{
|
2020-10-16 10:16:15 +03:00
|
|
|
pChannelClientData->pChannelInitEventProc(pChannelClientData->pInitHandle,
|
2020-11-18 09:51:45 +03:00
|
|
|
CHANNEL_EVENT_ATTACHED, (LPVOID)hostname,
|
2020-10-16 10:16:15 +03:00
|
|
|
(UINT)hostnameLength);
|
2016-12-19 19:07:01 +03:00
|
|
|
}
|
|
|
|
else if (pChannelClientData->pChannelInitEventProcEx)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelClientData->pChannelInitEventProcEx(
|
|
|
|
pChannelClientData->lpUserParam, pChannelClientData->pInitHandle,
|
2020-11-18 09:51:45 +03:00
|
|
|
CHANNEL_EVENT_ATTACHED, (LPVOID)hostname, (UINT)hostnameLength);
|
2016-12-19 19:07:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getChannelError(instance->context) != CHANNEL_RC_OK)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
pChannelOpenData = &channels->openDataList[index];
|
|
|
|
EventArgsInit(&e, "freerdp");
|
2019-11-06 17:24:51 +03:00
|
|
|
e.name = pChannelOpenData->name;
|
2016-12-19 19:07:01 +03:00
|
|
|
e.pInterface = pChannelOpenData->pInterface;
|
|
|
|
PubSub_OnChannelAttached(instance->context->pubSub, instance->context, &e);
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT freerdp_channels_detach(freerdp* instance)
|
|
|
|
{
|
|
|
|
UINT error = CHANNEL_RC_OK;
|
|
|
|
int index;
|
2020-11-18 09:51:45 +03:00
|
|
|
const char* hostname;
|
2019-10-29 12:18:09 +03:00
|
|
|
size_t hostnameLength;
|
2016-12-19 19:07:01 +03:00
|
|
|
rdpChannels* channels;
|
|
|
|
CHANNEL_CLIENT_DATA* pChannelClientData;
|
|
|
|
channels = instance->context->channels;
|
|
|
|
hostname = instance->settings->ServerHostname;
|
2019-10-29 12:18:09 +03:00
|
|
|
hostnameLength = strlen(hostname);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
|
|
|
for (index = 0; index < channels->clientDataCount; index++)
|
|
|
|
{
|
2017-01-10 11:17:14 +03:00
|
|
|
ChannelDetachedEventArgs e;
|
2016-12-19 19:07:01 +03:00
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
|
|
|
pChannelClientData = &channels->clientDataList[index];
|
|
|
|
|
|
|
|
if (pChannelClientData->pChannelInitEventProc)
|
|
|
|
{
|
2020-10-16 10:16:15 +03:00
|
|
|
pChannelClientData->pChannelInitEventProc(pChannelClientData->pInitHandle,
|
2020-11-18 09:51:45 +03:00
|
|
|
CHANNEL_EVENT_DETACHED, (LPVOID)hostname,
|
2020-10-16 10:16:15 +03:00
|
|
|
(UINT)hostnameLength);
|
2016-12-19 19:07:01 +03:00
|
|
|
}
|
|
|
|
else if (pChannelClientData->pChannelInitEventProcEx)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelClientData->pChannelInitEventProcEx(
|
|
|
|
pChannelClientData->lpUserParam, pChannelClientData->pInitHandle,
|
2020-11-18 09:51:45 +03:00
|
|
|
CHANNEL_EVENT_DETACHED, (LPVOID)hostname, (UINT)hostnameLength);
|
2016-12-19 19:07:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getChannelError(instance->context) != CHANNEL_RC_OK)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
pChannelOpenData = &channels->openDataList[index];
|
|
|
|
EventArgsInit(&e, "freerdp");
|
2019-11-06 17:24:51 +03:00
|
|
|
e.name = pChannelOpenData->name;
|
2016-12-19 19:07:01 +03:00
|
|
|
e.pInterface = pChannelOpenData->pInterface;
|
|
|
|
PubSub_OnChannelDetached(instance->context->pubSub, instance->context, &e);
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2014-02-11 08:13:29 +04:00
|
|
|
/**
|
|
|
|
* go through and inform all the libraries that we are connected
|
|
|
|
* this will tell the libraries that its ok to call MyVirtualChannelOpen
|
|
|
|
* called only from main thread
|
|
|
|
*/
|
2016-03-07 14:54:49 +03:00
|
|
|
UINT freerdp_channels_post_connect(rdpChannels* channels, freerdp* instance)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2016-03-07 14:54:49 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2019-02-07 16:22:28 +03:00
|
|
|
int index;
|
2020-11-18 09:51:45 +03:00
|
|
|
const char* hostname;
|
2018-06-18 11:44:35 +03:00
|
|
|
size_t hostnameLength;
|
2014-02-11 08:13:29 +04:00
|
|
|
CHANNEL_CLIENT_DATA* pChannelClientData;
|
2017-01-23 16:18:19 +03:00
|
|
|
channels->connected = TRUE;
|
2014-02-11 08:13:29 +04:00
|
|
|
hostname = instance->settings->ServerHostname;
|
2018-06-18 11:44:35 +03:00
|
|
|
hostnameLength = strlen(hostname);
|
2014-02-11 08:13:29 +04:00
|
|
|
|
|
|
|
for (index = 0; index < channels->clientDataCount; index++)
|
|
|
|
{
|
2016-11-15 17:09:30 +03:00
|
|
|
ChannelConnectedEventArgs e;
|
2016-12-19 19:07:01 +03:00
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
2014-02-11 08:13:29 +04:00
|
|
|
pChannelClientData = &channels->clientDataList[index];
|
|
|
|
|
|
|
|
if (pChannelClientData->pChannelInitEventProc)
|
|
|
|
{
|
2020-10-16 10:16:15 +03:00
|
|
|
pChannelClientData->pChannelInitEventProc(pChannelClientData->pInitHandle,
|
2020-11-18 09:51:45 +03:00
|
|
|
CHANNEL_EVENT_CONNECTED, (LPVOID)hostname,
|
2020-10-16 10:16:15 +03:00
|
|
|
(UINT)hostnameLength);
|
2016-11-15 17:09:30 +03:00
|
|
|
}
|
|
|
|
else if (pChannelClientData->pChannelInitEventProcEx)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelClientData->pChannelInitEventProcEx(
|
|
|
|
pChannelClientData->lpUserParam, pChannelClientData->pInitHandle,
|
2020-11-18 09:51:45 +03:00
|
|
|
CHANNEL_EVENT_CONNECTED, (LPVOID)hostname, (UINT)hostnameLength);
|
2016-11-15 17:09:30 +03:00
|
|
|
}
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2016-11-15 17:09:30 +03:00
|
|
|
if (getChannelError(instance->context) != CHANNEL_RC_OK)
|
|
|
|
goto fail;
|
2014-02-11 08:13:29 +04:00
|
|
|
|
2016-11-15 17:09:30 +03:00
|
|
|
pChannelOpenData = &channels->openDataList[index];
|
|
|
|
EventArgsInit(&e, "freerdp");
|
2018-04-09 12:04:27 +03:00
|
|
|
e.name = pChannelOpenData->name;
|
2016-11-15 17:09:30 +03:00
|
|
|
e.pInterface = pChannelOpenData->pInterface;
|
|
|
|
PubSub_OnChannelConnected(instance->context->pubSub, instance->context, &e);
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
2021-08-25 11:02:46 +03:00
|
|
|
channels->drdynvc = (DrdynvcClientContext*)freerdp_channels_get_static_channel_interface(
|
|
|
|
channels, DRDYNVC_SVC_CHANNEL_NAME);
|
2014-02-11 08:13:29 +04:00
|
|
|
|
|
|
|
if (channels->drdynvc)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
channels->drdynvc->custom = (void*)channels;
|
2014-02-11 08:13:29 +04:00
|
|
|
channels->drdynvc->OnChannelConnected = freerdp_drdynvc_on_channel_connected;
|
2019-11-06 17:24:51 +03:00
|
|
|
channels->drdynvc->OnChannelDisconnected = freerdp_drdynvc_on_channel_disconnected;
|
2016-12-19 19:07:01 +03:00
|
|
|
channels->drdynvc->OnChannelAttached = freerdp_drdynvc_on_channel_attached;
|
|
|
|
channels->drdynvc->OnChannelDetached = freerdp_drdynvc_on_channel_detached;
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
2016-03-07 14:54:49 +03:00
|
|
|
fail:
|
|
|
|
return error;
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
2020-03-09 12:58:02 +03:00
|
|
|
BOOL freerdp_channels_data(freerdp* instance, UINT16 channelId, const BYTE* cdata, size_t dataSize,
|
|
|
|
UINT32 flags, size_t totalSize)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2014-05-10 17:50:36 +04:00
|
|
|
UINT32 index;
|
2014-02-16 01:32:38 +04:00
|
|
|
rdpMcs* mcs;
|
2014-02-11 08:13:29 +04:00
|
|
|
rdpChannels* channels;
|
2014-02-16 01:32:38 +04:00
|
|
|
rdpMcsChannel* channel = NULL;
|
2014-02-11 08:13:29 +04:00
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
2021-02-24 15:53:43 +03:00
|
|
|
union {
|
2020-03-09 12:58:02 +03:00
|
|
|
const BYTE* pcb;
|
|
|
|
BYTE* pb;
|
|
|
|
} data;
|
2020-03-04 16:23:17 +03:00
|
|
|
|
2020-03-09 12:58:02 +03:00
|
|
|
data.pcb = cdata;
|
|
|
|
if (!instance || !data.pcb)
|
2020-03-04 16:23:17 +03:00
|
|
|
{
|
2020-03-09 12:58:02 +03:00
|
|
|
WLog_ERR(TAG, "%s(%p, %" PRIu16 ", %p, 0x%08x): Invalid arguments", __FUNCTION__, instance,
|
|
|
|
channelId, data, flags);
|
|
|
|
return FALSE;
|
2020-03-04 16:23:17 +03:00
|
|
|
}
|
|
|
|
|
2014-02-16 01:32:38 +04:00
|
|
|
mcs = instance->context->rdp->mcs;
|
2014-02-14 02:06:33 +04:00
|
|
|
channels = instance->context->channels;
|
2014-02-11 08:13:29 +04:00
|
|
|
|
2014-02-16 01:32:38 +04:00
|
|
|
if (!channels || !mcs)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2020-03-09 12:58:02 +03:00
|
|
|
return FALSE;
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
2014-02-16 01:32:38 +04:00
|
|
|
for (index = 0; index < mcs->channelCount; index++)
|
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
rdpMcsChannel* cur = &mcs->channels[index];
|
|
|
|
|
|
|
|
if (cur->ChannelId == channelId)
|
2014-02-16 01:32:38 +04:00
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
channel = cur;
|
2014-02-16 01:32:38 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-11 08:13:29 +04:00
|
|
|
|
|
|
|
if (!channel)
|
|
|
|
{
|
2020-03-09 12:58:02 +03:00
|
|
|
return FALSE;
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 00:44:45 +03:00
|
|
|
pChannelOpenData = freerdp_channels_find_channel_open_data_by_name(channels, channel->Name);
|
2014-02-11 08:13:29 +04:00
|
|
|
|
|
|
|
if (!pChannelOpenData)
|
|
|
|
{
|
2020-03-09 12:58:02 +03:00
|
|
|
return FALSE;
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pChannelOpenData->pChannelOpenEventProc)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelOpenData->pChannelOpenEventProc(pChannelOpenData->OpenHandle,
|
2020-10-16 10:16:15 +03:00
|
|
|
CHANNEL_EVENT_DATA_RECEIVED, data.pb,
|
|
|
|
(UINT32)dataSize, (UINT32)totalSize, flags);
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
2016-11-15 00:44:45 +03:00
|
|
|
else if (pChannelOpenData->pChannelOpenEventProcEx)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelOpenData->pChannelOpenEventProcEx(
|
|
|
|
pChannelOpenData->lpUserParam, pChannelOpenData->OpenHandle,
|
2020-10-16 10:16:15 +03:00
|
|
|
CHANNEL_EVENT_DATA_RECEIVED, data.pb, (UINT32)dataSize, (UINT32)totalSize, flags);
|
2016-11-15 00:44:45 +03:00
|
|
|
}
|
2014-02-11 08:13:29 +04:00
|
|
|
|
2020-03-09 12:58:02 +03:00
|
|
|
return TRUE;
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
2020-02-02 16:01:38 +03:00
|
|
|
UINT16 freerdp_channels_get_id_by_name(freerdp* instance, const char* channel_name)
|
|
|
|
{
|
|
|
|
rdpMcsChannel* mcsChannel;
|
|
|
|
if (!instance || !channel_name)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
mcsChannel = freerdp_channels_find_channel_by_name(instance->context->rdp, channel_name);
|
|
|
|
if (!mcsChannel)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return mcsChannel->ChannelId;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* freerdp_channels_get_name_by_id(freerdp* instance, UINT16 channelId)
|
|
|
|
{
|
|
|
|
rdpMcsChannel* mcsChannel;
|
|
|
|
if (!instance)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
mcsChannel = freerdp_channels_find_channel_by_id(instance->context->rdp, channelId);
|
|
|
|
if (!mcsChannel)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (const char*)mcsChannel->Name;
|
|
|
|
}
|
|
|
|
|
2019-10-28 17:13:42 +03:00
|
|
|
BOOL freerdp_channels_process_message_free(wMessage* message, DWORD type)
|
2019-10-28 16:57:39 +03:00
|
|
|
{
|
|
|
|
if (message->id == WMQ_QUIT)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->id == 0)
|
|
|
|
{
|
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
|
|
|
CHANNEL_OPEN_EVENT* item = (CHANNEL_OPEN_EVENT*)message->wParam;
|
|
|
|
|
|
|
|
if (!item)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pChannelOpenData = item->pChannelOpenData;
|
|
|
|
|
|
|
|
if (pChannelOpenData->pChannelOpenEventProc)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelOpenData->pChannelOpenEventProc(pChannelOpenData->OpenHandle, type,
|
|
|
|
item->UserData, item->DataLength,
|
|
|
|
item->DataLength, 0);
|
2019-10-28 16:57:39 +03:00
|
|
|
}
|
|
|
|
else if (pChannelOpenData->pChannelOpenEventProcEx)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelOpenData->pChannelOpenEventProcEx(
|
|
|
|
pChannelOpenData->lpUserParam, pChannelOpenData->OpenHandle, type, item->UserData,
|
|
|
|
item->DataLength, item->DataLength, 0);
|
2019-10-28 16:57:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL freerdp_channels_process_message(freerdp* instance, wMessage* message)
|
|
|
|
{
|
|
|
|
if (message->id == WMQ_QUIT)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->id == 0)
|
|
|
|
{
|
|
|
|
rdpMcsChannel* channel;
|
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
|
|
|
CHANNEL_OPEN_EVENT* item = (CHANNEL_OPEN_EVENT*)message->wParam;
|
|
|
|
|
|
|
|
if (!item)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pChannelOpenData = item->pChannelOpenData;
|
2020-10-16 10:16:15 +03:00
|
|
|
if (pChannelOpenData->flags != 2)
|
|
|
|
{
|
|
|
|
freerdp_channels_process_message_free(message, CHANNEL_EVENT_WRITE_CANCELLED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-10-28 16:57:39 +03:00
|
|
|
channel =
|
2019-11-06 17:24:51 +03:00
|
|
|
freerdp_channels_find_channel_by_name(instance->context->rdp, pChannelOpenData->name);
|
2019-10-28 16:57:39 +03:00
|
|
|
|
|
|
|
if (channel)
|
|
|
|
instance->SendChannelData(instance, channel->ChannelId, item->Data, item->DataLength);
|
|
|
|
}
|
|
|
|
|
2019-10-28 17:13:42 +03:00
|
|
|
if (!freerdp_channels_process_message_free(message, CHANNEL_EVENT_WRITE_COMPLETE))
|
2019-10-28 16:57:39 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
IFCALL(message->Free, message);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-02-11 08:13:29 +04:00
|
|
|
/**
|
|
|
|
* called only from main thread
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static int freerdp_channels_process_sync(rdpChannels* channels, freerdp* instance)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2014-02-16 01:32:38 +04:00
|
|
|
int status = TRUE;
|
2014-02-11 08:13:29 +04:00
|
|
|
wMessage message;
|
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
while (MessageQueue_Peek(channels->queue, &message, TRUE))
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2019-10-28 16:57:39 +03:00
|
|
|
freerdp_channels_process_message(instance, &message);
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
2014-02-16 01:32:38 +04:00
|
|
|
return status;
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* called only from main thread
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL freerdp_channels_get_fds(rdpChannels* channels, freerdp* instance, void** read_fds,
|
2016-07-14 17:08:06 +03:00
|
|
|
int* read_count, void** write_fds, int* write_count)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
|
|
|
void* pfd;
|
2014-12-27 23:20:29 +03:00
|
|
|
pfd = GetEventWaitObject(MessageQueue_Event(channels->queue));
|
2014-02-11 08:13:29 +04:00
|
|
|
|
|
|
|
if (pfd)
|
|
|
|
{
|
|
|
|
read_fds[*read_count] = pfd;
|
|
|
|
(*read_count)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
void* freerdp_channels_get_static_channel_interface(rdpChannels* channels, const char* name)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
|
|
|
void* pInterface = NULL;
|
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelOpenData = freerdp_channels_find_channel_open_data_by_name(channels, name);
|
2014-02-11 08:13:29 +04:00
|
|
|
|
|
|
|
if (pChannelOpenData)
|
|
|
|
pInterface = pChannelOpenData->pInterface;
|
|
|
|
|
|
|
|
return pInterface;
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE freerdp_channels_get_event_handle(freerdp* instance)
|
|
|
|
{
|
|
|
|
HANDLE event = NULL;
|
|
|
|
rdpChannels* channels;
|
|
|
|
channels = instance->context->channels;
|
2014-12-27 23:20:29 +03:00
|
|
|
event = MessageQueue_Event(channels->queue);
|
2014-02-11 08:13:29 +04:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
int freerdp_channels_process_pending_messages(freerdp* instance)
|
|
|
|
{
|
|
|
|
rdpChannels* channels;
|
|
|
|
channels = instance->context->channels;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (WaitForSingleObject(MessageQueue_Event(channels->queue), 0) == WAIT_OBJECT_0)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2016-07-14 17:08:06 +03:00
|
|
|
return freerdp_channels_process_sync(channels, instance);
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* called only from main thread
|
|
|
|
*/
|
|
|
|
BOOL freerdp_channels_check_fds(rdpChannels* channels, freerdp* instance)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (WaitForSingleObject(MessageQueue_Event(channels->queue), 0) == WAIT_OBJECT_0)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
|
|
|
freerdp_channels_process_sync(channels, instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-03-07 14:54:49 +03:00
|
|
|
UINT freerdp_channels_disconnect(rdpChannels* channels, freerdp* instance)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2016-03-07 14:54:49 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-02-11 08:13:29 +04:00
|
|
|
int index;
|
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
|
|
|
CHANNEL_CLIENT_DATA* pChannelClientData;
|
|
|
|
|
2015-02-07 01:35:14 +03:00
|
|
|
if (!channels->connected)
|
|
|
|
return 0;
|
|
|
|
|
2014-02-11 08:13:29 +04:00
|
|
|
freerdp_channels_check_fds(channels, instance);
|
|
|
|
|
|
|
|
/* tell all libraries we are shutting down */
|
|
|
|
for (index = 0; index < channels->clientDataCount; index++)
|
|
|
|
{
|
|
|
|
ChannelDisconnectedEventArgs e;
|
|
|
|
pChannelClientData = &channels->clientDataList[index];
|
2015-01-20 13:58:45 +03:00
|
|
|
|
|
|
|
if (pChannelClientData->pChannelInitEventProc)
|
2016-11-15 00:44:45 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelClientData->pChannelInitEventProc(pChannelClientData->pInitHandle,
|
|
|
|
CHANNEL_EVENT_DISCONNECTED, 0, 0);
|
2016-11-15 00:44:45 +03:00
|
|
|
}
|
2016-11-15 17:09:30 +03:00
|
|
|
else if (pChannelClientData->pChannelInitEventProcEx)
|
|
|
|
{
|
|
|
|
pChannelClientData->pChannelInitEventProcEx(pChannelClientData->lpUserParam,
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelClientData->pInitHandle,
|
|
|
|
CHANNEL_EVENT_DISCONNECTED, 0, 0);
|
2016-11-15 17:09:30 +03:00
|
|
|
}
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2016-03-14 15:19:08 +03:00
|
|
|
if (getChannelError(instance->context) != CHANNEL_RC_OK)
|
2017-01-17 18:00:51 +03:00
|
|
|
continue;
|
2015-01-20 13:58:45 +03:00
|
|
|
|
2014-02-11 08:13:29 +04:00
|
|
|
pChannelOpenData = &channels->openDataList[index];
|
|
|
|
EventArgsInit(&e, "freerdp");
|
2018-04-09 12:04:27 +03:00
|
|
|
e.name = pChannelOpenData->name;
|
2014-02-11 08:13:29 +04:00
|
|
|
e.pInterface = pChannelOpenData->pInterface;
|
|
|
|
PubSub_OnChannelDisconnected(instance->context->pubSub, instance->context, &e);
|
2015-01-20 13:58:45 +03:00
|
|
|
}
|
|
|
|
|
2017-01-23 16:18:19 +03:00
|
|
|
channels->connected = FALSE;
|
2016-03-07 14:54:49 +03:00
|
|
|
return error;
|
2015-01-20 13:58:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void freerdp_channels_close(rdpChannels* channels, freerdp* instance)
|
|
|
|
{
|
|
|
|
int index;
|
2017-02-22 15:45:25 +03:00
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
2015-01-20 13:58:45 +03:00
|
|
|
CHANNEL_CLIENT_DATA* pChannelClientData;
|
2020-11-03 17:24:30 +03:00
|
|
|
MessageQueue_PostQuit(channels->queue, 0);
|
|
|
|
freerdp_channels_check_fds(channels, instance);
|
|
|
|
|
2015-01-20 13:58:45 +03:00
|
|
|
/* tell all libraries we are shutting down */
|
|
|
|
for (index = 0; index < channels->clientDataCount; index++)
|
|
|
|
{
|
|
|
|
pChannelClientData = &channels->clientDataList[index];
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
if (pChannelClientData->pChannelInitEventProc)
|
2016-11-15 17:09:30 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelClientData->pChannelInitEventProc(pChannelClientData->pInitHandle,
|
|
|
|
CHANNEL_EVENT_TERMINATED, 0, 0);
|
2016-11-15 17:09:30 +03:00
|
|
|
}
|
|
|
|
else if (pChannelClientData->pChannelInitEventProcEx)
|
|
|
|
{
|
|
|
|
pChannelClientData->pChannelInitEventProcEx(pChannelClientData->lpUserParam,
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelClientData->pInitHandle,
|
|
|
|
CHANNEL_EVENT_TERMINATED, 0, 0);
|
2016-11-15 17:09:30 +03:00
|
|
|
}
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
2017-02-22 15:45:25 +03:00
|
|
|
channels->clientDataCount = 0;
|
|
|
|
|
|
|
|
for (index = 0; index < channels->openDataCount; index++)
|
|
|
|
{
|
|
|
|
pChannelOpenData = &channels->openDataList[index];
|
2020-10-16 10:16:15 +03:00
|
|
|
HashTable_Remove(g_ChannelHandles, (void*)(UINT_PTR)pChannelOpenData->OpenHandle);
|
2017-02-22 15:45:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
channels->openDataCount = 0;
|
|
|
|
channels->initDataCount = 0;
|
|
|
|
instance->settings->ChannelCount = 0;
|
2020-10-16 10:16:15 +03:00
|
|
|
g_Instance = NULL;
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT VCAPITYPE FreeRDP_VirtualChannelInitEx(
|
|
|
|
LPVOID lpUserParam, LPVOID clientContext, LPVOID pInitHandle, PCHANNEL_DEF pChannel,
|
|
|
|
INT channelCount, ULONG versionRequested, PCHANNEL_INIT_EVENT_EX_FN pChannelInitEventProcEx)
|
2016-11-15 00:44:45 +03:00
|
|
|
{
|
|
|
|
INT index;
|
|
|
|
rdpSettings* settings;
|
|
|
|
CHANNEL_INIT_DATA* pChannelInitData;
|
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
|
|
|
CHANNEL_CLIENT_DATA* pChannelClientData;
|
2020-07-29 00:54:42 +03:00
|
|
|
rdpChannels* channels;
|
2016-11-15 00:44:45 +03:00
|
|
|
|
|
|
|
if (!pInitHandle)
|
|
|
|
return CHANNEL_RC_BAD_INIT_HANDLE;
|
|
|
|
|
2019-10-16 19:49:24 +03:00
|
|
|
if (!pChannel)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL;
|
|
|
|
|
|
|
|
if ((channelCount <= 0) || !pChannelInitEventProcEx)
|
2016-11-15 00:44:45 +03:00
|
|
|
return CHANNEL_RC_INITIALIZATION_ERROR;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelInitData = (CHANNEL_INIT_DATA*)pInitHandle;
|
2016-11-15 00:44:45 +03:00
|
|
|
channels = pChannelInitData->channels;
|
2016-11-23 15:17:56 +03:00
|
|
|
pChannelInitData->pInterface = clientContext;
|
2016-11-15 00:44:45 +03:00
|
|
|
|
|
|
|
if (!channels->can_call_init)
|
|
|
|
return CHANNEL_RC_NOT_IN_VIRTUALCHANNELENTRY;
|
|
|
|
|
2017-11-28 11:40:04 +03:00
|
|
|
if ((channels->openDataCount + channelCount) > CHANNEL_MAX_COUNT)
|
2016-11-15 00:44:45 +03:00
|
|
|
return CHANNEL_RC_TOO_MANY_CHANNELS;
|
|
|
|
|
|
|
|
if (channels->connected)
|
|
|
|
return CHANNEL_RC_ALREADY_CONNECTED;
|
|
|
|
|
|
|
|
if (versionRequested != VIRTUAL_CHANNEL_VERSION_WIN2000)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < channelCount; index++)
|
|
|
|
{
|
2020-11-18 09:51:45 +03:00
|
|
|
const PCHANNEL_DEF pChannelDef = &pChannel[index];
|
2016-11-15 00:44:45 +03:00
|
|
|
|
|
|
|
if (freerdp_channels_find_channel_open_data_by_name(channels, pChannelDef->name) != 0)
|
|
|
|
{
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pChannelClientData = &channels->clientDataList[channels->clientDataCount];
|
|
|
|
pChannelClientData->pChannelInitEventProcEx = pChannelInitEventProcEx;
|
|
|
|
pChannelClientData->pInitHandle = pInitHandle;
|
2016-11-15 17:09:30 +03:00
|
|
|
pChannelClientData->lpUserParam = lpUserParam;
|
2016-11-15 00:44:45 +03:00
|
|
|
channels->clientDataCount++;
|
|
|
|
settings = channels->instance->context->settings;
|
|
|
|
|
|
|
|
for (index = 0; index < channelCount; index++)
|
|
|
|
{
|
2020-11-18 09:51:45 +03:00
|
|
|
const PCHANNEL_DEF pChannelDef = &pChannel[index];
|
2016-11-15 00:44:45 +03:00
|
|
|
pChannelOpenData = &channels->openDataList[channels->openDataCount];
|
2016-12-28 14:05:01 +03:00
|
|
|
pChannelOpenData->OpenHandle = InterlockedIncrement(&g_OpenHandleSeq);
|
2016-11-15 00:44:45 +03:00
|
|
|
pChannelOpenData->channels = channels;
|
2016-11-15 17:09:30 +03:00
|
|
|
pChannelOpenData->lpUserParam = lpUserParam;
|
2021-06-16 11:16:16 +03:00
|
|
|
if (!HashTable_Insert(g_ChannelHandles, (void*)(UINT_PTR)pChannelOpenData->OpenHandle,
|
|
|
|
(void*)pChannelOpenData))
|
|
|
|
return CHANNEL_RC_INITIALIZATION_ERROR;
|
2016-11-15 00:44:45 +03:00
|
|
|
pChannelOpenData->flags = 1; /* init */
|
|
|
|
strncpy(pChannelOpenData->name, pChannelDef->name, CHANNEL_NAME_LEN);
|
|
|
|
pChannelOpenData->options = pChannelDef->options;
|
|
|
|
|
|
|
|
if (settings->ChannelCount < CHANNEL_MAX_COUNT)
|
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
CHANNEL_DEF* channel = freerdp_settings_get_pointer_array_writable(
|
|
|
|
settings, FreeRDP_ChannelDefArray, settings->ChannelCount);
|
|
|
|
strncpy(channel->name, pChannelDef->name, CHANNEL_NAME_LEN);
|
2016-11-15 00:44:45 +03:00
|
|
|
channel->options = pChannelDef->options;
|
|
|
|
settings->ChannelCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
channels->openDataCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT VCAPITYPE FreeRDP_VirtualChannelInit(LPVOID* ppInitHandle, PCHANNEL_DEF pChannel,
|
|
|
|
INT channelCount, ULONG versionRequested,
|
|
|
|
PCHANNEL_INIT_EVENT_FN pChannelInitEventProc)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2016-07-14 17:08:06 +03:00
|
|
|
INT index;
|
2014-02-28 21:07:22 +04:00
|
|
|
CHANNEL_DEF* channel;
|
2014-02-16 02:42:59 +04:00
|
|
|
rdpSettings* settings;
|
2014-02-11 08:13:29 +04:00
|
|
|
PCHANNEL_DEF pChannelDef;
|
|
|
|
CHANNEL_INIT_DATA* pChannelInitData;
|
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
|
|
|
CHANNEL_CLIENT_DATA* pChannelClientData;
|
2020-10-16 10:16:15 +03:00
|
|
|
rdpChannels* channels;
|
|
|
|
|
|
|
|
/* g_Instance should have been set during freerdp_connect - otherwise VirtualChannelInit was
|
|
|
|
* called from a different thread */
|
|
|
|
if (!g_Instance || !g_Instance->context)
|
|
|
|
return CHANNEL_RC_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
channels = g_Instance->context->channels;
|
2014-02-11 08:13:29 +04:00
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
if (!ppInitHandle || !channels)
|
2014-02-11 08:13:29 +04:00
|
|
|
return CHANNEL_RC_BAD_INIT_HANDLE;
|
|
|
|
|
2019-10-16 19:49:24 +03:00
|
|
|
if (!pChannel)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL;
|
|
|
|
|
|
|
|
if ((channelCount <= 0) || !pChannelInitEventProc)
|
2016-07-14 17:08:06 +03:00
|
|
|
return CHANNEL_RC_INITIALIZATION_ERROR;
|
|
|
|
|
2014-02-11 08:13:29 +04:00
|
|
|
pChannelInitData = &(channels->initDataList[channels->initDataCount]);
|
|
|
|
*ppInitHandle = pChannelInitData;
|
|
|
|
channels->initDataCount++;
|
|
|
|
pChannelInitData->channels = channels;
|
2020-10-16 10:16:15 +03:00
|
|
|
pChannelInitData->pInterface = NULL;
|
2014-02-11 08:13:29 +04:00
|
|
|
|
|
|
|
if (!channels->can_call_init)
|
|
|
|
return CHANNEL_RC_NOT_IN_VIRTUALCHANNELENTRY;
|
|
|
|
|
2017-11-28 11:40:04 +03:00
|
|
|
if (channels->openDataCount + channelCount > CHANNEL_MAX_COUNT)
|
2014-02-11 08:13:29 +04:00
|
|
|
return CHANNEL_RC_TOO_MANY_CHANNELS;
|
|
|
|
|
2015-02-07 01:35:14 +03:00
|
|
|
if (channels->connected)
|
2014-02-11 08:13:29 +04:00
|
|
|
return CHANNEL_RC_ALREADY_CONNECTED;
|
|
|
|
|
|
|
|
if (versionRequested != VIRTUAL_CHANNEL_VERSION_WIN2000)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < channelCount; index++)
|
|
|
|
{
|
|
|
|
pChannelDef = &pChannel[index];
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (freerdp_channels_find_channel_open_data_by_name(channels, pChannelDef->name) != 0)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pChannelClientData = &channels->clientDataList[channels->clientDataCount];
|
|
|
|
pChannelClientData->pChannelInitEventProc = pChannelInitEventProc;
|
|
|
|
pChannelClientData->pInitHandle = *ppInitHandle;
|
|
|
|
channels->clientDataCount++;
|
2016-08-09 13:04:06 +03:00
|
|
|
settings = channels->instance->context->settings;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2014-02-11 08:13:29 +04:00
|
|
|
for (index = 0; index < channelCount; index++)
|
|
|
|
{
|
|
|
|
pChannelDef = &pChannel[index];
|
|
|
|
pChannelOpenData = &channels->openDataList[channels->openDataCount];
|
2016-12-28 14:05:01 +03:00
|
|
|
pChannelOpenData->OpenHandle = InterlockedIncrement(&g_OpenHandleSeq);
|
2014-02-15 23:57:10 +04:00
|
|
|
pChannelOpenData->channels = channels;
|
2021-06-16 11:16:16 +03:00
|
|
|
if (!HashTable_Insert(g_ChannelHandles, (void*)(UINT_PTR)pChannelOpenData->OpenHandle,
|
|
|
|
(void*)pChannelOpenData))
|
|
|
|
return CHANNEL_RC_INITIALIZATION_ERROR;
|
2014-02-11 08:13:29 +04:00
|
|
|
pChannelOpenData->flags = 1; /* init */
|
|
|
|
strncpy(pChannelOpenData->name, pChannelDef->name, CHANNEL_NAME_LEN);
|
|
|
|
pChannelOpenData->options = pChannelDef->options;
|
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
if (settings->ChannelCount < CHANNEL_MAX_COUNT)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
channel = freerdp_settings_get_pointer_array_writable(settings, FreeRDP_ChannelDefArray,
|
|
|
|
settings->ChannelCount);
|
|
|
|
strncpy(channel->name, pChannelDef->name, CHANNEL_NAME_LEN);
|
2014-02-11 08:13:29 +04:00
|
|
|
channel->options = pChannelDef->options;
|
2016-08-09 13:04:06 +03:00
|
|
|
settings->ChannelCount++;
|
2014-02-11 08:13:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
channels->openDataCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT VCAPITYPE
|
|
|
|
FreeRDP_VirtualChannelOpenEx(LPVOID pInitHandle, LPDWORD pOpenHandle, PCHAR pChannelName,
|
|
|
|
PCHANNEL_OPEN_EVENT_EX_FN pChannelOpenEventProcEx)
|
2016-11-15 00:44:45 +03:00
|
|
|
{
|
|
|
|
void* pInterface;
|
|
|
|
rdpChannels* channels;
|
|
|
|
CHANNEL_INIT_DATA* pChannelInitData;
|
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelInitData = (CHANNEL_INIT_DATA*)pInitHandle;
|
2016-11-15 00:44:45 +03:00
|
|
|
channels = pChannelInitData->channels;
|
|
|
|
pInterface = pChannelInitData->pInterface;
|
|
|
|
|
|
|
|
if (!pOpenHandle)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
|
|
|
if (!pChannelOpenEventProcEx)
|
|
|
|
return CHANNEL_RC_BAD_PROC;
|
|
|
|
|
|
|
|
if (!channels->connected)
|
|
|
|
return CHANNEL_RC_NOT_CONNECTED;
|
|
|
|
|
|
|
|
pChannelOpenData = freerdp_channels_find_channel_open_data_by_name(channels, pChannelName);
|
|
|
|
|
|
|
|
if (!pChannelOpenData)
|
|
|
|
return CHANNEL_RC_UNKNOWN_CHANNEL_NAME;
|
|
|
|
|
|
|
|
if (pChannelOpenData->flags == 2)
|
|
|
|
return CHANNEL_RC_ALREADY_OPEN;
|
|
|
|
|
|
|
|
pChannelOpenData->flags = 2; /* open */
|
|
|
|
pChannelOpenData->pInterface = pInterface;
|
|
|
|
pChannelOpenData->pChannelOpenEventProcEx = pChannelOpenEventProcEx;
|
|
|
|
*pOpenHandle = pChannelOpenData->OpenHandle;
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT VCAPITYPE FreeRDP_VirtualChannelOpen(LPVOID pInitHandle, LPDWORD pOpenHandle,
|
|
|
|
PCHAR pChannelName,
|
|
|
|
PCHANNEL_OPEN_EVENT_FN pChannelOpenEventProc)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
|
|
|
void* pInterface;
|
|
|
|
rdpChannels* channels;
|
|
|
|
CHANNEL_INIT_DATA* pChannelInitData;
|
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelInitData = (CHANNEL_INIT_DATA*)pInitHandle;
|
2014-02-11 08:13:29 +04:00
|
|
|
channels = pChannelInitData->channels;
|
|
|
|
pInterface = pChannelInitData->pInterface;
|
|
|
|
|
|
|
|
if (!pOpenHandle)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
|
|
|
if (!pChannelOpenEventProc)
|
|
|
|
return CHANNEL_RC_BAD_PROC;
|
|
|
|
|
2015-02-07 01:35:14 +03:00
|
|
|
if (!channels->connected)
|
2014-02-11 08:13:29 +04:00
|
|
|
return CHANNEL_RC_NOT_CONNECTED;
|
|
|
|
|
2016-11-15 00:44:45 +03:00
|
|
|
pChannelOpenData = freerdp_channels_find_channel_open_data_by_name(channels, pChannelName);
|
2014-02-11 08:13:29 +04:00
|
|
|
|
|
|
|
if (!pChannelOpenData)
|
|
|
|
return CHANNEL_RC_UNKNOWN_CHANNEL_NAME;
|
|
|
|
|
|
|
|
if (pChannelOpenData->flags == 2)
|
|
|
|
return CHANNEL_RC_ALREADY_OPEN;
|
|
|
|
|
|
|
|
pChannelOpenData->flags = 2; /* open */
|
|
|
|
pChannelOpenData->pInterface = pInterface;
|
|
|
|
pChannelOpenData->pChannelOpenEventProc = pChannelOpenEventProc;
|
|
|
|
*pOpenHandle = pChannelOpenData->OpenHandle;
|
2016-11-15 00:44:45 +03:00
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT VCAPITYPE FreeRDP_VirtualChannelCloseEx(LPVOID pInitHandle, DWORD openHandle)
|
|
|
|
{
|
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData = NULL;
|
|
|
|
|
|
|
|
if (!pInitHandle)
|
|
|
|
return CHANNEL_RC_BAD_INIT_HANDLE;
|
|
|
|
|
2020-10-16 10:16:15 +03:00
|
|
|
pChannelOpenData = HashTable_GetItemValue(g_ChannelHandles, (void*)(UINT_PTR)openHandle);
|
2020-05-12 18:16:14 +03:00
|
|
|
|
2016-11-15 00:44:45 +03:00
|
|
|
if (!pChannelOpenData)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
|
|
|
if (pChannelOpenData->flags != 2)
|
|
|
|
return CHANNEL_RC_NOT_OPEN;
|
|
|
|
|
|
|
|
pChannelOpenData->flags = 0;
|
2014-02-11 08:13:29 +04:00
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT VCAPITYPE FreeRDP_VirtualChannelClose(DWORD openHandle)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2020-10-16 10:16:15 +03:00
|
|
|
pChannelOpenData = HashTable_GetItemValue(g_ChannelHandles, (void*)(UINT_PTR)openHandle);
|
2014-02-11 08:13:29 +04:00
|
|
|
|
2014-02-15 23:57:10 +04:00
|
|
|
if (!pChannelOpenData)
|
2014-02-11 08:13:29 +04:00
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
|
|
|
if (pChannelOpenData->flags != 2)
|
|
|
|
return CHANNEL_RC_NOT_OPEN;
|
|
|
|
|
|
|
|
pChannelOpenData->flags = 0;
|
2016-11-15 00:44:45 +03:00
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT VCAPITYPE FreeRDP_VirtualChannelWriteEx(LPVOID pInitHandle, DWORD openHandle,
|
2019-11-06 17:24:51 +03:00
|
|
|
LPVOID pData, ULONG dataLength,
|
|
|
|
LPVOID pUserData)
|
2016-11-15 00:44:45 +03:00
|
|
|
{
|
|
|
|
rdpChannels* channels = NULL;
|
|
|
|
CHANNEL_INIT_DATA* pChannelInitData = NULL;
|
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData = NULL;
|
|
|
|
CHANNEL_OPEN_EVENT* pChannelOpenEvent = NULL;
|
2018-07-18 16:16:50 +03:00
|
|
|
wMessage message;
|
2016-11-15 00:44:45 +03:00
|
|
|
|
|
|
|
if (!pInitHandle)
|
|
|
|
return CHANNEL_RC_BAD_INIT_HANDLE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelInitData = (CHANNEL_INIT_DATA*)pInitHandle;
|
2016-11-15 00:44:45 +03:00
|
|
|
channels = pChannelInitData->channels;
|
|
|
|
|
|
|
|
if (!channels)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2020-10-16 10:16:15 +03:00
|
|
|
pChannelOpenData = HashTable_GetItemValue(g_ChannelHandles, (void*)(UINT_PTR)openHandle);
|
2016-11-15 00:44:45 +03:00
|
|
|
|
|
|
|
if (!pChannelOpenData)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2017-01-23 16:18:19 +03:00
|
|
|
if (!channels->connected)
|
|
|
|
return CHANNEL_RC_NOT_CONNECTED;
|
|
|
|
|
2016-11-15 00:44:45 +03:00
|
|
|
if (!pData)
|
|
|
|
return CHANNEL_RC_NULL_DATA;
|
|
|
|
|
|
|
|
if (!dataLength)
|
|
|
|
return CHANNEL_RC_ZERO_LENGTH;
|
|
|
|
|
|
|
|
if (pChannelOpenData->flags != 2)
|
|
|
|
return CHANNEL_RC_NOT_OPEN;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelOpenEvent = (CHANNEL_OPEN_EVENT*)malloc(sizeof(CHANNEL_OPEN_EVENT));
|
2016-11-15 00:44:45 +03:00
|
|
|
|
|
|
|
if (!pChannelOpenEvent)
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
|
|
|
|
pChannelOpenEvent->Data = pData;
|
|
|
|
pChannelOpenEvent->DataLength = dataLength;
|
|
|
|
pChannelOpenEvent->UserData = pUserData;
|
|
|
|
pChannelOpenEvent->pChannelOpenData = pChannelOpenData;
|
2018-07-18 16:16:50 +03:00
|
|
|
message.context = channels;
|
|
|
|
message.id = 0;
|
|
|
|
message.wParam = pChannelOpenEvent;
|
|
|
|
message.lParam = NULL;
|
|
|
|
message.Free = channel_queue_message_free;
|
2016-11-15 00:44:45 +03:00
|
|
|
|
2018-07-18 16:16:50 +03:00
|
|
|
if (!MessageQueue_Dispatch(channels->queue, &message))
|
2016-11-15 00:44:45 +03:00
|
|
|
{
|
2019-10-28 16:57:39 +03:00
|
|
|
free(pChannelOpenEvent);
|
2016-11-15 00:44:45 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-02-11 08:13:29 +04:00
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT VCAPITYPE FreeRDP_VirtualChannelWrite(DWORD openHandle, LPVOID pData, ULONG dataLength,
|
|
|
|
LPVOID pUserData)
|
2014-02-14 02:06:33 +04:00
|
|
|
{
|
2018-07-18 16:16:50 +03:00
|
|
|
wMessage message;
|
2014-02-14 02:06:33 +04:00
|
|
|
CHANNEL_OPEN_DATA* pChannelOpenData;
|
2014-02-15 23:57:10 +04:00
|
|
|
CHANNEL_OPEN_EVENT* pChannelOpenEvent;
|
2020-10-16 10:16:15 +03:00
|
|
|
rdpChannels* channels;
|
2014-02-15 23:57:10 +04:00
|
|
|
|
2020-10-16 10:16:15 +03:00
|
|
|
pChannelOpenData = HashTable_GetItemValue(g_ChannelHandles, (void*)(UINT_PTR)openHandle);
|
2014-02-15 23:57:10 +04:00
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
if (!pChannelOpenData)
|
2014-02-14 02:06:33 +04:00
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2020-10-16 10:16:15 +03:00
|
|
|
channels = pChannelOpenData->channels;
|
|
|
|
if (!channels)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2015-02-07 01:35:14 +03:00
|
|
|
if (!channels->connected)
|
2014-02-14 02:06:33 +04:00
|
|
|
return CHANNEL_RC_NOT_CONNECTED;
|
|
|
|
|
|
|
|
if (!pData)
|
|
|
|
return CHANNEL_RC_NULL_DATA;
|
|
|
|
|
|
|
|
if (!dataLength)
|
|
|
|
return CHANNEL_RC_ZERO_LENGTH;
|
|
|
|
|
|
|
|
if (pChannelOpenData->flags != 2)
|
|
|
|
return CHANNEL_RC_NOT_OPEN;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
pChannelOpenEvent = (CHANNEL_OPEN_EVENT*)malloc(sizeof(CHANNEL_OPEN_EVENT));
|
2014-02-15 23:57:10 +04:00
|
|
|
|
|
|
|
if (!pChannelOpenEvent)
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2014-02-14 02:06:33 +04:00
|
|
|
|
2014-02-15 23:57:10 +04:00
|
|
|
pChannelOpenEvent->Data = pData;
|
|
|
|
pChannelOpenEvent->DataLength = dataLength;
|
|
|
|
pChannelOpenEvent->UserData = pUserData;
|
|
|
|
pChannelOpenEvent->pChannelOpenData = pChannelOpenData;
|
2018-07-18 16:16:50 +03:00
|
|
|
message.context = channels;
|
|
|
|
message.id = 0;
|
|
|
|
message.wParam = pChannelOpenEvent;
|
|
|
|
message.lParam = NULL;
|
|
|
|
message.Free = channel_queue_message_free;
|
2014-02-14 02:06:33 +04:00
|
|
|
|
2018-07-18 16:16:50 +03:00
|
|
|
if (!MessageQueue_Dispatch(channels->queue, &message))
|
2015-07-29 18:32:09 +03:00
|
|
|
{
|
2019-10-28 16:57:39 +03:00
|
|
|
free(pChannelOpenEvent);
|
2015-05-23 23:47:18 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2015-07-29 18:32:09 +03:00
|
|
|
}
|
2014-02-14 02:06:33 +04:00
|
|
|
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-15 00:44:45 +03:00
|
|
|
static BOOL freerdp_channels_is_loaded(rdpChannels* channels, PVIRTUALCHANNELENTRY entry)
|
2015-01-20 20:01:33 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
for (i = 0; i < channels->clientDataCount; i++)
|
2015-01-20 20:01:33 +03:00
|
|
|
{
|
|
|
|
CHANNEL_CLIENT_DATA* pChannelClientData = &channels->clientDataList[i];
|
|
|
|
|
|
|
|
if (pChannelClientData->entry == entry)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-11-15 00:44:45 +03:00
|
|
|
static BOOL freerdp_channels_is_loaded_ex(rdpChannels* channels, PVIRTUALCHANNELENTRYEX entryEx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < channels->clientDataCount; i++)
|
|
|
|
{
|
|
|
|
CHANNEL_CLIENT_DATA* pChannelClientData = &channels->clientDataList[i];
|
|
|
|
|
|
|
|
if (pChannelClientData->entryEx == entryEx)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
int freerdp_channels_client_load(rdpChannels* channels, rdpSettings* settings,
|
|
|
|
PVIRTUALCHANNELENTRY entry, void* data)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
|
|
|
int status;
|
2014-02-17 02:38:59 +04:00
|
|
|
CHANNEL_ENTRY_POINTS_FREERDP EntryPoints;
|
2014-02-11 08:13:29 +04:00
|
|
|
CHANNEL_CLIENT_DATA* pChannelClientData;
|
|
|
|
|
2017-11-28 11:40:04 +03:00
|
|
|
if (channels->clientDataCount + 1 > CHANNEL_MAX_COUNT)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "error: too many channels");
|
2014-02-11 08:13:29 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-01-20 20:01:33 +03:00
|
|
|
if (freerdp_channels_is_loaded(channels, entry))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Skipping, channel already loaded");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-11 08:13:29 +04:00
|
|
|
pChannelClientData = &channels->clientDataList[channels->clientDataCount];
|
2015-01-20 13:58:45 +03:00
|
|
|
pChannelClientData->entry = entry;
|
2014-02-17 02:38:59 +04:00
|
|
|
ZeroMemory(&EntryPoints, sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
|
2014-02-17 02:27:36 +04:00
|
|
|
EntryPoints.cbSize = sizeof(EntryPoints);
|
|
|
|
EntryPoints.protocolVersion = VIRTUAL_CHANNEL_VERSION_WIN2000;
|
|
|
|
EntryPoints.pVirtualChannelInit = FreeRDP_VirtualChannelInit;
|
|
|
|
EntryPoints.pVirtualChannelOpen = FreeRDP_VirtualChannelOpen;
|
|
|
|
EntryPoints.pVirtualChannelClose = FreeRDP_VirtualChannelClose;
|
|
|
|
EntryPoints.pVirtualChannelWrite = FreeRDP_VirtualChannelWrite;
|
|
|
|
EntryPoints.MagicNumber = FREERDP_CHANNEL_MAGIC_NUMBER;
|
|
|
|
EntryPoints.pExtendedData = data;
|
2015-07-15 10:50:35 +03:00
|
|
|
EntryPoints.context = ((freerdp*)settings->instance)->context;
|
2014-02-11 08:13:29 +04:00
|
|
|
/* enable VirtualChannelInit */
|
|
|
|
channels->can_call_init = TRUE;
|
2016-08-09 13:04:06 +03:00
|
|
|
EnterCriticalSection(&channels->channelsLock);
|
2019-11-06 17:24:51 +03:00
|
|
|
status = pChannelClientData->entry((PCHANNEL_ENTRY_POINTS)&EntryPoints);
|
2016-08-09 13:04:06 +03:00
|
|
|
LeaveCriticalSection(&channels->channelsLock);
|
2014-02-11 08:13:29 +04:00
|
|
|
/* disable MyVirtualChannelInit */
|
|
|
|
channels->can_call_init = FALSE;
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "error: channel export function call failed");
|
2014-02-11 08:13:29 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-15 00:44:45 +03:00
|
|
|
int freerdp_channels_client_load_ex(rdpChannels* channels, rdpSettings* settings,
|
2016-11-23 15:17:56 +03:00
|
|
|
PVIRTUALCHANNELENTRYEX entryEx, void* data)
|
2016-11-15 00:44:45 +03:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
void* pInitHandle = NULL;
|
|
|
|
CHANNEL_ENTRY_POINTS_FREERDP_EX EntryPointsEx;
|
|
|
|
CHANNEL_INIT_DATA* pChannelInitData = NULL;
|
|
|
|
CHANNEL_CLIENT_DATA* pChannelClientData = NULL;
|
|
|
|
|
2017-11-28 11:40:04 +03:00
|
|
|
if (channels->clientDataCount + 1 > CHANNEL_MAX_COUNT)
|
2016-11-15 00:44:45 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "error: too many channels");
|
2016-11-15 00:44:45 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (freerdp_channels_is_loaded_ex(channels, entryEx))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Skipping, channel already loaded");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pChannelClientData = &channels->clientDataList[channels->clientDataCount];
|
|
|
|
pChannelClientData->entryEx = entryEx;
|
|
|
|
pChannelInitData = &(channels->initDataList[channels->initDataCount++]);
|
|
|
|
pInitHandle = pChannelInitData;
|
|
|
|
pChannelInitData->channels = channels;
|
|
|
|
ZeroMemory(&EntryPointsEx, sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX));
|
|
|
|
EntryPointsEx.cbSize = sizeof(EntryPointsEx);
|
|
|
|
EntryPointsEx.protocolVersion = VIRTUAL_CHANNEL_VERSION_WIN2000;
|
|
|
|
EntryPointsEx.pVirtualChannelInitEx = FreeRDP_VirtualChannelInitEx;
|
|
|
|
EntryPointsEx.pVirtualChannelOpenEx = FreeRDP_VirtualChannelOpenEx;
|
|
|
|
EntryPointsEx.pVirtualChannelCloseEx = FreeRDP_VirtualChannelCloseEx;
|
|
|
|
EntryPointsEx.pVirtualChannelWriteEx = FreeRDP_VirtualChannelWriteEx;
|
|
|
|
EntryPointsEx.MagicNumber = FREERDP_CHANNEL_MAGIC_NUMBER;
|
|
|
|
EntryPointsEx.pExtendedData = data;
|
2019-11-06 17:24:51 +03:00
|
|
|
EntryPointsEx.context = ((freerdp*)settings->instance)->context;
|
2016-11-15 00:44:45 +03:00
|
|
|
/* enable VirtualChannelInit */
|
|
|
|
channels->can_call_init = TRUE;
|
|
|
|
EnterCriticalSection(&channels->channelsLock);
|
2019-11-06 17:24:51 +03:00
|
|
|
status = pChannelClientData->entryEx((PCHANNEL_ENTRY_POINTS_EX)&EntryPointsEx, pInitHandle);
|
2016-11-15 00:44:45 +03:00
|
|
|
LeaveCriticalSection(&channels->channelsLock);
|
|
|
|
/* disable MyVirtualChannelInit */
|
|
|
|
channels->can_call_init = FALSE;
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
{
|
2016-11-15 18:58:38 +03:00
|
|
|
WLog_ERR(TAG, "error: channel export function call failed");
|
2016-11-15 00:44:45 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-11 08:13:29 +04:00
|
|
|
/**
|
|
|
|
* this is called when processing the command line parameters
|
|
|
|
* called only from main thread
|
|
|
|
*/
|
2016-11-23 15:17:56 +03:00
|
|
|
int freerdp_channels_load_plugin(rdpChannels* channels, rdpSettings* settings, const char* name,
|
|
|
|
void* data)
|
2014-02-11 08:13:29 +04:00
|
|
|
{
|
2016-10-07 15:06:46 +03:00
|
|
|
PVIRTUALCHANNELENTRY entry;
|
2016-11-15 17:09:30 +03:00
|
|
|
entry = freerdp_load_channel_addin_entry(name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC);
|
2014-02-11 08:13:29 +04:00
|
|
|
|
|
|
|
if (!entry)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return freerdp_channels_client_load(channels, settings, entry, data);
|
|
|
|
}
|