/[rdesktop]/sourceforge.net/trunk/rdesktop/rdp.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/rdp.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 25 by matty, Sat Jan 6 03:47:04 2001 UTC revision 365 by matthewc, Wed Apr 16 08:19:15 2003 UTC
# Line 1  Line 1 
1  /*  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Protocol services - RDP layer     Protocol services - RDP layer
4     Copyright (C) Matthew Chapman 1999-2000     Copyright (C) Matthew Chapman 1999-2002
5        
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 22  Line 22 
22    
23  extern uint16 mcs_userid;  extern uint16 mcs_userid;
24  extern char username[16];  extern char username[16];
25    extern BOOL bitmap_compression;
26  extern BOOL orders;  extern BOOL orders;
27    extern BOOL encryption;
28    extern BOOL desktop_save;
29    extern BOOL use_rdp5;
30    extern uint16 server_rdp_version;
31    
32  unsigned char *next_packet;  uint8 *next_packet;
33  uint32 rdp_shareid;  uint32 rdp_shareid;
34    
35  /* Initialise an RDP packet */  #if WITH_DEBUG
36  static STREAM  static uint32 packetno;
37  rdp_init(int maxlen)  #endif
 {  
         STREAM s;  
   
         s = sec_init(SEC_ENCRYPT, maxlen + 6);  
         s_push_layer(s, rdp_hdr, 6);  
   
         return s;  
 }  
   
 /* Send an RDP packet */  
 static void  
 rdp_send(STREAM s, uint8 pdu_type)  
 {  
         uint16 length;  
   
         s_pop_layer(s, rdp_hdr);  
         length = s->end - s->p;  
   
         out_uint16_le(s, length);  
         out_uint16_le(s, (pdu_type | 0x10));    /* Version 1 */  
         out_uint16_le(s, (mcs_userid + 1001));  
   
         sec_send(s, SEC_ENCRYPT);  
 }  
38    
39  /* Receive an RDP packet */  /* Receive an RDP packet */
40  static STREAM  static STREAM
41  rdp_recv(uint8 *type)  rdp_recv(uint8 * type)
42  {  {
43          static STREAM rdp_s;          static STREAM rdp_s;
44          uint16 length, pdu_type;          uint16 length, pdu_type;
# Line 76  rdp_recv(uint8 *type) Line 57  rdp_recv(uint8 *type)
57          }          }
58    
59          in_uint16_le(rdp_s, length);          in_uint16_le(rdp_s, length);
60            /* 32k packets are really 8, keepalive fix */
61            if (length == 0x8000)
62            {
63                    next_packet += 8;
64                    *type = 0;
65                    return rdp_s;
66            }
67          in_uint16_le(rdp_s, pdu_type);          in_uint16_le(rdp_s, pdu_type);
68          in_uint8s(rdp_s, 2);    /* userid */          in_uint8s(rdp_s, 2);    /* userid */
   
         next_packet += length;  
