/[rdesktop]/sourceforge.net/trunk/rdesktop/orders.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

Contents of /sourceforge.net/trunk/rdesktop/orders.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (show annotations)
Tue Oct 17 08:24:09 2000 UTC (23 years, 8 months ago) by matty
File MIME type: text/plain
File size: 19783 byte(s)
Fix for big-endian X-servers: rely on server to handle byte/bit order.

1 /*
2 rdesktop: A Remote Desktop Protocol client.
3 RDP order processing
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 #include "rdesktop.h"
22 #include "orders.h"
23
24 extern unsigned char *next_packet;
25 static RDP_ORDER_STATE order_state;
26
27 /* Read field indicating which parameters are present */
28 static void rdp_in_present(STREAM s, uint32 *present, uint8 flags, int size)
29 {
30 uint8 bits;
31 int i;
32
33 if (flags & RDP_ORDER_SMALL)
34 {
35 size--;
36 }
37
38 if (flags & RDP_ORDER_TINY)
39 {
40 if (size < 2)
41 size = 0;
42 else
43 size -= 2;
44 }
45
46 *present = 0;
47 for (i = 0; i < size; i++)
48 {
49 in_uint8(s, bits);
50 *present |= bits << (i * 8);
51 }
52 }
53
54 /* Read a co-ordinate (16-bit, or 8-bit delta) */
55 static void rdp_in_coord(STREAM s, uint16 *coord, BOOL delta)
56 {
57 uint8 change;
58
59 if (delta)
60 {
61 in_uint8(s, change);
62 *coord += (char)change;
63 }
64 else
65 {
66 in_uint16_le(s, *coord);
67 }
68 }
69
70 /* Read a colour entry */
71 static void rdp_in_colour(STREAM s, uint8 *colour)
72 {
73 in_uint8(s, *colour);
74 s->p += 2;
75 }
76
77 /* Parse bounds information */
78 static BOOL rdp_parse_bounds(STREAM s, BOUNDS *bounds)
79 {
80 uint8 present;
81
82 in_uint8(s, present);
83
84 if (present & 1)
85 rdp_in_coord(s, &bounds->left, False);
86 else if (present & 16)
87 rdp_in_coord(s, &bounds->left, True);
88
89 if (present & 2)
90 rdp_in_coord(s, &bounds->top, False);
91 else if (present & 32)
92 rdp_in_coord(s, &bounds->top, True);
93
94 if (present & 4)
95 rdp_in_coord(s, &bounds->right, False);
96 else if (present & 64)
97 rdp_in_coord(s, &bounds->right, True);
98
99 if (present & 8)
100 rdp_in_coord(s, &bounds->bottom, False);
101 else if (present & 128)
102 rdp_in_coord(s, &bounds->bottom, True);
103
104 return s_check(s);
105 }
106
107 /* Parse a pen */
108 static BOOL rdp_parse_pen(STREAM s, PEN *pen, uint32 present)
109 {
110 if (present & 1)
111 in_uint8(s, pen->style);
112
113 if (present & 2)
114 in_uint8(s, pen->width);
115
116 if (present & 4)
117 rdp_in_colour(s, &pen->colour);
118
119 return s_check(s);
120 }
121
122 /* Parse a brush */
123 static BOOL rdp_parse_brush(STREAM s, BRUSH *brush, uint32 present)
124 {
125 if (present & 1)
126 in_uint8(s, brush->xorigin);
127
128 if (present & 2)
129 in_uint8(s, brush->yorigin);
130
131 if (present & 4)
132 in_uint8(s, brush->style);
133
134 if (present & 8)
135 in_uint8(s, brush->pattern[0]);
136
137 if (present & 16)
138 in_uint8a(s, &brush->pattern[1], 7);
139
140 return s_check(s);
141 }
142
143 /* Process a destination blt order */
144 static void process_destblt(STREAM s, DESTBLT_ORDER *os,
145 uint32 present, BOOL delta)
146 {
147 if (present & 0x01)
148 rdp_in_coord(s, &os->x, delta);
149
150 if (present & 0x02)
151 rdp_in_coord(s, &os->y, delta);
152
153 if (present & 0x04)
154 rdp_in_coord(s, &os->cx, delta);
155
156 if (present & 0x08)
157 rdp_in_coord(s, &os->cy, delta);
158
159 if (present & 0x10)
160 in_uint8(s, os->opcode);
161
162 DEBUG("DESTBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d)\n",
163 os->opcode, os->x, os->y, os->cx, os->cy);
164
165 ui_destblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy);
166 }
167
168 /* Process a pattern blt order */
169 static void process_patblt(STREAM s, PATBLT_ORDER *os,
170 uint32 present, BOOL delta)
171 {
172 if (present & 0x0001)
173 rdp_in_coord(s, &os->x, delta);
174
175 if (present & 0x0002)
176 rdp_in_coord(s, &os->y, delta);
177
178 if (present & 0x0004)
179 rdp_in_coord(s, &os->cx, delta);
180
181 if (present & 0x0008)
182 rdp_in_coord(s, &os->cy, delta);
183
184 if (present & 0x0010)
185 in_uint8(s, os->opcode);
186
187 if (present & 0x0020)
188 rdp_in_colour(s, &os->bgcolour);
189
190 if (present & 0x0040)
191 rdp_in_colour(s, &os->fgcolour);
192
193 rdp_parse_brush(s, &os->brush, present >> 7);
194
195 DEBUG("PATBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,bs=%d,bg=0x%x,fg=0x%x)\n",
196 os->opcode, os->x, os->y, os->cx, os->cy,
197 os->brush.style, os->bgcolour, os->fgcolour);
198
199 ui_patblt(ROP2_P(os->opcode), os->x, os->y, os->cx, os->cy,
200 &os->brush, os->bgcolour, os->fgcolour);
201 }
202
203 /* Process a screen blt order */
204 static void process_screenblt(STREAM s, SCREENBLT_ORDER *os,
205 uint32 present, BOOL delta)
206 {
207 if (present & 0x0001)
208 rdp_in_coord(s, &os->x, delta);
209
210 if (present & 0x0002)
211 rdp_in_coord(s, &os->y, delta);
212
213 if (present & 0x0004)
214 rdp_in_coord(s, &os->cx, delta);
215
216 if (present & 0x0008)
217 rdp_in_coord(s, &os->cy, delta);
218
219 if (present & 0x0010)
220 in_uint8(s, os->opcode);
221
222 if (present & 0x0020)
223 rdp_in_coord(s, &os->srcx, delta);
224
225 if (present & 0x0040)
226 rdp_in_coord(s, &os->srcy, delta);
227
228 DEBUG("SCREENBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,srcx=%d,srcy=%d)\n",
229 os->opcode, os->x, os->y, os->cx, os->cy, os->srcx, os->srcy);
230
231 ui_screenblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy,
232 os->srcx, os->srcy);
233 }
234
235 /* Process a line order */
236 static void process_line(STREAM s, LINE_ORDER *os, uint32 present, BOOL delta)
237 {
238 if (present & 0x0001)
239 in_uint16_le(s, os->mixmode);
240
241 if (present & 0x0002)
242 rdp_in_coord(s, &os->startx, delta);
243
244 if (present & 0x0004)
245 rdp_in_coord(s, &os->starty, delta);
246
247 if (present & 0x0008)
248 rdp_in_coord(s, &os->endx, delta);
249
250 if (present & 0x0010)
251 rdp_in_coord(s, &os->endy, delta);
252
253 if (present & 0x0020)
254 rdp_in_colour(s, &os->bgcolour);
255
256 if (present & 0x0040)
257 in_uint8(s, os->opcode);
258
259 rdp_parse_pen(s, &os->pen, present >> 7);
260
261 DEBUG("LINE(op=0x%x,sx=%d,sy=%d,dx=%d,dx=%d,fg=0x%x)\n",
262 os->opcode, os->startx, os->starty, os->endx, os->endy,
263 os->pen.colour);
264
265 if (os->opcode < 0x01 || os->opcode > 0x10)
266 {
267 ERROR("bad ROP2 0x%x\n", os->opcode);
268 return;
269 }
270
271 ui_line(os->opcode-1, os->startx, os->starty,
272 os->endx, os->endy, &os->pen);
273 }
274
275 /* Process an opaque rectangle order */
276 static void process_rect(STREAM s, RECT_ORDER *os, uint32 present, BOOL delta)
277 {
278 if (present & 0x01)
279 rdp_in_coord(s, &os->x, delta);
280
281 if (present & 0x02)
282 rdp_in_coord(s, &os->y, delta);
283
284 if (present & 0x04)
285 rdp_in_coord(s, &os->cx, delta);
286
287 if (present & 0x08)
288 rdp_in_coord(s, &os->cy, delta);
289
290 if (present & 0x10)
291 in_uint8(s, os->colour);
292
293 DEBUG("RECT(x=%d,y=%d,cx=%d,cy=%d,fg=0x%x)\n",
294 os->x, os->y, os->cx, os->cy, os->colour);
295
296 ui_rect(os->x, os->y, os->cx, os->cy, os->colour);
297 }
298
299 /* Process a desktop save order */
300 static void process_desksave(STREAM s, DESKSAVE_ORDER *os,
301 uint32 present, BOOL delta)
302 {
303 int width, height;
304
305 if (present & 0x01)
306 in_uint32_le(s, os->offset);
307
308 if (present & 0x02)
309 rdp_in_coord(s, &os->left, delta);
310
311 if (present & 0x04)
312 rdp_in_coord(s, &os->top, delta);
313
314 if (present & 0x08)
315 rdp_in_coord(s, &os->right, delta);
316
317 if (present & 0x10)
318 rdp_in_coord(s, &os->bottom, delta);
319
320 if (present & 0x20)
321 in_uint8(s, os->action);
322
323 DEBUG("DESKSAVE(l=%d,t=%d,r=%d,b=%d,off=%d,op=%d)\n",
324 os->left, os->top, os->right, os->bottom, os->offset,
325 os->action);
326
327 width = os->right - os->left + 1;
328 height = os->bottom - os->top + 1;
329
330 if (os->action == 0)
331 ui_desktop_save(os->offset, os->left, os->top, width, height);
332 else
333 ui_desktop_restore(os->offset, os->left, os->top, width, height);
334 }
335
336 /* Process a memory blt order */
337 static void process_memblt(STREAM s, MEMBLT_ORDER *os,
338 uint32 present, BOOL delta)
339 {
340 HBITMAP bitmap;
341
342 if (present & 0x0001)
343 {
344 in_uint8(s, os->cache_id);
345 in_uint8(s, os->colour_table);
346 }
347
348 if (present & 0x0002)
349 rdp_in_coord(s, &os->x, delta);
350
351 if (present & 0x0004)
352 rdp_in_coord(s, &os->y, delta);
353
354 if (present & 0x0008)
355 rdp_in_coord(s, &os->cx, delta);
356
357 if (present & 0x0010)
358 rdp_in_coord(s, &os->cy, delta);
359
360 if (present & 0x0020)
361 in_uint8(s, os->opcode);
362
363 if (present & 0x0040)
364 rdp_in_coord(s, &os->srcx, delta);
365
366 if (present & 0x0080)
367 rdp_in_coord(s, &os->srcy, delta);
368
369 if (present & 0x0100)
370 in_uint16_le(s, os->cache_idx);
371
372 DEBUG("MEMBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,id=%d,idx=%d)\n",
373 os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id,
374 os->cache_idx);
375
376 bitmap = cache_get_bitmap(os->cache_id, os->cache_idx);
377 if (bitmap == NULL)
378 return;
379
380 ui_memblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy,
381 bitmap, os->srcx, os->srcy);
382 }
383
384 /* Process a 3-way blt order */
385 static void process_triblt(STREAM s, TRIBLT_ORDER *os,
386 uint32 present, BOOL delta)
387 {
388 HBITMAP bitmap;
389
390 if (present & 0x000001)
391 {
392 in_uint8(s, os->cache_id);
393 in_uint8(s, os->colour_table);
394 }
395
396 if (present & 0x000002)
397 rdp_in_coord(s, &os->x, delta);
398
399 if (present & 0x000004)
400 rdp_in_coord(s, &os->y, delta);
401
402 if (present & 0x000008)
403 rdp_in_coord(s, &os->cx, delta);
404
405 if (present & 0x000010)
406 rdp_in_coord(s, &os->cy, delta);
407
408 if (present & 0x000020)
409 in_uint8(s, os->opcode);
410
411 if (present & 0x000040)
412 rdp_in_coord(s, &os->srcx, delta);
413
414 if (present & 0x000080)
415 rdp_in_coord(s, &os->srcy, delta);
416
417 if (present & 0x000100)
418 rdp_in_colour(s, &os->bgcolour);
419
420 if (present & 0x000200)
421 rdp_in_colour(s, &os->fgcolour);
422
423 rdp_parse_brush(s, &os->brush, present >> 10);
424
425 if (present & 0x008000)
426 in_uint16_le(s, os->cache_idx);
427
428 if (present & 0x010000)
429 in_uint16_le(s, os->unknown);
430
431 DEBUG("TRIBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,id=%d,idx=%d,bs=%d,bg=0x%x,fg=0x%x)\n",
432 os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id,
433 os->cache_idx, os->brush.style, os->bgcolour, os->fgcolour);
434
435 bitmap = cache_get_bitmap(os->cache_id, os->cache_idx);
436 if (bitmap == NULL)
437 return;
438
439 ui_triblt(os->opcode, os->x, os->y, os->cx, os->cy,
440 bitmap, os->srcx, os->srcy,
441 &os->brush, os->bgcolour, os->fgcolour);
442 }
443
444 /* Parse a delta co-ordinate in polyline order form */
445 static int parse_delta(uint8 *buffer, int *offset)
446 {
447 int value = buffer[(*offset)++];
448 int two_byte = value & 0x80;
449
450 if (value & 0x40) /* sign bit */
451 value |= ~0x3f;
452 else
453 value &= 0x3f;
454
455 if (two_byte)
456 value = (value << 8) | buffer[(*offset)++];
457
458 return value;
459 }
460
461 /* Process a polyline order */
462 static void process_polyline(STREAM s, POLYLINE_ORDER *os,
463 uint32 present, BOOL delta)
464 {
465 int index, line, data;
466 int x, y, xfrom, yfrom;
467 uint8 flags = 0;
468 PEN pen;
469
470 if (present & 0x01)
471 rdp_in_coord(s, &os->x, delta);
472
473 if (present & 0x02)
474 rdp_in_coord(s, &os->y, delta);
475
476 if (present & 0x04)
477 in_uint8(s, os->flags);
478
479 if (present & 0x10)
480 rdp_in_colour(s, &os->fgcolour);
481
482 if (present & 0x20)
483 in_uint8(s, os->lines);
484
485 if (present & 0x40)
486 {
487 in_uint8(s, os->datasize);
488 in_uint8a(s, os->data, os->datasize);
489 }
490
491 DEBUG("POLYLINE(x=%d,y=%d,fl=0x%x,fg=0x%x,n=%d,sz=%d)\n",
492 os->x, os->y, os->flags, os->fgcolour, os->lines, os->datasize);
493
494 DEBUG("Data: ");
495
496 for (index = 0; index < os->datasize; index++)
497 DEBUG("%02x ", os->data[index]);
498
499 DEBUG("\n");
500
501 x = os->x;
502 y = os->y;
503 pen.style = pen.width = 0;
504 pen.colour = os->fgcolour;
505
506 index = 0;
507 data = ((os->lines - 1) / 4) + 1;
508 for (line = 0; (line < os->lines) && (data < os->datasize); line++)
509 {
510 xfrom = x;
511 yfrom = y;
512
513 if (line % 4 == 0)
514 flags = os->data[index++];
515
516 if ((flags & 0xc0) == 0)
517 flags |= 0xc0; /* none = both */
518
519 if (flags & 0x40)
520 x += parse_delta(os->data, &data);
521
522 if (flags & 0x80)
523 y += parse_delta(os->data, &data);
524
525 ui_line(ROP2_COPY, xfrom, yfrom, x, y, &pen);
526
527 flags <<= 2;
528 }
529 }
530
531 /* Process a text order */
532 static void process_text2(STREAM s, TEXT2_ORDER *os, uint32 present, BOOL delta)
533 {
534 DATABLOB *entry;
535 int i;
536
537 if (present & 0x000001)
538 in_uint8(s, os->font);
539
540 if (present & 0x000002)
541 in_uint8(s, os->flags);
542
543 if (present & 0x000004)
544 in_uint8(s, os->unknown);
545
546 if (present & 0x000008)
547 in_uint8(s, os->mixmode);
548
549 if (present & 0x000010)
550 rdp_in_colour(s, &os->fgcolour);
551
552 if (present & 0x000020)
553 rdp_in_colour(s, &os->bgcolour);
554
555 if (present & 0x000040)
556 in_uint16_le(s, os->clipleft);
557
558 if (present & 0x000080)
559 in_uint16_le(s, os->cliptop);
560
561 if (present & 0x000100)
562 in_uint16_le(s, os->clipright);
563
564 if (present & 0x000200)
565 in_uint16_le(s, os->clipbottom);
566
567 if (present & 0x000400)
568 in_uint16_le(s, os->boxleft);
569
570 if (present & 0x000800)
571 in_uint16_le(s, os->boxtop);
572
573 if (present & 0x001000)
574 in_uint16_le(s, os->boxright);
575
576 if (present & 0x002000)
577 in_uint16_le(s, os->boxbottom);
578
579 if (present & 0x080000)
580 in_uint16_le(s, os->x);
581
582 if (present & 0x100000)
583 in_uint16_le(s, os->y);
584
585 if (present & 0x200000)
586 {
587 in_uint8(s, os->length);
588 in_uint8a(s, os->text, os->length);
589 }
590
591 DEBUG("TEXT2(x=%d,y=%d,cl=%d,ct=%d,cr=%d,cb=%d,bl=%d,bt=%d,bb=%d,br=%d,fg=0x%x,bg=0x%x,font=%d,fl=0x%x,mix=%d,unk=0x%x,n=%d)\n",
592 os->x, os->y, os->clipleft, os->cliptop, os->clipright,
593 os->clipbottom, os->boxleft, os->boxtop, os->boxright,
594 os->boxbottom, os->fgcolour, os->bgcolour, os->font,
595 os->flags, os->mixmode, os->unknown, os->length);
596
597 DEBUG("Text: ");
598
599 for (i = 0; i < os->length; i++)
600 DEBUG("%02x ", os->text[i]);
601
602 DEBUG("\n");
603
604 /* Process special cache strings */
605 if ((os->length >= 2) && (os->text[0] == 0xfe))
606 {
607 entry = cache_get_text(os->text[1]);
608
609 if (entry == NULL)
610 return;
611
612 memcpy(os->text, entry->data, entry->size);
613 os->length = entry->size;
614 }
615 else if ((os->length >= 3) && (os->text[os->length-3] == 0xff))
616 {
617 os->length -= 3;
618 cache_put_text(os->text[os->length+1], os->text, os->length);
619 }
620
621 ui_draw_text(os->font, os->flags, os->mixmode, os->x, os->y,
622 os->clipleft, os->cliptop,
623 os->clipright - os->clipleft,
624 os->clipbottom - os->cliptop,
625 os->boxleft, os->boxtop,
626 os->boxright - os->boxleft,
627 os->boxbottom - os->boxtop,
628 os->bgcolour, os->fgcolour, os->text, os->length);
629 }
630
631 /* Process a raw bitmap cache order */
632 static void process_raw_bmpcache(STREAM s)
633 {
634 HBITMAP bitmap;
635 uint16 cache_idx, bufsize;
636 uint8 cache_id, width, height, bpp;
637 uint8 *data;
638
639 in_uint8(s, cache_id);
640 in_uint8s(s, 1); /* pad */
641 in_uint8(s, width);
642 in_uint8(s, height);
643 in_uint8(s, bpp);
644 in_uint16_le(s, bufsize);
645 in_uint16_le(s, cache_idx);
646 in_uint8p(s, data, bufsize);
647
648 DEBUG("RAW_BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n",
649 width, height, cache_id, cache_idx);
650
651 bitmap = ui_create_bitmap(width, height, data);
652 cache_put_bitmap(cache_id, cache_idx, bitmap);
653 }
654
655 /* Process a bitmap cache order */
656 static void process_bmpcache(STREAM s)
657 {
658 HBITMAP bitmap;
659 uint16 cache_idx, size;
660 uint8 cache_id, width, height, bpp;
661 uint8 *data, *bmpdata;
662
663 in_uint8(s, cache_id);
664 in_uint8s(s, 1); /* pad */
665 in_uint8(s, width);
666 in_uint8(s, height);
667 in_uint8(s, bpp);
668 in_uint8s(s, 2); /* bufsize */
669 in_uint16_le(s, cache_idx);
670 in_uint8s(s, 2); /* pad */
671 in_uint16_le(s, size);
672 in_uint8s(s, 4); /* row_size, final_size */
673 in_uint8p(s, data, size);
674
675 DEBUG("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n",
676 width, height, cache_id, cache_idx);
677
678 bmpdata = xmalloc(width * height);
679
680 if (bitmap_decompress(bmpdata, width, height, data, size))
681 {
682 bitmap = ui_create_bitmap(width, height, bmpdata);
683 cache_put_bitmap(cache_id, cache_idx, bitmap);
684 }
685
686 xfree(bmpdata);
687 }
688
689 /* Process a colourmap cache order */
690 static void process_colcache(STREAM s)
691 {
692 COLOURENTRY *entry;
693 COLOURMAP map;
694 HCOLOURMAP hmap;
695 uint8 cache_id;
696 int i;
697
698 in_uint8(s, cache_id);
699 in_uint16_le(s, map.ncolours);
700
701 map.colours = xmalloc(3 * map.ncolours);
702
703 for (i = 0; i < map.ncolours; i++)
704 {
705 entry = &map.colours[i];
706 in_uint8(s, entry->blue);
707 in_uint8(s, entry->green);
708 in_uint8(s, entry->red);
709 in_uint8s(s, 1); /* pad */
710 }
711
712 DEBUG("COLCACHE(id=%d,n=%d)\n", cache_id, map.ncolours);
713
714 hmap = ui_create_colourmap(&map);
715 ui_set_colourmap(hmap);
716
717 xfree(map.colours);
718 }
719
720 /* Process a font cache order */
721 static void process_fontcache(STREAM s)
722 {
723 HGLYPH bitmap;
724 uint8 font, nglyphs;
725 uint16 character, offset, baseline, width, height;
726 uint8 *data, *rev_data, in, out;
727 int i, j, datasize;
728
729 in_uint8(s, font);
730 in_uint8(s, nglyphs);
731
732 DEBUG("FONTCACHE(font=%d,n=%d)\n", font, nglyphs);
733
734 for (i = 0; i < nglyphs; i++)
735 {
736 in_uint16_le(s, character);
737 in_uint16_le(s, offset);
738 in_uint16_le(s, baseline);
739 in_uint16_le(s, width);
740 in_uint16_le(s, height);
741
742 datasize = (height * ((width + 7) / 8) + 3) & ~3;
743 in_uint8p(s, data, datasize);
744
745 bitmap = ui_create_glyph(width, height, data);
746 cache_put_font(font, character, offset, baseline,
747 width, height, bitmap);
748 }
749 }
750
751 /* Process a secondary order */
752 static void process_secondary_order(STREAM s)
753 {
754 uint16 length;
755 uint8 type;
756 uint8 *next_order;
757
758 in_uint16_le(s, length);
759 in_uint8s(s, 2); /* flags */
760 in_uint8(s, type);
761
762 next_order = s->p + length + 7;
763
764 switch (type)
765 {
766 case RDP_ORDER_RAW_BMPCACHE:
767 process_raw_bmpcache(s);
768 break;
769
770 case RDP_ORDER_COLCACHE:
771 process_colcache(s);
772 break;
773
774 case RDP_ORDER_BMPCACHE:
775 process_bmpcache(s);
776 break;
777
778 case RDP_ORDER_FONTCACHE:
779 process_fontcache(s);
780 break;
781
782 default:
783 NOTIMP("secondary order %d\n", type);
784 }
785
786 s->p = next_order;
787 }
788
789 /* Process an order PDU */
790 void process_orders(STREAM s)
791 {
792 RDP_ORDER_STATE *os = &order_state;
793 uint32 present;
794 uint16 num_orders;
795 uint8 order_flags;
796 int size, processed = 0;
797 BOOL delta;
798
799 in_uint8s(s, 2); /* pad */
800 in_uint16_le(s, num_orders);
801 in_uint8s(s, 2); /* pad */
802
803 while (processed < num_orders)
804 {
805 in_uint8(s, order_flags);
806
807 if (!(order_flags & RDP_ORDER_STANDARD))
808 {
809 ERROR("order parsing failed\n");
810 break;
811 }
812
813 if (order_flags & RDP_ORDER_SECONDARY)
814 {
815 process_secondary_order(s);
816 }
817 else
818 {
819 if (order_flags & RDP_ORDER_CHANGE)
820 {
821 in_uint8(s, os->order_type);
822 }
823
824 switch (os->order_type)
825 {
826 case RDP_ORDER_TRIBLT:
827 case RDP_ORDER_TEXT2:
828 size = 3;
829 break;
830
831 case RDP_ORDER_PATBLT:
832 case RDP_ORDER_MEMBLT:
833 case RDP_ORDER_LINE:
834 size = 2;
835 break;
836
837 default:
838 size = 1;
839 }
840
841 rdp_in_present(s, &present, order_flags, size);
842
843 if (order_flags & RDP_ORDER_BOUNDS)
844 {
845 if (!(order_flags & RDP_ORDER_LASTBOUNDS))
846 rdp_parse_bounds(s, &os->bounds);
847
848 ui_set_clip(os->bounds.left,
849 os->bounds.top,
850 os->bounds.right - os->bounds.left + 1,
851 os->bounds.bottom - os->bounds.top + 1);
852 }
853
854 delta = order_flags & RDP_ORDER_DELTA;
855
856 switch (os->order_type)
857 {
858 case RDP_ORDER_DESTBLT:
859 process_destblt(s, &os->destblt,
860 present, delta);
861 break;
862
863 case RDP_ORDER_PATBLT:
864 process_patblt(s, &os->patblt,
865 present, delta);
866 break;
867
868 case RDP_ORDER_SCREENBLT:
869 process_screenblt(s, &os->screenblt,
870 present, delta);
871 break;
872
873 case RDP_ORDER_LINE:
874 process_line(s, &os->line,
875 present, delta);
876 break;
877
878 case RDP_ORDER_RECT:
879 process_rect(s, &os->rect,
880 present, delta);
881 break;
882
883 case RDP_ORDER_DESKSAVE:
884 process_desksave(s, &os->desksave,
885 present, delta);
886 break;
887
888 case RDP_ORDER_MEMBLT:
889 process_memblt(s, &os->memblt,
890 present, delta);
891 break;
892
893 case RDP_ORDER_TRIBLT:
894 process_triblt(s, &os->triblt,
895 present, delta);
896 break;
897
898 case RDP_ORDER_POLYLINE:
899 process_polyline(s, &os->polyline,
900 present, delta);
901 break;
902
903 case RDP_ORDER_TEXT2:
904 process_text2(s, &os->text2,
905 present, delta);
906 break;
907
908 default:
909 NOTIMP("order %d\n", os->order_type);
910 return;
911 }
912
913 if (order_flags & RDP_ORDER_BOUNDS)
914 ui_reset_clip();
915 }
916
917 processed++;
918 }
919
920 if (s->p != next_packet)
921 WARN("%d bytes remaining\n", (int)(next_packet - s->p));
922 }
923
924 /* Reset order state */
925 void reset_order_state()
926 {
927 memset(&order_state, 0, sizeof(order_state));
928 }
929

  ViewVC Help
Powered by ViewVC 1.1.26