--- sourceforge.net/trunk/rdesktop/channels.c 2003/07/28 21:41:12 437 +++ sourceforge.net/trunk/rdesktop/channels.c 2005/03/06 21:11:18 828 @@ -2,7 +2,7 @@ rdesktop: A Remote Desktop Protocol client. Protocol services - Virtual channels Copyright (C) Erik Forsberg 2003 - Copyright (C) Matthew Chapman 2003 + Copyright (C) Matthew Chapman 2003-2005 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,14 +27,14 @@ #define CHANNEL_FLAG_LAST 0x02 #define CHANNEL_FLAG_SHOW_PROTOCOL 0x10 -extern BOOL use_rdp5; +extern BOOL g_use_rdp5; extern BOOL g_encryption; VCHANNEL g_channels[MAX_CHANNELS]; unsigned int g_num_channels; /* FIXME: We should use the information in TAG_SRV_CHANNELS to map RDP5 - channels to MCS channels. + channels to MCS channels. The format of TAG_SRV_CHANNELS seems to be @@ -48,7 +48,7 @@ { VCHANNEL *channel; - if (!use_rdp5) + if (!g_use_rdp5) return NULL; if (g_num_channels >= MAX_CHANNELS) @@ -81,13 +81,19 @@ { uint32 length, flags; uint32 thislength, remaining; - char *data; + uint8 *data; /* first fragment sent in-place */ s_pop_layer(s, channel_hdr); length = s->end - s->p - 8; + DEBUG_CLIPBOARD(("channel_send, length = %d\n", length)); + thislength = MIN(length, CHANNEL_CHUNK_LENGTH); +/* Note: In the original clipboard implementation, this number was + 1592, not 1600. However, I don't remember the reason and 1600 seems + to work so.. This applies only to *this* length, not the length of + continuation or ending packets. */ remaining = length - thislength; flags = (remaining == 0) ? CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST : CHANNEL_FLAG_FIRST; if (channel->flags & CHANNEL_OPTION_SHOW_PROTOCOL) @@ -96,6 +102,7 @@ out_uint32_le(s, length); out_uint32_le(s, flags); data = s->end = s->p + thislength; + DEBUG_CLIPBOARD(("Sending %d bytes with FLAG_FIRST\n", thislength)); sec_send_to_channel(s, g_encryption ? SEC_ENCRYPT : 0, channel->mcs_id); /* subsequent segments copied (otherwise would have to generate headers backwards) */ @@ -104,6 +111,10 @@ thislength = MIN(remaining, CHANNEL_CHUNK_LENGTH); remaining -= thislength; flags = (remaining == 0) ? CHANNEL_FLAG_LAST : 0; + if (channel->flags & CHANNEL_OPTION_SHOW_PROTOCOL) + flags |= CHANNEL_FLAG_SHOW_PROTOCOL; + + DEBUG_CLIPBOARD(("Sending %d bytes with flags %d\n", thislength, flags)); s = sec_init(g_encryption ? SEC_ENCRYPT : 0, thislength + 8); out_uint32_le(s, length); @@ -121,7 +132,7 @@ { uint32 length, flags; uint32 thislength; - VCHANNEL *channel; + VCHANNEL *channel = NULL; unsigned int i; STREAM in; @@ -150,19 +161,19 @@ { if (length > in->size) { - in->data = xrealloc(in->data, length); + in->data = (uint8 *) xrealloc(in->data, length); in->size = length; } in->p = in->data; } - thislength = s->end - s->p; + thislength = MIN(s->end - s->p, in->data + in->size - in->p); memcpy(in->p, s->p, thislength); - s->p += thislength; - s->end += thislength; + in->p += thislength; if (flags & CHANNEL_FLAG_LAST) { + in->end = in->p; in->p = in->data; channel->process(in); }