2011-08-02 22:03:02 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-02 22:03:02 +04:00
|
|
|
* Virtual Channels
|
|
|
|
*
|
|
|
|
* Copyright 2011 Vic Lee
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2011-08-02 22:03:02 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2011-08-02 22:03:02 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
2011-12-10 12:41:29 +04:00
|
|
|
#include <freerdp/peer.h>
|
2011-08-03 09:58:19 +04:00
|
|
|
#include <freerdp/constants.h>
|
2013-03-22 00:45:25 +04:00
|
|
|
#include <winpr/stream.h>
|
2011-08-02 22:03:02 +04:00
|
|
|
|
2011-08-03 09:58:19 +04:00
|
|
|
#include "rdp.h"
|
2011-10-16 08:50:10 +04:00
|
|
|
#include "channel.h"
|
2011-08-02 22:03:02 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channel_id, BYTE* data, int size)
|
2011-08-03 07:00:56 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 flags;
|
2011-10-16 08:50:10 +04:00
|
|
|
int i, left;
|
2011-08-03 09:58:19 +04:00
|
|
|
int chunk_size;
|
2011-10-16 22:57:15 +04:00
|
|
|
rdpChannel* channel = NULL;
|
2011-08-03 09:58:19 +04:00
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
for (i = 0; i < rdp->settings->ChannelCount; i++)
|
2011-08-03 09:58:19 +04:00
|
|
|
{
|
2012-11-08 08:29:24 +04:00
|
|
|
if (rdp->settings->ChannelDefArray[i].ChannelId == channel_id)
|
2011-08-03 09:58:19 +04:00
|
|
|
{
|
2012-11-08 08:29:24 +04:00
|
|
|
channel = &rdp->settings->ChannelDefArray[i];
|
2011-08-03 09:58:19 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-10-16 08:50:10 +04:00
|
|
|
|
2013-02-21 06:34:47 +04:00
|
|
|
if (!channel)
|
2011-08-03 09:58:19 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "freerdp_channel_send: unknown channel_id %d\n", channel_id);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-03 09:58:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
flags = CHANNEL_FLAG_FIRST;
|
2011-09-22 18:56:26 +04:00
|
|
|
left = size;
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2011-09-22 18:56:26 +04:00
|
|
|
while (left > 0)
|
2011-08-03 09:58:19 +04:00
|
|
|
{
|
2011-12-10 11:51:42 +04:00
|
|
|
s = rdp_send_stream_init(rdp);
|
2011-08-03 09:58:19 +04:00
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
if (left > (int) rdp->settings->VirtualChannelChunkSize)
|
2011-08-03 09:58:19 +04:00
|
|
|
{
|
2012-11-08 00:13:14 +04:00
|
|
|
chunk_size = rdp->settings->VirtualChannelChunkSize;
|
2011-08-03 09:58:19 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-22 18:56:26 +04:00
|
|
|
chunk_size = left;
|
2011-08-03 09:58:19 +04:00
|
|
|
flags |= CHANNEL_FLAG_LAST;
|
|
|
|
}
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2011-08-03 09:58:19 +04:00
|
|
|
if ((channel->options & CHANNEL_OPTION_SHOW_PROTOCOL))
|
|
|
|
{
|
|
|
|
flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(s, size);
|
|
|
|
Stream_Write_UINT32(s, flags);
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureCapacity(s, chunk_size);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(s, data, chunk_size);
|
2011-08-03 09:58:19 +04:00
|
|
|
|
2011-12-10 11:51:42 +04:00
|
|
|
rdp_send(rdp, s, channel_id);
|
2011-08-03 09:58:19 +04:00
|
|
|
|
|
|
|
data += chunk_size;
|
2011-09-22 18:56:26 +04:00
|
|
|
left -= chunk_size;
|
2011-08-03 09:58:19 +04:00
|
|
|
flags = 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-03 07:00:56 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL freerdp_channel_process(freerdp* instance, wStream* s, UINT16 channel_id)
|
2011-08-02 22:03:02 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 length;
|
|
|
|
UINT32 flags;
|
2011-08-03 07:00:56 +04:00
|
|
|
int chunk_length;
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2013-01-11 04:25:26 +04:00
|
|
|
return FALSE;
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, length);
|
|
|
|
Stream_Read_UINT32(s, flags);
|
2013-04-30 06:35:15 +04:00
|
|
|
chunk_length = Stream_GetRemainingLength(s);
|
2011-08-03 07:00:56 +04:00
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
IFCALL(instance->ReceiveChannelData, instance,
|
2013-04-30 06:35:15 +04:00
|
|
|
channel_id, Stream_Pointer(s), chunk_length, flags, length);
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2013-01-11 04:25:26 +04:00
|
|
|
return TRUE;
|
2011-08-02 22:03:02 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL freerdp_channel_peer_process(freerdp_peer* client, wStream* s, UINT16 channel_id)
|
2011-12-10 12:41:29 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 length;
|
|
|
|
UINT32 flags;
|
2011-12-10 12:41:29 +04:00
|
|
|
int chunk_length;
|
|
|
|
|
2013-05-15 23:54:33 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2013-01-11 04:25:26 +04:00
|
|
|
return FALSE;
|
2013-05-15 23:54:33 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, length);
|
|
|
|
Stream_Read_UINT32(s, flags);
|
2013-04-30 06:35:15 +04:00
|
|
|
chunk_length = Stream_GetRemainingLength(s);
|
2011-12-10 12:41:29 +04:00
|
|
|
|
|
|
|
IFCALL(client->ReceiveChannelData, client,
|
2013-04-30 06:35:15 +04:00
|
|
|
channel_id, Stream_Pointer(s), chunk_length, flags, length);
|
2013-05-15 23:54:33 +04:00
|
|
|
|
2013-01-11 04:25:26 +04:00
|
|
|
return TRUE;
|
2011-12-10 12:41:29 +04:00
|
|
|
}
|