FreeRDP
Loading...
Searching...
No Matches
client/cliprdr_main.c
1
22
23#include <freerdp/config.h>
24
25#include <winpr/wtypes.h>
26#include <winpr/assert.h>
27#include <winpr/crt.h>
28#include <winpr/print.h>
29#include <winpr/clipboard.h>
30
31#include <freerdp/types.h>
32#include <freerdp/constants.h>
33#include <freerdp/freerdp.h>
34#include <freerdp/client/cliprdr.h>
35
36#include "../../../channels/client/addin.h"
37
38#include "cliprdr_main.h"
39#include "cliprdr_format.h"
40#include "../cliprdr_common.h"
41
42const char type_FileGroupDescriptorW[] = "FileGroupDescriptorW";
43const char type_FileContents[] = "FileContents";
44
45CliprdrClientContext* cliprdr_get_client_interface(cliprdrPlugin* cliprdr)
46{
47 CliprdrClientContext* pInterface = nullptr;
48
49 if (!cliprdr)
50 return nullptr;
51
52 pInterface = (CliprdrClientContext*)cliprdr->channelEntryPoints.pInterface;
53 return pInterface;
54}
55
61static UINT cliprdr_packet_send(cliprdrPlugin* cliprdr, wStream* s)
62{
63 UINT status = ERROR_INVALID_DATA;
64
65 WINPR_ASSERT(cliprdr);
66 WINPR_ASSERT(s);
67
68 const size_t pos = Stream_GetPosition(s);
69 WINPR_ASSERT(pos >= 8ULL);
70 WINPR_ASSERT(pos <= UINT32_MAX - 8);
71
72 const uint32_t dataLen = WINPR_ASSERTING_INT_CAST(uint32_t, pos - 8UL);
73
74 if (!Stream_SetPosition(s, 4))
75 goto fail;
76 Stream_Write_UINT32(s, dataLen);
77 if (!Stream_SetPosition(s, pos))
78 goto fail;
79
80 WLog_Print(cliprdr->log, WLOG_DEBUG, "Cliprdr Sending (%" PRIuz " bytes)", pos);
81
82 if (!cliprdr)
83 status = CHANNEL_RC_BAD_INIT_HANDLE;
84 else
85 {
86 WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelWriteEx);
87 status = cliprdr->channelEntryPoints.pVirtualChannelWriteEx(
88 cliprdr->InitHandle, cliprdr->OpenHandle, Stream_Buffer(s),
89 (UINT32)Stream_GetPosition(s), s);
90 }
91
92fail:
93 if (status != CHANNEL_RC_OK)
94 {
95 Stream_Free(s, TRUE);
96 WLog_Print(cliprdr->log, WLOG_ERROR, "VirtualChannelWrite failed with %s [%08" PRIX32 "]",
97 WTSErrorToString(status), status);
98 }
99
100 return status;
101}
102
103UINT cliprdr_send_error_response(cliprdrPlugin* cliprdr, UINT16 type)
104{
105 wStream* s = cliprdr_packet_new(type, CB_RESPONSE_FAIL, 0);
106 if (!s)
107 {
108 WLog_Print(cliprdr->log, WLOG_ERROR, "cliprdr_packet_new failed!");
109 return ERROR_OUTOFMEMORY;
110 }
111
112 return cliprdr_packet_send(cliprdr, s);
113}
114
115static void cliprdr_print_general_capability_flags(wLog* log, UINT32 flags)
116{
117 WLog_Print(log, WLOG_DEBUG, "generalFlags (0x%08" PRIX32 ") {", flags);
118
119 if (flags & CB_USE_LONG_FORMAT_NAMES)
120 WLog_Print(log, WLOG_DEBUG, "\tCB_USE_LONG_FORMAT_NAMES");
121
122 if (flags & CB_STREAM_FILECLIP_ENABLED)
123 WLog_Print(log, WLOG_DEBUG, "\tCB_STREAM_FILECLIP_ENABLED");
124
125 if (flags & CB_FILECLIP_NO_FILE_PATHS)
126 WLog_Print(log, WLOG_DEBUG, "\tCB_FILECLIP_NO_FILE_PATHS");
127
128 if (flags & CB_CAN_LOCK_CLIPDATA)
129 WLog_Print(log, WLOG_DEBUG, "\tCB_CAN_LOCK_CLIPDATA");
130
131 if (flags & CB_HUGE_FILE_SUPPORT_ENABLED)
132 WLog_Print(log, WLOG_DEBUG, "\tCB_HUGE_FILE_SUPPORT_ENABLED");
133
134 WLog_Print(log, WLOG_DEBUG, "}");
135}
136
142static UINT cliprdr_process_general_capability(cliprdrPlugin* cliprdr, wStream* s)
143{
144 UINT32 version = 0;
145 UINT32 generalFlags = 0;
146 CLIPRDR_CAPABILITIES capabilities = WINPR_C_ARRAY_INIT;
147 CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet = WINPR_C_ARRAY_INIT;
148 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
149 UINT error = CHANNEL_RC_OK;
150
151 WINPR_ASSERT(cliprdr);
152 WINPR_ASSERT(s);
153
154 if (!context)
155 {
156 WLog_Print(cliprdr->log, WLOG_ERROR, "cliprdr_get_client_interface failed!");
157 return ERROR_INTERNAL_ERROR;
158 }
159
160 if (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, 8))
161 return ERROR_INVALID_DATA;
162
163 Stream_Read_UINT32(s, version); /* version (4 bytes) */
164 Stream_Read_UINT32(s, generalFlags); /* generalFlags (4 bytes) */
165 WLog_Print(cliprdr->log, WLOG_DEBUG, "Version: %" PRIu32 "", version);
166
167 cliprdr_print_general_capability_flags(cliprdr->log, generalFlags);
168
169 cliprdr->useLongFormatNames = (generalFlags & CB_USE_LONG_FORMAT_NAMES) != 0;
170 cliprdr->streamFileClipEnabled = (generalFlags & CB_STREAM_FILECLIP_ENABLED) != 0;
171 cliprdr->fileClipNoFilePaths = (generalFlags & CB_FILECLIP_NO_FILE_PATHS) != 0;
172 cliprdr->canLockClipData = (generalFlags & CB_CAN_LOCK_CLIPDATA) != 0;
173 cliprdr->hasHugeFileSupport = (generalFlags & CB_HUGE_FILE_SUPPORT_ENABLED) != 0;
174 cliprdr->capabilitiesReceived = TRUE;
175
176 capabilities.common.msgType = CB_CLIP_CAPS;
177 capabilities.cCapabilitiesSets = 1;
178 capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*)&(generalCapabilitySet);
179 generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
180 generalCapabilitySet.capabilitySetLength = 12;
181 generalCapabilitySet.version = version;
182 generalCapabilitySet.generalFlags = generalFlags;
183 IFCALLRET(context->ServerCapabilities, error, context, &capabilities);
184
185 if (error)
186 WLog_Print(cliprdr->log, WLOG_ERROR, "ServerCapabilities failed with error %" PRIu32 "!",
187 error);
188
189 return error;
190}
191
197static UINT cliprdr_process_clip_caps(cliprdrPlugin* cliprdr, wStream* s,
198 WINPR_ATTR_UNUSED UINT32 length,
199 WINPR_ATTR_UNUSED UINT16 flags)
200{
201 UINT16 lengthCapability = 0;
202 UINT16 cCapabilitiesSets = 0;
203 UINT16 capabilitySetType = 0;
204 UINT error = CHANNEL_RC_OK;
205
206 WINPR_ASSERT(cliprdr);
207 WINPR_ASSERT(s);
208
209 if (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, 4))
210 return ERROR_INVALID_DATA;
211
212 Stream_Read_UINT16(s, cCapabilitiesSets); /* cCapabilitiesSets (2 bytes) */
213 Stream_Seek_UINT16(s); /* pad1 (2 bytes) */
214 WLog_Print(cliprdr->log, WLOG_DEBUG, "ServerCapabilities");
215
216 for (UINT16 index = 0; index < cCapabilitiesSets; index++)
217 {
218 if (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, 4))
219 return ERROR_INVALID_DATA;
220
221 Stream_Read_UINT16(s, capabilitySetType); /* capabilitySetType (2 bytes) */
222 Stream_Read_UINT16(s, lengthCapability); /* lengthCapability (2 bytes) */
223
224 if ((lengthCapability < 4) ||
225 (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, lengthCapability - 4U)))
226 return ERROR_INVALID_DATA;
227
228 switch (capabilitySetType)
229 {
230 case CB_CAPSTYPE_GENERAL:
231 if ((error = cliprdr_process_general_capability(cliprdr, s)))
232 {
233 WLog_Print(cliprdr->log, WLOG_ERROR,
234 "cliprdr_process_general_capability failed with error %" PRIu32 "!",
235 error);
236 return error;
237 }
238
239 break;
240
241 default:
242 WLog_Print(cliprdr->log, WLOG_ERROR, "unknown cliprdr capability set: %" PRIu16 "",
243 capabilitySetType);
244 return CHANNEL_RC_BAD_PROC;
245 }
246 }
247
248 return error;
249}
250
256static UINT cliprdr_process_monitor_ready(cliprdrPlugin* cliprdr, WINPR_ATTR_UNUSED wStream* s,
257 UINT32 length, UINT16 flags)
258{
259 CLIPRDR_MONITOR_READY monitorReady = WINPR_C_ARRAY_INIT;
260 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
261 UINT error = CHANNEL_RC_OK;
262
263 WINPR_ASSERT(cliprdr);
264 WINPR_ASSERT(s);
265
266 WLog_Print(cliprdr->log, WLOG_DEBUG, "MonitorReady");
267
268 if (!cliprdr->capabilitiesReceived)
269 {
276 cliprdr->useLongFormatNames = FALSE;
277 cliprdr->streamFileClipEnabled = FALSE;
278 cliprdr->fileClipNoFilePaths = TRUE;
279 cliprdr->canLockClipData = FALSE;
280 }
281
282 monitorReady.common.msgType = CB_MONITOR_READY;
283 monitorReady.common.msgFlags = flags;
284 monitorReady.common.dataLen = length;
285 IFCALLRET(context->MonitorReady, error, context, &monitorReady);
286
287 if (error)
288 WLog_Print(cliprdr->log, WLOG_ERROR, "MonitorReady failed with error %" PRIu32 "!", error);
289
290 return error;
291}
292
298static UINT cliprdr_process_filecontents_request(cliprdrPlugin* cliprdr, wStream* s, UINT32 length,
299 UINT16 flags)
300{
301 CLIPRDR_FILE_CONTENTS_REQUEST request = WINPR_C_ARRAY_INIT;
302 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
303
304 WINPR_ASSERT(cliprdr);
305 WINPR_ASSERT(s);
306
307 WLog_Print(cliprdr->log, WLOG_DEBUG, "FileContentsRequest");
308
309 request.common.msgType = CB_FILECONTENTS_REQUEST;
310 request.common.msgFlags = flags;
311 request.common.dataLen = length;
312
313 UINT error = cliprdr_read_file_contents_request(s, &request);
314 if (error)
315 return error;
316
317 if (!cliprdr->streamFileClipEnabled)
318 {
319 WLog_Print(cliprdr->log, WLOG_WARN,
320 "clipboard::filecontents requested, but feature not announced! aborting.");
321 return ERROR_INVALID_DATA;
322 }
323
324 const UINT32 mask =
325 freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask);
326 if ((mask & (CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES)) == 0)
327 {
328 WLog_Print(cliprdr->log, WLOG_WARN, "local -> remote file copy disabled, ignoring request");
329 return cliprdr_send_error_response(cliprdr, CB_FILECONTENTS_RESPONSE);
330 }
331 IFCALLRET(context->ServerFileContentsRequest, error, context, &request);
332
333 if (error)
334 WLog_Print(cliprdr->log, WLOG_ERROR,
335 "ServerFileContentsRequest failed with error %" PRIu32 "!", error);
336
337 return error;
338}
339
345static UINT cliprdr_process_filecontents_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 length,
346 UINT16 flags)
347{
348 CLIPRDR_FILE_CONTENTS_RESPONSE response = WINPR_C_ARRAY_INIT;
349 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
350
351 WINPR_ASSERT(cliprdr);
352 WINPR_ASSERT(s);
353
354 WLog_Print(cliprdr->log, WLOG_DEBUG, "FileContentsResponse");
355
356 if (!cliprdr->streamFileClipEnabled)
357 {
358 WLog_Print(
359 cliprdr->log, WLOG_WARN,
360 "clipboard::filecontents_response requested, but feature not announced! aborting.");
361 return ERROR_INVALID_DATA;
362 }
363
364 response.common.msgType = CB_FILECONTENTS_RESPONSE;
365 response.common.msgFlags = flags;
366 response.common.dataLen = length;
367
368 UINT error = cliprdr_read_file_contents_response(s, &response);
369 if (error)
370 return error;
371
372 IFCALLRET(context->ServerFileContentsResponse, error, context, &response);
373
374 if (error)
375 WLog_Print(cliprdr->log, WLOG_ERROR,
376 "ServerFileContentsResponse failed with error %" PRIu32 "!", error);
377
378 return error;
379}
380
386static UINT cliprdr_process_lock_clipdata(cliprdrPlugin* cliprdr, wStream* s, UINT32 length,
387 UINT16 flags)
388{
389 CLIPRDR_LOCK_CLIPBOARD_DATA lockClipboardData = WINPR_C_ARRAY_INIT;
390 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
391 UINT error = CHANNEL_RC_OK;
392
393 WINPR_ASSERT(cliprdr);
394 WINPR_ASSERT(s);
395
396 WLog_Print(cliprdr->log, WLOG_DEBUG, "LockClipData");
397
398 if (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, 4))
399 return ERROR_INVALID_DATA;
400
401 if (!cliprdr->canLockClipData)
402 {
403 WLog_Print(cliprdr->log, WLOG_WARN,
404 "clipboard::lock requested, but feature not announced! aborting.");
405 return ERROR_INVALID_DATA;
406 }
407
408 lockClipboardData.common.msgType = CB_LOCK_CLIPDATA;
409 lockClipboardData.common.msgFlags = flags;
410 lockClipboardData.common.dataLen = length;
411 Stream_Read_UINT32(s, lockClipboardData.clipDataId); /* clipDataId (4 bytes) */
412 IFCALLRET(context->ServerLockClipboardData, error, context, &lockClipboardData);
413
414 if (error)
415 WLog_Print(cliprdr->log, WLOG_ERROR,
416 "ServerLockClipboardData failed with error %" PRIu32 "!", error);
417
418 return error;
419}
420
426static UINT cliprdr_process_unlock_clipdata(cliprdrPlugin* cliprdr, wStream* s, UINT32 length,
427 UINT16 flags)
428{
429 CLIPRDR_UNLOCK_CLIPBOARD_DATA unlockClipboardData = WINPR_C_ARRAY_INIT;
430 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
431
432 WINPR_ASSERT(cliprdr);
433 WINPR_ASSERT(s);
434
435 WLog_Print(cliprdr->log, WLOG_DEBUG, "UnlockClipData");
436
437 if (!cliprdr->canLockClipData)
438 {
439 WLog_Print(cliprdr->log, WLOG_WARN,
440 "clipboard::unlock requested, but feature not announced! aborting.");
441 return ERROR_INVALID_DATA;
442 }
443
444 UINT error = cliprdr_read_unlock_clipdata(s, &unlockClipboardData);
445 if (error)
446 return error;
447
448 unlockClipboardData.common.msgType = CB_UNLOCK_CLIPDATA;
449 unlockClipboardData.common.msgFlags = flags;
450 unlockClipboardData.common.dataLen = length;
451
452 IFCALLRET(context->ServerUnlockClipboardData, error, context, &unlockClipboardData);
453
454 if (error)
455 WLog_Print(cliprdr->log, WLOG_ERROR,
456 "ServerUnlockClipboardData failed with error %" PRIu32 "!", error);
457
458 return error;
459}
460
466static UINT cliprdr_order_recv(LPVOID userdata, wStream* s)
467{
468 cliprdrPlugin* cliprdr = userdata;
469 UINT16 msgType = 0;
470 UINT16 msgFlags = 0;
471 UINT32 dataLen = 0;
472 UINT error = 0;
473
474 WINPR_ASSERT(cliprdr);
475 WINPR_ASSERT(s);
476
477 if (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, 8))
478 return ERROR_INVALID_DATA;
479
480 Stream_Read_UINT16(s, msgType); /* msgType (2 bytes) */
481 Stream_Read_UINT16(s, msgFlags); /* msgFlags (2 bytes) */
482 Stream_Read_UINT32(s, dataLen); /* dataLen (4 bytes) */
483
484 const BOOL failedResponse =
485 (msgFlags & CB_RESPONSE_FAIL) &&
486 ((msgType == CB_FORMAT_DATA_RESPONSE) || (msgType == CB_FORMAT_LIST_RESPONSE) ||
487 (msgType == CB_FILECONTENTS_RESPONSE));
488 if (failedResponse)
489 {
490 /* A failed response carries no payload, MS-RDPECLIP defines dataLen == 0 for it. Not
491 * every server gets that right though: gnome-remote-desktop 50.x sends dataLen > 0
492 * with no data behind it after it could not produce the requested clipboard format.
493 * Insisting on dataLen bytes fails the channel, and a failed channel tears down the
494 * whole session - a clipboard problem must not kill the connection. Treat dataLen as a
495 * hint for a failed response and pass on what actually arrived; the message flag
496 * already tells the handler that there is nothing to read. */
497 const size_t available = Stream_GetRemainingLength(s);
498 if (dataLen > available)
499 {
500 WLog_Print(cliprdr->log, WLOG_WARN,
501 "failed response (msgType: %" PRIu16 ") claims dataLen: %" PRIu32
502 " but only %" PRIuz " bytes follow",
503 msgType, dataLen, available);
504 dataLen = WINPR_ASSERTING_INT_CAST(UINT32, available);
505 }
506 }
507 else if (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, dataLen))
508 return ERROR_INVALID_DATA;
509
510 char buffer1[64] = WINPR_C_ARRAY_INIT;
511 char buffer2[64] = WINPR_C_ARRAY_INIT;
512 WLog_Print(cliprdr->log, WLOG_DEBUG,
513 "msgType: %s (%" PRIu16 "), msgFlags: %s dataLen: %" PRIu32 "",
514 CB_MSG_TYPE_STRING(msgType, buffer1, sizeof(buffer1)), msgType,
515 CB_MSG_FLAGS_STRING(msgFlags, buffer2, sizeof(buffer2)), dataLen);
516
517 switch (msgType)
518 {
519 case CB_CLIP_CAPS:
520 if ((error = cliprdr_process_clip_caps(cliprdr, s, dataLen, msgFlags)))
521 WLog_Print(cliprdr->log, WLOG_ERROR,
522 "cliprdr_process_clip_caps failed with error %" PRIu32 "!", error);
523
524 break;
525
526 case CB_MONITOR_READY:
527 if ((error = cliprdr_process_monitor_ready(cliprdr, s, dataLen, msgFlags)))
528 WLog_Print(cliprdr->log, WLOG_ERROR,
529 "cliprdr_process_monitor_ready failed with error %" PRIu32 "!", error);
530
531 break;
532
533 case CB_FORMAT_LIST:
534 if ((error = cliprdr_process_format_list(cliprdr, s, dataLen, msgFlags)))
535 WLog_Print(cliprdr->log, WLOG_ERROR,
536 "cliprdr_process_format_list failed with error %" PRIu32 "!", error);
537
538 break;
539
540 case CB_FORMAT_LIST_RESPONSE:
541 if ((error = cliprdr_process_format_list_response(cliprdr, s, dataLen, msgFlags)))
542 WLog_Print(cliprdr->log, WLOG_ERROR,
543 "cliprdr_process_format_list_response failed with error %" PRIu32 "!",
544 error);
545
546 break;
547
548 case CB_FORMAT_DATA_REQUEST:
549 if ((error = cliprdr_process_format_data_request(cliprdr, s, dataLen, msgFlags)))
550 WLog_Print(cliprdr->log, WLOG_ERROR,
551 "cliprdr_process_format_data_request failed with error %" PRIu32 "!",
552 error);
553
554 break;
555
556 case CB_FORMAT_DATA_RESPONSE:
557 if ((error = cliprdr_process_format_data_response(cliprdr, s, dataLen, msgFlags)))
558 WLog_Print(cliprdr->log, WLOG_ERROR,
559 "cliprdr_process_format_data_response failed with error %" PRIu32 "!",
560 error);
561
562 break;
563
564 case CB_FILECONTENTS_REQUEST:
565 if ((error = cliprdr_process_filecontents_request(cliprdr, s, dataLen, msgFlags)))
566 WLog_Print(cliprdr->log, WLOG_ERROR,
567 "cliprdr_process_filecontents_request failed with error %" PRIu32 "!",
568 error);
569
570 break;
571
572 case CB_FILECONTENTS_RESPONSE:
573 if ((error = cliprdr_process_filecontents_response(cliprdr, s, dataLen, msgFlags)))
574 WLog_Print(cliprdr->log, WLOG_ERROR,
575 "cliprdr_process_filecontents_response failed with error %" PRIu32 "!",
576 error);
577
578 break;
579
580 case CB_LOCK_CLIPDATA:
581 if ((error = cliprdr_process_lock_clipdata(cliprdr, s, dataLen, msgFlags)))
582 WLog_Print(cliprdr->log, WLOG_ERROR,
583 "cliprdr_process_lock_clipdata failed with error %" PRIu32 "!", error);
584
585 break;
586
587 case CB_UNLOCK_CLIPDATA:
588 if ((error = cliprdr_process_unlock_clipdata(cliprdr, s, dataLen, msgFlags)))
589 WLog_Print(cliprdr->log, WLOG_ERROR,
590 "cliprdr_process_unlock_clipdata failed with error %" PRIu32 "!", error);
591
592 break;
593
594 default:
595 error = CHANNEL_RC_BAD_PROC;
596 WLog_Print(cliprdr->log, WLOG_ERROR, "unknown msgType %" PRIu16 "", msgType);
597 break;
598 }
599
600 Stream_Free(s, TRUE);
601 return error;
602}
603
607
613static UINT cliprdr_client_capabilities(CliprdrClientContext* context,
614 const CLIPRDR_CAPABILITIES* capabilities)
615{
616 wStream* s = nullptr;
617 UINT32 flags = 0;
618 const CLIPRDR_GENERAL_CAPABILITY_SET* generalCapabilitySet = nullptr;
619 cliprdrPlugin* cliprdr = nullptr;
620
621 WINPR_ASSERT(context);
622
623 cliprdr = (cliprdrPlugin*)context->handle;
624 WINPR_ASSERT(cliprdr);
625
626 s = cliprdr_packet_new(CB_CLIP_CAPS, 0, 4 + CB_CAPSTYPE_GENERAL_LEN);
627
628 if (!s)
629 {
630 WLog_Print(cliprdr->log, WLOG_ERROR, "cliprdr_packet_new failed!");
631 return ERROR_INTERNAL_ERROR;
632 }
633
634 Stream_Write_UINT16(s, 1); /* cCapabilitiesSets */
635 Stream_Write_UINT16(s, 0); /* pad1 */
636 generalCapabilitySet = WINPR_PACKED_ALIGN_CAST(const CLIPRDR_GENERAL_CAPABILITY_SET*,
637 capabilities->capabilitySets);
638 Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetType); /* capabilitySetType */
639 Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetLength); /* lengthCapability */
640 Stream_Write_UINT32(s, generalCapabilitySet->version); /* version */
641 flags = generalCapabilitySet->generalFlags;
642
643 /* Client capabilities are sent in response to server capabilities.
644 * -> Do not request features the server does not support.
645 * -> Update clipboard context feature state to what was agreed upon.
646 */
647 if (!cliprdr->useLongFormatNames)
648 flags &= (uint32_t)~CB_USE_LONG_FORMAT_NAMES;
649 if (!cliprdr->streamFileClipEnabled)
650 flags &= (uint32_t)~CB_STREAM_FILECLIP_ENABLED;
651 if (!cliprdr->fileClipNoFilePaths)
652 flags &= (uint32_t)~CB_FILECLIP_NO_FILE_PATHS;
653 if (!cliprdr->canLockClipData)
654 flags &= (uint32_t)~CB_CAN_LOCK_CLIPDATA;
655 if (!cliprdr->hasHugeFileSupport)
656 flags &= (uint32_t)~CB_HUGE_FILE_SUPPORT_ENABLED;
657
658 cliprdr->useLongFormatNames = (flags & CB_USE_LONG_FORMAT_NAMES) != 0;
659 cliprdr->streamFileClipEnabled = (flags & CB_STREAM_FILECLIP_ENABLED) != 0;
660 cliprdr->fileClipNoFilePaths = (flags & CB_FILECLIP_NO_FILE_PATHS) != 0;
661 cliprdr->canLockClipData = (flags & CB_CAN_LOCK_CLIPDATA) != 0;
662 cliprdr->hasHugeFileSupport = (flags & CB_HUGE_FILE_SUPPORT_ENABLED) != 0;
663
664 Stream_Write_UINT32(s, flags); /* generalFlags */
665 WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientCapabilities");
666
667 return cliprdr_packet_send(cliprdr, s);
668}
669
675static UINT cliprdr_temp_directory(CliprdrClientContext* context,
676 const CLIPRDR_TEMP_DIRECTORY* tempDirectory)
677{
678 wStream* s = nullptr;
679 cliprdrPlugin* cliprdr = nullptr;
680
681 WINPR_ASSERT(context);
682 WINPR_ASSERT(tempDirectory);
683
684 cliprdr = (cliprdrPlugin*)context->handle;
685 WINPR_ASSERT(cliprdr);
686
687 const size_t tmpDirCharLen = sizeof(tempDirectory->szTempDir) / sizeof(WCHAR);
688 s = cliprdr_packet_new(CB_TEMP_DIRECTORY, 0, tmpDirCharLen * sizeof(WCHAR));
689
690 if (!s)
691 {
692 WLog_Print(cliprdr->log, WLOG_ERROR, "cliprdr_packet_new failed!");
693 return ERROR_INTERNAL_ERROR;
694 }
695
696 if (Stream_Write_UTF16_String_From_UTF8(s, tmpDirCharLen - 1, tempDirectory->szTempDir,
697 ARRAYSIZE(tempDirectory->szTempDir), TRUE) < 0)
698 {
699 Stream_Free(s, TRUE);
700 return ERROR_INTERNAL_ERROR;
701 }
702 /* Path must be 260 UTF16 characters with '\0' termination.
703 * ensure this here */
704 Stream_Write_UINT16(s, 0);
705
706 WLog_Print(cliprdr->log, WLOG_DEBUG, "TempDirectory: %s", tempDirectory->szTempDir);
707 return cliprdr_packet_send(cliprdr, s);
708}
709
715static UINT cliprdr_client_format_list(CliprdrClientContext* context,
716 const CLIPRDR_FORMAT_LIST* formatList)
717{
718 WINPR_ASSERT(context);
719 WINPR_ASSERT(formatList);
720
721 cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle;
722 WINPR_ASSERT(cliprdr);
723
724 {
725 const UINT32 mask = CB_RESPONSE_OK | CB_RESPONSE_FAIL;
726 if ((formatList->common.msgFlags & mask) != 0)
727 WLog_Print(cliprdr->log, WLOG_WARN,
728 "Sending clipboard request with invalid flags msgFlags = 0x%08" PRIx32
729 ". Correct in your client!",
730 formatList->common.msgFlags & mask);
731 }
732
733 const UINT32 mask =
734 freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask);
735 CLIPRDR_FORMAT_LIST filterList = cliprdr_filter_format_list(
736 formatList, mask, CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES);
737
738 const uint32_t level = WLOG_DEBUG;
739 if (WLog_IsLevelActive(cliprdr->log, level))
740 {
741 WLog_Print(cliprdr->log, level, "ClientFormatList: numFormats: %" PRIu32 "",
742 formatList->numFormats);
743 for (size_t x = 0; x < filterList.numFormats; x++)
744 {
745 const CLIPRDR_FORMAT* format = &filterList.formats[x];
746 WLog_Print(cliprdr->log, level, "[%" PRIuz "]: id=0x%08" PRIx32 " [%s|%s]", x,
747 format->formatId, ClipboardGetFormatIdString(format->formatId),
748 format->formatName);
749 }
750 }
751
752 wStream* s = cliprdr_packet_format_list_new(&filterList, cliprdr->useLongFormatNames, FALSE);
753 cliprdr_free_format_list(&filterList);
754
755 if (!s)
756 {
757 WLog_Print(cliprdr->log, WLOG_ERROR, "cliprdr_packet_format_list_new failed!");
758 return ERROR_INTERNAL_ERROR;
759 }
760
761 return cliprdr_packet_send(cliprdr, s);
762}
763
769static UINT
770cliprdr_client_format_list_response(CliprdrClientContext* context,
771 const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
772{
773 wStream* s = nullptr;
774 cliprdrPlugin* cliprdr = nullptr;
775
776 WINPR_ASSERT(context);
777 WINPR_ASSERT(formatListResponse);
778
779 cliprdr = (cliprdrPlugin*)context->handle;
780 WINPR_ASSERT(cliprdr);
781
782 s = cliprdr_packet_new(CB_FORMAT_LIST_RESPONSE, formatListResponse->common.msgFlags, 0);
783
784 if (!s)
785 {
786 WLog_Print(cliprdr->log, WLOG_ERROR, "cliprdr_packet_new failed!");
787 return ERROR_INTERNAL_ERROR;
788 }
789
790 WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatListResponse");
791 return cliprdr_packet_send(cliprdr, s);
792}
793
799static UINT cliprdr_client_lock_clipboard_data(CliprdrClientContext* context,
800 const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
801{
802 wStream* s = nullptr;
803 cliprdrPlugin* cliprdr = nullptr;
804
805 WINPR_ASSERT(context);
806 WINPR_ASSERT(lockClipboardData);
807
808 cliprdr = (cliprdrPlugin*)context->handle;
809 WINPR_ASSERT(cliprdr);
810
811 s = cliprdr_packet_lock_clipdata_new(lockClipboardData);
812
813 if (!s)
814 {
815 WLog_Print(cliprdr->log, WLOG_ERROR, "cliprdr_packet_lock_clipdata_new failed!");
816 return ERROR_INTERNAL_ERROR;
817 }
818
819 WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientLockClipboardData: clipDataId: 0x%08" PRIX32 "",
820 lockClipboardData->clipDataId);
821 return cliprdr_packet_send(cliprdr, s);
822}
823
829static UINT
830cliprdr_client_unlock_clipboard_data(CliprdrClientContext* context,
831 const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
832{
833 wStream* s = nullptr;
834 cliprdrPlugin* cliprdr = nullptr;
835
836 WINPR_ASSERT(context);
837 WINPR_ASSERT(unlockClipboardData);
838
839 cliprdr = (cliprdrPlugin*)context->handle;
840 WINPR_ASSERT(cliprdr);
841
842 s = cliprdr_packet_unlock_clipdata_new(unlockClipboardData);
843
844 if (!s)
845 {
846 WLog_Print(cliprdr->log, WLOG_ERROR, "cliprdr_packet_unlock_clipdata_new failed!");
847 return ERROR_INTERNAL_ERROR;
848 }
849
850 WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientUnlockClipboardData: clipDataId: 0x%08" PRIX32 "",
851 unlockClipboardData->clipDataId);
852 return cliprdr_packet_send(cliprdr, s);
853}
854
860static UINT cliprdr_client_format_data_request(CliprdrClientContext* context,
861 const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
862{
863 WINPR_ASSERT(context);
864 WINPR_ASSERT(formatDataRequest);
865
866 cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle;
867 WINPR_ASSERT(cliprdr);
868
869 const UINT32 mask =
870 freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask);
871 if ((mask & (CLIPRDR_FLAG_REMOTE_TO_LOCAL | CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES)) == 0)
872 {
873 WLog_Print(cliprdr->log, WLOG_WARN, "remote -> local copy disabled, ignoring request");
874 return CHANNEL_RC_OK;
875 }
876
877 wStream* s = cliprdr_packet_new(CB_FORMAT_DATA_REQUEST, 0, 4);
878 if (!s)
879 {
880 WLog_Print(cliprdr->log, WLOG_ERROR, "cliprdr_packet_new failed!");
881 return ERROR_INTERNAL_ERROR;
882 }
883
884 Stream_Write_UINT32(s, formatDataRequest->requestedFormatId); /* requestedFormatId (4 bytes) */
885 WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatDataRequest(0x%08" PRIx32 " [%s])",
886 formatDataRequest->requestedFormatId,
887 ClipboardGetFormatIdString(formatDataRequest->requestedFormatId));
888 return cliprdr_packet_send(cliprdr, s);
889}
890
896static UINT
897cliprdr_client_format_data_response(CliprdrClientContext* context,
898 const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
899{
900 WINPR_ASSERT(context);
901 WINPR_ASSERT(formatDataResponse);
902
903 cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle;
904 WINPR_ASSERT(cliprdr);
905
906 WINPR_ASSERT(
907 (freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask) &
908 (CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES)) != 0);
909
910 wStream* s = cliprdr_packet_new(CB_FORMAT_DATA_RESPONSE, formatDataResponse->common.msgFlags,
911 formatDataResponse->common.dataLen);
912
913 if (!s)
914 {
915 WLog_Print(cliprdr->log, WLOG_ERROR, "cliprdr_packet_new failed!");
916 return ERROR_INTERNAL_ERROR;
917 }
918
919 Stream_Write(s, formatDataResponse->requestedFormatData, formatDataResponse->common.dataLen);
920 WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatDataResponse");
921 return cliprdr_packet_send(cliprdr, s);
922}
923
929static UINT
930cliprdr_client_file_contents_request(CliprdrClientContext* context,
931 const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
932{
933 WINPR_ASSERT(context);
934 WINPR_ASSERT(fileContentsRequest);
935
936 cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle;
937 if (!cliprdr)
938 return ERROR_INTERNAL_ERROR;
939
940 if (!cliprdr->streamFileClipEnabled)
941 {
942 WLog_Print(cliprdr->log, WLOG_WARN,
943 "clipboard::filecontents requested, but feature not announced! aborting.");
944 return ERROR_INVALID_DATA;
945 }
946
947 const UINT32 mask =
948 freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask);
949 if ((mask & CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES) == 0)
950 {
951 WLog_Print(cliprdr->log, WLOG_WARN, "remote -> local file copy disabled, ignoring request");
952 return CHANNEL_RC_OK;
953 }
954
955 if (!cliprdr->hasHugeFileSupport)
956 {
957 if (((UINT64)fileContentsRequest->cbRequested + fileContentsRequest->nPositionLow) >
958 UINT32_MAX)
959 return ERROR_INVALID_PARAMETER;
960 if (fileContentsRequest->nPositionHigh != 0)
961 return ERROR_INVALID_PARAMETER;
962 }
963
964 wStream* s = cliprdr_packet_file_contents_request_new(fileContentsRequest);
965
966 if (!s)
967 {
968 WLog_Print(cliprdr->log, WLOG_ERROR, "cliprdr_packet_file_contents_request_new failed!");
969 return ERROR_INTERNAL_ERROR;
970 }
971
972 WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFileContentsRequest: streamId: 0x%08" PRIX32 "",
973 fileContentsRequest->streamId);
974 return cliprdr_packet_send(cliprdr, s);
975}
976
982static UINT
983cliprdr_client_file_contents_response(CliprdrClientContext* context,
984 const CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse)
985{
986 WINPR_ASSERT(context);
987 WINPR_ASSERT(fileContentsResponse);
988
989 cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle;
990 WINPR_ASSERT(cliprdr);
991
992 if (!cliprdr->streamFileClipEnabled)
993 {
994 WLog_Print(
995 cliprdr->log, WLOG_WARN,
996 "clipboard::filecontents_response requested, but feature not announced! aborting.");
997 return ERROR_INVALID_DATA;
998 }
999
1000 const UINT32 mask =
1001 freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask);
1002 if ((mask & CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES) == 0)
1003 return cliprdr_send_error_response(cliprdr, CB_FILECONTENTS_RESPONSE);
1004
1005 wStream* s = cliprdr_packet_file_contents_response_new(fileContentsResponse);
1006
1007 if (!s)
1008 {
1009 WLog_Print(cliprdr->log, WLOG_ERROR, "cliprdr_packet_file_contents_response_new failed!");
1010 return ERROR_INTERNAL_ERROR;
1011 }
1012
1013 WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFileContentsResponse: streamId: 0x%08" PRIX32 "",
1014 fileContentsResponse->streamId);
1015 return cliprdr_packet_send(cliprdr, s);
1016}
1017
1018static VOID VCAPITYPE cliprdr_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle,
1019 UINT event, LPVOID pData,
1020 UINT32 dataLength, UINT32 totalLength,
1021 UINT32 dataFlags)
1022{
1023 UINT error = CHANNEL_RC_OK;
1024 cliprdrPlugin* cliprdr = (cliprdrPlugin*)lpUserParam;
1025 WINPR_ASSERT(cliprdr);
1026
1027 switch (event)
1028 {
1029 case CHANNEL_EVENT_DATA_RECEIVED:
1030 if (cliprdr->OpenHandle != openHandle)
1031 {
1032 WLog_Print(cliprdr->log, WLOG_ERROR, "error no match");
1033 return;
1034 }
1035 if ((error = channel_client_post_message(cliprdr->MsgsHandle, pData, dataLength,
1036 totalLength, dataFlags)))
1037 WLog_Print(cliprdr->log, WLOG_ERROR, "failed with error %" PRIu32 "", error);
1038
1039 break;
1040
1041 case CHANNEL_EVENT_WRITE_CANCELLED:
1042 case CHANNEL_EVENT_WRITE_COMPLETE:
1043 {
1044 wStream* s = (wStream*)pData;
1045 Stream_Free(s, TRUE);
1046 }
1047 break;
1048
1049 case CHANNEL_EVENT_USER:
1050 break;
1051 default:
1052 break;
1053 }
1054
1055 if (error && cliprdr->context->rdpcontext)
1056 setChannelError(cliprdr->context->rdpcontext, error,
1057 "cliprdr_virtual_channel_open_event_ex reported an error");
1058}
1059
1065static UINT cliprdr_virtual_channel_event_connected(cliprdrPlugin* cliprdr,
1066 WINPR_ATTR_UNUSED LPVOID pData,
1067 WINPR_ATTR_UNUSED UINT32 dataLength)
1068{
1069 DWORD status = 0;
1070 WINPR_ASSERT(cliprdr);
1071 WINPR_ASSERT(cliprdr->context);
1072
1073 WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelOpenEx);
1074 status = cliprdr->channelEntryPoints.pVirtualChannelOpenEx(
1075 cliprdr->InitHandle, &cliprdr->OpenHandle, cliprdr->channelDef.name,
1076 cliprdr_virtual_channel_open_event_ex);
1077 if (status != CHANNEL_RC_OK)
1078 return status;
1079
1080 cliprdr->MsgsHandle = channel_client_create_handler(
1081 cliprdr->context->rdpcontext, cliprdr, cliprdr_order_recv, CLIPRDR_SVC_CHANNEL_NAME);
1082 if (!cliprdr->MsgsHandle)
1083 return ERROR_INTERNAL_ERROR;
1084
1085 return status;
1086}
1087
1093static UINT cliprdr_virtual_channel_event_disconnected(cliprdrPlugin* cliprdr)
1094{
1095 UINT rc = 0;
1096
1097 WINPR_ASSERT(cliprdr);
1098
1099 channel_client_quit_handler(cliprdr->MsgsHandle);
1100 cliprdr->MsgsHandle = nullptr;
1101
1102 if (cliprdr->OpenHandle == 0)
1103 return CHANNEL_RC_OK;
1104
1105 WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelCloseEx);
1106 rc = cliprdr->channelEntryPoints.pVirtualChannelCloseEx(cliprdr->InitHandle,
1107 cliprdr->OpenHandle);
1108
1109 if (CHANNEL_RC_OK != rc)
1110 {
1111 WLog_Print(cliprdr->log, WLOG_ERROR, "pVirtualChannelClose failed with %s [%08" PRIX32 "]",
1112 WTSErrorToString(rc), rc);
1113 return rc;
1114 }
1115
1116 cliprdr->OpenHandle = 0;
1117
1118 return CHANNEL_RC_OK;
1119}
1120
1126static UINT cliprdr_virtual_channel_event_terminated(cliprdrPlugin* cliprdr)
1127{
1128 WINPR_ASSERT(cliprdr);
1129
1130 cliprdr->InitHandle = nullptr;
1131 free(cliprdr->context);
1132 free(cliprdr);
1133 return CHANNEL_RC_OK;
1134}
1135
1136static VOID VCAPITYPE cliprdr_virtual_channel_init_event_ex(LPVOID lpUserParam, LPVOID pInitHandle,
1137 UINT event, LPVOID pData,
1138 UINT dataLength)
1139{
1140 UINT error = CHANNEL_RC_OK;
1141 cliprdrPlugin* cliprdr = (cliprdrPlugin*)lpUserParam;
1142 WINPR_ASSERT(cliprdr);
1143
1144 if (cliprdr->InitHandle != pInitHandle)
1145 {
1146 WLog_Print(cliprdr->log, WLOG_ERROR, "error no match");
1147 return;
1148 }
1149
1150 switch (event)
1151 {
1152 case CHANNEL_EVENT_CONNECTED:
1153 if ((error = cliprdr_virtual_channel_event_connected(cliprdr, pData, dataLength)))
1154 WLog_Print(cliprdr->log, WLOG_ERROR,
1155 "cliprdr_virtual_channel_event_connected failed with error %" PRIu32 "!",
1156 error);
1157
1158 break;
1159
1160 case CHANNEL_EVENT_DISCONNECTED:
1161 if ((error = cliprdr_virtual_channel_event_disconnected(cliprdr)))
1162 WLog_Print(cliprdr->log, WLOG_ERROR,
1163 "cliprdr_virtual_channel_event_disconnected failed with error %" PRIu32
1164 "!",
1165 error);
1166
1167 break;
1168
1169 case CHANNEL_EVENT_TERMINATED:
1170 if ((error = cliprdr_virtual_channel_event_terminated(cliprdr)))
1171 WLog_Print(cliprdr->log, WLOG_ERROR,
1172 "cliprdr_virtual_channel_event_terminated failed with error %" PRIu32
1173 "!",
1174 error);
1175 break;
1176 default:
1177 break;
1178 }
1179
1180 if (error && cliprdr->context->rdpcontext)
1181 setChannelError(cliprdr->context->rdpcontext, error,
1182 "cliprdr_virtual_channel_init_event reported an error");
1183}
1184
1185/* cliprdr is always built-in */
1186#define VirtualChannelEntryEx cliprdr_VirtualChannelEntryEx
1187
1188FREERDP_ENTRY_POINT(BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS_EX pEntryPoints,
1189 PVOID pInitHandle))
1190{
1191 UINT rc = 0;
1192 CHANNEL_ENTRY_POINTS_FREERDP_EX* pEntryPointsEx = nullptr;
1193 cliprdrPlugin* cliprdr = (cliprdrPlugin*)calloc(1, sizeof(cliprdrPlugin));
1194
1195 wLog* log = WLog_Get(CHANNELS_TAG("cliprdr.client"));
1196 WINPR_ASSERT(log);
1197
1198 if (!cliprdr)
1199 {
1200 WLog_Print(log, WLOG_ERROR, "calloc failed!");
1201 return FALSE;
1202 }
1203
1204 cliprdr->log = log;
1205 cliprdr->channelDef.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP |
1206 CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL;
1207 (void)sprintf_s(cliprdr->channelDef.name, ARRAYSIZE(cliprdr->channelDef.name),
1208 CLIPRDR_SVC_CHANNEL_NAME);
1209 pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP_EX*)pEntryPoints;
1210 WINPR_ASSERT(pEntryPointsEx);
1211
1212 if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX)) &&
1213 (pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))
1214 {
1215 CliprdrClientContext* context =
1216 (CliprdrClientContext*)calloc(1, sizeof(CliprdrClientContext));
1217
1218 if (!context)
1219 {
1220 WLog_Print(cliprdr->log, WLOG_ERROR, "calloc failed!");
1221 free(cliprdr);
1222 return FALSE;
1223 }
1224
1225 context->handle = (void*)cliprdr;
1226 context->custom = nullptr;
1227 context->ClientCapabilities = cliprdr_client_capabilities;
1228 context->TempDirectory = cliprdr_temp_directory;
1229 context->ClientFormatList = cliprdr_client_format_list;
1230 context->ClientFormatListResponse = cliprdr_client_format_list_response;
1231 context->ClientLockClipboardData = cliprdr_client_lock_clipboard_data;
1232 context->ClientUnlockClipboardData = cliprdr_client_unlock_clipboard_data;
1233 context->ClientFormatDataRequest = cliprdr_client_format_data_request;
1234 context->ClientFormatDataResponse = cliprdr_client_format_data_response;
1235 context->ClientFileContentsRequest = cliprdr_client_file_contents_request;
1236 context->ClientFileContentsResponse = cliprdr_client_file_contents_response;
1237 cliprdr->context = context;
1238 context->rdpcontext = pEntryPointsEx->context;
1239 }
1240
1241 WLog_Print(cliprdr->log, WLOG_DEBUG, "VirtualChannelEntryEx");
1242 CopyMemory(&(cliprdr->channelEntryPoints), pEntryPoints,
1244 cliprdr->InitHandle = pInitHandle;
1245 rc = cliprdr->channelEntryPoints.pVirtualChannelInitEx(
1246 cliprdr, cliprdr->context, pInitHandle, &cliprdr->channelDef, 1,
1247 VIRTUAL_CHANNEL_VERSION_WIN2000, cliprdr_virtual_channel_init_event_ex);
1248
1249 if (CHANNEL_RC_OK != rc)
1250 {
1251 WLog_Print(cliprdr->log, WLOG_ERROR, "pVirtualChannelInit failed with %s [%08" PRIX32 "]",
1252 WTSErrorToString(rc), rc);
1253 free(cliprdr->context);
1254 free(cliprdr);
1255 return FALSE;
1256 }
1257
1258 cliprdr->channelEntryPoints.pInterface = cliprdr->context;
1259 return TRUE;
1260}
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
Definition svc.h:60