1 | /* $Id: clipboard-helper.h 82284 2019-11-29 13:23:55Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard - Some helper function for converting between the various EOLs.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2019 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 | * Get the size of the buffer needed to hold a UTF-16-LE zero terminated string
|
---|
52 | * with Windows EOLs converted from a UTF-16 string with Linux EOLs.
|
---|
53 | *
|
---|
54 | * @returns VBox status code.
|
---|
55 | * @param pcwszSrc The source UTF-16 string.
|
---|
56 | * @param cwcSrc The length of the source string in RTUTF16 units.
|
---|
57 | * @param pcwcDst The length of the destination string in RTUTF16 units.
|
---|
58 | */
|
---|
59 | int ShClUtf16GetWinSize(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pcwcDst);
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Convert a UTF-16 text with Linux EOLs to null-terminated UTF-16-LE with
|
---|
63 | * Windows EOLs.
|
---|
64 | *
|
---|
65 | * Does no checking for validity.
|
---|
66 | *
|
---|
67 | * @returns VBox status code.
|
---|
68 | * @param pcwszSrc Source UTF-16 text to convert.
|
---|
69 | * @param cwcSrc Size of the source text int RTUTF16 units.
|
---|
70 | * @param pwszDst Buffer to store the converted text to.
|
---|
71 | * @param cwcDst Size of the buffer for the converted text in RTUTF16 units.
|
---|
72 | */
|
---|
73 | int ShClUtf16LinToWin(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Get the size of the buffer needed to hold a zero-terminated UTF-16 string
|
---|
77 | * with Linux EOLs converted from a UTF-16 string with Windows EOLs.
|
---|
78 | *
|
---|
79 | * @returns VBox status code.
|
---|
80 | * @param pcwszSrc The source UTF-16 string.
|
---|
81 | * @param cwcSrc The length of the source string in RTUTF16 units.
|
---|
82 | * @param pcwcDst The length of the destination string in RTUTF16 units.
|
---|
83 | */
|
---|
84 | int ShClUtf16GetLinSize(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pcwcDst);
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Convert UTF-16-LE text with Windows EOLs to zero-terminated UTF-16 with Linux
|
---|
88 | * EOLs. This function does not verify that the UTF-16 is valid.
|
---|
89 | *
|
---|
90 | * @returns VBox status code.
|
---|
91 | * @param pcwszSrc Text to convert.
|
---|
92 | * @param cwcSrc Size of the source text in RTUTF16 units.
|
---|
93 | * @param pwszDst The buffer to store the converted text to.
|
---|
94 | * @param cwcDst The size of the buffer for the destination text in RTUTF16 chars.
|
---|
95 | */
|
---|
96 | int ShClUtf16WinToLin(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
|
---|
97 |
|
---|
98 | #pragma pack(1)
|
---|
99 | /** @todo r=bird: Why duplicate these structures here, we've got them in
|
---|
100 | * DevVGA.cpp already! */
|
---|
101 | /**
|
---|
102 | * Bitmap File Header. Official win32 name is BITMAPFILEHEADER
|
---|
103 | * Always Little Endian.
|
---|
104 | */
|
---|
105 | typedef struct BMFILEHEADER
|
---|
106 | {
|
---|
107 | uint16_t uType;
|
---|
108 | uint32_t uSize;
|
---|
109 | uint16_t uReserved1;
|
---|
110 | uint16_t uReserved2;
|
---|
111 | uint32_t uOffBits;
|
---|
112 | } BMFILEHEADER;
|
---|
113 | #pragma pack()
|
---|
114 |
|
---|
115 | /** Pointer to a BMFILEHEADER structure. */
|
---|
116 | typedef BMFILEHEADER *PBMFILEHEADER;
|
---|
117 | /** BMP file magic number */
|
---|
118 | #define BITMAPHEADERMAGIC (RT_H2LE_U16_C(0x4d42))
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Bitmap Info Header. Official win32 name is BITMAPINFOHEADER
|
---|
122 | * Always Little Endian.
|
---|
123 | */
|
---|
124 | typedef struct BMINFOHEADER
|
---|
125 | {
|
---|
126 | uint32_t uSize;
|
---|
127 | uint32_t uWidth;
|
---|
128 | uint32_t uHeight;
|
---|
129 | uint16_t uPlanes;
|
---|
130 | uint16_t uBitCount;
|
---|
131 | uint32_t uCompression;
|
---|
132 | uint32_t uSizeImage;
|
---|
133 | uint32_t uXBitsPerMeter;
|
---|
134 | uint32_t uYBitsPerMeter;
|
---|
135 | uint32_t uClrUsed;
|
---|
136 | uint32_t uClrImportant;
|
---|
137 | } BMINFOHEADER;
|
---|
138 | /** Pointer to a BMINFOHEADER structure. */
|
---|
139 | typedef BMINFOHEADER *PBMINFOHEADER;
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Convert CF_DIB data to full BMP data by prepending the BM header.
|
---|
143 | * Allocates with RTMemAlloc.
|
---|
144 | *
|
---|
145 | * @returns VBox status code.
|
---|
146 | * @param pvSrc DIB data to convert
|
---|
147 | * @param cbSrc Size of the DIB data to convert in bytes
|
---|
148 | * @param ppvDst Where to store the pointer to the buffer for the
|
---|
149 | * destination data
|
---|
150 | * @param pcbDst Pointer to the size of the buffer for the destination
|
---|
151 | * data in bytes.
|
---|
152 | */
|
---|
153 | int ShClDibToBmp(const void *pvSrc, size_t cbSrc, void **ppvDst, size_t *pcbDst);
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Get the address and size of CF_DIB data in a full BMP data in the input buffer.
|
---|
157 | * Does not do any allocation.
|
---|
158 | *
|
---|
159 | * @returns VBox status code.
|
---|
160 | * @param pvSrc BMP data to convert
|
---|
161 | * @param cbSrc Size of the BMP data to convert in bytes
|
---|
162 | * @param ppvDst Where to store the pointer to the destination data
|
---|
163 | * @param pcbDst Pointer to the size of the destination data in bytes
|
---|
164 | */
|
---|
165 | int ShClBmpGetDib(const void *pvSrc, size_t cbSrc, const void **ppvDst, size_t *pcbDst);
|
---|
166 |
|
---|
167 | #ifdef LOG_ENABLED
|
---|
168 | /**
|
---|
169 | * Dumps HTML data to the debug log.
|
---|
170 | *
|
---|
171 | * @returns VBox status code.
|
---|
172 | * @param pszSrc HTML data to dump.
|
---|
173 | * @param cbSrc Size (in bytes) of HTML data to dump.
|
---|
174 | */
|
---|
175 | int ShClDbgDumpHtml(const char *pszSrc, size_t cbSrc);
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * Dumps data using a specified clipboard format.
|
---|
179 | *
|
---|
180 | * @param pv Pointer to data to dump.
|
---|
181 | * @param cb Size (in bytes) of data to dump.
|
---|
182 | * @param u32Format Clipboard format to use for dumping.
|
---|
183 | */
|
---|
184 | void ShClDbgDumpData(const void *pv, size_t cb, SHCLFORMAT u32Format);
|
---|
185 | #endif /* LOG_ENABLED */
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * Translates a Shared Clipboard host function number to a string.
|
---|
189 | *
|
---|
190 | * @returns Function ID string name.
|
---|
191 | * @param uFn The function to translate.
|
---|
192 | */
|
---|
193 | const char *ShClHostFunctionToStr(uint32_t uFn);
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * Translates a Shared Clipboard host message enum to a string.
|
---|
197 | *
|
---|
198 | * @returns Message ID string name.
|
---|
199 | * @param uMsg The message to translate.
|
---|
200 | */
|
---|
201 | const char *ShClHostMsgToStr(uint32_t uMsg);
|
---|
202 |
|
---|
203 | /**
|
---|
204 | * Translates a Shared Clipboard guest message enum to a string.
|
---|
205 | *
|
---|
206 | * @returns Message ID string name.
|
---|
207 | * @param uMsg The message to translate.
|
---|
208 | */
|
---|
209 | const char *ShClGuestMsgToStr(uint32_t uMsg);
|
---|
210 |
|
---|
211 | #endif /* !VBOX_INCLUDED_GuestHost_clipboard_helper_h */
|
---|
212 |
|
---|