/[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 24 by matty, Sat Jan 6 03:12:10 2001 UTC revision 340 by forsberg, Thu Mar 6 14:11:17 2003 UTC
# Line 1  Line 1 
1  /*  /*
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    
30  unsigned char *next_packet;  uint8 *next_packet;
31  uint32 rdp_shareid;  uint32 rdp_shareid;
32    
33    #if WITH_DEBUG
34    static uint32 packetno;
35    #endif
36    
37  /* Initialise an RDP packet */  /* Initialise an RDP packet */
38  static STREAM rdp_init(int maxlen)  static STREAM
39    rdp_init(int maxlen)
40  {  {
41          STREAM s;          STREAM s;
42    
43          s = sec_init(SEC_ENCRYPT, maxlen + 6);          s = sec_init(encryption ? SEC_ENCRYPT : 0, maxlen + 6);
44          s_push_layer(s, rdp_hdr, 6);          s_push_layer(s, rdp_hdr, 6);
45    
46          return s;          return s;
47  }  }
48    
49  /* Send an RDP packet */  /* Send an RDP packet */
50  static void rdp_send(STREAM s, uint8 pdu_type)  static void
51    rdp_send(STREAM s, uint8 pdu_type)
52  {  {
53          uint16 length;          uint16 length;
54    
# Line 50  static void rdp_send(STREAM s, uint8 pdu Line 59  static void rdp_send(STREAM s, uint8 pdu
59          out_uint16_le(s, (pdu_type | 0x10));    /* Version 1 */          out_uint16_le(s, (pdu_type | 0x10));    /* Version 1 */
60          out_uint16_le(s, (mcs_userid + 1001));          out_uint16_le(s, (mcs_userid + 1001));
61    
62          sec_send(s, SEC_ENCRYPT);          sec_send(s, encryption ? SEC_ENCRYPT : 0);
63  }  }
64    
65  /* Receive an RDP packet */  /* Receive an RDP packet */
66  static STREAM rdp_recv(uint8 *type)  static STREAM
67    rdp_recv(uint8 * type)
68  {  {
69          static STREAM rdp_s;          static STREAM rdp_s;
70          uint16 length, pdu_type;          uint16 length, pdu_type;
# Line 73  static STREAM rdp_recv(uint8 *type) Line 83  static STREAM rdp_recv(uint8 *type)
83          }          }
84    
85          in_uint16_le(rdp_s, length);          in_uint16_le(rdp_s, length);
86            /* 32k packets are really 8, keepalive fix */
87            if (length == 0x8000)
88            {
89                    next_packet += 8;
90                    *type = 0;
91                    return rdp_s;
92            }
93          in_uint16_le(rdp_s, pdu_type);          in_uint16_le(rdp_s, pdu_type);
94          in_uint8s(rdp_s, 2);    /* userid */          in_uint8s(rdp_s, 2);    /* userid */
   
         next_packet += length;  
95          *type = pdu_type & 0xf;          *type = pdu_type & 0xf;
96    
97  #if RDP_DEBUG  #if WITH_DEBUG
98          DEBUG("RDP packet (type %x):\n", *type);          DEBUG(("RDP packet #%d, (type %x):\n", ++packetno, *type));
99          hexdump(rdp_s->p, length);          hexdump(next_packet, length);
100  #endif  #endif /*  */
101    
102            next_packet += length;
103          return rdp_s;          return rdp_s;
104  }  }
105    
106  /* Initialise an RDP data packet */  /* Initialise an RDP data packet */
107  static STREAM rdp_init_data(int maxlen)  static STREAM
108    rdp_init_data(int maxlen)
109  {  {
110          STREAM s;          STREAM s;
111    
112          s = sec_init(SEC_ENCRYPT, maxlen + 18);          s = sec_init(encryption ? SEC_ENCRYPT : 0, maxlen + 18);
113          s_push_layer(s, rdp_hdr, 18);          s_push_layer(s, rdp_hdr, 18);
114    
115          return s;          return s;
116  }  }
117    
118  /* Send an RDP data packet */  /* Send an RDP data packet */
119  static void rdp_send_data(STREAM s, uint8 data_pdu_type)  static void
120    rdp_send_data(STREAM s, uint8 data_pdu_type)
121  {  {
122          uint16 length;          uint16 length;
123    
# Line 113  static void rdp_send_data(STREAM s, uint Line 131  static void rdp_send_data(STREAM s, uint
131          out_uint32_le(s, rdp_shareid);          out_uint32_le(s, rdp_shareid);
132          out_uint8(s, 0);        /* pad */          out_uint8(s, 0);        /* pad */
133          out_uint8(s, 1);        /* streamid */          out_uint8(s, 1);        /* streamid */
134          out_uint16(s, (length - 14));          out_uint16_le(s, (length - 14));
135          out_uint8(s, data_pdu_type);          out_uint8(s, data_pdu_type);
136          out_uint8(s, 0);        /* compress_type */          out_uint8(s, 0);        /* compress_type */
137          out_uint16(s, 0);       /* compress_len */          out_uint16(s, 0);       /* compress_len */
138    
139          sec_send(s, SEC_ENCRYPT);          sec_send(s, encryption ? SEC_ENCRYPT : 0);
140  }  }
141    
142  /* Output a string in Unicode */  /* Output a string in Unicode */
143  void rdp_out_unistr(STREAM s, char *string, int len)  void
144    rdp_out_unistr(STREAM s, char *string, int len)
145  {  {
146          int i = 0, j = 0;          int i = 0, j = 0;
147    
# Line 138  void rdp_out_unistr(STREAM s, char *stri Line 157  void rdp_out_unistr(STREAM s, char *stri
157  }  }
158    
159  /* Parse a logon info packet */  /* Parse a logon info packet */
160  static void rdp_send_logon_info(uint32 flags, char *domain, char *user,  static void
161                                  char *password, char *program,  rdp_send_logon_info(uint32 flags, char *domain, char *user,
162                                  char *directory)                      char *password, char *program, char *directory)
163  {  {
164          int len_domain = 2 * strlen(domain);          int len_domain = 2 * strlen(domain);
165          int len_user = 2 * strlen(user);          int len_user = 2 * strlen(user);
166          int len_password = 2 * strlen(password);          int len_password = 2 * strlen(password);
167          int len_program = 2 * strlen(program);          int len_program = 2 * strlen(program);
168          int len_directory = 2 * strlen(directory);          int len_directory = 2 * strlen(directory);
169          uint32 sec_flags = SEC_LOGON_INFO | SEC_ENCRYPT;          uint32 sec_flags = encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT) : SEC_LOGON_INFO;
170          STREAM s;          STREAM s;
171    
172          s = sec_init(sec_flags, 18 + len_domain + len_user + len_password          s = sec_init(sec_flags, 18 + len_domain + len_user + len_password
# Line 171  static void rdp_send_logon_info(uint32 f Line 190  static void rdp_send_logon_info(uint32 f
190  }  }
191    
192  /* Send a control PDU */  /* Send a control PDU */
193  static void rdp_send_control(uint16 action)  static void
194    rdp_send_control(uint16 action)
195  {  {
196          STREAM s;          STREAM s;
197    
# Line 186  static void rdp_send_control(uint16 acti Line 206  static void rdp_send_control(uint16 acti
206  }  }
207    
208  /* Send a synchronisation PDU */  /* Send a synchronisation PDU */
209  static void rdp_send_synchronise()  static void
210    rdp_send_synchronise(void)
211  {  {
212          STREAM s;          STREAM s;
213    
# Line 200  static void rdp_send_synchronise() Line 221  static void rdp_send_synchronise()
221  }  }
222    
223  /* Send a single input event */  /* Send a single input event */
224  void rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags,  void
225                      uint16 param1, uint16 param2)  rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags, uint16 param1, uint16 param2)
226  {  {
227          STREAM s;          STREAM s;
228    
# Line 221  void rdp_send_input(uint32 time, uint16 Line 242  void rdp_send_input(uint32 time, uint16
242  }  }
243    
244  /* Send an (empty) font information PDU */  /* Send an (empty) font information PDU */
245  static void rdp_send_fonts(uint16 seq)  static void
246    rdp_send_fonts(uint16 seq)
247  {  {
248          STREAM s;          STREAM s;
249    
# Line 237  static void rdp_send_fonts(uint16 seq) Line 259  static void rdp_send_fonts(uint16 seq)
259  }  }
260    
261  /* Output general capability set */  /* Output general capability set */
262  static void rdp_out_general_caps(STREAM s)  static void
263    rdp_out_general_caps(STREAM s)
264  {  {
265          out_uint16_le(s, RDP_CAPSET_GENERAL);          out_uint16_le(s, RDP_CAPSET_GENERAL);
266          out_uint16_le(s, RDP_CAPLEN_GENERAL);          out_uint16_le(s, RDP_CAPLEN_GENERAL);
# Line 255  static void rdp_out_general_caps(STREAM Line 278  static void rdp_out_general_caps(STREAM
278  }  }
279    
280  /* Output bitmap capability set */  /* Output bitmap capability set */
281  static void rdp_out_bitmap_caps(STREAM s)  static void
282    rdp_out_bitmap_caps(STREAM s)
283  {  {
284          out_uint16_le(s, RDP_CAPSET_BITMAP);          out_uint16_le(s, RDP_CAPSET_BITMAP);
285          out_uint16_le(s, RDP_CAPLEN_BITMAP);          out_uint16_le(s, RDP_CAPLEN_BITMAP);
286    
287          out_uint16_le(s, 8);    /* Preferred BPP */          out_uint16_le(s, 8);    /* Preferred BPP */
288          out_uint16(s, 1);       /* Receive 1 BPP */          out_uint16_le(s, 1);    /* Receive 1 BPP */
289          out_uint16(s, 1);       /* Receive 4 BPP */          out_uint16_le(s, 1);    /* Receive 4 BPP */
290          out_uint16_le(s, 1);    /* Receive 8 BPP */          out_uint16_le(s, 1);    /* Receive 8 BPP */
291          out_uint16_le(s, 800);  /* Desktop width */          out_uint16_le(s, 800);  /* Desktop width */
292          out_uint16_le(s, 600);  /* Desktop height */          out_uint16_le(s, 600);  /* Desktop height */
293          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
294          out_uint16(s, 0);       /* Allow resize */          out_uint16(s, 0);       /* Allow resize */
295          out_uint16_le(s, 1);    /* Support compression */          out_uint16_le(s, bitmap_compression ? 1 : 0);   /* Support compression */
296          out_uint16(s, 0);       /* Unknown */          out_uint16(s, 0);       /* Unknown */
297          out_uint16_le(s, 1);    /* Unknown */          out_uint16_le(s, 1);    /* Unknown */
298          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
299  }  }
300    
301  /* Output order capability set */  /* Output order capability set */
302  static void rdp_out_order_caps(STREAM s)  static void
303    rdp_out_order_caps(STREAM s)
304  {  {
305          uint8 order_caps[32];          uint8 order_caps[32];
306    
         memset(order_caps, orders, 32);  
307    
308            memset(order_caps, 0, 32);
309            order_caps[0] = 1;      /* dest blt */
310            order_caps[1] = 1;      /* pat blt */
311            order_caps[2] = 1;      /* screen blt */
312            order_caps[3] = 1;      /* required for memblt? */
313            order_caps[8] = 1;      /* line */
314            order_caps[9] = 1;      /* line */
315            order_caps[10] = 1;     /* rect */
316            order_caps[11] = (desktop_save == False ? 0 : 1);       /* desksave */
317            order_caps[13] = 1;     /* memblt */
318            order_caps[14] = 1;     /* triblt */
319            order_caps[22] = 1;     /* polyline */
320            order_caps[27] = 1;     /* text2 */
321          out_uint16_le(s, RDP_CAPSET_ORDER);          out_uint16_le(s, RDP_CAPSET_ORDER);
322          out_uint16_le(s, RDP_CAPLEN_ORDER);          out_uint16_le(s, RDP_CAPLEN_ORDER);
323    
# Line 294  static void rdp_out_order_caps(STREAM s) Line 331  static void rdp_out_order_caps(STREAM s)
331          out_uint8p(s, order_caps, 32);  /* Orders supported */          out_uint8p(s, order_caps, 32);  /* Orders supported */
332          out_uint16_le(s, 0x6a1);        /* Text capability flags */          out_uint16_le(s, 0x6a1);        /* Text capability flags */
333          out_uint8s(s, 6);       /* Pad */          out_uint8s(s, 6);       /* Pad */
334          out_uint32(s, 0x38400); /* Desktop cache size */          out_uint32_le(s, desktop_save == False ? 0 : 0x38400);  /* Desktop cache size */
335          out_uint32(s, 0);       /* Unknown */          out_uint32(s, 0);       /* Unknown */
336          out_uint32(s, 0x4e4);   /* Unknown */          out_uint32_le(s, 0x4e4);        /* Unknown */
337  }  }
338    
339  /* Output bitmap cache capability set */  /* Output bitmap cache capability set */
340  static void rdp_out_bmpcache_caps(STREAM s)  static void
341    rdp_out_bmpcache_caps(STREAM s)
342  {  {
343          out_uint16_le(s, RDP_CAPSET_BMPCACHE);          out_uint16_le(s, RDP_CAPSET_BMPCACHE);
344          out_uint16_le(s, RDP_CAPLEN_BMPCACHE);          out_uint16_le(s, RDP_CAPLEN_BMPCACHE);
# Line 315  static void rdp_out_bmpcache_caps(STREAM Line 353  static void rdp_out_bmpcache_caps(STREAM
353  }  }
354    
355  /* Output control capability set */  /* Output control capability set */
356  static void rdp_out_control_caps(STREAM s)  static void
357    rdp_out_control_caps(STREAM s)
358  {  {
359          out_uint16_le(s, RDP_CAPSET_CONTROL);          out_uint16_le(s, RDP_CAPSET_CONTROL);
360          out_uint16_le(s, RDP_CAPLEN_CONTROL);          out_uint16_le(s, RDP_CAPLEN_CONTROL);
# Line 327  static void rdp_out_control_caps(STREAM Line 366  static void rdp_out_control_caps(STREAM
366  }  }
367    
368  /* Output activation capability set */  /* Output activation capability set */
369  static void rdp_out_activate_caps(STREAM s)  static void
370    rdp_out_activate_caps(STREAM s)
371  {  {
372          out_uint16_le(s, RDP_CAPSET_ACTIVATE);          out_uint16_le(s, RDP_CAPSET_ACTIVATE);
373          out_uint16_le(s, RDP_CAPLEN_ACTIVATE);          out_uint16_le(s, RDP_CAPLEN_ACTIVATE);
# Line 339  static void rdp_out_activate_caps(STREAM Line 379  static void rdp_out_activate_caps(STREAM
379  }  }
380    
381  /* Output pointer capability set */  /* Output pointer capability set */
382  static void rdp_out_pointer_caps(STREAM s)  static void
383    rdp_out_pointer_caps(STREAM s)
384  {  {
385          out_uint16_le(s, RDP_CAPSET_POINTER);          out_uint16_le(s, RDP_CAPSET_POINTER);
386          out_uint16_le(s, RDP_CAPLEN_POINTER);          out_uint16_le(s, RDP_CAPLEN_POINTER);
# Line 349  static void rdp_out_pointer_caps(STREAM Line 390  static void rdp_out_pointer_caps(STREAM
390  }  }
391    
392  /* Output share capability set */  /* Output share capability set */
393  static void rdp_out_share_caps(STREAM s)  static void
394    rdp_out_share_caps(STREAM s)
395  {  {
396          out_uint16_le(s, RDP_CAPSET_SHARE);          out_uint16_le(s, RDP_CAPSET_SHARE);
397          out_uint16_le(s, RDP_CAPLEN_SHARE);          out_uint16_le(s, RDP_CAPLEN_SHARE);
# Line 359  static void rdp_out_share_caps(STREAM s) Line 401  static void rdp_out_share_caps(STREAM s)
401  }  }
402    
403  /* Output colour cache capability set */  /* Output colour cache capability set */
404  static void rdp_out_colcache_caps(STREAM s)  static void
405    rdp_out_colcache_caps(STREAM s)
406  {  {
407          out_uint16_le(s, RDP_CAPSET_COLCACHE);          out_uint16_le(s, RDP_CAPSET_COLCACHE);
408          out_uint16_le(s, RDP_CAPLEN_COLCACHE);          out_uint16_le(s, RDP_CAPLEN_COLCACHE);
# Line 371  static void rdp_out_colcache_caps(STREAM Line 414  static void rdp_out_colcache_caps(STREAM
414  static uint8 canned_caps[] = {  static uint8 canned_caps[] = {
415          0x01, 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x04,          0x01, 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x04,
416          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
417                  0x00, 0x00, 0x00, 0x00, 0x00,          0x00, 0x00, 0x00, 0x00, 0x00,
418          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
419                  0x00, 0x00, 0x00, 0x00, 0x00,          0x00, 0x00, 0x00, 0x00, 0x00,
420          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
421                  0x00, 0x00, 0x00, 0x00, 0x00,          0x00, 0x00, 0x00, 0x00, 0x00,
422          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
423                  0x00, 0x00, 0x00, 0x00, 0x00,          0x00, 0x00, 0x00, 0x00, 0x00,
424          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
425                  0x0C, 0x00, 0x08, 0x00, 0x01,          0x0C, 0x00, 0x08, 0x00, 0x01,
426          0x00, 0x00, 0x00, 0x0E, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00,          0x00, 0x00, 0x00, 0x0E, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00,
427                  0x10, 0x00, 0x34, 0x00, 0xFE,          0x10, 0x00, 0x34, 0x00, 0xFE,
428          0x00, 0x04, 0x00, 0xFE, 0x00, 0x04, 0x00, 0xFE, 0x00, 0x08, 0x00,          0x00, 0x04, 0x00, 0xFE, 0x00, 0x04, 0x00, 0xFE, 0x00, 0x08, 0x00,
429                  0xFE, 0x00, 0x08, 0x00, 0xFE,          0xFE, 0x00, 0x08, 0x00, 0xFE,
430          0x00, 0x10, 0x00, 0xFE, 0x00, 0x20, 0x00, 0xFE, 0x00, 0x40, 0x00,          0x00, 0x10, 0x00, 0xFE, 0x00, 0x20, 0x00, 0xFE, 0x00, 0x40, 0x00,
431                  0xFE, 0x00, 0x80, 0x00, 0xFE,          0xFE, 0x00, 0x80, 0x00, 0xFE,
432          0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01,          0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01,
433                  0x02, 0x00, 0x00, 0x00          0x02, 0x00, 0x00, 0x00
434  };  };
435    
436  /* Output unknown capability set */  /* Output unknown capability set */
437  static void rdp_out_unknown_caps(STREAM s)  static void
438    rdp_out_unknown_caps(STREAM s)
439  {  {
440          out_uint16_le(s, RDP_CAPSET_UNKNOWN);          out_uint16_le(s, RDP_CAPSET_UNKNOWN);
441          out_uint16_le(s, 0x58);          out_uint16_le(s, 0x58);
# Line 400  static void rdp_out_unknown_caps(STREAM Line 444  static void rdp_out_unknown_caps(STREAM
444  }  }
445    
446  /* Send a confirm active PDU */  /* Send a confirm active PDU */
447  static void rdp_send_confirm_active()  static void
448    rdp_send_confirm_active(void)
449  {  {
450          STREAM s;          STREAM s;
451          uint16 caplen =          uint16 caplen =
452                  RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER +                  RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER +
453                  RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE +                  RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE +
454                  RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL +                  RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL +
455                  RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN;                  RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN + 4 /* w2k fix, why? */ ;
456    
457          s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));          s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));
458    
# Line 436  static void rdp_send_confirm_active() Line 481  static void rdp_send_confirm_active()
481  }  }
482    
483  /* Respond to a demand active PDU */  /* Respond to a demand active PDU */
484  static void process_demand_active(STREAM s)  static void
485    process_demand_active(STREAM s)
486  {  {
487          uint8 type;          uint8 type;
488    
489          in_uint32_le(s, rdp_shareid);          in_uint32_le(s, rdp_shareid);
490    
491          DEBUG("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid);          DEBUG(("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid));
492    
493          rdp_send_confirm_active();          rdp_send_confirm_active();
494          rdp_send_synchronise();          rdp_send_synchronise();
495          rdp_send_control(RDP_CTL_COOPERATE);          rdp_send_control(RDP_CTL_COOPERATE);
496          rdp_send_control(RDP_CTL_REQUEST_CONTROL);          rdp_send_control(RDP_CTL_REQUEST_CONTROL);
497          rdp_recv(&type);        // RDP_PDU_SYNCHRONIZE          rdp_recv(&type);        /* RDP_PDU_SYNCHRONIZE */
498          rdp_recv(&type);        // RDP_CTL_COOPERATE          rdp_recv(&type);        /* RDP_CTL_COOPERATE */
499          rdp_recv(&type);        // RDP_CTL_GRANT_CONTROL          rdp_recv(&type);        /* RDP_CTL_GRANT_CONTROL */
500          rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);          rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);
501          rdp_send_fonts(1);          rdp_send_fonts(1);
502          rdp_send_fonts(2);          rdp_send_fonts(2);
503          rdp_recv(&type);        // RDP_PDU_UNKNOWN 0x28          rdp_recv(&type);        /* RDP_PDU_UNKNOWN 0x28 */
504          reset_order_state();          reset_order_state();
505  }  }
506    
507  /* Process a pointer PDU */  /* Process a pointer PDU */
508  static void process_pointer_pdu(STREAM s)  static void
509    process_pointer_pdu(STREAM s)
510  {  {
511          uint16 message_type;          uint16 message_type;
512          uint16 x, y;          uint16 x, y, width, height, cache_idx, masklen, datalen;
513            uint8 *mask, *data;
514            HCURSOR cursor;
515    
516          in_uint16_le(s, message_type);          in_uint16_le(s, message_type);
517          in_uint8s(s, 2);        /* pad */          in_uint8s(s, 2);        /* pad */
# Line 476  static void process_pointer_pdu(STREAM s Line 525  static void process_pointer_pdu(STREAM s
525                                  ui_move_pointer(x, y);                                  ui_move_pointer(x, y);
526                          break;                          break;
527    
528                    case RDP_POINTER_COLOR:
529                            in_uint16_le(s, cache_idx);
530                            in_uint16_le(s, x);
531                            in_uint16_le(s, y);
532                            in_uint16_le(s, width);
533                            in_uint16_le(s, height);
534                            in_uint16_le(s, masklen);
535                            in_uint16_le(s, datalen);
536                            in_uint8p(s, data, datalen);
537                            in_uint8p(s, mask, masklen);
538                            cursor = ui_create_cursor(x, y, width, height, mask, data);
539                            ui_set_cursor(cursor);
540                            cache_put_cursor(cache_idx, cursor);
541                            break;
542    
543                    case RDP_POINTER_CACHED:
544                            in_uint16_le(s, cache_idx);
545                            ui_set_cursor(cache_get_cursor(cache_idx));
546                            break;
547    
548                  default:                  default:
549                          DEBUG("Pointer message 0x%x\n", message_type);                          DEBUG(("Pointer message 0x%x\n", message_type));
550          }          }
551  }  }
552    
553  /* Process bitmap updates */  /* Process bitmap updates */
554  static void process_bitmap_updates(STREAM s)  static void
555    process_bitmap_updates(STREAM s)
556  {  {
557          uint16 num_updates;          uint16 num_updates;
558          uint16 left, top, right, bottom, width, height;          uint16 left, top, right, bottom, width, height;
559          uint16 cx, cy, bpp, compress, bufsize, size;          uint16 cx, cy, bpp, Bpp, compress, bufsize, size;
560          uint8 *data, *rawdata;          uint8 *data, *bmpdata;
561          int i;          int i;
562    
563          in_uint16_le(s, num_updates);          in_uint16_le(s, num_updates);
# Line 501  static void process_bitmap_updates(STREA Line 571  static void process_bitmap_updates(STREA
571                  in_uint16_le(s, width);                  in_uint16_le(s, width);
572                  in_uint16_le(s, height);                  in_uint16_le(s, height);
573                  in_uint16_le(s, bpp);                  in_uint16_le(s, bpp);
574                    Bpp = (bpp + 7) / 8;
575                  in_uint16_le(s, compress);                  in_uint16_le(s, compress);
576                  in_uint16_le(s, bufsize);                  in_uint16_le(s, bufsize);
577    
578                  cx = right - left + 1;                  cx = right - left + 1;
579                  cy = bottom - top + 1;                  cy = bottom - top + 1;
580    
581                  DEBUG("UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,cmp=%d)\n",                  DEBUG(("UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,cmp=%d)\n",
582                        left, top, right, bottom, width, height, compress);                         left, top, right, bottom, width, height, compress));
583    
584                  if (!compress)                  if (!compress)
585                  {                  {
586                          in_uint8p(s, data, bufsize);                          int y;
587                          ui_paint_bitmap(left, top, cx, cy, width, height,                          bmpdata = xmalloc(width * height * Bpp);
588                                          data);                          for (y = 0; y < height; y++)
589                          return;                          {
590                                    in_uint8a(s, &bmpdata[(height - y - 1) * (width * Bpp)],
591                                              width * Bpp);
592                            }
593                            ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata);
594                            xfree(bmpdata);
595                            continue;
596                  }                  }
597    
598                  in_uint8s(s, 2);        /* pad */                  in_uint8s(s, 2);        /* pad */
599                  in_uint16_le(s, size);                  in_uint16_le(s, size);
600                  in_uint8s(s, 4);        /* line_size, final_size */                  in_uint8s(s, 4);        /* line_size, final_size */
601                  in_uint8p(s, data, size);                  in_uint8p(s, data, size);
602                    bmpdata = xmalloc(width * height * Bpp);
603                  rawdata = xmalloc(width * height);                  if (bitmap_decompress(bmpdata, width, height, data, size, Bpp))
                 if (bitmap_decompress(rawdata, width, height, data, size))  
604                  {                  {
605                          ui_paint_bitmap(left, top, cx, cy, width, height,                          ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata);
                                         rawdata);  
606                  }                  }
607                    xfree(bmpdata);
                 xfree(rawdata);  
