2012-10-13 18:17:52 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Server Channels
|
|
|
|
*
|
2012-10-16 01:03:34 +04:00
|
|
|
* Copyright 2011-2012 Vic Lee
|
2012-10-13 18:17:52 +04:00
|
|
|
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* 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-10-19 21:10:42 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-10-13 18:17:52 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
#include <freerdp/constants.h>
|
2012-10-13 18:17:52 +04:00
|
|
|
#include <freerdp/server/channels.h>
|
|
|
|
|
2012-11-22 05:21:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2012-10-16 01:03:34 +04:00
|
|
|
#include <winpr/synch.h>
|
2013-04-30 06:35:15 +04:00
|
|
|
#include <winpr/stream.h>
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
#include "channels.h"
|
|
|
|
|
2012-10-19 21:10:42 +04:00
|
|
|
/**
|
|
|
|
* this is a workaround to force importing symbols
|
|
|
|
* will need to fix that later on cleanly
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <freerdp/server/audin.h>
|
|
|
|
#include <freerdp/server/rdpsnd.h>
|
|
|
|
|
|
|
|
void freerdp_channels_dummy()
|
|
|
|
{
|
|
|
|
audin_server_context_new(NULL);
|
|
|
|
audin_server_context_free(NULL);
|
|
|
|
|
|
|
|
rdpsnd_server_context_new(NULL);
|
|
|
|
rdpsnd_server_context_free(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* end of ugly symbols import workaround
|
|
|
|
*/
|
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
#define CREATE_REQUEST_PDU 0x01
|
|
|
|
#define DATA_FIRST_PDU 0x02
|
|
|
|
#define DATA_PDU 0x03
|
|
|
|
#define CLOSE_REQUEST_PDU 0x04
|
|
|
|
#define CAPABILITY_REQUEST_PDU 0x05
|
|
|
|
|
|
|
|
typedef struct wts_data_item
|
|
|
|
{
|
|
|
|
UINT16 channel_id;
|
|
|
|
BYTE* buffer;
|
|
|
|
UINT32 length;
|
|
|
|
} wts_data_item;
|
|
|
|
|
|
|
|
static void wts_data_item_free(wts_data_item* item)
|
|
|
|
{
|
|
|
|
free(item->buffer);
|
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
2012-10-13 18:17:52 +04:00
|
|
|
void* freerdp_channels_server_find_static_entry(const char* name, const char* entry)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
static rdpPeerChannel* wts_get_dvc_channel_by_id(WTSVirtualChannelManager* vcm, UINT32 ChannelId)
|
|
|
|
{
|
|
|
|
LIST_ITEM* item;
|
|
|
|
rdpPeerChannel* channel = NULL;
|
|
|
|
|
|
|
|
for (item = vcm->dvc_channel_list->head; item; item = item->next)
|
|
|
|
{
|
|
|
|
channel = (rdpPeerChannel*) item->data;
|
|
|
|
|
|
|
|
if (channel->channel_id == ChannelId)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wts_queue_receive_data(rdpPeerChannel* channel, const BYTE* buffer, UINT32 length)
|
|
|
|
{
|
|
|
|
wts_data_item* item;
|
|
|
|
|
2012-11-22 05:21:08 +04:00
|
|
|
item = (wts_data_item*) malloc(sizeof(wts_data_item));
|
|
|
|
ZeroMemory(item, sizeof(wts_data_item));
|
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
item->length = length;
|
|
|
|
item->buffer = malloc(length);
|
2013-03-08 00:33:27 +04:00
|
|
|
CopyMemory(item->buffer, buffer, length);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
WaitForSingleObject(channel->mutex, INFINITE);
|
|
|
|
list_enqueue(channel->receive_queue, item);
|
|
|
|
ReleaseMutex(channel->mutex);
|
|
|
|
|
2012-11-27 05:15:48 +04:00
|
|
|
SetEvent(channel->receive_event);
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wts_queue_send_item(rdpPeerChannel* channel, wts_data_item* item)
|
|
|
|
{
|
|
|
|
WTSVirtualChannelManager* vcm;
|
|
|
|
|
|
|
|
vcm = channel->vcm;
|
|
|
|
|
|
|
|
item->channel_id = channel->channel_id;
|
|
|
|
|
|
|
|
WaitForSingleObject(vcm->mutex, INFINITE);
|
|
|
|
list_enqueue(vcm->send_queue, item);
|
|
|
|
ReleaseMutex(vcm->mutex);
|
|
|
|
|
2012-11-27 05:15:48 +04:00
|
|
|
SetEvent(vcm->send_event);
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static int wts_read_variable_uint(wStream* s, int cbLen, UINT32* val)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
|
|
|
switch (cbLen)
|
|
|
|
{
|
|
|
|
case 0:
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 1)
|
2012-10-16 01:03:34 +04:00
|
|
|
return 0;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, *val);
|
2012-10-16 01:03:34 +04:00
|
|
|
return 1;
|
2013-03-08 00:33:27 +04:00
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
case 1:
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 2)
|
2012-10-16 01:03:34 +04:00
|
|
|
return 0;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, *val);
|
2012-10-16 01:03:34 +04:00
|
|
|
return 2;
|
2013-03-08 00:33:27 +04:00
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
default:
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2012-10-16 01:03:34 +04:00
|
|
|
return 0;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, *val);
|
2012-10-16 01:03:34 +04:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, UINT32 length)
|
|
|
|
{
|
|
|
|
UINT16 Version;
|
|
|
|
|
|
|
|
if (length < 3)
|
|
|
|
return;
|
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Seek_UINT8(channel->receive_data); /* Pad (1 byte) */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(channel->receive_data, Version);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
DEBUG_DVC("Version: %d", Version);
|
|
|
|
|
|
|
|
channel->vcm->drdynvc_state = DRDYNVC_STATE_READY;
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void wts_read_drdynvc_create_response(rdpPeerChannel* channel, wStream* s, UINT32 length)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
|
|
|
UINT32 CreationStatus;
|
|
|
|
|
|
|
|
if (length < 4)
|
|
|
|
return;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, CreationStatus);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
if ((INT32) CreationStatus < 0)
|
|
|
|
{
|
2012-11-18 02:03:02 +04:00
|
|
|
DEBUG_DVC("ChannelId %d creation failed (%d)", channel->channel_id, (INT32) CreationStatus);
|
2012-10-16 01:03:34 +04:00
|
|
|
channel->dvc_open_state = DVC_OPEN_STATE_FAILED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-18 02:03:02 +04:00
|
|
|
DEBUG_DVC("ChannelId %d creation succeeded", channel->channel_id);
|
2012-10-16 01:03:34 +04:00
|
|
|
channel->dvc_open_state = DVC_OPEN_STATE_SUCCEEDED;
|
|
|
|
}
|
2012-11-27 05:15:48 +04:00
|
|
|
|
|
|
|
SetEvent(channel->receive_event);
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void wts_read_drdynvc_data_first(rdpPeerChannel* channel, wStream* s, int cbLen, UINT32 length)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
|
|
|
int value;
|
|
|
|
|
|
|
|
value = wts_read_variable_uint(s, cbLen, &channel->dvc_total_length);
|
|
|
|
|
|
|
|
if (value == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
length -= value;
|
|
|
|
|
|
|
|
if (length > channel->dvc_total_length)
|
|
|
|
return;
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(channel->receive_data, 0);
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(channel->receive_data, (int) channel->dvc_total_length);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(channel->receive_data, Stream_Pointer(s), length);
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void wts_read_drdynvc_data(rdpPeerChannel* channel, wStream* s, UINT32 length)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
|
|
|
if (channel->dvc_total_length > 0)
|
|
|
|
{
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetPosition(channel->receive_data) + length > channel->dvc_total_length)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
|
|
|
channel->dvc_total_length = 0;
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "wts_read_drdynvc_data: incorrect fragment data, discarded.\n");
|
2012-10-16 01:03:34 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(channel->receive_data, Stream_Pointer(s), length);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetPosition(channel->receive_data) >= (int) channel->dvc_total_length)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
2013-05-09 00:27:21 +04:00
|
|
|
wts_queue_receive_data(channel, Stream_Buffer(channel->receive_data), channel->dvc_total_length);
|
2012-10-16 01:03:34 +04:00
|
|
|
channel->dvc_total_length = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-30 06:35:15 +04:00
|
|
|
wts_queue_receive_data(channel, Stream_Pointer(s), length);
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wts_read_drdynvc_close_response(rdpPeerChannel* channel)
|
|
|
|
{
|
2012-11-18 02:03:02 +04:00
|
|
|
DEBUG_DVC("ChannelId %d close response", channel->channel_id);
|
2012-10-16 01:03:34 +04:00
|
|
|
channel->dvc_open_state = DVC_OPEN_STATE_CLOSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wts_read_drdynvc_pdu(rdpPeerChannel* channel)
|
|
|
|
{
|
|
|
|
UINT32 length;
|
|
|
|
int value;
|
|
|
|
int Cmd;
|
|
|
|
int Sp;
|
|
|
|
int cbChId;
|
|
|
|
UINT32 ChannelId;
|
|
|
|
rdpPeerChannel* dvc;
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
length = Stream_GetPosition(channel->receive_data);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
if (length < 1)
|
|
|
|
return;
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(channel->receive_data, 0);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(channel->receive_data, value);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
length--;
|
|
|
|
Cmd = (value & 0xf0) >> 4;
|
|
|
|
Sp = (value & 0x0c) >> 2;
|
|
|
|
cbChId = (value & 0x03) >> 0;
|
|
|
|
|
|
|
|
if (Cmd == CAPABILITY_REQUEST_PDU)
|
|
|
|
{
|
|
|
|
wts_read_drdynvc_capabilities_response(channel, length);
|
|
|
|
}
|
|
|
|
else if (channel->vcm->drdynvc_state == DRDYNVC_STATE_READY)
|
|
|
|
{
|
|
|
|
value = wts_read_variable_uint(channel->receive_data, cbChId, &ChannelId);
|
|
|
|
|
|
|
|
if (value == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
length -= value;
|
|
|
|
|
|
|
|
DEBUG_DVC("Cmd %d ChannelId %d length %d", Cmd, ChannelId, length);
|
|
|
|
dvc = wts_get_dvc_channel_by_id(channel->vcm, ChannelId);
|
|
|
|
|
|
|
|
if (dvc)
|
|
|
|
{
|
|
|
|
switch (Cmd)
|
|
|
|
{
|
|
|
|
case CREATE_REQUEST_PDU:
|
|
|
|
wts_read_drdynvc_create_response(dvc, channel->receive_data, length);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_FIRST_PDU:
|
|
|
|
wts_read_drdynvc_data_first(dvc, channel->receive_data, Sp, length);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU:
|
|
|
|
wts_read_drdynvc_data(dvc, channel->receive_data, length);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLOSE_REQUEST_PDU:
|
|
|
|
wts_read_drdynvc_close_response(dvc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "wts_read_drdynvc_pdu: Cmd %d not recognized.\n", Cmd);
|
2012-10-16 01:03:34 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DEBUG_DVC("ChannelId %d not exists.", ChannelId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "wts_read_drdynvc_pdu: received Cmd %d but channel is not ready.\n", Cmd);
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static int wts_write_variable_uint(wStream* stream, UINT32 val)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
|
|
|
int cb;
|
|
|
|
|
|
|
|
if (val <= 0xFF)
|
|
|
|
{
|
|
|
|
cb = 0;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(stream, val);
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
else if (val <= 0xFFFF)
|
|
|
|
{
|
|
|
|
cb = 1;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(stream, val);
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cb = 3;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(stream, val);
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return cb;
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void wts_write_drdynvc_header(wStream *s, BYTE Cmd, UINT32 ChannelId)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
|
|
|
BYTE* bm;
|
|
|
|
int cbChId;
|
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_GetPointer(s, bm);
|
|
|
|
Stream_Seek_UINT8(s);
|
2012-10-16 01:03:34 +04:00
|
|
|
cbChId = wts_write_variable_uint(s, ChannelId);
|
|
|
|
*bm = ((Cmd & 0x0F) << 4) | cbChId;
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void wts_write_drdynvc_create_request(wStream *s, UINT32 ChannelId, const char *ChannelName)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
|
|
|
UINT32 len;
|
|
|
|
|
|
|
|
wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId);
|
|
|
|
len = strlen(ChannelName) + 1;
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, (int) len);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(s, ChannelName, len);
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void WTSProcessChannelData(rdpPeerChannel* channel, int channelId, BYTE* data, int size, int flags, int total_size)
|
|
|
|
{
|
|
|
|
if (flags & CHANNEL_FLAG_FIRST)
|
|
|
|
{
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(channel->receive_data, 0);
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(channel->receive_data, size);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(channel->receive_data, data, size);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
if (flags & CHANNEL_FLAG_LAST)
|
|
|
|
{
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetPosition(channel->receive_data) != total_size)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "WTSProcessChannelData: read error\n");
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
if (channel == channel->vcm->drdynvc_channel)
|
|
|
|
{
|
|
|
|
wts_read_drdynvc_pdu(channel);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-09 00:27:21 +04:00
|
|
|
wts_queue_receive_data(channel, Stream_Buffer(channel->receive_data), Stream_GetPosition(channel->receive_data));
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(channel->receive_data, 0);
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int WTSReceiveChannelData(freerdp_peer* client, int channelId, BYTE* data, int size, int flags, int total_size)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BOOL result = FALSE;
|
|
|
|
rdpPeerChannel* channel;
|
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
for (i = 0; i < client->settings->ChannelCount; i++)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
2012-11-08 08:29:24 +04:00
|
|
|
if (client->settings->ChannelDefArray[i].ChannelId == channelId)
|
2012-10-16 01:03:34 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-03-08 00:33:27 +04:00
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
if (i < client->settings->ChannelCount)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
2012-11-08 08:29:24 +04:00
|
|
|
channel = (rdpPeerChannel*) client->settings->ChannelDefArray[i].handle;
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
if (channel != NULL)
|
|
|
|
{
|
|
|
|
WTSProcessChannelData(channel, channelId, data, size, flags, total_size);
|
|
|
|
result = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
WTSVirtualChannelManager* WTSCreateVirtualChannelManager(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
WTSVirtualChannelManager* vcm;
|
|
|
|
|
2012-11-22 05:21:08 +04:00
|
|
|
vcm = (WTSVirtualChannelManager*) malloc(sizeof(WTSVirtualChannelManager));
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
if (vcm != NULL)
|
|
|
|
{
|
2012-11-22 05:21:08 +04:00
|
|
|
ZeroMemory(vcm, sizeof(WTSVirtualChannelManager));
|
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
vcm->client = client;
|
2012-11-27 05:15:48 +04:00
|
|
|
vcm->send_event = CreateEvent(NULL, TRUE, FALSE, NULL);
|
2012-10-16 01:03:34 +04:00
|
|
|
vcm->send_queue = list_new();
|
|
|
|
vcm->mutex = CreateMutex(NULL, FALSE, NULL);
|
|
|
|
vcm->dvc_channel_id_seq = 1;
|
|
|
|
vcm->dvc_channel_list = list_new();
|
|
|
|
|
|
|
|
client->ReceiveChannelData = WTSReceiveChannelData;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vcm;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WTSDestroyVirtualChannelManager(WTSVirtualChannelManager* vcm)
|
|
|
|
{
|
|
|
|
wts_data_item* item;
|
|
|
|
rdpPeerChannel* channel;
|
|
|
|
|
|
|
|
if (vcm != NULL)
|
|
|
|
{
|
|
|
|
while ((channel = (rdpPeerChannel*) list_dequeue(vcm->dvc_channel_list)) != NULL)
|
|
|
|
{
|
|
|
|
WTSVirtualChannelClose(channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
list_free(vcm->dvc_channel_list);
|
|
|
|
|
|
|
|
if (vcm->drdynvc_channel != NULL)
|
|
|
|
{
|
|
|
|
WTSVirtualChannelClose(vcm->drdynvc_channel);
|
|
|
|
vcm->drdynvc_channel = NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-27 05:15:48 +04:00
|
|
|
CloseHandle(vcm->send_event);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
while ((item = (wts_data_item*) list_dequeue(vcm->send_queue)) != NULL)
|
|
|
|
{
|
|
|
|
wts_data_item_free(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
list_free(vcm->send_queue);
|
|
|
|
CloseHandle(vcm->mutex);
|
|
|
|
free(vcm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WTSVirtualChannelManagerGetFileDescriptor(WTSVirtualChannelManager* vcm,
|
|
|
|
void** fds, int* fds_count)
|
|
|
|
{
|
2012-12-19 21:16:39 +04:00
|
|
|
void* fd;
|
2012-11-27 05:15:48 +04:00
|
|
|
|
2012-12-19 21:16:39 +04:00
|
|
|
fd = GetEventWaitObject(vcm->send_event);
|
2012-11-27 05:15:48 +04:00
|
|
|
|
2012-12-19 21:16:39 +04:00
|
|
|
if (fd)
|
2012-11-27 05:15:48 +04:00
|
|
|
{
|
2012-12-19 21:16:39 +04:00
|
|
|
fds[*fds_count] = fd;
|
2012-11-27 05:15:48 +04:00
|
|
|
(*fds_count)++;
|
|
|
|
}
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
if (vcm->drdynvc_channel)
|
|
|
|
{
|
2012-12-19 21:16:39 +04:00
|
|
|
fd = GetEventWaitObject(vcm->drdynvc_channel->receive_event);
|
2012-11-27 05:15:48 +04:00
|
|
|
|
2012-12-19 21:16:39 +04:00
|
|
|
if (fd)
|
2012-11-27 05:15:48 +04:00
|
|
|
{
|
2012-12-19 21:16:39 +04:00
|
|
|
fds[*fds_count] = fd;
|
2012-11-27 05:15:48 +04:00
|
|
|
(*fds_count)++;
|
|
|
|
}
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSVirtualChannelManagerCheckFileDescriptor(WTSVirtualChannelManager* vcm)
|
|
|
|
{
|
|
|
|
BOOL result = TRUE;
|
|
|
|
wts_data_item* item;
|
|
|
|
rdpPeerChannel* channel;
|
|
|
|
UINT32 dynvc_caps;
|
|
|
|
|
|
|
|
if (vcm->drdynvc_state == DRDYNVC_STATE_NONE && vcm->client->activated)
|
|
|
|
{
|
|
|
|
/* Initialize drdynvc channel once and only once. */
|
|
|
|
vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED;
|
|
|
|
|
|
|
|
channel = WTSVirtualChannelOpenEx(vcm, "drdynvc", 0);
|
|
|
|
|
|
|
|
if (channel)
|
|
|
|
{
|
|
|
|
vcm->drdynvc_channel = channel;
|
|
|
|
dynvc_caps = 0x00010050; /* DYNVC_CAPS_VERSION1 (4 bytes) */
|
|
|
|
WTSVirtualChannelWrite(channel, (BYTE*) &dynvc_caps, sizeof(dynvc_caps), NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-27 05:15:48 +04:00
|
|
|
ResetEvent(vcm->send_event);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
WaitForSingleObject(vcm->mutex, INFINITE);
|
|
|
|
|
|
|
|
while ((item = (wts_data_item*) list_dequeue(vcm->send_queue)) != NULL)
|
|
|
|
{
|
|
|
|
if (vcm->client->SendChannelData(vcm->client, item->channel_id, item->buffer, item->length) == FALSE)
|
|
|
|
{
|
|
|
|
result = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
wts_data_item_free(item);
|
|
|
|
|
|
|
|
if (result == FALSE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseMutex(vcm->mutex);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* WTSVirtualChannelOpenEx(
|
|
|
|
/* __in */ WTSVirtualChannelManager* vcm,
|
|
|
|
/* __in */ const char* pVirtualName,
|
|
|
|
/* __in */ UINT32 flags)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int len;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-10-16 01:03:34 +04:00
|
|
|
rdpPeerChannel* channel;
|
|
|
|
freerdp_peer* client = vcm->client;
|
|
|
|
|
|
|
|
if ((flags & WTS_CHANNEL_OPTION_DYNAMIC) != 0)
|
|
|
|
{
|
2013-05-20 03:46:02 +04:00
|
|
|
for (i = 0; i < client->settings->ChannelCount; i++)
|
|
|
|
{
|
|
|
|
if (client->settings->ChannelDefArray[i].joined &&
|
|
|
|
strncmp(client->settings->ChannelDefArray[i].Name, "drdynvc", 7) == 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i >= client->settings->ChannelCount)
|
|
|
|
{
|
|
|
|
DEBUG_DVC("Dynamic virtual channel not registered.");
|
|
|
|
SetLastError(ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
if (vcm->drdynvc_channel == NULL || vcm->drdynvc_state != DRDYNVC_STATE_READY)
|
|
|
|
{
|
|
|
|
DEBUG_DVC("Dynamic virtual channel not ready.");
|
2013-05-20 03:46:02 +04:00
|
|
|
SetLastError(ERROR_NOT_READY);
|
2012-10-16 01:03:34 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-22 05:21:08 +04:00
|
|
|
channel = (rdpPeerChannel*) malloc(sizeof(rdpPeerChannel));
|
|
|
|
ZeroMemory(channel, sizeof(rdpPeerChannel));
|
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
channel->vcm = vcm;
|
|
|
|
channel->client = client;
|
|
|
|
channel->channel_type = RDP_PEER_CHANNEL_TYPE_DVC;
|
2013-05-09 01:48:30 +04:00
|
|
|
channel->receive_data = Stream_New(NULL, client->settings->VirtualChannelChunkSize);
|
2012-11-27 05:15:48 +04:00
|
|
|
channel->receive_event = CreateEvent(NULL, TRUE, FALSE, NULL);
|
2012-10-16 01:03:34 +04:00
|
|
|
channel->receive_queue = list_new();
|
|
|
|
channel->mutex = CreateMutex(NULL, FALSE, NULL);
|
|
|
|
|
|
|
|
WaitForSingleObject(vcm->mutex, INFINITE);
|
|
|
|
channel->channel_id = vcm->dvc_channel_id_seq++;
|
|
|
|
list_enqueue(vcm->dvc_channel_list, channel);
|
|
|
|
ReleaseMutex(vcm->mutex);
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
s = Stream_New(NULL, 64);
|
2012-10-16 01:03:34 +04:00
|
|
|
wts_write_drdynvc_create_request(s, channel->channel_id, pVirtualName);
|
2013-05-09 00:27:21 +04:00
|
|
|
WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_Buffer(s), Stream_GetPosition(s), NULL);
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, TRUE);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
2012-11-18 02:03:02 +04:00
|
|
|
DEBUG_DVC("ChannelId %d.%s (total %d)", channel->channel_id, pVirtualName, list_size(vcm->dvc_channel_list));
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = strlen(pVirtualName);
|
|
|
|
|
|
|
|
if (len > 8)
|
2013-05-20 03:46:02 +04:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_FOUND);
|
2012-10-16 01:03:34 +04:00
|
|
|
return NULL;
|
2013-05-20 03:46:02 +04:00
|
|
|
}
|
2012-10-16 01:03:34 +04:00
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
for (i = 0; i < client->settings->ChannelCount; i++)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
2012-11-08 08:29:24 +04:00
|
|
|
if (client->settings->ChannelDefArray[i].joined &&
|
|
|
|
strncmp(client->settings->ChannelDefArray[i].Name, pVirtualName, len) == 0)
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
if (i >= client->settings->ChannelCount)
|
2013-05-20 03:46:02 +04:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_FOUND);
|
2012-10-16 01:03:34 +04:00
|
|
|
return NULL;
|
2013-05-20 03:46:02 +04:00
|
|
|
}
|
2012-10-16 01:03:34 +04:00
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
channel = (rdpPeerChannel*) client->settings->ChannelDefArray[i].handle;
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
if (channel == NULL)
|
|
|
|
{
|
2012-11-22 05:21:08 +04:00
|
|
|
channel = (rdpPeerChannel*) malloc(sizeof(rdpPeerChannel));
|
|
|
|
ZeroMemory(channel, sizeof(rdpPeerChannel));
|
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
channel->vcm = vcm;
|
|
|
|
channel->client = client;
|
2012-11-08 08:29:24 +04:00
|
|
|
channel->channel_id = client->settings->ChannelDefArray[i].ChannelId;
|
2012-10-16 01:03:34 +04:00
|
|
|
channel->index = i;
|
|
|
|
channel->channel_type = RDP_PEER_CHANNEL_TYPE_SVC;
|
2013-05-09 01:48:30 +04:00
|
|
|
channel->receive_data = Stream_New(NULL, client->settings->VirtualChannelChunkSize);
|
2012-11-27 05:15:48 +04:00
|
|
|
channel->receive_event = CreateEvent(NULL, TRUE, FALSE, NULL);
|
2012-10-16 01:03:34 +04:00
|
|
|
channel->receive_queue = list_new();
|
|
|
|
channel->mutex = CreateMutex(NULL, FALSE, NULL);
|
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
client->settings->ChannelDefArray[i].handle = channel;
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSVirtualChannelQuery(
|
|
|
|
/* __in */ void* hChannelHandle,
|
|
|
|
/* __in */ WTS_VIRTUAL_CLASS WtsVirtualClass,
|
|
|
|
/* __out */ void** ppBuffer,
|
|
|
|
/* __out */ UINT32* pBytesReturned)
|
|
|
|
{
|
2012-12-19 21:16:39 +04:00
|
|
|
void* pfd;
|
2012-10-16 01:03:34 +04:00
|
|
|
BOOL bval;
|
|
|
|
void* fds[10];
|
|
|
|
int fds_count = 0;
|
|
|
|
BOOL result = FALSE;
|
|
|
|
rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle;
|
2013-03-15 21:22:49 +04:00
|
|
|
ZeroMemory(fds, sizeof(fds));
|
2012-10-16 01:03:34 +04:00
|
|
|
switch (WtsVirtualClass)
|
|
|
|
{
|
|
|
|
case WTSVirtualFileHandle:
|
2012-11-27 05:15:48 +04:00
|
|
|
|
2012-12-19 21:16:39 +04:00
|
|
|
pfd = GetEventWaitObject(channel->receive_event);
|
2012-11-27 05:15:48 +04:00
|
|
|
|
2012-12-19 21:16:39 +04:00
|
|
|
if (pfd)
|
2012-11-27 05:15:48 +04:00
|
|
|
{
|
2012-12-19 21:16:39 +04:00
|
|
|
fds[fds_count] = pfd;
|
2012-11-27 05:15:48 +04:00
|
|
|
(fds_count)++;
|
|
|
|
}
|
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
*ppBuffer = malloc(sizeof(void*));
|
2013-03-08 00:33:27 +04:00
|
|
|
CopyMemory(*ppBuffer, &fds[0], sizeof(void*));
|
2012-10-16 01:03:34 +04:00
|
|
|
*pBytesReturned = sizeof(void*);
|
|
|
|
result = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTSVirtualChannelReady:
|
|
|
|
if (channel->channel_type == RDP_PEER_CHANNEL_TYPE_SVC)
|
|
|
|
{
|
|
|
|
bval = TRUE;
|
|
|
|
result = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (channel->dvc_open_state)
|
|
|
|
{
|
|
|
|
case DVC_OPEN_STATE_NONE:
|
|
|
|
bval = FALSE;
|
|
|
|
result = TRUE;
|
|
|
|
break;
|
2013-03-08 00:33:27 +04:00
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
case DVC_OPEN_STATE_SUCCEEDED:
|
|
|
|
bval = TRUE;
|
|
|
|
result = TRUE;
|
|
|
|
break;
|
2013-03-08 00:33:27 +04:00
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
default:
|
|
|
|
bval = FALSE;
|
|
|
|
result = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-03-08 00:33:27 +04:00
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
*ppBuffer = malloc(sizeof(BOOL));
|
2013-03-08 00:33:27 +04:00
|
|
|
CopyMemory(*ppBuffer, &bval, sizeof(BOOL));
|
2012-10-16 01:03:34 +04:00
|
|
|
*pBytesReturned = sizeof(BOOL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WTSFreeMemory(
|
|
|
|
/* __in */ void* pMemory)
|
|
|
|
{
|
|
|
|
free(pMemory);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSVirtualChannelRead(
|
|
|
|
/* __in */ void* hChannelHandle,
|
|
|
|
/* __in */ UINT32 TimeOut,
|
|
|
|
/* __out */ BYTE* Buffer,
|
|
|
|
/* __in */ UINT32 BufferSize,
|
|
|
|
/* __out */ UINT32* pBytesRead)
|
|
|
|
{
|
|
|
|
wts_data_item* item;
|
|
|
|
rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle;
|
|
|
|
|
|
|
|
item = (wts_data_item*) list_peek(channel->receive_queue);
|
|
|
|
|
|
|
|
if (item == NULL)
|
|
|
|
{
|
2012-11-27 05:15:48 +04:00
|
|
|
ResetEvent(channel->receive_event);
|
2012-10-16 01:03:34 +04:00
|
|
|
*pBytesRead = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pBytesRead = item->length;
|
|
|
|
|
|
|
|
if (item->length > BufferSize)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* remove the first element (same as what we just peek) */
|
|
|
|
WaitForSingleObject(channel->mutex, INFINITE);
|
|
|
|
list_dequeue(channel->receive_queue);
|
|
|
|
|
|
|
|
if (list_size(channel->receive_queue) == 0)
|
2012-11-27 05:15:48 +04:00
|
|
|
ResetEvent(channel->receive_event);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
ReleaseMutex(channel->mutex);
|
|
|
|
|
2013-03-08 00:33:27 +04:00
|
|
|
CopyMemory(Buffer, item->buffer, item->length);
|
2012-10-16 01:03:34 +04:00
|
|
|
wts_data_item_free(item) ;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSVirtualChannelWrite(
|
|
|
|
/* __in */ void* hChannelHandle,
|
|
|
|
/* __in */ BYTE* Buffer,
|
|
|
|
/* __in */ UINT32 Length,
|
|
|
|
/* __out */ UINT32* pBytesWritten)
|
|
|
|
{
|
|
|
|
rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle;
|
|
|
|
wts_data_item* item;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-10-16 01:03:34 +04:00
|
|
|
int cbLen;
|
|
|
|
int cbChId;
|
|
|
|
int first;
|
|
|
|
UINT32 written;
|
|
|
|
|
|
|
|
if (channel == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (channel->channel_type == RDP_PEER_CHANNEL_TYPE_SVC)
|
|
|
|
{
|
2012-11-22 05:21:08 +04:00
|
|
|
item = (wts_data_item*) malloc(sizeof(wts_data_item));
|
|
|
|
ZeroMemory(item, sizeof(wts_data_item));
|
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
item->buffer = malloc(Length);
|
|
|
|
item->length = Length;
|
2013-03-08 00:33:27 +04:00
|
|
|
CopyMemory(item->buffer, Buffer, Length);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
wts_queue_send_item(channel, item);
|
|
|
|
}
|
|
|
|
else if (channel->vcm->drdynvc_channel == NULL || channel->vcm->drdynvc_state != DRDYNVC_STATE_READY)
|
|
|
|
{
|
|
|
|
DEBUG_DVC("drdynvc not ready");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
first = TRUE;
|
|
|
|
|
|
|
|
while (Length > 0)
|
|
|
|
{
|
2012-11-22 05:21:08 +04:00
|
|
|
item = (wts_data_item*) malloc(sizeof(wts_data_item));
|
|
|
|
ZeroMemory(item, sizeof(wts_data_item));
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
s = Stream_New(NULL, channel->client->settings->VirtualChannelChunkSize);
|
|
|
|
item->buffer = Stream_Buffer(s);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Seek_UINT8(s);
|
2012-10-16 01:03:34 +04:00
|
|
|
cbChId = wts_write_variable_uint(s, channel->channel_id);
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (first && (Length > (UINT32) Stream_GetRemainingLength(s)))
|
2012-10-16 01:03:34 +04:00
|
|
|
{
|
|
|
|
cbLen = wts_write_variable_uint(s, Length);
|
|
|
|
item->buffer[0] = (DATA_FIRST_PDU << 4) | (cbLen << 2) | cbChId;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item->buffer[0] = (DATA_PDU << 4) | cbChId;
|
|
|
|
}
|
|
|
|
|
|
|
|
first = FALSE;
|
2013-04-30 06:35:15 +04:00
|
|
|
written = Stream_GetRemainingLength(s);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
if (written > Length)
|
|
|
|
written = Length;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(s, Buffer, written);
|
2013-04-30 06:35:15 +04:00
|
|
|
item->length = Stream_GetPosition(s);
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, FALSE);
|
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
Length -= written;
|
|
|
|
Buffer += written;
|
|
|
|
|
|
|
|
wts_queue_send_item(channel->vcm->drdynvc_channel, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pBytesWritten != NULL)
|
|
|
|
*pBytesWritten = Length;
|
2013-05-09 01:48:30 +04:00
|
|
|
|
2012-10-16 01:03:34 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSVirtualChannelClose(
|
|
|
|
/* __in */ void* hChannelHandle)
|
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-10-16 01:03:34 +04:00
|
|
|
wts_data_item* item;
|
|
|
|
WTSVirtualChannelManager* vcm;
|
|
|
|
rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle;
|
|
|
|
|
|
|
|
if (channel)
|
|
|
|
{
|
|
|
|
vcm = channel->vcm;
|
|
|
|
|
|
|
|
if (channel->channel_type == RDP_PEER_CHANNEL_TYPE_SVC)
|
|
|
|
{
|
2012-11-08 08:29:24 +04:00
|
|
|
if (channel->index < channel->client->settings->ChannelCount)
|
|
|
|
channel->client->settings->ChannelDefArray[channel->index].handle = NULL;
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WaitForSingleObject(vcm->mutex, INFINITE);
|
|
|
|
list_remove(vcm->dvc_channel_list, channel);
|
|
|
|
ReleaseMutex(vcm->mutex);
|
|
|
|
|
|
|
|
if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
|
|
|
|
{
|
2013-05-09 01:48:30 +04:00
|
|
|
s = Stream_New(NULL, 8);
|
2012-10-16 01:03:34 +04:00
|
|
|
wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channel_id);
|
2013-05-09 00:27:21 +04:00
|
|
|
WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_Buffer(s), Stream_GetPosition(s), NULL);
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, TRUE);
|
2012-10-16 01:03:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channel->receive_data)
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(channel->receive_data, TRUE);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
if (channel->receive_event)
|
2012-11-27 05:15:48 +04:00
|
|
|
CloseHandle(channel->receive_event);
|
2012-10-16 01:03:34 +04:00
|
|
|
|
|
|
|
if (channel->receive_queue)
|
|
|
|
{
|
|
|
|
while ((item = (wts_data_item*) list_dequeue(channel->receive_queue)) != NULL)
|
|
|
|
{
|
|
|
|
wts_data_item_free(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
list_free(channel->receive_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channel->mutex)
|
|
|
|
CloseHandle(channel->mutex);
|
|
|
|
|
|
|
|
free(channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|