23 #include <freerdp/config.h>
25 #include <winpr/wtypes.h>
26 #include <winpr/assert.h>
27 #include <winpr/crt.h>
28 #include <winpr/print.h>
30 #include <freerdp/types.h>
31 #include <freerdp/constants.h>
32 #include <freerdp/freerdp.h>
33 #include <freerdp/client/cliprdr.h>
35 #include "../../../channels/client/addin.h"
37 #include "cliprdr_main.h"
38 #include "cliprdr_format.h"
39 #include "../cliprdr_common.h"
41 const char type_FileGroupDescriptorW[] =
"FileGroupDescriptorW";
42 const char type_FileContents[] =
"FileContents";
44 CliprdrClientContext* cliprdr_get_client_interface(
cliprdrPlugin* cliprdr)
46 CliprdrClientContext* pInterface = NULL;
51 pInterface = (CliprdrClientContext*)cliprdr->channelEntryPoints.pInterface;
62 UINT status = CHANNEL_RC_OK;
64 WINPR_ASSERT(cliprdr);
67 const size_t pos = Stream_GetPosition(s);
68 const size_t dataLen = pos - 8;
69 WINPR_ASSERT(dataLen <= UINT32_MAX);
71 Stream_SetPosition(s, 4);
72 Stream_Write_UINT32(s, (UINT32)dataLen);
73 Stream_SetPosition(s, pos);
75 WLog_DBG(TAG,
"Cliprdr Sending (%" PRIu32
" bytes)", dataLen + 8);
79 status = CHANNEL_RC_BAD_INIT_HANDLE;
83 WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelWriteEx);
84 status = cliprdr->channelEntryPoints.pVirtualChannelWriteEx(
85 cliprdr->InitHandle, cliprdr->OpenHandle, Stream_Buffer(s),
86 (UINT32)Stream_GetPosition(s), s);
89 if (status != CHANNEL_RC_OK)
92 WLog_ERR(TAG,
"VirtualChannelWrite failed with %s [%08" PRIX32
"]",
93 WTSErrorToString(status), status);
99 UINT cliprdr_send_error_response(
cliprdrPlugin* cliprdr, UINT16 type)
101 wStream* s = cliprdr_packet_new(type, CB_RESPONSE_FAIL, 0);
104 WLog_ERR(TAG,
"cliprdr_packet_new failed!");
105 return ERROR_OUTOFMEMORY;
108 return cliprdr_packet_send(cliprdr, s);
111 static void cliprdr_print_general_capability_flags(UINT32 flags)
113 WLog_DBG(TAG,
"generalFlags (0x%08" PRIX32
") {", flags);
115 if (flags & CB_USE_LONG_FORMAT_NAMES)
116 WLog_DBG(TAG,
"\tCB_USE_LONG_FORMAT_NAMES");
118 if (flags & CB_STREAM_FILECLIP_ENABLED)
119 WLog_DBG(TAG,
"\tCB_STREAM_FILECLIP_ENABLED");
121 if (flags & CB_FILECLIP_NO_FILE_PATHS)
122 WLog_DBG(TAG,
"\tCB_FILECLIP_NO_FILE_PATHS");
124 if (flags & CB_CAN_LOCK_CLIPDATA)
125 WLog_DBG(TAG,
"\tCB_CAN_LOCK_CLIPDATA");
127 if (flags & CB_HUGE_FILE_SUPPORT_ENABLED)
128 WLog_DBG(TAG,
"\tCB_HUGE_FILE_SUPPORT_ENABLED");
141 UINT32 generalFlags = 0;
144 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
145 UINT error = CHANNEL_RC_OK;
147 WINPR_ASSERT(cliprdr);
152 WLog_ERR(TAG,
"cliprdr_get_client_interface failed!");
153 return ERROR_INTERNAL_ERROR;
156 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
157 return ERROR_INVALID_DATA;
159 Stream_Read_UINT32(s, version);
160 Stream_Read_UINT32(s, generalFlags);
161 WLog_DBG(TAG,
"Version: %" PRIu32
"", version);
163 cliprdr_print_general_capability_flags(generalFlags);
165 cliprdr->useLongFormatNames = (generalFlags & CB_USE_LONG_FORMAT_NAMES) ? TRUE : FALSE;
166 cliprdr->streamFileClipEnabled = (generalFlags & CB_STREAM_FILECLIP_ENABLED) ? TRUE : FALSE;
167 cliprdr->fileClipNoFilePaths = (generalFlags & CB_FILECLIP_NO_FILE_PATHS) ? TRUE : FALSE;
168 cliprdr->canLockClipData = (generalFlags & CB_CAN_LOCK_CLIPDATA) ? TRUE : FALSE;
169 cliprdr->hasHugeFileSupport = (generalFlags & CB_HUGE_FILE_SUPPORT_ENABLED) ? TRUE : FALSE;
170 cliprdr->capabilitiesReceived = TRUE;
172 capabilities.common.msgType = CB_CLIP_CAPS;
173 capabilities.cCapabilitiesSets = 1;
175 generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
176 generalCapabilitySet.capabilitySetLength = 12;
177 generalCapabilitySet.version = version;
178 generalCapabilitySet.generalFlags = generalFlags;
179 IFCALLRET(context->ServerCapabilities, error, context, &capabilities);
182 WLog_ERR(TAG,
"ServerCapabilities failed with error %" PRIu32
"!", error);
195 UINT16 lengthCapability = 0;
196 UINT16 cCapabilitiesSets = 0;
197 UINT16 capabilitySetType = 0;
198 UINT error = CHANNEL_RC_OK;
200 WINPR_ASSERT(cliprdr);
203 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
204 return ERROR_INVALID_DATA;
206 Stream_Read_UINT16(s, cCapabilitiesSets);
207 Stream_Seek_UINT16(s);
208 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ServerCapabilities");
210 for (UINT16 index = 0; index < cCapabilitiesSets; index++)
212 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
213 return ERROR_INVALID_DATA;
215 Stream_Read_UINT16(s, capabilitySetType);
216 Stream_Read_UINT16(s, lengthCapability);
218 if ((lengthCapability < 4) ||
219 (!Stream_CheckAndLogRequiredLength(TAG, s, lengthCapability - 4U)))
220 return ERROR_INVALID_DATA;
222 switch (capabilitySetType)
224 case CB_CAPSTYPE_GENERAL:
225 if ((error = cliprdr_process_general_capability(cliprdr, s)))
228 "cliprdr_process_general_capability failed with error %" PRIu32
"!",
236 WLog_ERR(TAG,
"unknown cliprdr capability set: %" PRIu16
"", capabilitySetType);
237 return CHANNEL_RC_BAD_PROC;
253 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
254 UINT error = CHANNEL_RC_OK;
256 WINPR_ASSERT(cliprdr);
259 WLog_Print(cliprdr->log, WLOG_DEBUG,
"MonitorReady");
261 if (!cliprdr->capabilitiesReceived)
269 cliprdr->useLongFormatNames = FALSE;
270 cliprdr->streamFileClipEnabled = FALSE;
271 cliprdr->fileClipNoFilePaths = TRUE;
272 cliprdr->canLockClipData = FALSE;
275 monitorReady.common.msgType = CB_MONITOR_READY;
276 monitorReady.common.msgFlags = flags;
277 monitorReady.common.dataLen = length;
278 IFCALLRET(context->MonitorReady, error, context, &monitorReady);
281 WLog_ERR(TAG,
"MonitorReady failed with error %" PRIu32
"!", error);
291 static UINT cliprdr_process_filecontents_request(
cliprdrPlugin* cliprdr,
wStream* s, UINT32 length,
295 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
296 UINT error = CHANNEL_RC_OK;
298 WINPR_ASSERT(cliprdr);
301 WLog_Print(cliprdr->log, WLOG_DEBUG,
"FileContentsRequest");
303 request.common.msgType = CB_FILECONTENTS_REQUEST;
304 request.common.msgFlags = flags;
305 request.common.dataLen = length;
307 if ((error = cliprdr_read_file_contents_request(s, &request)))
312 if ((mask & (CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES)) == 0)
314 WLog_WARN(TAG,
"local -> remote file copy disabled, ignoring request");
315 return cliprdr_send_error_response(cliprdr, CB_FILECONTENTS_RESPONSE);
317 IFCALLRET(context->ServerFileContentsRequest, error, context, &request);
320 WLog_ERR(TAG,
"ServerFileContentsRequest failed with error %" PRIu32
"!", error);
330 static UINT cliprdr_process_filecontents_response(
cliprdrPlugin* cliprdr,
wStream* s, UINT32 length,
334 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
335 UINT error = CHANNEL_RC_OK;
337 WINPR_ASSERT(cliprdr);
340 WLog_Print(cliprdr->log, WLOG_DEBUG,
"FileContentsResponse");
342 response.common.msgType = CB_FILECONTENTS_RESPONSE;
343 response.common.msgFlags = flags;
344 response.common.dataLen = length;
346 if ((error = cliprdr_read_file_contents_response(s, &response)))
349 IFCALLRET(context->ServerFileContentsResponse, error, context, &response);
352 WLog_ERR(TAG,
"ServerFileContentsResponse failed with error %" PRIu32
"!", error);
366 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
367 UINT error = CHANNEL_RC_OK;
369 WINPR_ASSERT(cliprdr);
372 WLog_Print(cliprdr->log, WLOG_DEBUG,
"LockClipData");
374 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
375 return ERROR_INVALID_DATA;
377 lockClipboardData.common.msgType = CB_LOCK_CLIPDATA;
378 lockClipboardData.common.msgFlags = flags;
379 lockClipboardData.common.dataLen = length;
380 Stream_Read_UINT32(s, lockClipboardData.clipDataId);
381 IFCALLRET(context->ServerLockClipboardData, error, context, &lockClipboardData);
384 WLog_ERR(TAG,
"ServerLockClipboardData failed with error %" PRIu32
"!", error);
398 CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
399 UINT error = CHANNEL_RC_OK;
401 WINPR_ASSERT(cliprdr);
404 WLog_Print(cliprdr->log, WLOG_DEBUG,
"UnlockClipData");
406 if ((error = cliprdr_read_unlock_clipdata(s, &unlockClipboardData)))
409 unlockClipboardData.common.msgType = CB_UNLOCK_CLIPDATA;
410 unlockClipboardData.common.msgFlags = flags;
411 unlockClipboardData.common.dataLen = length;
413 IFCALLRET(context->ServerUnlockClipboardData, error, context, &unlockClipboardData);
416 WLog_ERR(TAG,
"ServerUnlockClipboardData failed with error %" PRIu32
"!", error);
426 static UINT cliprdr_order_recv(LPVOID userdata,
wStream* s)
434 WINPR_ASSERT(cliprdr);
437 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
438 return ERROR_INVALID_DATA;
440 Stream_Read_UINT16(s, msgType);
441 Stream_Read_UINT16(s, msgFlags);
442 Stream_Read_UINT32(s, dataLen);
444 if (!Stream_CheckAndLogRequiredLength(TAG, s, dataLen))
445 return ERROR_INVALID_DATA;
447 char buffer1[64] = { 0 };
448 char buffer2[64] = { 0 };
449 WLog_DBG(TAG,
"msgType: %s (%" PRIu16
"), msgFlags: %s dataLen: %" PRIu32
"",
450 CB_MSG_TYPE_STRING(msgType, buffer1,
sizeof(buffer1)), msgType,
451 CB_MSG_FLAGS_STRING(msgFlags, buffer2,
sizeof(buffer2)), dataLen);
456 if ((error = cliprdr_process_clip_caps(cliprdr, s, dataLen, msgFlags)))
457 WLog_ERR(TAG,
"cliprdr_process_clip_caps failed with error %" PRIu32
"!", error);
461 case CB_MONITOR_READY:
462 if ((error = cliprdr_process_monitor_ready(cliprdr, s, dataLen, msgFlags)))
463 WLog_ERR(TAG,
"cliprdr_process_monitor_ready failed with error %" PRIu32
"!",
469 if ((error = cliprdr_process_format_list(cliprdr, s, dataLen, msgFlags)))
470 WLog_ERR(TAG,
"cliprdr_process_format_list failed with error %" PRIu32
"!", error);
474 case CB_FORMAT_LIST_RESPONSE:
475 if ((error = cliprdr_process_format_list_response(cliprdr, s, dataLen, msgFlags)))
476 WLog_ERR(TAG,
"cliprdr_process_format_list_response failed with error %" PRIu32
"!",
481 case CB_FORMAT_DATA_REQUEST:
482 if ((error = cliprdr_process_format_data_request(cliprdr, s, dataLen, msgFlags)))
483 WLog_ERR(TAG,
"cliprdr_process_format_data_request failed with error %" PRIu32
"!",
488 case CB_FORMAT_DATA_RESPONSE:
489 if ((error = cliprdr_process_format_data_response(cliprdr, s, dataLen, msgFlags)))
490 WLog_ERR(TAG,
"cliprdr_process_format_data_response failed with error %" PRIu32
"!",
495 case CB_FILECONTENTS_REQUEST:
496 if ((error = cliprdr_process_filecontents_request(cliprdr, s, dataLen, msgFlags)))
497 WLog_ERR(TAG,
"cliprdr_process_filecontents_request failed with error %" PRIu32
"!",
502 case CB_FILECONTENTS_RESPONSE:
503 if ((error = cliprdr_process_filecontents_response(cliprdr, s, dataLen, msgFlags)))
505 "cliprdr_process_filecontents_response failed with error %" PRIu32
"!",
510 case CB_LOCK_CLIPDATA:
511 if ((error = cliprdr_process_lock_clipdata(cliprdr, s, dataLen, msgFlags)))
512 WLog_ERR(TAG,
"cliprdr_process_lock_clipdata failed with error %" PRIu32
"!",
517 case CB_UNLOCK_CLIPDATA:
518 if ((error = cliprdr_process_unlock_clipdata(cliprdr, s, dataLen, msgFlags)))
519 WLog_ERR(TAG,
"cliprdr_process_unlock_clipdata failed with error %" PRIu32
"!",
525 error = CHANNEL_RC_BAD_PROC;
526 WLog_ERR(TAG,
"unknown msgType %" PRIu16
"", msgType);
530 Stream_Free(s, TRUE);
543 static UINT cliprdr_client_capabilities(CliprdrClientContext* context,
551 WINPR_ASSERT(context);
554 WINPR_ASSERT(cliprdr);
556 s = cliprdr_packet_new(CB_CLIP_CAPS, 0, 4 + CB_CAPSTYPE_GENERAL_LEN);
560 WLog_ERR(TAG,
"cliprdr_packet_new failed!");
561 return ERROR_INTERNAL_ERROR;
564 Stream_Write_UINT16(s, 1);
565 Stream_Write_UINT16(s, 0);
567 Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetType);
568 Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetLength);
569 Stream_Write_UINT32(s, generalCapabilitySet->version);
570 flags = generalCapabilitySet->generalFlags;
576 if (!cliprdr->useLongFormatNames)
577 flags &= ~CB_USE_LONG_FORMAT_NAMES;
578 if (!cliprdr->streamFileClipEnabled)
579 flags &= ~CB_STREAM_FILECLIP_ENABLED;
580 if (!cliprdr->fileClipNoFilePaths)
581 flags &= ~CB_FILECLIP_NO_FILE_PATHS;
582 if (!cliprdr->canLockClipData)
583 flags &= ~CB_CAN_LOCK_CLIPDATA;
584 if (!cliprdr->hasHugeFileSupport)
585 flags &= ~CB_HUGE_FILE_SUPPORT_ENABLED;
587 cliprdr->useLongFormatNames = (flags & CB_USE_LONG_FORMAT_NAMES) ? TRUE : FALSE;
588 cliprdr->streamFileClipEnabled = (flags & CB_STREAM_FILECLIP_ENABLED) ? TRUE : FALSE;
589 cliprdr->fileClipNoFilePaths = (flags & CB_FILECLIP_NO_FILE_PATHS) ? TRUE : FALSE;
590 cliprdr->canLockClipData = (flags & CB_CAN_LOCK_CLIPDATA) ? TRUE : FALSE;
591 cliprdr->hasHugeFileSupport = (flags & CB_HUGE_FILE_SUPPORT_ENABLED) ? TRUE : FALSE;
593 Stream_Write_UINT32(s, flags);
594 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientCapabilities");
596 cliprdr->initialFormatListSent = FALSE;
598 return cliprdr_packet_send(cliprdr, s);
606 static UINT cliprdr_temp_directory(CliprdrClientContext* context,
612 WINPR_ASSERT(context);
613 WINPR_ASSERT(tempDirectory);
616 WINPR_ASSERT(cliprdr);
618 const size_t tmpDirCharLen =
sizeof(tempDirectory->szTempDir) /
sizeof(WCHAR);
619 s = cliprdr_packet_new(CB_TEMP_DIRECTORY, 0, tmpDirCharLen *
sizeof(WCHAR));
623 WLog_ERR(TAG,
"cliprdr_packet_new failed!");
624 return ERROR_INTERNAL_ERROR;
627 if (Stream_Write_UTF16_String_From_UTF8(s, tmpDirCharLen - 1, tempDirectory->szTempDir,
628 ARRAYSIZE(tempDirectory->szTempDir), TRUE) < 0)
630 Stream_Free(s, TRUE);
631 return ERROR_INTERNAL_ERROR;
635 Stream_Write_UINT16(s, 0);
637 WLog_Print(cliprdr->log, WLOG_DEBUG,
"TempDirectory: %s", tempDirectory->szTempDir);
638 return cliprdr_packet_send(cliprdr, s);
646 static UINT cliprdr_client_format_list(CliprdrClientContext* context,
652 WINPR_ASSERT(context);
653 WINPR_ASSERT(formatList);
656 WINPR_ASSERT(cliprdr);
659 const UINT32 mask = CB_RESPONSE_OK | CB_RESPONSE_FAIL;
660 if ((formatList->common.msgFlags & mask) != 0)
662 "Sending clipboard request with invalid flags msgFlags = 0x%08" PRIx32
663 ". Correct in your client!",
664 formatList->common.msgFlags & mask);
670 formatList, mask, CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES);
673 if ((filterList.numFormats == 0) && cliprdr->initialFormatListSent)
675 cliprdr_free_format_list(&filterList);
676 return CHANNEL_RC_OK;
678 cliprdr->initialFormatListSent = TRUE;
680 s = cliprdr_packet_format_list_new(&filterList, cliprdr->useLongFormatNames, FALSE);
681 cliprdr_free_format_list(&filterList);
685 WLog_ERR(TAG,
"cliprdr_packet_format_list_new failed!");
686 return ERROR_INTERNAL_ERROR;
689 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFormatList: numFormats: %" PRIu32
"",
690 formatList->numFormats);
691 return cliprdr_packet_send(cliprdr, s);
700 cliprdr_client_format_list_response(CliprdrClientContext* context,
706 WINPR_ASSERT(context);
707 WINPR_ASSERT(formatListResponse);
710 WINPR_ASSERT(cliprdr);
712 s = cliprdr_packet_new(CB_FORMAT_LIST_RESPONSE, formatListResponse->common.msgFlags, 0);
716 WLog_ERR(TAG,
"cliprdr_packet_new failed!");
717 return ERROR_INTERNAL_ERROR;
720 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFormatListResponse");
721 return cliprdr_packet_send(cliprdr, s);
729 static UINT cliprdr_client_lock_clipboard_data(CliprdrClientContext* context,
735 WINPR_ASSERT(context);
736 WINPR_ASSERT(lockClipboardData);
739 WINPR_ASSERT(cliprdr);
741 s = cliprdr_packet_lock_clipdata_new(lockClipboardData);
745 WLog_ERR(TAG,
"cliprdr_packet_lock_clipdata_new failed!");
746 return ERROR_INTERNAL_ERROR;
749 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientLockClipboardData: clipDataId: 0x%08" PRIX32
"",
750 lockClipboardData->clipDataId);
751 return cliprdr_packet_send(cliprdr, s);
760 cliprdr_client_unlock_clipboard_data(CliprdrClientContext* context,
766 WINPR_ASSERT(context);
767 WINPR_ASSERT(unlockClipboardData);
770 WINPR_ASSERT(cliprdr);
772 s = cliprdr_packet_unlock_clipdata_new(unlockClipboardData);
776 WLog_ERR(TAG,
"cliprdr_packet_unlock_clipdata_new failed!");
777 return ERROR_INTERNAL_ERROR;
780 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientUnlockClipboardData: clipDataId: 0x%08" PRIX32
"",
781 unlockClipboardData->clipDataId);
782 return cliprdr_packet_send(cliprdr, s);
790 static UINT cliprdr_client_format_data_request(CliprdrClientContext* context,
793 WINPR_ASSERT(context);
794 WINPR_ASSERT(formatDataRequest);
797 WINPR_ASSERT(cliprdr);
801 if ((mask & (CLIPRDR_FLAG_REMOTE_TO_LOCAL | CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES)) == 0)
803 WLog_WARN(TAG,
"remote -> local copy disabled, ignoring request");
804 return CHANNEL_RC_OK;
807 wStream* s = cliprdr_packet_new(CB_FORMAT_DATA_REQUEST, 0, 4);
810 WLog_ERR(TAG,
"cliprdr_packet_new failed!");
811 return ERROR_INTERNAL_ERROR;
814 Stream_Write_UINT32(s, formatDataRequest->requestedFormatId);
815 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFormatDataRequest(0x%08" PRIx32
")",
816 formatDataRequest->requestedFormatId);
817 return cliprdr_packet_send(cliprdr, s);
826 cliprdr_client_format_data_response(CliprdrClientContext* context,
829 WINPR_ASSERT(context);
830 WINPR_ASSERT(formatDataResponse);
833 WINPR_ASSERT(cliprdr);
837 (CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES)) != 0);
839 wStream* s = cliprdr_packet_new(CB_FORMAT_DATA_RESPONSE, formatDataResponse->common.msgFlags,
840 formatDataResponse->common.dataLen);
844 WLog_ERR(TAG,
"cliprdr_packet_new failed!");
845 return ERROR_INTERNAL_ERROR;
848 Stream_Write(s, formatDataResponse->requestedFormatData, formatDataResponse->common.dataLen);
849 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFormatDataResponse");
850 return cliprdr_packet_send(cliprdr, s);
859 cliprdr_client_file_contents_request(CliprdrClientContext* context,
865 WINPR_ASSERT(context);
866 WINPR_ASSERT(fileContentsRequest);
870 if ((mask & CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES) == 0)
872 WLog_WARN(TAG,
"remote -> local file copy disabled, ignoring request");
873 return CHANNEL_RC_OK;
878 return ERROR_INTERNAL_ERROR;
880 if (!cliprdr->hasHugeFileSupport)
882 if (((UINT64)fileContentsRequest->cbRequested + fileContentsRequest->nPositionLow) >
884 return ERROR_INVALID_PARAMETER;
885 if (fileContentsRequest->nPositionHigh != 0)
886 return ERROR_INVALID_PARAMETER;
889 s = cliprdr_packet_file_contents_request_new(fileContentsRequest);
893 WLog_ERR(TAG,
"cliprdr_packet_file_contents_request_new failed!");
894 return ERROR_INTERNAL_ERROR;
897 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFileContentsRequest: streamId: 0x%08" PRIX32
"",
898 fileContentsRequest->streamId);
899 return cliprdr_packet_send(cliprdr, s);
908 cliprdr_client_file_contents_response(CliprdrClientContext* context,
914 WINPR_ASSERT(context);
915 WINPR_ASSERT(fileContentsResponse);
918 WINPR_ASSERT(cliprdr);
922 if ((mask & CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES) == 0)
923 return cliprdr_send_error_response(cliprdr, CB_FILECONTENTS_RESPONSE);
925 s = cliprdr_packet_file_contents_response_new(fileContentsResponse);
929 WLog_ERR(TAG,
"cliprdr_packet_file_contents_response_new failed!");
930 return ERROR_INTERNAL_ERROR;
933 WLog_Print(cliprdr->log, WLOG_DEBUG,
"ClientFileContentsResponse: streamId: 0x%08" PRIX32
"",
934 fileContentsResponse->streamId);
935 return cliprdr_packet_send(cliprdr, s);
938 static VOID VCAPITYPE cliprdr_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle,
939 UINT event, LPVOID pData,
940 UINT32 dataLength, UINT32 totalLength,
943 UINT error = CHANNEL_RC_OK;
948 case CHANNEL_EVENT_DATA_RECEIVED:
949 if (!cliprdr || (cliprdr->OpenHandle != openHandle))
951 WLog_ERR(TAG,
"error no match");
954 if ((error = channel_client_post_message(cliprdr->MsgsHandle, pData, dataLength,
955 totalLength, dataFlags)))
956 WLog_ERR(TAG,
"failed with error %" PRIu32
"", error);
960 case CHANNEL_EVENT_WRITE_CANCELLED:
961 case CHANNEL_EVENT_WRITE_COMPLETE:
964 Stream_Free(s, TRUE);
968 case CHANNEL_EVENT_USER:
974 if (error && cliprdr && cliprdr->context->rdpcontext)
975 setChannelError(cliprdr->context->rdpcontext, error,
976 "cliprdr_virtual_channel_open_event_ex reported an error");
984 static UINT cliprdr_virtual_channel_event_connected(
cliprdrPlugin* cliprdr, LPVOID pData,
988 WINPR_ASSERT(cliprdr);
989 WINPR_ASSERT(cliprdr->context);
991 WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelOpenEx);
992 status = cliprdr->channelEntryPoints.pVirtualChannelOpenEx(
993 cliprdr->InitHandle, &cliprdr->OpenHandle, cliprdr->channelDef.name,
994 cliprdr_virtual_channel_open_event_ex);
995 if (status != CHANNEL_RC_OK)
998 cliprdr->MsgsHandle = channel_client_create_handler(
999 cliprdr->context->rdpcontext, cliprdr, cliprdr_order_recv, CLIPRDR_SVC_CHANNEL_NAME);
1000 if (!cliprdr->MsgsHandle)
1001 return ERROR_INTERNAL_ERROR;
1011 static UINT cliprdr_virtual_channel_event_disconnected(
cliprdrPlugin* cliprdr)
1015 WINPR_ASSERT(cliprdr);
1017 channel_client_quit_handler(cliprdr->MsgsHandle);
1018 cliprdr->MsgsHandle = NULL;
1020 if (cliprdr->OpenHandle == 0)
1021 return CHANNEL_RC_OK;
1023 WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelCloseEx);
1024 rc = cliprdr->channelEntryPoints.pVirtualChannelCloseEx(cliprdr->InitHandle,
1025 cliprdr->OpenHandle);
1027 if (CHANNEL_RC_OK != rc)
1029 WLog_ERR(TAG,
"pVirtualChannelClose failed with %s [%08" PRIX32
"]", WTSErrorToString(rc),
1034 cliprdr->OpenHandle = 0;
1036 return CHANNEL_RC_OK;
1044 static UINT cliprdr_virtual_channel_event_terminated(
cliprdrPlugin* cliprdr)
1046 WINPR_ASSERT(cliprdr);
1048 cliprdr->InitHandle = 0;
1049 free(cliprdr->context);
1051 return CHANNEL_RC_OK;
1054 static VOID VCAPITYPE cliprdr_virtual_channel_init_event_ex(LPVOID lpUserParam, LPVOID pInitHandle,
1055 UINT event, LPVOID pData,
1058 UINT error = CHANNEL_RC_OK;
1061 if (!cliprdr || (cliprdr->InitHandle != pInitHandle))
1063 WLog_ERR(TAG,
"error no match");
1069 case CHANNEL_EVENT_CONNECTED:
1070 if ((error = cliprdr_virtual_channel_event_connected(cliprdr, pData, dataLength)))
1072 "cliprdr_virtual_channel_event_connected failed with error %" PRIu32
"!",
1077 case CHANNEL_EVENT_DISCONNECTED:
1078 if ((error = cliprdr_virtual_channel_event_disconnected(cliprdr)))
1080 "cliprdr_virtual_channel_event_disconnected failed with error %" PRIu32
1086 case CHANNEL_EVENT_TERMINATED:
1087 if ((error = cliprdr_virtual_channel_event_terminated(cliprdr)))
1089 "cliprdr_virtual_channel_event_terminated failed with error %" PRIu32
"!",
1096 if (error && cliprdr->context->rdpcontext)
1097 setChannelError(cliprdr->context->rdpcontext, error,
1098 "cliprdr_virtual_channel_init_event reported an error");
1102 #define VirtualChannelEntryEx cliprdr_VirtualChannelEntryEx
1104 FREERDP_ENTRY_POINT(BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS pEntryPoints,
1109 CliprdrClientContext* context = NULL;
1115 WLog_ERR(TAG,
"calloc failed!");
1119 cliprdr->channelDef.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP |
1120 CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL;
1121 (void)sprintf_s(cliprdr->channelDef.name, ARRAYSIZE(cliprdr->channelDef.name),
1122 CLIPRDR_SVC_CHANNEL_NAME);
1124 WINPR_ASSERT(pEntryPointsEx);
1127 (pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))
1129 context = (CliprdrClientContext*)calloc(1,
sizeof(CliprdrClientContext));
1134 WLog_ERR(TAG,
"calloc failed!");
1138 context->handle = (
void*)cliprdr;
1139 context->custom = NULL;
1140 context->ClientCapabilities = cliprdr_client_capabilities;
1141 context->TempDirectory = cliprdr_temp_directory;
1142 context->ClientFormatList = cliprdr_client_format_list;
1143 context->ClientFormatListResponse = cliprdr_client_format_list_response;
1144 context->ClientLockClipboardData = cliprdr_client_lock_clipboard_data;
1145 context->ClientUnlockClipboardData = cliprdr_client_unlock_clipboard_data;
1146 context->ClientFormatDataRequest = cliprdr_client_format_data_request;
1147 context->ClientFormatDataResponse = cliprdr_client_format_data_response;
1148 context->ClientFileContentsRequest = cliprdr_client_file_contents_request;
1149 context->ClientFileContentsResponse = cliprdr_client_file_contents_response;
1150 cliprdr->context = context;
1151 context->rdpcontext = pEntryPointsEx->context;
1154 cliprdr->log = WLog_Get(CHANNELS_TAG(
"channels.cliprdr.client"));
1155 WLog_Print(cliprdr->log, WLOG_DEBUG,
"VirtualChannelEntryEx");
1156 CopyMemory(&(cliprdr->channelEntryPoints), pEntryPoints,
1158 cliprdr->InitHandle = pInitHandle;
1159 rc = cliprdr->channelEntryPoints.pVirtualChannelInitEx(
1160 cliprdr, context, pInitHandle, &cliprdr->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
1161 cliprdr_virtual_channel_init_event_ex);
1163 if (CHANNEL_RC_OK != rc)
1165 WLog_ERR(TAG,
"pVirtualChannelInit failed with %s [%08" PRIX32
"]", WTSErrorToString(rc),
1167 free(cliprdr->context);
1172 cliprdr->channelEntryPoints.pInterface = context;
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.