Coverage Report

Created: 2026-03-04 06:17

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