--- sourceforge.net/trunk/rdesktop/rdp.c 2004/06/29 16:22:41 730 +++ sourceforge.net/trunk/rdesktop/rdp.c 2005/03/08 00:23:02 830 @@ -1,7 +1,7 @@ /* -*- c-basic-offset: 8 -*- rdesktop: A Remote Desktop Protocol client. Protocol services - RDP layer - Copyright (C) Matthew Chapman 1999-2002 + 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 @@ -51,12 +51,26 @@ { static STREAM rdp_s; uint16 length, pdu_type; + uint8 rdpver; if ((rdp_s == NULL) || (g_next_packet >= rdp_s->end)) { - rdp_s = sec_recv(); + rdp_s = sec_recv(&rdpver); if (rdp_s == NULL) return NULL; + if (rdpver == 0xff) + { + g_next_packet = rdp_s->end; + *type = 0; + return rdp_s; + } + else if (rdpver != 3) + { + /* rdp5_process should move g_next_packet ok */ + rdp5_process(rdp_s); + *type = 0; + return rdp_s; + } g_next_packet = rdp_s->p; } @@ -372,22 +386,22 @@ rdp_enum_bmpcache2(void) { STREAM s; - uint8 idlist[BMPCACHE2_NUM_PSTCELLS * sizeof(BITMAP_ID)]; - uint32 nids, offset, count, flags; + HASH_KEY keylist[BMPCACHE2_NUM_PSTCELLS]; + uint32 num_keys, offset, count, flags; offset = 0; - nids = pstcache_enumerate(2, idlist); + num_keys = pstcache_enumerate(2, keylist); - while (offset < nids) + while (offset < num_keys) { - count = MIN(nids - offset, 169); + count = MIN(num_keys - offset, 169); - s = rdp_init_data(24 + count * sizeof(BITMAP_ID)); + s = rdp_init_data(24 + count * sizeof(HASH_KEY)); flags = 0; if (offset == 0) flags |= PDU_FLAG_FIRST; - if (nids - offset <= 169) + if (num_keys - offset <= 169) flags |= PDU_FLAG_LAST; /* header */ @@ -397,13 +411,12 @@ out_uint16_le(s, 0); out_uint16_le(s, 0); out_uint16_le(s, 0); - out_uint16_le(s, nids); + out_uint16_le(s, num_keys); out_uint32_le(s, 0); out_uint32_le(s, flags); /* list */ - out_uint8a(s, idlist + offset * sizeof(BITMAP_ID), - count * sizeof(BITMAP_ID)); + out_uint8a(s, keylist[offset], count * sizeof(HASH_KEY)); s_mark_end(s); rdp_send_data(s, 0x2b); @@ -553,7 +566,7 @@ { out_uint32_le(s, BMPCACHE2_C2_CELLS); } - out_uint8s(s, 20); /* other bitmap caches not used */ + out_uint8s(s, 20); /* other bitmap caches not used */ } /* Output control capability set */ @@ -644,7 +657,7 @@ /* Output unknown capability sets */ static void -rdp_out_unknown_caps(STREAM s, uint16 id, uint16 length, uint8 *caps) +rdp_out_unknown_caps(STREAM s, uint16 id, uint16 length, uint8 * caps) { out_uint16_le(s, id); out_uint16_le(s, length); @@ -664,7 +677,7 @@ RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE + RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL + RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + - 0x58 + 0x08 + 0x08 + 0x34 /* unknown caps */ + + 0x58 + 0x08 + 0x08 + 0x34 /* unknown caps */ + 4 /* w2k fix, why? */ ; s = sec_init(sec_flags, 6 + 14 + caplen + sizeof(RDP_SOURCE)); @@ -692,11 +705,11 @@ rdp_out_pointer_caps(s); rdp_out_share_caps(s); - rdp_out_unknown_caps(s, 0x0d, 0x58, caps_0x0d); /* international? */ + rdp_out_unknown_caps(s, 0x0d, 0x58, caps_0x0d); /* international? */ rdp_out_unknown_caps(s, 0x0c, 0x08, caps_0x0c); rdp_out_unknown_caps(s, 0x0e, 0x08, caps_0x0e); - rdp_out_unknown_caps(s, 0x10, 0x34, caps_0x10); /* glyph cache? */ - + rdp_out_unknown_caps(s, 0x10, 0x34, caps_0x10); /* glyph cache? */ + s_mark_end(s); sec_send(s, sec_flags); } @@ -740,7 +753,7 @@ if (g_width != width || g_height != height) { warning("screen size changed from %dx%d to %dx%d\n", g_width, g_height, - width, height); + width, height); g_width = width; g_height = height; ui_resize_window(); @@ -1078,7 +1091,8 @@ if (ctype & RDP_MPPC_COMPRESSED) { - + if (len > RDP_MPPC_DICT_SIZE) + error("error decompressed packet size exceeds max\n"); if (mppc_expand(s->p, clen, ctype, &roff, &rlen) == -1) error("error while decompressing packet\n"); @@ -1135,47 +1149,15 @@ } /* Process incoming packets */ +/* nevers gets out of here till app is done */ void rdp_main_loop(BOOL * deactivated, uint32 * ext_disc_reason) { - uint8 type; - BOOL disc = False; /* True when a disconnect PDU was received */ - STREAM s; - - while ((s = rdp_recv(&type)) != NULL) - { - switch (type) - { - case RDP_PDU_DEMAND_ACTIVE: - process_demand_active(s); - *deactivated = False; - break; - - case RDP_PDU_DEACTIVATE: - DEBUG(("RDP_PDU_DEACTIVATE\n")); - *deactivated = True; - break; - - case RDP_PDU_DATA: - disc = process_data_pdu(s, ext_disc_reason); - break; - - case 0: - break; - - default: - unimpl("PDU %d\n", type); - } - - if (disc) - { - return; - } - } - return; + while (rdp_loop(deactivated, ext_disc_reason)) + ; } -/* used in uiports, processes the rdp packets waiting */ +/* used in uiports and rdp_main_loop, processes the rdp packets waiting */ BOOL rdp_loop(BOOL * deactivated, uint32 * ext_disc_reason) {