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