FreeRDP
Loading...
Searching...
No Matches
message.c
1
22#include <freerdp/config.h>
23
24#include <winpr/assert.h>
25
26#include "rdp.h"
27#include "message.h"
28#include "transport.h"
29
30#include <freerdp/log.h>
31#include <freerdp/freerdp.h>
32
33#include <winpr/crt.h>
34#include <winpr/stream.h>
35#include <winpr/collections.h>
36
37#include "../cache/pointer.h"
38#include "../cache/bitmap.h"
39#include "../cache/palette.h"
40#include "../cache/glyph.h"
41#include "../cache/brush.h"
42#include "../cache/cache.h"
43
44#define TAG FREERDP_TAG("core.message")
45
46/* Update */
47
48static BOOL update_message_BeginPaint(rdpContext* context)
49{
50 rdp_update_internal* up = nullptr;
51
52 if (!context || !context->update)
53 return FALSE;
54
55 up = update_cast(context->update);
56 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, BeginPaint), nullptr,
57 nullptr);
58}
59
60static BOOL update_message_EndPaint(rdpContext* context)
61{
62 rdp_update_internal* up = nullptr;
63
64 if (!context || !context->update)
65 return FALSE;
66
67 up = update_cast(context->update);
68 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, EndPaint), nullptr,
69 nullptr);
70}
71
72static BOOL update_message_SetBounds(rdpContext* context, const rdpBounds* bounds)
73{
74 rdpBounds* wParam = nullptr;
75 rdp_update_internal* up = nullptr;
76
77 if (!context || !context->update)
78 return FALSE;
79
80 if (bounds)
81 {
82 wParam = (rdpBounds*)malloc(sizeof(rdpBounds));
83
84 if (!wParam)
85 return FALSE;
86
87 CopyMemory(wParam, bounds, sizeof(rdpBounds));
88 }
89
90 up = update_cast(context->update);
91 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, SetBounds),
92 (void*)wParam, nullptr);
93}
94
95static BOOL update_message_Synchronize(rdpContext* context)
96{
97 rdp_update_internal* up = nullptr;
98
99 if (!context || !context->update)
100 return FALSE;
101
102 up = update_cast(context->update);
103 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, Synchronize), nullptr,
104 nullptr);
105}
106
107static BOOL update_message_DesktopResize(rdpContext* context)
108{
109 rdp_update_internal* up = nullptr;
110
111 if (!context || !context->update)
112 return FALSE;
113
114 up = update_cast(context->update);
115 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, DesktopResize),
116 nullptr, nullptr);
117}
118
119static BOOL update_message_BitmapUpdate(rdpContext* context, const BITMAP_UPDATE* bitmap)
120{
121 BITMAP_UPDATE* wParam = nullptr;
122 rdp_update_internal* up = nullptr;
123
124 if (!context || !context->update || !bitmap)
125 return FALSE;
126
127 wParam = copy_bitmap_update(context, bitmap);
128
129 if (!wParam)
130 return FALSE;
131
132 up = update_cast(context->update);
133 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, BitmapUpdate),
134 (void*)wParam, nullptr);
135}
136
137static BOOL update_message_Palette(rdpContext* context, const PALETTE_UPDATE* palette)
138{
139 PALETTE_UPDATE* wParam = nullptr;
140 rdp_update_internal* up = nullptr;
141
142 if (!context || !context->update || !palette)
143 return FALSE;
144
145 wParam = copy_palette_update(context, palette);
146
147 if (!wParam)
148 return FALSE;
149
150 up = update_cast(context->update);
151 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, Palette),
152 (void*)wParam, nullptr);
153}
154
155static BOOL update_message_PlaySound(rdpContext* context, const PLAY_SOUND_UPDATE* playSound)
156{
157 PLAY_SOUND_UPDATE* wParam = nullptr;
158 rdp_update_internal* up = nullptr;
159
160 if (!context || !context->update || !playSound)
161 return FALSE;
162
163 wParam = (PLAY_SOUND_UPDATE*)malloc(sizeof(PLAY_SOUND_UPDATE));
164
165 if (!wParam)
166 return FALSE;
167
168 CopyMemory(wParam, playSound, sizeof(PLAY_SOUND_UPDATE));
169
170 up = update_cast(context->update);
171 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, PlaySound),
172 (void*)wParam, nullptr);
173}
174
175static BOOL update_message_SetKeyboardIndicators(rdpContext* context, UINT16 led_flags)
176{
177 rdp_update_internal* up = nullptr;
178
179 if (!context || !context->update)
180 return FALSE;
181
182 up = update_cast(context->update);
183 return MessageQueue_Post(up->queue, (void*)context,
184 MakeMessageId(Update, SetKeyboardIndicators), (void*)(size_t)led_flags,
185 nullptr);
186}
187
188static BOOL update_message_SetKeyboardImeStatus(rdpContext* context, UINT16 imeId, UINT32 imeState,
189 UINT32 imeConvMode)
190{
191 rdp_update_internal* up = nullptr;
192
193 if (!context || !context->update)
194 return FALSE;
195
196 up = update_cast(context->update);
197 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, SetKeyboardImeStatus),
198 (void*)(size_t)((((UINT32)imeId << 16UL) & 0xFFFF0000) | imeState),
199 (void*)(size_t)imeConvMode);
200}
201
202static BOOL update_message_RefreshRect(rdpContext* context, BYTE count, const RECTANGLE_16* areas)
203{
204 RECTANGLE_16* lParam = nullptr;
205 rdp_update_internal* up = nullptr;
206
207 if (!context || !context->update || !areas)
208 return FALSE;
209
210 lParam = (RECTANGLE_16*)calloc(count, sizeof(RECTANGLE_16));
211
212 if (!lParam)
213 return FALSE;
214
215 CopyMemory(lParam, areas, sizeof(RECTANGLE_16) * count);
216
217 up = update_cast(context->update);
218 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, RefreshRect),
219 (void*)(size_t)count, (void*)lParam);
220}
221
222static BOOL update_message_SuppressOutput(rdpContext* context, BYTE allow, const RECTANGLE_16* area)
223{
224 RECTANGLE_16* lParam = nullptr;
225 rdp_update_internal* up = nullptr;
226
227 if (!context || !context->update)
228 return FALSE;
229
230 if (area)
231 {
232 lParam = (RECTANGLE_16*)malloc(sizeof(RECTANGLE_16));
233
234 if (!lParam)
235 return FALSE;
236
237 CopyMemory(lParam, area, sizeof(RECTANGLE_16));
238 }
239
240 up = update_cast(context->update);
241 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, SuppressOutput),
242 (void*)(size_t)allow, (void*)lParam);
243}
244
245static BOOL update_message_SurfaceCommand(rdpContext* context, wStream* s)
246{
247 wStream* wParam = nullptr;
248 rdp_update_internal* up = nullptr;
249
250 if (!context || !context->update || !s)
251 return FALSE;
252
253 wParam = Stream_New(nullptr, Stream_GetRemainingLength(s));
254
255 if (!wParam)
256 return FALSE;
257
258 Stream_Copy(s, wParam, Stream_GetRemainingLength(s));
259 Stream_ResetPosition(wParam);
260
261 up = update_cast(context->update);
262 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, SurfaceCommand),
263 (void*)wParam, nullptr);
264}
265
266static BOOL update_message_SurfaceBits(rdpContext* context,
267 const SURFACE_BITS_COMMAND* surfaceBitsCommand)
268{
269 SURFACE_BITS_COMMAND* wParam = nullptr;
270 rdp_update_internal* up = nullptr;
271
272 if (!context || !context->update || !surfaceBitsCommand)
273 return FALSE;
274
275 wParam = copy_surface_bits_command(context, surfaceBitsCommand);
276
277 if (!wParam)
278 return FALSE;
279
280 up = update_cast(context->update);
281 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, SurfaceBits),
282 (void*)wParam, nullptr);
283}
284
285static BOOL update_message_SurfaceFrameMarker(rdpContext* context,
286 const SURFACE_FRAME_MARKER* surfaceFrameMarker)
287{
288 SURFACE_FRAME_MARKER* wParam = nullptr;
289 rdp_update_internal* up = nullptr;
290
291 if (!context || !context->update || !surfaceFrameMarker)
292 return FALSE;
293
294 wParam = (SURFACE_FRAME_MARKER*)malloc(sizeof(SURFACE_FRAME_MARKER));
295
296 if (!wParam)
297 return FALSE;
298
299 CopyMemory(wParam, surfaceFrameMarker, sizeof(SURFACE_FRAME_MARKER));
300
301 up = update_cast(context->update);
302 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(Update, SurfaceFrameMarker),
303 (void*)wParam, nullptr);
304}
305
306static BOOL update_message_SurfaceFrameAcknowledge(rdpContext* context, UINT32 frameId)
307{
308 rdp_update_internal* up = nullptr;
309
310 if (!context || !context->update)
311 return FALSE;
312
313 up = update_cast(context->update);
314 return MessageQueue_Post(up->queue, (void*)context,
315 MakeMessageId(Update, SurfaceFrameAcknowledge), (void*)(size_t)frameId,
316 nullptr);
317}
318
319/* Primary Update */
320
321static BOOL update_message_DstBlt(rdpContext* context, const DSTBLT_ORDER* dstBlt)
322{
323 DSTBLT_ORDER* wParam = nullptr;
324 rdp_update_internal* up = nullptr;
325
326 if (!context || !context->update || !dstBlt)
327 return FALSE;
328
329 wParam = (DSTBLT_ORDER*)malloc(sizeof(DSTBLT_ORDER));
330
331 if (!wParam)
332 return FALSE;
333
334 CopyMemory(wParam, dstBlt, sizeof(DSTBLT_ORDER));
335
336 up = update_cast(context->update);
337 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, DstBlt),
338 (void*)wParam, nullptr);
339}
340
341static BOOL update_message_PatBlt(rdpContext* context, PATBLT_ORDER* patBlt)
342{
343 PATBLT_ORDER* wParam = nullptr;
344 rdp_update_internal* up = nullptr;
345
346 if (!context || !context->update || !patBlt)
347 return FALSE;
348
349 wParam = (PATBLT_ORDER*)malloc(sizeof(PATBLT_ORDER));
350
351 if (!wParam)
352 return FALSE;
353
354 CopyMemory(wParam, patBlt, sizeof(PATBLT_ORDER));
355 wParam->brush.data = (BYTE*)wParam->brush.p8x8;
356
357 up = update_cast(context->update);
358 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, PatBlt),
359 (void*)wParam, nullptr);
360}
361
362static BOOL update_message_ScrBlt(rdpContext* context, const SCRBLT_ORDER* scrBlt)
363{
364 SCRBLT_ORDER* wParam = nullptr;
365 rdp_update_internal* up = nullptr;
366
367 if (!context || !context->update || !scrBlt)
368 return FALSE;
369
370 wParam = (SCRBLT_ORDER*)malloc(sizeof(SCRBLT_ORDER));
371
372 if (!wParam)
373 return FALSE;
374
375 CopyMemory(wParam, scrBlt, sizeof(SCRBLT_ORDER));
376
377 up = update_cast(context->update);
378 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, ScrBlt),
379 (void*)wParam, nullptr);
380}
381
382static BOOL update_message_OpaqueRect(rdpContext* context, const OPAQUE_RECT_ORDER* opaqueRect)
383{
384 OPAQUE_RECT_ORDER* wParam = nullptr;
385 rdp_update_internal* up = nullptr;
386
387 if (!context || !context->update || !opaqueRect)
388 return FALSE;
389
390 wParam = (OPAQUE_RECT_ORDER*)malloc(sizeof(OPAQUE_RECT_ORDER));
391
392 if (!wParam)
393 return FALSE;
394
395 CopyMemory(wParam, opaqueRect, sizeof(OPAQUE_RECT_ORDER));
396
397 up = update_cast(context->update);
398 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, OpaqueRect),
399 (void*)wParam, nullptr);
400}
401
402static BOOL update_message_DrawNineGrid(rdpContext* context,
403 const DRAW_NINE_GRID_ORDER* drawNineGrid)
404{
405 DRAW_NINE_GRID_ORDER* wParam = nullptr;
406 rdp_update_internal* up = nullptr;
407
408 if (!context || !context->update || !drawNineGrid)
409 return FALSE;
410
411 wParam = (DRAW_NINE_GRID_ORDER*)malloc(sizeof(DRAW_NINE_GRID_ORDER));
412
413 if (!wParam)
414 return FALSE;
415
416 CopyMemory(wParam, drawNineGrid, sizeof(DRAW_NINE_GRID_ORDER));
417
418 up = update_cast(context->update);
419 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, DrawNineGrid),
420 (void*)wParam, nullptr);
421}
422
423static BOOL update_message_MultiDstBlt(rdpContext* context, const MULTI_DSTBLT_ORDER* multiDstBlt)
424{
425 MULTI_DSTBLT_ORDER* wParam = nullptr;
426 rdp_update_internal* up = nullptr;
427
428 if (!context || !context->update || !multiDstBlt)
429 return FALSE;
430
431 wParam = (MULTI_DSTBLT_ORDER*)malloc(sizeof(MULTI_DSTBLT_ORDER));
432
433 if (!wParam)
434 return FALSE;
435
436 CopyMemory(wParam, multiDstBlt, sizeof(MULTI_DSTBLT_ORDER));
437
438 up = update_cast(context->update);
439 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, MultiDstBlt),
440 (void*)wParam, nullptr);
441}
442
443static BOOL update_message_MultiPatBlt(rdpContext* context, const MULTI_PATBLT_ORDER* multiPatBlt)
444{
445 MULTI_PATBLT_ORDER* wParam = nullptr;
446 rdp_update_internal* up = nullptr;
447
448 if (!context || !context->update || !multiPatBlt)
449 return FALSE;
450
451 wParam = (MULTI_PATBLT_ORDER*)malloc(sizeof(MULTI_PATBLT_ORDER));
452
453 if (!wParam)
454 return FALSE;
455
456 CopyMemory(wParam, multiPatBlt, sizeof(MULTI_PATBLT_ORDER));
457 wParam->brush.data = (BYTE*)wParam->brush.p8x8;
458
459 up = update_cast(context->update);
460 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, MultiPatBlt),
461 (void*)wParam, nullptr);
462}
463
464static BOOL update_message_MultiScrBlt(rdpContext* context, const MULTI_SCRBLT_ORDER* multiScrBlt)
465{
466 MULTI_SCRBLT_ORDER* wParam = nullptr;
467 rdp_update_internal* up = nullptr;
468
469 if (!context || !context->update || !multiScrBlt)
470 return FALSE;
471
472 wParam = (MULTI_SCRBLT_ORDER*)malloc(sizeof(MULTI_SCRBLT_ORDER));
473
474 if (!wParam)
475 return FALSE;
476
477 CopyMemory(wParam, multiScrBlt, sizeof(MULTI_SCRBLT_ORDER));
478
479 up = update_cast(context->update);
480 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, MultiScrBlt),
481 (void*)wParam, nullptr);
482}
483
484static BOOL update_message_MultiOpaqueRect(rdpContext* context,
485 const MULTI_OPAQUE_RECT_ORDER* multiOpaqueRect)
486{
487 MULTI_OPAQUE_RECT_ORDER* wParam = nullptr;
488 rdp_update_internal* up = nullptr;
489
490 if (!context || !context->update || !multiOpaqueRect)
491 return FALSE;
492
493 wParam = (MULTI_OPAQUE_RECT_ORDER*)malloc(sizeof(MULTI_OPAQUE_RECT_ORDER));
494
495 if (!wParam)
496 return FALSE;
497
498 CopyMemory(wParam, multiOpaqueRect, sizeof(MULTI_OPAQUE_RECT_ORDER));
499
500 up = update_cast(context->update);
501 return MessageQueue_Post(up->queue, (void*)context,
502 MakeMessageId(PrimaryUpdate, MultiOpaqueRect), (void*)wParam, nullptr);
503}
504
505static BOOL update_message_MultiDrawNineGrid(rdpContext* context,
506 const MULTI_DRAW_NINE_GRID_ORDER* multiDrawNineGrid)
507{
508 MULTI_DRAW_NINE_GRID_ORDER* wParam = nullptr;
509 rdp_update_internal* up = nullptr;
510
511 if (!context || !context->update || !multiDrawNineGrid)
512 return FALSE;
513
515
516 if (!wParam)
517 return FALSE;
518
519 CopyMemory(wParam, multiDrawNineGrid, sizeof(MULTI_DRAW_NINE_GRID_ORDER));
520 /* TODO: complete copy */
521
522 up = update_cast(context->update);
523 return MessageQueue_Post(up->queue, (void*)context,
524 MakeMessageId(PrimaryUpdate, MultiDrawNineGrid), (void*)wParam,
525 nullptr);
526}
527
528static BOOL update_message_LineTo(rdpContext* context, const LINE_TO_ORDER* lineTo)
529{
530 LINE_TO_ORDER* wParam = nullptr;
531 rdp_update_internal* up = nullptr;
532
533 if (!context || !context->update || !lineTo)
534 return FALSE;
535
536 wParam = (LINE_TO_ORDER*)malloc(sizeof(LINE_TO_ORDER));
537
538 if (!wParam)
539 return FALSE;
540
541 CopyMemory(wParam, lineTo, sizeof(LINE_TO_ORDER));
542
543 up = update_cast(context->update);
544 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, LineTo),
545 (void*)wParam, nullptr);
546}
547
548static BOOL update_message_Polyline(rdpContext* context, const POLYLINE_ORDER* polyline)
549{
550 POLYLINE_ORDER* wParam = nullptr;
551 rdp_update_internal* up = nullptr;
552
553 if (!context || !context->update || !polyline)
554 return FALSE;
555
556 wParam = (POLYLINE_ORDER*)malloc(sizeof(POLYLINE_ORDER));
557
558 if (!wParam)
559 return FALSE;
560
561 CopyMemory(wParam, polyline, sizeof(POLYLINE_ORDER));
562 wParam->points = (DELTA_POINT*)calloc(wParam->numDeltaEntries, sizeof(DELTA_POINT));
563
564 if (!wParam->points)
565 {
566 free(wParam);
567 return FALSE;
568 }
569
570 CopyMemory(wParam->points, polyline->points, sizeof(DELTA_POINT) * wParam->numDeltaEntries);
571
572 up = update_cast(context->update);
573 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, Polyline),
574 (void*)wParam, nullptr);
575}
576
577static BOOL update_message_MemBlt(rdpContext* context, MEMBLT_ORDER* memBlt)
578{
579 MEMBLT_ORDER* wParam = nullptr;
580 rdp_update_internal* up = nullptr;
581
582 if (!context || !context->update || !memBlt)
583 return FALSE;
584
585 wParam = (MEMBLT_ORDER*)malloc(sizeof(MEMBLT_ORDER));
586
587 if (!wParam)
588 return FALSE;
589
590 CopyMemory(wParam, memBlt, sizeof(MEMBLT_ORDER));
591
592 up = update_cast(context->update);
593 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, MemBlt),
594 (void*)wParam, nullptr);
595}
596
597static BOOL update_message_Mem3Blt(rdpContext* context, MEM3BLT_ORDER* mem3Blt)
598{
599 MEM3BLT_ORDER* wParam = nullptr;
600 rdp_update_internal* up = nullptr;
601
602 if (!context || !context->update || !mem3Blt)
603 return FALSE;
604
605 wParam = (MEM3BLT_ORDER*)malloc(sizeof(MEM3BLT_ORDER));
606
607 if (!wParam)
608 return FALSE;
609
610 CopyMemory(wParam, mem3Blt, sizeof(MEM3BLT_ORDER));
611 wParam->brush.data = (BYTE*)wParam->brush.p8x8;
612
613 up = update_cast(context->update);
614 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, Mem3Blt),
615 (void*)wParam, nullptr);
616}
617
618static BOOL update_message_SaveBitmap(rdpContext* context, const SAVE_BITMAP_ORDER* saveBitmap)
619{
620 SAVE_BITMAP_ORDER* wParam = nullptr;
621 rdp_update_internal* up = nullptr;
622
623 if (!context || !context->update || !saveBitmap)
624 return FALSE;
625
626 wParam = (SAVE_BITMAP_ORDER*)malloc(sizeof(SAVE_BITMAP_ORDER));
627
628 if (!wParam)
629 return FALSE;
630
631 CopyMemory(wParam, saveBitmap, sizeof(SAVE_BITMAP_ORDER));
632
633 up = update_cast(context->update);
634 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, SaveBitmap),
635 (void*)wParam, nullptr);
636}
637
638static BOOL update_message_GlyphIndex(rdpContext* context, GLYPH_INDEX_ORDER* glyphIndex)
639{
640 GLYPH_INDEX_ORDER* wParam = nullptr;
641 rdp_update_internal* up = nullptr;
642
643 if (!context || !context->update || !glyphIndex)
644 return FALSE;
645
646 wParam = (GLYPH_INDEX_ORDER*)malloc(sizeof(GLYPH_INDEX_ORDER));
647
648 if (!wParam)
649 return FALSE;
650
651 CopyMemory(wParam, glyphIndex, sizeof(GLYPH_INDEX_ORDER));
652 wParam->brush.data = (BYTE*)wParam->brush.p8x8;
653
654 up = update_cast(context->update);
655 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, GlyphIndex),
656 (void*)wParam, nullptr);
657}
658
659static BOOL update_message_FastIndex(rdpContext* context, const FAST_INDEX_ORDER* fastIndex)
660{
661 FAST_INDEX_ORDER* wParam = nullptr;
662 rdp_update_internal* up = nullptr;
663
664 if (!context || !context->update || !fastIndex)
665 return FALSE;
666
667 wParam = (FAST_INDEX_ORDER*)malloc(sizeof(FAST_INDEX_ORDER));
668
669 if (!wParam)
670 return FALSE;
671
672 CopyMemory(wParam, fastIndex, sizeof(FAST_INDEX_ORDER));
673
674 up = update_cast(context->update);
675 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, FastIndex),
676 (void*)wParam, nullptr);
677}
678
679static BOOL update_message_FastGlyph(rdpContext* context, const FAST_GLYPH_ORDER* fastGlyph)
680{
681 FAST_GLYPH_ORDER* wParam = nullptr;
682 rdp_update_internal* up = nullptr;
683
684 if (!context || !context->update || !fastGlyph)
685 return FALSE;
686
687 wParam = (FAST_GLYPH_ORDER*)malloc(sizeof(FAST_GLYPH_ORDER));
688
689 if (!wParam)
690 return FALSE;
691
692 CopyMemory(wParam, fastGlyph, sizeof(FAST_GLYPH_ORDER));
693
694 if (wParam->cbData > 1)
695 {
696 wParam->glyphData.aj = (BYTE*)malloc(fastGlyph->glyphData.cb);
697
698 if (!wParam->glyphData.aj)
699 {
700 free(wParam);
701 return FALSE;
702 }
703
704 CopyMemory(wParam->glyphData.aj, fastGlyph->glyphData.aj, fastGlyph->glyphData.cb);
705 }
706 else
707 {
708 wParam->glyphData.aj = nullptr;
709 }
710
711 up = update_cast(context->update);
712 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, FastGlyph),
713 (void*)wParam, nullptr);
714}
715
716static BOOL update_message_PolygonSC(rdpContext* context, const POLYGON_SC_ORDER* polygonSC)
717{
718 if (!context || !context->update || !polygonSC)
719 return FALSE;
720
721 POLYGON_SC_ORDER* wParam = (POLYGON_SC_ORDER*)malloc(sizeof(POLYGON_SC_ORDER));
722
723 if (!wParam)
724 return FALSE;
725
726 *wParam = *polygonSC;
727 if (polygonSC->numPoints > 0)
728 {
729 wParam->points = (DELTA_POINT*)calloc(polygonSC->numPoints, sizeof(DELTA_POINT));
730
731 if (!wParam->points)
732 {
733 free(wParam);
734 return FALSE;
735 }
736
737 CopyMemory(wParam->points, polygonSC->points, sizeof(DELTA_POINT) * wParam->numPoints);
738 }
739
740 rdp_update_internal* up = update_cast(context->update);
741 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, PolygonSC),
742 (void*)wParam, nullptr);
743}
744
745static BOOL update_message_PolygonCB(rdpContext* context, POLYGON_CB_ORDER* polygonCB)
746{
747 if (!context || !context->update || !polygonCB)
748 return FALSE;
749
750 POLYGON_CB_ORDER* wParam = (POLYGON_CB_ORDER*)malloc(sizeof(POLYGON_CB_ORDER));
751
752 if (!wParam)
753 return FALSE;
754
755 *wParam = *polygonCB;
756 if (polygonCB->numPoints > 0)
757 {
758 wParam->points = (DELTA_POINT*)calloc(polygonCB->numPoints, sizeof(DELTA_POINT));
759
760 if (!wParam->points)
761 {
762 free(wParam);
763 return FALSE;
764 }
765
766 CopyMemory(wParam->points, polygonCB->points, sizeof(DELTA_POINT) * wParam->numPoints);
767 }
768
769 wParam->brush.data = (BYTE*)wParam->brush.p8x8;
770
771 rdp_update_internal* up = update_cast(context->update);
772 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, PolygonCB),
773 (void*)wParam, nullptr);
774}
775
776static BOOL update_message_EllipseSC(rdpContext* context, const ELLIPSE_SC_ORDER* ellipseSC)
777{
778 if (!context || !context->update || !ellipseSC)
779 return FALSE;
780
781 ELLIPSE_SC_ORDER* wParam = (ELLIPSE_SC_ORDER*)malloc(sizeof(ELLIPSE_SC_ORDER));
782
783 if (!wParam)
784 return FALSE;
785
786 CopyMemory(wParam, ellipseSC, sizeof(ELLIPSE_SC_ORDER));
787
788 rdp_update_internal* up = update_cast(context->update);
789 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, EllipseSC),
790 (void*)wParam, nullptr);
791}
792
793static BOOL update_message_EllipseCB(rdpContext* context, const ELLIPSE_CB_ORDER* ellipseCB)
794{
795 ELLIPSE_CB_ORDER* wParam = nullptr;
796 rdp_update_internal* up = nullptr;
797
798 if (!context || !context->update || !ellipseCB)
799 return FALSE;
800
801 wParam = (ELLIPSE_CB_ORDER*)malloc(sizeof(ELLIPSE_CB_ORDER));
802
803 if (!wParam)
804 return FALSE;
805
806 CopyMemory(wParam, ellipseCB, sizeof(ELLIPSE_CB_ORDER));
807 wParam->brush.data = (BYTE*)wParam->brush.p8x8;
808
809 up = update_cast(context->update);
810 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PrimaryUpdate, EllipseCB),
811 (void*)wParam, nullptr);
812}
813
814/* Secondary Update */
815
816static BOOL update_message_CacheBitmap(rdpContext* context,
817 const CACHE_BITMAP_ORDER* cacheBitmapOrder)
818{
819 CACHE_BITMAP_ORDER* wParam = nullptr;
820 rdp_update_internal* up = nullptr;
821
822 if (!context || !context->update || !cacheBitmapOrder)
823 return FALSE;
824
825 wParam = copy_cache_bitmap_order(context, cacheBitmapOrder);
826
827 if (!wParam)
828 return FALSE;
829
830 up = update_cast(context->update);
831 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(SecondaryUpdate, CacheBitmap),
832 (void*)wParam, nullptr);
833}
834
835static BOOL update_message_CacheBitmapV2(rdpContext* context,
836 CACHE_BITMAP_V2_ORDER* cacheBitmapV2Order)
837{
838 CACHE_BITMAP_V2_ORDER* wParam = nullptr;
839 rdp_update_internal* up = nullptr;
840
841 if (!context || !context->update || !cacheBitmapV2Order)
842 return FALSE;
843
844 wParam = copy_cache_bitmap_v2_order(context, cacheBitmapV2Order);
845
846 if (!wParam)
847 return FALSE;
848
849 up = update_cast(context->update);
850 return MessageQueue_Post(up->queue, (void*)context,
851 MakeMessageId(SecondaryUpdate, CacheBitmapV2), (void*)wParam, nullptr);
852}
853
854static BOOL update_message_CacheBitmapV3(rdpContext* context,
855 CACHE_BITMAP_V3_ORDER* cacheBitmapV3Order)
856{
857 CACHE_BITMAP_V3_ORDER* wParam = nullptr;
858 rdp_update_internal* up = nullptr;
859
860 if (!context || !context->update || !cacheBitmapV3Order)
861 return FALSE;
862
863 wParam = copy_cache_bitmap_v3_order(context, cacheBitmapV3Order);
864
865 if (!wParam)
866 return FALSE;
867
868 up = update_cast(context->update);
869 return MessageQueue_Post(up->queue, (void*)context,
870 MakeMessageId(SecondaryUpdate, CacheBitmapV3), (void*)wParam, nullptr);
871}
872
873static BOOL update_message_CacheColorTable(rdpContext* context,
874 const CACHE_COLOR_TABLE_ORDER* cacheColorTableOrder)
875{
876 CACHE_COLOR_TABLE_ORDER* wParam = nullptr;
877 rdp_update_internal* up = nullptr;
878
879 if (!context || !context->update || !cacheColorTableOrder)
880 return FALSE;
881
882 wParam = copy_cache_color_table_order(context, cacheColorTableOrder);
883
884 if (!wParam)
885 return FALSE;
886
887 up = update_cast(context->update);
888 return MessageQueue_Post(up->queue, (void*)context,
889 MakeMessageId(SecondaryUpdate, CacheColorTable), (void*)wParam,
890 nullptr);
891}
892
893static BOOL update_message_CacheGlyph(rdpContext* context, const CACHE_GLYPH_ORDER* cacheGlyphOrder)
894{
895 CACHE_GLYPH_ORDER* wParam = nullptr;
896 rdp_update_internal* up = nullptr;
897
898 if (!context || !context->update || !cacheGlyphOrder)
899 return FALSE;
900
901 wParam = copy_cache_glyph_order(context, cacheGlyphOrder);
902
903 if (!wParam)
904 return FALSE;
905
906 up = update_cast(context->update);
907 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(SecondaryUpdate, CacheGlyph),
908 (void*)wParam, nullptr);
909}
910
911static BOOL update_message_CacheGlyphV2(rdpContext* context,
912 const CACHE_GLYPH_V2_ORDER* cacheGlyphV2Order)
913{
914 CACHE_GLYPH_V2_ORDER* wParam = nullptr;
915 rdp_update_internal* up = nullptr;
916
917 if (!context || !context->update || !cacheGlyphV2Order)
918 return FALSE;
919
920 wParam = copy_cache_glyph_v2_order(context, cacheGlyphV2Order);
921
922 if (!wParam)
923 return FALSE;
924
925 up = update_cast(context->update);
926 return MessageQueue_Post(up->queue, (void*)context,
927 MakeMessageId(SecondaryUpdate, CacheGlyphV2), (void*)wParam, nullptr);
928}
929
930static BOOL update_message_CacheBrush(rdpContext* context, const CACHE_BRUSH_ORDER* cacheBrushOrder)
931{
932 CACHE_BRUSH_ORDER* wParam = nullptr;
933 rdp_update_internal* up = nullptr;
934
935 if (!context || !context->update || !cacheBrushOrder)
936 return FALSE;
937
938 wParam = copy_cache_brush_order(context, cacheBrushOrder);
939
940 if (!wParam)
941 return FALSE;
942
943 up = update_cast(context->update);
944 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(SecondaryUpdate, CacheBrush),
945 (void*)wParam, nullptr);
946}
947
948/* Alternate Secondary Update */
949
950static BOOL
951update_message_CreateOffscreenBitmap(rdpContext* context,
952 const CREATE_OFFSCREEN_BITMAP_ORDER* createOffscreenBitmap)
953{
954 CREATE_OFFSCREEN_BITMAP_ORDER* wParam = nullptr;
955 rdp_update_internal* up = nullptr;
956
957 if (!context || !context->update || !createOffscreenBitmap)
958 return FALSE;
959
961
962 if (!wParam)
963 return FALSE;
964
965 CopyMemory(wParam, createOffscreenBitmap, sizeof(CREATE_OFFSCREEN_BITMAP_ORDER));
966 wParam->deleteList.cIndices = createOffscreenBitmap->deleteList.cIndices;
967 wParam->deleteList.sIndices = wParam->deleteList.cIndices;
968 wParam->deleteList.indices = (UINT16*)calloc(wParam->deleteList.cIndices, sizeof(UINT16));
969
970 if (!wParam->deleteList.indices)
971 {
972 free(wParam);
973 return FALSE;
974 }
975
976 CopyMemory(wParam->deleteList.indices, createOffscreenBitmap->deleteList.indices,
977 wParam->deleteList.cIndices);
978
979 up = update_cast(context->update);
980 return MessageQueue_Post(up->queue, (void*)context,
981 MakeMessageId(AltSecUpdate, CreateOffscreenBitmap), (void*)wParam,
982 nullptr);
983}
984
985static BOOL update_message_SwitchSurface(rdpContext* context,
986 const SWITCH_SURFACE_ORDER* switchSurface)
987{
988 SWITCH_SURFACE_ORDER* wParam = nullptr;
989 rdp_update_internal* up = nullptr;
990
991 if (!context || !context->update || !switchSurface)
992 return FALSE;
993
994 wParam = (SWITCH_SURFACE_ORDER*)malloc(sizeof(SWITCH_SURFACE_ORDER));
995
996 if (!wParam)
997 return FALSE;
998
999 CopyMemory(wParam, switchSurface, sizeof(SWITCH_SURFACE_ORDER));
1000
1001 up = update_cast(context->update);
1002 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(AltSecUpdate, SwitchSurface),
1003 (void*)wParam, nullptr);
1004}
1005
1006static BOOL
1007update_message_CreateNineGridBitmap(rdpContext* context,
1008 const CREATE_NINE_GRID_BITMAP_ORDER* createNineGridBitmap)
1009{
1010 CREATE_NINE_GRID_BITMAP_ORDER* wParam = nullptr;
1011 rdp_update_internal* up = nullptr;
1012
1013 if (!context || !context->update || !createNineGridBitmap)
1014 return FALSE;
1015
1017
1018 if (!wParam)
1019 return FALSE;
1020
1021 CopyMemory(wParam, createNineGridBitmap, sizeof(CREATE_NINE_GRID_BITMAP_ORDER));
1022
1023 up = update_cast(context->update);
1024 return MessageQueue_Post(up->queue, (void*)context,
1025 MakeMessageId(AltSecUpdate, CreateNineGridBitmap), (void*)wParam,
1026 nullptr);
1027}
1028
1029static BOOL update_message_FrameMarker(rdpContext* context, const FRAME_MARKER_ORDER* frameMarker)
1030{
1031 FRAME_MARKER_ORDER* wParam = nullptr;
1032 rdp_update_internal* up = nullptr;
1033
1034 if (!context || !context->update || !frameMarker)
1035 return FALSE;
1036
1037 wParam = (FRAME_MARKER_ORDER*)malloc(sizeof(FRAME_MARKER_ORDER));
1038
1039 if (!wParam)
1040 return FALSE;
1041
1042 CopyMemory(wParam, frameMarker, sizeof(FRAME_MARKER_ORDER));
1043
1044 up = update_cast(context->update);
1045 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(AltSecUpdate, FrameMarker),
1046 (void*)wParam, nullptr);
1047}
1048
1049static BOOL update_message_StreamBitmapFirst(rdpContext* context,
1050 const STREAM_BITMAP_FIRST_ORDER* streamBitmapFirst)
1051{
1052 STREAM_BITMAP_FIRST_ORDER* wParam = nullptr;
1053 rdp_update_internal* up = nullptr;
1054
1055 if (!context || !context->update || !streamBitmapFirst)
1056 return FALSE;
1057
1058 wParam = (STREAM_BITMAP_FIRST_ORDER*)malloc(sizeof(STREAM_BITMAP_FIRST_ORDER));
1059
1060 if (!wParam)
1061 return FALSE;
1062
1063 CopyMemory(wParam, streamBitmapFirst, sizeof(STREAM_BITMAP_FIRST_ORDER));
1064 /* TODO: complete copy */
1065
1066 up = update_cast(context->update);
1067 return MessageQueue_Post(up->queue, (void*)context,
1068 MakeMessageId(AltSecUpdate, StreamBitmapFirst), (void*)wParam,
1069 nullptr);
1070}
1071
1072static BOOL update_message_StreamBitmapNext(rdpContext* context,
1073 const STREAM_BITMAP_NEXT_ORDER* streamBitmapNext)
1074{
1075 STREAM_BITMAP_NEXT_ORDER* wParam = nullptr;
1076 rdp_update_internal* up = nullptr;
1077
1078 if (!context || !context->update || !streamBitmapNext)
1079 return FALSE;
1080
1081 wParam = (STREAM_BITMAP_NEXT_ORDER*)malloc(sizeof(STREAM_BITMAP_NEXT_ORDER));
1082
1083 if (!wParam)
1084 return FALSE;
1085
1086 CopyMemory(wParam, streamBitmapNext, sizeof(STREAM_BITMAP_NEXT_ORDER));
1087 /* TODO: complete copy */
1088
1089 up = update_cast(context->update);
1090 return MessageQueue_Post(up->queue, (void*)context,
1091 MakeMessageId(AltSecUpdate, StreamBitmapNext), (void*)wParam, nullptr);
1092}
1093
1094static BOOL update_message_DrawGdiPlusFirst(rdpContext* context,
1095 const DRAW_GDIPLUS_FIRST_ORDER* drawGdiPlusFirst)
1096{
1097 DRAW_GDIPLUS_FIRST_ORDER* wParam = nullptr;
1098 rdp_update_internal* up = nullptr;
1099
1100 if (!context || !context->update || !drawGdiPlusFirst)
1101 return FALSE;
1102
1103 wParam = (DRAW_GDIPLUS_FIRST_ORDER*)malloc(sizeof(DRAW_GDIPLUS_FIRST_ORDER));
1104
1105 if (!wParam)
1106 return FALSE;
1107
1108 CopyMemory(wParam, drawGdiPlusFirst, sizeof(DRAW_GDIPLUS_FIRST_ORDER));
1109 /* TODO: complete copy */
1110 up = update_cast(context->update);
1111 return MessageQueue_Post(up->queue, (void*)context,
1112 MakeMessageId(AltSecUpdate, DrawGdiPlusFirst), (void*)wParam, nullptr);
1113}
1114
1115static BOOL update_message_DrawGdiPlusNext(rdpContext* context,
1116 const DRAW_GDIPLUS_NEXT_ORDER* drawGdiPlusNext)
1117{
1118 DRAW_GDIPLUS_NEXT_ORDER* wParam = nullptr;
1119 rdp_update_internal* up = nullptr;
1120
1121 if (!context || !context->update || !drawGdiPlusNext)
1122 return FALSE;
1123
1124 wParam = (DRAW_GDIPLUS_NEXT_ORDER*)malloc(sizeof(DRAW_GDIPLUS_NEXT_ORDER));
1125
1126 if (!wParam)
1127 return FALSE;
1128
1129 CopyMemory(wParam, drawGdiPlusNext, sizeof(DRAW_GDIPLUS_NEXT_ORDER));
1130 /* TODO: complete copy */
1131
1132 up = update_cast(context->update);
1133 return MessageQueue_Post(up->queue, (void*)context,
1134 MakeMessageId(AltSecUpdate, DrawGdiPlusNext), (void*)wParam, nullptr);
1135}
1136
1137static BOOL update_message_DrawGdiPlusEnd(rdpContext* context,
1138 const DRAW_GDIPLUS_END_ORDER* drawGdiPlusEnd)
1139{
1140 DRAW_GDIPLUS_END_ORDER* wParam = nullptr;
1141 rdp_update_internal* up = nullptr;
1142
1143 if (!context || !context->update || !drawGdiPlusEnd)
1144 return FALSE;
1145
1146 wParam = (DRAW_GDIPLUS_END_ORDER*)malloc(sizeof(DRAW_GDIPLUS_END_ORDER));
1147
1148 if (!wParam)
1149 return FALSE;
1150
1151 CopyMemory(wParam, drawGdiPlusEnd, sizeof(DRAW_GDIPLUS_END_ORDER));
1152 /* TODO: complete copy */
1153
1154 up = update_cast(context->update);
1155 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(AltSecUpdate, DrawGdiPlusEnd),
1156 (void*)wParam, nullptr);
1157}
1158
1159static BOOL
1160update_message_DrawGdiPlusCacheFirst(rdpContext* context,
1161 const DRAW_GDIPLUS_CACHE_FIRST_ORDER* drawGdiPlusCacheFirst)
1162{
1163 DRAW_GDIPLUS_CACHE_FIRST_ORDER* wParam = nullptr;
1164 rdp_update_internal* up = nullptr;
1165
1166 if (!context || !context->update || !drawGdiPlusCacheFirst)
1167 return FALSE;
1168
1170
1171 if (!wParam)
1172 return FALSE;
1173
1174 CopyMemory(wParam, drawGdiPlusCacheFirst, sizeof(DRAW_GDIPLUS_CACHE_FIRST_ORDER));
1175 /* TODO: complete copy */
1176
1177 up = update_cast(context->update);
1178 return MessageQueue_Post(up->queue, (void*)context,
1179 MakeMessageId(AltSecUpdate, DrawGdiPlusCacheFirst), (void*)wParam,
1180 nullptr);
1181}
1182
1183static BOOL
1184update_message_DrawGdiPlusCacheNext(rdpContext* context,
1185 const DRAW_GDIPLUS_CACHE_NEXT_ORDER* drawGdiPlusCacheNext)
1186{
1187 DRAW_GDIPLUS_CACHE_NEXT_ORDER* wParam = nullptr;
1188 rdp_update_internal* up = nullptr;
1189
1190 if (!context || !context->update || !drawGdiPlusCacheNext)
1191 return FALSE;
1192
1194
1195 if (!wParam)
1196 return FALSE;
1197
1198 CopyMemory(wParam, drawGdiPlusCacheNext, sizeof(DRAW_GDIPLUS_CACHE_NEXT_ORDER));
1199 /* TODO: complete copy */
1200
1201 up = update_cast(context->update);
1202 return MessageQueue_Post(up->queue, (void*)context,
1203 MakeMessageId(AltSecUpdate, DrawGdiPlusCacheNext), (void*)wParam,
1204 nullptr);
1205}
1206
1207static BOOL
1208update_message_DrawGdiPlusCacheEnd(rdpContext* context,
1209 const DRAW_GDIPLUS_CACHE_END_ORDER* drawGdiPlusCacheEnd)
1210{
1211 DRAW_GDIPLUS_CACHE_END_ORDER* wParam = nullptr;
1212 rdp_update_internal* up = nullptr;
1213
1214 if (!context || !context->update || !drawGdiPlusCacheEnd)
1215 return FALSE;
1216
1218
1219 if (!wParam)
1220 return FALSE;
1221
1222 CopyMemory(wParam, drawGdiPlusCacheEnd, sizeof(DRAW_GDIPLUS_CACHE_END_ORDER));
1223 /* TODO: complete copy */
1224
1225 up = update_cast(context->update);
1226 return MessageQueue_Post(up->queue, (void*)context,
1227 MakeMessageId(AltSecUpdate, DrawGdiPlusCacheEnd), (void*)wParam,
1228 nullptr);
1229}
1230
1231/* Window Update */
1232static RAIL_UNICODE_STRING rail_unicode_string_clone(const RAIL_UNICODE_STRING* str)
1233{
1234 WINPR_ASSERT(str);
1235 WINPR_ASSERT(((str->length == 0) && (str->string == nullptr)) ||
1236 (str->length == _wcsnlen(str->string, str->length)));
1237 RAIL_UNICODE_STRING clone = { .string = wcsndup(str->string, str->length),
1238 .length = str->length };
1239 return clone;
1240}
1241
1242static void window_state_order_free(WINDOW_STATE_ORDER* order)
1243{
1244 if (!order)
1245 return;
1246 free(order->windowRects);
1247 free(order->visibilityRects);
1248 rail_unicode_string_free(&order->titleInfo);
1249 rail_unicode_string_free(&order->OverlayDescription);
1250
1251 free(order);
1252}
1253
1254static WINDOW_STATE_ORDER* window_state_order_clone(const WINDOW_STATE_ORDER* order)
1255{
1256 WINDOW_STATE_ORDER* clone = calloc(1, sizeof(WINDOW_STATE_ORDER));
1257 if (!clone)
1258 return nullptr;
1259 *clone = *order;
1260
1261 clone->titleInfo = rail_unicode_string_clone(&order->titleInfo);
1262 clone->OverlayDescription = rail_unicode_string_clone(&order->OverlayDescription);
1263 clone->windowRects = rectangles_clone(order->windowRects, order->numWindowRects);
1264 clone->visibilityRects = rectangles_clone(order->visibilityRects, order->numVisibilityRects);
1265 if (!clone->windowRects || !clone->visibilityRects ||
1266 (!clone->titleInfo.string && (clone->titleInfo.length > 0)) ||
1267 (!clone->OverlayDescription.string && (clone->OverlayDescription.length > 0)))
1268 {
1269 window_state_order_free(clone);
1270 return nullptr;
1271 }
1272 return clone;
1273}
1274
1275static BOOL update_message_WindowCreate(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
1276 const WINDOW_STATE_ORDER* windowState)
1277{
1278 if (!context || !context->update || !orderInfo || !windowState)
1279 return FALSE;
1280
1281 WINDOW_ORDER_INFO* wParam = (WINDOW_ORDER_INFO*)malloc(sizeof(WINDOW_ORDER_INFO));
1282
1283 if (!wParam)
1284 return FALSE;
1285
1286 *wParam = *orderInfo;
1287
1288 WINDOW_STATE_ORDER* lParam = window_state_order_clone(windowState);
1289
1290 if (!lParam)
1291 {
1292 free(wParam);
1293 return FALSE;
1294 }
1295
1296 rdp_update_internal* up = update_cast(context->update);
1297 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(WindowUpdate, WindowCreate),
1298 (void*)wParam, (void*)lParam);
1299}
1300
1301static BOOL update_message_WindowUpdate(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
1302 const WINDOW_STATE_ORDER* windowState)
1303{
1304 if (!context || !context->update || !orderInfo || !windowState)
1305 return FALSE;
1306
1307 WINDOW_ORDER_INFO* wParam = (WINDOW_ORDER_INFO*)malloc(sizeof(WINDOW_ORDER_INFO));
1308
1309 if (!wParam)
1310 return FALSE;
1311
1312 *wParam = *orderInfo;
1313
1314 WINDOW_STATE_ORDER* lParam = window_state_order_clone(windowState);
1315
1316 if (!lParam)
1317 {
1318 free(wParam);
1319 return FALSE;
1320 }
1321
1322 rdp_update_internal* up = update_cast(context->update);
1323 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(WindowUpdate, WindowUpdate),
1324 (void*)wParam, (void*)lParam);
1325}
1326
1327static BOOL update_message_WindowIcon(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
1328 const WINDOW_ICON_ORDER* windowIcon)
1329{
1330 if (!context || !context->update || !orderInfo || !windowIcon)
1331 return FALSE;
1332
1333 WINDOW_ORDER_INFO* wParam = (WINDOW_ORDER_INFO*)malloc(sizeof(WINDOW_ORDER_INFO));
1334
1335 if (!wParam)
1336 return FALSE;
1337
1338 *wParam = *orderInfo;
1339
1340 WINDOW_ICON_ORDER* lParam = (WINDOW_ICON_ORDER*)calloc(1, sizeof(WINDOW_ICON_ORDER));
1341
1342 if (!lParam)
1343 goto out_fail;
1344
1345 *lParam = *windowIcon;
1346 lParam->iconInfo = calloc(1, sizeof(ICON_INFO));
1347
1348 if (!lParam->iconInfo)
1349 goto out_fail;
1350
1351 *lParam->iconInfo = *windowIcon->iconInfo;
1352
1353 WLog_VRB(TAG, "update_message_WindowIcon");
1354
1355 if (windowIcon->iconInfo->cbBitsColor > 0)
1356 {
1357 lParam->iconInfo->bitsColor = (BYTE*)malloc(windowIcon->iconInfo->cbBitsColor);
1358
1359 if (!lParam->iconInfo->bitsColor)
1360 goto out_fail;
1361
1362 CopyMemory(lParam->iconInfo->bitsColor, windowIcon->iconInfo->bitsColor,
1363 windowIcon->iconInfo->cbBitsColor);
1364 }
1365
1366 if (windowIcon->iconInfo->cbBitsMask > 0)
1367 {
1368 lParam->iconInfo->bitsMask = (BYTE*)malloc(windowIcon->iconInfo->cbBitsMask);
1369
1370 if (!lParam->iconInfo->bitsMask)
1371 goto out_fail;
1372
1373 CopyMemory(lParam->iconInfo->bitsMask, windowIcon->iconInfo->bitsMask,
1374 windowIcon->iconInfo->cbBitsMask);
1375 }
1376
1377 if (windowIcon->iconInfo->cbColorTable > 0)
1378 {
1379 lParam->iconInfo->colorTable = (BYTE*)malloc(windowIcon->iconInfo->cbColorTable);
1380
1381 if (!lParam->iconInfo->colorTable)
1382 goto out_fail;
1383
1384 CopyMemory(lParam->iconInfo->colorTable, windowIcon->iconInfo->colorTable,
1385 windowIcon->iconInfo->cbColorTable);
1386 }
1387
1388 rdp_update_internal* up = update_cast(context->update);
1389 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(WindowUpdate, WindowIcon),
1390 (void*)wParam, (void*)lParam);
1391out_fail:
1392
1393 if (lParam && lParam->iconInfo)
1394 {
1395 free(lParam->iconInfo->bitsColor);
1396 free(lParam->iconInfo->bitsMask);
1397 free(lParam->iconInfo->colorTable);
1398 free(lParam->iconInfo);
1399 }
1400
1401 free(lParam);
1402 free(wParam);
1403 return FALSE;
1404}
1405
1406static BOOL update_message_WindowCachedIcon(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
1407 const WINDOW_CACHED_ICON_ORDER* windowCachedIcon)
1408{
1409 WINDOW_ORDER_INFO* wParam = nullptr;
1410 WINDOW_CACHED_ICON_ORDER* lParam = nullptr;
1411 rdp_update_internal* up = nullptr;
1412
1413 if (!context || !context->update || !orderInfo || !windowCachedIcon)
1414 return FALSE;
1415
1416 wParam = (WINDOW_ORDER_INFO*)malloc(sizeof(WINDOW_ORDER_INFO));
1417
1418 if (!wParam)
1419 return FALSE;
1420
1421 CopyMemory(wParam, orderInfo, sizeof(WINDOW_ORDER_INFO));
1422 lParam = (WINDOW_CACHED_ICON_ORDER*)malloc(sizeof(WINDOW_CACHED_ICON_ORDER));
1423
1424 if (!lParam)
1425 {
1426 free(wParam);
1427 return FALSE;
1428 }
1429
1430 CopyMemory(lParam, windowCachedIcon, sizeof(WINDOW_CACHED_ICON_ORDER));
1431
1432 up = update_cast(context->update);
1433 return MessageQueue_Post(up->queue, (void*)context,
1434 MakeMessageId(WindowUpdate, WindowCachedIcon), (void*)wParam,
1435 (void*)lParam);
1436}
1437
1438static BOOL update_message_WindowDelete(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo)
1439{
1440 WINDOW_ORDER_INFO* wParam = nullptr;
1441 rdp_update_internal* up = nullptr;
1442
1443 if (!context || !context->update || !orderInfo)
1444 return FALSE;
1445
1446 wParam = (WINDOW_ORDER_INFO*)malloc(sizeof(WINDOW_ORDER_INFO));
1447
1448 if (!wParam)
1449 return FALSE;
1450
1451 CopyMemory(wParam, orderInfo, sizeof(WINDOW_ORDER_INFO));
1452
1453 up = update_cast(context->update);
1454 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(WindowUpdate, WindowDelete),
1455 (void*)wParam, nullptr);
1456}
1457
1458static void notify_icon_state_order_free(NOTIFY_ICON_STATE_ORDER* notify)
1459{
1460 if (!notify)
1461 return;
1462
1463 rail_unicode_string_free(&notify->toolTip);
1464 rail_unicode_string_free(&notify->infoTip.text);
1465 rail_unicode_string_free(&notify->infoTip.title);
1466 free(notify->icon.bitsColor);
1467 free(notify->icon.bitsMask);
1468 free(notify->icon.colorTable);
1469 free(notify);
1470}
1471
1472static BOOL icon_info_clone(ICON_INFO* dst, const ICON_INFO* src)
1473{
1474 dst->bitsColor = nullptr;
1475 dst->bitsMask = nullptr;
1476 dst->colorTable = nullptr;
1477
1478 if (src->cbBitsColor > 0)
1479 {
1480 dst->bitsColor = (BYTE*)malloc(src->cbBitsColor);
1481 if (!dst->bitsColor)
1482 return FALSE;
1483 CopyMemory(dst->bitsColor, src->bitsColor, src->cbBitsColor);
1484 }
1485
1486 if (src->cbBitsMask > 0)
1487 {
1488 dst->bitsMask = (BYTE*)malloc(src->cbBitsMask);
1489 if (!dst->bitsMask)
1490 return FALSE;
1491 CopyMemory(dst->bitsMask, src->bitsMask, src->cbBitsMask);
1492 }
1493
1494 if (src->cbColorTable > 0)
1495 {
1496 dst->colorTable = (BYTE*)malloc(src->cbColorTable);
1497 if (!dst->colorTable)
1498 return FALSE;
1499 CopyMemory(dst->colorTable, src->colorTable, src->cbColorTable);
1500 }
1501
1502 return TRUE;
1503}
1504
1505static NOTIFY_ICON_STATE_ORDER* notify_icon_state_order_clone(const NOTIFY_ICON_STATE_ORDER* order)
1506{
1507 NOTIFY_ICON_STATE_ORDER* clone = calloc(1, sizeof(NOTIFY_ICON_STATE_ORDER));
1508 if (!clone)
1509 return nullptr;
1510
1511 *clone = *order;
1512 clone->toolTip = rail_unicode_string_clone(&order->toolTip);
1513 clone->infoTip.text = rail_unicode_string_clone(&order->infoTip.text);
1514 clone->infoTip.title = rail_unicode_string_clone(&order->infoTip.title);
1515
1516 if (!icon_info_clone(&clone->icon, &order->icon) ||
1517 (!clone->toolTip.string && (order->toolTip.length > 0)) ||
1518 (!clone->infoTip.text.string && (order->infoTip.text.length > 0)) ||
1519 (!clone->infoTip.title.string && (order->infoTip.title.length > 0)))
1520 {
1521 notify_icon_state_order_free(clone);
1522 return nullptr;
1523 }
1524
1525 return clone;
1526}
1527
1528static BOOL update_message_NotifyIconCreate(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
1529 const NOTIFY_ICON_STATE_ORDER* notifyIconState)
1530{
1531 WINDOW_ORDER_INFO* wParam = nullptr;
1532 NOTIFY_ICON_STATE_ORDER* lParam = nullptr;
1533 rdp_update_internal* up = nullptr;
1534
1535 if (!context || !context->update || !orderInfo || !notifyIconState)
1536 return FALSE;
1537
1538 wParam = (WINDOW_ORDER_INFO*)malloc(sizeof(WINDOW_ORDER_INFO));
1539
1540 if (!wParam)
1541 return FALSE;
1542
1543 CopyMemory(wParam, orderInfo, sizeof(WINDOW_ORDER_INFO));
1544 lParam = notify_icon_state_order_clone(notifyIconState);
1545
1546 if (!lParam)
1547 {
1548 free(wParam);
1549 return FALSE;
1550 }
1551
1552 up = update_cast(context->update);
1553 return MessageQueue_Post(up->queue, (void*)context,
1554 MakeMessageId(WindowUpdate, NotifyIconCreate), (void*)wParam,
1555 (void*)lParam);
1556}
1557
1558static BOOL update_message_NotifyIconUpdate(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
1559 const NOTIFY_ICON_STATE_ORDER* notifyIconState)
1560{
1561 WINDOW_ORDER_INFO* wParam = nullptr;
1562 NOTIFY_ICON_STATE_ORDER* lParam = nullptr;
1563 rdp_update_internal* up = nullptr;
1564
1565 if (!context || !context->update || !orderInfo || !notifyIconState)
1566 return FALSE;
1567
1568 wParam = (WINDOW_ORDER_INFO*)malloc(sizeof(WINDOW_ORDER_INFO));
1569
1570 if (!wParam)
1571 return FALSE;
1572
1573 CopyMemory(wParam, orderInfo, sizeof(WINDOW_ORDER_INFO));
1574 lParam = notify_icon_state_order_clone(notifyIconState);
1575
1576 if (!lParam)
1577 {
1578 free(wParam);
1579 return FALSE;
1580 }
1581
1582 up = update_cast(context->update);
1583 return MessageQueue_Post(up->queue, (void*)context,
1584 MakeMessageId(WindowUpdate, NotifyIconUpdate), (void*)wParam,
1585 (void*)lParam);
1586}
1587
1588static BOOL update_message_NotifyIconDelete(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo)
1589{
1590 WINDOW_ORDER_INFO* wParam = nullptr;
1591 rdp_update_internal* up = nullptr;
1592
1593 if (!context || !context->update || !orderInfo)
1594 return FALSE;
1595
1596 wParam = (WINDOW_ORDER_INFO*)malloc(sizeof(WINDOW_ORDER_INFO));
1597
1598 if (!wParam)
1599 return FALSE;
1600
1601 CopyMemory(wParam, orderInfo, sizeof(WINDOW_ORDER_INFO));
1602
1603 up = update_cast(context->update);
1604 return MessageQueue_Post(up->queue, (void*)context,
1605 MakeMessageId(WindowUpdate, NotifyIconDelete), (void*)wParam, nullptr);
1606}
1607
1608static BOOL update_message_MonitoredDesktop(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
1609 const MONITORED_DESKTOP_ORDER* monitoredDesktop)
1610{
1611 WINDOW_ORDER_INFO* wParam = nullptr;
1612 MONITORED_DESKTOP_ORDER* lParam = nullptr;
1613 rdp_update_internal* up = nullptr;
1614
1615 if (!context || !context->update || !orderInfo || !monitoredDesktop)
1616 return FALSE;
1617
1618 wParam = (WINDOW_ORDER_INFO*)malloc(sizeof(WINDOW_ORDER_INFO));
1619
1620 if (!wParam)
1621 return FALSE;
1622
1623 CopyMemory(wParam, orderInfo, sizeof(WINDOW_ORDER_INFO));
1624 lParam = (MONITORED_DESKTOP_ORDER*)malloc(sizeof(MONITORED_DESKTOP_ORDER));
1625
1626 if (!lParam)
1627 {
1628 free(wParam);
1629 return FALSE;
1630 }
1631
1632 CopyMemory(lParam, monitoredDesktop, sizeof(MONITORED_DESKTOP_ORDER));
1633 lParam->windowIds = nullptr;
1634
1635 if (lParam->numWindowIds)
1636 {
1637 lParam->windowIds = (UINT32*)calloc(lParam->numWindowIds, sizeof(UINT32));
1638 CopyMemory(lParam->windowIds, monitoredDesktop->windowIds, lParam->numWindowIds);
1639 }
1640
1641 up = update_cast(context->update);
1642 return MessageQueue_Post(up->queue, (void*)context,
1643 MakeMessageId(WindowUpdate, MonitoredDesktop), (void*)wParam,
1644 (void*)lParam);
1645}
1646
1647static BOOL update_message_NonMonitoredDesktop(rdpContext* context,
1648 const WINDOW_ORDER_INFO* orderInfo)
1649{
1650 WINDOW_ORDER_INFO* wParam = nullptr;
1651 rdp_update_internal* up = nullptr;
1652
1653 if (!context || !context->update || !orderInfo)
1654 return FALSE;
1655
1656 wParam = (WINDOW_ORDER_INFO*)malloc(sizeof(WINDOW_ORDER_INFO));
1657
1658 if (!wParam)
1659 return FALSE;
1660
1661 CopyMemory(wParam, orderInfo, sizeof(WINDOW_ORDER_INFO));
1662
1663 up = update_cast(context->update);
1664 return MessageQueue_Post(up->queue, (void*)context,
1665 MakeMessageId(WindowUpdate, NonMonitoredDesktop), (void*)wParam,
1666 nullptr);
1667}
1668
1669/* Pointer Update */
1670
1671static BOOL update_message_PointerPosition(rdpContext* context,
1672 const POINTER_POSITION_UPDATE* pointerPosition)
1673{
1674 POINTER_POSITION_UPDATE* wParam = nullptr;
1675 rdp_update_internal* up = nullptr;
1676
1677 if (!context || !context->update || !pointerPosition)
1678 return FALSE;
1679
1680 wParam = copy_pointer_position_update(context, pointerPosition);
1681
1682 if (!wParam)
1683 return FALSE;
1684
1685 up = update_cast(context->update);
1686 return MessageQueue_Post(up->queue, (void*)context,
1687 MakeMessageId(PointerUpdate, PointerPosition), (void*)wParam, nullptr);
1688}
1689
1690static BOOL update_message_PointerSystem(rdpContext* context,
1691 const POINTER_SYSTEM_UPDATE* pointerSystem)
1692{
1693 POINTER_SYSTEM_UPDATE* wParam = nullptr;
1694 rdp_update_internal* up = nullptr;
1695
1696 if (!context || !context->update || !pointerSystem)
1697 return FALSE;
1698
1699 wParam = copy_pointer_system_update(context, pointerSystem);
1700
1701 if (!wParam)
1702 return FALSE;
1703
1704 up = update_cast(context->update);
1705 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PointerUpdate, PointerSystem),
1706 (void*)wParam, nullptr);
1707}
1708
1709static BOOL update_message_PointerColor(rdpContext* context,
1710 const POINTER_COLOR_UPDATE* pointerColor)
1711{
1712 POINTER_COLOR_UPDATE* wParam = nullptr;
1713 rdp_update_internal* up = nullptr;
1714
1715 if (!context || !context->update || !pointerColor)
1716 return FALSE;
1717
1718 wParam = copy_pointer_color_update(context, pointerColor);
1719
1720 if (!wParam)
1721 return FALSE;
1722
1723 up = update_cast(context->update);
1724 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PointerUpdate, PointerColor),
1725 (void*)wParam, nullptr);
1726}
1727
1728static BOOL update_message_PointerLarge(rdpContext* context, const POINTER_LARGE_UPDATE* pointer)
1729{
1730 POINTER_LARGE_UPDATE* wParam = nullptr;
1731 rdp_update_internal* up = nullptr;
1732
1733 if (!context || !context->update || !pointer)
1734 return FALSE;
1735
1736 wParam = copy_pointer_large_update(context, pointer);
1737
1738 if (!wParam)
1739 return FALSE;
1740
1741 up = update_cast(context->update);
1742 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PointerUpdate, PointerLarge),
1743 (void*)wParam, nullptr);
1744}
1745
1746static BOOL update_message_PointerNew(rdpContext* context, const POINTER_NEW_UPDATE* pointerNew)
1747{
1748 POINTER_NEW_UPDATE* wParam = nullptr;
1749 rdp_update_internal* up = nullptr;
1750
1751 if (!context || !context->update || !pointerNew)
1752 return FALSE;
1753
1754 wParam = copy_pointer_new_update(context, pointerNew);
1755
1756 if (!wParam)
1757 return FALSE;
1758
1759 up = update_cast(context->update);
1760 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PointerUpdate, PointerNew),
1761 (void*)wParam, nullptr);
1762}
1763
1764static BOOL update_message_PointerCached(rdpContext* context,
1765 const POINTER_CACHED_UPDATE* pointerCached)
1766{
1767 POINTER_CACHED_UPDATE* wParam = nullptr;
1768 rdp_update_internal* up = nullptr;
1769
1770 if (!context || !context->update || !pointerCached)
1771 return FALSE;
1772
1773 wParam = copy_pointer_cached_update(context, pointerCached);
1774
1775 if (!wParam)
1776 return FALSE;
1777
1778 up = update_cast(context->update);
1779 return MessageQueue_Post(up->queue, (void*)context, MakeMessageId(PointerUpdate, PointerCached),
1780 (void*)wParam, nullptr);
1781}
1782
1783/* Message Queue */
1784static BOOL update_message_free_update_class(wMessage* msg, int type)
1785{
1786 rdpContext* context = nullptr;
1787
1788 if (!msg)
1789 return FALSE;
1790
1791 context = (rdpContext*)msg->context;
1792
1793 switch (type)
1794 {
1795 case Update_BeginPaint:
1796 break;
1797
1798 case Update_EndPaint:
1799 break;
1800
1801 case Update_SetBounds:
1802 free(msg->wParam);
1803 break;
1804
1805 case Update_Synchronize:
1806 break;
1807
1808 case Update_DesktopResize:
1809 break;
1810
1811 case Update_BitmapUpdate:
1812 {
1813 BITMAP_UPDATE* wParam = (BITMAP_UPDATE*)msg->wParam;
1814 free_bitmap_update(context, wParam);
1815 }
1816 break;
1817
1818 case Update_Palette:
1819 {
1820 PALETTE_UPDATE* palette = (PALETTE_UPDATE*)msg->wParam;
1821 free_palette_update(context, palette);
1822 }
1823 break;
1824
1825 case Update_PlaySound:
1826 free(msg->wParam);
1827 break;
1828
1829 case Update_RefreshRect:
1830 free(msg->lParam);
1831 break;
1832
1833 case Update_SuppressOutput:
1834 free(msg->lParam);
1835 break;
1836
1837 case Update_SurfaceCommand:
1838 {
1839 wStream* s = (wStream*)msg->wParam;
1840 Stream_Free(s, TRUE);
1841 }
1842 break;
1843
1844 case Update_SurfaceBits:
1845 {
1846 SURFACE_BITS_COMMAND* wParam = (SURFACE_BITS_COMMAND*)msg->wParam;
1847 free_surface_bits_command(context, wParam);
1848 }
1849 break;
1850
1851 case Update_SurfaceFrameMarker:
1852 free(msg->wParam);
1853 break;
1854
1855 case Update_SurfaceFrameAcknowledge:
1856 case Update_SetKeyboardIndicators:
1857 case Update_SetKeyboardImeStatus:
1858 break;
1859
1860 default:
1861 return FALSE;
1862 }
1863
1864 return TRUE;
1865}
1866
1867static BOOL update_message_process_update_class(rdpUpdateProxy* proxy, wMessage* msg, int type)
1868{
1869 BOOL rc = FALSE;
1870
1871 if (!proxy || !msg)
1872 return FALSE;
1873
1874 switch (type)
1875 {
1876 case Update_BeginPaint:
1877 rc = IFCALLRESULT(TRUE, proxy->BeginPaint, msg->context);
1878 break;
1879
1880 case Update_EndPaint:
1881 rc = IFCALLRESULT(TRUE, proxy->EndPaint, msg->context);
1882 break;
1883
1884 case Update_SetBounds:
1885 rc = IFCALLRESULT(TRUE, proxy->SetBounds, msg->context, (rdpBounds*)msg->wParam);
1886 break;
1887
1888 case Update_Synchronize:
1889 rc = IFCALLRESULT(TRUE, proxy->Synchronize, msg->context);
1890 break;
1891
1892 case Update_DesktopResize:
1893 rc = IFCALLRESULT(TRUE, proxy->DesktopResize, msg->context);
1894 break;
1895
1896 case Update_BitmapUpdate:
1897 rc = IFCALLRESULT(TRUE, proxy->BitmapUpdate, msg->context, (BITMAP_UPDATE*)msg->wParam);
1898 break;
1899
1900 case Update_Palette:
1901 rc = IFCALLRESULT(TRUE, proxy->Palette, msg->context, (PALETTE_UPDATE*)msg->wParam);
1902 break;
1903
1904 case Update_PlaySound:
1905 rc =
1906 IFCALLRESULT(TRUE, proxy->PlaySound, msg->context, (PLAY_SOUND_UPDATE*)msg->wParam);
1907 break;
1908
1909 case Update_RefreshRect:
1910 rc = IFCALLRESULT(TRUE, proxy->RefreshRect, msg->context, (BYTE)(size_t)msg->wParam,
1911 (RECTANGLE_16*)msg->lParam);
1912 break;
1913
1914 case Update_SuppressOutput:
1915 rc = IFCALLRESULT(TRUE, proxy->SuppressOutput, msg->context, (BYTE)(size_t)msg->wParam,
1916 (RECTANGLE_16*)msg->lParam);
1917 break;
1918
1919 case Update_SurfaceCommand:
1920 rc = IFCALLRESULT(TRUE, proxy->SurfaceCommand, msg->context, (wStream*)msg->wParam);
1921 break;
1922
1923 case Update_SurfaceBits:
1924 rc = IFCALLRESULT(TRUE, proxy->SurfaceBits, msg->context,
1925 (SURFACE_BITS_COMMAND*)msg->wParam);
1926 break;
1927
1928 case Update_SurfaceFrameMarker:
1929 rc = IFCALLRESULT(TRUE, proxy->SurfaceFrameMarker, msg->context,
1930 (SURFACE_FRAME_MARKER*)msg->wParam);
1931 break;
1932
1933 case Update_SurfaceFrameAcknowledge:
1934 rc = IFCALLRESULT(TRUE, proxy->SurfaceFrameAcknowledge, msg->context,
1935 (UINT32)(size_t)msg->wParam);
1936 break;
1937
1938 case Update_SetKeyboardIndicators:
1939 rc = IFCALLRESULT(TRUE, proxy->SetKeyboardIndicators, msg->context,
1940 (UINT16)(size_t)msg->wParam);
1941 break;
1942
1943 case Update_SetKeyboardImeStatus:
1944 {
1945 const UINT16 imeId = ((size_t)msg->wParam) >> 16 & 0xFFFF;
1946 const UINT32 imeState = ((size_t)msg->wParam) & 0xFFFF;
1947 const UINT32 imeConvMode = ((size_t)msg->lParam) & 0xFFFFFFFFUL;
1948 rc = IFCALLRESULT(TRUE, proxy->SetKeyboardImeStatus, msg->context, imeId, imeState,
1949 imeConvMode);
1950 }
1951 break;
1952
1953 default:
1954 break;
1955 }
1956
1957 return rc;
1958}
1959
1960static BOOL update_message_free_primary_update_class(wMessage* msg, int type)
1961{
1962 if (!msg)
1963 return FALSE;
1964
1965 switch (type)
1966 {
1967 case PrimaryUpdate_DstBlt:
1968 free(msg->wParam);
1969 break;
1970
1971 case PrimaryUpdate_PatBlt:
1972 free(msg->wParam);
1973 break;
1974
1975 case PrimaryUpdate_ScrBlt:
1976 free(msg->wParam);
1977 break;
1978
1979 case PrimaryUpdate_OpaqueRect:
1980 free(msg->wParam);
1981 break;
1982
1983 case PrimaryUpdate_DrawNineGrid:
1984 free(msg->wParam);
1985 break;
1986
1987 case PrimaryUpdate_MultiDstBlt:
1988 free(msg->wParam);
1989 break;
1990
1991 case PrimaryUpdate_MultiPatBlt:
1992 free(msg->wParam);
1993 break;
1994
1995 case PrimaryUpdate_MultiScrBlt:
1996 free(msg->wParam);
1997 break;
1998
1999 case PrimaryUpdate_MultiOpaqueRect:
2000 free(msg->wParam);
2001 break;
2002
2003 case PrimaryUpdate_MultiDrawNineGrid:
2004 free(msg->wParam);
2005 break;
2006
2007 case PrimaryUpdate_LineTo:
2008 free(msg->wParam);
2009 break;
2010
2011 case PrimaryUpdate_Polyline:
2012 {
2013 POLYLINE_ORDER* wParam = (POLYLINE_ORDER*)msg->wParam;
2014 free(wParam->points);
2015 free(wParam);
2016 }
2017 break;
2018
2019 case PrimaryUpdate_MemBlt:
2020 free(msg->wParam);
2021 break;
2022
2023 case PrimaryUpdate_Mem3Blt:
2024 free(msg->wParam);
2025 break;
2026
2027 case PrimaryUpdate_SaveBitmap:
2028 free(msg->wParam);
2029 break;
2030
2031 case PrimaryUpdate_GlyphIndex:
2032 free(msg->wParam);
2033 break;
2034
2035 case PrimaryUpdate_FastIndex:
2036 free(msg->wParam);
2037 break;
2038
2039 case PrimaryUpdate_FastGlyph:
2040 {
2041 FAST_GLYPH_ORDER* wParam = (FAST_GLYPH_ORDER*)msg->wParam;
2042 free(wParam->glyphData.aj);
2043 free(wParam);
2044 }
2045 break;
2046
2047 case PrimaryUpdate_PolygonSC:
2048 {
2049 POLYGON_SC_ORDER* wParam = (POLYGON_SC_ORDER*)msg->wParam;
2050 free(wParam->points);
2051 free(wParam);
2052 }
2053 break;
2054
2055 case PrimaryUpdate_PolygonCB:
2056 {
2057 POLYGON_CB_ORDER* wParam = (POLYGON_CB_ORDER*)msg->wParam;
2058 free(wParam->points);
2059 free(wParam);
2060 }
2061 break;
2062
2063 case PrimaryUpdate_EllipseSC:
2064 free(msg->wParam);
2065 break;
2066
2067 case PrimaryUpdate_EllipseCB:
2068 free(msg->wParam);
2069 break;
2070
2071 default:
2072 return FALSE;
2073 }
2074
2075 return TRUE;
2076}
2077
2078static BOOL update_message_process_primary_update_class(rdpUpdateProxy* proxy, wMessage* msg,
2079 int type)
2080{
2081 if (!proxy || !msg)
2082 return FALSE;
2083
2084 switch (type)
2085 {
2086 case PrimaryUpdate_DstBlt:
2087 return IFCALLRESULT(TRUE, proxy->DstBlt, msg->context, (DSTBLT_ORDER*)msg->wParam);
2088
2089 case PrimaryUpdate_PatBlt:
2090 return IFCALLRESULT(TRUE, proxy->PatBlt, msg->context, (PATBLT_ORDER*)msg->wParam);
2091
2092 case PrimaryUpdate_ScrBlt:
2093 return IFCALLRESULT(TRUE, proxy->ScrBlt, msg->context, (SCRBLT_ORDER*)msg->wParam);
2094
2095 case PrimaryUpdate_OpaqueRect:
2096 return IFCALLRESULT(TRUE, proxy->OpaqueRect, msg->context,
2097 (OPAQUE_RECT_ORDER*)msg->wParam);
2098
2099 case PrimaryUpdate_DrawNineGrid:
2100 return IFCALLRESULT(TRUE, proxy->DrawNineGrid, msg->context,
2101 (DRAW_NINE_GRID_ORDER*)msg->wParam);
2102
2103 case PrimaryUpdate_MultiDstBlt:
2104 return IFCALLRESULT(TRUE, proxy->MultiDstBlt, msg->context,
2105 (MULTI_DSTBLT_ORDER*)msg->wParam);
2106
2107 case PrimaryUpdate_MultiPatBlt:
2108 return IFCALLRESULT(TRUE, proxy->MultiPatBlt, msg->context,
2109 (MULTI_PATBLT_ORDER*)msg->wParam);
2110
2111 case PrimaryUpdate_MultiScrBlt:
2112 return IFCALLRESULT(TRUE, proxy->MultiScrBlt, msg->context,
2113 (MULTI_SCRBLT_ORDER*)msg->wParam);
2114
2115 case PrimaryUpdate_MultiOpaqueRect:
2116 return IFCALLRESULT(TRUE, proxy->MultiOpaqueRect, msg->context,
2117 (MULTI_OPAQUE_RECT_ORDER*)msg->wParam);
2118
2119 case PrimaryUpdate_MultiDrawNineGrid:
2120 return IFCALLRESULT(TRUE, proxy->MultiDrawNineGrid, msg->context,
2121 (MULTI_DRAW_NINE_GRID_ORDER*)msg->wParam);
2122
2123 case PrimaryUpdate_LineTo:
2124 return IFCALLRESULT(TRUE, proxy->LineTo, msg->context, (LINE_TO_ORDER*)msg->wParam);
2125
2126 case PrimaryUpdate_Polyline:
2127 return IFCALLRESULT(TRUE, proxy->Polyline, msg->context, (POLYLINE_ORDER*)msg->wParam);
2128
2129 case PrimaryUpdate_MemBlt:
2130 return IFCALLRESULT(TRUE, proxy->MemBlt, msg->context, (MEMBLT_ORDER*)msg->wParam);
2131
2132 case PrimaryUpdate_Mem3Blt:
2133 return IFCALLRESULT(TRUE, proxy->Mem3Blt, msg->context, (MEM3BLT_ORDER*)msg->wParam);
2134
2135 case PrimaryUpdate_SaveBitmap:
2136 return IFCALLRESULT(TRUE, proxy->SaveBitmap, msg->context,
2137 (SAVE_BITMAP_ORDER*)msg->wParam);
2138
2139 case PrimaryUpdate_GlyphIndex:
2140 return IFCALLRESULT(TRUE, proxy->GlyphIndex, msg->context,
2141 (GLYPH_INDEX_ORDER*)msg->wParam);
2142
2143 case PrimaryUpdate_FastIndex:
2144 return IFCALLRESULT(TRUE, proxy->FastIndex, msg->context,
2145 (FAST_INDEX_ORDER*)msg->wParam);
2146
2147 case PrimaryUpdate_FastGlyph:
2148 return IFCALLRESULT(TRUE, proxy->FastGlyph, msg->context,
2149 (FAST_GLYPH_ORDER*)msg->wParam);
2150
2151 case PrimaryUpdate_PolygonSC:
2152 return IFCALLRESULT(TRUE, proxy->PolygonSC, msg->context,
2153 (POLYGON_SC_ORDER*)msg->wParam);
2154
2155 case PrimaryUpdate_PolygonCB:
2156 return IFCALLRESULT(TRUE, proxy->PolygonCB, msg->context,
2157 (POLYGON_CB_ORDER*)msg->wParam);
2158
2159 case PrimaryUpdate_EllipseSC:
2160 return IFCALLRESULT(TRUE, proxy->EllipseSC, msg->context,
2161 (ELLIPSE_SC_ORDER*)msg->wParam);
2162
2163 case PrimaryUpdate_EllipseCB:
2164 return IFCALLRESULT(TRUE, proxy->EllipseCB, msg->context,
2165 (ELLIPSE_CB_ORDER*)msg->wParam);
2166
2167 default:
2168 return FALSE;
2169 }
2170}
2171
2172static BOOL update_message_free_secondary_update_class(wMessage* msg, int type)
2173{
2174 rdpContext* context = nullptr;
2175
2176 if (!msg)
2177 return FALSE;
2178
2179 context = msg->context;
2180
2181 switch (type)
2182 {
2183 case SecondaryUpdate_CacheBitmap:
2184 {
2185 CACHE_BITMAP_ORDER* wParam = (CACHE_BITMAP_ORDER*)msg->wParam;
2186 free_cache_bitmap_order(context, wParam);
2187 }
2188 break;
2189
2190 case SecondaryUpdate_CacheBitmapV2:
2191 {
2192 CACHE_BITMAP_V2_ORDER* wParam = (CACHE_BITMAP_V2_ORDER*)msg->wParam;
2193 free_cache_bitmap_v2_order(context, wParam);
2194 }
2195 break;
2196
2197 case SecondaryUpdate_CacheBitmapV3:
2198 {
2199 CACHE_BITMAP_V3_ORDER* wParam = (CACHE_BITMAP_V3_ORDER*)msg->wParam;
2200 free_cache_bitmap_v3_order(context, wParam);
2201 }
2202 break;
2203
2204 case SecondaryUpdate_CacheColorTable:
2205 {
2206 CACHE_COLOR_TABLE_ORDER* wParam = (CACHE_COLOR_TABLE_ORDER*)msg->wParam;
2207 free_cache_color_table_order(context, wParam);
2208 }
2209 break;
2210
2211 case SecondaryUpdate_CacheGlyph:
2212 {
2213 CACHE_GLYPH_ORDER* wParam = (CACHE_GLYPH_ORDER*)msg->wParam;
2214 free_cache_glyph_order(context, wParam);
2215 }
2216 break;
2217
2218 case SecondaryUpdate_CacheGlyphV2:
2219 {
2220 CACHE_GLYPH_V2_ORDER* wParam = (CACHE_GLYPH_V2_ORDER*)msg->wParam;
2221 free_cache_glyph_v2_order(context, wParam);
2222 }
2223 break;
2224
2225 case SecondaryUpdate_CacheBrush:
2226 {
2227 CACHE_BRUSH_ORDER* wParam = (CACHE_BRUSH_ORDER*)msg->wParam;
2228 free_cache_brush_order(context, wParam);
2229 }
2230 break;
2231
2232 default:
2233 return FALSE;
2234 }
2235
2236 return TRUE;
2237}
2238
2239static BOOL update_message_process_secondary_update_class(rdpUpdateProxy* proxy, wMessage* msg,
2240 int type)
2241{
2242 if (!proxy || !msg)
2243 return FALSE;
2244
2245 switch (type)
2246 {
2247 case SecondaryUpdate_CacheBitmap:
2248 return IFCALLRESULT(TRUE, proxy->CacheBitmap, msg->context,
2249 (CACHE_BITMAP_ORDER*)msg->wParam);
2250
2251 case SecondaryUpdate_CacheBitmapV2:
2252 return IFCALLRESULT(TRUE, proxy->CacheBitmapV2, msg->context,
2253 (CACHE_BITMAP_V2_ORDER*)msg->wParam);
2254
2255 case SecondaryUpdate_CacheBitmapV3:
2256 return IFCALLRESULT(TRUE, proxy->CacheBitmapV3, msg->context,
2257 (CACHE_BITMAP_V3_ORDER*)msg->wParam);
2258
2259 case SecondaryUpdate_CacheColorTable:
2260 return IFCALLRESULT(TRUE, proxy->CacheColorTable, msg->context,
2261 (CACHE_COLOR_TABLE_ORDER*)msg->wParam);
2262
2263 case SecondaryUpdate_CacheGlyph:
2264 return IFCALLRESULT(TRUE, proxy->CacheGlyph, msg->context,
2265 (CACHE_GLYPH_ORDER*)msg->wParam);
2266
2267 case SecondaryUpdate_CacheGlyphV2:
2268 return IFCALLRESULT(TRUE, proxy->CacheGlyphV2, msg->context,
2269 (CACHE_GLYPH_V2_ORDER*)msg->wParam);
2270
2271 case SecondaryUpdate_CacheBrush:
2272 return IFCALLRESULT(TRUE, proxy->CacheBrush, msg->context,
2273 (CACHE_BRUSH_ORDER*)msg->wParam);
2274
2275 default:
2276 return FALSE;
2277 }
2278}
2279
2280static BOOL update_message_free_altsec_update_class(wMessage* msg, int type)
2281{
2282 if (!msg)
2283 return FALSE;
2284
2285 switch (type)
2286 {
2287 case AltSecUpdate_CreateOffscreenBitmap:
2288 {
2290 free(wParam->deleteList.indices);
2291 free(wParam);
2292 }
2293 break;
2294
2295 case AltSecUpdate_SwitchSurface:
2296 free(msg->wParam);
2297 break;
2298
2299 case AltSecUpdate_CreateNineGridBitmap:
2300 free(msg->wParam);
2301 break;
2302
2303 case AltSecUpdate_FrameMarker:
2304 free(msg->wParam);
2305 break;
2306
2307 case AltSecUpdate_StreamBitmapFirst:
2308 free(msg->wParam);
2309 break;
2310
2311 case AltSecUpdate_StreamBitmapNext:
2312 free(msg->wParam);
2313 break;
2314
2315 case AltSecUpdate_DrawGdiPlusFirst:
2316 free(msg->wParam);
2317 break;
2318
2319 case AltSecUpdate_DrawGdiPlusNext:
2320 free(msg->wParam);
2321 break;
2322
2323 case AltSecUpdate_DrawGdiPlusEnd:
2324 free(msg->wParam);
2325 break;
2326
2327 case AltSecUpdate_DrawGdiPlusCacheFirst:
2328 free(msg->wParam);
2329 break;
2330
2331 case AltSecUpdate_DrawGdiPlusCacheNext:
2332 free(msg->wParam);
2333 break;
2334
2335 case AltSecUpdate_DrawGdiPlusCacheEnd:
2336 free(msg->wParam);
2337 break;
2338
2339 default:
2340 return FALSE;
2341 }
2342
2343 return TRUE;
2344}
2345
2346static BOOL update_message_process_altsec_update_class(rdpUpdateProxy* proxy, wMessage* msg,
2347 int type)
2348{
2349 if (!proxy || !msg)
2350 return FALSE;
2351
2352 switch (type)
2353 {
2354 case AltSecUpdate_CreateOffscreenBitmap:
2355 return IFCALLRESULT(TRUE, proxy->CreateOffscreenBitmap, msg->context,
2356 (CREATE_OFFSCREEN_BITMAP_ORDER*)msg->wParam);
2357
2358 case AltSecUpdate_SwitchSurface:
2359 return IFCALLRESULT(TRUE, proxy->SwitchSurface, msg->context,
2360 (SWITCH_SURFACE_ORDER*)msg->wParam);
2361
2362 case AltSecUpdate_CreateNineGridBitmap:
2363 return IFCALLRESULT(TRUE, proxy->CreateNineGridBitmap, msg->context,
2364 (CREATE_NINE_GRID_BITMAP_ORDER*)msg->wParam);
2365
2366 case AltSecUpdate_FrameMarker:
2367 return IFCALLRESULT(TRUE, proxy->FrameMarker, msg->context,
2368 (FRAME_MARKER_ORDER*)msg->wParam);
2369
2370 case AltSecUpdate_StreamBitmapFirst:
2371 return IFCALLRESULT(TRUE, proxy->StreamBitmapFirst, msg->context,
2372 (STREAM_BITMAP_FIRST_ORDER*)msg->wParam);
2373
2374 case AltSecUpdate_StreamBitmapNext:
2375 return IFCALLRESULT(TRUE, proxy->StreamBitmapNext, msg->context,
2376 (STREAM_BITMAP_NEXT_ORDER*)msg->wParam);
2377
2378 case AltSecUpdate_DrawGdiPlusFirst:
2379 return IFCALLRESULT(TRUE, proxy->DrawGdiPlusFirst, msg->context,
2380 (DRAW_GDIPLUS_FIRST_ORDER*)msg->wParam);
2381
2382 case AltSecUpdate_DrawGdiPlusNext:
2383 return IFCALLRESULT(TRUE, proxy->DrawGdiPlusNext, msg->context,
2384 (DRAW_GDIPLUS_NEXT_ORDER*)msg->wParam);
2385
2386 case AltSecUpdate_DrawGdiPlusEnd:
2387 return IFCALLRESULT(TRUE, proxy->DrawGdiPlusEnd, msg->context,
2388 (DRAW_GDIPLUS_END_ORDER*)msg->wParam);
2389
2390 case AltSecUpdate_DrawGdiPlusCacheFirst:
2391 return IFCALLRESULT(TRUE, proxy->DrawGdiPlusCacheFirst, msg->context,
2392 (DRAW_GDIPLUS_CACHE_FIRST_ORDER*)msg->wParam);
2393
2394 case AltSecUpdate_DrawGdiPlusCacheNext:
2395 return IFCALLRESULT(TRUE, proxy->DrawGdiPlusCacheNext, msg->context,
2396 (DRAW_GDIPLUS_CACHE_NEXT_ORDER*)msg->wParam);
2397
2398 case AltSecUpdate_DrawGdiPlusCacheEnd:
2399 return IFCALLRESULT(TRUE, proxy->DrawGdiPlusCacheEnd, msg->context,
2400 (DRAW_GDIPLUS_CACHE_END_ORDER*)msg->wParam);
2401
2402 default:
2403 return FALSE;
2404 }
2405}
2406
2407static BOOL update_message_free_window_update_class(wMessage* msg, int type)
2408{
2409 if (!msg)
2410 return FALSE;
2411
2412 switch (type)
2413 {
2414 case WindowUpdate_WindowCreate:
2415 free(msg->wParam);
2416 window_state_order_free(msg->lParam);
2417 break;
2418
2419 case WindowUpdate_WindowUpdate:
2420 free(msg->wParam);
2421 window_state_order_free(msg->lParam);
2422 break;
2423
2424 case WindowUpdate_WindowIcon:
2425 {
2426 WINDOW_ORDER_INFO* orderInfo = (WINDOW_ORDER_INFO*)msg->wParam;
2427 WINDOW_ICON_ORDER* windowIcon = (WINDOW_ICON_ORDER*)msg->lParam;
2428
2429 if (windowIcon->iconInfo->cbBitsColor > 0)
2430 {
2431 free(windowIcon->iconInfo->bitsColor);
2432 }
2433
2434 if (windowIcon->iconInfo->cbBitsMask > 0)
2435 {
2436 free(windowIcon->iconInfo->bitsMask);
2437 }
2438
2439 if (windowIcon->iconInfo->cbColorTable > 0)
2440 {
2441 free(windowIcon->iconInfo->colorTable);
2442 }
2443
2444 free(orderInfo);
2445 free(windowIcon->iconInfo);
2446 free(windowIcon);
2447 }
2448 break;
2449
2450 case WindowUpdate_WindowCachedIcon:
2451 free(msg->wParam);
2452 free(msg->lParam);
2453 break;
2454
2455 case WindowUpdate_WindowDelete:
2456 free(msg->wParam);
2457 break;
2458
2459 case WindowUpdate_NotifyIconCreate:
2460 free(msg->wParam);
2461 notify_icon_state_order_free(msg->lParam);
2462 break;
2463
2464 case WindowUpdate_NotifyIconUpdate:
2465 free(msg->wParam);
2466 notify_icon_state_order_free(msg->lParam);
2467 break;
2468
2469 case WindowUpdate_NotifyIconDelete:
2470 free(msg->wParam);
2471 break;
2472
2473 case WindowUpdate_MonitoredDesktop:
2474 {
2475 MONITORED_DESKTOP_ORDER* lParam = (MONITORED_DESKTOP_ORDER*)msg->lParam;
2476 free(msg->wParam);
2477 free(lParam->windowIds);
2478 free(lParam);
2479 }
2480 break;
2481
2482 case WindowUpdate_NonMonitoredDesktop:
2483 free(msg->wParam);
2484 break;
2485
2486 default:
2487 return FALSE;
2488 }
2489
2490 return TRUE;
2491}
2492
2493static BOOL update_message_process_window_update_class(rdpUpdateProxy* proxy, wMessage* msg,
2494 int type)
2495{
2496 if (!proxy || !msg)
2497 return FALSE;
2498
2499 switch (type)
2500 {
2501 case WindowUpdate_WindowCreate:
2502 return IFCALLRESULT(TRUE, proxy->WindowCreate, msg->context,
2503 (WINDOW_ORDER_INFO*)msg->wParam, (WINDOW_STATE_ORDER*)msg->lParam);
2504
2505 case WindowUpdate_WindowUpdate:
2506 return IFCALLRESULT(TRUE, proxy->WindowCreate, msg->context,
2507 (WINDOW_ORDER_INFO*)msg->wParam, (WINDOW_STATE_ORDER*)msg->lParam);
2508
2509 case WindowUpdate_WindowIcon:
2510 {
2511 WINDOW_ORDER_INFO* orderInfo = (WINDOW_ORDER_INFO*)msg->wParam;
2512 WINDOW_ICON_ORDER* windowIcon = (WINDOW_ICON_ORDER*)msg->lParam;
2513 return IFCALLRESULT(TRUE, proxy->WindowIcon, msg->context, orderInfo, windowIcon);
2514 }
2515
2516 case WindowUpdate_WindowCachedIcon:
2517 return IFCALLRESULT(TRUE, proxy->WindowCachedIcon, msg->context,
2518 (WINDOW_ORDER_INFO*)msg->wParam,
2519 (WINDOW_CACHED_ICON_ORDER*)msg->lParam);
2520
2521 case WindowUpdate_WindowDelete:
2522 return IFCALLRESULT(TRUE, proxy->WindowDelete, msg->context,
2523 (WINDOW_ORDER_INFO*)msg->wParam);
2524
2525 case WindowUpdate_NotifyIconCreate:
2526 return IFCALLRESULT(TRUE, proxy->NotifyIconCreate, msg->context,
2527 (WINDOW_ORDER_INFO*)msg->wParam,
2528 (NOTIFY_ICON_STATE_ORDER*)msg->lParam);
2529
2530 case WindowUpdate_NotifyIconUpdate:
2531 return IFCALLRESULT(TRUE, proxy->NotifyIconUpdate, msg->context,
2532 (WINDOW_ORDER_INFO*)msg->wParam,
2533 (NOTIFY_ICON_STATE_ORDER*)msg->lParam);
2534
2535 case WindowUpdate_NotifyIconDelete:
2536 return IFCALLRESULT(TRUE, proxy->NotifyIconDelete, msg->context,
2537 (WINDOW_ORDER_INFO*)msg->wParam);
2538
2539 case WindowUpdate_MonitoredDesktop:
2540 return IFCALLRESULT(TRUE, proxy->MonitoredDesktop, msg->context,
2541 (WINDOW_ORDER_INFO*)msg->wParam,
2542 (MONITORED_DESKTOP_ORDER*)msg->lParam);
2543
2544 case WindowUpdate_NonMonitoredDesktop:
2545 return IFCALLRESULT(TRUE, proxy->NonMonitoredDesktop, msg->context,
2546 (WINDOW_ORDER_INFO*)msg->wParam);
2547
2548 default:
2549 return FALSE;
2550 }
2551}
2552
2553static BOOL update_message_free_pointer_update_class(wMessage* msg, int type)
2554{
2555 rdpContext* context = nullptr;
2556
2557 if (!msg)
2558 return FALSE;
2559
2560 context = msg->context;
2561
2562 switch (type)
2563 {
2564 case PointerUpdate_PointerPosition:
2565 {
2566 POINTER_POSITION_UPDATE* wParam = (POINTER_POSITION_UPDATE*)msg->wParam;
2567 free_pointer_position_update(context, wParam);
2568 }
2569 break;
2570
2571 case PointerUpdate_PointerSystem:
2572 {
2573 POINTER_SYSTEM_UPDATE* wParam = (POINTER_SYSTEM_UPDATE*)msg->wParam;
2574 free_pointer_system_update(context, wParam);
2575 }
2576 break;
2577
2578 case PointerUpdate_PointerCached:
2579 {
2580 POINTER_CACHED_UPDATE* wParam = (POINTER_CACHED_UPDATE*)msg->wParam;
2581 free_pointer_cached_update(context, wParam);
2582 }
2583 break;
2584
2585 case PointerUpdate_PointerColor:
2586 {
2587 POINTER_COLOR_UPDATE* wParam = (POINTER_COLOR_UPDATE*)msg->wParam;
2588 free_pointer_color_update(context, wParam);
2589 }
2590 break;
2591
2592 case PointerUpdate_PointerNew:
2593 {
2594 POINTER_NEW_UPDATE* wParam = (POINTER_NEW_UPDATE*)msg->wParam;
2595 free_pointer_new_update(context, wParam);
2596 }
2597 break;
2598
2599 default:
2600 return FALSE;
2601 }
2602
2603 return TRUE;
2604}
2605
2606static BOOL update_message_process_pointer_update_class(rdpUpdateProxy* proxy, wMessage* msg,
2607 int type)
2608{
2609 if (!proxy || !msg)
2610 return FALSE;
2611
2612 switch (type)
2613 {
2614 case PointerUpdate_PointerPosition:
2615 return IFCALLRESULT(TRUE, proxy->PointerPosition, msg->context,
2616 (POINTER_POSITION_UPDATE*)msg->wParam);
2617
2618 case PointerUpdate_PointerSystem:
2619 return IFCALLRESULT(TRUE, proxy->PointerSystem, msg->context,
2620 (POINTER_SYSTEM_UPDATE*)msg->wParam);
2621
2622 case PointerUpdate_PointerColor:
2623 return IFCALLRESULT(TRUE, proxy->PointerColor, msg->context,
2624 (POINTER_COLOR_UPDATE*)msg->wParam);
2625
2626 case PointerUpdate_PointerNew:
2627 return IFCALLRESULT(TRUE, proxy->PointerNew, msg->context,
2628 (POINTER_NEW_UPDATE*)msg->wParam);
2629
2630 case PointerUpdate_PointerCached:
2631 return IFCALLRESULT(TRUE, proxy->PointerCached, msg->context,
2632 (POINTER_CACHED_UPDATE*)msg->wParam);
2633
2634 default:
2635 return FALSE;
2636 }
2637}
2638
2639static BOOL update_message_free_class(wMessage* msg, int msgClass, int msgType)
2640{
2641 BOOL status = FALSE;
2642
2643 switch (msgClass)
2644 {
2645 case Update_Class:
2646 status = update_message_free_update_class(msg, msgType);
2647 break;
2648
2649 case PrimaryUpdate_Class:
2650 status = update_message_free_primary_update_class(msg, msgType);
2651 break;
2652
2653 case SecondaryUpdate_Class:
2654 status = update_message_free_secondary_update_class(msg, msgType);
2655 break;
2656
2657 case AltSecUpdate_Class:
2658 status = update_message_free_altsec_update_class(msg, msgType);
2659 break;
2660
2661 case WindowUpdate_Class:
2662 status = update_message_free_window_update_class(msg, msgType);
2663 break;
2664
2665 case PointerUpdate_Class:
2666 status = update_message_free_pointer_update_class(msg, msgType);
2667 break;
2668
2669 default:
2670 break;
2671 }
2672
2673 if (!status)
2674 WLog_ERR(TAG, "Unknown message: class: %d type: %d", msgClass, msgType);
2675
2676 return status;
2677}
2678
2679static int update_message_process_class(rdpUpdateProxy* proxy, wMessage* msg, int msgClass,
2680 int msgType)
2681{
2682 BOOL status = FALSE;
2683
2684 switch (msgClass)
2685 {
2686 case Update_Class:
2687 status = update_message_process_update_class(proxy, msg, msgType);
2688 break;
2689
2690 case PrimaryUpdate_Class:
2691 status = update_message_process_primary_update_class(proxy, msg, msgType);
2692 break;
2693
2694 case SecondaryUpdate_Class:
2695 status = update_message_process_secondary_update_class(proxy, msg, msgType);
2696 break;
2697
2698 case AltSecUpdate_Class:
2699 status = update_message_process_altsec_update_class(proxy, msg, msgType);
2700 break;
2701
2702 case WindowUpdate_Class:
2703 status = update_message_process_window_update_class(proxy, msg, msgType);
2704 break;
2705
2706 case PointerUpdate_Class:
2707 status = update_message_process_pointer_update_class(proxy, msg, msgType);
2708 break;
2709
2710 default:
2711 status = FALSE;
2712 break;
2713 }
2714
2715 if (!status)
2716 {
2717 WLog_ERR(TAG, "message: class: %d type: %d failed", msgClass, msgType);
2718 return -1;
2719 }
2720
2721 return 0;
2722}
2723
2724int update_message_queue_process_message(rdpUpdate* update, wMessage* message)
2725{
2726 int status = 0;
2727 int msgClass = 0;
2728 int msgType = 0;
2729 rdp_update_internal* up = update_cast(update);
2730
2731 if (!update || !message)
2732 return -1;
2733
2734 if (message->id == WMQ_QUIT)
2735 return 0;
2736
2737 msgClass = GetMessageClass(message->id);
2738 msgType = GetMessageType(message->id);
2739 status = update_message_process_class(up->proxy, message, msgClass, msgType);
2740 update_message_free_class(message, msgClass, msgType);
2741
2742 if (status < 0)
2743 return -1;
2744
2745 return 1;
2746}
2747
2748int update_message_queue_free_message(wMessage* message)
2749{
2750 int msgClass = 0;
2751 int msgType = 0;
2752
2753 if (!message)
2754 return -1;
2755
2756 if (message->id == WMQ_QUIT)
2757 return 0;
2758
2759 msgClass = GetMessageClass(message->id);
2760 msgType = GetMessageType(message->id);
2761 return update_message_free_class(message, msgClass, msgType);
2762}
2763
2764int update_message_queue_process_pending_messages(rdpUpdate* update)
2765{
2766 int status = 1;
2767 wMessage message = WINPR_C_ARRAY_INIT;
2768 rdp_update_internal* up = update_cast(update);
2769
2770 wMessageQueue* queue = up->queue;
2771
2772 while (MessageQueue_Peek(queue, &message, TRUE))
2773 {
2774 status = update_message_queue_process_message(update, &message);
2775
2776 if (!status)
2777 break;
2778 }
2779
2780 return status;
2781}
2782
2783static BOOL update_message_register_interface(rdpUpdateProxy* message, rdpUpdate* update)
2784{
2785 rdpPrimaryUpdate* primary = nullptr;
2786 rdpSecondaryUpdate* secondary = nullptr;
2787 rdpAltSecUpdate* altsec = nullptr;
2788 rdpWindowUpdate* window = nullptr;
2789 rdpPointerUpdate* pointer = nullptr;
2790
2791 if (!message || !update)
2792 return FALSE;
2793
2794 primary = update->primary;
2795 secondary = update->secondary;
2796 altsec = update->altsec;
2797 window = update->window;
2798 pointer = update->pointer;
2799
2800 if (!primary || !secondary || !altsec || !window || !pointer)
2801 return FALSE;
2802
2803 /* Update */
2804 message->BeginPaint = update->BeginPaint;
2805 message->EndPaint = update->EndPaint;
2806 message->SetBounds = update->SetBounds;
2807 message->Synchronize = update->Synchronize;
2808 message->DesktopResize = update->DesktopResize;
2809 message->BitmapUpdate = update->BitmapUpdate;
2810 message->Palette = update->Palette;
2811 message->PlaySound = update->PlaySound;
2812 message->SetKeyboardIndicators = update->SetKeyboardIndicators;
2813 message->SetKeyboardImeStatus = update->SetKeyboardImeStatus;
2814 message->RefreshRect = update->RefreshRect;
2815 message->SuppressOutput = update->SuppressOutput;
2816 message->SurfaceCommand = update->SurfaceCommand;
2817 message->SurfaceBits = update->SurfaceBits;
2818 message->SurfaceFrameMarker = update->SurfaceFrameMarker;
2819 message->SurfaceFrameAcknowledge = update->SurfaceFrameAcknowledge;
2820 update->BeginPaint = update_message_BeginPaint;
2821 update->EndPaint = update_message_EndPaint;
2822 update->SetBounds = update_message_SetBounds;
2823 update->Synchronize = update_message_Synchronize;
2824 update->DesktopResize = update_message_DesktopResize;
2825 update->BitmapUpdate = update_message_BitmapUpdate;
2826 update->Palette = update_message_Palette;
2827 update->PlaySound = update_message_PlaySound;
2828 update->SetKeyboardIndicators = update_message_SetKeyboardIndicators;
2829 update->SetKeyboardImeStatus = update_message_SetKeyboardImeStatus;
2830 update->RefreshRect = update_message_RefreshRect;
2831 update->SuppressOutput = update_message_SuppressOutput;
2832 update->SurfaceCommand = update_message_SurfaceCommand;
2833 update->SurfaceBits = update_message_SurfaceBits;
2834 update->SurfaceFrameMarker = update_message_SurfaceFrameMarker;
2835 update->SurfaceFrameAcknowledge = update_message_SurfaceFrameAcknowledge;
2836 /* Primary Update */
2837 message->DstBlt = primary->DstBlt;
2838 message->PatBlt = primary->PatBlt;
2839 message->ScrBlt = primary->ScrBlt;
2840 message->OpaqueRect = primary->OpaqueRect;
2841 message->DrawNineGrid = primary->DrawNineGrid;
2842 message->MultiDstBlt = primary->MultiDstBlt;
2843 message->MultiPatBlt = primary->MultiPatBlt;
2844 message->MultiScrBlt = primary->MultiScrBlt;
2845 message->MultiOpaqueRect = primary->MultiOpaqueRect;
2846 message->MultiDrawNineGrid = primary->MultiDrawNineGrid;
2847 message->LineTo = primary->LineTo;
2848 message->Polyline = primary->Polyline;
2849 message->MemBlt = primary->MemBlt;
2850 message->Mem3Blt = primary->Mem3Blt;
2851 message->SaveBitmap = primary->SaveBitmap;
2852 message->GlyphIndex = primary->GlyphIndex;
2853 message->FastIndex = primary->FastIndex;
2854 message->FastGlyph = primary->FastGlyph;
2855 message->PolygonSC = primary->PolygonSC;
2856 message->PolygonCB = primary->PolygonCB;
2857 message->EllipseSC = primary->EllipseSC;
2858 message->EllipseCB = primary->EllipseCB;
2859 primary->DstBlt = update_message_DstBlt;
2860 primary->PatBlt = update_message_PatBlt;
2861 primary->ScrBlt = update_message_ScrBlt;
2862 primary->OpaqueRect = update_message_OpaqueRect;
2863 primary->DrawNineGrid = update_message_DrawNineGrid;
2864 primary->MultiDstBlt = update_message_MultiDstBlt;
2865 primary->MultiPatBlt = update_message_MultiPatBlt;
2866 primary->MultiScrBlt = update_message_MultiScrBlt;
2867 primary->MultiOpaqueRect = update_message_MultiOpaqueRect;
2868 primary->MultiDrawNineGrid = update_message_MultiDrawNineGrid;
2869 primary->LineTo = update_message_LineTo;
2870 primary->Polyline = update_message_Polyline;
2871 primary->MemBlt = update_message_MemBlt;
2872 primary->Mem3Blt = update_message_Mem3Blt;
2873 primary->SaveBitmap = update_message_SaveBitmap;
2874 primary->GlyphIndex = update_message_GlyphIndex;
2875 primary->FastIndex = update_message_FastIndex;
2876 primary->FastGlyph = update_message_FastGlyph;
2877 primary->PolygonSC = update_message_PolygonSC;
2878 primary->PolygonCB = update_message_PolygonCB;
2879 primary->EllipseSC = update_message_EllipseSC;
2880 primary->EllipseCB = update_message_EllipseCB;
2881 /* Secondary Update */
2882 message->CacheBitmap = secondary->CacheBitmap;
2883 message->CacheBitmapV2 = secondary->CacheBitmapV2;
2884 message->CacheBitmapV3 = secondary->CacheBitmapV3;
2885 message->CacheColorTable = secondary->CacheColorTable;
2886 message->CacheGlyph = secondary->CacheGlyph;
2887 message->CacheGlyphV2 = secondary->CacheGlyphV2;
2888 message->CacheBrush = secondary->CacheBrush;
2889 secondary->CacheBitmap = update_message_CacheBitmap;
2890 secondary->CacheBitmapV2 = update_message_CacheBitmapV2;
2891 secondary->CacheBitmapV3 = update_message_CacheBitmapV3;
2892 secondary->CacheColorTable = update_message_CacheColorTable;
2893 secondary->CacheGlyph = update_message_CacheGlyph;
2894 secondary->CacheGlyphV2 = update_message_CacheGlyphV2;
2895 secondary->CacheBrush = update_message_CacheBrush;
2896 /* Alternate Secondary Update */
2897 message->CreateOffscreenBitmap = altsec->CreateOffscreenBitmap;
2898 message->SwitchSurface = altsec->SwitchSurface;
2899 message->CreateNineGridBitmap = altsec->CreateNineGridBitmap;
2900 message->FrameMarker = altsec->FrameMarker;
2901 message->StreamBitmapFirst = altsec->StreamBitmapFirst;
2902 message->StreamBitmapNext = altsec->StreamBitmapNext;
2903 message->DrawGdiPlusFirst = altsec->DrawGdiPlusFirst;
2904 message->DrawGdiPlusNext = altsec->DrawGdiPlusNext;
2905 message->DrawGdiPlusEnd = altsec->DrawGdiPlusEnd;
2906 message->DrawGdiPlusCacheFirst = altsec->DrawGdiPlusCacheFirst;
2907 message->DrawGdiPlusCacheNext = altsec->DrawGdiPlusCacheNext;
2908 message->DrawGdiPlusCacheEnd = altsec->DrawGdiPlusCacheEnd;
2909 altsec->CreateOffscreenBitmap = update_message_CreateOffscreenBitmap;
2910 altsec->SwitchSurface = update_message_SwitchSurface;
2911 altsec->CreateNineGridBitmap = update_message_CreateNineGridBitmap;
2912 altsec->FrameMarker = update_message_FrameMarker;
2913 altsec->StreamBitmapFirst = update_message_StreamBitmapFirst;
2914 altsec->StreamBitmapNext = update_message_StreamBitmapNext;
2915 altsec->DrawGdiPlusFirst = update_message_DrawGdiPlusFirst;
2916 altsec->DrawGdiPlusNext = update_message_DrawGdiPlusNext;
2917 altsec->DrawGdiPlusEnd = update_message_DrawGdiPlusEnd;
2918 altsec->DrawGdiPlusCacheFirst = update_message_DrawGdiPlusCacheFirst;
2919 altsec->DrawGdiPlusCacheNext = update_message_DrawGdiPlusCacheNext;
2920 altsec->DrawGdiPlusCacheEnd = update_message_DrawGdiPlusCacheEnd;
2921 /* Window Update */
2922 message->WindowCreate = window->WindowCreate;
2923 message->WindowUpdate = window->WindowUpdate;
2924 message->WindowIcon = window->WindowIcon;
2925 message->WindowCachedIcon = window->WindowCachedIcon;
2926 message->WindowDelete = window->WindowDelete;
2927 message->NotifyIconCreate = window->NotifyIconCreate;
2928 message->NotifyIconUpdate = window->NotifyIconUpdate;
2929 message->NotifyIconDelete = window->NotifyIconDelete;
2930 message->MonitoredDesktop = window->MonitoredDesktop;
2931 message->NonMonitoredDesktop = window->NonMonitoredDesktop;
2932 window->WindowCreate = update_message_WindowCreate;
2933 window->WindowUpdate = update_message_WindowUpdate;
2934 window->WindowIcon = update_message_WindowIcon;
2935 window->WindowCachedIcon = update_message_WindowCachedIcon;
2936 window->WindowDelete = update_message_WindowDelete;
2937 window->NotifyIconCreate = update_message_NotifyIconCreate;
2938 window->NotifyIconUpdate = update_message_NotifyIconUpdate;
2939 window->NotifyIconDelete = update_message_NotifyIconDelete;
2940 window->MonitoredDesktop = update_message_MonitoredDesktop;
2941 window->NonMonitoredDesktop = update_message_NonMonitoredDesktop;
2942 /* Pointer Update */
2943 message->PointerPosition = pointer->PointerPosition;
2944 message->PointerSystem = pointer->PointerSystem;
2945 message->PointerColor = pointer->PointerColor;
2946 message->PointerLarge = pointer->PointerLarge;
2947 message->PointerNew = pointer->PointerNew;
2948 message->PointerCached = pointer->PointerCached;
2949 pointer->PointerPosition = update_message_PointerPosition;
2950 pointer->PointerSystem = update_message_PointerSystem;
2951 pointer->PointerColor = update_message_PointerColor;
2952 pointer->PointerLarge = update_message_PointerLarge;
2953 pointer->PointerNew = update_message_PointerNew;
2954 pointer->PointerCached = update_message_PointerCached;
2955 return TRUE;
2956}
2957
2958static DWORD WINAPI update_message_proxy_thread(LPVOID arg)
2959{
2960 rdpUpdate* update = (rdpUpdate*)arg;
2961 wMessage message = WINPR_C_ARRAY_INIT;
2962 rdp_update_internal* up = update_cast(update);
2963
2964 while (MessageQueue_Wait(up->queue))
2965 {
2966 int status = 0;
2967
2968 if (MessageQueue_Peek(up->queue, &message, TRUE))
2969 status = update_message_queue_process_message(update, &message);
2970
2971 if (!status)
2972 break;
2973 }
2974
2975 ExitThread(0);
2976 return 0;
2977}
2978
2979rdpUpdateProxy* update_message_proxy_new(rdpUpdate* update)
2980{
2981 rdpUpdateProxy* message = nullptr;
2982
2983 if (!update)
2984 return nullptr;
2985
2986 if (!(message = (rdpUpdateProxy*)calloc(1, sizeof(rdpUpdateProxy))))
2987 return nullptr;
2988
2989 message->update = update;
2990 update_message_register_interface(message, update);
2991
2992 if (!(message->thread =
2993 CreateThread(nullptr, 0, update_message_proxy_thread, update, 0, nullptr)))
2994 {
2995 WLog_ERR(TAG, "Failed to create proxy thread");
2996 free(message);
2997 return nullptr;
2998 }
2999
3000 return message;
3001}
3002
3003void update_message_proxy_free(rdpUpdateProxy* message)
3004{
3005 if (message)
3006 {
3007 rdp_update_internal* up = update_cast(message->update);
3008 if (MessageQueue_PostQuit(up->queue, 0))
3009 (void)WaitForSingleObject(message->thread, INFINITE);
3010
3011 (void)CloseHandle(message->thread);
3012 free(message);
3013 }
3014}
3015
3016/* Event Queue */
3017static int input_message_free_input_class(wMessage* msg, int type)
3018{
3019 int status = 0;
3020
3021 WINPR_UNUSED(msg);
3022
3023 switch (type)
3024 {
3025 case Input_SynchronizeEvent:
3026 break;
3027
3028 case Input_KeyboardEvent:
3029 break;
3030
3031 case Input_UnicodeKeyboardEvent:
3032 break;
3033
3034 case Input_MouseEvent:
3035 break;
3036
3037 case Input_ExtendedMouseEvent:
3038 break;
3039
3040 case Input_FocusInEvent:
3041 break;
3042
3043 case Input_KeyboardPauseEvent:
3044 break;
3045
3046 default:
3047 status = -1;
3048 break;
3049 }
3050
3051 return status;
3052}
3053
3054static int input_message_process_input_class(rdpInputProxy* proxy, wMessage* msg, int type)
3055{
3056 int status = 0;
3057
3058 if (!proxy || !msg)
3059 return -1;
3060
3061 switch (type)
3062 {
3063 case Input_SynchronizeEvent:
3064 IFCALL(proxy->SynchronizeEvent, msg->context, (UINT32)(size_t)msg->wParam);
3065 break;
3066
3067 case Input_KeyboardEvent:
3068 IFCALL(proxy->KeyboardEvent, msg->context, (UINT16)(size_t)msg->wParam,
3069 (UINT8)(size_t)msg->lParam);
3070 break;
3071
3072 case Input_UnicodeKeyboardEvent:
3073 IFCALL(proxy->UnicodeKeyboardEvent, msg->context, (UINT16)(size_t)msg->wParam,
3074 (UINT16)(size_t)msg->lParam);
3075 break;
3076
3077 case Input_MouseEvent:
3078 {
3079 UINT32 pos = 0;
3080 UINT16 x = 0;
3081 UINT16 y = 0;
3082 pos = (UINT32)(size_t)msg->lParam;
3083 x = ((pos & 0xFFFF0000) >> 16);
3084 y = (pos & 0x0000FFFF);
3085 IFCALL(proxy->MouseEvent, msg->context, (UINT16)(size_t)msg->wParam, x, y);
3086 }
3087 break;
3088
3089 case Input_ExtendedMouseEvent:
3090 {
3091 UINT32 pos = 0;
3092 UINT16 x = 0;
3093 UINT16 y = 0;
3094 pos = (UINT32)(size_t)msg->lParam;
3095 x = ((pos & 0xFFFF0000) >> 16);
3096 y = (pos & 0x0000FFFF);
3097 IFCALL(proxy->ExtendedMouseEvent, msg->context, (UINT16)(size_t)msg->wParam, x, y);
3098 }
3099 break;
3100
3101 case Input_FocusInEvent:
3102 IFCALL(proxy->FocusInEvent, msg->context, (UINT16)(size_t)msg->wParam);
3103 break;
3104
3105 case Input_KeyboardPauseEvent:
3106 IFCALL(proxy->KeyboardPauseEvent, msg->context);
3107 break;
3108
3109 default:
3110 status = -1;
3111 break;
3112 }
3113
3114 return status;
3115}
3116
3117static int input_message_free_class(wMessage* msg, int msgClass, int msgType)
3118{
3119 int status = 0;
3120
3121 switch (msgClass)
3122 {
3123 case Input_Class:
3124 status = input_message_free_input_class(msg, msgType);
3125 break;
3126
3127 default:
3128 status = -1;
3129 break;
3130 }
3131
3132 if (status < 0)
3133 WLog_ERR(TAG, "Unknown event: class: %d type: %d", msgClass, msgType);
3134
3135 return status;
3136}
3137
3138static int input_message_process_class(rdpInputProxy* proxy, wMessage* msg, int msgClass,
3139 int msgType)
3140{
3141 int status = 0;
3142
3143 switch (msgClass)
3144 {
3145 case Input_Class:
3146 status = input_message_process_input_class(proxy, msg, msgType);
3147 break;
3148
3149 default:
3150 status = -1;
3151 break;
3152 }
3153
3154 if (status < 0)
3155 WLog_ERR(TAG, "Unknown event: class: %d type: %d", msgClass, msgType);
3156
3157 return status;
3158}
3159
3160int input_message_queue_free_message(wMessage* message)
3161{
3162 int status = 0;
3163 int msgClass = 0;
3164 int msgType = 0;
3165
3166 if (!message)
3167 return -1;
3168
3169 if (message->id == WMQ_QUIT)
3170 return 0;
3171
3172 msgClass = GetMessageClass(message->id);
3173 msgType = GetMessageType(message->id);
3174 status = input_message_free_class(message, msgClass, msgType);
3175
3176 if (status < 0)
3177 return -1;
3178
3179 return 1;
3180}
3181
3182int input_message_queue_process_message(rdpInput* input, wMessage* message)
3183{
3184 int status = 0;
3185 int msgClass = 0;
3186 int msgType = 0;
3187 rdp_input_internal* in = input_cast(input);
3188
3189 if (!message)
3190 return -1;
3191
3192 if (message->id == WMQ_QUIT)
3193 return 0;
3194
3195 msgClass = GetMessageClass(message->id);
3196 msgType = GetMessageType(message->id);
3197 status = input_message_process_class(in->proxy, message, msgClass, msgType);
3198 input_message_free_class(message, msgClass, msgType);
3199
3200 if (status < 0)
3201 return -1;
3202
3203 return 1;
3204}
3205
3206int input_message_queue_process_pending_messages(rdpInput* input)
3207{
3208 int status = 1;
3209 wMessage message = WINPR_C_ARRAY_INIT;
3210 rdp_input_internal* in = input_cast(input);
3211
3212 if (!in->queue)
3213 return -1;
3214
3215 wMessageQueue* queue = in->queue;
3216
3217 while (MessageQueue_Peek(queue, &message, TRUE))
3218 {
3219 status = input_message_queue_process_message(input, &message);
3220
3221 if (!status)
3222 break;
3223 }
3224
3225 return status;
3226}