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