1 | /* $Id: clipboard-helper.h 85845 2020-08-20 14:28:33Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard - Some helper function for converting between the various EOLs.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef VBOX_INCLUDED_GuestHost_clipboard_helper_h
|
---|
28 | #define VBOX_INCLUDED_GuestHost_clipboard_helper_h
|
---|
29 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
30 | # pragma once
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include <iprt/string.h>
|
---|
34 |
|
---|
35 | #include <VBox/GuestHost/SharedClipboard.h>
|
---|
36 |
|
---|
37 | /** Constants needed for string conversions done by the Linux/Mac clipboard code. */
|
---|
38 | enum
|
---|
39 | {
|
---|
40 | /** In Linux, lines end with a linefeed character. */
|
---|
41 | VBOX_SHCL_LINEFEED = 0xa,
|
---|
42 | /** In Windows, lines end with a carriage return and a linefeed character. */
|
---|
43 | VBOX_SHCL_CARRIAGERETURN = 0xd,
|
---|
44 | /** Little endian "real" UTF-16 strings start with this marker. */
|
---|
45 | VBOX_SHCL_UTF16LEMARKER = 0xfeff,
|
---|
46 | /** Big endian "real" UTF-16 strings start with this marker. */
|
---|
47 | VBOX_SHCL_UTF16BEMARKER = 0xfffe
|
---|
48 | };
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Returns the length (in UTF-8 characters) of an UTF-16 string with LF EOL.
|
---|
52 | *
|
---|
53 | * @returns VBox status code.
|
---|
54 | * @param pcwszSrc UTF-16 string to return size for.
|
---|
55 | * @param cwcSrc Length of the string in RTUTF16 units.
|
---|
56 | * @param pchLen Where to return the length (in UTF-8 characters).
|
---|
57 | * Does not include terminator.
|
---|
58 | */
|
---|
59 | int ShClUtf16LFLenUtf8(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pchLen);
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Returns the length (in UTF-8 characters) of an UTF-16 string with CRLF EOL.
|
---|
63 | *
|
---|
64 | * @returns VBox status code.
|
---|
65 | * @param pcwszSrc UTF-16 string to return size for.
|
---|
66 | * @param cwcSrc Length of the source string in RTUTF16 units.
|
---|
67 | * @param pchLen Where to return the length (in UTF-8 characters).
|
---|
68 | * Does not include terminator.
|
---|
69 | */
|
---|
70 | int ShClUtf16CRLFLenUtf8(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pchLen);
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Returns the length (in characters) of an UTF-16 string, including terminator.
|
---|
74 | *
|
---|
75 | * @returns VBox status code.
|
---|
76 | * @param pcwszSrc UTF-16 string to return size for.
|
---|
77 | * @param cwcSrc Length of the source string in RTUTF16 units.
|
---|
78 | * @param pchLen Where to return the length (in UTF-8 characters).
|
---|
79 | * Does not include terminator.
|
---|
80 | */
|
---|
81 | int ShClUtf16LenUtf8(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pchLen);
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Converts an UTF-16 string with LF EOL to an UTF-16 string with CRLF EOL.
|
---|
85 | *
|
---|
86 | * @returns VBox status code.
|
---|
87 | * @param pcwszSrc UTF-16 string to convert.
|
---|
88 | * @param cwcSrc Size of the string int RTUTF16 units.
|
---|
89 | * @param pwszDst Buffer to store the converted string to.
|
---|
90 | * @param cwcDst The size of \a pwszDst in RTUTF16 units.
|
---|
91 | */
|
---|
92 | int ShClConvUtf16LFToCRLF(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Converts an UTF-16 string with LF EOL to an UTF-16 string with CRLF EOL.
|
---|
96 | *
|
---|
97 | * Convenience function which returns the allocated + converted string on success.
|
---|
98 | *
|
---|
99 | * @returns VBox status code.
|
---|
100 | * @param pcwszSrc UTF-16 string to convert.
|
---|
101 | * @param cwcSrc Size of the string int RTUTF16 units.
|
---|
102 | * @param ppwszDst Where to return the allocated converted string. Must be free'd by the caller.
|
---|
103 | * @param pcwDst Where to return the size of the converted string in RTUTF16 units.
|
---|
104 | * Does not include the terminator.
|
---|
105 | */
|
---|
106 | int ShClConvUtf16LFToCRLFA(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 *ppwszDst, size_t *pcwDst);
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Converts an UTF-16 string with CRLF EOL to an UTF-16 string with LF EOL.
|
---|
110 | *
|
---|
111 | * @returns VBox status code.
|
---|
112 | * @param pcwszSrc UTF-16 string to convert.
|
---|
113 | * @param cwcSrc Size of the string in RTUTF16 units.
|
---|
114 | * @param pwszDst Where to store the converted string to.
|
---|
115 | * @param cwcDst The size of \a pwszDst in RTUTF16 units.
|
---|
116 | */
|
---|
117 | int ShClConvUtf16CRLFToLF(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Converts an UTF-16 string with CRLF EOL to UTF-8 LF.
|
---|
121 | *
|
---|
122 | * @returns VBox status code. Will return VERR_NO_DATA if no data was converted.
|
---|
123 | * @param pcwszSrc UTF-16 string to convert.
|
---|
124 | * @param cbSrc Length of @a pwszSrc (in bytes).
|
---|
125 | * @param pszBuf Where to write the converted string.
|
---|
126 | * @param cbBuf The size of the buffer pointed to by @a pszBuf.
|
---|
127 | * @param pcbLen Where to store the size (in bytes) of the converted string.
|
---|
128 | * Does not include terminator.
|
---|
129 | */
|
---|
130 | int ShClConvUtf16CRLFToUtf8LF(PCRTUTF16 pcwszSrc, size_t cbSrc, char *pszBuf, size_t cbBuf, size_t *pcbLen);
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Converts an HTML string from UTF-16 into UTF-8.
|
---|
134 | *
|
---|
135 | * @returns VBox status code.
|
---|
136 | * @param pcwszSrc UTF-16 string to convert.
|
---|
137 | * @param cwcSrc Length (in RTUTF16 units) of the source text.
|
---|
138 | * @param ppszDst Where to store the converted result on success.
|
---|
139 | * @param pcbDst Where to store the number of bytes written.
|
---|
140 | */
|
---|
141 | int ShClConvUtf16ToUtf8HTML(PCRTUTF16 pcwszSrc, size_t cwcSrc, char **ppszDst, size_t *pcbDst);
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Converts an UTF-8 string with LF EOL into UTF-16 CRLF.
|
---|
145 | *
|
---|
146 | * @returns VBox status code.
|
---|
147 | * @param pcszSrc UTF-8 string to convert.
|
---|
148 | * @param cbSrc Size of UTF-8 string to convert (in bytes), not counting the terminating zero.
|
---|
149 | * @param ppwszDst Where to return the allocated buffer on success.
|
---|
150 | * @param pcwDst Where to return the size (in RTUTF16 units) of the allocated buffer on success.
|
---|
151 | * Does not include terminator.
|
---|
152 | */
|
---|
153 | int ShClConvUtf8LFToUtf16CRLF(const char *pcszSrc, size_t cbSrc, PRTUTF16 *ppwszDst, size_t *pcwDst);
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Converts a Latin-1 string with LF EOL into UTF-16 CRLF.
|
---|
157 | *
|
---|
158 | * @returns VBox status code.
|
---|
159 | * @param pcszSrc UTF-8 string to convert.
|
---|
160 | * @param cbSrc Size of string (in bytes), not counting the terminating zero.
|
---|
161 | * @param ppwszDst Where to return the allocated buffer on success.
|
---|
162 | * @param pcwDst Where to return the size (in RTUTF16 units) of the allocated buffer on success.
|
---|
163 | * Does not include terminator.
|
---|
164 | */
|
---|
165 | int ShClConvLatin1LFToUtf16CRLF(const char *pcszSrc, size_t cbSrc, PRTUTF16 *ppwszDst, size_t *pcwDst);
|
---|
166 |
|
---|
167 | #pragma pack(1)
|
---|
168 | /** @todo r=bird: Why duplicate these structures here, we've got them in
|
---|
169 | * DevVGA.cpp already! */
|
---|
170 | /**
|
---|
171 | * Bitmap File Header. Official win32 name is BITMAPFILEHEADER
|
---|
172 | * Always Little Endian.
|
---|
173 | */
|
---|
174 | typedef struct BMFILEHEADER
|
---|
175 | {
|
---|
176 | uint16_t uType;
|
---|
177 | uint32_t uSize;
|
---|
178 | uint16_t uReserved1;
|
---|
179 | uint16_t uReserved2;
|
---|
180 | uint32_t uOffBits;
|
---|
181 | } BMFILEHEADER;
|
---|
182 | #pragma pack()
|
---|
183 |
|
---|
184 | /** Pointer to a BMFILEHEADER structure. */
|
---|
185 | typedef BMFILEHEADER *PBMFILEHEADER;
|
---|
186 | /** BMP file magic number */
|
---|
187 | #define BITMAPHEADERMAGIC (RT_H2LE_U16_C(0x4d42))
|
---|
188 |
|
---|
189 | /**
|
---|
190 | * Bitmap Info Header. Official win32 name is BITMAPINFOHEADER
|
---|
191 | * Always Little Endian.
|
---|
192 | */
|
---|
193 | typedef struct BMINFOHEADER
|
---|
194 | {
|
---|
195 | uint32_t uSize;
|
---|
196 | uint32_t uWidth;
|
---|
197 | uint32_t uHeight;
|
---|
198 | uint16_t uPlanes;
|
---|
199 | uint16_t uBitCount;
|
---|
200 | uint32_t uCompression;
|
---|
201 | uint32_t uSizeImage;
|
---|
202 | uint32_t uXBitsPerMeter;
|
---|
203 | uint32_t uYBitsPerMeter;
|
---|
204 | uint32_t uClrUsed;
|
---|
205 | uint32_t uClrImportant;
|
---|
206 | } BMINFOHEADER;
|
---|
207 | /** Pointer to a BMINFOHEADER structure. */
|
---|
208 | typedef BMINFOHEADER *PBMINFOHEADER;
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * Convert CF_DIB data to full BMP data by prepending the BM header.
|
---|
212 | * Allocates with RTMemAlloc.
|
---|
213 | *
|
---|
214 | * @returns VBox status code.
|
---|
215 | * @param pvSrc DIB data to convert
|
---|
216 | * @param cbSrc Size of the DIB data to convert in bytes
|
---|
217 | * @param ppvDst Where to store the pointer to the buffer for the
|
---|
218 | * destination data
|
---|
219 | * @param pcbDst Pointer to the size of the buffer for the destination
|
---|
220 | * data in bytes.
|
---|
221 | */
|
---|
222 | int ShClDibToBmp(const void *pvSrc, size_t cbSrc, void **ppvDst, size_t *pcbDst);
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * Get the address and size of CF_DIB data in a full BMP data in the input buffer.
|
---|
226 | * Does not do any allocation.
|
---|
227 | *
|
---|
228 | * @returns VBox status code.
|
---|
229 | * @param pvSrc BMP data to convert
|
---|
230 | * @param cbSrc Size of the BMP data to convert in bytes
|
---|
231 | * @param ppvDst Where to store the pointer to the destination data
|
---|
232 | * @param pcbDst Pointer to the size of the destination data in bytes
|
---|
233 | */
|
---|
234 | int ShClBmpGetDib(const void *pvSrc, size_t cbSrc, const void **ppvDst, size_t *pcbDst);
|
---|
235 |
|
---|
236 | #ifdef LOG_ENABLED
|
---|
237 | /**
|
---|
238 | * Dumps HTML data to the debug log.
|
---|
239 | *
|
---|
240 | * @returns VBox status code.
|
---|
241 | * @param pszSrc HTML data to dump.
|
---|
242 | * @param cbSrc Size (in bytes) of HTML data to dump.
|
---|
243 | */
|
---|
244 | int ShClDbgDumpHtml(const char *pszSrc, size_t cbSrc);
|
---|
245 |
|
---|
246 | /**
|
---|
247 | * Dumps data using a specified clipboard format.
|
---|
248 | *
|
---|
249 | * @param pv Pointer to data to dump.
|
---|
250 | * @param cb Size (in bytes) of data to dump.
|
---|
251 | * @param u32Format Clipboard format to use for dumping.
|
---|
252 | */
|
---|
253 | void ShClDbgDumpData(const void *pv, size_t cb, SHCLFORMAT u32Format);
|
---|
254 | #endif /* LOG_ENABLED */
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * Translates a Shared Clipboard host function number to a string.
|
---|
258 | *
|
---|
259 | * @returns Function ID string name.
|
---|
260 | * @param uFn The function to translate.
|
---|
261 | */
|
---|
262 | const char *ShClHostFunctionToStr(uint32_t uFn);
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * Translates a Shared Clipboard host message enum to a string.
|
---|
266 | *
|
---|
267 | * @returns Message ID string name.
|
---|
268 | * @param uMsg The message to translate.
|
---|
269 | */
|
---|
270 | const char *ShClHostMsgToStr(uint32_t uMsg);
|
---|
271 |
|
---|
272 | /**
|
---|
273 | * Translates a Shared Clipboard guest message enum to a string.
|
---|
274 | *
|
---|
275 | * @returns Message ID string name.
|
---|
276 | * @param uMsg The message to translate.
|
---|
277 | */
|
---|
278 | const char *ShClGuestMsgToStr(uint32_t uMsg);
|
---|
279 |
|
---|
280 | #endif /* !VBOX_INCLUDED_GuestHost_clipboard_helper_h */
|
---|
281 |
|
---|