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 = nullptr;
76 DWORD Error = ERROR_SUCCESS;
77 DWORD BytesReturned = 0;
78 PULONG pSessionId = nullptr;
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 = nullptr;
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 = nullptr;
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 = nullptr;
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_ResetPosition(s);
250 rc = WTSVirtualChannelRead(mouse_cursor->mouse_cursor_channel, 0, nullptr, 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 if (!Stream_SetLength(s, BytesReturned))
275 goto out;
276
277 if (!Stream_CheckAndLogRequiredLength(TAG, s, RDPEMSC_HEADER_SIZE))
278 return ERROR_NO_DATA;
279
280 {
281 const UINT8 pduType = Stream_Get_UINT8(s);
282 const UINT8 updateType = Stream_Get_UINT8(s);
283 switch (updateType)
284 {
285 case TS_UPDATETYPE_MOUSEPTR_SYSTEM_NULL:
286 case TS_UPDATETYPE_MOUSEPTR_SYSTEM_DEFAULT:
287 case TS_UPDATETYPE_MOUSEPTR_POSITION:
288 case TS_UPDATETYPE_MOUSEPTR_CACHED:
289 case TS_UPDATETYPE_MOUSEPTR_POINTER:
290 case TS_UPDATETYPE_MOUSEPTR_LARGE_POINTER:
291 break;
292 default:
293 WLog_ERR(TAG,
294 "mouse_cursor_process_message: unknown or invalid updateType %" PRIu8 "",
295 updateType);
296 return ERROR_INVALID_DATA;
297 }
298
299 RDP_MOUSE_CURSOR_HEADER header = { .updateType = (TS_UPDATETYPE_MOUSEPTR)updateType,
300 .reserved = Stream_Get_UINT16(s),
301 .pduType = PDUTYPE_EMSC_RESERVED };
302
303 switch (pduType)
304 {
305 case PDUTYPE_CS_CAPS_ADVERTISE:
306 header.pduType = PDUTYPE_CS_CAPS_ADVERTISE;
307 error =
308 mouse_cursor_server_recv_cs_caps_advertise(&mouse_cursor->context, s, &header);
309 break;
310 default:
311 WLog_ERR(TAG, "mouse_cursor_process_message: unknown or invalid pduType %" PRIu8 "",
312 pduType);
313 break;
314 }
315 }
316
317out:
318 if (error)
319 WLog_ERR(TAG, "Response failed with error %" PRIu32 "!", error);
320
321 return error;
322}
323
324static UINT mouse_cursor_server_context_poll_int(MouseCursorServerContext* context)
325{
326 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
327 UINT error = ERROR_INTERNAL_ERROR;
328
329 WINPR_ASSERT(mouse_cursor);
330
331 switch (mouse_cursor->state)
332 {
333 case MOUSE_CURSOR_INITIAL:
334 error = mouse_cursor_server_open_channel(mouse_cursor);
335 if (error)
336 WLog_ERR(TAG, "mouse_cursor_server_open_channel failed with error %" PRIu32 "!",
337 error);
338 else
339 mouse_cursor->state = MOUSE_CURSOR_OPENED;
340 break;
341 case MOUSE_CURSOR_OPENED:
342 error = mouse_cursor_process_message(mouse_cursor);
343 break;
344 default:
345 break;
346 }
347
348 return error;
349}
350
351static HANDLE mouse_cursor_server_get_channel_handle(mouse_cursor_server* mouse_cursor)
352{
353 void* buffer = nullptr;
354 DWORD BytesReturned = 0;
355 HANDLE ChannelEvent = nullptr;
356
357 WINPR_ASSERT(mouse_cursor);
358
359 if (WTSVirtualChannelQuery(mouse_cursor->mouse_cursor_channel, WTSVirtualEventHandle, &buffer,
360 &BytesReturned) == TRUE)
361 {
362 if (BytesReturned == sizeof(HANDLE))
363 ChannelEvent = *(HANDLE*)buffer;
364
365 WTSFreeMemory(buffer);
366 }
367
368 return ChannelEvent;
369}
370
371static DWORD WINAPI mouse_cursor_server_thread_func(LPVOID arg)
372{
373 DWORD nCount = 0;
374 HANDLE events[2] = WINPR_C_ARRAY_INIT;
375 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)arg;
376 UINT error = CHANNEL_RC_OK;
377 DWORD status = 0;
378
379 WINPR_ASSERT(mouse_cursor);
380
381 nCount = 0;
382 events[nCount++] = mouse_cursor->stopEvent;
383
384 while ((error == CHANNEL_RC_OK) && (WaitForSingleObject(events[0], 0) != WAIT_OBJECT_0))
385 {
386 switch (mouse_cursor->state)
387 {
388 case MOUSE_CURSOR_INITIAL:
389 error = mouse_cursor_server_context_poll_int(&mouse_cursor->context);
390 if (error == CHANNEL_RC_OK)
391 {
392 events[1] = mouse_cursor_server_get_channel_handle(mouse_cursor);
393 nCount = 2;
394 }
395 break;
396 case MOUSE_CURSOR_OPENED:
397 status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
398 switch (status)
399 {
400 case WAIT_OBJECT_0:
401 break;
402 case WAIT_OBJECT_0 + 1:
403 case WAIT_TIMEOUT:
404 error = mouse_cursor_server_context_poll_int(&mouse_cursor->context);
405 break;
406
407 case WAIT_FAILED:
408 default:
409 error = ERROR_INTERNAL_ERROR;
410 break;
411 }
412 break;
413 default:
414 break;
415 }
416 }
417
418 (void)WTSVirtualChannelClose(mouse_cursor->mouse_cursor_channel);
419 mouse_cursor->mouse_cursor_channel = nullptr;
420
421 if (error && mouse_cursor->context.rdpcontext)
422 setChannelError(mouse_cursor->context.rdpcontext, error,
423 "mouse_cursor_server_thread_func reported an error");
424
425 ExitThread(error);
426 return error;
427}
428
429static UINT mouse_cursor_server_open(MouseCursorServerContext* context)
430{
431 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
432
433 WINPR_ASSERT(mouse_cursor);
434
435 if (!mouse_cursor->externalThread && (mouse_cursor->thread == nullptr))
436 {
437 mouse_cursor->stopEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
438 if (!mouse_cursor->stopEvent)
439 {
440 WLog_ERR(TAG, "CreateEvent failed!");
441 return ERROR_INTERNAL_ERROR;
442 }
443
444 mouse_cursor->thread =
445 CreateThread(nullptr, 0, mouse_cursor_server_thread_func, mouse_cursor, 0, nullptr);
446 if (!mouse_cursor->thread)
447 {
448 WLog_ERR(TAG, "CreateThread failed!");
449 (void)CloseHandle(mouse_cursor->stopEvent);
450 mouse_cursor->stopEvent = nullptr;
451 return ERROR_INTERNAL_ERROR;
452 }
453 }
454 mouse_cursor->isOpened = TRUE;
455
456 return CHANNEL_RC_OK;
457}
458
459static UINT mouse_cursor_server_close(MouseCursorServerContext* context)
460{
461 UINT error = CHANNEL_RC_OK;
462 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
463
464 WINPR_ASSERT(mouse_cursor);
465
466 if (!mouse_cursor->externalThread && mouse_cursor->thread)
467 {
468 (void)SetEvent(mouse_cursor->stopEvent);
469
470 if (WaitForSingleObject(mouse_cursor->thread, INFINITE) == WAIT_FAILED)
471 {
472 error = GetLastError();
473 WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error);
474 return error;
475 }
476
477 (void)CloseHandle(mouse_cursor->thread);
478 (void)CloseHandle(mouse_cursor->stopEvent);
479 mouse_cursor->thread = nullptr;
480 mouse_cursor->stopEvent = nullptr;
481 }
482 if (mouse_cursor->externalThread)
483 {
484 if (mouse_cursor->state != MOUSE_CURSOR_INITIAL)
485 {
486 (void)WTSVirtualChannelClose(mouse_cursor->mouse_cursor_channel);
487 mouse_cursor->mouse_cursor_channel = nullptr;
488 mouse_cursor->state = MOUSE_CURSOR_INITIAL;
489 }
490 }
491 mouse_cursor->isOpened = FALSE;
492
493 return error;
494}
495
496static UINT mouse_cursor_server_context_poll(MouseCursorServerContext* context)
497{
498 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
499
500 WINPR_ASSERT(mouse_cursor);
501
502 if (!mouse_cursor->externalThread)
503 return ERROR_INTERNAL_ERROR;
504
505 return mouse_cursor_server_context_poll_int(context);
506}
507
508static BOOL mouse_cursor_server_context_handle(MouseCursorServerContext* context, HANDLE* handle)
509{
510 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
511
512 WINPR_ASSERT(mouse_cursor);
513 WINPR_ASSERT(handle);
514
515 if (!mouse_cursor->externalThread)
516 return FALSE;
517 if (mouse_cursor->state == MOUSE_CURSOR_INITIAL)
518 return FALSE;
519
520 *handle = mouse_cursor_server_get_channel_handle(mouse_cursor);
521
522 return TRUE;
523}
524
525static wStream* mouse_cursor_server_packet_new(size_t size, RDP_MOUSE_CURSOR_PDUTYPE pduType,
526 const RDP_MOUSE_CURSOR_HEADER* header)
527{
528 wStream* s = nullptr;
529
530 /* Allocate what we need plus header bytes */
531 s = Stream_New(nullptr, size + RDPEMSC_HEADER_SIZE);
532 if (!s)
533 {
534 WLog_ERR(TAG, "Stream_New failed!");
535 return nullptr;
536 }
537
538 WINPR_ASSERT(pduType <= UINT8_MAX);
539 Stream_Write_UINT8(s, (BYTE)pduType);
540
541 WINPR_ASSERT(header->updateType <= UINT8_MAX);
542 Stream_Write_UINT8(s, (BYTE)header->updateType);
543 Stream_Write_UINT16(s, header->reserved);
544
545 return s;
546}
547
548static UINT mouse_cursor_server_packet_send(MouseCursorServerContext* context, wStream* s)
549{
550 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
551 UINT error = CHANNEL_RC_OK;
552 ULONG written = 0;
553
554 WINPR_ASSERT(mouse_cursor);
555 WINPR_ASSERT(s);
556
557 const size_t pos = Stream_GetPosition(s);
558
559 WINPR_ASSERT(pos <= UINT32_MAX);
560 if (!WTSVirtualChannelWrite(mouse_cursor->mouse_cursor_channel, Stream_BufferAs(s, char),
561 (ULONG)pos, &written))
562 {
563 WLog_ERR(TAG, "WTSVirtualChannelWrite failed!");
564 error = ERROR_INTERNAL_ERROR;
565 goto out;
566 }
567
568 if (written < Stream_GetPosition(s))
569 {
570 WLog_WARN(TAG, "Unexpected bytes written: %" PRIu32 "/%" PRIuz "", written,
571 Stream_GetPosition(s));
572 }
573
574out:
575 Stream_Free(s, TRUE);
576 return error;
577}
578
579static UINT
580mouse_cursor_server_send_sc_caps_confirm(MouseCursorServerContext* context,
581 const RDP_MOUSE_CURSOR_CAPS_CONFIRM_PDU* capsConfirm)
582{
583 RDP_MOUSE_CURSOR_CAPSET* capsetHeader = nullptr;
584 RDP_MOUSE_CURSOR_PDUTYPE pduType = PDUTYPE_EMSC_RESERVED;
585 size_t caps_size = 0;
586 wStream* s = nullptr;
587
588 WINPR_ASSERT(context);
589 WINPR_ASSERT(capsConfirm);
590
591 capsetHeader = capsConfirm->capsSet;
592 WINPR_ASSERT(capsetHeader);
593
594 caps_size = 12;
595 switch (capsetHeader->version)
596 {
598 break;
599 default:
600 WINPR_ASSERT(FALSE);
601 break;
602 }
603
604 pduType = PDUTYPE_SC_CAPS_CONFIRM;
605 s = mouse_cursor_server_packet_new(caps_size, pduType, &capsConfirm->header);
606 if (!s)
607 return ERROR_NOT_ENOUGH_MEMORY;
608
609 Stream_Write_UINT32(s, capsetHeader->signature);
610 Stream_Write_UINT32(s, capsetHeader->version);
611 Stream_Write_UINT32(s, capsetHeader->size);
612
613 /* Write capsData */
614 switch (capsetHeader->version)
615 {
617 break;
618 default:
619 WINPR_ASSERT(FALSE);
620 break;
621 }
622
623 return mouse_cursor_server_packet_send(context, s);
624}
625
626static void write_point16(wStream* s, const TS_POINT16* point16)
627{
628 WINPR_ASSERT(s);
629 WINPR_ASSERT(point16);
630
631 Stream_Write_UINT16(s, point16->xPos);
632 Stream_Write_UINT16(s, point16->yPos);
633}
634
635static UINT mouse_cursor_server_send_sc_mouseptr_update(
636 MouseCursorServerContext* context, const RDP_MOUSE_CURSOR_MOUSEPTR_UPDATE_PDU* mouseptrUpdate)
637{
638 TS_POINT16* position = nullptr;
639 TS_POINTERATTRIBUTE* pointerAttribute = nullptr;
640 TS_LARGEPOINTERATTRIBUTE* largePointerAttribute = nullptr;
641 RDP_MOUSE_CURSOR_PDUTYPE pduType = PDUTYPE_EMSC_RESERVED;
642 size_t update_size = 0;
643 wStream* s = nullptr;
644
645 WINPR_ASSERT(context);
646 WINPR_ASSERT(mouseptrUpdate);
647
648 position = mouseptrUpdate->position;
649 pointerAttribute = mouseptrUpdate->pointerAttribute;
650 largePointerAttribute = mouseptrUpdate->largePointerAttribute;
651
652 switch (mouseptrUpdate->header.updateType)
653 {
654 case TS_UPDATETYPE_MOUSEPTR_SYSTEM_NULL:
655 case TS_UPDATETYPE_MOUSEPTR_SYSTEM_DEFAULT:
656 update_size = 0;
657 break;
658 case TS_UPDATETYPE_MOUSEPTR_POSITION:
659 WINPR_ASSERT(position);
660 update_size = 4;
661 break;
662 case TS_UPDATETYPE_MOUSEPTR_CACHED:
663 WINPR_ASSERT(mouseptrUpdate->cachedPointerIndex);
664 update_size = 2;
665 break;
666 case TS_UPDATETYPE_MOUSEPTR_POINTER:
667 WINPR_ASSERT(pointerAttribute);
668 update_size = 2 + 2 + 4 + 2 + 2 + 2 + 2;
669 update_size += pointerAttribute->lengthAndMask;
670 update_size += pointerAttribute->lengthXorMask;
671 break;
672 case TS_UPDATETYPE_MOUSEPTR_LARGE_POINTER:
673 WINPR_ASSERT(largePointerAttribute);
674 update_size = 2 + 2 + 4 + 2 + 2 + 4 + 4;
675 update_size += largePointerAttribute->lengthAndMask;
676 update_size += largePointerAttribute->lengthXorMask;
677 break;
678 default:
679 WINPR_ASSERT(FALSE);
680 break;
681 }
682
683 pduType = PDUTYPE_SC_MOUSEPTR_UPDATE;
684 s = mouse_cursor_server_packet_new(update_size, pduType, &mouseptrUpdate->header);
685 if (!s)
686 return ERROR_NOT_ENOUGH_MEMORY;
687
688 switch (mouseptrUpdate->header.updateType)
689 {
690 case TS_UPDATETYPE_MOUSEPTR_SYSTEM_NULL:
691 case TS_UPDATETYPE_MOUSEPTR_SYSTEM_DEFAULT:
692 break;
693 case TS_UPDATETYPE_MOUSEPTR_POSITION:
694 write_point16(s, position);
695 break;
696 case TS_UPDATETYPE_MOUSEPTR_CACHED:
697 Stream_Write_UINT16(s, *mouseptrUpdate->cachedPointerIndex);
698 break;
699 case TS_UPDATETYPE_MOUSEPTR_POINTER:
700 Stream_Write_UINT16(s, pointerAttribute->xorBpp);
701 Stream_Write_UINT16(s, pointerAttribute->cacheIndex);
702 write_point16(s, &pointerAttribute->hotSpot);
703 Stream_Write_UINT16(s, pointerAttribute->width);
704 Stream_Write_UINT16(s, pointerAttribute->height);
705 Stream_Write_UINT16(s, pointerAttribute->lengthAndMask);
706 Stream_Write_UINT16(s, pointerAttribute->lengthXorMask);
707 Stream_Write(s, pointerAttribute->xorMaskData, pointerAttribute->lengthXorMask);
708 Stream_Write(s, pointerAttribute->andMaskData, pointerAttribute->lengthAndMask);
709 break;
710 case TS_UPDATETYPE_MOUSEPTR_LARGE_POINTER:
711 Stream_Write_UINT16(s, largePointerAttribute->xorBpp);
712 Stream_Write_UINT16(s, largePointerAttribute->cacheIndex);
713 write_point16(s, &largePointerAttribute->hotSpot);
714 Stream_Write_UINT16(s, largePointerAttribute->width);
715 Stream_Write_UINT16(s, largePointerAttribute->height);
716 Stream_Write_UINT32(s, largePointerAttribute->lengthAndMask);
717 Stream_Write_UINT32(s, largePointerAttribute->lengthXorMask);
718 Stream_Write(s, largePointerAttribute->xorMaskData,
719 largePointerAttribute->lengthXorMask);
720 Stream_Write(s, largePointerAttribute->andMaskData,
721 largePointerAttribute->lengthAndMask);
722 break;
723 default:
724 WINPR_ASSERT(FALSE);
725 break;
726 }
727
728 return mouse_cursor_server_packet_send(context, s);
729}
730
731MouseCursorServerContext* mouse_cursor_server_context_new(HANDLE vcm)
732{
733 mouse_cursor_server* mouse_cursor =
734 (mouse_cursor_server*)calloc(1, sizeof(mouse_cursor_server));
735
736 if (!mouse_cursor)
737 return nullptr;
738
739 mouse_cursor->context.vcm = vcm;
740 mouse_cursor->context.Initialize = mouse_cursor_server_initialize;
741 mouse_cursor->context.Open = mouse_cursor_server_open;
742 mouse_cursor->context.Close = mouse_cursor_server_close;
743 mouse_cursor->context.Poll = mouse_cursor_server_context_poll;
744 mouse_cursor->context.ChannelHandle = mouse_cursor_server_context_handle;
745
746 mouse_cursor->context.CapsConfirm = mouse_cursor_server_send_sc_caps_confirm;
747 mouse_cursor->context.MouseptrUpdate = mouse_cursor_server_send_sc_mouseptr_update;
748
749 mouse_cursor->buffer = Stream_New(nullptr, 4096);
750 if (!mouse_cursor->buffer)
751 goto fail;
752
753 return &mouse_cursor->context;
754fail:
755 WINPR_PRAGMA_DIAG_PUSH
756 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
757 mouse_cursor_server_context_free(&mouse_cursor->context);
758 WINPR_PRAGMA_DIAG_POP
759 return nullptr;
760}
761
762void mouse_cursor_server_context_free(MouseCursorServerContext* context)
763{
764 mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context;
765
766 if (mouse_cursor)
767 {
768 mouse_cursor_server_close(context);
769 Stream_Free(mouse_cursor->buffer, TRUE);
770 }
771
772 free(mouse_cursor);
773}
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:59