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