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