608          }          }
609  }  }
610    
611  /* Process a palette update */  /* Process a palette update */
612  static void process_palette(STREAM s)  static void
613    process_palette(STREAM s)
614  {  {
615          HCOLOURMAP hmap;          COLOURENTRY *entry;
616          COLOURMAP map;          COLOURMAP map;
617            HCOLOURMAP hmap;
618            int i;
619    
620          in_uint8s(s, 2);        /* pad */          in_uint8s(s, 2);        /* pad */
621          in_uint16_le(s, map.ncolours);          in_uint16_le(s, map.ncolours);
622          in_uint8s(s, 2);        /* pad */          in_uint8s(s, 2);        /* pad */
623          in_uint8p(s, (uint8 *) map.colours, (map.ncolours * 3));  
624            map.colours = xmalloc(3 * map.ncolours);
625    
626            for (i = 0; i < map.ncolours; i++)
627            {
628                    entry = &map.colours[i];
629                    in_uint8(s, entry->red);
630                    in_uint8(s, entry->green);
631                    in_uint8(s, entry->blue);
632            }
633    
634          hmap = ui_create_colourmap(&map);          hmap = ui_create_colourmap(&map);
635          ui_set_colourmap(hmap);          ui_set_colourmap(hmap);
636    
637            xfree(map.colours);
638  }  }
639    
640  /* Process an update PDU */  /* Process an update PDU */
641  static void process_update_pdu(STREAM s)  static void
642    process_update_pdu(STREAM s)
643  {  {
644          uint16 update_type;          uint16 update_type;
645    
# Line 574  static void process_update_pdu(STREAM s) Line 663  static void process_update_pdu(STREAM s)
663                          break;                          break;
664    
665                  default:                  default:
666                          NOTIMP("update %d\n", update_type);                          unimpl("update %d\n", update_type);
667          }          }
668    
669  }  }
670    
671  /* Process data PDU */  /* Process data PDU */
672  static void process_data_pdu(STREAM s)  static void
673    process_data_pdu(STREAM s)
674  {  {
675          uint8 data_pdu_type;          uint8 data_pdu_type;
676    
# Line 607  static void process_data_pdu(STREAM s) Line 697  static void process_data_pdu(STREAM s)
697                          break;                          break;
698    
699                  default:                  default:
700                          NOTIMP("data PDU %d\n", data_pdu_type);                          unimpl("data PDU %d\n", data_pdu_type);
701          }          }
702  }  }
703    
704  /* Process incoming packets */  /* Process incoming packets */
705  void rdp_main_loop()  void
706    rdp_main_loop(void)
707  {  {
708          uint8 type;          uint8 type;
709          STREAM s;          STREAM s;
# Line 632  void rdp_main_loop() Line 723  void rdp_main_loop()
723                                  process_data_pdu(s);                                  process_data_pdu(s);
724                                  break;                                  break;
725    
726                            case 0:
727                                    break;
728    
729                          default:                          default:
730                                  NOTIMP("PDU %d\n", type);                                  unimpl("PDU %d\n", type);
731                  }                  }
732          }          }
733  }  }
734    
735  /* Establish a connection up to the RDP layer */  /* Establish a connection up to the RDP layer */
736  BOOL rdp_connect(char *server, uint32 flags, char *domain, char *password,  BOOL
737                   char *command, char *directory)  rdp_connect(char *server, uint32 flags, char *domain, char *password,
738                char *command, char *directory)
739  {  {
740          if (!sec_connect(server))          if (!sec_connect(server))
741                  return False;                  return False;
742    
743          rdp_send_logon_info(flags, domain, username, password,          rdp_send_logon_info(flags, domain, username, password, command, directory);
                             command, directory);  
744          return True;          return True;
745  }  }
746    
747  /* Disconnect from the RDP layer */  /* Disconnect from the RDP layer */
748  void rdp_disconnect()  void
749    rdp_disconnect(void)
750  {  {
751          sec_disconnect();          sec_disconnect();
752  }  }

Legend:
Removed from v.24  
changed lines
  Added in v.340

  ViewVC Help
Powered by ViewVC 1.1.26