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 capabilities->capabilitySets);
586 Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetType);
587 Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetLength);
588 Stream_Write_UINT32(s, generalCapabilitySet->version);
589 flags = generalCapabilitySet->generalFlags;
595 if (!cliprdr->useLongFormatNames)
596 flags &= (uint32_t)~CB_USE_LONG_FORMAT_NAMES;
597 if (!cliprdr->streamFileClipEnabled)
598 flags &= (uint32_t)~CB_STREAM_FILECLIP_ENABLED;
599 if (!cliprdr->fileClipNoFilePaths)
600 flags &= (uint32_t)~CB_FILECLIP_NO_FILE_PATHS;
601 if (!cliprdr->canLockClipData)
602 flags &= (uint32_t)~CB_CAN_LOCK_CLIPDATA;
603 if (!cliprdr->hasHugeFileSupport)
604 flags &= (uint32_t)~CB_HUGE_FILE_SUPPORT_ENABLED;
606 cliprdr->useLongFormatNames = (flags & CB_USE_LONG_FORMAT_NAMES) != 0;
607 cliprdr->streamFileClipEnabled = (flags & CB_STREAM_FILECLIP_ENABLED) != 0;
608 cliprdr->fileClipNoFilePaths = (flags & CB_FILECLIP_NO_FILE_PATHS) != 0;
609 cliprdr->canLockClipData = (flags & CB_CAN_LOCK_CLIPDATA) != 0;
610 cliprdr->hasHugeFileSupport = (flags & CB_HUGE_FILE_SUPPORT_ENABLED) != 0;
612 Stream_Write_UINT32(s, flags);
613 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientCapabilities");
615 cliprdr->initialFormatListSent = FALSE;
617 return cliprdr_packet_send(cliprdr, s);
625static UINT cliprdr_temp_directory(CliprdrClientContext* context,
631 WINPR_ASSERT(context);
632 WINPR_ASSERT(tempDirectory);
635 WINPR_ASSERT(cliprdr);
637 const size_t tmpDirCharLen =
sizeof(tempDirectory->szTempDir) /
sizeof(WCHAR);
638 s = cliprdr_packet_new(CB_TEMP_DIRECTORY, 0, tmpDirCharLen *
sizeof(WCHAR));
642 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_new failed!");
643 return ERROR_INTERNAL_ERROR;
646 if (Stream_Write_UTF16_String_From_UTF8(s, tmpDirCharLen - 1, tempDirectory->szTempDir,
647 ARRAYSIZE(tempDirectory->szTempDir), TRUE) < 0)
649 Stream_Free(s, TRUE);
650 return ERROR_INTERNAL_ERROR;
654 Stream_Write_UINT16(s, 0);
656 WLog_Print(cliprdr->log, WLOG_DEBUG,
"TempDirectory: %s", tempDirectory->szTempDir);
657 return cliprdr_packet_send(cliprdr, s);
665static UINT cliprdr_client_format_list(CliprdrClientContext* context,
671 WINPR_ASSERT(context);
672 WINPR_ASSERT(formatList);
675 WINPR_ASSERT(cliprdr);
678 const UINT32 mask = CB_RESPONSE_OK | CB_RESPONSE_FAIL;
679 if ((formatList->common.msgFlags & mask) != 0)
680 WLog_Print(cliprdr->log, WLOG_WARN,
681 "Sending clipboard request with invalid flags msgFlags = 0x%08" PRIx32
682 ". Correct in your client!",
683 formatList->common.msgFlags & mask);
689 formatList, mask, CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES);
692 if ((filterList.numFormats == 0) && cliprdr->initialFormatListSent)
694 cliprdr_free_format_list(&filterList);
695 return CHANNEL_RC_OK;
697 cliprdr->initialFormatListSent = TRUE;
699 const uint32_t level = WLOG_DEBUG;
700 if (WLog_IsLevelActive(cliprdr->log, level))
702 WLog_Print(cliprdr->log, level,
"ClientFormatList: numFormats: %" PRIu32
"",
703 formatList->numFormats);
704 for (
size_t x = 0; x < filterList.numFormats; x++)
707 WLog_Print(cliprdr->log, level,
"[%" PRIuz
"]: id=0x%08" PRIx32
" [%s|%s]", x,
708 format->formatId, ClipboardGetFormatIdString(format->formatId),
713 s = cliprdr_packet_format_list_new(&filterList, cliprdr->useLongFormatNames, FALSE);
714 cliprdr_free_format_list(&filterList);
718 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_format_list_new failed!");
719 return ERROR_INTERNAL_ERROR;
722 return cliprdr_packet_send(cliprdr, s);
731cliprdr_client_format_list_response(CliprdrClientContext* context,
737 WINPR_ASSERT(context);
738 WINPR_ASSERT(formatListResponse);
741 WINPR_ASSERT(cliprdr);
743 s = cliprdr_packet_new(CB_FORMAT_LIST_RESPONSE, formatListResponse->common.msgFlags, 0);
747 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_new failed!");
748 return ERROR_INTERNAL_ERROR;
751 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFormatListResponse");
752 return cliprdr_packet_send(cliprdr, s);
760static UINT cliprdr_client_lock_clipboard_data(CliprdrClientContext* context,
766 WINPR_ASSERT(context);
767 WINPR_ASSERT(lockClipboardData);
770 WINPR_ASSERT(cliprdr);
772 s = cliprdr_packet_lock_clipdata_new(lockClipboardData);
776 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_lock_clipdata_new failed!");
777 return ERROR_INTERNAL_ERROR;
780 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientLockClipboardData: clipDataId: 0x%08" PRIX32
"",
781 lockClipboardData->clipDataId);
782 return cliprdr_packet_send(cliprdr, s);
791cliprdr_client_unlock_clipboard_data(CliprdrClientContext* context,
797 WINPR_ASSERT(context);
798 WINPR_ASSERT(unlockClipboardData);
801 WINPR_ASSERT(cliprdr);
803 s = cliprdr_packet_unlock_clipdata_new(unlockClipboardData);
807 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_unlock_clipdata_new failed!");
808 return ERROR_INTERNAL_ERROR;
811 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientUnlockClipboardData: clipDataId: 0x%08" PRIX32
"",
812 unlockClipboardData->clipDataId);
813 return cliprdr_packet_send(cliprdr, s);
821static UINT cliprdr_client_format_data_request(CliprdrClientContext* context,
824 WINPR_ASSERT(context);
825 WINPR_ASSERT(formatDataRequest);
828 WINPR_ASSERT(cliprdr);
832 if ((mask & (CLIPRDR_FLAG_REMOTE_TO_LOCAL | CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES)) == 0)
834 WLog_Print(cliprdr->log, WLOG_WARN,
"remote -> local copy disabled, ignoring request");
835 return CHANNEL_RC_OK;
838 wStream* s = cliprdr_packet_new(CB_FORMAT_DATA_REQUEST, 0, 4);
841 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_new failed!");
842 return ERROR_INTERNAL_ERROR;
845 Stream_Write_UINT32(s, formatDataRequest->requestedFormatId);
846 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFormatDataRequest(0x%08" PRIx32
" [%s])",
847 formatDataRequest->requestedFormatId,
848 ClipboardGetFormatIdString(formatDataRequest->requestedFormatId));
849 return cliprdr_packet_send(cliprdr, s);
858cliprdr_client_format_data_response(CliprdrClientContext* context,
861 WINPR_ASSERT(context);
862 WINPR_ASSERT(formatDataResponse);
865 WINPR_ASSERT(cliprdr);
869 (CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES)) != 0);
871 wStream* s = cliprdr_packet_new(CB_FORMAT_DATA_RESPONSE, formatDataResponse->common.msgFlags,
872 formatDataResponse->common.dataLen);
876 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_new failed!");
877 return ERROR_INTERNAL_ERROR;
880 Stream_Write(s, formatDataResponse->requestedFormatData, formatDataResponse->common.dataLen);
881 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFormatDataResponse");
882 return cliprdr_packet_send(cliprdr, s);
891cliprdr_client_file_contents_request(CliprdrClientContext* context,
896 WINPR_ASSERT(context);
897 WINPR_ASSERT(fileContentsRequest);
901 return ERROR_INTERNAL_ERROR;
905 if ((mask & CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES) == 0)
907 WLog_Print(cliprdr->log, WLOG_WARN,
"remote -> local file copy disabled, ignoring request");
908 return CHANNEL_RC_OK;
911 if (!cliprdr->hasHugeFileSupport)
913 if (((UINT64)fileContentsRequest->cbRequested + fileContentsRequest->nPositionLow) >
915 return ERROR_INVALID_PARAMETER;
916 if (fileContentsRequest->nPositionHigh != 0)
917 return ERROR_INVALID_PARAMETER;
920 s = cliprdr_packet_file_contents_request_new(fileContentsRequest);
924 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_file_contents_request_new failed!");
925 return ERROR_INTERNAL_ERROR;
928 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFileContentsRequest: streamId: 0x%08" PRIX32
"",
929 fileContentsRequest->streamId);
930 return cliprdr_packet_send(cliprdr, s);
939cliprdr_client_file_contents_response(CliprdrClientContext* context,
945 WINPR_ASSERT(context);
946 WINPR_ASSERT(fileContentsResponse);
949 WINPR_ASSERT(cliprdr);
953 if ((mask & CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES) == 0)
954 return cliprdr_send_error_response(cliprdr, CB_FILECONTENTS_RESPONSE);
956 s = cliprdr_packet_file_contents_response_new(fileContentsResponse);
960 WLog_Print(cliprdr->log, WLOG_ERROR,
"cliprdr_packet_file_contents_response_new failed!");
961 return ERROR_INTERNAL_ERROR;
964 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFileContentsResponse: streamId: 0x%08" PRIX32
"",
965 fileContentsResponse->streamId);
966 return cliprdr_packet_send(cliprdr, s);
969static VOID VCAPITYPE cliprdr_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle,
970 UINT event, LPVOID pData,
971 UINT32 dataLength, UINT32 totalLength,
974 UINT error = CHANNEL_RC_OK;
976 WINPR_ASSERT(cliprdr);
980 case CHANNEL_EVENT_DATA_RECEIVED:
981 if (cliprdr->OpenHandle != openHandle)
983 WLog_Print(cliprdr->log, WLOG_ERROR,
"error no match");
986 if ((error = channel_client_post_message(cliprdr->MsgsHandle, pData, dataLength,
987 totalLength, dataFlags)))
988 WLog_Print(cliprdr->log, WLOG_ERROR,
"failed with error %" PRIu32
"", error);
992 case CHANNEL_EVENT_WRITE_CANCELLED:
993 case CHANNEL_EVENT_WRITE_COMPLETE:
996 Stream_Free(s, TRUE);
1000 case CHANNEL_EVENT_USER:
1006 if (error && cliprdr->context->rdpcontext)
1007 setChannelError(cliprdr->context->rdpcontext, error,
1008 "cliprdr_virtual_channel_open_event_ex reported an error");
1016static UINT cliprdr_virtual_channel_event_connected(
cliprdrPlugin* cliprdr,
1017 WINPR_ATTR_UNUSED LPVOID pData,
1018 WINPR_ATTR_UNUSED UINT32 dataLength)
1021 WINPR_ASSERT(cliprdr);
1022 WINPR_ASSERT(cliprdr->context);
1024 WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelOpenEx);
1025 status = cliprdr->channelEntryPoints.pVirtualChannelOpenEx(
1026 cliprdr->InitHandle, &cliprdr->OpenHandle, cliprdr->channelDef.name,
1027 cliprdr_virtual_channel_open_event_ex);
1028 if (status != CHANNEL_RC_OK)
1031 cliprdr->MsgsHandle = channel_client_create_handler(
1032 cliprdr->context->rdpcontext, cliprdr, cliprdr_order_recv, CLIPRDR_SVC_CHANNEL_NAME);
1033 if (!cliprdr->MsgsHandle)
1034 return ERROR_INTERNAL_ERROR;
1044static UINT cliprdr_virtual_channel_event_disconnected(
cliprdrPlugin* cliprdr)
1048 WINPR_ASSERT(cliprdr);
1050 channel_client_quit_handler(cliprdr->MsgsHandle);
1051 cliprdr->MsgsHandle =
nullptr;
1053 if (cliprdr->OpenHandle == 0)
1054 return CHANNEL_RC_OK;
1056 WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelCloseEx);
1057 rc = cliprdr->channelEntryPoints.pVirtualChannelCloseEx(cliprdr->InitHandle,
1058 cliprdr->OpenHandle);
1060 if (CHANNEL_RC_OK != rc)
1062 WLog_Print(cliprdr->log, WLOG_ERROR,
"pVirtualChannelClose failed with %s [%08" PRIX32
"]",
1063 WTSErrorToString(rc), rc);
1067 cliprdr->OpenHandle = 0;
1069 return CHANNEL_RC_OK;
1077static UINT cliprdr_virtual_channel_event_terminated(
cliprdrPlugin* cliprdr)
1079 WINPR_ASSERT(cliprdr);
1081 cliprdr->InitHandle =
nullptr;
1082 free(cliprdr->context);
1084 return CHANNEL_RC_OK;
1087static VOID VCAPITYPE cliprdr_virtual_channel_init_event_ex(LPVOID lpUserParam, LPVOID pInitHandle,
1088 UINT event, LPVOID pData,
1091 UINT error = CHANNEL_RC_OK;
1093 WINPR_ASSERT(cliprdr);
1095 if (cliprdr->InitHandle != pInitHandle)
1097 WLog_Print(cliprdr->log, WLOG_ERROR,
"error no match");
1103 case CHANNEL_EVENT_CONNECTED:
1104 if ((error = cliprdr_virtual_channel_event_connected(cliprdr, pData, dataLength)))
1105 WLog_Print(cliprdr->log, WLOG_ERROR,
1106 "cliprdr_virtual_channel_event_connected failed with error %" PRIu32
"!",
1111 case CHANNEL_EVENT_DISCONNECTED:
1112 if ((error = cliprdr_virtual_channel_event_disconnected(cliprdr)))
1113 WLog_Print(cliprdr->log, WLOG_ERROR,
1114 "cliprdr_virtual_channel_event_disconnected failed with error %" PRIu32
1120 case CHANNEL_EVENT_TERMINATED:
1121 if ((error = cliprdr_virtual_channel_event_terminated(cliprdr)))
1122 WLog_Print(cliprdr->log, WLOG_ERROR,
1123 "cliprdr_virtual_channel_event_terminated failed with error %" PRIu32
1131 if (error && cliprdr->context->rdpcontext)
1132 setChannelError(cliprdr->context->rdpcontext, error,
1133 "cliprdr_virtual_channel_init_event reported an error");
1137#define VirtualChannelEntryEx cliprdr_VirtualChannelEntryEx
1139FREERDP_ENTRY_POINT(BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS_EX pEntryPoints,
1146 wLog* log = WLog_Get(CHANNELS_TAG(
"cliprdr.client"));
1151 WLog_Print(log, WLOG_ERROR,
"calloc failed!");
1156 cliprdr->channelDef.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP |
1157 CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL;
1158 (void)sprintf_s(cliprdr->channelDef.name, ARRAYSIZE(cliprdr->channelDef.name),
1159 CLIPRDR_SVC_CHANNEL_NAME);
1161 WINPR_ASSERT(pEntryPointsEx);
1164 (pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))
1166 CliprdrClientContext* context =
1167 (CliprdrClientContext*)calloc(1,
sizeof(CliprdrClientContext));
1171 WLog_Print(cliprdr->log, WLOG_ERROR,
"calloc failed!");
1176 context->handle = (
void*)cliprdr;
1177 context->custom =
nullptr;
1178 context->ClientCapabilities = cliprdr_client_capabilities;
1179 context->TempDirectory = cliprdr_temp_directory;
1180 context->ClientFormatList = cliprdr_client_format_list;
1181 context->ClientFormatListResponse = cliprdr_client_format_list_response;
1182 context->ClientLockClipboardData = cliprdr_client_lock_clipboard_data;
1183 context->ClientUnlockClipboardData = cliprdr_client_unlock_clipboard_data;
1184 context->ClientFormatDataRequest = cliprdr_client_format_data_request;
1185 context->ClientFormatDataResponse = cliprdr_client_format_data_response;
1186 context->ClientFileContentsRequest = cliprdr_client_file_contents_request;
1187 context->ClientFileContentsResponse = cliprdr_client_file_contents_response;
1188 cliprdr->context = context;
1189 context->rdpcontext = pEntryPointsEx->context;
1192 WLog_Print(cliprdr->log, WLOG_DEBUG,
"VirtualChannelEntryEx");
1193 CopyMemory(&(cliprdr->channelEntryPoints), pEntryPoints,
1195 cliprdr->InitHandle = pInitHandle;
1196 rc = cliprdr->channelEntryPoints.pVirtualChannelInitEx(
1197 cliprdr, cliprdr->context, pInitHandle, &cliprdr->channelDef, 1,
1198 VIRTUAL_CHANNEL_VERSION_WIN2000, cliprdr_virtual_channel_init_event_ex);
1200 if (CHANNEL_RC_OK != rc)
1202 WLog_Print(cliprdr->log, WLOG_ERROR,
"pVirtualChannelInit failed with %s [%08" PRIX32
"]",
1203 WTSErrorToString(rc), rc);
1204 free(cliprdr->context);
1209 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.