From 72da43c808c7aec017f8840010757df40fcea52c Mon Sep 17 00:00:00 2001 From: Matt Chapman Date: Wed, 5 Jul 2000 07:44:21 +0000 Subject: [PATCH] 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 --- Makefile | 12 ++++++-- client.c | 6 +++- includes.h | 3 ++ parse.h | 3 ++ proto.h | 8 ++++++ rdp.c | 58 +++++++++++++++++++++++++------------- xwin.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ xwin.h | 32 +++++++++++++++++++++ 8 files changed, 182 insertions(+), 23 deletions(-) create mode 100644 xwin.c create mode 100644 xwin.h diff --git a/Makefile b/Makefile index 5bf3d65..ac882b0 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/client.c b/client.c index bd8781b..75eec59 100644 --- a/client.c +++ b/client.c @@ -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; diff --git a/includes.h b/includes.h index de4f5bf..6c5e5ac 100644 --- a/includes.h +++ b/includes.h @@ -31,14 +31,17 @@ #include #include +#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" diff --git a/parse.h b/parse.h index f318bc6..1d58302 100644 --- a/parse.h +++ b/parse.h @@ -39,6 +39,9 @@ typedef struct stream /* Connection state */ typedef struct connection { + /* User interface */ + HWINDOW wnd; + /* Parsing layer */ struct stream in; struct stream out; diff --git a/proto.h b/proto.h index bc0dd8e..52f5a45 100644 --- a/proto.h +++ b/proto.h @@ -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); + diff --git a/rdp.c b/rdp.c index 8d56b12..2274aa5 100644 --- a/rdp.c +++ b/rdp.c @@ -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); diff --git a/xwin.c b/xwin.c new file mode 100644 index 0000000..dac171d --- /dev/null +++ b/xwin.c @@ -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); +} diff --git a/xwin.h b/xwin.h new file mode 100644 index 0000000..e3e28d9 --- /dev/null +++ b/xwin.h @@ -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 +#include + +typedef struct window +{ + Display *display; + Window wnd; + GC gc; + +} *HWINDOW; + +typedef XImage *HBITMAP;