Started hacking on an X-Windows (Xlib) interface.

Currently pops up a window and displays bitmaps it sees side by side.
Next step is to go back to the protocol and interpret the surrounding data
stream.


git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@5 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Matt Chapman 2000-07-05 07:44:21 +00:00
parent 34f82f3e18
commit 72da43c808
8 changed files with 182 additions and 23 deletions

View File

@ -4,7 +4,13 @@
# Copyright (C) Matthew Chapman 1999-2000 #
##############################################
SOURCES=client.c parse.c tcp.c iso.c mcs.c rdp.c bitmap.c
CC = gcc
CFLAGS = -g -Wall
LIBS = -L/usr/X11R6/lib -lX11
OBJECTS = client.o parse.o tcp.o iso.o mcs.o rdp.o bitmap.o xwin.o
rdesktop: $(SOURCES)
@gcc -g -Wall -o rdesktop $(SOURCES)
rdesktop: $(OBJECTS)
@$(CC) $(CFLAGS) -o rdesktop $(LIBS) $(OBJECTS)
clean:
rm -f *.o

View File

@ -1,6 +1,6 @@
/*
rdesktop: A Remote Desktop Protocol client.
Protocol services - ISO layer
Entrypoint and utility functions
Copyright (C) Matthew Chapman 1999-2000
This program is free software; you can redistribute it and/or modify
@ -39,6 +39,10 @@ int main(int argc, char *argv[])
fprintf(stderr, "Connection successful.\n");
conn->wnd = ui_create_window(640, 480);
rdp_main_loop(conn);
ui_destroy_window(conn->wnd);
rdp_disconnect(conn);
return 0;

View File

@ -31,14 +31,17 @@
#include <sys/socket.h>
#include <arpa/inet.h>
#if 0
#define False (0)
#define True (1)
#endif
typedef int BOOL;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
#include "xwin.h"
#include "parse.h"
#include "tcp.h"
#include "iso.h"

View File

@ -39,6 +39,9 @@ typedef struct stream
/* Connection state */
typedef struct connection
{
/* User interface */
HWINDOW wnd;
/* Parsing layer */
struct stream in;
struct stream out;

View File

@ -74,6 +74,7 @@ BOOL mcs_io_data(STREAM s, MCS_DATA *dt, BOOL request);
/* RDP layer */
HCONN rdp_connect(char *server);
void rdp_main_loop(HCONN conn);
void process_orders(HCONN conn, RDP_ORDER_STATE *os);
void rdp_establish_key(HCONN conn);
void rdp_send_cert(HCONN conn);
@ -131,3 +132,10 @@ void *xrealloc(void *oldmem, int size);
BOOL bitmap_decompress(unsigned char *input, int size,
unsigned char *output, int width);
/* User interface routines */
HWINDOW ui_create_window(int width, int height);
void ui_destroy_window(HWINDOW wnd);
HBITMAP ui_create_bitmap(HWINDOW wnd, int width, int height, uint8 *data);
void ui_destroy_bitmap(HBITMAP bmp);
void ui_paint_bitmap(HWINDOW wnd, HBITMAP bmp, int x, int y);

58
rdp.c
View File

@ -25,13 +25,8 @@ HCONN rdp_connect(char *server)
{
HCONN conn;
RDP_ACTIVE_PDU active;
RDP_DATA_HEADER hdr;
RDP_UPDATE_PDU update;
RDP_ORDER_STATE os;
uint8 type;
memset(&os, 0, sizeof(os));
if ((conn = mcs_connect(server)) == NULL)
return NULL;
@ -40,7 +35,7 @@ HCONN rdp_connect(char *server)
rdp_send_cert(conn);
mcs_recv(conn, False);
if (rdp_recv_pdu(conn, &type) && (type != RDP_PDU_DEMAND_ACTIVE))
if (!rdp_recv_pdu(conn, &type) || (type != RDP_PDU_DEMAND_ACTIVE))
{
fprintf(stderr, "RDP error, expected Demand Active\n");
mcs_disconnect(conn);
@ -59,6 +54,19 @@ HCONN rdp_connect(char *server)
rdp_send_fonts(conn, 1);
rdp_send_fonts(conn, 2);
rdp_recv_pdu(conn, &type); // RDP_PDU_UNKNOWN 0x28
return conn;
}
void rdp_main_loop(HCONN conn)
{
RDP_DATA_HEADER hdr;
RDP_UPDATE_PDU update;
RDP_ORDER_STATE os;
uint8 type;
memset(&os, 0, sizeof(os));
while (rdp_recv_pdu(conn, &type))
{
if (type != RDP_PDU_DATA)
@ -78,8 +86,6 @@ HCONN rdp_connect(char *server)
break;
}
}
return conn;
}
void prs_io_coord(STREAM s, uint16 *coord, BOOL delta)
@ -120,6 +126,30 @@ void process_opaque_rect(HCONN conn, RDP_ORDER_STATE *os, BOOL delta)
fprintf(stderr, "Opaque rectangle at %d, %d\n", os->opaque_rect.x, os->opaque_rect.y);
}
void process_bmpcache(HCONN conn)
{
RDP_BITMAP_HEADER rbh;
char *bmpdata;
HBITMAP bmp;
static int x = 0;
rdp_io_bitmap_header(&conn->in, &rbh);
fprintf(stderr, "Decompressing bitmap %d x %d, final size %d\n", rbh.width, rbh.height, rbh.final_size);
bmpdata = malloc(rbh.width * rbh.height);
bitmap_decompress(conn->in.data
+ conn->in.offset, rbh.size,
bmpdata, rbh.width);
conn->in.offset += rbh.size;
bmp = ui_create_bitmap(conn->wnd, rbh.width, rbh.height, bmpdata);
ui_paint_bitmap(conn->wnd, bmp, x, 0);
ui_destroy_bitmap(bmp);
x += rbh.width;
}
void process_orders(HCONN conn, RDP_ORDER_STATE *os)
{
uint16 num_orders;
@ -151,18 +181,8 @@ void process_orders(HCONN conn, RDP_ORDER_STATE *os)
switch (rso.type)
{
case RDP_ORDER_BMPCACHE:
{
RDP_BITMAP_HEADER rbh;
char output[8192];
rdp_io_bitmap_header(&conn->in, &rbh);
fprintf(stderr, "Decompressing bitmap %d x %d, final size %d\n", rbh.width, rbh.height, rbh.final_size);
bitmap_decompress(conn->in.data
+ conn->in.offset, rbh.size,
output, rbh.width);
conn->in.offset += rbh.size;
process_bmpcache(conn);
break;
}
default:
fprintf(stderr, "Unknown secondary order %d\n",
rso.type);

83
xwin.c Normal file
View File

@ -0,0 +1,83 @@
/*
rdesktop: A Remote Desktop Protocol client.
User interface services - X-Windows
Copyright (C) Matthew Chapman 1999-2000
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 "includes.h"
HWINDOW ui_create_window(int width, int height)
{
struct window *wnd;
Display *display;
Window window;
int black;
GC gc;
display = XOpenDisplay(NULL);
if (display == NULL)
return NULL;
black = BlackPixel(display, DefaultScreen(display));
window = XCreateSimpleWindow(display, DefaultRootWindow(display),
0, 0, width, height, 0, black, black);
XMapWindow(display, window);
XSync(display, True);
gc = XCreateGC(display, window, 0, NULL);
wnd = xmalloc(sizeof(struct window));
wnd->display = display;
wnd->wnd = window;
wnd->gc = gc;
return wnd;
}
void ui_destroy_window(HWINDOW wnd)
{
XFreeGC(wnd->display, wnd->gc);
XDestroyWindow(wnd->display, wnd->wnd);
XCloseDisplay(wnd->display);
}
HBITMAP ui_create_bitmap(HWINDOW wnd, int width, int height, uint8 *data)
{
XImage *image;
Visual *visual;
visual = DefaultVisual(wnd->display, DefaultScreen(wnd->display));
image = XCreateImage(wnd->display, visual, 8, ZPixmap, 0,
data, width, height, 32, width);
return (HBITMAP)image;
}
void ui_destroy_bitmap(HBITMAP bmp)
{
XDestroyImage((XImage *)bmp);
}
void ui_paint_bitmap(HWINDOW wnd, HBITMAP bmp, int x, int y)
{
XImage *image = (XImage *)bmp;
XPutImage(wnd->display, wnd->wnd, wnd->gc, image,
0, 0, x, y, image->width, image->height);
XSync(wnd->display, True);
}

32
xwin.h Normal file
View File

@ -0,0 +1,32 @@
/*
rdesktop: A Remote Desktop Protocol client.
User interface services - X-Windows
Copyright (C) Matthew Chapman 1999-2000
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 <X11/Xlib.h>
#include <X11/Xutil.h>
typedef struct window
{
Display *display;
Window wnd;
GC gc;
} *HWINDOW;
typedef XImage *HBITMAP;