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