2011-07-19 10:07:15 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-19 10:07:15 +04:00
|
|
|
* Dynamic Virtual Channel
|
|
|
|
*
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
2015-05-29 15:02:31 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2011-07-19 10:07:15 +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
|
|
|
|
|
2012-10-09 04:26:11 +04:00
|
|
|
#include <winpr/crt.h>
|
2013-05-14 01:39:53 +04:00
|
|
|
#include <winpr/stream.h>
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
#include "drdynvc_main.h"
|
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
#define TAG CHANNELS_TAG("drdynvc.client")
|
|
|
|
|
2015-01-26 21:26:38 +03:00
|
|
|
static void dvcman_channel_free(void* channel);
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId,
|
|
|
|
const BYTE* data, UINT32 dataSize);
|
2015-01-21 14:58:18 +03:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT dvcman_get_configuration(IWTSListener* pListener, void** ppPropertyBag)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
*ppPropertyBag = NULL;
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT dvcman_create_listener(IWTSVirtualChannelManager* pChannelMgr,
|
2015-09-22 18:53:50 +03:00
|
|
|
const char* pszChannelName, ULONG ulFlags,
|
2014-12-27 23:20:29 +03:00
|
|
|
IWTSListenerCallback* pListenerCallback, IWTSListener** ppListener)
|
|
|
|
{
|
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
|
|
|
DVCMAN_LISTENER* listener;
|
|
|
|
|
|
|
|
if (dvcman->num_listeners < MAX_PLUGINS)
|
|
|
|
{
|
2015-03-13 01:28:44 +03:00
|
|
|
WLog_DBG(TAG, "create_listener: %d.%s.", dvcman->num_listeners, pszChannelName);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
listener = (DVCMAN_LISTENER*) calloc(1, sizeof(DVCMAN_LISTENER));
|
2015-06-29 21:47:46 +03:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!listener)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
listener->iface.GetConfiguration = dvcman_get_configuration;
|
|
|
|
listener->iface.pInterface = NULL;
|
|
|
|
|
|
|
|
listener->dvcman = dvcman;
|
|
|
|
listener->channel_name = _strdup(pszChannelName);
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!listener->channel_name)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "_strdup failed!");
|
|
|
|
free(listener);
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
listener->flags = ulFlags;
|
|
|
|
listener->listener_callback = pListenerCallback;
|
|
|
|
|
|
|
|
if (ppListener)
|
|
|
|
*ppListener = (IWTSListener*) listener;
|
|
|
|
|
|
|
|
dvcman->listeners[dvcman->num_listeners++] = (IWTSListener*) listener;
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-29 15:02:31 +03:00
|
|
|
WLog_ERR(TAG, "create_listener: Maximum DVC listener number reached.");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT dvcman_register_plugin(IDRDYNVC_ENTRY_POINTS* pEntryPoints,
|
|
|
|
const char* name, IWTSPlugin* pPlugin)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
DVCMAN* dvcman = ((DVCMAN_ENTRY_POINTS*) pEntryPoints)->dvcman;
|
|
|
|
|
|
|
|
if (dvcman->num_plugins < MAX_PLUGINS)
|
|
|
|
{
|
|
|
|
dvcman->plugin_names[dvcman->num_plugins] = name;
|
|
|
|
dvcman->plugins[dvcman->num_plugins++] = pPlugin;
|
2015-03-13 01:28:44 +03:00
|
|
|
WLog_DBG(TAG, "register_plugin: num_plugins %d", dvcman->num_plugins);
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-29 15:02:31 +03:00
|
|
|
WLog_ERR(TAG, "register_plugin: Maximum DVC plugin number %d reached.", MAX_PLUGINS);
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static IWTSPlugin* dvcman_get_plugin(IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* name)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
DVCMAN* dvcman = ((DVCMAN_ENTRY_POINTS*) pEntryPoints)->dvcman;
|
|
|
|
|
|
|
|
for (i = 0; i < dvcman->num_plugins; i++)
|
|
|
|
{
|
|
|
|
if (dvcman->plugin_names[i] == name ||
|
|
|
|
strcmp(dvcman->plugin_names[i], name) == 0)
|
|
|
|
{
|
|
|
|
return dvcman->plugins[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static ADDIN_ARGV* dvcman_get_plugin_data(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
return ((DVCMAN_ENTRY_POINTS*) pEntryPoints)->args;
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static void* dvcman_get_rdp_settings(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
return (void*) ((DVCMAN_ENTRY_POINTS*) pEntryPoints)->settings;
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT32 dvcman_get_channel_id(IWTSVirtualChannel * channel)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
return ((DVCMAN_CHANNEL*) channel)->channel_id;
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static IWTSVirtualChannel* dvcman_find_channel_by_id(IWTSVirtualChannelManager* pChannelMgr,
|
|
|
|
UINT32 ChannelId)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
DVCMAN_CHANNEL* channel;
|
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
|
|
|
|
|
|
|
ArrayList_Lock(dvcman->channels);
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
channel = (DVCMAN_CHANNEL*) ArrayList_GetItem(dvcman->channels, index++);
|
|
|
|
|
|
|
|
while (channel)
|
|
|
|
{
|
|
|
|
if (channel->channel_id == ChannelId)
|
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel = (DVCMAN_CHANNEL*) ArrayList_GetItem(dvcman->channels, index++);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayList_Unlock(dvcman->channels);
|
|
|
|
|
|
|
|
return (found) ? ((IWTSVirtualChannel*) channel) : NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static void* dvcman_get_channel_interface_by_name(IWTSVirtualChannelManager* pChannelMgr,
|
|
|
|
const char* ChannelName)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
void* pInterface = NULL;
|
|
|
|
DVCMAN_LISTENER* listener;
|
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
|
|
|
|
|
|
|
for (i = 0; i < dvcman->num_listeners; i++)
|
|
|
|
{
|
|
|
|
listener = (DVCMAN_LISTENER*) dvcman->listeners[i];
|
|
|
|
|
|
|
|
if (strcmp(listener->channel_name, ChannelName) == 0)
|
|
|
|
{
|
|
|
|
pInterface = listener->iface.pInterface;
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (found) ? pInterface : NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static IWTSVirtualChannelManager* dvcman_new(drdynvcPlugin* plugin)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
DVCMAN* dvcman;
|
|
|
|
|
|
|
|
dvcman = (DVCMAN*) calloc(1, sizeof(DVCMAN));
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!dvcman)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
dvcman->iface.CreateListener = dvcman_create_listener;
|
|
|
|
dvcman->iface.FindChannelById = dvcman_find_channel_by_id;
|
|
|
|
dvcman->iface.GetChannelId = dvcman_get_channel_id;
|
|
|
|
dvcman->drdynvc = plugin;
|
|
|
|
dvcman->channels = ArrayList_New(TRUE);
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!dvcman->channels)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ArrayList_New failed!");
|
|
|
|
free(dvcman);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-01-21 14:58:18 +03:00
|
|
|
dvcman->channels->object.fnObjectFree = dvcman_channel_free;
|
2014-12-27 23:20:29 +03:00
|
|
|
dvcman->pool = StreamPool_New(TRUE, 10);
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!dvcman->pool)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "StreamPool_New failed!");
|
|
|
|
ArrayList_Free(dvcman->channels);
|
|
|
|
free(dvcman);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
return (IWTSVirtualChannelManager*) dvcman;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT dvcman_load_addin(IWTSVirtualChannelManager* pChannelMgr, ADDIN_ARGV* args,
|
|
|
|
rdpSettings* settings)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
DVCMAN_ENTRY_POINTS entryPoints;
|
|
|
|
PDVC_PLUGIN_ENTRY pDVCPluginEntry = NULL;
|
|
|
|
|
|
|
|
WLog_INFO(TAG, "Loading Dynamic Virtual Channel %s", args->argv[0]);
|
|
|
|
|
|
|
|
pDVCPluginEntry = (PDVC_PLUGIN_ENTRY) freerdp_load_channel_addin_entry(args->argv[0],
|
|
|
|
NULL, NULL, FREERDP_ADDIN_CHANNEL_DYNAMIC);
|
|
|
|
|
|
|
|
if (pDVCPluginEntry)
|
|
|
|
{
|
|
|
|
entryPoints.iface.RegisterPlugin = dvcman_register_plugin;
|
|
|
|
entryPoints.iface.GetPlugin = dvcman_get_plugin;
|
|
|
|
entryPoints.iface.GetPluginData = dvcman_get_plugin_data;
|
|
|
|
entryPoints.iface.GetRdpSettings = dvcman_get_rdp_settings;
|
|
|
|
entryPoints.dvcman = (DVCMAN*) pChannelMgr;
|
|
|
|
entryPoints.args = args;
|
|
|
|
entryPoints.settings = settings;
|
|
|
|
|
2016-03-07 14:54:49 +03:00
|
|
|
return pDVCPluginEntry((IDRDYNVC_ENTRY_POINTS*) &entryPoints);
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static DVCMAN_CHANNEL* dvcman_channel_new(IWTSVirtualChannelManager* pChannelMgr,
|
|
|
|
UINT32 ChannelId, const char* ChannelName)
|
2014-12-28 19:13:51 +03:00
|
|
|
{
|
|
|
|
DVCMAN_CHANNEL* channel;
|
|
|
|
|
2015-01-26 21:26:38 +03:00
|
|
|
if (dvcman_find_channel_by_id(pChannelMgr, ChannelId))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Protocol error: Duplicated ChannelId %d (%s)!", ChannelId, ChannelName);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-12-28 19:13:51 +03:00
|
|
|
channel = (DVCMAN_CHANNEL*) calloc(1, sizeof(DVCMAN_CHANNEL));
|
|
|
|
|
|
|
|
if (!channel)
|
2015-05-29 15:02:31 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
2014-12-28 19:13:51 +03:00
|
|
|
return NULL;
|
2015-05-29 15:02:31 +03:00
|
|
|
}
|
2014-12-28 19:13:51 +03:00
|
|
|
|
|
|
|
channel->dvcman = (DVCMAN*) pChannelMgr;
|
|
|
|
channel->channel_id = ChannelId;
|
|
|
|
channel->channel_name = _strdup(ChannelName);
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!channel->channel_name)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "_strdup failed!");
|
|
|
|
free(channel);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-12-28 19:13:51 +03:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!InitializeCriticalSectionEx(&(channel->lock), 0 ,0))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "InitializeCriticalSectionEx failed!");
|
|
|
|
free(channel->channel_name);
|
|
|
|
free(channel);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-12-28 19:13:51 +03:00
|
|
|
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static void dvcman_channel_free(void* arg)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2015-01-26 21:26:38 +03:00
|
|
|
DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*) arg;
|
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
if (channel->channel_callback)
|
2015-01-21 14:58:18 +03:00
|
|
|
{
|
2014-12-27 23:20:29 +03:00
|
|
|
channel->channel_callback->OnClose(channel->channel_callback);
|
2015-01-21 14:58:18 +03:00
|
|
|
channel->channel_callback = NULL;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2014-12-28 19:13:51 +03:00
|
|
|
if (channel->dvc_data)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2014-12-28 19:13:51 +03:00
|
|
|
Stream_Release(channel->dvc_data);
|
|
|
|
channel->dvc_data = NULL;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2014-12-28 19:13:51 +03:00
|
|
|
DeleteCriticalSection(&(channel->lock));
|
|
|
|
|
2015-01-21 14:58:18 +03:00
|
|
|
if (channel->channel_name)
|
|
|
|
{
|
|
|
|
free(channel->channel_name);
|
|
|
|
channel->channel_name = NULL;
|
|
|
|
}
|
2014-12-28 19:13:51 +03:00
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
free(channel);
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static void dvcman_free(IWTSVirtualChannelManager* pChannelMgr)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
IWTSPlugin* pPlugin;
|
|
|
|
DVCMAN_LISTENER* listener;
|
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
ArrayList_Free(dvcman->channels);
|
|
|
|
|
|
|
|
for (i = 0; i < dvcman->num_listeners; i++)
|
|
|
|
{
|
|
|
|
listener = (DVCMAN_LISTENER*) dvcman->listeners[i];
|
|
|
|
free(listener->channel_name);
|
|
|
|
free(listener);
|
|
|
|
}
|
|
|
|
|
2015-02-06 01:01:56 +03:00
|
|
|
dvcman->num_listeners = 0;
|
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
for (i = 0; i < dvcman->num_plugins; i++)
|
|
|
|
{
|
|
|
|
pPlugin = dvcman->plugins[i];
|
|
|
|
|
|
|
|
if (pPlugin->Terminated)
|
2015-05-29 15:02:31 +03:00
|
|
|
if ((error = pPlugin->Terminated(pPlugin)))
|
|
|
|
WLog_ERR(TAG, "Terminated failed with error %lu!", error);
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-02-06 01:01:56 +03:00
|
|
|
dvcman->num_plugins = 0;
|
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
StreamPool_Free(dvcman->pool);
|
2015-02-06 01:01:56 +03:00
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
free(dvcman);
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT dvcman_init(IWTSVirtualChannelManager* pChannelMgr)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
IWTSPlugin* pPlugin;
|
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
for (i = 0; i < dvcman->num_plugins; i++)
|
|
|
|
{
|
|
|
|
pPlugin = dvcman->plugins[i];
|
|
|
|
|
|
|
|
if (pPlugin->Initialize)
|
2015-05-29 15:02:31 +03:00
|
|
|
if ((error = pPlugin->Initialize(pPlugin, pChannelMgr)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Initialize failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT dvcman_write_channel(IWTSVirtualChannel* pChannel, ULONG cbSize,
|
|
|
|
const BYTE* pBuffer, void* pReserved)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2014-12-27 23:20:29 +03:00
|
|
|
DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*) pChannel;
|
|
|
|
|
|
|
|
EnterCriticalSection(&(channel->lock));
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
status = drdynvc_write_data(channel->dvcman->drdynvc,
|
|
|
|
channel->channel_id, pBuffer, cbSize);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
LeaveCriticalSection(&(channel->lock));
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT dvcman_close_channel_iface(IWTSVirtualChannel* pChannel)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*) pChannel;
|
|
|
|
|
2015-03-13 01:28:44 +03:00
|
|
|
WLog_DBG(TAG, "close_channel_iface: id=%d", channel->channel_id);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
UINT dvcman_create_channel(IWTSVirtualChannelManager* pChannelMgr,
|
|
|
|
UINT32 ChannelId, const char* ChannelName)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
int i;
|
2015-09-07 14:54:19 +03:00
|
|
|
BOOL bAccept;
|
2014-12-27 23:20:29 +03:00
|
|
|
DVCMAN_LISTENER* listener;
|
|
|
|
DVCMAN_CHANNEL* channel;
|
|
|
|
DrdynvcClientContext* context;
|
|
|
|
IWTSVirtualChannelCallback* pCallback;
|
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!(channel = dvcman_channel_new(pChannelMgr, ChannelId, ChannelName)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "dvcman_channel_new failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2015-01-26 21:26:38 +03:00
|
|
|
|
2014-12-28 19:13:51 +03:00
|
|
|
channel->status = 1;
|
|
|
|
ArrayList_Add(dvcman->channels, channel);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
for (i = 0; i < dvcman->num_listeners; i++)
|
|
|
|
{
|
|
|
|
listener = (DVCMAN_LISTENER*) dvcman->listeners[i];
|
|
|
|
|
|
|
|
if (strcmp(listener->channel_name, ChannelName) == 0)
|
|
|
|
{
|
|
|
|
channel->iface.Write = dvcman_write_channel;
|
|
|
|
channel->iface.Close = dvcman_close_channel_iface;
|
|
|
|
|
2015-09-07 14:54:19 +03:00
|
|
|
bAccept = TRUE;
|
2014-12-27 23:20:29 +03:00
|
|
|
pCallback = NULL;
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if ((error = listener->listener_callback->OnNewChannelConnection(listener->listener_callback,
|
2015-09-07 14:54:19 +03:00
|
|
|
(IWTSVirtualChannel*) channel, NULL, &bAccept, &pCallback)) == CHANNEL_RC_OK && bAccept)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
WLog_DBG(TAG, "listener %s created new channel %d",
|
|
|
|
listener->channel_name, channel->channel_id);
|
|
|
|
|
|
|
|
channel->status = 0;
|
|
|
|
channel->channel_callback = pCallback;
|
|
|
|
channel->pInterface = listener->iface.pInterface;
|
|
|
|
|
|
|
|
context = dvcman->drdynvc->context;
|
2015-05-29 15:02:31 +03:00
|
|
|
IFCALLRET(context->OnChannelConnected, error, context, ChannelName, listener->iface.pInterface);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2016-03-07 14:54:49 +03:00
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context.ReceiveSamples failed with error %lu", error);
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "OnNewChannelConnection failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "OnNewChannelConnection returned with bAccept FALSE!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT dvcman_open_channel(IWTSVirtualChannelManager* pChannelMgr,
|
|
|
|
UINT32 ChannelId)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
DVCMAN_CHANNEL* channel;
|
|
|
|
IWTSVirtualChannelCallback* pCallback;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
channel = (DVCMAN_CHANNEL*) dvcman_find_channel_by_id(pChannelMgr, ChannelId);
|
|
|
|
|
|
|
|
if (!channel)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ChannelId %d not found!", ChannelId);
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (channel->status == CHANNEL_RC_OK)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
pCallback = channel->channel_callback;
|
2015-07-30 16:49:21 +03:00
|
|
|
if ((pCallback->OnOpen) && (error = pCallback->OnOpen(pCallback)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "OnOpen failed with eror %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2015-03-13 01:28:44 +03:00
|
|
|
WLog_DBG(TAG, "open_channel: ChannelId %d", ChannelId);
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT dvcman_close_channel(IWTSVirtualChannelManager* pChannelMgr,
|
|
|
|
UINT32 ChannelId)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
DVCMAN_CHANNEL* channel;
|
|
|
|
IWTSVirtualChannel* ichannel;
|
|
|
|
DrdynvcClientContext* context;
|
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
channel = (DVCMAN_CHANNEL*) dvcman_find_channel_by_id(pChannelMgr, ChannelId);
|
|
|
|
|
|
|
|
if (!channel)
|
|
|
|
{
|
2015-08-25 10:07:04 +03:00
|
|
|
//WLog_ERR(TAG, "ChannelId %d not found!", ChannelId);
|
2015-06-29 21:47:46 +03:00
|
|
|
/**
|
|
|
|
* Windows 8 / Windows Server 2012 send close requests for channels that failed to be created.
|
|
|
|
* Do not warn, simply return success here.
|
|
|
|
*/
|
2015-08-25 10:07:04 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (channel->status == CHANNEL_RC_OK)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
context = dvcman->drdynvc->context;
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
IFCALLRET(context->OnChannelDisconnected, error, context, channel->channel_name, channel->pInterface);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "OnChannelDisconnected returned with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
WLog_DBG(TAG, "dvcman_close_channel: channel %d closed", ChannelId);
|
2014-12-28 19:13:51 +03:00
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
ichannel = (IWTSVirtualChannel*) channel;
|
2014-12-28 19:13:51 +03:00
|
|
|
|
2015-07-30 16:49:21 +03:00
|
|
|
if ((ichannel->Close) && (error = ichannel->Close(ichannel)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Close failed with eror %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-01-21 16:16:23 +03:00
|
|
|
ArrayList_Remove(dvcman->channels, channel);
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT dvcman_receive_channel_data_first(IWTSVirtualChannelManager* pChannelMgr,
|
|
|
|
UINT32 ChannelId, UINT32 length)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
DVCMAN_CHANNEL* channel;
|
|
|
|
|
|
|
|
channel = (DVCMAN_CHANNEL*) dvcman_find_channel_by_id(pChannelMgr, ChannelId);
|
|
|
|
|
|
|
|
if (!channel)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ChannelId %d not found!", ChannelId);
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (channel->dvc_data)
|
|
|
|
Stream_Release(channel->dvc_data);
|
|
|
|
|
|
|
|
channel->dvc_data = StreamPool_Take(channel->dvcman->pool, length);
|
2015-06-29 21:47:46 +03:00
|
|
|
|
2015-03-26 19:09:47 +03:00
|
|
|
if (!channel->dvc_data)
|
2015-05-29 15:02:31 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "StreamPool_Take failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
channel->dvc_data_length = length;
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT dvcman_receive_channel_data(IWTSVirtualChannelManager* pChannelMgr,
|
|
|
|
UINT32 ChannelId, wStream* data)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status = CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
DVCMAN_CHANNEL* channel;
|
2015-05-29 15:02:31 +03:00
|
|
|
size_t dataSize = Stream_GetRemainingLength(data);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
channel = (DVCMAN_CHANNEL*) dvcman_find_channel_by_id(pChannelMgr, ChannelId);
|
|
|
|
|
|
|
|
if (!channel)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ChannelId %d not found!", ChannelId);
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (channel->dvc_data)
|
|
|
|
{
|
|
|
|
/* Fragmented data */
|
|
|
|
if (Stream_GetPosition(channel->dvc_data) + dataSize > (UINT32) Stream_Capacity(channel->dvc_data))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "data exceeding declared length!");
|
|
|
|
Stream_Release(channel->dvc_data);
|
|
|
|
channel->dvc_data = NULL;
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Write(channel->dvc_data, Stream_Pointer(data), dataSize);
|
|
|
|
|
|
|
|
if (((size_t) Stream_GetPosition(channel->dvc_data)) >= channel->dvc_data_length)
|
|
|
|
{
|
|
|
|
Stream_SealLength(channel->dvc_data);
|
|
|
|
Stream_SetPosition(channel->dvc_data, 0);
|
|
|
|
status = channel->channel_callback->OnDataReceived(channel->channel_callback, channel->dvc_data);
|
|
|
|
Stream_Release(channel->dvc_data);
|
|
|
|
channel->dvc_data = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = channel->channel_callback->OnDataReceived(channel->channel_callback, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
static UINT drdynvc_write_variable_uint(wStream* s, UINT32 val)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2015-05-29 15:02:31 +03:00
|
|
|
UINT cb;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
if (val <= 0xFF)
|
|
|
|
{
|
|
|
|
cb = 0;
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write_UINT8(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
else if (val <= 0xFFFF)
|
|
|
|
{
|
|
|
|
cb = 1;
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write_UINT16(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-25 22:27:38 +04:00
|
|
|
cb = 2;
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write_UINT32(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return cb;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT drdynvc_send(drdynvcPlugin* drdynvc, wStream* s)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
if (!drdynvc)
|
|
|
|
{
|
|
|
|
status = CHANNEL_RC_BAD_INIT_HANDLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = drdynvc->channelEntryPoints.pVirtualChannelWrite(drdynvc->OpenHandle,
|
|
|
|
Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
2015-02-06 22:21:26 +03:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
|
2015-01-20 13:58:04 +03:00
|
|
|
WTSErrorToString(status), status);
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId,
|
|
|
|
const BYTE* data, UINT32 dataSize)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* data_out;
|
2016-01-28 13:45:06 +03:00
|
|
|
unsigned long pos;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 cbChId;
|
|
|
|
UINT32 cbLen;
|
2015-05-29 15:02:31 +03:00
|
|
|
unsigned long chunkLength;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2015-03-13 01:28:44 +03:00
|
|
|
WLog_DBG(TAG, "write_data: ChannelId=%d size=%d", ChannelId, dataSize);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
data_out = Stream_New(NULL, CHANNEL_CHUNK_LENGTH);
|
2015-05-29 15:02:31 +03:00
|
|
|
|
|
|
|
if (!data_out)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, 1);
|
2011-07-19 10:07:15 +04:00
|
|
|
cbChId = drdynvc_write_variable_uint(data_out, ChannelId);
|
|
|
|
|
2016-01-28 13:45:06 +03:00
|
|
|
pos = Stream_GetPosition(data_out);
|
2014-06-17 21:34:23 +04:00
|
|
|
if (dataSize == 0)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, 0);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(data_out, 0x40 | cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, pos);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
2014-06-17 21:34:23 +04:00
|
|
|
else if (dataSize <= CHANNEL_CHUNK_LENGTH - pos)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, 0);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(data_out, 0x30 | cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, pos);
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write(data_out, data, dataSize);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Fragment the data */
|
2014-06-17 21:34:23 +04:00
|
|
|
cbLen = drdynvc_write_variable_uint(data_out, dataSize);
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(data_out);
|
|
|
|
Stream_SetPosition(data_out, 0);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(data_out, 0x20 | cbChId | (cbLen << 2));
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, pos);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
chunkLength = CHANNEL_CHUNK_LENGTH - pos;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write(data_out, data, chunkLength);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
data += chunkLength;
|
|
|
|
dataSize -= chunkLength;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
while (status == CHANNEL_RC_OK && dataSize > 0)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-05-09 01:48:30 +04:00
|
|
|
data_out = Stream_New(NULL, CHANNEL_CHUNK_LENGTH);
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!data_out)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, 1);
|
2011-07-19 10:07:15 +04:00
|
|
|
cbChId = drdynvc_write_variable_uint(data_out, ChannelId);
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(data_out);
|
|
|
|
Stream_SetPosition(data_out, 0);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(data_out, 0x30 | cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, pos);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
chunkLength = dataSize;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
if (chunkLength > CHANNEL_CHUNK_LENGTH - pos)
|
|
|
|
chunkLength = CHANNEL_CHUNK_LENGTH - pos;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write(data_out, data, chunkLength);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
data += chunkLength;
|
|
|
|
dataSize -= chunkLength;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
if (status != CHANNEL_RC_OK)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2015-02-06 22:21:26 +03:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
|
2015-01-20 13:58:04 +03:00
|
|
|
WTSErrorToString(status), status);
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT drdynvc_send_capability_response(drdynvcPlugin* drdynvc)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2014-06-17 21:34:23 +04:00
|
|
|
wStream* s;
|
2014-06-03 21:00:03 +04:00
|
|
|
|
2015-03-13 01:28:44 +03:00
|
|
|
WLog_DBG(TAG, "capability_response");
|
2015-06-29 21:47:46 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
s = Stream_New(NULL, 4);
|
2015-05-29 15:02:31 +03:00
|
|
|
|
|
|
|
if (!s)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_Ndrdynvc_write_variable_uintew failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write_UINT16(s, 0x0050); /* Cmd+Sp+cbChId+Pad. Note: MSTSC sends 0x005c */
|
|
|
|
Stream_Write_UINT16(s, drdynvc->version);
|
2014-06-03 21:00:03 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
status = drdynvc_send(drdynvc, s);
|
2014-06-03 21:00:03 +04:00
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
{
|
2015-02-06 22:21:26 +03:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
|
2015-01-20 13:58:04 +03:00
|
|
|
WTSErrorToString(status), status);
|
2014-06-03 21:00:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT drdynvc_process_capability_request(drdynvcPlugin* drdynvc, int Sp,
|
|
|
|
int cbChId, wStream* s)
|
2014-06-03 21:00:03 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2015-03-13 01:28:44 +03:00
|
|
|
WLog_DBG(TAG, "capability_request Sp=%d cbChId=%d", Sp, cbChId);
|
2014-06-03 21:00:03 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, 1); /* pad */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, drdynvc->version);
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2013-05-10 23:57:22 +04:00
|
|
|
/* RDP8 servers offer version 3, though Microsoft forgot to document it
|
|
|
|
* in their early documents. It behaves the same as version 2.
|
|
|
|
*/
|
|
|
|
if ((drdynvc->version == 2) || (drdynvc->version == 3))
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, drdynvc->PriorityCharge0);
|
|
|
|
Stream_Read_UINT16(s, drdynvc->PriorityCharge1);
|
|
|
|
Stream_Read_UINT16(s, drdynvc->PriorityCharge2);
|
|
|
|
Stream_Read_UINT16(s, drdynvc->PriorityCharge3);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2014-06-03 21:00:03 +04:00
|
|
|
status = drdynvc_send_capability_response(drdynvc);
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2014-06-03 21:00:03 +04:00
|
|
|
drdynvc->state = DRDYNVC_STATE_READY;
|
2012-04-25 22:27:38 +04:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
static UINT32 drdynvc_read_variable_uint(wStream* s, int cbLen)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 val;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
switch (cbLen)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Read_UINT8(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case 1:
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Read_UINT16(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
default:
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Read_UINT32(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT drdynvc_process_create_request(drdynvcPlugin* drdynvc, int Sp,
|
|
|
|
int cbChId, wStream* s)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2015-05-29 15:02:31 +03:00
|
|
|
unsigned long pos;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 ChannelId;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* data_out;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT channel_status;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-03 21:00:03 +04:00
|
|
|
if (drdynvc->state == DRDYNVC_STATE_CAPABILITIES)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* For some reason the server does not always send the
|
|
|
|
* capabilities pdu as it should. When this happens,
|
|
|
|
* send a capabilities response.
|
|
|
|
*/
|
|
|
|
|
|
|
|
drdynvc->version = 3;
|
2015-05-29 15:02:31 +03:00
|
|
|
if ((status = drdynvc_send_capability_response(drdynvc)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "drdynvc_send_capability_response failed!");
|
|
|
|
return status;
|
|
|
|
}
|
2014-06-03 21:00:03 +04:00
|
|
|
drdynvc->state = DRDYNVC_STATE_READY;
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:53:00 +04:00
|
|
|
ChannelId = drdynvc_read_variable_uint(s, cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(s);
|
2015-03-13 01:28:44 +03:00
|
|
|
WLog_DBG(TAG, "process_create_request: ChannelId=%d ChannelName=%s", ChannelId, Stream_Pointer(s));
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-03 17:49:00 +04:00
|
|
|
channel_status = dvcman_create_channel(drdynvc->channel_mgr, ChannelId, (char*) Stream_Pointer(s));
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
data_out = Stream_New(NULL, pos + 4);
|
2015-05-29 15:02:31 +03:00
|
|
|
|
|
|
|
if (!s)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(data_out, 0x10 | cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, 1);
|
2016-03-01 13:39:21 +03:00
|
|
|
Stream_Copy(s, data_out, pos - 1);
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (channel_status == CHANNEL_RC_OK)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2014-12-27 23:20:29 +03:00
|
|
|
WLog_DBG(TAG, "channel created");
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(data_out, 0);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-27 23:20:29 +03:00
|
|
|
WLog_DBG(TAG, "no listener");
|
2015-08-25 10:07:04 +03:00
|
|
|
Stream_Write_UINT32(data_out, (UINT32) 0xC0000001); /* same code used by mstsc */
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
if (status != CHANNEL_RC_OK)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2015-02-06 22:21:26 +03:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
|
2015-01-20 13:58:04 +03:00
|
|
|
WTSErrorToString(status), status);
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (channel_status == CHANNEL_RC_OK)
|
2014-06-03 17:49:00 +04:00
|
|
|
{
|
2015-05-29 15:02:31 +03:00
|
|
|
if ((status = dvcman_open_channel(drdynvc->channel_mgr, ChannelId)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "dvcman_open_channel failed with error %lu!", status);
|
|
|
|
return status;
|
|
|
|
}
|
2014-06-03 17:49:00 +04:00
|
|
|
}
|
2015-06-29 21:47:46 +03:00
|
|
|
else
|
|
|
|
{
|
2015-08-25 10:07:04 +03:00
|
|
|
if ((status = dvcman_close_channel(drdynvc->channel_mgr, ChannelId)))
|
|
|
|
WLog_ERR(TAG, "dvcman_close_channel failed with error %lu!", status);
|
2015-06-29 21:47:46 +03:00
|
|
|
}
|
2014-06-03 17:49:00 +04:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT drdynvc_process_data_first(drdynvcPlugin* drdynvc, int Sp,
|
|
|
|
int cbChId, wStream* s)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2012-11-20 07:31:15 +04:00
|
|
|
UINT32 Length;
|
|
|
|
UINT32 ChannelId;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2011-09-19 18:53:00 +04:00
|
|
|
ChannelId = drdynvc_read_variable_uint(s, cbChId);
|
|
|
|
Length = drdynvc_read_variable_uint(s, Sp);
|
2015-03-13 01:28:44 +03:00
|
|
|
WLog_DBG(TAG, "process_data_first: Sp=%d cbChId=%d, ChannelId=%d Length=%d", Sp, cbChId, ChannelId, Length);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2013-05-14 01:39:53 +04:00
|
|
|
status = dvcman_receive_channel_data_first(drdynvc->channel_mgr, ChannelId, Length);
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2013-05-14 01:39:53 +04:00
|
|
|
if (status)
|
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-12 20:03:08 +04:00
|
|
|
return dvcman_receive_channel_data(drdynvc->channel_mgr, ChannelId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT drdynvc_process_data(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 ChannelId;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2011-09-19 18:53:00 +04:00
|
|
|
ChannelId = drdynvc_read_variable_uint(s, cbChId);
|
2015-03-13 01:28:44 +03:00
|
|
|
WLog_DBG(TAG, "process_data: Sp=%d cbChId=%d, ChannelId=%d", Sp, cbChId, ChannelId);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-12 20:03:08 +04:00
|
|
|
return dvcman_receive_channel_data(drdynvc->channel_mgr, ChannelId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT drdynvc_process_close_request(drdynvcPlugin* drdynvc, int Sp,
|
|
|
|
int cbChId, wStream* s)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-09-13 17:22:10 +04:00
|
|
|
int value;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-11-12 21:34:07 +03:00
|
|
|
UINT32 ChannelId;
|
|
|
|
wStream* data_out;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2011-09-19 18:53:00 +04:00
|
|
|
ChannelId = drdynvc_read_variable_uint(s, cbChId);
|
2014-12-28 19:13:51 +03:00
|
|
|
|
2015-03-13 01:28:44 +03:00
|
|
|
WLog_DBG(TAG, "process_close_request: Sp=%d cbChId=%d, ChannelId=%d", Sp, cbChId, ChannelId);
|
2014-12-28 19:13:51 +03:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if ((error = dvcman_close_channel(drdynvc->channel_mgr, ChannelId)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "dvcman_close_channel failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2016-03-07 14:54:49 +03:00
|
|
|
|
2013-09-13 17:22:10 +04:00
|
|
|
data_out = Stream_New(NULL, 4);
|
2015-05-29 15:02:31 +03:00
|
|
|
|
|
|
|
if (!data_out)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2013-09-17 00:48:08 +04:00
|
|
|
value = (CLOSE_REQUEST_PDU << 4) | (cbChId & 0x03);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2013-09-13 17:22:10 +04:00
|
|
|
Stream_Write_UINT8(data_out, value);
|
|
|
|
drdynvc_write_variable_uint(data_out, ChannelId);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
error = drdynvc_send(drdynvc, data_out);
|
2015-05-29 15:02:31 +03:00
|
|
|
|
|
|
|
if (error)
|
2015-02-06 22:21:26 +03:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
|
2015-01-20 13:58:04 +03:00
|
|
|
WTSErrorToString(error), error);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return error;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT drdynvc_order_recv(drdynvcPlugin* drdynvc, wStream* s)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
|
|
|
int value;
|
|
|
|
int Cmd;
|
|
|
|
int Sp;
|
|
|
|
int cbChId;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, value);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
Cmd = (value & 0xf0) >> 4;
|
|
|
|
Sp = (value & 0x0c) >> 2;
|
|
|
|
cbChId = (value & 0x03) >> 0;
|
2011-09-19 18:53:00 +04:00
|
|
|
|
2015-03-13 01:28:44 +03:00
|
|
|
WLog_DBG(TAG, "order_recv: Cmd=0x%x, Sp=%d cbChId=%d, ChannelId=%d", Cmd, Sp, cbChId);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
switch (Cmd)
|
|
|
|
{
|
|
|
|
case CAPABILITY_REQUEST_PDU:
|
2015-05-29 15:02:31 +03:00
|
|
|
return drdynvc_process_capability_request(drdynvc, Sp, cbChId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case CREATE_REQUEST_PDU:
|
2015-05-29 15:02:31 +03:00
|
|
|
return drdynvc_process_create_request(drdynvc, Sp, cbChId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case DATA_FIRST_PDU:
|
2015-05-29 15:02:31 +03:00
|
|
|
return drdynvc_process_data_first(drdynvc, Sp, cbChId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case DATA_PDU:
|
2015-05-29 15:02:31 +03:00
|
|
|
return drdynvc_process_data(drdynvc, Sp, cbChId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case CLOSE_REQUEST_PDU:
|
2015-05-29 15:02:31 +03:00
|
|
|
return drdynvc_process_close_request(drdynvc, Sp, cbChId, s);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
default:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "unknown drdynvc cmd 0x%x", Cmd);
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
/****************************************************************************************/
|
|
|
|
|
2015-01-20 14:31:39 +03:00
|
|
|
static wListDictionary* g_InitHandles = NULL;
|
|
|
|
static wListDictionary* g_OpenHandles = NULL;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT drdynvc_add_init_handle_data(void* pInitHandle, void* pUserData)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2014-11-12 21:34:07 +03:00
|
|
|
if (!g_InitHandles)
|
|
|
|
g_InitHandles = ListDictionary_New(TRUE);
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!g_InitHandles)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ListDictionary_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ListDictionary_Add(g_InitHandles, pInitHandle, pUserData))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ListDictionary_New failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static void* drdynvc_get_init_handle_data(void* pInitHandle)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
|
|
|
void* pUserData = NULL;
|
|
|
|
pUserData = ListDictionary_GetItemValue(g_InitHandles, pInitHandle);
|
|
|
|
return pUserData;
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static void drdynvc_remove_init_handle_data(void* pInitHandle)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
|
|
|
ListDictionary_Remove(g_InitHandles, pInitHandle);
|
2015-06-29 21:47:46 +03:00
|
|
|
|
2015-01-20 14:31:39 +03:00
|
|
|
if (ListDictionary_Count(g_InitHandles) < 1)
|
|
|
|
{
|
|
|
|
ListDictionary_Free(g_InitHandles);
|
|
|
|
g_InitHandles = NULL;
|
|
|
|
}
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT drdynvc_add_open_handle_data(DWORD openHandle, void* pUserData)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
|
|
|
void* pOpenHandle = (void*) (size_t) openHandle;
|
|
|
|
|
|
|
|
if (!g_OpenHandles)
|
|
|
|
g_OpenHandles = ListDictionary_New(TRUE);
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!g_OpenHandles)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ListDictionary_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ListDictionary_Add(g_OpenHandles, pOpenHandle, pUserData))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ListDictionary_New failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static void* drdynvc_get_open_handle_data(DWORD openHandle)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
|
|
|
void* pUserData = NULL;
|
|
|
|
void* pOpenHandle = (void*) (size_t) openHandle;
|
|
|
|
pUserData = ListDictionary_GetItemValue(g_OpenHandles, pOpenHandle);
|
|
|
|
return pUserData;
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static void drdynvc_remove_open_handle_data(DWORD openHandle)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
|
|
|
void* pOpenHandle = (void*) (size_t) openHandle;
|
2016-03-07 14:54:49 +03:00
|
|
|
|
|
|
|
if (!g_OpenHandles)
|
|
|
|
return;
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
ListDictionary_Remove(g_OpenHandles, pOpenHandle);
|
2015-06-29 21:47:46 +03:00
|
|
|
|
2015-01-20 14:31:39 +03:00
|
|
|
if (ListDictionary_Count(g_OpenHandles) < 1)
|
|
|
|
{
|
|
|
|
ListDictionary_Free(g_OpenHandles);
|
|
|
|
g_OpenHandles = NULL;
|
|
|
|
}
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT drdynvc_virtual_channel_event_data_received(drdynvcPlugin* drdynvc,
|
2014-11-12 21:34:07 +03:00
|
|
|
void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
|
|
|
|
{
|
|
|
|
wStream* data_in;
|
|
|
|
|
|
|
|
if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME))
|
|
|
|
{
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dataFlags & CHANNEL_FLAG_FIRST)
|
|
|
|
{
|
|
|
|
if (drdynvc->data_in)
|
|
|
|
Stream_Free(drdynvc->data_in, TRUE);
|
|
|
|
|
|
|
|
drdynvc->data_in = Stream_New(NULL, totalLength);
|
|
|
|
}
|
|
|
|
|
2015-03-30 18:23:22 +03:00
|
|
|
if (!(data_in = drdynvc->data_in))
|
2015-05-29 15:02:31 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2015-03-30 18:23:22 +03:00
|
|
|
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(data_in, (int) dataLength))
|
2015-03-26 19:09:47 +03:00
|
|
|
{
|
2015-05-29 15:02:31 +03:00
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
2015-03-26 19:09:47 +03:00
|
|
|
Stream_Free(drdynvc->data_in, TRUE);
|
|
|
|
drdynvc->data_in = NULL;
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-03-26 19:09:47 +03:00
|
|
|
}
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
Stream_Write(data_in, pData, dataLength);
|
|
|
|
|
|
|
|
if (dataFlags & CHANNEL_FLAG_LAST)
|
|
|
|
{
|
|
|
|
if (Stream_Capacity(data_in) != Stream_GetPosition(data_in))
|
|
|
|
{
|
2015-02-06 22:21:26 +03:00
|
|
|
WLog_ERR(TAG, "drdynvc_plugin_process_received: read error");
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
drdynvc->data_in = NULL;
|
|
|
|
Stream_SealLength(data_in);
|
|
|
|
Stream_SetPosition(data_in, 0);
|
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (!MessageQueue_Post(drdynvc->queue, NULL, 0, (void*) data_in, NULL))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "MessageQueue_Post failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
static void VCAPITYPE drdynvc_virtual_channel_open_event(DWORD openHandle, UINT event,
|
2014-11-12 21:34:07 +03:00
|
|
|
LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
|
|
|
|
{
|
|
|
|
drdynvcPlugin* drdynvc;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
drdynvc = (drdynvcPlugin*) drdynvc_get_open_handle_data(openHandle);
|
|
|
|
|
|
|
|
if (!drdynvc)
|
|
|
|
{
|
2015-02-06 22:21:26 +03:00
|
|
|
WLog_ERR(TAG, "drdynvc_virtual_channel_open_event: error no match");
|
2014-11-12 21:34:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case CHANNEL_EVENT_DATA_RECEIVED:
|
2015-07-15 10:50:35 +03:00
|
|
|
if ((error = drdynvc_virtual_channel_event_data_received(drdynvc, pData, dataLength, totalLength, dataFlags)))
|
|
|
|
WLog_ERR(TAG, "drdynvc_virtual_channel_event_data_received failed with error %lu", error);
|
2014-11-12 21:34:07 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_WRITE_COMPLETE:
|
|
|
|
Stream_Free((wStream*) pData, TRUE);
|
|
|
|
break;
|
2015-01-20 13:58:04 +03:00
|
|
|
|
|
|
|
case CHANNEL_EVENT_USER:
|
|
|
|
break;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
2015-07-15 10:50:35 +03:00
|
|
|
if (error && drdynvc->rdpcontext)
|
|
|
|
setChannelError(drdynvc->rdpcontext, error, "drdynvc_virtual_channel_open_event reported an error");
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void* drdynvc_virtual_channel_client_thread(void* arg)
|
|
|
|
{
|
|
|
|
wStream* data;
|
|
|
|
wMessage message;
|
|
|
|
drdynvcPlugin* drdynvc = (drdynvcPlugin*) arg;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2014-12-27 23:20:29 +03:00
|
|
|
if (!MessageQueue_Wait(drdynvc->queue))
|
2015-07-15 10:50:35 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "MessageQueue_Wait failed!");
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
2014-11-12 21:34:07 +03:00
|
|
|
break;
|
2015-07-15 10:50:35 +03:00
|
|
|
}
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (!MessageQueue_Peek(drdynvc->queue, &message, TRUE))
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
2015-07-15 10:50:35 +03:00
|
|
|
WLog_ERR(TAG, "MessageQueue_Peek failed!");
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (message.id == WMQ_QUIT)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (message.id == 0)
|
|
|
|
{
|
|
|
|
data = (wStream*) message.wParam;
|
|
|
|
if ((error = drdynvc_order_recv(drdynvc, data)))
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
2014-12-15 20:36:56 +03:00
|
|
|
Stream_Free(data, TRUE);
|
2015-07-15 10:50:35 +03:00
|
|
|
WLog_ERR(TAG, "drdynvc_order_recv failed with error %lu!", error);
|
|
|
|
break;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
2015-07-15 10:50:35 +03:00
|
|
|
Stream_Free(data, TRUE);
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (error && drdynvc->rdpcontext)
|
|
|
|
setChannelError(drdynvc->rdpcontext, error, "drdynvc_virtual_channel_client_thread reported an error");
|
2015-05-29 15:02:31 +03:00
|
|
|
ExitThread((DWORD) error);
|
2014-11-12 21:34:07 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT drdynvc_virtual_channel_event_connected(drdynvcPlugin* drdynvc,
|
|
|
|
LPVOID pData, UINT32 dataLength)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
|
|
|
UINT32 status;
|
2014-02-11 07:12:13 +04:00
|
|
|
UINT32 index;
|
2012-11-20 07:31:15 +04:00
|
|
|
ADDIN_ARGV* args;
|
|
|
|
rdpSettings* settings;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
status = drdynvc->channelEntryPoints.pVirtualChannelOpen(drdynvc->InitHandle,
|
|
|
|
&drdynvc->OpenHandle, drdynvc->channelDef.name, drdynvc_virtual_channel_open_event);
|
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
{
|
2015-02-06 22:21:26 +03:00
|
|
|
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
|
2015-01-20 13:58:04 +03:00
|
|
|
WTSErrorToString(status), status);
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = drdynvc_add_open_handle_data(drdynvc->OpenHandle, drdynvc)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "drdynvc_add_open_handle_data failed with error %lu!", error);
|
|
|
|
return error;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
drdynvc->queue = MessageQueue_New(NULL);
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!drdynvc->queue)
|
|
|
|
{
|
|
|
|
error = CHANNEL_RC_NO_MEMORY;
|
|
|
|
WLog_ERR(TAG, "MessageQueue_New failed!");
|
|
|
|
goto error;
|
|
|
|
}
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
drdynvc->channel_mgr = dvcman_new(drdynvc);
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!drdynvc->channel_mgr)
|
|
|
|
{
|
|
|
|
error = CHANNEL_RC_NO_MEMORY;
|
|
|
|
WLog_ERR(TAG, "dvcman_new failed!");
|
|
|
|
goto error;
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
settings = (rdpSettings*) drdynvc->channelEntryPoints.pExtendedData;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
|
|
|
for (index = 0; index < settings->DynamicChannelCount; index++)
|
|
|
|
{
|
|
|
|
args = settings->DynamicChannelArray[index];
|
2016-03-07 14:54:49 +03:00
|
|
|
error = dvcman_load_addin(drdynvc->channel_mgr, args, settings);
|
|
|
|
if (CHANNEL_RC_OK != error)
|
|
|
|
goto error;
|
2012-11-20 07:31:15 +04:00
|
|
|
}
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if ((error = dvcman_init(drdynvc->channel_mgr)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "dvcman_init failed with error %lu!", error);
|
|
|
|
goto error;
|
|
|
|
}
|
2014-06-03 21:00:03 +04:00
|
|
|
|
|
|
|
drdynvc->state = DRDYNVC_STATE_CAPABILITIES;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!(drdynvc->thread = CreateThread(NULL, 0,
|
|
|
|
(LPTHREAD_START_ROUTINE) drdynvc_virtual_channel_client_thread, (void*) drdynvc, 0, NULL)))
|
|
|
|
{
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
|
|
|
WLog_ERR(TAG, "CreateThread failed!");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
error:
|
|
|
|
drdynvc_remove_open_handle_data(drdynvc->OpenHandle);
|
|
|
|
return error;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT drdynvc_virtual_channel_event_disconnected(drdynvcPlugin* drdynvc)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2014-12-27 21:50:50 +03:00
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
if (MessageQueue_PostQuit(drdynvc->queue, 0) &&
|
|
|
|
(WaitForSingleObject(drdynvc->thread, INFINITE) == WAIT_FAILED))
|
2016-03-07 14:54:49 +03:00
|
|
|
{
|
|
|
|
status = GetLastError();
|
|
|
|
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", status);
|
|
|
|
return status;
|
|
|
|
}
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2015-01-20 13:58:04 +03:00
|
|
|
MessageQueue_Free(drdynvc->queue);
|
|
|
|
CloseHandle(drdynvc->thread);
|
|
|
|
|
|
|
|
drdynvc->queue = NULL;
|
|
|
|
drdynvc->thread = NULL;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2015-02-07 01:35:14 +03:00
|
|
|
status = drdynvc->channelEntryPoints.pVirtualChannelClose(drdynvc->OpenHandle);
|
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
2015-01-20 13:58:04 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
|
2015-02-07 01:35:14 +03:00
|
|
|
WTSErrorToString(status), status);
|
2015-01-20 13:58:04 +03:00
|
|
|
}
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
if (drdynvc->data_in)
|
|
|
|
{
|
|
|
|
Stream_Free(drdynvc->data_in, TRUE);
|
|
|
|
drdynvc->data_in = NULL;
|
|
|
|
}
|
2014-06-20 01:08:50 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
if (drdynvc->channel_mgr)
|
2014-06-20 01:08:50 +04:00
|
|
|
{
|
2011-07-19 10:07:15 +04:00
|
|
|
dvcman_free(drdynvc->channel_mgr);
|
2014-06-20 01:08:50 +04:00
|
|
|
drdynvc->channel_mgr = NULL;
|
|
|
|
}
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc_remove_open_handle_data(drdynvc->OpenHandle);
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
2015-01-20 13:58:04 +03:00
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT drdynvc_virtual_channel_event_terminated(drdynvcPlugin* drdynvc)
|
2015-01-20 13:58:04 +03:00
|
|
|
{
|
|
|
|
drdynvc_remove_init_handle_data(drdynvc->InitHandle);
|
2014-12-27 23:20:29 +03:00
|
|
|
free(drdynvc);
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2016-03-14 15:19:08 +03:00
|
|
|
static VOID VCAPITYPE drdynvc_virtual_channel_init_event(LPVOID pInitHandle,
|
2016-03-07 14:54:49 +03:00
|
|
|
UINT event, LPVOID pData,
|
|
|
|
UINT dataLength)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
|
|
|
drdynvcPlugin* drdynvc;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-06-12 20:03:08 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc = (drdynvcPlugin*) drdynvc_get_init_handle_data(pInitHandle);
|
|
|
|
|
|
|
|
if (!drdynvc)
|
|
|
|
{
|
2015-02-06 22:21:26 +03:00
|
|
|
WLog_ERR(TAG, "drdynvc_virtual_channel_init_event: error no match");
|
2016-03-14 15:19:08 +03:00
|
|
|
return;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case CHANNEL_EVENT_CONNECTED:
|
2015-07-15 10:50:35 +03:00
|
|
|
if ((error = drdynvc_virtual_channel_event_connected(drdynvc, pData, dataLength)))
|
|
|
|
WLog_ERR(TAG, "drdynvc_virtual_channel_event_connected failed with error %lu", error);
|
2014-11-12 21:34:07 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_DISCONNECTED:
|
2015-07-15 10:50:35 +03:00
|
|
|
if ((error = drdynvc_virtual_channel_event_disconnected(drdynvc)))
|
|
|
|
WLog_ERR(TAG, "drdynvc_virtual_channel_event_disconnected failed with error %lu", error);
|
2014-11-12 21:34:07 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_TERMINATED:
|
2015-07-15 10:50:35 +03:00
|
|
|
if ((error = drdynvc_virtual_channel_event_terminated(drdynvc)))
|
|
|
|
WLog_ERR(TAG, "drdynvc_virtual_channel_event_terminated failed with error %lu", error);
|
2014-11-12 21:34:07 +03:00
|
|
|
break;
|
|
|
|
}
|
2015-07-15 10:50:35 +03:00
|
|
|
if (error && drdynvc->rdpcontext)
|
|
|
|
setChannelError(drdynvc->rdpcontext, error, "drdynvc_virtual_channel_init_event reported an error");
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
/**
|
|
|
|
* Channel Client Interface
|
|
|
|
*/
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static int drdynvc_get_version(DrdynvcClientContext* context)
|
2013-05-14 00:07:42 +04:00
|
|
|
{
|
|
|
|
drdynvcPlugin* drdynvc = (drdynvcPlugin*) context->handle;
|
|
|
|
return drdynvc->version;
|
|
|
|
}
|
|
|
|
|
2012-10-09 06:48:17 +04:00
|
|
|
/* drdynvc is always built-in */
|
2012-10-09 04:26:11 +04:00
|
|
|
#define VirtualChannelEntry drdynvc_VirtualChannelEntry
|
|
|
|
|
2014-03-04 03:28:31 +04:00
|
|
|
BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
|
2012-10-09 04:26:11 +04:00
|
|
|
{
|
2015-01-20 13:58:04 +03:00
|
|
|
UINT rc;
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvcPlugin* drdynvc;
|
2013-05-14 00:07:42 +04:00
|
|
|
DrdynvcClientContext* context;
|
2014-02-17 02:38:59 +04:00
|
|
|
CHANNEL_ENTRY_POINTS_FREERDP* pEntryPointsEx;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc = (drdynvcPlugin*) calloc(1, sizeof(drdynvcPlugin));
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
if (!drdynvc)
|
2015-05-29 15:02:31 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
2014-06-17 21:34:23 +04:00
|
|
|
return FALSE;
|
2015-05-29 15:02:31 +03:00
|
|
|
}
|
2014-06-17 21:34:23 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc->channelDef.options =
|
2012-10-09 04:26:11 +04:00
|
|
|
CHANNEL_OPTION_INITIALIZED |
|
|
|
|
CHANNEL_OPTION_ENCRYPT_RDP |
|
|
|
|
CHANNEL_OPTION_COMPRESS_RDP;
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
strcpy(drdynvc->channelDef.name, "drdynvc");
|
2014-06-03 21:00:03 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc->state = DRDYNVC_STATE_INITIAL;
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2014-02-17 02:38:59 +04:00
|
|
|
pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP*) pEntryPoints;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2014-02-17 02:38:59 +04:00
|
|
|
if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP)) &&
|
2013-05-14 00:07:42 +04:00
|
|
|
(pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))
|
|
|
|
{
|
2014-06-17 21:34:23 +04:00
|
|
|
context = (DrdynvcClientContext*) calloc(1, sizeof(DrdynvcClientContext));
|
|
|
|
|
|
|
|
if (!context)
|
2014-11-16 18:02:28 +03:00
|
|
|
{
|
2015-05-29 15:02:31 +03:00
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
2014-11-16 18:02:28 +03:00
|
|
|
free(drdynvc);
|
2015-05-29 15:02:31 +03:00
|
|
|
return FALSE;
|
2014-11-16 18:02:28 +03:00
|
|
|
}
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
context->handle = (void*) drdynvc;
|
|
|
|
context->custom = NULL;
|
|
|
|
|
|
|
|
drdynvc->context = context;
|
2013-05-14 01:39:53 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
context->GetVersion = drdynvc_get_version;
|
2015-07-15 10:50:35 +03:00
|
|
|
drdynvc->rdpcontext = pEntryPointsEx->context;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
|
|
|
*(pEntryPointsEx->ppInterface) = (void*) context;
|
|
|
|
}
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc->log = WLog_Get("com.freerdp.channels.drdynvc.client");
|
|
|
|
|
|
|
|
WLog_Print(drdynvc->log, WLOG_DEBUG, "VirtualChannelEntry");
|
|
|
|
|
|
|
|
CopyMemory(&(drdynvc->channelEntryPoints), pEntryPoints, sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
|
|
|
|
|
2015-01-20 13:58:04 +03:00
|
|
|
rc = drdynvc->channelEntryPoints.pVirtualChannelInit(&drdynvc->InitHandle,
|
2014-11-12 21:34:07 +03:00
|
|
|
&drdynvc->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, drdynvc_virtual_channel_init_event);
|
2015-05-29 15:02:31 +03:00
|
|
|
|
2015-01-20 13:58:04 +03:00
|
|
|
if (CHANNEL_RC_OK != rc)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
|
|
|
|
WTSErrorToString(rc), rc);
|
|
|
|
free(drdynvc);
|
2015-05-29 15:02:31 +03:00
|
|
|
free(*(pEntryPointsEx->ppInterface));
|
|
|
|
*(pEntryPointsEx->ppInterface) = NULL;
|
|
|
|
return FALSE;
|
2015-01-20 13:58:04 +03:00
|
|
|
}
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
drdynvc->channelEntryPoints.pInterface = *(drdynvc->channelEntryPoints.ppInterface);
|
|
|
|
drdynvc->channelEntryPoints.ppInterface = &(drdynvc->channelEntryPoints.pInterface);
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if ((error = drdynvc_add_init_handle_data(drdynvc->InitHandle, (void*) drdynvc)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "drdynvc_add_init_handle_data failed with error %lu!",error);
|
|
|
|
free(drdynvc);
|
|
|
|
free(*(pEntryPointsEx->ppInterface));
|
|
|
|
*(pEntryPointsEx->ppInterface) = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return TRUE;
|
2012-10-09 04:26:11 +04:00
|
|
|
}
|
2014-06-12 20:03:08 +04:00
|
|
|
|