/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (hide annotations)
Sat Jan 6 03:47:04 2001 UTC (23 years, 4 months ago) by matty
File MIME type: text/plain
File size: 15300 byte(s)
Changed indentation style (-psl).

1 matty 3 /*
2     rdesktop: A Remote Desktop Protocol client.
3     Protocol services - RDP layer
4     Copyright (C) Matthew Chapman 1999-2000
5    
6     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
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10    
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     GNU General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19     */
20    
21 matty 10 #include "rdesktop.h"
22 matty 3
23 matty 10 extern uint16 mcs_userid;
24     extern char username[16];
25     extern BOOL orders;
26 matty 3
27 matty 10 unsigned char *next_packet;
28     uint32 rdp_shareid;
29 matty 3
30 matty 10 /* Initialise an RDP packet */
31 matty 25 static STREAM
32     rdp_init(int maxlen)
33 matty 3 {
34 matty 10 STREAM s;
35 matty 3
36 matty 10 s = sec_init(SEC_ENCRYPT, maxlen + 6);
37     s_push_layer(s, rdp_hdr, 6);
38 matty 9
39 matty 10 return s;
40 matty 9 }
41    
42 matty 10 /* Send an RDP packet */
43 matty 25 static void
44     rdp_send(STREAM s, uint8 pdu_type)
45 matty 3 {
46 matty 10 uint16 length;
47 matty 3
48 matty 10 s_pop_layer(s, rdp_hdr);
49     length = s->end - s->p;
50 matty 3
51 matty 10 out_uint16_le(s, length);
52 matty 24 out_uint16_le(s, (pdu_type | 0x10)); /* Version 1 */
53 matty 10 out_uint16_le(s, (mcs_userid + 1001));
54 matty 3
55 matty 10 sec_send(s, SEC_ENCRYPT);
56 matty 3 }
57    
58 matty 10 /* Receive an RDP packet */
59 matty 25 static STREAM
60     rdp_recv(uint8 *type)
61 matty 3 {
62 matty 10 static STREAM rdp_s;
63     uint16 length, pdu_type;
64 matty 3
65 matty 10 if ((rdp_s == NULL) || (next_packet >= rdp_s->end))
66     {
67     rdp_s = sec_recv();
68     if (rdp_s == NULL)
69     return NULL;
70 matty 3
71 matty 10 next_packet = rdp_s->p;
72     }
73     else
74 matty 7 {
75 matty 10 rdp_s->p = next_packet;
76 matty 7 }
77    
78 matty 10 in_uint16_le(rdp_s, length);
79     in_uint16_le(rdp_s, pdu_type);
80 matty 24 in_uint8s(rdp_s, 2); /* userid */
81 matty 3
82 matty 10 next_packet += length;
83     *type = pdu_type & 0xf;
84 matty 7
85 matty 10 #if RDP_DEBUG
86     DEBUG("RDP packet (type %x):\n", *type);
87     hexdump(rdp_s->p, length);
88 matty 7 #endif
89    
90 matty 10 return rdp_s;
91 matty 3 }
92    
93 matty 10 /* Initialise an RDP data packet */
94 matty 25 static STREAM
95     rdp_init_data(int maxlen)
96 matty 3 {
97 matty 10 STREAM s;
98 matty 3
99 matty 10 s = sec_init(SEC_ENCRYPT, maxlen + 18);
100     s_push_layer(s, rdp_hdr, 18);
101    
102     return s;
103 matty 3 }
104    
105 matty 10 /* Send an RDP data packet */
106 matty 25 static void
107     rdp_send_data(STREAM s, uint8 data_pdu_type)
108 matty 9 {
109 matty 10 uint16 length;
110 matty 9
111 matty 10 s_pop_layer(s, rdp_hdr);
112     length = s->end - s->p;
113 matty 9
114 matty 10 out_uint16_le(s, length);
115     out_uint16_le(s, (RDP_PDU_DATA | 0x10));
116     out_uint16_le(s, (mcs_userid + 1001));
117 matty 9
118 matty 10 out_uint32_le(s, rdp_shareid);
119 matty 24 out_uint8(s, 0); /* pad */
120     out_uint8(s, 1); /* streamid */
121 matty 10 out_uint16(s, (length - 14));
122     out_uint8(s, data_pdu_type);
123 matty 24 out_uint8(s, 0); /* compress_type */
124     out_uint16(s, 0); /* compress_len */
125 matty 3
126 matty 10 sec_send(s, SEC_ENCRYPT);
127 matty 3 }
128    
129 matty 10 /* Output a string in Unicode */
130 matty 25 void
131     rdp_out_unistr(STREAM s, char *string, int len)
132 matty 3 {
133 matty 10 int i = 0, j = 0;
134 matty 9
135 matty 10 len += 2;
136 matty 9
137 matty 10 while (i < len)
138 matty 9 {
139 matty 10 s->p[i++] = string[j++];
140     s->p[i++] = 0;
141 matty 9 }
142    
143 matty 10 s->p += len;
144 matty 3 }
145    
146 matty 10 /* Parse a logon info packet */
147 matty 25 static void
148     rdp_send_logon_info(uint32 flags, char *domain, char *user,
149     char *password, char *program, char *directory)
150 matty 3 {
151 matty 24 int len_domain = 2 * strlen(domain);
152     int len_user = 2 * strlen(user);
153     int len_password = 2 * strlen(password);
154     int len_program = 2 * strlen(program);
155 matty 10 int len_directory = 2 * strlen(directory);
156     uint32 sec_flags = SEC_LOGON_INFO | SEC_ENCRYPT;
157     STREAM s;
158 matty 3
159 matty 10 s = sec_init(sec_flags, 18 + len_domain + len_user + len_password
160 matty 24 + len_program + len_directory + 10);
161 matty 3
162 matty 10 out_uint32(s, 0);
163     out_uint32_le(s, flags);
164     out_uint16_le(s, len_domain);
165     out_uint16_le(s, len_user);
166     out_uint16_le(s, len_password);
167     out_uint16_le(s, len_program);
168     out_uint16_le(s, len_directory);
169 matty 24 rdp_out_unistr(s, domain, len_domain);
170     rdp_out_unistr(s, user, len_user);
171     rdp_out_unistr(s, password, len_password);
172     rdp_out_unistr(s, program, len_program);
173 matty 10 rdp_out_unistr(s, directory, len_directory);
174 matty 3
175 matty 10 s_mark_end(s);
176     sec_send(s, sec_flags);
177 matty 3 }
178    
179 matty 10 /* Send a control PDU */
180 matty 25 static void
181     rdp_send_control(uint16 action)
182 matty 3 {
183 matty 10 STREAM s;
184 matty 9
185 matty 10 s = rdp_init_data(8);
186 matty 9
187 matty 10 out_uint16_le(s, action);
188 matty 24 out_uint16(s, 0); /* userid */
189     out_uint32(s, 0); /* control id */
190 matty 9
191 matty 10 s_mark_end(s);
192     rdp_send_data(s, RDP_DATA_PDU_CONTROL);
193 matty 3 }
194    
195 matty 10 /* Send a synchronisation PDU */
196 matty 25 static void
197     rdp_send_synchronise()
198 matty 3 {
199 matty 10 STREAM s;
200 matty 9
201 matty 10 s = rdp_init_data(4);
202 matty 9
203 matty 24 out_uint16_le(s, 1); /* type */
204 matty 10 out_uint16_le(s, 1002);
205 matty 9
206 matty 10 s_mark_end(s);
207     rdp_send_data(s, RDP_DATA_PDU_SYNCHRONISE);
208 matty 3 }
209    
210 matty 10 /* Send a single input event */
211 matty 25 void
212     rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags,
213     uint16 param1, uint16 param2)
214 matty 3 {
215 matty 10 STREAM s;
216 matty 9
217 matty 10 s = rdp_init_data(16);
218 matty 9
219 matty 24 out_uint16_le(s, 1); /* number of events */
220     out_uint16(s, 0); /* pad */
221 matty 9
222 matty 10 out_uint32_le(s, time);
223     out_uint16_le(s, message_type);
224     out_uint16_le(s, device_flags);
225     out_uint16_le(s, param1);
226     out_uint16_le(s, param2);
227 matty 9
228 matty 10 s_mark_end(s);
229     rdp_send_data(s, RDP_DATA_PDU_INPUT);
230 matty 3 }
231    
232 matty 10 /* Send an (empty) font information PDU */
233 matty 25 static void
234     rdp_send_fonts(uint16 seq)
235 matty 3 {
236 matty 10 STREAM s;
237 matty 3
238 matty 10 s = rdp_init_data(8);
239 matty 9
240 matty 10 out_uint16(s, 0); /* number of fonts */
241     out_uint16_le(s, 0x3e); /* unknown */
242     out_uint16_le(s, seq); /* unknown */
243     out_uint16_le(s, 0x32); /* entry size */
244 matty 9
245 matty 10 s_mark_end(s);
246     rdp_send_data(s, RDP_DATA_PDU_FONT2);
247 matty 3 }
248    
249 matty 10 /* Output general capability set */
250 matty 25 static void
251     rdp_out_general_caps(STREAM s)
252 matty 3 {
253 matty 10 out_uint16_le(s, RDP_CAPSET_GENERAL);
254     out_uint16_le(s, RDP_CAPLEN_GENERAL);
255 matty 3
256 matty 10 out_uint16_le(s, 1); /* OS major type */
257     out_uint16_le(s, 3); /* OS minor type */
258 matty 24 out_uint16_le(s, 0x200); /* Protocol version */
259 matty 10 out_uint16(s, 0); /* Pad */
260     out_uint16(s, 0); /* Compression types */
261     out_uint16(s, 0); /* Pad */
262     out_uint16(s, 0); /* Update capability */
263     out_uint16(s, 0); /* Remote unshare capability */
264     out_uint16(s, 0); /* Compression level */
265     out_uint16(s, 0); /* Pad */
266 matty 3 }
267    
268 matty 10 /* Output bitmap capability set */
269 matty 25 static void
270     rdp_out_bitmap_caps(STREAM s)
271 matty 9 {
272 matty 10 out_uint16_le(s, RDP_CAPSET_BITMAP);
273     out_uint16_le(s, RDP_CAPLEN_BITMAP);
274 matty 9
275 matty 10 out_uint16_le(s, 8); /* Preferred BPP */
276     out_uint16(s, 1); /* Receive 1 BPP */
277     out_uint16(s, 1); /* Receive 4 BPP */
278     out_uint16_le(s, 1); /* Receive 8 BPP */
279     out_uint16_le(s, 800); /* Desktop width */
280     out_uint16_le(s, 600); /* Desktop height */
281     out_uint16(s, 0); /* Pad */
282     out_uint16(s, 0); /* Allow resize */
283     out_uint16_le(s, 1); /* Support compression */
284     out_uint16(s, 0); /* Unknown */
285     out_uint16_le(s, 1); /* Unknown */
286     out_uint16(s, 0); /* Pad */
287 matty 9 }
288    
289 matty 10 /* Output order capability set */
290 matty 25 static void
291     rdp_out_order_caps(STREAM s)
292 matty 3 {
293 matty 10 uint8 order_caps[32];
294 matty 3
295 matty 10 memset(order_caps, orders, 32);
296 matty 9
297 matty 10 out_uint16_le(s, RDP_CAPSET_ORDER);
298     out_uint16_le(s, RDP_CAPLEN_ORDER);
299 matty 9
300 matty 10 out_uint8s(s, 20); /* Terminal desc, pad */
301     out_uint16_le(s, 1); /* Cache X granularity */
302     out_uint16_le(s, 20); /* Cache Y granularity */
303     out_uint16(s, 0); /* Pad */
304     out_uint16_le(s, 1); /* Max order level */
305     out_uint16_le(s, 0x147); /* Number of fonts */
306 matty 24 out_uint16_le(s, 0x2a); /* Capability flags */
307 matty 10 out_uint8p(s, order_caps, 32); /* Orders supported */
308     out_uint16_le(s, 0x6a1); /* Text capability flags */
309     out_uint8s(s, 6); /* Pad */
310     out_uint32(s, 0x38400); /* Desktop cache size */
311     out_uint32(s, 0); /* Unknown */
312     out_uint32(s, 0x4e4); /* Unknown */
313 matty 9 }
314    
315 matty 10 /* Output bitmap cache capability set */
316 matty 25 static void
317     rdp_out_bmpcache_caps(STREAM s)
318 matty 9 {
319 matty 10 out_uint16_le(s, RDP_CAPSET_BMPCACHE);
320     out_uint16_le(s, RDP_CAPLEN_BMPCACHE);
321 matty 3
322 matty 24 out_uint8s(s, 24); /* unused */
323     out_uint16_le(s, 0x258); /* entries */
324     out_uint16_le(s, 0x100); /* max cell size */
325     out_uint16_le(s, 0x12c); /* entries */
326     out_uint16_le(s, 0x400); /* max cell size */
327     out_uint16_le(s, 0x106); /* entries */
328     out_uint16_le(s, 0x1000); /* max cell size */
329 matty 9 }
330    
331 matty 10 /* Output control capability set */
332 matty 25 static void
333     rdp_out_control_caps(STREAM s)
334 matty 9 {
335 matty 10 out_uint16_le(s, RDP_CAPSET_CONTROL);
336     out_uint16_le(s, RDP_CAPLEN_CONTROL);
337 matty 9
338 matty 10 out_uint16(s, 0); /* Control capabilities */
339     out_uint16(s, 0); /* Remote detach */
340     out_uint16_le(s, 2); /* Control interest */
341     out_uint16_le(s, 2); /* Detach interest */
342 matty 9 }
343    
344 matty 10 /* Output activation capability set */
345 matty 25 static void
346     rdp_out_activate_caps(STREAM s)
347 matty 9 {
348 matty 10 out_uint16_le(s, RDP_CAPSET_ACTIVATE);
349     out_uint16_le(s, RDP_CAPLEN_ACTIVATE);
350 matty 9
351 matty 10 out_uint16(s, 0); /* Help key */
352     out_uint16(s, 0); /* Help index key */
353     out_uint16(s, 0); /* Extended help key */
354     out_uint16(s, 0); /* Window activate */
355 matty 9 }
356    
357 matty 10 /* Output pointer capability set */
358 matty 25 static void
359     rdp_out_pointer_caps(STREAM s)
360 matty 9 {
361 matty 10 out_uint16_le(s, RDP_CAPSET_POINTER);
362     out_uint16_le(s, RDP_CAPLEN_POINTER);
363 matty 9
364 matty 10 out_uint16(s, 0); /* Colour pointer */
365     out_uint16_le(s, 20); /* Cache size */
366 matty 9 }
367    
368 matty 10 /* Output share capability set */
369 matty 25 static void
370     rdp_out_share_caps(STREAM s)
371 matty 3 {
372 matty 10 out_uint16_le(s, RDP_CAPSET_SHARE);
373     out_uint16_le(s, RDP_CAPLEN_SHARE);
374 matty 3
375 matty 10 out_uint16(s, 0); /* userid */
376     out_uint16(s, 0); /* pad */
377 matty 9 }
378 matty 3
379 matty 10 /* Output colour cache capability set */
380 matty 25 static void
381     rdp_out_colcache_caps(STREAM s)
382 matty 9 {
383 matty 10 out_uint16_le(s, RDP_CAPSET_COLCACHE);
384     out_uint16_le(s, RDP_CAPLEN_COLCACHE);
385 matty 3
386 matty 10 out_uint16_le(s, 6); /* cache size */
387     out_uint16(s, 0); /* pad */
388 matty 3 }
389    
390 matty 10 static uint8 canned_caps[] = {
391 matty 24 0x01, 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x04,
392     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
393 matty 25 0x00, 0x00, 0x00, 0x00, 0x00,
394 matty 24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
395 matty 25 0x00, 0x00, 0x00, 0x00, 0x00,
396 matty 24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
397 matty 25 0x00, 0x00, 0x00, 0x00, 0x00,
398 matty 24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
399 matty 25 0x00, 0x00, 0x00, 0x00, 0x00,
400 matty 24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
401 matty 25 0x0C, 0x00, 0x08, 0x00, 0x01,
402 matty 24 0x00, 0x00, 0x00, 0x0E, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00,
403 matty 25 0x10, 0x00, 0x34, 0x00, 0xFE,
404 matty 24 0x00, 0x04, 0x00, 0xFE, 0x00, 0x04, 0x00, 0xFE, 0x00, 0x08, 0x00,
405 matty 25 0xFE, 0x00, 0x08, 0x00, 0xFE,
406 matty 24 0x00, 0x10, 0x00, 0xFE, 0x00, 0x20, 0x00, 0xFE, 0x00, 0x40, 0x00,
407 matty 25 0xFE, 0x00, 0x80, 0x00, 0xFE,
408 matty 24 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01,
409 matty 25 0x02, 0x00, 0x00, 0x00
410 matty 10 };
411 matty 3
412 matty 10 /* Output unknown capability set */
413 matty 25 static void
414     rdp_out_unknown_caps(STREAM s)
415 matty 3 {
416 matty 10 out_uint16_le(s, RDP_CAPSET_UNKNOWN);
417     out_uint16_le(s, 0x58);
418 matty 24
419     out_uint8p(s, canned_caps, RDP_CAPLEN_UNKNOWN - 4);
420 matty 3 }
421    
422 matty 10 /* Send a confirm active PDU */
423 matty 25 static void
424     rdp_send_confirm_active()
425 matty 7 {
426 matty 10 STREAM s;
427 matty 24 uint16 caplen =
428     RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER +
429     RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE +
430     RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL +
431     RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN;
432 matty 7
433 matty 10 s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));
434 matty 9
435 matty 10 out_uint32_le(s, rdp_shareid);
436 matty 24 out_uint16_le(s, 0x3ea); /* userid */
437 matty 10 out_uint16_le(s, sizeof(RDP_SOURCE));
438     out_uint16_le(s, caplen);
439 matty 9
440 matty 10 out_uint8p(s, RDP_SOURCE, sizeof(RDP_SOURCE));
441 matty 24 out_uint16_le(s, 0xd); /* num_caps */
442     out_uint8s(s, 2); /* pad */
443 matty 9
444 matty 10 rdp_out_general_caps(s);
445     rdp_out_bitmap_caps(s);
446     rdp_out_order_caps(s);
447     rdp_out_bmpcache_caps(s);
448     rdp_out_colcache_caps(s);
449     rdp_out_activate_caps(s);
450     rdp_out_control_caps(s);
451     rdp_out_pointer_caps(s);
452     rdp_out_share_caps(s);
453     rdp_out_unknown_caps(s);
454 matty 9
455 matty 10 s_mark_end(s);
456     rdp_send(s, RDP_PDU_CONFIRM_ACTIVE);
457 matty 9 }
458    
459 matty 10 /* Respond to a demand active PDU */
460 matty 25 static void
461     process_demand_active(STREAM s)
462 matty 9 {
463 matty 10 uint8 type;
464 matty 9
465 matty 10 in_uint32_le(s, rdp_shareid);
466 matty 9
467 matty 10 DEBUG("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid);
468 matty 9
469 matty 10 rdp_send_confirm_active();
470     rdp_send_synchronise();
471     rdp_send_control(RDP_CTL_COOPERATE);
472     rdp_send_control(RDP_CTL_REQUEST_CONTROL);
473 matty 24 rdp_recv(&type); // RDP_PDU_SYNCHRONIZE
474     rdp_recv(&type); // RDP_CTL_COOPERATE
475     rdp_recv(&type); // RDP_CTL_GRANT_CONTROL
476 matty 10 rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);
477     rdp_send_fonts(1);
478     rdp_send_fonts(2);
479 matty 24 rdp_recv(&type); // RDP_PDU_UNKNOWN 0x28
480 matty 10 reset_order_state();
481 matty 9 }
482    
483 matty 10 /* Process a pointer PDU */
484 matty 25 static void
485     process_pointer_pdu(STREAM s)
486 matty 9 {
487 matty 10 uint16 message_type;
488     uint16 x, y;
489 matty 9
490 matty 10 in_uint16_le(s, message_type);
491 matty 24 in_uint8s(s, 2); /* pad */
492 matty 9
493 matty 10 switch (message_type)
494 matty 7 {
495 matty 10 case RDP_POINTER_MOVE:
496     in_uint16_le(s, x);
497     in_uint16_le(s, y);
498     if (s_check(s))
499     ui_move_pointer(x, y);
500     break;
501 matty 9
502 matty 10 default:
503     DEBUG("Pointer message 0x%x\n", message_type);
504 matty 7 }
505 matty 9 }
506    
507 matty 10 /* Process bitmap updates */
508 matty 25 static void
509     process_bitmap_updates(STREAM s)
510 matty 9 {
511 matty 10 uint16 num_updates;
512     uint16 left, top, right, bottom, width, height;
513     uint16 cx, cy, bpp, compress, bufsize, size;
514     uint8 *data, *rawdata;
515 matty 9 int i;
516    
517 matty 10 in_uint16_le(s, num_updates);
518 matty 9
519 matty 10 for (i = 0; i < num_updates; i++)
520 matty 9 {
521 matty 10 in_uint16_le(s, left);
522     in_uint16_le(s, top);
523     in_uint16_le(s, right);
524     in_uint16_le(s, bottom);
525     in_uint16_le(s, width);
526     in_uint16_le(s, height);
527     in_uint16_le(s, bpp);
528     in_uint16_le(s, compress);
529     in_uint16_le(s, bufsize);
530 matty 9
531 matty 10 cx = right - left + 1;
532     cy = bottom - top + 1;
533 matty 7
534 matty 10 DEBUG("UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,cmp=%d)\n",
535 matty 24 left, top, right, bottom, width, height, compress);
536 matty 9
537 matty 10 if (!compress)
538     {
539     in_uint8p(s, data, bufsize);
540 matty 24 ui_paint_bitmap(left, top, cx, cy, width, height,
541     data);
542 matty 10 return;
543     }
544 matty 9
545 matty 24 in_uint8s(s, 2); /* pad */
546 matty 10 in_uint16_le(s, size);
547 matty 24 in_uint8s(s, 4); /* line_size, final_size */
548 matty 10 in_uint8p(s, data, size);
549 matty 9
550 matty 10 rawdata = xmalloc(width * height);
551     if (bitmap_decompress(rawdata, width, height, data, size))
552 matty 9 {
553 matty 10 ui_paint_bitmap(left, top, cx, cy, width, height,
554     rawdata);
555 matty 9 }
556    
557 matty 10 xfree(rawdata);
558     }
559 matty 9 }
560    
561 matty 10 /* Process a palette update */
562 matty 25 static void
563     process_palette(STREAM s)
564 matty 9 {
565 matty 10 HCOLOURMAP hmap;
566     COLOURMAP map;
567 matty 9
568 matty 24 in_uint8s(s, 2); /* pad */
569     in_uint16_le(s, map.ncolours);
570     in_uint8s(s, 2); /* pad */
571     in_uint8p(s, (uint8 *) map.colours, (map.ncolours * 3));
572 matty 3
573 matty 10 hmap = ui_create_colourmap(&map);
574     ui_set_colourmap(hmap);
575 matty 3 }
576    
577 matty 10 /* Process an update PDU */
578 matty 25 static void
579     process_update_pdu(STREAM s)
580 matty 9 {
581 matty 10 uint16 update_type;
582 matty 9
583 matty 10 in_uint16_le(s, update_type);
584 matty 3
585 matty 10 switch (update_type)
586 matty 3 {
587 matty 10 case RDP_UPDATE_ORDERS:
588     process_orders(s);
589     break;
590 matty 3
591 matty 10 case RDP_UPDATE_BITMAP:
592     process_bitmap_updates(s);
593     break;
594 matty 3
595 matty 10 case RDP_UPDATE_PALETTE:
596     process_palette(s);
597     break;
598 matty 3
599 matty 10 case RDP_UPDATE_SYNCHRONIZE:
600     break;
601 matty 9
602 matty 10 default:
603     NOTIMP("update %d\n", update_type);
604 matty 3 }
605    
606     }
607    
608 matty 10 /* Process data PDU */
609 matty 25 static void
610     process_data_pdu(STREAM s)
611 matty 9 {
612 matty 10 uint8 data_pdu_type;
613 matty 9
614 matty 24 in_uint8s(s, 8); /* shareid, pad, streamid, length */
615 matty 10 in_uint8(s, data_pdu_type);
616 matty 24 in_uint8s(s, 3); /* compress_type, compress_len */
617 matty 3
618 matty 10 switch (data_pdu_type)
619 matty 3 {
620 matty 10 case RDP_DATA_PDU_UPDATE:
621     process_update_pdu(s);
622     break;
623 matty 3
624 matty 10 case RDP_DATA_PDU_POINTER:
625     process_pointer_pdu(s);
626     break;
627 matty 3
628 matty 10 case RDP_DATA_PDU_BELL:
629     ui_bell();
630     break;
631 matty 3
632 matty 10 case RDP_DATA_PDU_LOGON:
633     /* User logged on */
634     break;
635 matty 3
636 matty 10 default:
637     NOTIMP("data PDU %d\n", data_pdu_type);
638 matty 3 }
639     }
640    
641 matty 10 /* Process incoming packets */
642 matty 25 void
643     rdp_main_loop()
644 matty 9 {
645 matty 10 uint8 type;
646     STREAM s;
647 matty 9
648 matty 10 while ((s = rdp_recv(&type)) != NULL)
649 matty 3 {
650 matty 10 switch (type)
651     {
652     case RDP_PDU_DEMAND_ACTIVE:
653     process_demand_active(s);
654     break;
655 matty 3
656 matty 10 case RDP_PDU_DEACTIVATE:
657     break;
658 matty 3
659 matty 10 case RDP_PDU_DATA:
660     process_data_pdu(s);
661     break;
662 matty 3
663 matty 10 default:
664     NOTIMP("PDU %d\n", type);
665     }
666 matty 3 }
667     }
668    
669 matty 10 /* Establish a connection up to the RDP layer */
670 matty 25 BOOL
671     rdp_connect(char *server, uint32 flags, char *domain, char *password,
672     char *command, char *directory)
673 matty 9 {
674 matty 10 if (!sec_connect(server))
675 matty 3 return False;
676    
677 matty 21 rdp_send_logon_info(flags, domain, username, password,
678 matty 24 command, directory);
679 matty 10 return True;
680 matty 3 }
681    
682 matty 10 /* Disconnect from the RDP layer */
683 matty 25 void
684     rdp_disconnect()
685 matty 9 {
686 matty 10 sec_disconnect();
687 matty 9 }

  ViewVC Help
Powered by ViewVC 1.1.26