From: Oliver Kurth Date: Wed, 27 Feb 2019 22:39:54 +0000 (-0800) Subject: Common source file changes not applicable to open-vm-tools. X-Git-Tag: stable-11.0.0~185 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=577bc573f875ad5fe0e932cc58f2d607c422ea92;p=thirdparty%2Fopen-vm-tools.git Common source file changes not applicable to open-vm-tools. --- diff --git a/open-vm-tools/services/plugins/dndcp/dnd/dnd.h b/open-vm-tools/services/plugins/dndcp/dnd/dnd.h index c64869d54..9701f45f6 100644 --- a/open-vm-tools/services/plugins/dndcp/dnd/dnd.h +++ b/open-vm-tools/services/plugins/dndcp/dnd/dnd.h @@ -292,6 +292,10 @@ Bool DnD_CPNameListToDynBufArray(char *fileList, DynBufArray *dynBufArray); char *DnD_GetLastDirName(const char *str); +void DnD_SetCPClipboardAndTruncateText(CPClipboard *clip, + char *destBuf, + size_t len); + /* vmblock support functions. */ Bool DnD_InitializeBlocking(DnDBlockControl *blkCtrl); Bool DnD_UninitializeBlocking(DnDBlockControl *blkCtrl); diff --git a/open-vm-tools/services/plugins/dndcp/dnd/dndCommon.c b/open-vm-tools/services/plugins/dndcp/dnd/dndCommon.c index e8b4e8088..fc369513e 100644 --- a/open-vm-tools/services/plugins/dndcp/dnd/dndCommon.c +++ b/open-vm-tools/services/plugins/dndcp/dnd/dndCommon.c @@ -29,8 +29,10 @@ #include #include "vmware.h" +#include "codeset.h" #include "dndInt.h" #include "dnd.h" +#include "dndClipboard.h" #include "file.h" #include "str.h" #include "random.h" @@ -671,6 +673,46 @@ DnD_GetLastDirName(const char *str) // IN return Unicode_AllocWithLength(str + start, res, STRING_ENCODING_UTF8); } +/* + *----------------------------------------------------------------------------- + * + * DnD_SetCPClipboardAndTruncateText -- + * + * Truncate the text if the size exceeds the maximum size and then put it + * into clip. + * + * Results: + * None + * + * Side effects: + * The destBuf should be released by the caller where the destBuf allocated. + * + *----------------------------------------------------------------------------- + */ + +void +DnD_SetCPClipboardAndTruncateText(CPClipboard *clip, // IN/OUT + char *destBuf, // IN + size_t len) // IN +{ + size_t bytesLeft = clip->maxSize - CPClipboard_GetTotalSize(clip) - 1; + + // Truncate if the length is greater than max allowed. + if (len > bytesLeft) { + size_t boundaryPoint = + CodeSet_Utf8FindCodePointBoundary(destBuf, bytesLeft - 1); + destBuf[boundaryPoint] = '\0'; + ASSERT(Unicode_IsBufferValid(destBuf, -1, STRING_ENCODING_UTF8)); + Log("%s: Truncating text from %" FMTSZ "d chars to %" FMTSZ "d chars.\n", + __FUNCTION__, len - 1, boundaryPoint); + len = boundaryPoint + 1; + } + + CPClipboard_SetItem(clip, CPFORMAT_TEXT, destBuf, len); + Log("%s: retrieved text (%" FMTSZ "d bytes) from clipboard.\n", + __FUNCTION__, len); +} + /* Transport layer big buffer support functions. */