23#include <freerdp/config.h>
25#include <winpr/wtypes.h>
26#include <winpr/assert.h>
28#include <winpr/print.h>
29#include <winpr/clipboard.h>
31#include <freerdp/types.h>
32#include <freerdp/constants.h>
33#include <freerdp/freerdp.h>
34#include <freerdp/client/cliprdr.h>
36#include "../../../channels/client/addin.h"
38#include "cliprdr_main.h"
39#include "cliprdr_format.h"
40#include "../cliprdr_common.h"
42const char type_FileGroupDescriptorW[] =
"FileGroupDescriptorW";
43const char type_FileContents[] =
"FileContents";
45CliprdrClientContext* cliprdr_get_client_interface(
cliprdrPlugin* cliprdr)
47 CliprdrClientContext* pInterface =
nullptr;
52 pInterface = (CliprdrClientContext*)cliprdr->channelEntryPoints.pInterface;
63 UINT status = ERROR_INVALID_DATA;
65 WINPR_ASSERT(cliprdr);
68 const size_t pos = Stream_GetPosition(s);
69 WINPR_ASSERT(pos >= 8ULL);
70 WINPR_ASSERT(pos <= UINT32_MAX - 8);
72 const uint32_t dataLen = WINPR_ASSERTING_INT_CAST(uint32_t, pos - 8UL);
74 if (!Stream_SetPosition(s, 4))
76 Stream_Write_UINT32(s, dataLen);
77 if (!Stream_SetPosition(s, pos))
80 WLog_Print(cliprdr->log, WLOG_DEBUG,
"Cliprdr Sending (%" PRIuz
" bytes)", pos);
83 status = CHANNEL_RC_BAD_INIT_HANDLE;
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);
93 if (status != CHANNEL_RC_OK)
96 WLog_Print(cliprdr->log, WLOG_ERROR,
"VirtualChannelWrite failed with %s [%08" PRIX32
"]",
97 WTSErrorToString(status), status);
103UINT cliprdr_send_error_response(
cliprdrPlugin* cliprdr, UINT16 type)
105 wStream* s = cliprdr_packet_new(type, CB_RESPONSE_FAIL, 0);
108 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_new failed!");
109 return ERROR_OUTOFMEMORY;
112 return cliprdr_packet_send(cliprdr, s);
115static void cliprdr_print_general_capability_flags(wLog* log, UINT32 flags)
117 WLog_Print(log, WLOG_DEBUG,
"generalFlags (0x%08" PRIX32
") {", flags);
119 if (flags & CB_USE_LONG_FORMAT_NAMES)
120 WLog_Print(log, WLOG_DEBUG,
"\tCB_USE_LONG_FORMAT_NAMES");
122 if (flags & CB_STREAM_FILECLIP_ENABLED)
123 WLog_Print(log, WLOG_DEBUG,
"\tCB_STREAM_FILECLIP_ENABLED");
125 if (flags & CB_FILECLIP_NO_FILE_PATHS)
126 WLog_Print(log, WLOG_DEBUG,
"\tCB_FILECLIP_NO_FILE_PATHS");
128 if (flags & CB_CAN_LOCK_CLIPDATA)
129 WLog_Print(log, WLOG_DEBUG,
"\tCB_CAN_LOCK_CLIPDATA");
131 if (flags & CB_HUGE_FILE_SUPPORT_ENABLED)
132 WLog_Print(log, WLOG_DEBUG,
"\tCB_HUGE_FILE_SUPPORT_ENABLED");
134 WLog_Print(log, WLOG_DEBUG,
"}");
145 UINT32 generalFlags = 0;
148 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
149 UINT error = CHANNEL_RC_OK;
151 WINPR_ASSERT(cliprdr);
156 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_get_client_interface failed!");
157 return ERROR_INTERNAL_ERROR;
160 if (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, 8))
161 return ERROR_INVALID_DATA;
163 Stream_Read_UINT32(s, version);
164 Stream_Read_UINT32(s, generalFlags);
165 WLog_Print(cliprdr->log, WLOG_DEBUG,
"Version: %" PRIu32
"", version);
167 cliprdr_print_general_capability_flags(cliprdr->log, generalFlags);
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;
176 capabilities.common.msgType = CB_CLIP_CAPS;
177 capabilities.cCapabilitiesSets = 1;
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);
186 WLog_Print(cliprdr->log, WLOG_ERROR,
"ServerCapabilities failed with error %" PRIu32
"!",
198 WINPR_ATTR_UNUSED UINT32 length,
199 WINPR_ATTR_UNUSED UINT16 flags)
201 UINT16 lengthCapability = 0;
202 UINT16 cCapabilitiesSets = 0;
203 UINT16 capabilitySetType = 0;
204 UINT error = CHANNEL_RC_OK;
206 WINPR_ASSERT(cliprdr);
209 if (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, 4))
210 return ERROR_INVALID_DATA;
212 Stream_Read_UINT16(s, cCapabilitiesSets);
213 Stream_Seek_UINT16(s);
214 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ServerCapabilities");
216 for (UINT16 index = 0; index < cCapabilitiesSets; index++)
218 if (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, 4))
219 return ERROR_INVALID_DATA;
221 Stream_Read_UINT16(s, capabilitySetType);
222 Stream_Read_UINT16(s, lengthCapability);
224 if ((lengthCapability < 4) ||
225 (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, lengthCapability - 4U)))
226 return ERROR_INVALID_DATA;
228 switch (capabilitySetType)
230 case CB_CAPSTYPE_GENERAL:
231 if ((error = cliprdr_process_general_capability(cliprdr, s)))
233 WLog_Print(cliprdr->log, WLOG_ERROR,
234 "cliprdr_process_general_capability failed with error %" PRIu32
"!",
242 WLog_Print(cliprdr->log, WLOG_ERROR,
"unknown cliprdr capability set: %" PRIu16
"",
244 return CHANNEL_RC_BAD_PROC;
257 UINT32 length, UINT16 flags)
260 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
261 UINT error = CHANNEL_RC_OK;
263 WINPR_ASSERT(cliprdr);
266 WLog_Print(cliprdr->log, WLOG_DEBUG,
"MonitorReady");
268 if (!cliprdr->capabilitiesReceived)
276 cliprdr->useLongFormatNames = FALSE;
277 cliprdr->streamFileClipEnabled = FALSE;
278 cliprdr->fileClipNoFilePaths = TRUE;
279 cliprdr->canLockClipData = FALSE;
282 monitorReady.common.msgType = CB_MONITOR_READY;
283 monitorReady.common.msgFlags = flags;
284 monitorReady.common.dataLen = length;
285 IFCALLRET(context->MonitorReady, error, context, &monitorReady);
288 WLog_Print(cliprdr->log, WLOG_ERROR,
"MonitorReady failed with error %" PRIu32
"!", error);
298static UINT cliprdr_process_filecontents_request(
cliprdrPlugin* cliprdr,
wStream* s, UINT32 length,
302 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
303 UINT error = CHANNEL_RC_OK;
305 WINPR_ASSERT(cliprdr);
308 WLog_Print(cliprdr->log, WLOG_DEBUG,
"FileContentsRequest");
310 request.common.msgType = CB_FILECONTENTS_REQUEST;
311 request.common.msgFlags = flags;
312 request.common.dataLen = length;
314 if ((error = cliprdr_read_file_contents_request(s, &request)))
319 if ((mask & (CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES)) == 0)
321 WLog_Print(cliprdr->log, WLOG_WARN,
"local -> remote file copy disabled, ignoring request");
322 return cliprdr_send_error_response(cliprdr, CB_FILECONTENTS_RESPONSE);
324 IFCALLRET(context->ServerFileContentsRequest, error, context, &request);
327 WLog_Print(cliprdr->log, WLOG_ERROR,
328 "ServerFileContentsRequest failed with error %" PRIu32
"!", error);
338static UINT cliprdr_process_filecontents_response(
cliprdrPlugin* cliprdr,
wStream* s, UINT32 length,
342 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
343 UINT error = CHANNEL_RC_OK;
345 WINPR_ASSERT(cliprdr);
348 WLog_Print(cliprdr->log, WLOG_DEBUG,
"FileContentsResponse");
350 response.common.msgType = CB_FILECONTENTS_RESPONSE;
351 response.common.msgFlags = flags;
352 response.common.dataLen = length;
354 if ((error = cliprdr_read_file_contents_response(s, &response)))
357 IFCALLRET(context->ServerFileContentsResponse, error, context, &response);
360 WLog_Print(cliprdr->log, WLOG_ERROR,
361 "ServerFileContentsResponse failed with error %" PRIu32
"!", error);
375 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
376 UINT error = CHANNEL_RC_OK;
378 WINPR_ASSERT(cliprdr);
381 WLog_Print(cliprdr->log, WLOG_DEBUG,
"LockClipData");
383 if (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, 4))
384 return ERROR_INVALID_DATA;
386 lockClipboardData.common.msgType = CB_LOCK_CLIPDATA;
387 lockClipboardData.common.msgFlags = flags;
388 lockClipboardData.common.dataLen = length;
389 Stream_Read_UINT32(s, lockClipboardData.clipDataId);
390 IFCALLRET(context->ServerLockClipboardData, error, context, &lockClipboardData);
393 WLog_Print(cliprdr->log, WLOG_ERROR,
394 "ServerLockClipboardData failed with error %" PRIu32
"!", error);
408 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
409 UINT error = CHANNEL_RC_OK;
411 WINPR_ASSERT(cliprdr);
414 WLog_Print(cliprdr->log, WLOG_DEBUG,
"UnlockClipData");
416 if ((error = cliprdr_read_unlock_clipdata(s, &unlockClipboardData)))
419 unlockClipboardData.common.msgType = CB_UNLOCK_CLIPDATA;
420 unlockClipboardData.common.msgFlags = flags;
421 unlockClipboardData.common.dataLen = length;
423 IFCALLRET(context->ServerUnlockClipboardData, error, context, &unlockClipboardData);
426 WLog_Print(cliprdr->log, WLOG_ERROR,
427 "ServerUnlockClipboardData failed with error %" PRIu32
"!", error);
437static UINT cliprdr_order_recv(LPVOID userdata,
wStream* s)
445 WINPR_ASSERT(cliprdr);
448 if (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, 8))
449 return ERROR_INVALID_DATA;
451 Stream_Read_UINT16(s, msgType);
452 Stream_Read_UINT16(s, msgFlags);
453 Stream_Read_UINT32(s, dataLen);
455 if (!Stream_CheckAndLogRequiredLengthWLog(cliprdr->log, s, dataLen))
456 return ERROR_INVALID_DATA;
458 char buffer1[64] = WINPR_C_ARRAY_INIT;
459 char buffer2[64] = WINPR_C_ARRAY_INIT;
460 WLog_Print(cliprdr->log, WLOG_DEBUG,
461 "msgType: %s (%" PRIu16
"), msgFlags: %s dataLen: %" PRIu32
"",
462 CB_MSG_TYPE_STRING(msgType, buffer1,
sizeof(buffer1)), msgType,
463 CB_MSG_FLAGS_STRING(msgFlags, buffer2,
sizeof(buffer2)), dataLen);
468 if ((error = cliprdr_process_clip_caps(cliprdr, s, dataLen, msgFlags)))
469 WLog_Print(cliprdr->log, WLOG_ERROR,
470 "cliprdr_process_clip_caps failed with error %" PRIu32
"!", error);
474 case CB_MONITOR_READY:
475 if ((error = cliprdr_process_monitor_ready(cliprdr, s, dataLen, msgFlags)))
476 WLog_Print(cliprdr->log, WLOG_ERROR,
477 "cliprdr_process_monitor_ready failed with error %" PRIu32
"!", error);
482 if ((error = cliprdr_process_format_list(cliprdr, s, dataLen, msgFlags)))
483 WLog_Print(cliprdr->log, WLOG_ERROR,
484 "cliprdr_process_format_list failed with error %" PRIu32
"!", error);
488 case CB_FORMAT_LIST_RESPONSE:
489 if ((error = cliprdr_process_format_list_response(cliprdr, s, dataLen, msgFlags)))
490 WLog_Print(cliprdr->log, WLOG_ERROR,
491 "cliprdr_process_format_list_response failed with error %" PRIu32
"!",
496 case CB_FORMAT_DATA_REQUEST:
497 if ((error = cliprdr_process_format_data_request(cliprdr, s, dataLen, msgFlags)))
498 WLog_Print(cliprdr->log, WLOG_ERROR,
499 "cliprdr_process_format_data_request failed with error %" PRIu32
"!",
504 case CB_FORMAT_DATA_RESPONSE:
505 if ((error = cliprdr_process_format_data_response(cliprdr, s, dataLen, msgFlags)))
506 WLog_Print(cliprdr->log, WLOG_ERROR,
507 "cliprdr_process_format_data_response failed with error %" PRIu32
"!",
512 case CB_FILECONTENTS_REQUEST:
513 if ((error = cliprdr_process_filecontents_request(cliprdr, s, dataLen, msgFlags)))
514 WLog_Print(cliprdr->log, WLOG_ERROR,
515 "cliprdr_process_filecontents_request failed with error %" PRIu32
"!",
520 case CB_FILECONTENTS_RESPONSE:
521 if ((error = cliprdr_process_filecontents_response(cliprdr, s, dataLen, msgFlags)))
522 WLog_Print(cliprdr->log, WLOG_ERROR,
523 "cliprdr_process_filecontents_response failed with error %" PRIu32
"!",
528 case CB_LOCK_CLIPDATA:
529 if ((error = cliprdr_process_lock_clipdata(cliprdr, s, dataLen, msgFlags)))
530 WLog_Print(cliprdr->log, WLOG_ERROR,
531 "cliprdr_process_lock_clipdata failed with error %" PRIu32
"!", error);
535 case CB_UNLOCK_CLIPDATA:
536 if ((error = cliprdr_process_unlock_clipdata(cliprdr, s, dataLen, msgFlags)))
537 WLog_Print(cliprdr->log, WLOG_ERROR,
538 "cliprdr_process_unlock_clipdata failed with error %" PRIu32
"!", error);
543 error = CHANNEL_RC_BAD_PROC;
544 WLog_Print(cliprdr->log, WLOG_ERROR,
"unknown msgType %" PRIu16
"", msgType);
548 Stream_Free(s, TRUE);
561static UINT cliprdr_client_capabilities(CliprdrClientContext* context,
569 WINPR_ASSERT(context);
572 WINPR_ASSERT(cliprdr);
574 s = cliprdr_packet_new(CB_CLIP_CAPS, 0, 4 + CB_CAPSTYPE_GENERAL_LEN);
578 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_new failed!");
579 return ERROR_INTERNAL_ERROR;
582 Stream_Write_UINT16(s, 1);
583 Stream_Write_UINT16(s, 0);
585 Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetType);
586 Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetLength);
587 Stream_Write_UINT32(s, generalCapabilitySet->version);
588 flags = generalCapabilitySet->generalFlags;
594 if (!cliprdr->useLongFormatNames)
595 flags &= (uint32_t)~CB_USE_LONG_FORMAT_NAMES;
596 if (!cliprdr->streamFileClipEnabled)
597 flags &= (uint32_t)~CB_STREAM_FILECLIP_ENABLED;
598 if (!cliprdr->fileClipNoFilePaths)
599 flags &= (uint32_t)~CB_FILECLIP_NO_FILE_PATHS;
600 if (!cliprdr->canLockClipData)
601 flags &= (uint32_t)~CB_CAN_LOCK_CLIPDATA;
602 if (!cliprdr->hasHugeFileSupport)
603 flags &= (uint32_t)~CB_HUGE_FILE_SUPPORT_ENABLED;
605 cliprdr->useLongFormatNames = (flags & CB_USE_LONG_FORMAT_NAMES) != 0;
606 cliprdr->streamFileClipEnabled = (flags & CB_STREAM_FILECLIP_ENABLED) != 0;
607 cliprdr->fileClipNoFilePaths = (flags & CB_FILECLIP_NO_FILE_PATHS) != 0;
608 cliprdr->canLockClipData = (flags & CB_CAN_LOCK_CLIPDATA) != 0;
609 cliprdr->hasHugeFileSupport = (flags & CB_HUGE_FILE_SUPPORT_ENABLED) != 0;
611 Stream_Write_UINT32(s, flags);
612 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientCapabilities");
614 cliprdr->initialFormatListSent = FALSE;
616 return cliprdr_packet_send(cliprdr, s);
624static UINT cliprdr_temp_directory(CliprdrClientContext* context,
630 WINPR_ASSERT(context);
631 WINPR_ASSERT(tempDirectory);
634 WINPR_ASSERT(cliprdr);
636 const size_t tmpDirCharLen =
sizeof(tempDirectory->szTempDir) /
sizeof(WCHAR);
637 s = cliprdr_packet_new(CB_TEMP_DIRECTORY, 0, tmpDirCharLen *
sizeof(WCHAR));
641 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_new failed!");
642 return ERROR_INTERNAL_ERROR;
645 if (Stream_Write_UTF16_String_From_UTF8(s, tmpDirCharLen - 1, tempDirectory->szTempDir,
646 ARRAYSIZE(tempDirectory->szTempDir), TRUE) < 0)
648 Stream_Free(s, TRUE);
649 return ERROR_INTERNAL_ERROR;
653 Stream_Write_UINT16(s, 0);
655 WLog_Print(cliprdr->log, WLOG_DEBUG,
"TempDirectory: %s", tempDirectory->szTempDir);
656 return cliprdr_packet_send(cliprdr, s);
664static UINT cliprdr_client_format_list(CliprdrClientContext* context,
670 WINPR_ASSERT(context);
671 WINPR_ASSERT(formatList);
674 WINPR_ASSERT(cliprdr);
677 const UINT32 mask = CB_RESPONSE_OK | CB_RESPONSE_FAIL;
678 if ((formatList->common.msgFlags & mask) != 0)
679 WLog_Print(cliprdr->log, WLOG_WARN,
680 "Sending clipboard request with invalid flags msgFlags = 0x%08" PRIx32
681 ". Correct in your client!",
682 formatList->common.msgFlags & mask);
688 formatList, mask, CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES);
691 if ((filterList.numFormats == 0) && cliprdr->initialFormatListSent)
693 cliprdr_free_format_list(&filterList);
694 return CHANNEL_RC_OK;
696 cliprdr->initialFormatListSent = TRUE;
698 const uint32_t level = WLOG_DEBUG;
699 if (WLog_IsLevelActive(cliprdr->log, level))
701 WLog_Print(cliprdr->log, level,
"ClientFormatList: numFormats: %" PRIu32
"",
702 formatList->numFormats);
703 for (
size_t x = 0; x < filterList.numFormats; x++)
706 WLog_Print(cliprdr->log, level,
"[%" PRIuz
"]: id=0x%08" PRIx32
" [%s|%s]", x,
707 format->formatId, ClipboardGetFormatIdString(format->formatId),
712 s = cliprdr_packet_format_list_new(&filterList, cliprdr->useLongFormatNames, FALSE);
713 cliprdr_free_format_list(&filterList);
717 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_format_list_new failed!");
718 return ERROR_INTERNAL_ERROR;
721 return cliprdr_packet_send(cliprdr, s);
730cliprdr_client_format_list_response(CliprdrClientContext* context,
736 WINPR_ASSERT(context);
737 WINPR_ASSERT(formatListResponse);
740 WINPR_ASSERT(cliprdr);
742 s = cliprdr_packet_new(CB_FORMAT_LIST_RESPONSE, formatListResponse->common.msgFlags, 0);
746 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_new failed!");
747 return ERROR_INTERNAL_ERROR;
750 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFormatListResponse");
751 return cliprdr_packet_send(cliprdr, s);
759static UINT cliprdr_client_lock_clipboard_data(CliprdrClientContext* context,
765 WINPR_ASSERT(context);
766 WINPR_ASSERT(lockClipboardData);
769 WINPR_ASSERT(cliprdr);
771 s = cliprdr_packet_lock_clipdata_new(lockClipboardData);
775 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_lock_clipdata_new failed!");
776 return ERROR_INTERNAL_ERROR;
779 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientLockClipboardData: clipDataId: 0x%08" PRIX32
"",
780 lockClipboardData->clipDataId);
781 return cliprdr_packet_send(cliprdr, s);
790cliprdr_client_unlock_clipboard_data(CliprdrClientContext* context,
796 WINPR_ASSERT(context);
797 WINPR_ASSERT(unlockClipboardData);
800 WINPR_ASSERT(cliprdr);
802 s = cliprdr_packet_unlock_clipdata_new(unlockClipboardData);
806 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_unlock_clipdata_new failed!");
807 return ERROR_INTERNAL_ERROR;
810 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientUnlockClipboardData: clipDataId: 0x%08" PRIX32
"",
811 unlockClipboardData->clipDataId);
812 return cliprdr_packet_send(cliprdr, s);
820static UINT cliprdr_client_format_data_request(CliprdrClientContext* context,
823 WINPR_ASSERT(context);
824 WINPR_ASSERT(formatDataRequest);
827 WINPR_ASSERT(cliprdr);
831 if ((mask & (CLIPRDR_FLAG_REMOTE_TO_LOCAL | CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES)) == 0)
833 WLog_Print(cliprdr->log, WLOG_WARN,
"remote -> local copy disabled, ignoring request");
834 return CHANNEL_RC_OK;
837 wStream* s = cliprdr_packet_new(CB_FORMAT_DATA_REQUEST, 0, 4);
840 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_new failed!");
841 return ERROR_INTERNAL_ERROR;
844 Stream_Write_UINT32(s, formatDataRequest->requestedFormatId);
845 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFormatDataRequest(0x%08" PRIx32
" [%s])",
846 formatDataRequest->requestedFormatId,
847 ClipboardGetFormatIdString(formatDataRequest->requestedFormatId));
848 return cliprdr_packet_send(cliprdr, s);
857cliprdr_client_format_data_response(CliprdrClientContext* context,
860 WINPR_ASSERT(context);
861 WINPR_ASSERT(formatDataResponse);
864 WINPR_ASSERT(cliprdr);
868 (CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES)) != 0);
870 wStream* s = cliprdr_packet_new(CB_FORMAT_DATA_RESPONSE, formatDataResponse->common.msgFlags,
871 formatDataResponse->common.dataLen);
875 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_new failed!");
876 return ERROR_INTERNAL_ERROR;
879 Stream_Write(s, formatDataResponse->requestedFormatData, formatDataResponse->common.dataLen);
880 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFormatDataResponse");
881 return cliprdr_packet_send(cliprdr, s);
890cliprdr_client_file_contents_request(CliprdrClientContext* context,
895 WINPR_ASSERT(context);
896 WINPR_ASSERT(fileContentsRequest);
900 return ERROR_INTERNAL_ERROR;
904 if ((mask & CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES) == 0)
906 WLog_Print(cliprdr->log, WLOG_WARN,
"remote -> local file copy disabled, ignoring request");
907 return CHANNEL_RC_OK;
910 if (!cliprdr->hasHugeFileSupport)
912 if (((UINT64)fileContentsRequest->cbRequested + fileContentsRequest->nPositionLow) >
914 return ERROR_INVALID_PARAMETER;
915 if (fileContentsRequest->nPositionHigh != 0)
916 return ERROR_INVALID_PARAMETER;
919 s = cliprdr_packet_file_contents_request_new(fileContentsRequest);
923 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_file_contents_request_new failed!");
924 return ERROR_INTERNAL_ERROR;
927 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFileContentsRequest: streamId: 0x%08" PRIX32
"",
928 fileContentsRequest->streamId);
929 return cliprdr_packet_send(cliprdr, s);
938cliprdr_client_file_contents_response(CliprdrClientContext* context,
944 WINPR_ASSERT(context);
945 WINPR_ASSERT(fileContentsResponse);
948 WINPR_ASSERT(cliprdr);
952 if ((mask & CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES) == 0)
953 return cliprdr_send_error_response(cliprdr, CB_FILECONTENTS_RESPONSE);
955 s = cliprdr_packet_file_contents_response_new(fileContentsResponse);
959 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_file_contents_response_new failed!");
960 return ERROR_INTERNAL_ERROR;
963 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFileContentsResponse: streamId: 0x%08" PRIX32
"",
964 fileContentsResponse->streamId);
965 return cliprdr_packet_send(cliprdr, s);
968static VOID VCAPITYPE cliprdr_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle,
969 UINT event, LPVOID pData,
970 UINT32 dataLength, UINT32 totalLength,
973 UINT error = CHANNEL_RC_OK;
975 WINPR_ASSERT(cliprdr);
979 case CHANNEL_EVENT_DATA_RECEIVED:
980 if (cliprdr->OpenHandle != openHandle)
982 WLog_Print(cliprdr->log, WLOG_ERROR,
"error no match");
985 if ((error = channel_client_post_message(cliprdr->MsgsHandle, pData, dataLength,
986 totalLength, dataFlags)))
987 WLog_Print(cliprdr->log, WLOG_ERROR,
"failed with error %" PRIu32
"", error);
991 case CHANNEL_EVENT_WRITE_CANCELLED:
992 case CHANNEL_EVENT_WRITE_COMPLETE:
995 Stream_Free(s, TRUE);
999 case CHANNEL_EVENT_USER:
1005 if (error && cliprdr->context->rdpcontext)
1006 setChannelError(cliprdr->context->rdpcontext, error,
1007 "cliprdr_virtual_channel_open_event_ex reported an error");
1015static UINT cliprdr_virtual_channel_event_connected(
cliprdrPlugin* cliprdr,
1016 WINPR_ATTR_UNUSED LPVOID pData,
1017 WINPR_ATTR_UNUSED UINT32 dataLength)
1020 WINPR_ASSERT(cliprdr);
1021 WINPR_ASSERT(cliprdr->context);
1023 WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelOpenEx);
1024 status = cliprdr->channelEntryPoints.pVirtualChannelOpenEx(
1025 cliprdr->InitHandle, &cliprdr->OpenHandle, cliprdr->channelDef.name,
1026 cliprdr_virtual_channel_open_event_ex);
1027 if (status != CHANNEL_RC_OK)
1030 cliprdr->MsgsHandle = channel_client_create_handler(
1031 cliprdr->context->rdpcontext, cliprdr, cliprdr_order_recv, CLIPRDR_SVC_CHANNEL_NAME);
1032 if (!cliprdr->MsgsHandle)
1033 return ERROR_INTERNAL_ERROR;
1043static UINT cliprdr_virtual_channel_event_disconnected(
cliprdrPlugin* cliprdr)
1047 WINPR_ASSERT(cliprdr);
1049 channel_client_quit_handler(cliprdr->MsgsHandle);
1050 cliprdr->MsgsHandle =
nullptr;
1052 if (cliprdr->OpenHandle == 0)
1053 return CHANNEL_RC_OK;
1055 WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelCloseEx);
1056 rc = cliprdr->channelEntryPoints.pVirtualChannelCloseEx(cliprdr->InitHandle,
1057 cliprdr->OpenHandle);
1059 if (CHANNEL_RC_OK != rc)
1061 WLog_Print(cliprdr->log, WLOG_ERROR,
"pVirtualChannelClose failed with %s [%08" PRIX32
"]",
1062 WTSErrorToString(rc), rc);
1066 cliprdr->OpenHandle = 0;
1068 return CHANNEL_RC_OK;
1076static UINT cliprdr_virtual_channel_event_terminated(
cliprdrPlugin* cliprdr)
1078 WINPR_ASSERT(cliprdr);
1080 cliprdr->InitHandle =
nullptr;
1081 free(cliprdr->context);
1083 return CHANNEL_RC_OK;
1086static VOID VCAPITYPE cliprdr_virtual_channel_init_event_ex(LPVOID lpUserParam, LPVOID pInitHandle,
1087 UINT event, LPVOID pData,
1090 UINT error = CHANNEL_RC_OK;
1092 WINPR_ASSERT(cliprdr);
1094 if (cliprdr->InitHandle != pInitHandle)
1096 WLog_Print(cliprdr->log, WLOG_ERROR,
"error no match");
1102 case CHANNEL_EVENT_CONNECTED:
1103 if ((error = cliprdr_virtual_channel_event_connected(cliprdr, pData, dataLength)))
1104 WLog_Print(cliprdr->log, WLOG_ERROR,
1105 "cliprdr_virtual_channel_event_connected failed with error %" PRIu32
"!",
1110 case CHANNEL_EVENT_DISCONNECTED:
1111 if ((error = cliprdr_virtual_channel_event_disconnected(cliprdr)))
1112 WLog_Print(cliprdr->log, WLOG_ERROR,
1113 "cliprdr_virtual_channel_event_disconnected failed with error %" PRIu32
1119 case CHANNEL_EVENT_TERMINATED:
1120 if ((error = cliprdr_virtual_channel_event_terminated(cliprdr)))
1121 WLog_Print(cliprdr->log, WLOG_ERROR,
1122 "cliprdr_virtual_channel_event_terminated failed with error %" PRIu32
1130 if (error && cliprdr->context->rdpcontext)
1131 setChannelError(cliprdr->context->rdpcontext, error,
1132 "cliprdr_virtual_channel_init_event reported an error");
1136#define VirtualChannelEntryEx cliprdr_VirtualChannelEntryEx
1138FREERDP_ENTRY_POINT(BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS_EX pEntryPoints,
1145 wLog* log = WLog_Get(CHANNELS_TAG(
"cliprdr.client"));
1150 WLog_Print(log, WLOG_ERROR,
"calloc failed!");
1155 cliprdr->channelDef.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP |
1156 CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL;
1157 (void)sprintf_s(cliprdr->channelDef.name, ARRAYSIZE(cliprdr->channelDef.name),
1158 CLIPRDR_SVC_CHANNEL_NAME);
1160 WINPR_ASSERT(pEntryPointsEx);
1163 (pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))
1165 CliprdrClientContext* context =
1166 (CliprdrClientContext*)calloc(1,
sizeof(CliprdrClientContext));
1170 WLog_Print(cliprdr->log, WLOG_ERROR,
"calloc failed!");
1175 context->handle = (
void*)cliprdr;
1176 context->custom =
nullptr;
1177 context->ClientCapabilities = cliprdr_client_capabilities;
1178 context->TempDirectory = cliprdr_temp_directory;
1179 context->ClientFormatList = cliprdr_client_format_list;
1180 context->ClientFormatListResponse = cliprdr_client_format_list_response;
1181 context->ClientLockClipboardData = cliprdr_client_lock_clipboard_data;
1182 context->ClientUnlockClipboardData = cliprdr_client_unlock_clipboard_data;
1183 context->ClientFormatDataRequest = cliprdr_client_format_data_request;
1184 context->ClientFormatDataResponse = cliprdr_client_format_data_response;
1185 context->ClientFileContentsRequest = cliprdr_client_file_contents_request;
1186 context->ClientFileContentsResponse = cliprdr_client_file_contents_response;
1187 cliprdr->context = context;
1188 context->rdpcontext = pEntryPointsEx->context;
1191 WLog_Print(cliprdr->log, WLOG_DEBUG,
"VirtualChannelEntryEx");
1192 CopyMemory(&(cliprdr->channelEntryPoints), pEntryPoints,
1194 cliprdr->InitHandle = pInitHandle;
1195 rc = cliprdr->channelEntryPoints.pVirtualChannelInitEx(
1196 cliprdr, cliprdr->context, pInitHandle, &cliprdr->channelDef, 1,
1197 VIRTUAL_CHANNEL_VERSION_WIN2000, cliprdr_virtual_channel_init_event_ex);
1199 if (CHANNEL_RC_OK != rc)
1201 WLog_Print(cliprdr->log, WLOG_ERROR,
"pVirtualChannelInit failed with %s [%08" PRIX32
"]",
1202 WTSErrorToString(rc), rc);
1203 free(cliprdr->context);
1208 cliprdr->channelEntryPoints.pInterface = cliprdr->context;
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.