/[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 30 - (show annotations)
Fri Sep 14 13:51:38 2001 UTC (22 years, 8 months ago) by matty
File MIME type: text/plain
File size: 20141 byte(s)
Portability fixes, including elimination of variable argument macros.
Rudimentary configure script.
Miscellaneous cleanups.

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

  ViewVC Help
Powered by ViewVC 1.1.26