From 7722961fccbb4e689e96e86360eb8b076e1d638c Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 1 Mar 2023 09:12:02 +0100 Subject: [PATCH] [client,common] simplify file clipboard API --- client/Wayland/wlf_cliprdr.c | 5 +- client/X11/xf_cliprdr.c | 6 +-- client/common/CMakeLists.txt | 2 +- client/common/client_cliprdr_file.c | 54 ++++++++++---------- include/freerdp/client/client_cliprdr_file.h | 22 ++++++-- 5 files changed, 50 insertions(+), 39 deletions(-) diff --git a/client/Wayland/wlf_cliprdr.c b/client/Wayland/wlf_cliprdr.c index 51b3407c7..b8e2d5caa 100644 --- a/client/Wayland/wlf_cliprdr.c +++ b/client/Wayland/wlf_cliprdr.c @@ -869,9 +869,8 @@ wlf_cliprdr_server_format_data_response(CliprdrClientContext* context, ClipboardGetFormatId(clipboard->system, type_FileGroupDescriptorW); dstFormatId = ClipboardGetFormatId(clipboard->system, request->responseMime); - if (!cliprdr_file_context_update_server_data(clipboard->file, data, size)) - goto unlock; - else if (!cliprdr_file_context_update_base(clipboard->file, clipboard->system)) + if (!cliprdr_file_context_update_server_data(clipboard->file, clipboard->system, + data, size)) goto unlock; } else if (strcmp(type_HtmlFormat, name) == 0) diff --git a/client/X11/xf_cliprdr.c b/client/X11/xf_cliprdr.c index f0fa41909..c4d9fff8c 100644 --- a/client/X11/xf_cliprdr.c +++ b/client/X11/xf_cliprdr.c @@ -1888,11 +1888,9 @@ xf_cliprdr_server_format_data_response(CliprdrClientContext* context, if (strcmp(clipboard->requestedFormat->formatName, type_FileGroupDescriptorW) == 0) { - if (!cliprdr_file_context_update_server_data(clipboard->file, data, size)) + if (!cliprdr_file_context_update_server_data(clipboard->file, clipboard->system, data, + size)) WLog_WARN(TAG, "failed to update file descriptors"); - else if (!cliprdr_file_context_update_base(clipboard->file, clipboard->system)) - { - } srcFormatId = ClipboardGetFormatId(clipboard->system, type_FileGroupDescriptorW); const xfCliprdrFormat* dstTargetFormat = diff --git a/client/common/CMakeLists.txt b/client/common/CMakeLists.txt index 97583961f..c5369f935 100644 --- a/client/common/CMakeLists.txt +++ b/client/common/CMakeLists.txt @@ -95,7 +95,7 @@ if (WITH_LIBRARY_VERSIONING) set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION}) endif() -set(LIBS freerdp winpr) +list(APPEND LIBS freerdp winpr) target_link_libraries(${MODULE_NAME} PRIVATE ${FREERDP_CHANNELS_CLIENT_LIBS}) target_link_libraries(${MODULE_NAME} PUBLIC ${LIBS}) diff --git a/client/common/client_cliprdr_file.c b/client/common/client_cliprdr_file.c index f363e067e..a4e030175 100644 --- a/client/common/client_cliprdr_file.c +++ b/client/common/client_cliprdr_file.c @@ -1781,21 +1781,37 @@ static BOOL cliprdr_file_client_content_changed_and_update(CliprdrFileContext* f sizeof(file->client_data_hash), data, size); } -BOOL cliprdr_file_context_update_server_data(CliprdrFileContext* file, const void* data, - size_t size) +static BOOL cliprdr_file_context_update_base(CliprdrFileContext* file, wClipboard* clip) +{ + wClipboardDelegate* delegate = ClipboardGetDelegate(clip); + if (!delegate) + return FALSE; + ClipboardLock(clip); + HashTable_Lock(file->remote_streams); + free(file->exposed_path); + file->exposed_path = _strdup(file->current_path); + HashTable_Unlock(file->remote_streams); + + delegate->basePath = (file->exposed_path); + ClipboardUnlock(clip); + return delegate->basePath != NULL; +} + +BOOL cliprdr_file_context_update_server_data(CliprdrFileContext* file, wClipboard* clip, + const void* data, size_t size) { WINPR_ASSERT(file); - if (cliprdr_file_server_content_changed_and_update(file, data, size)) - { -#if defined(WITH_FUSE2) || defined(WITH_FUSE3) - /* Build inode table for FILEDESCRIPTORW*/ - if (!cliprdr_file_fuse_generate_list(file, data, size, 0)) - return FALSE; -#endif - } + if (!cliprdr_file_server_content_changed_and_update(file, data, size)) + return TRUE; - return TRUE; +#if defined(WITH_FUSE2) || defined(WITH_FUSE3) + /* Build inode table for FILEDESCRIPTORW*/ + if (!cliprdr_file_fuse_generate_list(file, data, size, 0)) + return FALSE; +#endif + + return cliprdr_file_context_update_base(file, clip); } void* cliprdr_file_context_get_context(CliprdrFileContext* file) @@ -2290,22 +2306,6 @@ UINT32 cliprdr_file_context_remote_get_flags(CliprdrFileContext* file) return file->file_capability_flags; } -BOOL cliprdr_file_context_update_base(CliprdrFileContext* file, wClipboard* clip) -{ - wClipboardDelegate* delegate = ClipboardGetDelegate(clip); - if (!delegate) - return FALSE; - ClipboardLock(clip); - HashTable_Lock(file->remote_streams); - free(file->exposed_path); - file->exposed_path = _strdup(file->current_path); - HashTable_Unlock(file->remote_streams); - - delegate->basePath = (file->exposed_path); - ClipboardUnlock(clip); - return delegate->basePath != NULL; -} - BOOL cliprdr_file_context_has_local_support(CliprdrFileContext* file) { WINPR_UNUSED(file); diff --git a/include/freerdp/client/client_cliprdr_file.h b/include/freerdp/client/client_cliprdr_file.h index 40d137f34..bab9edcdf 100644 --- a/include/freerdp/client/client_cliprdr_file.h +++ b/include/freerdp/client/client_cliprdr_file.h @@ -58,8 +58,6 @@ extern "C" FREERDP_API void* cliprdr_file_context_get_context(CliprdrFileContext* file); - FREERDP_API BOOL cliprdr_file_context_update_base(CliprdrFileContext* file, wClipboard* clip); - FREERDP_API BOOL cliprdr_file_context_init(CliprdrFileContext* file, CliprdrClientContext* cliprdr); FREERDP_API BOOL cliprdr_file_context_uninit(CliprdrFileContext* file, @@ -67,11 +65,27 @@ extern "C" FREERDP_API BOOL cliprdr_file_context_clear(CliprdrFileContext* file); + /** \brief updates the files the client announces to the server + * + * \param file the file context to update + * \param data the file list + * \param count the length of the file list + * + * \return \b TRUE for success, \b FALSE otherwise + */ FREERDP_API BOOL cliprdr_file_context_update_client_data(CliprdrFileContext* file, const char* data, size_t count); - + /** \brief updates the files the server announces to the client + * + * \param file the file context to update + * \param data the file list [MS-RDPECLIP] 2.2.5.2.3 Packed File List (CLIPRDR_FILELIST) + * \param count the length of the file list + * + * \return \b TRUE for success, \b FALSE otherwise + */ FREERDP_API BOOL cliprdr_file_context_update_server_data(CliprdrFileContext* file, - const void* data, size_t size); + wClipboard* clip, const void* data, + size_t size); #ifdef __cplusplus }