a180a41bba1d50822df23fff0099e90b86638b89vboxsync/* -*- c-basic-offset: 8 -*-
a180a41bba1d50822df23fff0099e90b86638b89vboxsync rdesktop: A Remote Desktop Protocol client.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync Protocol services - Virtual channels
a180a41bba1d50822df23fff0099e90b86638b89vboxsync Copyright 2003 Erik Forsberg <forsberg@cendio.se> for Cendio AB
a180a41bba1d50822df23fff0099e90b86638b89vboxsync Copyright (C) Matthew Chapman <matthewc.unsw.edu.au> 2003-2008
a180a41bba1d50822df23fff0099e90b86638b89vboxsync This program is free software: you can redistribute it and/or modify
a180a41bba1d50822df23fff0099e90b86638b89vboxsync it under the terms of the GNU General Public License as published by
a180a41bba1d50822df23fff0099e90b86638b89vboxsync the Free Software Foundation, either version 3 of the License, or
a180a41bba1d50822df23fff0099e90b86638b89vboxsync (at your option) any later version.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync This program is distributed in the hope that it will be useful,
a180a41bba1d50822df23fff0099e90b86638b89vboxsync but WITHOUT ANY WARRANTY; without even the implied warranty of
a180a41bba1d50822df23fff0099e90b86638b89vboxsync MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a180a41bba1d50822df23fff0099e90b86638b89vboxsync GNU General Public License for more details.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync You should have received a copy of the GNU General Public License
a180a41bba1d50822df23fff0099e90b86638b89vboxsync along with this program. If not, see <http://www.gnu.org/licenses/>.
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync * Oracle GPL Disclaimer: For the avoidance of doubt, except that if any license choice
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync * the General Public License version 2 (GPLv2) at this time for any software where
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync * a choice of GPL license versions is made available with the language indicating
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync * that GPLv2 or any later version may be used, or where a choice of which version
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync * of the GPL is applied is otherwise unspecified.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync/* FIXME: We should use the information in TAG_SRV_CHANNELS to map RDP5
a180a41bba1d50822df23fff0099e90b86638b89vboxsync channels to MCS channels.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync The format of TAG_SRV_CHANNELS seems to be
a180a41bba1d50822df23fff0099e90b86638b89vboxsync global_channel_no (uint16le)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync number_of_other_channels (uint16le)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync ..followed by uint16les for the other channels.
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncchannel_register(char *name, uint32 flags, void (*callback) (STREAM))
a180a41bba1d50822df23fff0099e90b86638b89vboxsync error("Channel table full, increase MAX_CHANNELS\n");
a180a41bba1d50822df23fff0099e90b86638b89vboxsync channel->mcs_id = MCS_GLOBAL_CHANNEL + 1 + g_num_channels;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync s = sec_init(g_encryption ? SEC_ENCRYPT : 0, length + 8);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* first fragment sent in-place */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync DEBUG_CHANNEL(("channel_send, length = %d\n", length));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync/* Note: In the original clipboard implementation, this number was
a180a41bba1d50822df23fff0099e90b86638b89vboxsync 1592, not 1600. However, I don't remember the reason and 1600 seems
a180a41bba1d50822df23fff0099e90b86638b89vboxsync to work so.. This applies only to *this* length, not the length of
a180a41bba1d50822df23fff0099e90b86638b89vboxsync continuation or ending packets. */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync flags = (remaining == 0) ? CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST : CHANNEL_FLAG_FIRST;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync DEBUG_CHANNEL(("Sending %d bytes with FLAG_FIRST\n", thislength));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync sec_send_to_channel(s, g_encryption ? SEC_ENCRYPT : 0, channel->mcs_id);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* subsequent segments copied (otherwise would have to generate headers backwards) */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync DEBUG_CHANNEL(("Sending %d bytes with flags %d\n", thislength, flags));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync s = sec_init(g_encryption ? SEC_ENCRYPT : 0, thislength + 8);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync sec_send_to_channel(s, g_encryption ? SEC_ENCRYPT : 0, channel->mcs_id);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync unsigned int i;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync for (i = 0; i < g_num_channels; i++)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if ((flags & CHANNEL_FLAG_FIRST) && (flags & CHANNEL_FLAG_LAST))
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* single fragment - pass straight up */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* add fragment to defragmentation buffer */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync thislength = MIN(s->end - s->p, in->data + in->size - in->p);