1 | /* $Id: clipboard-common.cpp 82527 2019-12-10 01:46:40Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard: Some helper function for converting between the various eol.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Includes contributions from François Revol
|
---|
8 | *
|
---|
9 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD
|
---|
21 |
|
---|
22 | #include <iprt/alloc.h>
|
---|
23 | #include <iprt/assert.h>
|
---|
24 | #include <iprt/semaphore.h>
|
---|
25 | #include <iprt/path.h>
|
---|
26 | #include <iprt/rand.h>
|
---|
27 |
|
---|
28 | #include <iprt/errcore.h>
|
---|
29 | #include <VBox/log.h>
|
---|
30 | #include <VBox/GuestHost/clipboard-helper.h>
|
---|
31 | #include <VBox/HostServices/VBoxClipboardSvc.h>
|
---|
32 |
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Allocates a new event payload.
|
---|
36 | *
|
---|
37 | * @returns VBox status code.
|
---|
38 | * @param uID Payload ID to set for this payload. Useful for consequtive payloads.
|
---|
39 | * @param pvData Data block to associate to this payload.
|
---|
40 | * @param cbData Size (in bytes) of data block to associate.
|
---|
41 | * @param ppPayload Where to store the allocated event payload on success.
|
---|
42 | */
|
---|
43 | int ShClPayloadAlloc(uint32_t uID, const void *pvData, uint32_t cbData,
|
---|
44 | PSHCLEVENTPAYLOAD *ppPayload)
|
---|
45 | {
|
---|
46 | AssertPtrReturn(pvData, VERR_INVALID_POINTER);
|
---|
47 | AssertReturn(cbData > 0, VERR_INVALID_PARAMETER);
|
---|
48 |
|
---|
49 | PSHCLEVENTPAYLOAD pPayload = (PSHCLEVENTPAYLOAD)RTMemAlloc(sizeof(SHCLEVENTPAYLOAD));
|
---|
50 | if (pPayload)
|
---|
51 | {
|
---|
52 | pPayload->pvData = RTMemDup(pvData, cbData);
|
---|
53 | if (pPayload->pvData)
|
---|
54 | {
|
---|
55 | pPayload->cbData = cbData;
|
---|
56 | pPayload->uID = uID;
|
---|
57 |
|
---|
58 | *ppPayload = pPayload;
|
---|
59 | return VINF_SUCCESS;
|
---|
60 | }
|
---|
61 |
|
---|
62 | RTMemFree(pPayload);
|
---|
63 | }
|
---|
64 | return VERR_NO_MEMORY;
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Frees an event payload.
|
---|
69 | *
|
---|
70 | * @returns VBox status code.
|
---|
71 | * @param pPayload Event payload to free.
|
---|
72 | */
|
---|
73 | void ShClPayloadFree(PSHCLEVENTPAYLOAD pPayload)
|
---|
74 | {
|
---|
75 | if (!pPayload)
|
---|
76 | return;
|
---|
77 |
|
---|
78 | if (pPayload->pvData)
|
---|
79 | {
|
---|
80 | Assert(pPayload->cbData);
|
---|
81 | RTMemFree(pPayload->pvData);
|
---|
82 | pPayload->pvData = NULL;
|
---|
83 | }
|
---|
84 |
|
---|
85 | pPayload->cbData = 0;
|
---|
86 | pPayload->uID = UINT32_MAX;
|
---|
87 |
|
---|
88 | RTMemFree(pPayload);
|
---|
89 | }
|
---|
90 |
|
---|
91 | #if 0 /* currently not used */
|
---|
92 | /**
|
---|
93 | * Creates (initializes) an event.
|
---|
94 | *
|
---|
95 | * @returns VBox status code.
|
---|
96 | * @param pEvent Event to initialize.
|
---|
97 | * @param idEvent Event ID to use.
|
---|
98 | */
|
---|
99 | static int shClEventInit(PSHCLEVENT pEvent, SHCLEVENTID idEvent)
|
---|
100 | {
|
---|
101 | AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
|
---|
102 |
|
---|
103 | LogFlowFunc(("Event %RU32\n", idEvent));
|
---|
104 |
|
---|
105 | int rc = RTSemEventMultiCreate(&pEvent->hEvtMulSem);
|
---|
106 | if (RT_SUCCESS(rc))
|
---|
107 | {
|
---|
108 | pEvent->idEvent = idEvent;
|
---|
109 | pEvent->pPayload = NULL;
|
---|
110 | }
|
---|
111 |
|
---|
112 | return rc;
|
---|
113 | }
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Destroys an event, but doesn't free the memory.
|
---|
118 | *
|
---|
119 | * @param pEvent Event to destroy.
|
---|
120 | */
|
---|
121 | static void shClEventTerm(PSHCLEVENT pEvent)
|
---|
122 | {
|
---|
123 | if (!pEvent)
|
---|
124 | return;
|
---|
125 |
|
---|
126 | LogFlowFunc(("Event %RU32\n", pEvent->idEvent));
|
---|
127 |
|
---|
128 | if (pEvent->hEvtMulSem != NIL_RTSEMEVENT)
|
---|
129 | {
|
---|
130 | RTSemEventMultiDestroy(pEvent->hEvtMulSem);
|
---|
131 | pEvent->hEvtMulSem = NIL_RTSEMEVENT;
|
---|
132 | }
|
---|
133 |
|
---|
134 | ShClPayloadFree(pEvent->pPayload);
|
---|
135 |
|
---|
136 | pEvent->idEvent = 0;
|
---|
137 | }
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Creates a new event source.
|
---|
141 | *
|
---|
142 | * @returns VBox status code.
|
---|
143 | * @param pSource Event source to create.
|
---|
144 | * @param uID ID to use for event source.
|
---|
145 | */
|
---|
146 | int ShClEventSourceCreate(PSHCLEVENTSOURCE pSource, SHCLEVENTSOURCEID uID)
|
---|
147 | {
|
---|
148 | LogFlowFunc(("pSource=%p, uID=%RU16\n", pSource, uID));
|
---|
149 | AssertPtrReturn(pSource, VERR_INVALID_POINTER);
|
---|
150 |
|
---|
151 | RTListInit(&pSource->lstEvents);
|
---|
152 |
|
---|
153 | pSource->uID = uID;
|
---|
154 | /* Choose a random event ID starting point. */
|
---|
155 | pSource->idNextEvent = RTRandU32Ex(1, VBOX_SHCL_MAX_EVENTS - 1);
|
---|
156 |
|
---|
157 | LogFlowFuncLeaveRC(VINF_SUCCESS);
|
---|
158 | return VINF_SUCCESS;
|
---|
159 | }
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Destroys an event source.
|
---|
163 | *
|
---|
164 | * @param pSource Event source to destroy.
|
---|
165 | */
|
---|
166 | void ShClEventSourceDestroy(PSHCLEVENTSOURCE pSource)
|
---|
167 | {
|
---|
168 | if (!pSource)
|
---|
169 | return;
|
---|
170 |
|
---|
171 | LogFlowFunc(("ID=%RU32\n", pSource->uID));
|
---|
172 |
|
---|
173 | ShClEventSourceReset(pSource);
|
---|
174 |
|
---|
175 | pSource->uID = UINT16_MAX;
|
---|
176 | pSource->idNextEvent = UINT32_MAX;
|
---|
177 | }
|
---|
178 |
|
---|
179 | /**
|
---|
180 | * Resets an event source.
|
---|
181 | *
|
---|
182 | * @param pSource Event source to reset.
|
---|
183 | */
|
---|
184 | void ShClEventSourceReset(PSHCLEVENTSOURCE pSource)
|
---|
185 | {
|
---|
186 | LogFlowFunc(("ID=%RU32\n", pSource->uID));
|
---|
187 |
|
---|
188 | PSHCLEVENT pEvIt;
|
---|
189 | PSHCLEVENT pEvItNext;
|
---|
190 | RTListForEachSafe(&pSource->lstEvents, pEvIt, pEvItNext, SHCLEVENT, Node)
|
---|
191 | {
|
---|
192 | RTListNodeRemove(&pEvIt->Node);
|
---|
193 |
|
---|
194 | shClEventTerm(pEvIt);
|
---|
195 |
|
---|
196 | RTMemFree(pEvIt);
|
---|
197 | pEvIt = NULL;
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * Returns a specific event of a event source.
|
---|
203 | *
|
---|
204 | * @returns Pointer to event if found, or NULL if not found.
|
---|
205 | * @param pSource Event source to get event from.
|
---|
206 | * @param uID Event ID to get.
|
---|
207 | */
|
---|
208 | DECLINLINE(PSHCLEVENT) shclEventGet(PSHCLEVENTSOURCE pSource, SHCLEVENTID idEvent)
|
---|
209 | {
|
---|
210 | PSHCLEVENT pEvent;
|
---|
211 | RTListForEach(&pSource->lstEvents, pEvent, SHCLEVENT, Node)
|
---|
212 | {
|
---|
213 | if (pEvent->idEvent == idEvent)
|
---|
214 | return pEvent;
|
---|
215 | }
|
---|
216 |
|
---|
217 | return NULL;
|
---|
218 | }
|
---|
219 |
|
---|
220 | /**
|
---|
221 | * Generates a new event ID for a specific event source.
|
---|
222 | *
|
---|
223 | * @returns New event ID generated, or 0 on error.
|
---|
224 | * @param pSource Event source to generate event for.
|
---|
225 | * @deprecated as this does not deal with duplicates.
|
---|
226 | */
|
---|
227 | SHCLEVENTID ShClEventIDGenerate(PSHCLEVENTSOURCE pSource)
|
---|
228 | {
|
---|
229 | AssertPtrReturn(pSource, 0);
|
---|
230 |
|
---|
231 | SHCLEVENTID idEvent = ++pSource->idNextEvent;
|
---|
232 | if (idEvent >= VBOX_SHCL_MAX_EVENTS)
|
---|
233 | pSource->idNextEvent = idEvent = 1; /* zero == error, remember! */
|
---|
234 |
|
---|
235 | LogFlowFunc(("uSource=%RU16: New event: %RU32\n", pSource->uID, idEvent));
|
---|
236 | return idEvent;
|
---|
237 | }
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Generates a new event ID for a specific event source and registers it.
|
---|
241 | *
|
---|
242 | * @returns New event ID generated, or 0 on error.
|
---|
243 | * @param pSource Event source to generate event for.
|
---|
244 | */
|
---|
245 | SHCLEVENTID ShClEventIdGenerateAndRegister(PSHCLEVENTSOURCE pSource)
|
---|
246 | {
|
---|
247 | AssertPtrReturn(pSource, 0);
|
---|
248 |
|
---|
249 | /*
|
---|
250 | * Allocate an event.
|
---|
251 | */
|
---|
252 | PSHCLEVENT pEvent = (PSHCLEVENT)RTMemAllocZ(sizeof(SHCLEVENT));
|
---|
253 | AssertReturn(pEvent, 0);
|
---|
254 | int rc = RTSemEventMultiCreate(&pEvent->hEvtMulSem);
|
---|
255 | AssertRCReturnStmt(rc, RTMemFree(pEvent), 0);
|
---|
256 |
|
---|
257 | /*
|
---|
258 | * Allocate an unique event ID.
|
---|
259 | */
|
---|
260 | for (uint32_t cTries = 0;; cTries++)
|
---|
261 | {
|
---|
262 | SHCLEVENTID idEvent = ++pSource->idNextEvent;
|
---|
263 | if (idEvent < VBOX_SHCL_MAX_EVENTS)
|
---|
264 | { /* likely */ }
|
---|
265 | else
|
---|
266 | pSource->idNextEvent = idEvent = 1; /* zero == error, remember! */
|
---|
267 |
|
---|
268 | if (shclEventGet(pSource, idEvent) == NULL)
|
---|
269 | {
|
---|
270 |
|
---|
271 | pEvent->idEvent = idEvent;
|
---|
272 | RTListAppend(&pSource->lstEvents, &pEvent->Node);
|
---|
273 |
|
---|
274 | LogFlowFunc(("uSource=%RU16: New event: %#x\n", pSource->uID, idEvent));
|
---|
275 | return idEvent;
|
---|
276 | }
|
---|
277 |
|
---|
278 | AssertBreak(cTries < 4096);
|
---|
279 | }
|
---|
280 |
|
---|
281 | RTMemFree(pEvent);
|
---|
282 | return 0;
|
---|
283 | }
|
---|
284 |
|
---|
285 | /**
|
---|
286 | * Returns the last (newest) event ID which has been registered for an event source.
|
---|
287 | *
|
---|
288 | * @returns Last registered event ID, or 0 if not found.
|
---|
289 | * @param pSource Event source to get last registered event from.
|
---|
290 | */
|
---|
291 | SHCLEVENTID ShClEventGetLast(PSHCLEVENTSOURCE pSource)
|
---|
292 | {
|
---|
293 | AssertPtrReturn(pSource, 0);
|
---|
294 | PSHCLEVENT pEvent = RTListGetLast(&pSource->lstEvents, SHCLEVENT, Node);
|
---|
295 | if (pEvent)
|
---|
296 | return pEvent->idEvent;
|
---|
297 |
|
---|
298 | return 0;
|
---|
299 | }
|
---|
300 |
|
---|
301 | /**
|
---|
302 | * Detaches a payload from an event, internal version.
|
---|
303 | *
|
---|
304 | * @param pEvent Event to detach payload for.
|
---|
305 | */
|
---|
306 | static void shclEventPayloadDetachInternal(PSHCLEVENT pEvent)
|
---|
307 | {
|
---|
308 | /** @todo r=bird: This should return pPayload. It should also not need
|
---|
309 | * assert the validity of pEvent in non-strict builds, given that this
|
---|
310 | * is an static + internal function, that's a complete waste of time. */
|
---|
311 | AssertPtrReturnVoid(pEvent);
|
---|
312 |
|
---|
313 | pEvent->pPayload = NULL;
|
---|
314 | }
|
---|
315 |
|
---|
316 | #if 0 /** @todo fix later */
|
---|
317 | /**
|
---|
318 | * Registers an event.
|
---|
319 | *
|
---|
320 | * @returns VBox status code.
|
---|
321 | * @param pSource Event source to register event for.
|
---|
322 | * @param uID Event ID to register.
|
---|
323 | */
|
---|
324 | int ShClEventRegister(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID)
|
---|
325 | {
|
---|
326 | AssertPtrReturn(pSource, VERR_INVALID_POINTER);
|
---|
327 |
|
---|
328 | int rc;
|
---|
329 |
|
---|
330 | LogFlowFunc(("uSource=%RU16, uEvent=%RU32\n", pSource->uID, uID));
|
---|
331 |
|
---|
332 | if (shclEventGet(pSource, uID) == NULL)
|
---|
333 | {
|
---|
334 | PSHCLEVENT pEvent = (PSHCLEVENT)RTMemAllocZ(sizeof(SHCLEVENT));
|
---|
335 | if (pEvent)
|
---|
336 | {
|
---|
337 | rc = shClEventInit(pEvent, uID);
|
---|
338 | if (RT_SUCCESS(rc))
|
---|
339 | {
|
---|
340 | RTListAppend(&pSource->lstEvents, &pEvent->Node);
|
---|
341 |
|
---|
342 | LogFlowFunc(("Event %RU32\n", uID));
|
---|
343 | }
|
---|
344 | }
|
---|
345 | else
|
---|
346 | rc = VERR_NO_MEMORY;
|
---|
347 | }
|
---|
348 | else
|
---|
349 | rc = VERR_ALREADY_EXISTS;
|
---|
350 |
|
---|
351 | #ifdef DEBUG_andy
|
---|
352 | AssertRC(rc);
|
---|
353 | #endif
|
---|
354 |
|
---|
355 | LogFlowFuncLeaveRC(rc);
|
---|
356 | return rc;
|
---|
357 | }
|
---|
358 | #endif /* later */
|
---|
359 |
|
---|
360 | /**
|
---|
361 | * Unregisters an event.
|
---|
362 | *
|
---|
363 | * @returns VBox status code.
|
---|
364 | * @param pSource Event source to unregister event for.
|
---|
365 | * @param uID Event ID to unregister.
|
---|
366 | */
|
---|
367 | int ShClEventUnregister(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID)
|
---|
368 | {
|
---|
369 | AssertPtrReturn(pSource, VERR_INVALID_POINTER);
|
---|
370 |
|
---|
371 | int rc;
|
---|
372 |
|
---|
373 | LogFlowFunc(("uSource=%RU16, uEvent=%RU32\n", pSource->uID, uID));
|
---|
374 |
|
---|
375 | PSHCLEVENT pEvent = shclEventGet(pSource, uID);
|
---|
376 | if (pEvent)
|
---|
377 | {
|
---|
378 | LogFlowFunc(("Event %RU32\n", pEvent->idEvent));
|
---|
379 |
|
---|
380 | RTListNodeRemove(&pEvent->Node);
|
---|
381 |
|
---|
382 | shClEventTerm(pEvent);
|
---|
383 |
|
---|
384 | RTMemFree(pEvent);
|
---|
385 | pEvent = NULL;
|
---|
386 |
|
---|
387 | rc = VINF_SUCCESS;
|
---|
388 | }
|
---|
389 | else
|
---|
390 | rc = VERR_NOT_FOUND;
|
---|
391 |
|
---|
392 | LogFlowFuncLeaveRC(rc);
|
---|
393 | return rc;
|
---|
394 | }
|
---|
395 |
|
---|
396 | /**
|
---|
397 | * Waits for an event to get signalled.
|
---|
398 | *
|
---|
399 | * @returns VBox status code.
|
---|
400 | * @param pSource Event source that contains the event to wait for.
|
---|
401 | * @param uID Event ID to wait for.
|
---|
402 | * @param uTimeoutMs Timeout (in ms) to wait.
|
---|
403 | * @param ppPayload Where to store the (allocated) event payload on success. Needs to be free'd with
|
---|
404 | * SharedClipboardPayloadFree(). Optional.
|
---|
405 | */
|
---|
406 | int ShClEventWait(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID, RTMSINTERVAL uTimeoutMs,
|
---|
407 | PSHCLEVENTPAYLOAD* ppPayload)
|
---|
408 | {
|
---|
409 | AssertPtrReturn(pSource, VERR_INVALID_POINTER);
|
---|
410 | /** ppPayload is optional. */
|
---|
411 |
|
---|
412 | LogFlowFuncEnter();
|
---|
413 |
|
---|
414 | int rc;
|
---|
415 |
|
---|
416 | PSHCLEVENT pEvent = shclEventGet(pSource, uID);
|
---|
417 | if (pEvent)
|
---|
418 | {
|
---|
419 | rc = RTSemEventMultiWait(pEvent->hEvtMulSem, uTimeoutMs);
|
---|
420 | if (RT_SUCCESS(rc))
|
---|
421 | {
|
---|
422 | if (ppPayload)
|
---|
423 | {
|
---|
424 | *ppPayload = pEvent->pPayload;
|
---|
425 |
|
---|
426 | /* Make sure to detach payload here, as the caller now owns the data. */
|
---|
427 | shclEventPayloadDetachInternal(pEvent);
|
---|
428 | }
|
---|
429 | }
|
---|
430 | }
|
---|
431 | else
|
---|
432 | rc = VERR_NOT_FOUND;
|
---|
433 |
|
---|
434 | LogFlowFuncLeaveRC(rc);
|
---|
435 | return rc;
|
---|
436 | }
|
---|
437 |
|
---|
438 | /**
|
---|
439 | * Signals an event.
|
---|
440 | *
|
---|
441 | * @returns VBox status code.
|
---|
442 | * @param pSource Event source of event to signal.
|
---|
443 | * @param uID Event ID to signal.
|
---|
444 | * @param pPayload Event payload to associate. Takes ownership. Optional.
|
---|
445 | */
|
---|
446 | int ShClEventSignal(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID,
|
---|
447 | PSHCLEVENTPAYLOAD pPayload)
|
---|
448 | {
|
---|
449 | AssertPtrReturn(pSource, VERR_INVALID_POINTER);
|
---|
450 |
|
---|
451 | int rc;
|
---|
452 |
|
---|
453 | LogFlowFunc(("uSource=%RU16, uEvent=%RU32\n", pSource->uID, uID));
|
---|
454 |
|
---|
455 | PSHCLEVENT pEvent = shclEventGet(pSource, uID);
|
---|
456 | if (pEvent)
|
---|
457 | {
|
---|
458 | Assert(pEvent->pPayload == NULL);
|
---|
459 |
|
---|
460 | pEvent->pPayload = pPayload;
|
---|
461 |
|
---|
462 | rc = RTSemEventMultiSignal(pEvent->hEvtMulSem);
|
---|
463 | }
|
---|
464 | else
|
---|
465 | rc = VERR_NOT_FOUND;
|
---|
466 |
|
---|
467 | LogFlowFuncLeaveRC(rc);
|
---|
468 | return rc;
|
---|
469 | }
|
---|
470 |
|
---|
471 | /**
|
---|
472 | * Detaches a payload from an event.
|
---|
473 | *
|
---|
474 | * @returns VBox status code.
|
---|
475 | * @param pSource Event source of event to detach payload for.
|
---|
476 | * @param uID Event ID to detach payload for.
|
---|
477 | */
|
---|
478 | void ShClEventPayloadDetach(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID)
|
---|
479 | {
|
---|
480 | /** @todo r=bird: This API is not needed, it either is a no-op as it
|
---|
481 | * replicates work done by ShClEventWait or it leaks the payload as
|
---|
482 | * ShClEventWait is the only way to get it as far as I can tell. */
|
---|
483 |
|
---|
484 | AssertPtrReturnVoid(pSource);
|
---|
485 |
|
---|
486 | LogFlowFunc(("uSource=%RU16, uEvent=%RU32\n", pSource->uID, uID));
|
---|
487 |
|
---|
488 | PSHCLEVENT pEvent = shclEventGet(pSource, uID);
|
---|
489 | if (pEvent)
|
---|
490 | {
|
---|
491 | shclEventPayloadDetachInternal(pEvent);
|
---|
492 | }
|
---|
493 | #ifdef DEBUG_andy
|
---|
494 | else
|
---|
495 | AssertMsgFailed(("uSource=%RU16, uEvent=%RU32\n", pSource->uID, uID));
|
---|
496 | #endif
|
---|
497 | }
|
---|
498 |
|
---|
499 | /** @todo Delinuxify the code (*Lin* -> *Host*); use AssertLogRel*. */
|
---|
500 |
|
---|
501 | int ShClUtf16GetWinSize(PCRTUTF16 pcwszSrc, size_t cwSrc, size_t *pcwDest)
|
---|
502 | {
|
---|
503 | size_t cwDest, i;
|
---|
504 |
|
---|
505 | LogFlowFunc(("pcwszSrc=%.*ls, cwSrc=%u\n", cwSrc, pcwszSrc, cwSrc));
|
---|
506 | AssertLogRelMsgReturn(pcwszSrc != NULL, ("vboxClipboardUtf16GetWinSize: received a null Utf16 string, returning VERR_INVALID_PARAMETER\n"), VERR_INVALID_PARAMETER);
|
---|
507 | if (cwSrc == 0)
|
---|
508 | {
|
---|
509 | *pcwDest = 0;
|
---|
510 | LogFlowFunc(("empty source string, returning\n"));
|
---|
511 | return VINF_SUCCESS;
|
---|
512 | }
|
---|
513 | /** @todo convert the remainder of the Assert stuff to AssertLogRel. */
|
---|
514 | /* We only take little endian Utf16 */
|
---|
515 | if (pcwszSrc[0] == VBOX_SHCL_UTF16BEMARKER)
|
---|
516 | {
|
---|
517 | LogRel(("Shared Clipboard: vboxClipboardUtf16GetWinSize: received a big endian Utf16 string, returning VERR_INVALID_PARAMETER\n"));
|
---|
518 | AssertReturn(pcwszSrc[0] != VBOX_SHCL_UTF16BEMARKER, VERR_INVALID_PARAMETER);
|
---|
519 | }
|
---|
520 | cwDest = 0;
|
---|
521 | /* Calculate the size of the destination text string. */
|
---|
522 | /* Is this Utf16 or Utf16-LE? */
|
---|
523 | for (i = (pcwszSrc[0] == VBOX_SHCL_UTF16LEMARKER ? 1 : 0); i < cwSrc; ++i, ++cwDest)
|
---|
524 | {
|
---|
525 | /* Check for a single line feed */
|
---|
526 | if (pcwszSrc[i] == VBOX_SHCL_LINEFEED)
|
---|
527 | ++cwDest;
|
---|
528 | #ifdef RT_OS_DARWIN
|
---|
529 | /* Check for a single carriage return (MacOS) */
|
---|
530 | if (pcwszSrc[i] == VBOX_SHCL_CARRIAGERETURN)
|
---|
531 | ++cwDest;
|
---|
532 | #endif
|
---|
533 | if (pcwszSrc[i] == 0)
|
---|
534 | {
|
---|
535 | /* Don't count this, as we do so below. */
|
---|
536 | break;
|
---|
537 | }
|
---|
538 | }
|
---|
539 | /* Count the terminating null byte. */
|
---|
540 | ++cwDest;
|
---|
541 | LogFlowFunc(("returning VINF_SUCCESS, %d 16bit words\n", cwDest));
|
---|
542 | *pcwDest = cwDest;
|
---|
543 | return VINF_SUCCESS;
|
---|
544 | }
|
---|
545 |
|
---|
546 | int ShClUtf16LinToWin(PCRTUTF16 pcwszSrc, size_t cwSrc, PRTUTF16 pu16Dest, size_t cwDest)
|
---|
547 | {
|
---|
548 | size_t i, j;
|
---|
549 | LogFlowFunc(("pcwszSrc=%.*ls, cwSrc=%u\n", cwSrc, pcwszSrc, cwSrc));
|
---|
550 | if (!VALID_PTR(pcwszSrc) || !VALID_PTR(pu16Dest))
|
---|
551 | {
|
---|
552 | LogRel(("Shared Clipboard: vboxClipboardUtf16LinToWin: received an invalid pointer, returning VERR_INVALID_PARAMETER\n"));
|
---|
553 | AssertReturn(VALID_PTR(pcwszSrc) && VALID_PTR(pu16Dest), VERR_INVALID_PARAMETER);
|
---|
554 | }
|
---|
555 | if (cwSrc == 0)
|
---|
556 | {
|
---|
557 | if (cwDest == 0)
|
---|
558 | {
|
---|
559 | LogFlowFunc(("returning VERR_BUFFER_OVERFLOW\n"));
|
---|
560 | return VERR_BUFFER_OVERFLOW;
|
---|
561 | }
|
---|
562 | pu16Dest[0] = 0;
|
---|
563 | LogFlowFunc(("empty source string, returning\n"));
|
---|
564 | return VINF_SUCCESS;
|
---|
565 | }
|
---|
566 | /* We only take little endian Utf16 */
|
---|
567 | if (pcwszSrc[0] == VBOX_SHCL_UTF16BEMARKER)
|
---|
568 | {
|
---|
569 | LogRel(("Shared Clipboard: vboxClipboardUtf16LinToWin: received a big endian Utf16 string, returning VERR_INVALID_PARAMETER\n"));
|
---|
570 | AssertReturn(pcwszSrc[0] != VBOX_SHCL_UTF16BEMARKER, VERR_INVALID_PARAMETER);
|
---|
571 | }
|
---|
572 | /* Don't copy the endian marker. */
|
---|
573 | for (i = (pcwszSrc[0] == VBOX_SHCL_UTF16LEMARKER ? 1 : 0), j = 0; i < cwSrc; ++i, ++j)
|
---|
574 | {
|
---|
575 | /* Don't copy the null byte, as we add it below. */
|
---|
576 | if (pcwszSrc[i] == 0)
|
---|
577 | break;
|
---|
578 | if (j == cwDest)
|
---|
579 | {
|
---|
580 | LogFlowFunc(("returning VERR_BUFFER_OVERFLOW\n"));
|
---|
581 | return VERR_BUFFER_OVERFLOW;
|
---|
582 | }
|
---|
583 | if (pcwszSrc[i] == VBOX_SHCL_LINEFEED)
|
---|
584 | {
|
---|
585 | pu16Dest[j] = VBOX_SHCL_CARRIAGERETURN;
|
---|
586 | ++j;
|
---|
587 | if (j == cwDest)
|
---|
588 | {
|
---|
589 | LogFlowFunc(("returning VERR_BUFFER_OVERFLOW\n"));
|
---|
590 | return VERR_BUFFER_OVERFLOW;
|
---|
591 | }
|
---|
592 | }
|
---|
593 | #ifdef RT_OS_DARWIN
|
---|
594 | /* Check for a single carriage return (MacOS) */
|
---|
595 | else if (pcwszSrc[i] == VBOX_SHCL_CARRIAGERETURN)
|
---|
596 | {
|
---|
597 | /* set cr */
|
---|
598 | pu16Dest[j] = VBOX_SHCL_CARRIAGERETURN;
|
---|
599 | ++j;
|
---|
600 | if (j == cwDest)
|
---|
601 | {
|
---|
602 | LogFlowFunc(("returning VERR_BUFFER_OVERFLOW\n"));
|
---|
603 | return VERR_BUFFER_OVERFLOW;
|
---|
604 | }
|
---|
605 | /* add the lf */
|
---|
606 | pu16Dest[j] = VBOX_SHCL_LINEFEED;
|
---|
607 | continue;
|
---|
608 | }
|
---|
609 | #endif
|
---|
610 | pu16Dest[j] = pcwszSrc[i];
|
---|
611 | }
|
---|
612 | /* Add the trailing null. */
|
---|
613 | if (j == cwDest)
|
---|
614 | {
|
---|
615 | LogFlowFunc(("returning VERR_BUFFER_OVERFLOW\n"));
|
---|
616 | return VERR_BUFFER_OVERFLOW;
|
---|
617 | }
|
---|
618 | pu16Dest[j] = 0;
|
---|
619 | LogFlowFunc(("rc=VINF_SUCCESS, pu16Dest=%ls\n", pu16Dest));
|
---|
620 | return VINF_SUCCESS;
|
---|
621 | }
|
---|
622 |
|
---|
623 | int ShClUtf16GetLinSize(PCRTUTF16 pcwszSrc, size_t cwSrc, size_t *pcwDest)
|
---|
624 | {
|
---|
625 | size_t cwDest;
|
---|
626 |
|
---|
627 | LogFlowFunc(("pcwszSrc=%.*ls, cwSrc=%u\n", cwSrc, pcwszSrc, cwSrc));
|
---|
628 | if (!VALID_PTR(pcwszSrc))
|
---|
629 | {
|
---|
630 | LogRel(("Shared Clipboard: vboxClipboardUtf16GetLinSize: received an invalid Utf16 string, returning VERR_INVALID_PARAMETER\n"));
|
---|
631 | AssertReturn(VALID_PTR(pcwszSrc), VERR_INVALID_PARAMETER);
|
---|
632 | }
|
---|
633 | if (cwSrc == 0)
|
---|
634 | {
|
---|
635 | LogFlowFunc(("empty source string, returning VINF_SUCCESS\n"));
|
---|
636 | *pcwDest = 0;
|
---|
637 | return VINF_SUCCESS;
|
---|
638 | }
|
---|
639 | /* We only take little endian Utf16 */
|
---|
640 | if (pcwszSrc[0] == VBOX_SHCL_UTF16BEMARKER)
|
---|
641 | {
|
---|
642 | LogRel(("Shared Clipboard: vboxClipboardUtf16GetLinSize: received a big endian Utf16 string, returning VERR_INVALID_PARAMETER\n"));
|
---|
643 | AssertReturn(pcwszSrc[0] != VBOX_SHCL_UTF16BEMARKER, VERR_INVALID_PARAMETER);
|
---|
644 | }
|
---|
645 | /* Calculate the size of the destination text string. */
|
---|
646 | /* Is this Utf16 or Utf16-LE? */
|
---|
647 | if (pcwszSrc[0] == VBOX_SHCL_UTF16LEMARKER)
|
---|
648 | cwDest = 0;
|
---|
649 | else
|
---|
650 | cwDest = 1;
|
---|
651 | for (size_t i = 0; i < cwSrc; ++i, ++cwDest)
|
---|
652 | {
|
---|
653 | if ( (i + 1 < cwSrc)
|
---|
654 | && (pcwszSrc[i] == VBOX_SHCL_CARRIAGERETURN)
|
---|
655 | && (pcwszSrc[i + 1] == VBOX_SHCL_LINEFEED))
|
---|
656 | {
|
---|
657 | ++i;
|
---|
658 | }
|
---|
659 | if (pcwszSrc[i] == 0)
|
---|
660 | {
|
---|
661 | break;
|
---|
662 | }
|
---|
663 | }
|
---|
664 | /* Terminating zero */
|
---|
665 | ++cwDest;
|
---|
666 | LogFlowFunc(("returning %d\n", cwDest));
|
---|
667 | *pcwDest = cwDest;
|
---|
668 | return VINF_SUCCESS;
|
---|
669 | }
|
---|
670 |
|
---|
671 | int ShClUtf16WinToLin(PCRTUTF16 pcwszSrc, size_t cwSrc, PRTUTF16 pu16Dest, size_t cwDest)
|
---|
672 | {
|
---|
673 | size_t cwDestPos;
|
---|
674 |
|
---|
675 | LogFlowFunc(("pcwszSrc=%.*ls, cwSrc=%u, pu16Dest=%p, cwDest=%u\n",
|
---|
676 | cwSrc, pcwszSrc, cwSrc, pu16Dest, cwDest));
|
---|
677 | /* A buffer of size 0 may not be an error, but it is not a good idea either. */
|
---|
678 | Assert(cwDest > 0);
|
---|
679 | if (!VALID_PTR(pcwszSrc) || !VALID_PTR(pu16Dest))
|
---|
680 | {
|
---|
681 | LogRel(("Shared Clipboard: vboxClipboardUtf16WinToLin: received an invalid pointer, returning VERR_INVALID_PARAMETER\n"));
|
---|
682 | AssertReturn(VALID_PTR(pcwszSrc) && VALID_PTR(pu16Dest), VERR_INVALID_PARAMETER);
|
---|
683 | }
|
---|
684 | /* We only take little endian Utf16 */
|
---|
685 | if (pcwszSrc[0] == VBOX_SHCL_UTF16BEMARKER)
|
---|
686 | {
|
---|
687 | LogRel(("Shared Clipboard: vboxClipboardUtf16WinToLin: received a big endian Utf16 string, returning VERR_INVALID_PARAMETER\n"));
|
---|
688 | AssertMsgFailedReturn(("received a big endian string\n"), VERR_INVALID_PARAMETER);
|
---|
689 | }
|
---|
690 | if (cwDest == 0)
|
---|
691 | {
|
---|
692 | LogFlowFunc(("returning VERR_BUFFER_OVERFLOW\n"));
|
---|
693 | return VERR_BUFFER_OVERFLOW;
|
---|
694 | }
|
---|
695 | if (cwSrc == 0)
|
---|
696 | {
|
---|
697 | pu16Dest[0] = 0;
|
---|
698 | LogFlowFunc(("received empty string. Returning VINF_SUCCESS\n"));
|
---|
699 | return VINF_SUCCESS;
|
---|
700 | }
|
---|
701 | /* Prepend the Utf16 byte order marker if it is missing. */
|
---|
702 | if (pcwszSrc[0] == VBOX_SHCL_UTF16LEMARKER)
|
---|
703 | {
|
---|
704 | cwDestPos = 0;
|
---|
705 | }
|
---|
706 | else
|
---|
707 | {
|
---|
708 | pu16Dest[0] = VBOX_SHCL_UTF16LEMARKER;
|
---|
709 | cwDestPos = 1;
|
---|
710 | }
|
---|
711 | for (size_t i = 0; i < cwSrc; ++i, ++cwDestPos)
|
---|
712 | {
|
---|
713 | if (pcwszSrc[i] == 0)
|
---|
714 | {
|
---|
715 | break;
|
---|
716 | }
|
---|
717 | if (cwDestPos == cwDest)
|
---|
718 | {
|
---|
719 | LogFlowFunc(("returning VERR_BUFFER_OVERFLOW\n"));
|
---|
720 | return VERR_BUFFER_OVERFLOW;
|
---|
721 | }
|
---|
722 | if ( (i + 1 < cwSrc)
|
---|
723 | && (pcwszSrc[i] == VBOX_SHCL_CARRIAGERETURN)
|
---|
724 | && (pcwszSrc[i + 1] == VBOX_SHCL_LINEFEED))
|
---|
725 | {
|
---|
726 | ++i;
|
---|
727 | }
|
---|
728 | pu16Dest[cwDestPos] = pcwszSrc[i];
|
---|
729 | }
|
---|
730 | /* Terminating zero */
|
---|
731 | if (cwDestPos == cwDest)
|
---|
732 | {
|
---|
733 | LogFlowFunc(("returning VERR_BUFFER_OVERFLOW\n"));
|
---|
734 | return VERR_BUFFER_OVERFLOW;
|
---|
735 | }
|
---|
736 | pu16Dest[cwDestPos] = 0;
|
---|
737 | LogFlowFunc(("set string %ls. Returning\n", pu16Dest + 1));
|
---|
738 | return VINF_SUCCESS;
|
---|
739 | }
|
---|
740 |
|
---|
741 | int ShClDibToBmp(const void *pvSrc, size_t cbSrc, void **ppvDest, size_t *pcbDest)
|
---|
742 | {
|
---|
743 | size_t cb = sizeof(BMFILEHEADER) + cbSrc;
|
---|
744 | PBMFILEHEADER pFileHeader = NULL;
|
---|
745 | void *pvDest = NULL;
|
---|
746 | size_t offPixel = 0;
|
---|
747 |
|
---|
748 | AssertPtrReturn(pvSrc, VERR_INVALID_PARAMETER);
|
---|
749 | AssertPtrReturn(ppvDest, VERR_INVALID_PARAMETER);
|
---|
750 | AssertPtrReturn(pcbDest, VERR_INVALID_PARAMETER);
|
---|
751 |
|
---|
752 | PBMINFOHEADER pBitmapInfoHeader = (PBMINFOHEADER)pvSrc;
|
---|
753 | /** @todo Support all the many versions of the DIB headers. */
|
---|
754 | if ( cbSrc < sizeof(BMINFOHEADER)
|
---|
755 | || RT_LE2H_U32(pBitmapInfoHeader->uSize) < sizeof(BMINFOHEADER)
|
---|
756 | || RT_LE2H_U32(pBitmapInfoHeader->uSize) != sizeof(BMINFOHEADER))
|
---|
757 | {
|
---|
758 | Log(("vboxClipboardDibToBmp: invalid or unsupported bitmap data\n"));
|
---|
759 | return VERR_INVALID_PARAMETER;
|
---|
760 | }
|
---|
761 |
|
---|
762 | offPixel = sizeof(BMFILEHEADER)
|
---|
763 | + RT_LE2H_U32(pBitmapInfoHeader->uSize)
|
---|
764 | + RT_LE2H_U32(pBitmapInfoHeader->uClrUsed) * sizeof(uint32_t);
|
---|
765 | if (cbSrc < offPixel)
|
---|
766 | {
|
---|
767 | Log(("vboxClipboardDibToBmp: invalid bitmap data\n"));
|
---|
768 | return VERR_INVALID_PARAMETER;
|
---|
769 | }
|
---|
770 |
|
---|
771 | pvDest = RTMemAlloc(cb);
|
---|
772 | if (!pvDest)
|
---|
773 | {
|
---|
774 | Log(("writeToPasteboard: cannot allocate memory for bitmap\n"));
|
---|
775 | return VERR_NO_MEMORY;
|
---|
776 | }
|
---|
777 |
|
---|
778 | pFileHeader = (PBMFILEHEADER)pvDest;
|
---|
779 | pFileHeader->uType = BITMAPHEADERMAGIC;
|
---|
780 | pFileHeader->uSize = (uint32_t)RT_H2LE_U32(cb);
|
---|
781 | pFileHeader->uReserved1 = pFileHeader->uReserved2 = 0;
|
---|
782 | pFileHeader->uOffBits = (uint32_t)RT_H2LE_U32(offPixel);
|
---|
783 | memcpy((uint8_t *)pvDest + sizeof(BMFILEHEADER), pvSrc, cbSrc);
|
---|
784 | *ppvDest = pvDest;
|
---|
785 | *pcbDest = cb;
|
---|
786 | return VINF_SUCCESS;
|
---|
787 | }
|
---|
788 |
|
---|
789 | int ShClBmpGetDib(const void *pvSrc, size_t cbSrc, const void **ppvDest, size_t *pcbDest)
|
---|
790 | {
|
---|
791 | AssertPtrReturn(pvSrc, VERR_INVALID_PARAMETER);
|
---|
792 | AssertPtrReturn(ppvDest, VERR_INVALID_PARAMETER);
|
---|
793 | AssertPtrReturn(pcbDest, VERR_INVALID_PARAMETER);
|
---|
794 |
|
---|
795 | PBMFILEHEADER pFileHeader = (PBMFILEHEADER)pvSrc;
|
---|
796 | if ( cbSrc < sizeof(BMFILEHEADER)
|
---|
797 | || pFileHeader->uType != BITMAPHEADERMAGIC
|
---|
798 | || RT_LE2H_U32(pFileHeader->uSize) != cbSrc)
|
---|
799 | {
|
---|
800 | Log(("vboxClipboardBmpGetDib: invalid bitmap data\n"));
|
---|
801 | return VERR_INVALID_PARAMETER;
|
---|
802 | }
|
---|
803 |
|
---|
804 | *ppvDest = ((uint8_t *)pvSrc) + sizeof(BMFILEHEADER);
|
---|
805 | *pcbDest = cbSrc - sizeof(BMFILEHEADER);
|
---|
806 | return VINF_SUCCESS;
|
---|
807 | }
|
---|
808 |
|
---|
809 | #ifdef LOG_ENABLED
|
---|
810 | int ShClDbgDumpHtml(const char *pcszSrc, size_t cbSrc)
|
---|
811 | {
|
---|
812 | size_t cchIgnored = 0;
|
---|
813 | int rc = RTStrNLenEx(pcszSrc, cbSrc, &cchIgnored);
|
---|
814 | if (RT_SUCCESS(rc))
|
---|
815 | {
|
---|
816 | char *pszBuf = (char *)RTMemAllocZ(cbSrc + 1);
|
---|
817 | if (pszBuf)
|
---|
818 | {
|
---|
819 | rc = RTStrCopy(pszBuf, cbSrc + 1, (const char *)pcszSrc);
|
---|
820 | if (RT_SUCCESS(rc))
|
---|
821 | {
|
---|
822 | for (size_t i = 0; i < cbSrc; ++i)
|
---|
823 | if (pszBuf[i] == '\n' || pszBuf[i] == '\r')
|
---|
824 | pszBuf[i] = ' ';
|
---|
825 | }
|
---|
826 | else
|
---|
827 | LogFunc(("Error in copying string\n"));
|
---|
828 | LogFunc(("Removed \\r\\n: %s\n", pszBuf));
|
---|
829 | RTMemFree(pszBuf);
|
---|
830 | }
|
---|
831 | else
|
---|
832 | rc = VERR_NO_MEMORY;
|
---|
833 | }
|
---|
834 |
|
---|
835 | return rc;
|
---|
836 | }
|
---|
837 |
|
---|
838 | void ShClDbgDumpData(const void *pv, size_t cb, SHCLFORMAT uFormat)
|
---|
839 | {
|
---|
840 | if (uFormat & VBOX_SHCL_FMT_UNICODETEXT)
|
---|
841 | {
|
---|
842 | LogFunc(("VBOX_SHCL_FMT_UNICODETEXT:\n"));
|
---|
843 | if (pv && cb)
|
---|
844 | LogFunc(("%ls\n", pv));
|
---|
845 | else
|
---|
846 | LogFunc(("%p %zu\n", pv, cb));
|
---|
847 | }
|
---|
848 | else if (uFormat & VBOX_SHCL_FMT_BITMAP)
|
---|
849 | LogFunc(("VBOX_SHCL_FMT_BITMAP\n"));
|
---|
850 | else if (uFormat & VBOX_SHCL_FMT_HTML)
|
---|
851 | {
|
---|
852 | LogFunc(("VBOX_SHCL_FMT_HTML:\n"));
|
---|
853 | if (pv && cb)
|
---|
854 | {
|
---|
855 | LogFunc(("%s\n", pv));
|
---|
856 |
|
---|
857 | //size_t cb = RTStrNLen(pv, );
|
---|
858 | char *pszBuf = (char *)RTMemAllocZ(cb + 1);
|
---|
859 | RTStrCopy(pszBuf, cb + 1, (const char *)pv);
|
---|
860 | for (size_t off = 0; off < cb; ++off)
|
---|
861 | {
|
---|
862 | if (pszBuf[off] == '\n' || pszBuf[off] == '\r')
|
---|
863 | pszBuf[off] = ' ';
|
---|
864 | }
|
---|
865 |
|
---|
866 | LogFunc(("%s\n", pszBuf));
|
---|
867 | RTMemFree(pszBuf);
|
---|
868 | }
|
---|
869 | else
|
---|
870 | LogFunc(("%p %zu\n", pv, cb));
|
---|
871 | }
|
---|
872 | else
|
---|
873 | LogFunc(("Invalid format %02X\n", uFormat));
|
---|
874 | }
|
---|
875 | #endif /* LOG_ENABLED */
|
---|
876 |
|
---|
877 | /**
|
---|
878 | * Translates a Shared Clipboard host function number to a string.
|
---|
879 | *
|
---|
880 | * @returns Function ID string name.
|
---|
881 | * @param uFn The function to translate.
|
---|
882 | */
|
---|
883 | const char *ShClHostFunctionToStr(uint32_t uFn)
|
---|
884 | {
|
---|
885 | switch (uFn)
|
---|
886 | {
|
---|
887 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_SET_MODE);
|
---|
888 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_SET_TRANSFER_MODE);
|
---|
889 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_SET_HEADLESS);
|
---|
890 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_CANCEL);
|
---|
891 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_ERROR);
|
---|
892 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_AREA_REGISTER);
|
---|
893 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_AREA_UNREGISTER);
|
---|
894 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_AREA_ATTACH);
|
---|
895 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_AREA_DETACH);
|
---|
896 | }
|
---|
897 | return "Unknown";
|
---|
898 | }
|
---|
899 |
|
---|
900 | /**
|
---|
901 | * Translates a Shared Clipboard host message enum to a string.
|
---|
902 | *
|
---|
903 | * @returns Message ID string name.
|
---|
904 | * @param uMsg The message to translate.
|
---|
905 | */
|
---|
906 | const char *ShClHostMsgToStr(uint32_t uMsg)
|
---|
907 | {
|
---|
908 | switch (uMsg)
|
---|
909 | {
|
---|
910 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_QUIT);
|
---|
911 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_READ_DATA);
|
---|
912 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_FORMATS_REPORT);
|
---|
913 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_STATUS);
|
---|
914 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_ROOT_LIST_HDR_READ);
|
---|
915 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_ROOT_LIST_HDR_WRITE);
|
---|
916 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_ROOT_LIST_ENTRY_READ);
|
---|
917 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_ROOT_LIST_ENTRY_WRITE);
|
---|
918 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_OPEN);
|
---|
919 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_CLOSE);
|
---|
920 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_HDR_READ);
|
---|
921 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_HDR_WRITE);
|
---|
922 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_ENTRY_READ);
|
---|
923 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_ENTRY_WRITE);
|
---|
924 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_OPEN);
|
---|
925 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_CLOSE);
|
---|
926 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_READ);
|
---|
927 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_WRITE);
|
---|
928 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_CANCEL);
|
---|
929 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_ERROR);
|
---|
930 | }
|
---|
931 | return "Unknown";
|
---|
932 | }
|
---|
933 |
|
---|
934 | /**
|
---|
935 | * Translates a Shared Clipboard guest message enum to a string.
|
---|
936 | *
|
---|
937 | * @returns Message ID string name.
|
---|
938 | * @param uMsg The message to translate.
|
---|
939 | */
|
---|
940 | const char *ShClGuestMsgToStr(uint32_t uMsg)
|
---|
941 | {
|
---|
942 | switch (uMsg)
|
---|
943 | {
|
---|
944 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_MSG_OLD_GET_WAIT);
|
---|
945 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_REPORT_FORMATS);
|
---|
946 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_DATA_READ);
|
---|
947 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_DATA_WRITE);
|
---|
948 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_CONNECT);
|
---|
949 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_REPORT_FEATURES);
|
---|
950 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_QUERY_FEATURES);
|
---|
951 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_MSG_PEEK_NOWAIT);
|
---|
952 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_MSG_PEEK_WAIT);
|
---|
953 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_MSG_GET);
|
---|
954 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_MSG_CANCEL);
|
---|
955 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_REPLY);
|
---|
956 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_ROOT_LIST_HDR_READ);
|
---|
957 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_ROOT_LIST_HDR_WRITE);
|
---|
958 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_ROOT_LIST_ENTRY_READ);
|
---|
959 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_ROOT_LIST_ENTRY_WRITE);
|
---|
960 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_LIST_OPEN);
|
---|
961 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_LIST_CLOSE);
|
---|
962 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_LIST_HDR_READ);
|
---|
963 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_LIST_HDR_WRITE);
|
---|
964 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_LIST_ENTRY_READ);
|
---|
965 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_LIST_ENTRY_WRITE);
|
---|
966 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_OBJ_OPEN);
|
---|
967 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_OBJ_CLOSE);
|
---|
968 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_OBJ_READ);
|
---|
969 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_OBJ_WRITE);
|
---|
970 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_ERROR);
|
---|
971 | }
|
---|
972 | return "Unknown";
|
---|
973 | }
|
---|