--- sourceforge.net/trunk/rdesktop/orders.c 2003/02/04 05:32:13 309 +++ sourceforge.net/trunk/rdesktop/orders.c 2003/06/06 11:09:24 414 @@ -1,4 +1,4 @@ -/* +/* -*- c-basic-offset: 8 -*- rdesktop: A Remote Desktop Protocol client. RDP order processing Copyright (C) Matthew Chapman 1999-2002 @@ -22,7 +22,8 @@ #include "orders.h" extern uint8 *next_packet; -static RDP_ORDER_STATE order_state; +static RDP_ORDER_STATE g_order_state; +extern BOOL use_rdp5; /* Read field indicating which parameters are present */ static void @@ -54,7 +55,7 @@ /* Read a co-ordinate (16-bit, or 8-bit delta) */ static void -rdp_in_coord(STREAM s, uint16 * coord, BOOL delta) +rdp_in_coord(STREAM s, sint16 * coord, BOOL delta) { sint8 change; @@ -605,6 +606,10 @@ if (present & 0x002000) in_uint16_le(s, os->boxbottom); + if (present & 0x004000) /* fix for connecting to a server that */ + in_uint8s(s, 10); /* was disconnected with mstsc.exe */ + /* 0x008000, 0x020000, and 0x040000 are present too ??? */ + if (present & 0x080000) in_uint16_le(s, os->x); @@ -641,7 +646,7 @@ { HBITMAP bitmap; uint16 cache_idx, bufsize; - uint8 cache_id, width, height, bpp; + uint8 cache_id, width, height, bpp, Bpp; uint8 *data, *inverted; int y; @@ -650,17 +655,17 @@ in_uint8(s, width); in_uint8(s, height); in_uint8(s, bpp); + Bpp = (bpp + 7) / 8; in_uint16_le(s, bufsize); in_uint16_le(s, cache_idx); in_uint8p(s, data, bufsize); - if (bpp != 8) /* todo */ - return; DEBUG(("RAW_BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", width, height, cache_id, cache_idx)); - inverted = xmalloc(width * height); + inverted = (uint8 *) xmalloc(width * height * Bpp); for (y = 0; y < height; y++) { - memcpy(&inverted[(height - y - 1) * width], &data[y * width], width); + memcpy(&inverted[(height - y - 1) * (width * Bpp)], &data[y * (width * Bpp)], + width * Bpp); } bitmap = ui_create_bitmap(width, height, inverted); @@ -674,32 +679,52 @@ { HBITMAP bitmap; uint16 cache_idx, size; - uint8 cache_id, width, height, bpp; + uint8 cache_id, width, height, bpp, Bpp; uint8 *data, *bmpdata; + uint16 bufsize, pad2, row_size, final_size; + uint8 pad1; + + pad2 = row_size = final_size = 0xffff; /* Shut the compiler up */ in_uint8(s, cache_id); - in_uint8s(s, 1); /* pad */ + in_uint8(s, pad1); /* pad */ in_uint8(s, width); in_uint8(s, height); in_uint8(s, bpp); - in_uint8s(s, 2); /* bufsize */ + Bpp = (bpp + 7) / 8; + in_uint16_le(s, bufsize); /* bufsize */ in_uint16_le(s, cache_idx); - in_uint8s(s, 2); /* pad */ - in_uint16_le(s, size); - in_uint8s(s, 4); /* row_size, final_size */ + + if (!use_rdp5) + { + + /* Begin compressedBitmapData */ + in_uint16_le(s, pad2); /* pad */ + in_uint16_le(s, size); + // in_uint8s(s, 4); /* row_size, final_size */ + in_uint16_le(s, row_size); + in_uint16_le(s, final_size); + + } + else + { + size = bufsize; + } in_uint8p(s, data, size); - if (bpp != 8) /* todo */ - return; - DEBUG(("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", width, height, cache_id, cache_idx)); + DEBUG(("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d,bpp=%d,size=%d,pad1=%d,bufsize=%d,pad2=%d,rs=%d,fs=%d)\n", width, height, cache_id, cache_idx, bpp, size, pad1, bufsize, pad2, row_size, final_size)); - bmpdata = xmalloc(width * height); + bmpdata = (uint8 *) xmalloc(width * height * Bpp); - if (bitmap_decompress(bmpdata, width, height, data, size, bpp)) + if (bitmap_decompress(bmpdata, width, height, data, size, Bpp)) { bitmap = ui_create_bitmap(width, height, bmpdata); cache_put_bitmap(cache_id, cache_idx, bitmap); } + else + { + DEBUG(("Failed to decompress bitmap data\n")); + } xfree(bmpdata); } @@ -717,7 +742,7 @@ in_uint8(s, cache_id); in_uint16_le(s, map.ncolours); - map.colours = xmalloc(3 * map.ncolours); + map.colours = (COLOURENTRY *) xmalloc(3 * map.ncolours); for (i = 0; i < map.ncolours; i++) { @@ -808,19 +833,14 @@ /* Process an order PDU */ void -process_orders(STREAM s) +process_orders(STREAM s, uint16 num_orders) { - RDP_ORDER_STATE *os = &order_state; + RDP_ORDER_STATE *os = &g_order_state; uint32 present; - uint16 num_orders; uint8 order_flags; int size, processed = 0; BOOL delta; - in_uint8s(s, 2); /* pad */ - in_uint16_le(s, num_orders); - in_uint8s(s, 2); /* pad */ - while (processed < num_orders) { in_uint8(s, order_flags); @@ -937,6 +957,6 @@ void reset_order_state(void) { - memset(&order_state, 0, sizeof(order_state)); - order_state.order_type = RDP_ORDER_PATBLT; + memset(&g_order_state, 0, sizeof(g_order_state)); + g_order_state.order_type = RDP_ORDER_PATBLT; }