1 | /* $Id: clipboard-helper.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard - Some helper function for converting between the various EOLs.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef VBOX_INCLUDED_GuestHost_clipboard_helper_h
|
---|
38 | #define VBOX_INCLUDED_GuestHost_clipboard_helper_h
|
---|
39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
40 | # pragma once
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <iprt/string.h>
|
---|
44 |
|
---|
45 | #include <VBox/GuestHost/SharedClipboard.h>
|
---|
46 |
|
---|
47 | /** Guest property which is set by GUI in order to notify guest about VM window focus change. */
|
---|
48 | #define VBOX_GUI_FOCUS_CHANGE_GUEST_PROP_NAME "/VirtualBox/GuestAdd/GuiOnFocus"
|
---|
49 |
|
---|
50 | /** Constants needed for string conversions done by the Linux/Mac clipboard code. */
|
---|
51 | enum
|
---|
52 | {
|
---|
53 | /** In Linux, lines end with a linefeed character. */
|
---|
54 | VBOX_SHCL_LINEFEED = 0xa,
|
---|
55 | /** In Windows, lines end with a carriage return and a linefeed character. */
|
---|
56 | VBOX_SHCL_CARRIAGERETURN = 0xd,
|
---|
57 | /** Little endian "real" UTF-16 strings start with this marker. */
|
---|
58 | VBOX_SHCL_UTF16LEMARKER = 0xfeff,
|
---|
59 | /** Big endian "real" UTF-16 strings start with this marker. */
|
---|
60 | VBOX_SHCL_UTF16BEMARKER = 0xfffe
|
---|
61 | };
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Returns calculated length (in UTF-8 characters) of normalized UTF-16 string with CRLF EOL.
|
---|
65 | *
|
---|
66 | * This function should be used in order to calculate number of UTF-8 characters
|
---|
67 | * in normalized UTF-16. Normalized string is expected to have LF characters replaced
|
---|
68 | * with CRLF sequences.
|
---|
69 | *
|
---|
70 | * @returns VBox status code.
|
---|
71 | * @param pcwszSrc UTF-16 string to return size for.
|
---|
72 | * @param cwcSrc Length of the string in RTUTF16 units.
|
---|
73 | * @param pchLen Where to return the length (in UTF-8 characters).
|
---|
74 | * Does not include terminator.
|
---|
75 | */
|
---|
76 | int ShClUtf16CalcNormalizedEolToCRLFLength(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pchLen);
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Returns the length (in UTF-8 characters) of an UTF-16 string with CRLF EOL.
|
---|
80 | *
|
---|
81 | * @returns VBox status code.
|
---|
82 | * @param pcwszSrc UTF-16 string to return size for.
|
---|
83 | * @param cwcSrc Length of the source string in RTUTF16 units.
|
---|
84 | * @param pchLen Where to return the length (in UTF-8 characters).
|
---|
85 | * Does not include terminator.
|
---|
86 | */
|
---|
87 | int ShClUtf16CRLFLenUtf8(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pchLen);
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Returns the length (in characters) of an UTF-16 string, including terminator.
|
---|
91 | *
|
---|
92 | * @returns VBox status code.
|
---|
93 | * @param pcwszSrc UTF-16 string to return size for.
|
---|
94 | * @param cwcSrc Length of the source string in RTUTF16 units.
|
---|
95 | * @param pchLen Where to return the length (in UTF-8 characters).
|
---|
96 | * Does not include terminator.
|
---|
97 | */
|
---|
98 | int ShClUtf16LenUtf8(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pchLen);
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Converts an UTF-16 string with LF EOL to an UTF-16 string with CRLF EOL.
|
---|
102 | *
|
---|
103 | * @returns VBox status code.
|
---|
104 | * @param pcwszSrc UTF-16 string to convert.
|
---|
105 | * @param cwcSrc Size of the string int RTUTF16 units.
|
---|
106 | * @param pwszDst Buffer to store the converted string to.
|
---|
107 | * @param cwcDst The size of \a pwszDst in RTUTF16 units.
|
---|
108 | */
|
---|
109 | int ShClConvUtf16LFToCRLF(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Converts an UTF-16 string with LF EOL to an UTF-16 string with CRLF EOL.
|
---|
113 | *
|
---|
114 | * Convenience function which returns the allocated + converted string on success.
|
---|
115 | *
|
---|
116 | * @returns VBox status code.
|
---|
117 | * @param pcwszSrc UTF-16 string to convert.
|
---|
118 | * @param cwcSrc Size of the string int RTUTF16 units.
|
---|
119 | * @param ppwszDst Where to return the allocated converted string. Must be free'd by the caller.
|
---|
120 | * @param pcwDst Where to return the size of the converted string in RTUTF16 units.
|
---|
121 | * Does not include the terminator.
|
---|
122 | */
|
---|
123 | int ShClConvUtf16LFToCRLFA(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 *ppwszDst, size_t *pcwDst);
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Converts an UTF-16 string with CRLF EOL to an UTF-16 string with LF EOL.
|
---|
127 | *
|
---|
128 | * @returns VBox status code.
|
---|
129 | * @param pcwszSrc UTF-16 string to convert.
|
---|
130 | * @param cwcSrc Size of the string in RTUTF16 units.
|
---|
131 | * @param pwszDst Where to store the converted string to.
|
---|
132 | * @param cwcDst The size of \a pwszDst in RTUTF16 units.
|
---|
133 | */
|
---|
134 | int ShClConvUtf16CRLFToLF(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Converts an UTF-16 string with CRLF EOL to UTF-8 LF.
|
---|
138 | *
|
---|
139 | * @returns VBox status code. Will return VERR_NO_DATA if no data was converted.
|
---|
140 | * @param pcwszSrc UTF-16 string to convert.
|
---|
141 | * @param cbSrc Length of @a pwszSrc (in bytes).
|
---|
142 | * @param pszBuf Where to write the converted string.
|
---|
143 | * @param cbBuf The size of the buffer pointed to by @a pszBuf.
|
---|
144 | * @param pcbLen Where to store the size (in bytes) of the converted string.
|
---|
145 | * Does not include terminator.
|
---|
146 | */
|
---|
147 | int ShClConvUtf16CRLFToUtf8LF(PCRTUTF16 pcwszSrc, size_t cbSrc, char *pszBuf, size_t cbBuf, size_t *pcbLen);
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * Converts an HTML string from UTF-16 into UTF-8.
|
---|
151 | *
|
---|
152 | * @returns VBox status code.
|
---|
153 | * @param pcwszSrc UTF-16 string to convert.
|
---|
154 | * @param cwcSrc Length (in RTUTF16 units) of the source text.
|
---|
155 | * @param ppszDst Where to store the converted result on success.
|
---|
156 | * @param pcbDst Where to store the number of bytes written.
|
---|
157 | */
|
---|
158 | int ShClConvUtf16ToUtf8HTML(PCRTUTF16 pcwszSrc, size_t cwcSrc, char **ppszDst, size_t *pcbDst);
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Converts an UTF-8 string with LF EOL into UTF-16 CRLF.
|
---|
162 | *
|
---|
163 | * @returns VBox status code.
|
---|
164 | * @param pcszSrc UTF-8 string to convert.
|
---|
165 | * @param cbSrc Size of UTF-8 string to convert (in bytes), not counting the terminating zero.
|
---|
166 | * @param ppwszDst Where to return the allocated buffer on success.
|
---|
167 | * @param pcwDst Where to return the size (in RTUTF16 units) of the allocated buffer on success.
|
---|
168 | * Does not include terminator.
|
---|
169 | */
|
---|
170 | int ShClConvUtf8LFToUtf16CRLF(const char *pcszSrc, size_t cbSrc, PRTUTF16 *ppwszDst, size_t *pcwDst);
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * Converts a Latin-1 string with LF EOL into UTF-16 CRLF.
|
---|
174 | *
|
---|
175 | * @returns VBox status code.
|
---|
176 | * @param pcszSrc UTF-8 string to convert.
|
---|
177 | * @param cbSrc Size of string (in bytes), not counting the terminating zero.
|
---|
178 | * @param ppwszDst Where to return the allocated buffer on success.
|
---|
179 | * @param pcwDst Where to return the size (in RTUTF16 units) of the allocated buffer on success.
|
---|
180 | * Does not include terminator.
|
---|
181 | */
|
---|
182 | int ShClConvLatin1LFToUtf16CRLF(const char *pcszSrc, size_t cbSrc, PRTUTF16 *ppwszDst, size_t *pcwDst);
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Convert CF_DIB data to full BMP data by prepending the BM header.
|
---|
186 | * Allocates with RTMemAlloc.
|
---|
187 | *
|
---|
188 | * @returns VBox status code.
|
---|
189 | * @param pvSrc DIB data to convert
|
---|
190 | * @param cbSrc Size of the DIB data to convert in bytes
|
---|
191 | * @param ppvDst Where to store the pointer to the buffer for the
|
---|
192 | * destination data
|
---|
193 | * @param pcbDst Pointer to the size of the buffer for the destination
|
---|
194 | * data in bytes.
|
---|
195 | */
|
---|
196 | int ShClDibToBmp(const void *pvSrc, size_t cbSrc, void **ppvDst, size_t *pcbDst);
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Get the address and size of CF_DIB data in a full BMP data in the input buffer.
|
---|
200 | * Does not do any allocation.
|
---|
201 | *
|
---|
202 | * @returns VBox status code.
|
---|
203 | * @param pvSrc BMP data to convert
|
---|
204 | * @param cbSrc Size of the BMP data to convert in bytes
|
---|
205 | * @param ppvDst Where to store the pointer to the destination data
|
---|
206 | * @param pcbDst Pointer to the size of the destination data in bytes
|
---|
207 | */
|
---|
208 | int ShClBmpGetDib(const void *pvSrc, size_t cbSrc, const void **ppvDst, size_t *pcbDst);
|
---|
209 |
|
---|
210 | #ifdef LOG_ENABLED
|
---|
211 | /**
|
---|
212 | * Dumps HTML data to the debug log.
|
---|
213 | *
|
---|
214 | * @returns VBox status code.
|
---|
215 | * @param pszSrc HTML data to dump.
|
---|
216 | * @param cbSrc Size (in bytes) of HTML data to dump.
|
---|
217 | */
|
---|
218 | int ShClDbgDumpHtml(const char *pszSrc, size_t cbSrc);
|
---|
219 |
|
---|
220 | /**
|
---|
221 | * Dumps data using a specified clipboard format.
|
---|
222 | *
|
---|
223 | * @param pv Pointer to data to dump.
|
---|
224 | * @param cb Size (in bytes) of data to dump.
|
---|
225 | * @param u32Format Clipboard format to use for dumping.
|
---|
226 | */
|
---|
227 | void ShClDbgDumpData(const void *pv, size_t cb, SHCLFORMAT u32Format);
|
---|
228 | #endif /* LOG_ENABLED */
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * Translates a Shared Clipboard host function number to a string.
|
---|
232 | *
|
---|
233 | * @returns Function ID string name.
|
---|
234 | * @param uFn The function to translate.
|
---|
235 | */
|
---|
236 | const char *ShClHostFunctionToStr(uint32_t uFn);
|
---|
237 |
|
---|
238 | /**
|
---|
239 | * Translates a Shared Clipboard host message enum to a string.
|
---|
240 | *
|
---|
241 | * @returns Message ID string name.
|
---|
242 | * @param uMsg The message to translate.
|
---|
243 | */
|
---|
244 | const char *ShClHostMsgToStr(uint32_t uMsg);
|
---|
245 |
|
---|
246 | /**
|
---|
247 | * Translates a Shared Clipboard guest message enum to a string.
|
---|
248 | *
|
---|
249 | * @returns Message ID string name.
|
---|
250 | * @param uMsg The message to translate.
|
---|
251 | */
|
---|
252 | const char *ShClGuestMsgToStr(uint32_t uMsg);
|
---|
253 |
|
---|
254 | char *ShClFormatsToStrA(SHCLFORMATS fFormats);
|
---|
255 |
|
---|
256 | #endif /* !VBOX_INCLUDED_GuestHost_clipboard_helper_h */
|
---|
257 |
|
---|