1 | /* $Id: clipboard-helper.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard - Some helper function for converting between the various EOLs.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 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 | /** Constants needed for string conversions done by the Linux/Mac clipboard code. */
|
---|
48 | enum
|
---|
49 | {
|
---|
50 | /** In Linux, lines end with a linefeed character. */
|
---|
51 | VBOX_SHCL_LINEFEED = 0xa,
|
---|
52 | /** In Windows, lines end with a carriage return and a linefeed character. */
|
---|
53 | VBOX_SHCL_CARRIAGERETURN = 0xd,
|
---|
54 | /** Little endian "real" UTF-16 strings start with this marker. */
|
---|
55 | VBOX_SHCL_UTF16LEMARKER = 0xfeff,
|
---|
56 | /** Big endian "real" UTF-16 strings start with this marker. */
|
---|
57 | VBOX_SHCL_UTF16BEMARKER = 0xfffe
|
---|
58 | };
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Returns the length (in UTF-8 characters) of an UTF-16 string with LF EOL.
|
---|
62 | *
|
---|
63 | * @returns VBox status code.
|
---|
64 | * @param pcwszSrc UTF-16 string to return size for.
|
---|
65 | * @param cwcSrc Length of the string in RTUTF16 units.
|
---|
66 | * @param pchLen Where to return the length (in UTF-8 characters).
|
---|
67 | * Does not include terminator.
|
---|
68 | */
|
---|
69 | int ShClUtf16LFLenUtf8(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pchLen);
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Returns the length (in UTF-8 characters) of an UTF-16 string with CRLF EOL.
|
---|
73 | *
|
---|
74 | * @returns VBox status code.
|
---|
75 | * @param pcwszSrc UTF-16 string to return size for.
|
---|
76 | * @param cwcSrc Length of the source string in RTUTF16 units.
|
---|
77 | * @param pchLen Where to return the length (in UTF-8 characters).
|
---|
78 | * Does not include terminator.
|
---|
79 | */
|
---|
80 | int ShClUtf16CRLFLenUtf8(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pchLen);
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Returns the length (in characters) of an UTF-16 string, including terminator.
|
---|
84 | *
|
---|
85 | * @returns VBox status code.
|
---|
86 | * @param pcwszSrc UTF-16 string to return size for.
|
---|
87 | * @param cwcSrc Length of the source string in RTUTF16 units.
|
---|
88 | * @param pchLen Where to return the length (in UTF-8 characters).
|
---|
89 | * Does not include terminator.
|
---|
90 | */
|
---|
91 | int ShClUtf16LenUtf8(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pchLen);
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Converts an UTF-16 string with LF EOL to an UTF-16 string with CRLF EOL.
|
---|
95 | *
|
---|
96 | * @returns VBox status code.
|
---|
97 | * @param pcwszSrc UTF-16 string to convert.
|
---|
98 | * @param cwcSrc Size of the string int RTUTF16 units.
|
---|
99 | * @param pwszDst Buffer to store the converted string to.
|
---|
100 | * @param cwcDst The size of \a pwszDst in RTUTF16 units.
|
---|
101 | */
|
---|
102 | int ShClConvUtf16LFToCRLF(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Converts an UTF-16 string with LF EOL to an UTF-16 string with CRLF EOL.
|
---|
106 | *
|
---|
107 | * Convenience function which returns the allocated + converted string on success.
|
---|
108 | *
|
---|
109 | * @returns VBox status code.
|
---|
110 | * @param pcwszSrc UTF-16 string to convert.
|
---|
111 | * @param cwcSrc Size of the string int RTUTF16 units.
|
---|
112 | * @param ppwszDst Where to return the allocated converted string. Must be free'd by the caller.
|
---|
113 | * @param pcwDst Where to return the size of the converted string in RTUTF16 units.
|
---|
114 | * Does not include the terminator.
|
---|
115 | */
|
---|
116 | int ShClConvUtf16LFToCRLFA(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 *ppwszDst, size_t *pcwDst);
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Converts an UTF-16 string with CRLF EOL to an UTF-16 string with LF EOL.
|
---|
120 | *
|
---|
121 | * @returns VBox status code.
|
---|
122 | * @param pcwszSrc UTF-16 string to convert.
|
---|
123 | * @param cwcSrc Size of the string in RTUTF16 units.
|
---|
124 | * @param pwszDst Where to store the converted string to.
|
---|
125 | * @param cwcDst The size of \a pwszDst in RTUTF16 units.
|
---|
126 | */
|
---|
127 | int ShClConvUtf16CRLFToLF(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Converts an UTF-16 string with CRLF EOL to UTF-8 LF.
|
---|
131 | *
|
---|
132 | * @returns VBox status code. Will return VERR_NO_DATA if no data was converted.
|
---|
133 | * @param pcwszSrc UTF-16 string to convert.
|
---|
134 | * @param cbSrc Length of @a pwszSrc (in bytes).
|
---|
135 | * @param pszBuf Where to write the converted string.
|
---|
136 | * @param cbBuf The size of the buffer pointed to by @a pszBuf.
|
---|
137 | * @param pcbLen Where to store the size (in bytes) of the converted string.
|
---|
138 | * Does not include terminator.
|
---|
139 | */
|
---|
140 | int ShClConvUtf16CRLFToUtf8LF(PCRTUTF16 pcwszSrc, size_t cbSrc, char *pszBuf, size_t cbBuf, size_t *pcbLen);
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Converts an HTML string from UTF-16 into UTF-8.
|
---|
144 | *
|
---|
145 | * @returns VBox status code.
|
---|
146 | * @param pcwszSrc UTF-16 string to convert.
|
---|
147 | * @param cwcSrc Length (in RTUTF16 units) of the source text.
|
---|
148 | * @param ppszDst Where to store the converted result on success.
|
---|
149 | * @param pcbDst Where to store the number of bytes written.
|
---|
150 | */
|
---|
151 | int ShClConvUtf16ToUtf8HTML(PCRTUTF16 pcwszSrc, size_t cwcSrc, char **ppszDst, size_t *pcbDst);
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Converts an UTF-8 string with LF EOL into UTF-16 CRLF.
|
---|
155 | *
|
---|
156 | * @returns VBox status code.
|
---|
157 | * @param pcszSrc UTF-8 string to convert.
|
---|
158 | * @param cbSrc Size of UTF-8 string to convert (in bytes), not counting the terminating zero.
|
---|
159 | * @param ppwszDst Where to return the allocated buffer on success.
|
---|
160 | * @param pcwDst Where to return the size (in RTUTF16 units) of the allocated buffer on success.
|
---|
161 | * Does not include terminator.
|
---|
162 | */
|
---|
163 | int ShClConvUtf8LFToUtf16CRLF(const char *pcszSrc, size_t cbSrc, PRTUTF16 *ppwszDst, size_t *pcwDst);
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Converts a Latin-1 string with LF EOL into UTF-16 CRLF.
|
---|
167 | *
|
---|
168 | * @returns VBox status code.
|
---|
169 | * @param pcszSrc UTF-8 string to convert.
|
---|
170 | * @param cbSrc Size of string (in bytes), not counting the terminating zero.
|
---|
171 | * @param ppwszDst Where to return the allocated buffer on success.
|
---|
172 | * @param pcwDst Where to return the size (in RTUTF16 units) of the allocated buffer on success.
|
---|
173 | * Does not include terminator.
|
---|
174 | */
|
---|
175 | int ShClConvLatin1LFToUtf16CRLF(const char *pcszSrc, size_t cbSrc, PRTUTF16 *ppwszDst, size_t *pcwDst);
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * Convert CF_DIB data to full BMP data by prepending the BM header.
|
---|
179 | * Allocates with RTMemAlloc.
|
---|
180 | *
|
---|
181 | * @returns VBox status code.
|
---|
182 | * @param pvSrc DIB data to convert
|
---|
183 | * @param cbSrc Size of the DIB data to convert in bytes
|
---|
184 | * @param ppvDst Where to store the pointer to the buffer for the
|
---|
185 | * destination data
|
---|
186 | * @param pcbDst Pointer to the size of the buffer for the destination
|
---|
187 | * data in bytes.
|
---|
188 | */
|
---|
189 | int ShClDibToBmp(const void *pvSrc, size_t cbSrc, void **ppvDst, size_t *pcbDst);
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Get the address and size of CF_DIB data in a full BMP data in the input buffer.
|
---|
193 | * Does not do any allocation.
|
---|
194 | *
|
---|
195 | * @returns VBox status code.
|
---|
196 | * @param pvSrc BMP data to convert
|
---|
197 | * @param cbSrc Size of the BMP data to convert in bytes
|
---|
198 | * @param ppvDst Where to store the pointer to the destination data
|
---|
199 | * @param pcbDst Pointer to the size of the destination data in bytes
|
---|
200 | */
|
---|
201 | int ShClBmpGetDib(const void *pvSrc, size_t cbSrc, const void **ppvDst, size_t *pcbDst);
|
---|
202 |
|
---|
203 | #ifdef LOG_ENABLED
|
---|
204 | /**
|
---|
205 | * Dumps HTML data to the debug log.
|
---|
206 | *
|
---|
207 | * @returns VBox status code.
|
---|
208 | * @param pszSrc HTML data to dump.
|
---|
209 | * @param cbSrc Size (in bytes) of HTML data to dump.
|
---|
210 | */
|
---|
211 | int ShClDbgDumpHtml(const char *pszSrc, size_t cbSrc);
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * Dumps data using a specified clipboard format.
|
---|
215 | *
|
---|
216 | * @param pv Pointer to data to dump.
|
---|
217 | * @param cb Size (in bytes) of data to dump.
|
---|
218 | * @param u32Format Clipboard format to use for dumping.
|
---|
219 | */
|
---|
220 | void ShClDbgDumpData(const void *pv, size_t cb, SHCLFORMAT u32Format);
|
---|
221 | #endif /* LOG_ENABLED */
|
---|
222 |
|
---|
223 | /**
|
---|
224 | * Translates a Shared Clipboard host function number to a string.
|
---|
225 | *
|
---|
226 | * @returns Function ID string name.
|
---|
227 | * @param uFn The function to translate.
|
---|
228 | */
|
---|
229 | const char *ShClHostFunctionToStr(uint32_t uFn);
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * Translates a Shared Clipboard host message enum to a string.
|
---|
233 | *
|
---|
234 | * @returns Message ID string name.
|
---|
235 | * @param uMsg The message to translate.
|
---|
236 | */
|
---|
237 | const char *ShClHostMsgToStr(uint32_t uMsg);
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Translates a Shared Clipboard guest message enum to a string.
|
---|
241 | *
|
---|
242 | * @returns Message ID string name.
|
---|
243 | * @param uMsg The message to translate.
|
---|
244 | */
|
---|
245 | const char *ShClGuestMsgToStr(uint32_t uMsg);
|
---|
246 |
|
---|
247 | char *ShClFormatsToStrA(SHCLFORMATS fFormats);
|
---|
248 |
|
---|
249 | #endif /* !VBOX_INCLUDED_GuestHost_clipboard_helper_h */
|
---|
250 |
|
---|