added files from rdesktop
This commit is contained in:
parent
d490be59e3
commit
fac0e03c03
181
uirdesktop/channels.c
Normal file
181
uirdesktop/channels.c
Normal file
@ -0,0 +1,181 @@
|
||||
/* -*- c-basic-offset: 8 -*-
|
||||
rdesktop: A Remote Desktop Protocol client.
|
||||
Protocol services - Virtual channels
|
||||
Copyright (C) Erik Forsberg <forsberg@cendio.se> 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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "rdesktop.h"
|
||||
|
||||
#define MAX_CHANNELS 6
|
||||
#define CHANNEL_CHUNK_LENGTH 1600
|
||||
#define CHANNEL_FLAG_FIRST 0x01
|
||||
#define CHANNEL_FLAG_LAST 0x02
|
||||
#define CHANNEL_FLAG_SHOW_PROTOCOL 0x10
|
||||
|
||||
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.
|
||||
|
||||
The format of TAG_SRV_CHANNELS seems to be
|
||||
|
||||
global_channel_no (uint16le)
|
||||
number_of_other_channels (uint16le)
|
||||
..followed by uint16les for the other channels.
|
||||
*/
|
||||
|
||||
VCHANNEL *
|
||||
channel_register(char *name, uint32 flags, void (*callback) (STREAM))
|
||||
{
|
||||
VCHANNEL *channel;
|
||||
|
||||
if (!g_use_rdp5)
|
||||
return NULL;
|
||||
|
||||
if (g_num_channels >= MAX_CHANNELS)
|
||||
{
|
||||
error("Channel table full, increase MAX_CHANNELS\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
channel = &g_channels[g_num_channels];
|
||||
channel->mcs_id = MCS_GLOBAL_CHANNEL + 1 + g_num_channels;
|
||||
strncpy(channel->name, name, 8);
|
||||
channel->flags = flags;
|
||||
channel->process = callback;
|
||||
g_num_channels++;
|
||||
return channel;
|
||||
}
|
||||
|
||||
STREAM
|
||||
channel_init(VCHANNEL * channel, uint32 length)
|
||||
{
|
||||
STREAM s;
|
||||
|
||||
s = sec_init(g_encryption ? SEC_ENCRYPT : 0, length + 8);
|
||||
s_push_layer(s, channel_hdr, 8);
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
channel_send(STREAM s, VCHANNEL * channel)
|
||||
{
|
||||
uint32 length, flags;
|
||||
uint32 thislength, remaining;
|
||||
uint8 *data;
|
||||
|
||||
/* first fragment sent in-place */
|
||||
s_pop_layer(s, channel_hdr);
|
||||
length = s->end - s->p - 8;
|
||||
|
||||
DEBUG_CHANNEL(("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)
|
||||
flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
|
||||
|
||||
out_uint32_le(s, length);
|
||||
out_uint32_le(s, flags);
|
||||
data = s->end = s->p + thislength;
|
||||
DEBUG_CHANNEL(("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) */
|
||||
while (remaining > 0)
|
||||
{
|
||||
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_CHANNEL(("Sending %d bytes with flags %d\n", thislength, flags));
|
||||
|
||||
s = sec_init(g_encryption ? SEC_ENCRYPT : 0, thislength + 8);
|
||||
out_uint32_le(s, length);
|
||||
out_uint32_le(s, flags);
|
||||
out_uint8p(s, data, thislength);
|
||||
s_mark_end(s);
|
||||
sec_send_to_channel(s, g_encryption ? SEC_ENCRYPT : 0, channel->mcs_id);
|
||||
|
||||
data += thislength;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
channel_process(STREAM s, uint16 mcs_channel)
|
||||
{
|
||||
uint32 length, flags;
|
||||
uint32 thislength;
|
||||
VCHANNEL *channel = NULL;
|
||||
unsigned int i;
|
||||
STREAM in;
|
||||
|
||||
for (i = 0; i < g_num_channels; i++)
|
||||
{
|
||||
channel = &g_channels[i];
|
||||
if (channel->mcs_id == mcs_channel)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i >= g_num_channels)
|
||||
return;
|
||||
|
||||
in_uint32_le(s, length);
|
||||
in_uint32_le(s, flags);
|
||||
if ((flags & CHANNEL_FLAG_FIRST) && (flags & CHANNEL_FLAG_LAST))
|
||||
{
|
||||
/* single fragment - pass straight up */
|
||||
channel->process(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* add fragment to defragmentation buffer */
|
||||
in = &channel->in;
|
||||
if (flags & CHANNEL_FLAG_FIRST)
|
||||
{
|
||||
if (length > in->size)
|
||||
{
|
||||
in->data = (uint8 *) xrealloc(in->data, length);
|
||||
in->size = length;
|
||||
}
|
||||
in->p = in->data;
|
||||
}
|
||||
|
||||
thislength = MIN(s->end - s->p, in->data + in->size - in->p);
|
||||
memcpy(in->p, s->p, thislength);
|
||||
in->p += thislength;
|
||||
|
||||
if (flags & CHANNEL_FLAG_LAST)
|
||||
{
|
||||
in->end = in->p;
|
||||
in->p = in->data;
|
||||
channel->process(in);
|
||||
}
|
||||
}
|
||||
}
|
119
uirdesktop/rdesktop.h
Normal file
119
uirdesktop/rdesktop.h
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
rdesktop: A Remote Desktop Protocol client.
|
||||
Master include file
|
||||
Copyright (C) Matthew Chapman 1999-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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/time.h>
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <limits.h> /* PATH_MAX */
|
||||
|
||||
#define VERSION "1.4.1"
|
||||
|
||||
#ifdef WITH_DEBUG
|
||||
#define DEBUG(args) printf args;
|
||||
#else
|
||||
#define DEBUG(args)
|
||||
#endif
|
||||
|
||||
#ifdef WITH_DEBUG_KBD
|
||||
#define DEBUG_KBD(args) printf args;
|
||||
#else
|
||||
#define DEBUG_KBD(args)
|
||||
#endif
|
||||
|
||||
#ifdef WITH_DEBUG_RDP5
|
||||
#define DEBUG_RDP5(args) printf args;
|
||||
#else
|
||||
#define DEBUG_RDP5(args)
|
||||
#endif
|
||||
|
||||
#ifdef WITH_DEBUG_CLIPBOARD
|
||||
#define DEBUG_CLIPBOARD(args) printf args;
|
||||
#else
|
||||
#define DEBUG_CLIPBOARD(args)
|
||||
#endif
|
||||
|
||||
#ifdef WITH_DEBUG_CHANNEL
|
||||
#define DEBUG_CHANNEL(args) printf args;
|
||||
#else
|
||||
#define DEBUG_CHANNEL(args)
|
||||
#endif
|
||||
|
||||
#define STRNCPY(dst,src,n) { strncpy(dst,src,n-1); dst[n-1] = 0; }
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
/* timeval macros */
|
||||
#ifndef timerisset
|
||||
#define timerisset(tvp)\
|
||||
((tvp)->tv_sec || (tvp)->tv_usec)
|
||||
#endif
|
||||
#ifndef timercmp
|
||||
#define timercmp(tvp, uvp, cmp)\
|
||||
((tvp)->tv_sec cmp (uvp)->tv_sec ||\
|
||||
(tvp)->tv_sec == (uvp)->tv_sec &&\
|
||||
(tvp)->tv_usec cmp (uvp)->tv_usec)
|
||||
#endif
|
||||
#ifndef timerclear
|
||||
#define timerclear(tvp)\
|
||||
((tvp)->tv_sec = (tvp)->tv_usec = 0)
|
||||
#endif
|
||||
|
||||
/* If configure does not define the endianess, try
|
||||
to find it out */
|
||||
#if !defined(L_ENDIAN) && !defined(B_ENDIAN)
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define L_ENDIAN
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define B_ENDIAN
|
||||
#else
|
||||
#error Unknown endianness. Edit rdesktop.h.
|
||||
#endif
|
||||
#endif /* B_ENDIAN, L_ENDIAN from configure */
|
||||
|
||||
/* No need for alignment on x86 and amd64 */
|
||||
#if !defined(NEED_ALIGN)
|
||||
#if !(defined(__x86__) || defined(__x86_64__) || \
|
||||
defined(__AMD64__) || defined(_M_IX86) || \
|
||||
defined(__i386__))
|
||||
#define NEED_ALIGN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "parse.h"
|
||||
#include "constants.h"
|
||||
#include "types.h"
|
||||
|
||||
#ifndef MAKE_PROTO
|
||||
#include "proto.h"
|
||||
#endif
|
1447
uirdesktop/rdp.c
Normal file
1447
uirdesktop/rdp.c
Normal file
File diff suppressed because it is too large
Load Diff
121
uirdesktop/rdp5.c
Normal file
121
uirdesktop/rdp5.c
Normal file
@ -0,0 +1,121 @@
|
||||
/* -*- c-basic-offset: 8 -*-
|
||||
rdesktop: A Remote Desktop Protocol client.
|
||||
Protocol services - RDP5 short form PDU processing
|
||||
Copyright (C) Matthew Chapman 1999-2005
|
||||
Copyright (C) Erik Forsberg 2003
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "rdesktop.h"
|
||||
|
||||
extern uint8 *g_next_packet;
|
||||
|
||||
extern RDPCOMP g_mppc_dict;
|
||||
|
||||
void
|
||||
rdp5_process(STREAM s)
|
||||
{
|
||||
uint16 length, count, x, y;
|
||||
uint8 type, ctype;
|
||||
uint8 *next;
|
||||
|
||||
uint32 roff, rlen;
|
||||
struct stream *ns = &(g_mppc_dict.ns);
|
||||
struct stream *ts;
|
||||
|
||||
#if 0
|
||||
printf("RDP5 data:\n");
|
||||
hexdump(s->p, s->end - s->p);
|
||||
#endif
|
||||
|
||||
ui_begin_update();
|
||||
while (s->p < s->end)
|
||||
{
|
||||
in_uint8(s, type);
|
||||
if (type & RDP5_COMPRESSED)
|
||||
{
|
||||
in_uint8(s, ctype);
|
||||
in_uint16_le(s, length);
|
||||
type ^= RDP5_COMPRESSED;
|
||||
}
|
||||
else
|
||||
{
|
||||
ctype = 0;
|
||||
in_uint16_le(s, length);
|
||||
}
|
||||
g_next_packet = next = s->p + length;
|
||||
|
||||
if (ctype & RDP_MPPC_COMPRESSED)
|
||||
{
|
||||
if (mppc_expand(s->p, length, ctype, &roff, &rlen) == -1)
|
||||
error("error while decompressing packet\n");
|
||||
|
||||
/* allocate memory and copy the uncompressed data into the temporary stream */
|
||||
ns->data = (uint8 *) xrealloc(ns->data, rlen);
|
||||
|
||||
memcpy((ns->data), (unsigned char *) (g_mppc_dict.hist + roff), rlen);
|
||||
|
||||
ns->size = rlen;
|
||||
ns->end = (ns->data + ns->size);
|
||||
ns->p = ns->data;
|
||||
ns->rdp_hdr = ns->p;
|
||||
|
||||
ts = ns;
|
||||
}
|
||||
else
|
||||
ts = s;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 0: /* update orders */
|
||||
in_uint16_le(ts, count);
|
||||
process_orders(ts, count);
|
||||
break;
|
||||
case 1: /* update bitmap */
|
||||
in_uint8s(ts, 2); /* part length */
|
||||
process_bitmap_updates(ts);
|
||||
break;
|
||||
case 2: /* update palette */
|
||||
in_uint8s(ts, 2); /* uint16 = 2 */
|
||||
process_palette(ts);
|
||||
break;
|
||||
case 3: /* update synchronize */
|
||||
break;
|
||||
case 5: /* null pointer */
|
||||
ui_set_null_cursor();
|
||||
break;
|
||||
case 6: /* default pointer */
|
||||
break;
|
||||
case 8: /* pointer position */
|
||||
in_uint16_le(ts, x);
|
||||
in_uint16_le(ts, y);
|
||||
if (s_check(ts))
|
||||
ui_move_pointer(x, y);
|
||||
break;
|
||||
case 9: /* color pointer */
|
||||
process_colour_pointer_pdu(ts);
|
||||
break;
|
||||
case 10: /* cached pointer */
|
||||
process_cached_pointer_pdu(ts);
|
||||
break;
|
||||
default:
|
||||
unimpl("RDP5 opcode %d\n", type);
|
||||
}
|
||||
|
||||
s->p = next;
|
||||
}
|
||||
ui_end_update();
|
||||
}
|
Loading…
Reference in New Issue
Block a user