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>
|
2011-08-02 22:03:02 +04:00
|
|
|
#include <freerdp/utils/memory.h>
|
|
|
|
#include <freerdp/utils/stream.h>
|
|
|
|
|
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
|
|
|
|
2011-12-10 11:51:42 +04:00
|
|
|
boolean freerdp_channel_send(rdpRdp* rdp, uint16 channel_id, uint8* data, int size)
|
2011-08-03 07:00:56 +04:00
|
|
|
{
|
2011-08-03 09:58:19 +04:00
|
|
|
STREAM* s;
|
|
|
|
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
|
|
|
|
2011-12-10 11:51:42 +04:00
|
|
|
for (i = 0; i < rdp->settings->num_channels; i++)
|
2011-08-03 09:58:19 +04:00
|
|
|
{
|
2011-12-10 11:51:42 +04:00
|
|
|
if (rdp->settings->channels[i].channel_id == channel_id)
|
2011-08-03 09:58:19 +04:00
|
|
|
{
|
2011-12-10 11:51:42 +04:00
|
|
|
channel = &rdp->settings->channels[i];
|
2011-08-03 09:58:19 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-10-16 08:50:10 +04:00
|
|
|
|
2011-08-03 09:58:19 +04:00
|
|
|
if (channel == NULL)
|
|
|
|
{
|
2011-10-16 08:50:10 +04:00
|
|
|
printf("freerdp_channel_send: unknown channel_id %d\n", channel_id);
|
2011-11-19 21:19:16 +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;
|
|
|
|
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
|
|
|
|
2011-12-10 11:51:42 +04:00
|
|
|
if (left > (int) rdp->settings->vc_chunk_size)
|
2011-08-03 09:58:19 +04:00
|
|
|
{
|
2011-12-10 11:51:42 +04:00
|
|
|
chunk_size = rdp->settings->vc_chunk_size;
|
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;
|
|
|
|
}
|
|
|
|
if ((channel->options & CHANNEL_OPTION_SHOW_PROTOCOL))
|
|
|
|
{
|
|
|
|
flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
|
|
|
|
}
|
|
|
|
|
2011-09-22 18:56:26 +04:00
|
|
|
stream_write_uint32(s, size);
|
2011-08-03 09:58:19 +04:00
|
|
|
stream_write_uint32(s, flags);
|
|
|
|
stream_check_size(s, chunk_size);
|
|
|
|
stream_write(s, data, chunk_size);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-03 07:00:56 +04:00
|
|
|
}
|
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
void freerdp_channel_process(freerdp* instance, STREAM* s, uint16 channel_id)
|
2011-08-02 22:03:02 +04:00
|
|
|
{
|
2011-08-03 07:00:56 +04:00
|
|
|
uint32 length;
|
|
|
|
uint32 flags;
|
|
|
|
int chunk_length;
|
|
|
|
|
|
|
|
stream_read_uint32(s, length);
|
|
|
|
stream_read_uint32(s, flags);
|
|
|
|
chunk_length = stream_get_left(s);
|
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
IFCALL(instance->ReceiveChannelData, instance,
|
2011-08-03 07:00:56 +04:00
|
|
|
channel_id, stream_get_tail(s), chunk_length, flags, length);
|
2011-08-02 22:03:02 +04:00
|
|
|
}
|
|
|
|
|
2011-12-10 12:41:29 +04:00
|
|
|
void freerdp_channel_peer_process(freerdp_peer* client, STREAM* s, uint16 channel_id)
|
|
|
|
{
|
|
|
|
uint32 length;
|
|
|
|
uint32 flags;
|
|
|
|
int chunk_length;
|
|
|
|
|
|
|
|
stream_read_uint32(s, length);
|
|
|
|
stream_read_uint32(s, flags);
|
|
|
|
chunk_length = stream_get_left(s);
|
|
|
|
|
|
|
|
IFCALL(client->ReceiveChannelData, client,
|
|
|
|
channel_id, stream_get_tail(s), chunk_length, flags, length);
|
|
|
|
}
|