69          *type = pdu_type & 0xf;          *type = pdu_type & 0xf;
70    
71  #if RDP_DEBUG  #if WITH_DEBUG
72          DEBUG("RDP packet (type %x):\n", *type);          DEBUG(("RDP packet #%d, (type %x)\n", ++packetno, *type));
73          hexdump(rdp_s->p, length);          //      hexdump(next_packet, length);
74  #endif  #endif /*  */
75    
76            next_packet += length;
77          return rdp_s;          return rdp_s;
78  }  }
79    
# Line 96  rdp_init_data(int maxlen) Line 83  rdp_init_data(int maxlen)
83  {  {
84          STREAM s;          STREAM s;
85    
86          s = sec_init(SEC_ENCRYPT, maxlen + 18);          s = sec_init(encryption ? SEC_ENCRYPT : 0, maxlen + 18);
87          s_push_layer(s, rdp_hdr, 18);          s_push_layer(s, rdp_hdr, 18);
88    
89          return s;          return s;
# Line 118  rdp_send_data(STREAM s, uint8 data_pdu_t Line 105  rdp_send_data(STREAM s, uint8 data_pdu_t
105          out_uint32_le(s, rdp_shareid);          out_uint32_le(s, rdp_shareid);
106          out_uint8(s, 0);        /* pad */          out_uint8(s, 0);        /* pad */
107          out_uint8(s, 1);        /* streamid */          out_uint8(s, 1);        /* streamid */
108          out_uint16(s, (length - 14));          out_uint16_le(s, (length - 14));
109          out_uint8(s, data_pdu_type);          out_uint8(s, data_pdu_type);
110          out_uint8(s, 0);        /* compress_type */          out_uint8(s, 0);        /* compress_type */
111          out_uint16(s, 0);       /* compress_len */          out_uint16(s, 0);       /* compress_len */
112    
113          sec_send(s, SEC_ENCRYPT);          sec_send(s, encryption ? SEC_ENCRYPT : 0);
114  }  }
115    
116  /* Output a string in Unicode */  /* Output a string in Unicode */
# Line 153  rdp_send_logon_info(uint32 flags, char * Line 140  rdp_send_logon_info(uint32 flags, char *
140          int len_password = 2 * strlen(password);          int len_password = 2 * strlen(password);
141          int len_program = 2 * strlen(program);          int len_program = 2 * strlen(program);
142          int len_directory = 2 * strlen(directory);          int len_directory = 2 * strlen(directory);
143          uint32 sec_flags = SEC_LOGON_INFO | SEC_ENCRYPT;          uint32 sec_flags = encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT) : SEC_LOGON_INFO;
144          STREAM s;          STREAM s;
145    
146          s = sec_init(sec_flags, 18 + len_domain + len_user + len_password          if (1 == server_rdp_version)
147                       + len_program + len_directory + 10);          {
148                    DEBUG_RDP5(("Sending RDP4-style Logon packet\n"));
149    
150                    s = sec_init(sec_flags, 18 + len_domain + len_user + len_password
151                                 + len_program + len_directory + 10);
152    
153                    out_uint32(s, 0);
154                    out_uint32_le(s, flags);
155                    out_uint16_le(s, len_domain);
156                    out_uint16_le(s, len_user);
157                    out_uint16_le(s, len_password);
158                    out_uint16_le(s, len_program);
159                    out_uint16_le(s, len_directory);
160                    rdp_out_unistr(s, domain, len_domain);
161                    rdp_out_unistr(s, user, len_user);
162                    rdp_out_unistr(s, password, len_password);
163                    rdp_out_unistr(s, program, len_program);
164                    rdp_out_unistr(s, directory, len_directory);
165            }
166            else
167            {
168                    DEBUG_RDP5(("Sending RDP5-style Logon packet\n"));
169                    s = sec_init(sec_flags, 12 + (flags & RDP_LOGON_AUTO ? 2 : 0) + 6 + (flags & RDP_LOGON_AUTO ? len_password : 0) + len_domain + len_user + 4 + len_program + len_directory + 30 + 2 + 60 + 32 + 20 + 32 + 20);   /* Phew! */
170    
171          out_uint32(s, 0);                  out_uint32(s, 0);
172          out_uint32_le(s, flags);                  out_uint32_le(s, flags);
173          out_uint16_le(s, len_domain);                  out_uint16_le(s, len_domain);
174          out_uint16_le(s, len_user);                  out_uint16_le(s, len_user);
175          out_uint16_le(s, len_password);                  if (flags & RDP_LOGON_AUTO)
176          out_uint16_le(s, len_program);                  {
177          out_uint16_le(s, len_directory);                          out_uint16_le(s, len_password);
178          rdp_out_unistr(s, domain, len_domain);                  }
179          rdp_out_unistr(s, user, len_user);                  out_uint16(s, 0);       /* Seems to be length of a 512 byte blob with
180          rdp_out_unistr(s, password, len_password);                                             completely unknown data, but hopefully we'll do
181          rdp_out_unistr(s, program, len_program);                                             with a 0 length block as well */
182          rdp_out_unistr(s, directory, len_directory);                  out_uint16_le(s, len_program);
183                    out_uint16_le(s, len_directory);
184                    if (flags & RDP_LOGON_AUTO)
185                    {
186                            rdp_out_unistr(s, password, len_password);
187                    }
188                    rdp_out_unistr(s, domain, len_domain);
189                    rdp_out_unistr(s, user, len_user);
190                    out_uint16(s, 0);
191                    out_uint16(s, 0);
192                    if (0 < len_program)
193                            rdp_out_unistr(s, program, len_program);
194                    if (0 < len_directory)
195                            rdp_out_unistr(s, directory, len_directory);
196                    out_uint8s(s, 30);      /* Some kind of client data - let's see if the server
197                                               handles zeros well.. */
198                    out_uint16_le(s, 60);
199                    rdp_out_unistr(s, "C:\\WINNT\\System32\\mstscax.dll", 58);
200                    out_uint32_be(s, 0x88ffffff);
201                    rdp_out_unistr(s, "GTB, normaltid", 2 * strlen("GTB, normaltid") - 2);
202                    out_uint8s(s, 30 - 2 * strlen("GTP, normaltid"));
203    
204                    out_uint32_le(s, 0x0a0000);
205                    out_uint32_le(s, 0x050000);
206                    out_uint32_le(s, 2);
207                    out_uint32(s, 0);
208                    out_uint32_le(s, 0xffffffc4);
209                    out_uint32_le(s, 0xfffffffe);
210                    out_uint32_le(s, 0x0f);
211                    out_uint32(s, 0);
212    
213                    rdp_out_unistr(s, "GTB, sommartid", 2 * strlen("GTB, sommartid") - 1);
214                    out_uint8s(s, 30 - 2 * strlen("GTP, sommartid"));
215    
216                    out_uint32_le(s, 0x030000);
217                    out_uint32_le(s, 0x050000);
218                    out_uint32_le(s, 2);
219                    out_uint32(s, 0);
220                    out_uint32_le(s, 0xffffffc4);
221                    out_uint32_le(s, 0xfffffffe);
222                    out_uint32_le(s, 0x0f);
223                    out_uint32(s, 0);
224    
225            }
226          s_mark_end(s);          s_mark_end(s);
227          sec_send(s, sec_flags);          sec_send(s, sec_flags);
228  }  }
# Line 194  rdp_send_control(uint16 action) Line 245  rdp_send_control(uint16 action)
245    
246  /* Send a synchronisation PDU */  /* Send a synchronisation PDU */
247  static void  static void
248  rdp_send_synchronise()  rdp_send_synchronise(void)
249  {  {
250          STREAM s;          STREAM s;
251    
# Line 209  rdp_send_synchronise() Line 260  rdp_send_synchronise()
260    
261  /* Send a single input event */  /* Send a single input event */
262  void  void
263  rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags,  rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags, uint16 param1, uint16 param2)
                uint16 param1, uint16 param2)  
