FreeRDP
Loading...
Searching...
No Matches
mouse_cursor_main.c
1
20#include <freerdp/config.h>
21
22#include <freerdp/freerdp.h>
23#include <freerdp/channels/log.h>
24#include <freerdp/server/rdpemsc.h>
25
26#define TAG CHANNELS_TAG("rdpemsc.server")
27
28typedef enum
29{
30 MOUSE_CURSOR_INITIAL,
31 MOUSE_CURSOR_OPENED,
32} eMouseCursorChannelState;
33
34typedef struct
35{
36 MouseCursorServerContext context;
37
38 HANDLE stopEvent;
39
40 HANDLE thread;
41 void* mouse_cursor_channel;
42
43 DWORD SessionId;
44
45 BOOL isOpened;
46 BOOL externalThread;
47
48 /* Channel state */
49 eMouseCursorChannelState state;
50
51 wStream* buffer;
52} mouse_cursor_server;
53
54static UINT mouse_cursor_server_initialize(MouseCursorServerContext* context, BOOL externalThread)
55{
56 UINT error = CHANNEL_RC_OK;
57 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
58
59 WINPR_ASSERT(mouse_cursor);
60
61 if (mouse_cursor->isOpened)
62 {
63 WLog_WARN(TAG, "Application error: Mouse Cursor channel already initialized, "
64 "calling in this state is not possible!");
65 return ERROR_INVALID_STATE;
66 }
67
68 mouse_cursor->externalThread = externalThread;
69
70 return error;
71}
72
73static UINT mouse_cursor_server_open_channel(mouse_cursor_server* mouse_cursor)
74{
75 MouseCursorServerContext* context = NULL;
76 DWORD Error = ERROR_SUCCESS;
77 DWORD BytesReturned = 0;
78 PULONG pSessionId = NULL;
79 UINT32 channelId = 0;
80 BOOL status = TRUE;
81
82 WINPR_ASSERT(mouse_cursor);
83 context = &mouse_cursor->context;
84 WINPR_ASSERT(context);
85
86 if (WTSQuerySessionInformationA(mouse_cursor->context.vcm, WTS_CURRENT_SESSION, WTSSessionId,
87 (LPSTR*)&pSessionId, &BytesReturned) == FALSE)
88 {
89 WLog_ERR(TAG, "WTSQuerySessionInformationA failed!");
90 return ERROR_INTERNAL_ERROR;
91 }
92
93 mouse_cursor->SessionId = (DWORD)*pSessionId;
94 WTSFreeMemory(pSessionId);
95
96 mouse_cursor->mouse_cursor_channel = WTSVirtualChannelOpenEx(
97 mouse_cursor->SessionId, RDPEMSC_DVC_CHANNEL_NAME, WTS_CHANNEL_OPTION_DYNAMIC);
98 if (!mouse_cursor->mouse_cursor_channel)
99 {
100 Error = GetLastError();
101 WLog_ERR(TAG, "WTSVirtualChannelOpenEx failed with error %" PRIu32 "!", Error);
102 return Error;
103 }
104
105 channelId = WTSChannelGetIdByHandle(mouse_cursor->mouse_cursor_channel);
106
107 IFCALLRET(context->ChannelIdAssigned, status, context, channelId);
108 if (!status)
109 {
110 WLog_ERR(TAG, "context->ChannelIdAssigned failed!");
111 return ERROR_INTERNAL_ERROR;
112 }
113
114 return Error;
115}
116
117static BOOL read_cap_set(wStream* s, wArrayList* capsSets)
118{
119 RDP_MOUSE_CURSOR_CAPSET* capsSet = NULL;
120 UINT32 signature = 0;
121 UINT32 size = 0;
122 size_t capsDataSize = 0;
123
124 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
125 return FALSE;
126
127 Stream_Read_UINT32(s, signature);
128
129 RDP_MOUSE_CURSOR_CAPVERSION version = RDP_MOUSE_CURSOR_CAPVERSION_INVALID;
130 {
131 const UINT32 val = Stream_Get_UINT32(s);
132 switch (val)
133 {
136 break;
137 default:
138 WLog_WARN(TAG, "Received caps set with unknown version %" PRIu32, val);
139 break;
140 }
141 }
142
143 Stream_Read_UINT32(s, size);
144
145 if (size < 12)
146 {
147 WLog_ERR(TAG, "Size of caps set is invalid: %u", size);
148 return FALSE;
149 }
150
151 capsDataSize = size - 12;
152 if (!Stream_CheckAndLogRequiredLength(TAG, s, capsDataSize))
153 return FALSE;
154
155 switch (version)
156 {
158 {
159 RDP_MOUSE_CURSOR_CAPSET_VERSION1* capsSetV1 = NULL;
160
161 capsSetV1 = calloc(1, sizeof(RDP_MOUSE_CURSOR_CAPSET_VERSION1));
162 if (!capsSetV1)
163 return FALSE;
164
165 capsSet = (RDP_MOUSE_CURSOR_CAPSET*)capsSetV1;
166 break;
167 }
168 default:
169 Stream_Seek(s, capsDataSize);
170 return TRUE;
171 }
172 WINPR_ASSERT(capsSet);
173
174 capsSet->signature = signature;
175 capsSet->version = version;
176 capsSet->size = size;
177
178 if (!ArrayList_Append(capsSets, capsSet))
179 {
180 WLog_ERR(TAG, "Failed to append caps set to arraylist");
181 free(capsSet);
182 return FALSE;
183 }
184
185 // NOLINTNEXTLINE(clang-analyzer-unix.Malloc): ArrayList_Append owns capsSet
186 return TRUE;
187}
188
189static UINT mouse_cursor_server_recv_cs_caps_advertise(MouseCursorServerContext* context,
190 wStream* s,
191 const RDP_MOUSE_CURSOR_HEADER* header)
192{
193 UINT error = CHANNEL_RC_OK;
194
195 WINPR_ASSERT(context);
196 WINPR_ASSERT(s);
197 WINPR_ASSERT(header);
198
199 /* There must be at least one capability set present */
200 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
201 return ERROR_NO_DATA;
202
204 .header = *header,
205 .capsSets = ArrayList_New(FALSE),
206 };
207
208 if (!pdu.capsSets)
209 {
210 WLog_ERR(TAG, "Failed to allocate arraylist");
211 return ERROR_NOT_ENOUGH_MEMORY;
212 }
213
214 wObject* aobj = ArrayList_Object(pdu.capsSets);
215 WINPR_ASSERT(aobj);
216 aobj->fnObjectFree = free;
217
218 while (Stream_GetRemainingLength(s) > 0)
219 {
220 if (!read_cap_set(s, pdu.capsSets))
221 {
222 ArrayList_Free(pdu.capsSets);
223 return ERROR_INVALID_DATA;
224 }
225 }
226
227 IFCALLRET(context->CapsAdvertise, error, context, &pdu);
228 if (error)
229 WLog_ERR(TAG, "context->CapsAdvertise failed with error %" PRIu32 "", error);
230
231 ArrayList_Free(pdu.capsSets);
232
233 return error;
234}
235
236static UINT mouse_cursor_process_message(mouse_cursor_server* mouse_cursor)
237{
238 BOOL rc = 0;
239 UINT error = ERROR_INTERNAL_ERROR;
240 ULONG BytesReturned = 0;
241 wStream* s = NULL;
242
243 WINPR_ASSERT(mouse_cursor);
244 WINPR_ASSERT(mouse_cursor->mouse_cursor_channel);
245
246 s = mouse_cursor->buffer;
247 WINPR_ASSERT(s);
248
249 Stream_SetPosition(s, 0);
250 rc = WTSVirtualChannelRead(mouse_cursor->mouse_cursor_channel, 0, NULL, 0, &BytesReturned);
251 if (!rc)
252 goto out;
253
254 if (BytesReturned < 1)
255 {
256 error = CHANNEL_RC_OK;
257 goto out;
258 }
259
260 if (!Stream_EnsureRemainingCapacity(s, BytesReturned))
261 {
262 WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
263 error = CHANNEL_RC_NO_MEMORY;
264 goto out;
265 }
266
267 if (WTSVirtualChannelRead(mouse_cursor->mouse_cursor_channel, 0, Stream_BufferAs(s, char),
268 (ULONG)Stream_Capacity(s), &BytesReturned) == FALSE)
269 {
270 WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
271 goto out;
272 }
273
274 Stream_SetLength(s, BytesReturned);
275 if (!Stream_CheckAndLogRequiredLength(TAG, s, RDPEMSC_HEADER_SIZE))
276 return ERROR_NO_DATA;
277
278 {
279 const UINT8 pduType = Stream_Get_UINT8(s);
280 const UINT8 updateType = Stream_Get_UINT8(s);
281 switch (updateType)
282 {
283 case TS_UPDATETYPE_MOUSEPTR_SYSTEM_NULL:
284 case TS_UPDATETYPE_MOUSEPTR_SYSTEM_DEFAULT:
285 case TS_UPDATETYPE_MOUSEPTR_POSITION:
286 case TS_UPDATETYPE_MOUSEPTR_CACHED:
287 case TS_UPDATETYPE_MOUSEPTR_POINTER:
288 case TS_UPDATETYPE_MOUSEPTR_LARGE_POINTER:
289 break;
290 default:
291 WLog_ERR(TAG,
292 "mouse_cursor_process_message: unknown or invalid updateType %" PRIu8 "",
293 updateType);
294 return ERROR_INVALID_DATA;
295 }
296
297 RDP_MOUSE_CURSOR_HEADER header = { .updateType = (TS_UPDATETYPE_MOUSEPTR)updateType,
298 .reserved = Stream_Get_UINT16(s),
299 .pduType = PDUTYPE_EMSC_RESERVED };
300
301 switch (pduType)
302 {
303 case PDUTYPE_CS_CAPS_ADVERTISE:
304 header.pduType = PDUTYPE_CS_CAPS_ADVERTISE;
305 error =
306 mouse_cursor_server_recv_cs_caps_advertise(&mouse_cursor->context, s, &header);
307 break;
308 default:
309 WLog_ERR(TAG, "mouse_cursor_process_message: unknown or invalid pduType %" PRIu8 "",
310 pduType);
311 break;
312 }
313 }
314
315out:
316 if (error)
317 WLog_ERR(TAG, "Response failed with error %" PRIu32 "!", error);
318
319 return error;
320}
321
322static UINT mouse_cursor_server_context_poll_int(MouseCursorServerContext* context)
323{
324 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
325 UINT error = ERROR_INTERNAL_ERROR;
326
327 WINPR_ASSERT(mouse_cursor);
328
329 switch (mouse_cursor->state)
330 {
331 case MOUSE_CURSOR_INITIAL:
332 error = mouse_cursor_server_open_channel(mouse_cursor);
333 if (error)
334 WLog_ERR(TAG, "mouse_cursor_server_open_channel failed with error %" PRIu32 "!",
335 error);
336 else
337 mouse_cursor->state = MOUSE_CURSOR_OPENED;
338 break;
339 case MOUSE_CURSOR_OPENED:
340 error = mouse_cursor_process_message(mouse_cursor);
341 break;
342 default:
343 break;
344 }
345
346 return error;
347}
348
349static HANDLE mouse_cursor_server_get_channel_handle(mouse_cursor_server* mouse_cursor)
350{
351 void* buffer = NULL;
352 DWORD BytesReturned = 0;
353 HANDLE ChannelEvent = NULL;
354
355 WINPR_ASSERT(mouse_cursor);
356
357 if (WTSVirtualChannelQuery(mouse_cursor->mouse_cursor_channel, WTSVirtualEventHandle, &buffer,
358 &BytesReturned) == TRUE)
359 {
360 if (BytesReturned == sizeof(HANDLE))
361 ChannelEvent = *(HANDLE*)buffer;
362
363 WTSFreeMemory(buffer);
364 }
365
366 return ChannelEvent;
367}
368
369static DWORD WINAPI mouse_cursor_server_thread_func(LPVOID arg)
370{
371 DWORD nCount = 0;
372 HANDLE events[2] = { 0 };
373 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)arg;
374 UINT error = CHANNEL_RC_OK;
375 DWORD status = 0;
376
377 WINPR_ASSERT(mouse_cursor);
378
379 nCount = 0;
380 events[nCount++] = mouse_cursor->stopEvent;
381
382 while ((error == CHANNEL_RC_OK) && (WaitForSingleObject(events[0], 0) != WAIT_OBJECT_0))
383 {
384 switch (mouse_cursor->state)
385 {
386 case MOUSE_CURSOR_INITIAL:
387 error = mouse_cursor_server_context_poll_int(&mouse_cursor->context);
388 if (error == CHANNEL_RC_OK)
389 {
390 events[1] = mouse_cursor_server_get_channel_handle(mouse_cursor);
391 nCount = 2;
392 }
393 break;
394 case MOUSE_CURSOR_OPENED:
395 status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
396 switch (status)
397 {
398 case WAIT_OBJECT_0:
399 break;
400 case WAIT_OBJECT_0 + 1:
401 case WAIT_TIMEOUT:
402 error = mouse_cursor_server_context_poll_int(&mouse_cursor->context);
403 break;
404
405 case WAIT_FAILED:
406 default:
407 error = ERROR_INTERNAL_ERROR;
408 break;
409 }
410 break;
411 default:
412 break;
413 }
414 }
415
416 (void)WTSVirtualChannelClose(mouse_cursor->mouse_cursor_channel);
417 mouse_cursor->mouse_cursor_channel = NULL;
418
419 if (error && mouse_cursor->context.rdpcontext)
420 setChannelError(mouse_cursor->context.rdpcontext, error,
421 "mouse_cursor_server_thread_func reported an error");
422
423 ExitThread(error);
424 return error;
425}
426
427static UINT mouse_cursor_server_open(MouseCursorServerContext* context)
428{
429 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
430
431 WINPR_ASSERT(mouse_cursor);
432
433 if (!mouse_cursor->externalThread && (mouse_cursor->thread == NULL))
434 {
435 mouse_cursor->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
436 if (!mouse_cursor->stopEvent)
437 {
438 WLog_ERR(TAG, "CreateEvent failed!");
439 return ERROR_INTERNAL_ERROR;
440 }
441
442 mouse_cursor->thread =
443 CreateThread(NULL, 0, mouse_cursor_server_thread_func, mouse_cursor, 0, NULL);
444 if (!mouse_cursor->thread)
445 {
446 WLog_ERR(TAG, "CreateThread failed!");
447 (void)CloseHandle(mouse_cursor->stopEvent);
448 mouse_cursor->stopEvent = NULL;
449 return ERROR_INTERNAL_ERROR;
450 }
451 }
452 mouse_cursor->isOpened = TRUE;
453
454 return CHANNEL_RC_OK;
455}
456
457static UINT mouse_cursor_server_close(MouseCursorServerContext* context)
458{
459 UINT error = CHANNEL_RC_OK;
460 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
461
462 WINPR_ASSERT(mouse_cursor);
463
464 if (!mouse_cursor->externalThread && mouse_cursor->thread)
465 {
466 (void)SetEvent(mouse_cursor->stopEvent);
467
468 if (WaitForSingleObject(mouse_cursor->thread, INFINITE) == WAIT_FAILED)
469 {
470 error = GetLastError();
471 WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error);
472 return error;
473 }
474
475 (void)CloseHandle(mouse_cursor->thread);
476 (void)CloseHandle(mouse_cursor->stopEvent);
477 mouse_cursor->thread = NULL;
478 mouse_cursor->stopEvent = NULL;
479 }
480 if (mouse_cursor->externalThread)
481 {
482 if (mouse_cursor->state != MOUSE_CURSOR_INITIAL)
483 {
484 (void)WTSVirtualChannelClose(mouse_cursor->mouse_cursor_channel);
485 mouse_cursor->mouse_cursor_channel = NULL;
486 mouse_cursor->state = MOUSE_CURSOR_INITIAL;
487 }
488 }
489 mouse_cursor->isOpened = FALSE;
490
491 return error;
492}
493
494static UINT mouse_cursor_server_context_poll(MouseCursorServerContext* context)
495{
496 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
497
498 WINPR_ASSERT(mouse_cursor);
499
500 if (!mouse_cursor->externalThread)
501 return ERROR_INTERNAL_ERROR;
502
503 return mouse_cursor_server_context_poll_int(context);
504}
505
506static BOOL mouse_cursor_server_context_handle(MouseCursorServerContext* context, HANDLE* handle)
507{
508 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
509
510 WINPR_ASSERT(mouse_cursor);
511 WINPR_ASSERT(handle);
512
513 if (!mouse_cursor->externalThread)
514 return FALSE;
515 if (mouse_cursor->state == MOUSE_CURSOR_INITIAL)
516 return FALSE;
517
518 *handle = mouse_cursor_server_get_channel_handle(mouse_cursor);
519
520 return TRUE;
521}
522
523static wStream* mouse_cursor_server_packet_new(size_t size, RDP_MOUSE_CURSOR_PDUTYPE pduType,
524 const RDP_MOUSE_CURSOR_HEADER* header)
525{
526 wStream* s = NULL;
527
528 /* Allocate what we need plus header bytes */
529 s = Stream_New(NULL, size + RDPEMSC_HEADER_SIZE);
530 if (!s)
531 {
532 WLog_ERR(TAG, "Stream_New failed!");
533 return NULL;
534 }
535
536 WINPR_ASSERT(pduType <= UINT8_MAX);
537 Stream_Write_UINT8(s, (BYTE)pduType);
538
539 WINPR_ASSERT(header->updateType <= UINT8_MAX);
540 Stream_Write_UINT8(s, (BYTE)header->updateType);
541 Stream_Write_UINT16(s, header->reserved);
542
543 return s;
544}
545
546static UINT mouse_cursor_server_packet_send(MouseCursorServerContext* context, wStream* s)
547{
548 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
549 UINT error = CHANNEL_RC_OK;
550 ULONG written = 0;
551
552 WINPR_ASSERT(mouse_cursor);
553 WINPR_ASSERT(s);
554
555 const size_t pos = Stream_GetPosition(s);
556
557 WINPR_ASSERT(pos <= UINT32_MAX);
558 if (!WTSVirtualChannelWrite(mouse_cursor->mouse_cursor_channel, Stream_BufferAs(s, char),
559 (ULONG)pos, &written))
560 {
561 WLog_ERR(TAG, "WTSVirtualChannelWrite failed!");
562 error = ERROR_INTERNAL_ERROR;
563 goto out;
564 }
565
566 if (written < Stream_GetPosition(s))
567 {
568 WLog_WARN(TAG, "Unexpected bytes written: %" PRIu32 "/%" PRIuz "", written,
569 Stream_GetPosition(s));
570 }
571
572out:
573 Stream_Free(s, TRUE);
574 return error;
575}
576
577static UINT
578mouse_cursor_server_send_sc_caps_confirm(MouseCursorServerContext* context,
579 const RDP_MOUSE_CURSOR_CAPS_CONFIRM_PDU* capsConfirm)
580{
581 RDP_MOUSE_CURSOR_CAPSET* capsetHeader = NULL;
582 RDP_MOUSE_CURSOR_PDUTYPE pduType = PDUTYPE_EMSC_RESERVED;
583 size_t caps_size = 0;
584 wStream* s = NULL;
585
586 WINPR_ASSERT(context);
587 WINPR_ASSERT(capsConfirm);
588
589 capsetHeader = capsConfirm->capsSet;
590 WINPR_ASSERT(capsetHeader);
591
592 caps_size = 12;
593 switch (capsetHeader->version)
594 {
596 break;
597 default:
598 WINPR_ASSERT(FALSE);
599 break;
600 }
601
602 pduType = PDUTYPE_SC_CAPS_CONFIRM;
603 s = mouse_cursor_server_packet_new(caps_size, pduType, &capsConfirm->header);
604 if (!s)
605 return ERROR_NOT_ENOUGH_MEMORY;
606
607 Stream_Write_UINT32(s, capsetHeader->signature);
608 Stream_Write_UINT32(s, capsetHeader->version);
609 Stream_Write_UINT32(s, capsetHeader->size);
610
611 /* Write capsData */
612 switch (capsetHeader->version)
613 {
615 break;
616 default:
617 WINPR_ASSERT(FALSE);
618 break;
619 }
620
621 return mouse_cursor_server_packet_send(context, s);
622}
623
624static void write_point16(wStream* s, const TS_POINT16* point16)
625{
626 WINPR_ASSERT(s);
627 WINPR_ASSERT(point16);
628
629 Stream_Write_UINT16(s, point16->xPos);
630 Stream_Write_UINT16(s, point16->yPos);
631}
632
633static UINT mouse_cursor_server_send_sc_mouseptr_update(
634 MouseCursorServerContext* context, const RDP_MOUSE_CURSOR_MOUSEPTR_UPDATE_PDU* mouseptrUpdate)
635{
636 TS_POINT16* position = NULL;
637 TS_POINTERATTRIBUTE* pointerAttribute = NULL;
638 TS_LARGEPOINTERATTRIBUTE* largePointerAttribute = NULL;
639 RDP_MOUSE_CURSOR_PDUTYPE pduType = PDUTYPE_EMSC_RESERVED;
640 size_t update_size = 0;
641 wStream* s = NULL;
642
643 WINPR_ASSERT(context);
644 WINPR_ASSERT(mouseptrUpdate);
645
646 position = mouseptrUpdate->position;
647 pointerAttribute = mouseptrUpdate->pointerAttribute;
648 largePointerAttribute = mouseptrUpdate->largePointerAttribute;
649
650 switch (mouseptrUpdate->header.updateType)
651 {
652 case TS_UPDATETYPE_MOUSEPTR_SYSTEM_NULL:
653 case TS_UPDATETYPE_MOUSEPTR_SYSTEM_DEFAULT:
654 update_size = 0;
655 break;
656 case TS_UPDATETYPE_MOUSEPTR_POSITION:
657 WINPR_ASSERT(position);
658 update_size = 4;
659 break;
660 case TS_UPDATETYPE_MOUSEPTR_CACHED:
661 WINPR_ASSERT(mouseptrUpdate->cachedPointerIndex);
662 update_size = 2;
663 break;
664 case TS_UPDATETYPE_MOUSEPTR_POINTER:
665 WINPR_ASSERT(pointerAttribute);
666 update_size = 2 + 2 + 4 + 2 + 2 + 2 + 2;
667 update_size += pointerAttribute->lengthAndMask;
668 update_size += pointerAttribute->lengthXorMask;
669 break;
670 case TS_UPDATETYPE_MOUSEPTR_LARGE_POINTER:
671 WINPR_ASSERT(largePointerAttribute);
672 update_size = 2 + 2 + 4 + 2 + 2 + 4 + 4;
673 update_size += largePointerAttribute->lengthAndMask;
674 update_size += largePointerAttribute->lengthXorMask;
675 break;
676 default:
677 WINPR_ASSERT(FALSE);
678 break;
679 }
680
681 pduType = PDUTYPE_SC_MOUSEPTR_UPDATE;
682 s = mouse_cursor_server_packet_new(update_size, pduType, &mouseptrUpdate->header);
683 if (!s)
684 return ERROR_NOT_ENOUGH_MEMORY;
685
686 switch (mouseptrUpdate->header.updateType)
687 {
688 case TS_UPDATETYPE_MOUSEPTR_SYSTEM_NULL:
689 case TS_UPDATETYPE_MOUSEPTR_SYSTEM_DEFAULT:
690 break;
691 case TS_UPDATETYPE_MOUSEPTR_POSITION:
692 write_point16(s, position);
693 break;
694 case TS_UPDATETYPE_MOUSEPTR_CACHED:
695 Stream_Write_UINT16(s, *mouseptrUpdate->cachedPointerIndex);
696 break;
697 case TS_UPDATETYPE_MOUSEPTR_POINTER:
698 Stream_Write_UINT16(s, pointerAttribute->xorBpp);
699 Stream_Write_UINT16(s, pointerAttribute->cacheIndex);
700 write_point16(s, &pointerAttribute->hotSpot);
701 Stream_Write_UINT16(s, pointerAttribute->width);
702 Stream_Write_UINT16(s, pointerAttribute->height);
703 Stream_Write_UINT16(s, pointerAttribute->lengthAndMask);
704 Stream_Write_UINT16(s, pointerAttribute->lengthXorMask);
705 Stream_Write(s, pointerAttribute->xorMaskData, pointerAttribute->lengthXorMask);
706 Stream_Write(s, pointerAttribute->andMaskData, pointerAttribute->lengthAndMask);
707 break;
708 case TS_UPDATETYPE_MOUSEPTR_LARGE_POINTER:
709 Stream_Write_UINT16(s, largePointerAttribute->xorBpp);
710 Stream_Write_UINT16(s, largePointerAttribute->cacheIndex);
711 write_point16(s, &largePointerAttribute->hotSpot);
712 Stream_Write_UINT16(s, largePointerAttribute->width);
713 Stream_Write_UINT16(s, largePointerAttribute->height);
714 Stream_Write_UINT32(s, largePointerAttribute->lengthAndMask);
715 Stream_Write_UINT32(s, largePointerAttribute->lengthXorMask);
716 Stream_Write(s, largePointerAttribute->xorMaskData,
717 largePointerAttribute->lengthXorMask);
718 Stream_Write(s, largePointerAttribute->andMaskData,
719 largePointerAttribute->lengthAndMask);
720 break;
721 default:
722 WINPR_ASSERT(FALSE);
723 break;
724 }
725
726 return mouse_cursor_server_packet_send(context, s);
727}
728
729MouseCursorServerContext* mouse_cursor_server_context_new(HANDLE vcm)
730{
731 mouse_cursor_server* mouse_cursor =
732 (mouse_cursor_server*)calloc(1, sizeof(mouse_cursor_server));
733
734 if (!mouse_cursor)
735 return NULL;
736
737 mouse_cursor->context.vcm = vcm;
738 mouse_cursor->context.Initialize = mouse_cursor_server_initialize;
739 mouse_cursor->context.Open = mouse_cursor_server_open;
740 mouse_cursor->context.Close = mouse_cursor_server_close;
741 mouse_cursor->context.Poll = mouse_cursor_server_context_poll;
742 mouse_cursor->context.ChannelHandle = mouse_cursor_server_context_handle;
743
744 mouse_cursor->context.CapsConfirm = mouse_cursor_server_send_sc_caps_confirm;
745 mouse_cursor->context.MouseptrUpdate = mouse_cursor_server_send_sc_mouseptr_update;
746
747 mouse_cursor->buffer = Stream_New(NULL, 4096);
748 if (!mouse_cursor->buffer)
749 goto fail;
750
751 return &mouse_cursor->context;
752fail:
753 WINPR_PRAGMA_DIAG_PUSH
754 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
755 mouse_cursor_server_context_free(&mouse_cursor->context);
756 WINPR_PRAGMA_DIAG_POP
757 return NULL;
758}
759
760void mouse_cursor_server_context_free(MouseCursorServerContext* context)
761{
762 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
763
764 if (mouse_cursor)
765 {
766 mouse_cursor_server_close(context);
767 Stream_Free(mouse_cursor->buffer, TRUE);
768 }
769
770 free(mouse_cursor);
771}
RDP_MOUSE_CURSOR_CAPVERSION
@ RDP_MOUSE_CURSOR_CAPVERSION_1
This struct contains function pointer to initialize/free objects.
Definition collections.h:52
OBJECT_FREE_FN fnObjectFree
Definition collections.h:58