264  {  {
265          STREAM s;          STREAM s;
266    
# Line 258  rdp_out_general_caps(STREAM s) Line 308  rdp_out_general_caps(STREAM s)
308          out_uint16_le(s, 0x200);        /* Protocol version */          out_uint16_le(s, 0x200);        /* Protocol version */
309          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
310          out_uint16(s, 0);       /* Compression types */          out_uint16(s, 0);       /* Compression types */
311          out_uint16(s, 0);       /* Pad */          out_uint16_le(s, use_rdp5 ? 0x40d : 0);
312            /* Pad, according to T.128. 0x40d seems to
313               trigger
314               the server to start sending RDP5 packets.
315               However, the value is 0x1d04 with W2KTSK and
316               NT4MS. Hmm.. Anyway, thankyou, Microsoft,
317               for sending such information in a padding
318               field.. */
319          out_uint16(s, 0);       /* Update capability */          out_uint16(s, 0);       /* Update capability */
320          out_uint16(s, 0);       /* Remote unshare capability */          out_uint16(s, 0);       /* Remote unshare capability */
321          out_uint16(s, 0);       /* Compression level */          out_uint16(s, 0);       /* Compression level */
# Line 273  rdp_out_bitmap_caps(STREAM s) Line 330  rdp_out_bitmap_caps(STREAM s)
330          out_uint16_le(s, RDP_CAPLEN_BITMAP);          out_uint16_le(s, RDP_CAPLEN_BITMAP);
331    
332          out_uint16_le(s, 8);    /* Preferred BPP */          out_uint16_le(s, 8);    /* Preferred BPP */
333          out_uint16(s, 1);       /* Receive 1 BPP */          out_uint16_le(s, 1);    /* Receive 1 BPP */
334          out_uint16(s, 1);       /* Receive 4 BPP */          out_uint16_le(s, 1);    /* Receive 4 BPP */
335          out_uint16_le(s, 1);    /* Receive 8 BPP */          out_uint16_le(s, 1);    /* Receive 8 BPP */
336          out_uint16_le(s, 800);  /* Desktop width */          out_uint16_le(s, 800);  /* Desktop width */
337          out_uint16_le(s, 600);  /* Desktop height */          out_uint16_le(s, 600);  /* Desktop height */
338          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
339          out_uint16(s, 0);       /* Allow resize */          out_uint16(s, 0);       /* Allow resize */
340          out_uint16_le(s, 1);    /* Support compression */          out_uint16_le(s, bitmap_compression ? 1 : 0);   /* Support compression */
341          out_uint16(s, 0);       /* Unknown */          out_uint16(s, 0);       /* Unknown */
342          out_uint16_le(s, 1);    /* Unknown */          out_uint16_le(s, 1);    /* Unknown */
343          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
# Line 292  rdp_out_order_caps(STREAM s) Line 349  rdp_out_order_caps(STREAM s)
349  {  {
350          uint8 order_caps[32];          uint8 order_caps[32];
351    
         memset(order_caps, orders, 32);  
352    
353            memset(order_caps, 0, 32);
354            order_caps[0] = 1;      /* dest blt */
355            order_caps[1] = 1;      /* pat blt */
356            order_caps[2] = 1;      /* screen blt */
357            order_caps[3] = 1;      /* required for memblt? */
358            order_caps[8] = 1;      /* line */
359            order_caps[9] = 1;      /* line */
360            order_caps[10] = 1;     /* rect */
361            order_caps[11] = (desktop_save == False ? 0 : 1);       /* desksave */
362            order_caps[13] = 1;     /* memblt */
363            order_caps[14] = 1;     /* triblt */
364            order_caps[22] = 1;     /* polyline */
365            order_caps[27] = 1;     /* text2 */
366          out_uint16_le(s, RDP_CAPSET_ORDER);          out_uint16_le(s, RDP_CAPSET_ORDER);
367          out_uint16_le(s, RDP_CAPLEN_ORDER);          out_uint16_le(s, RDP_CAPLEN_ORDER);
368    
# Line 307  rdp_out_order_caps(STREAM s) Line 376  rdp_out_order_caps(STREAM s)
376          out_uint8p(s, order_caps, 32);  /* Orders supported */          out_uint8p(s, order_caps, 32);  /* Orders supported */
377          out_uint16_le(s, 0x6a1);        /* Text capability flags */          out_uint16_le(s, 0x6a1);        /* Text capability flags */
378          out_uint8s(s, 6);       /* Pad */          out_uint8s(s, 6);       /* Pad */
379          out_uint32(s, 0x38400); /* Desktop cache size */          out_uint32_le(s, desktop_save == False ? 0 : 0x38400);  /* Desktop cache size */
380          out_uint32(s, 0);       /* Unknown */          out_uint32(s, 0);       /* Unknown */
381          out_uint32(s, 0x4e4);   /* Unknown */          out_uint32_le(s, 0x4e4);        /* Unknown */
382  }  }
383    
384  /* Output bitmap cache capability set */  /* Output bitmap cache capability set */
# Line 409  static uint8 canned_caps[] = { Line 478  static uint8 canned_caps[] = {
478          0x02, 0x00, 0x00, 0x00          0x02, 0x00, 0x00, 0x00
479  };  };
480    
481  /* Output unknown capability set */  /* Output unknown capability sets (number 13, 12, 14 and 16) */
482  static void  static void
483  rdp_out_unknown_caps(STREAM s)  rdp_out_unknown_caps(STREAM s)
484  {  {
# Line 419  rdp_out_unknown_caps(STREAM s) Line 488  rdp_out_unknown_caps(STREAM s)
488          out_uint8p(s, canned_caps, RDP_CAPLEN_UNKNOWN - 4);          out_uint8p(s, canned_caps, RDP_CAPLEN_UNKNOWN - 4);
489  }  }
490    
491    #define RDP5_FLAG 0x0030
492  /* Send a confirm active PDU */  /* Send a confirm active PDU */
493  static void  static void
494  rdp_send_confirm_active()  rdp_send_confirm_active(void)
495  {  {
496          STREAM s;          STREAM s;
497            uint32 sec_flags = encryption ? (RDP5_FLAG | SEC_ENCRYPT) : RDP5_FLAG;
498          uint16 caplen =          uint16 caplen =
499                  RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER +                  RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER +
500                  RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE +                  RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE +
501                  RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL +                  RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL +
502                  RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN;                  RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN + 4 /* w2k fix, why? */ ;
503    
504          s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));          s = sec_init(sec_flags, 6 + 14 + caplen + sizeof(RDP_SOURCE));
505    
506            out_uint16_le(s, 2 + 14 + caplen + sizeof(RDP_SOURCE));
507            out_uint16_le(s, (RDP_PDU_CONFIRM_ACTIVE | 0x10));      /* Version 1 */
508            out_uint16_le(s, (mcs_userid + 1001));
509    
510          out_uint32_le(s, rdp_shareid);          out_uint32_le(s, rdp_shareid);
511          out_uint16_le(s, 0x3ea);        /* userid */          out_uint16_le(s, 0x3ea);        /* userid */
# Line 453  rdp_send_confirm_active() Line 528  rdp_send_confirm_active()
528          rdp_out_unknown_caps(s);          rdp_out_unknown_caps(s);
529    
530          s_mark_end(s);          s_mark_end(s);
531          rdp_send(s, RDP_PDU_CONFIRM_ACTIVE);          sec_send(s, sec_flags);
532  }  }
533    
534  /* Respond to a demand active PDU */  /* Respond to a demand active PDU */
# Line 464  process_demand_active(STREAM s) Line 539  process_demand_active(STREAM s)
539    
540          in_uint32_le(s, rdp_shareid);          in_uint32_le(s, rdp_shareid);
541    
542          DEBUG("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid);          DEBUG(("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid));
543    
544          rdp_send_confirm_active();          rdp_send_confirm_active();
545          rdp_send_synchronise();          rdp_send_synchronise();
546          rdp_send_control(RDP_CTL_COOPERATE);          rdp_send_control(RDP_CTL_COOPERATE);
547          rdp_send_control(RDP_CTL_REQUEST_CONTROL);          rdp_send_control(RDP_CTL_REQUEST_CONTROL);
548          rdp_recv(&type);        // RDP_PDU_SYNCHRONIZE          rdp_recv(&type);        /* RDP_PDU_SYNCHRONIZE */
549          rdp_recv(&type);        // RDP_CTL_COOPERATE          rdp_recv(&type);        /* RDP_CTL_COOPERATE */
550          rdp_recv(&type);        // RDP_CTL_GRANT_CONTROL          rdp_recv(&type);        /* RDP_CTL_GRANT_CONTROL */
551          rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);          rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);
552          rdp_send_fonts(1);          rdp_send_fonts(1);
553          rdp_send_fonts(2);          rdp_send_fonts(2);
554          rdp_recv(&type);        // RDP_PDU_UNKNOWN 0x28          rdp_recv(&type);        /* RDP_PDU_UNKNOWN 0x28 */
555          reset_order_state();          reset_order_state();
556  }  }
557    
558    /* Process a null system pointer PDU */
559    void
560    process_null_system_pointer_pdu(STREAM s)
561    {
562            // FIXME: We should probably set another cursor here,
563            // like the X window system base cursor or something.
564            ui_set_cursor(cache_get_cursor(0));
565    }
566    
567    /* Process a colour pointer PDU */
568    void
569    process_colour_pointer_pdu(STREAM s)
570    {
571            uint16 x, y, width, height, cache_idx, masklen, datalen;
572            uint8 *mask, *data;
573            HCURSOR cursor;
574    
575            in_uint16_le(s, cache_idx);
576            in_uint16_le(s, x);
577            in_uint16_le(s, y);
578            in_uint16_le(s, width);
579            in_uint16_le(s, height);
580            in_uint16_le(s, masklen);
581            in_uint16_le(s, datalen);
582            in_uint8p(s, data, datalen);
583            in_uint8p(s, mask, masklen);
584            cursor = ui_create_cursor(x, y, width, height, mask, data);
585            ui_set_cursor(cursor);
586            cache_put_cursor(cache_idx, cursor);
587    }
588    
589    /* Process a cached pointer PDU */
590    void
591    process_cached_pointer_pdu(STREAM s)
592    {
593            uint16 cache_idx;
594    
595            in_uint16_le(s, cache_idx);
596            ui_set_cursor(cache_get_cursor(cache_idx));
597    }
598    
599    
600  /* Process a pointer PDU */  /* Process a pointer PDU */
601  static void  static void
602  process_pointer_pdu(STREAM s)  process_pointer_pdu(STREAM s)
# Line 499  process_pointer_pdu(STREAM s) Line 616  process_pointer_pdu(STREAM s)
616                                  ui_move_pointer(x, y);                                  ui_move_pointer(x, y);
617                          break;                          break;
618    
619                    case RDP_POINTER_COLOR:
620                            process_colour_pointer_pdu(s);
621                            break;
622    
623                    case RDP_POINTER_CACHED:
624                            process_cached_pointer_pdu(s);
625                            break;
626    
627                  default:                  default:
628                          DEBUG("Pointer message 0x%x\n", message_type);                          DEBUG(("Pointer message 0x%x\n", message_type));
629          }          }
630  }  }
631    
632  /* Process bitmap updates */  /* Process bitmap updates */
633  static void  void
634  process_bitmap_updates(STREAM s)  process_bitmap_updates(STREAM s)
635  {  {
636          uint16 num_updates;          uint16 num_updates;
637          uint16 left, top, right, bottom, width, height;          uint16 left, top, right, bottom, width, height;
638          uint16 cx, cy, bpp, compress, bufsize, size;          uint16 cx, cy, bpp, Bpp, compress, bufsize, size;
639          uint8 *data, *rawdata;          uint8 *data, *bmpdata;
640          int i;          int i;
641    
642          in_uint16_le(s, num_updates);          in_uint16_le(s, num_updates);
# Line 525  process_bitmap_updates(STREAM s) Line 650  process_bitmap_updates(STREAM s)
650                  in_uint16_le(s, width);                  in_uint16_le(s, width);
651                  in_uint16_le(s, height);                  in_uint16_le(s, height);
652                  in_uint16_le(s, bpp);                  in_uint16_le(s, bpp);
653                    Bpp = (bpp + 7) / 8;
654                  in_uint16_le(s, compress);                  in_uint16_le(s, compress);
655                  in_uint16_le(s, bufsize);                  in_uint16_le(s, bufsize);
656    
657                  cx = right - left + 1;                  cx = right - left + 1;
658                  cy = bottom - top + 1;                  cy = bottom - top + 1;
659    
660                  DEBUG("UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,cmp=%d)\n",                  DEBUG(("BITMAP_UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,Bpp=%d,cmp=%d)\n",
661                        left, top, right, bottom, width, height, compress);                         left, top, right, bottom, width, height, Bpp, compress));
662    
663                  if (!compress)                  if (!compress)
664                  {                  {
665                          in_uint8p(s, data, bufsize);                          int y;
666                          ui_paint_bitmap(left, top, cx, cy, width, height,                          bmpdata = xmalloc(width * height * Bpp);
667                                          data);                          for (y = 0; y < height; y++)
668                          return;                          {
669                                    in_uint8a(s, &bmpdata[(height - y - 1) * (width * Bpp)],
670                                              width * Bpp);
671                            }
672                            ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata);
673                            xfree(bmpdata);
674                            continue;
675                  }                  }
676    
                 in_uint8s(s, 2);        /* pad */  
                 in_uint16_le(s, size);  
                 in_uint8s(s, 4);        /* line_size, final_size */  
                 in_uint8p(s, data, size);  
677    
678                  rawdata = xmalloc(width * height);                  if (compress & 0x400)
                 if (bitmap_decompress(rawdata, width, height, data, size))  
679                  {                  {
680                          ui_paint_bitmap(left, top, cx, cy, width, height,                          size = bufsize;
681                                          rawdata);                  }
682                    else
683                    {
684                            in_uint8s(s, 2);        /* pad */
685                            in_uint16_le(s, size);
686                            in_uint8s(s, 4);        /* line_size, final_size */
687                    }
688                    in_uint8p(s, data, size);
689                    bmpdata = xmalloc(width * height * Bpp);
690                    if (bitmap_decompress(bmpdata, width, height, data, size, Bpp))
691                    {
692                            ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata);
693                    }
694                    else
695                    {
696                            DEBUG_RDP5(("Failed to decompress data\n"));
697                  }                  }
698    
699                  xfree(rawdata);                  xfree(bmpdata);
700          }          }
701  }  }
702    
703  /* Process a palette update */  /* Process a palette update */
704  static void  void
705  process_palette(STREAM s)  process_palette(STREAM s)
706  {  {
707          HCOLOURMAP hmap;          COLOURENTRY *entry;
708          COLOURMAP map;          COLOURMAP map;
709            HCOLOURMAP hmap;
710            int i;
711    
712          in_uint8s(s, 2);        /* pad */          in_uint8s(s, 2);        /* pad */
713          in_uint16_le(s, map.ncolours);          in_uint16_le(s, map.ncolours);
714          in_uint8s(s, 2);        /* pad */          in_uint8s(s, 2);        /* pad */
715          in_uint8p(s, (uint8 *) map.colours, (map.ncolours * 3));  
716            map.colours = xmalloc(3 * map.ncolours);
717    
718            DEBUG(("PALETTE(c=%d)\n", map.ncolours));
719    
720            for (i = 0; i < map.ncolours; i++)
721            {
722                    entry = &map.colours[i];
723                    in_uint8(s, entry->red);
724                    in_uint8(s, entry->green);
725                    in_uint8(s, entry->blue);
726            }
727    
728          hmap = ui_create_colourmap(&map);          hmap = ui_create_colourmap(&map);
729          ui_set_colourmap(hmap);          ui_set_colourmap(hmap);
730    
731            xfree(map.colours);
732  }  }
733    
734  /* Process an update PDU */  /* Process an update PDU */
735  static void  static void
736  process_update_pdu(STREAM s)  process_update_pdu(STREAM s)
737  {  {
738          uint16 update_type;          uint16 update_type, count;
739    
740          in_uint16_le(s, update_type);          in_uint16_le(s, update_type);
741    
742          switch (update_type)          switch (update_type)
743          {          {
744                  case RDP_UPDATE_ORDERS:                  case RDP_UPDATE_ORDERS:
745                          process_orders(s);                          in_uint8s(s, 2);        /* pad */
746                            in_uint16_le(s, count);
747                            in_uint8s(s, 2);        /* pad */
748                            process_orders(s, count);
749                          break;                          break;
750    
751                  case RDP_UPDATE_BITMAP:                  case RDP_UPDATE_BITMAP:
# Line 600  process_update_pdu(STREAM s) Line 760  process_update_pdu(STREAM s)
760                          break;                          break;
761    
762                  default:                  default:
763                          NOTIMP("update %d\n", update_type);                          unimpl("update %d\n", update_type);
764          }          }
765    
766  }  }
# Line 630  process_data_pdu(STREAM s) Line 790  process_data_pdu(STREAM s)
790                          break;                          break;
791    
792                  case RDP_DATA_PDU_LOGON:                  case RDP_DATA_PDU_LOGON:
793                            DEBUG(("Received Logon PDU\n"));
794                          /* User logged on */                          /* User logged on */
795                          break;                          break;
796    
797                  default:                  default:
798                          NOTIMP("data PDU %d\n", data_pdu_type);                          unimpl("data PDU %d\n", data_pdu_type);
799          }          }
800  }  }
801    
802  /* Process incoming packets */  /* Process incoming packets */
803  void  void
804  rdp_main_loop()  rdp_main_loop(void)
805  {  {
806          uint8 type;          uint8 type;
807          STREAM s;          STREAM s;
# Line 660  rdp_main_loop() Line 821  rdp_main_loop()
821                                  process_data_pdu(s);                                  process_data_pdu(s);
822                                  break;                                  break;
823    
824                            case 0:
825                                    break;
826    
827                          default:                          default:
828                                  NOTIMP("PDU %d\n", type);                                  unimpl("PDU %d\n", type);
829                  }                  }
830          }          }
831  }  }
# Line 671  BOOL Line 835  BOOL
835  rdp_connect(char *server, uint32 flags, char *domain, char *password,  rdp_connect(char *server, uint32 flags, char *domain, char *password,
836              char *command, char *directory)              char *command, char *directory)
837  {  {
838          if (!sec_connect(server))          if (!sec_connect(server, username))
839                  return False;                  return False;
840    
841          rdp_send_logon_info(flags, domain, username, password,          rdp_send_logon_info(flags, domain, username, password, command, directory);
                             command, directory);  
842          return True;          return True;
843  }  }
844    
845  /* Disconnect from the RDP layer */  /* Disconnect from the RDP layer */
846  void  void
847  rdp_disconnect()  rdp_disconnect(void)
848  {  {
849          sec_disconnect();          sec_disconnect();
850  }  }

Legend:
Removed from v.25  
changed lines
  Added in v.365

  ViewVC Help
Powered by ViewVC 1.1.26