[7117] | 1 | /* $Id: clipboard-common.cpp 102815 2024-01-10 13:44:29Z vboxsync $ */
|
---|
[7073] | 2 | /** @file
|
---|
[7117] | 3 | * Shared Clipboard: Some helper function for converting between the various eol.
|
---|
[7073] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[46422] | 7 | * Includes contributions from François Revol
|
---|
[7073] | 8 | *
|
---|
[98103] | 9 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[43123] | 10 | *
|
---|
[96407] | 11 | * This file is part of VirtualBox base platform packages, as
|
---|
| 12 | * available from https://www.virtualbox.org.
|
---|
| 13 | *
|
---|
| 14 | * This program is free software; you can redistribute it and/or
|
---|
| 15 | * modify it under the terms of the GNU General Public License
|
---|
| 16 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 17 | * License.
|
---|
| 18 | *
|
---|
| 19 | * This program is distributed in the hope that it will be useful, but
|
---|
| 20 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 22 | * General Public License for more details.
|
---|
| 23 | *
|
---|
| 24 | * You should have received a copy of the GNU General Public License
|
---|
| 25 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 26 | *
|
---|
| 27 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[7073] | 28 | */
|
---|
| 29 |
|
---|
[79036] | 30 | #define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD
|
---|
| 31 |
|
---|
[41083] | 32 | #include <iprt/alloc.h>
|
---|
[7073] | 33 | #include <iprt/assert.h>
|
---|
[80444] | 34 | #include <iprt/semaphore.h>
|
---|
[79120] | 35 | #include <iprt/path.h>
|
---|
[80468] | 36 | #include <iprt/rand.h>
|
---|
[85828] | 37 | #include <iprt/utf16.h>
|
---|
[78974] | 38 |
|
---|
[85856] | 39 | #include <iprt/formats/bmp.h>
|
---|
| 40 |
|
---|
[79272] | 41 | #include <iprt/errcore.h>
|
---|
[18398] | 42 | #include <VBox/log.h>
|
---|
| 43 | #include <VBox/GuestHost/clipboard-helper.h>
|
---|
[80285] | 44 | #include <VBox/HostServices/VBoxClipboardSvc.h>
|
---|
[7073] | 45 |
|
---|
[80444] | 46 |
|
---|
[86000] | 47 | /*********************************************************************************************************************************
|
---|
| 48 | * Prototypes *
|
---|
| 49 | *********************************************************************************************************************************/
|
---|
[92735] | 50 | static void shClEventSourceResetInternal(PSHCLEVENTSOURCE pSource);
|
---|
[100641] | 51 | static int shClEventSourceUnregisterEvent(PSHCLEVENTSOURCE pSource, PSHCLEVENT pEvent);
|
---|
[92735] | 52 |
|
---|
| 53 | static void shClEventDestroy(PSHCLEVENT pEvent);
|
---|
[86000] | 54 | DECLINLINE(PSHCLEVENT) shclEventGet(PSHCLEVENTSOURCE pSource, SHCLEVENTID idEvent);
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | /*********************************************************************************************************************************
|
---|
| 58 | * Implementation *
|
---|
| 59 | *********************************************************************************************************************************/
|
---|
| 60 |
|
---|
[80444] | 61 | /**
|
---|
| 62 | * Allocates a new event payload.
|
---|
| 63 | *
|
---|
| 64 | * @returns VBox status code.
|
---|
[80468] | 65 | * @param uID Payload ID to set for this payload. Useful for consequtive payloads.
|
---|
[100204] | 66 | * @param pvData Data to associate to this payload.
|
---|
| 67 | * The payload owns the data then.
|
---|
| 68 | * @param cbData Size (in bytes) of data to associate.
|
---|
[80444] | 69 | * @param ppPayload Where to store the allocated event payload on success.
|
---|
| 70 | */
|
---|
[100204] | 71 | int ShClPayloadInit(uint32_t uID, void *pvData, uint32_t cbData,
|
---|
| 72 | PSHCLEVENTPAYLOAD *ppPayload)
|
---|
[80444] | 73 | {
|
---|
| 74 | AssertPtrReturn(pvData, VERR_INVALID_POINTER);
|
---|
[82477] | 75 | AssertReturn(cbData > 0, VERR_INVALID_PARAMETER);
|
---|
[80444] | 76 |
|
---|
[82477] | 77 | PSHCLEVENTPAYLOAD pPayload = (PSHCLEVENTPAYLOAD)RTMemAlloc(sizeof(SHCLEVENTPAYLOAD));
|
---|
| 78 | if (pPayload)
|
---|
[80444] | 79 | {
|
---|
[100204] | 80 | pPayload->pvData = pvData;
|
---|
| 81 | pPayload->cbData = cbData;
|
---|
| 82 | pPayload->uID = uID;
|
---|
[80444] | 83 |
|
---|
[100204] | 84 | *ppPayload = pPayload;
|
---|
| 85 | return VINF_SUCCESS;
|
---|
| 86 | }
|
---|
[80444] | 87 |
|
---|
| 88 | return VERR_NO_MEMORY;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | /**
|
---|
[100204] | 92 | * Allocates a new event payload.
|
---|
| 93 | *
|
---|
| 94 | * @returns VBox status code.
|
---|
| 95 | * @param uID Payload ID to set for this payload. Useful for consequtive payloads.
|
---|
| 96 | * @param pvData Data block to allocate (duplicate) to this payload.
|
---|
| 97 | * @param cbData Size (in bytes) of data block to allocate.
|
---|
| 98 | * @param ppPayload Where to store the allocated event payload on success.
|
---|
| 99 | */
|
---|
| 100 | int ShClPayloadAlloc(uint32_t uID, const void *pvData, uint32_t cbData,
|
---|
| 101 | PSHCLEVENTPAYLOAD *ppPayload)
|
---|
| 102 | {
|
---|
| 103 | AssertPtrReturn(pvData, VERR_INVALID_POINTER);
|
---|
| 104 | AssertReturn(cbData > 0, VERR_INVALID_PARAMETER);
|
---|
| 105 |
|
---|
| 106 | void *pvDataDup = RTMemDup(pvData, cbData);
|
---|
| 107 | if (pvDataDup)
|
---|
| 108 | return ShClPayloadInit(uID, pvDataDup, cbData, ppPayload);
|
---|
| 109 |
|
---|
| 110 | return VERR_NO_MEMORY;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | /**
|
---|
[80444] | 114 | * Frees an event payload.
|
---|
| 115 | *
|
---|
| 116 | * @returns VBox status code.
|
---|
| 117 | * @param pPayload Event payload to free.
|
---|
| 118 | */
|
---|
[81223] | 119 | void ShClPayloadFree(PSHCLEVENTPAYLOAD pPayload)
|
---|
[80444] | 120 | {
|
---|
| 121 | if (!pPayload)
|
---|
| 122 | return;
|
---|
| 123 |
|
---|
| 124 | if (pPayload->pvData)
|
---|
| 125 | {
|
---|
| 126 | Assert(pPayload->cbData);
|
---|
| 127 | RTMemFree(pPayload->pvData);
|
---|
| 128 | pPayload->pvData = NULL;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | pPayload->cbData = 0;
|
---|
[82477] | 132 | pPayload->uID = UINT32_MAX;
|
---|
[80444] | 133 |
|
---|
| 134 | RTMemFree(pPayload);
|
---|
| 135 | }
|
---|
| 136 |
|
---|
[80459] | 137 | /**
|
---|
| 138 | * Creates a new event source.
|
---|
| 139 | *
|
---|
| 140 | * @returns VBox status code.
|
---|
| 141 | * @param pSource Event source to create.
|
---|
| 142 | * @param uID ID to use for event source.
|
---|
| 143 | */
|
---|
[81223] | 144 | int ShClEventSourceCreate(PSHCLEVENTSOURCE pSource, SHCLEVENTSOURCEID uID)
|
---|
[80444] | 145 | {
|
---|
[82477] | 146 | LogFlowFunc(("pSource=%p, uID=%RU16\n", pSource, uID));
|
---|
[80444] | 147 | AssertPtrReturn(pSource, VERR_INVALID_POINTER);
|
---|
| 148 |
|
---|
[92735] | 149 | int rc = RTCritSectInit(&pSource->CritSect);
|
---|
| 150 | AssertRCReturn(rc, rc);
|
---|
| 151 |
|
---|
[80444] | 152 | RTListInit(&pSource->lstEvents);
|
---|
| 153 |
|
---|
| 154 | pSource->uID = uID;
|
---|
[80468] | 155 | /* Choose a random event ID starting point. */
|
---|
[82527] | 156 | pSource->idNextEvent = RTRandU32Ex(1, VBOX_SHCL_MAX_EVENTS - 1);
|
---|
[80444] | 157 |
|
---|
[82477] | 158 | return VINF_SUCCESS;
|
---|
[80444] | 159 | }
|
---|
| 160 |
|
---|
[80459] | 161 | /**
|
---|
| 162 | * Destroys an event source.
|
---|
| 163 | *
|
---|
[92735] | 164 | * @returns VBox status code.
|
---|
[80459] | 165 | * @param pSource Event source to destroy.
|
---|
| 166 | */
|
---|
[92735] | 167 | int ShClEventSourceDestroy(PSHCLEVENTSOURCE pSource)
|
---|
[80444] | 168 | {
|
---|
| 169 | if (!pSource)
|
---|
[92735] | 170 | return VINF_SUCCESS;
|
---|
[80444] | 171 |
|
---|
[99974] | 172 | if (!RTCritSectIsInitialized(&pSource->CritSect)) /* Already destroyed? Bail out. */
|
---|
| 173 | return VINF_SUCCESS;
|
---|
| 174 |
|
---|
[81346] | 175 | LogFlowFunc(("ID=%RU32\n", pSource->uID));
|
---|
[80444] | 176 |
|
---|
[92735] | 177 | int rc = RTCritSectEnter(&pSource->CritSect);
|
---|
| 178 | if (RT_SUCCESS(rc))
|
---|
| 179 | {
|
---|
| 180 | shClEventSourceResetInternal(pSource);
|
---|
[81444] | 181 |
|
---|
[92735] | 182 | rc = RTCritSectLeave(&pSource->CritSect);
|
---|
| 183 | AssertRC(rc);
|
---|
| 184 |
|
---|
| 185 | RTCritSectDelete(&pSource->CritSect);
|
---|
| 186 |
|
---|
| 187 | pSource->uID = UINT16_MAX;
|
---|
| 188 | pSource->idNextEvent = UINT32_MAX;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | return rc;
|
---|
[81444] | 192 | }
|
---|
| 193 |
|
---|
| 194 | /**
|
---|
[92735] | 195 | * Resets an event source, internal version.
|
---|
[81444] | 196 | *
|
---|
| 197 | * @param pSource Event source to reset.
|
---|
| 198 | */
|
---|
[92735] | 199 | static void shClEventSourceResetInternal(PSHCLEVENTSOURCE pSource)
|
---|
[81444] | 200 | {
|
---|
| 201 | LogFlowFunc(("ID=%RU32\n", pSource->uID));
|
---|
| 202 |
|
---|
[80662] | 203 | PSHCLEVENT pEvIt;
|
---|
| 204 | PSHCLEVENT pEvItNext;
|
---|
| 205 | RTListForEachSafe(&pSource->lstEvents, pEvIt, pEvItNext, SHCLEVENT, Node)
|
---|
[80444] | 206 | {
|
---|
[100641] | 207 | bool const fDealloc = ASMAtomicReadU32(&pEvIt->cRefs) == 0; /* Still any references left? Skip de-allocation. */
|
---|
| 208 | if (!fDealloc)
|
---|
| 209 | Log3Func(("Event %RU32 has %RU32 references left, skipping de-allocation\n", pEvIt->idEvent, pEvIt->cRefs));
|
---|
[80845] | 210 |
|
---|
[92735] | 211 | shClEventDestroy(pEvIt);
|
---|
[80845] | 212 |
|
---|
[100641] | 213 | int rc2 = shClEventSourceUnregisterEvent(pSource, pEvIt);
|
---|
| 214 | AssertRC(rc2);
|
---|
| 215 |
|
---|
| 216 | if (fDealloc)
|
---|
| 217 | {
|
---|
| 218 | RTMemFree(pEvIt);
|
---|
| 219 | pEvIt = NULL;
|
---|
| 220 | }
|
---|
[80444] | 221 | }
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | /**
|
---|
[92735] | 225 | * Resets an event source.
|
---|
| 226 | *
|
---|
| 227 | * @param pSource Event source to reset.
|
---|
| 228 | */
|
---|
| 229 | void ShClEventSourceReset(PSHCLEVENTSOURCE pSource)
|
---|
| 230 | {
|
---|
| 231 | int rc2 = RTCritSectEnter(&pSource->CritSect);
|
---|
| 232 | if (RT_SUCCESS(rc2))
|
---|
| 233 | {
|
---|
| 234 | shClEventSourceResetInternal(pSource);
|
---|
| 235 |
|
---|
| 236 | rc2 = RTCritSectLeave(&pSource->CritSect);
|
---|
| 237 | AssertRC(rc2);
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | /**
|
---|
[82527] | 242 | * Generates a new event ID for a specific event source and registers it.
|
---|
[80444] | 243 | *
|
---|
[92735] | 244 | * @returns VBox status code.
|
---|
[82527] | 245 | * @param pSource Event source to generate event for.
|
---|
[92735] | 246 | * @param ppEvent Where to return the new event generated on success.
|
---|
[80444] | 247 | */
|
---|
[92735] | 248 | int ShClEventSourceGenerateAndRegisterEvent(PSHCLEVENTSOURCE pSource, PSHCLEVENT *ppEvent)
|
---|
[80444] | 249 | {
|
---|
[92735] | 250 | AssertPtrReturn(pSource, VERR_INVALID_POINTER);
|
---|
| 251 | AssertPtrReturn(ppEvent, VERR_INVALID_POINTER);
|
---|
[82527] | 252 |
|
---|
| 253 | PSHCLEVENT pEvent = (PSHCLEVENT)RTMemAllocZ(sizeof(SHCLEVENT));
|
---|
[92735] | 254 | AssertReturn(pEvent, VERR_NO_MEMORY);
|
---|
[82527] | 255 | int rc = RTSemEventMultiCreate(&pEvent->hEvtMulSem);
|
---|
[92735] | 256 | if (RT_SUCCESS(rc))
|
---|
[80444] | 257 | {
|
---|
[92735] | 258 | rc = RTCritSectEnter(&pSource->CritSect);
|
---|
| 259 | if (RT_SUCCESS(rc))
|
---|
[82527] | 260 | {
|
---|
[92735] | 261 | /*
|
---|
| 262 | * Allocate an unique event ID.
|
---|
| 263 | */
|
---|
| 264 | for (uint32_t cTries = 0;; cTries++)
|
---|
| 265 | {
|
---|
| 266 | SHCLEVENTID idEvent = ++pSource->idNextEvent;
|
---|
| 267 | if (idEvent < VBOX_SHCL_MAX_EVENTS)
|
---|
| 268 | { /* likely */ }
|
---|
| 269 | else
|
---|
| 270 | pSource->idNextEvent = idEvent = 1; /* zero == error, remember! */
|
---|
[82527] | 271 |
|
---|
[92735] | 272 | if (shclEventGet(pSource, idEvent) == NULL)
|
---|
| 273 | {
|
---|
| 274 | pEvent->pParent = pSource;
|
---|
| 275 | pEvent->idEvent = idEvent;
|
---|
| 276 | RTListAppend(&pSource->lstEvents, &pEvent->Node);
|
---|
| 277 |
|
---|
| 278 | rc = RTCritSectLeave(&pSource->CritSect);
|
---|
| 279 | AssertRC(rc);
|
---|
| 280 |
|
---|
| 281 | LogFlowFunc(("uSource=%RU16: New event: %#x\n", pSource->uID, idEvent));
|
---|
| 282 |
|
---|
[92772] | 283 | ShClEventRetain(pEvent);
|
---|
[92735] | 284 | *ppEvent = pEvent;
|
---|
| 285 |
|
---|
| 286 | return VINF_SUCCESS;
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | AssertBreak(cTries < 4096);
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | rc = RTCritSectLeave(&pSource->CritSect);
|
---|
| 293 | AssertRC(rc);
|
---|
[82527] | 294 | }
|
---|
[80444] | 295 | }
|
---|
| 296 |
|
---|
[82871] | 297 | AssertMsgFailed(("Unable to register a new event ID for event source %RU16\n", pSource->uID));
|
---|
| 298 |
|
---|
[91625] | 299 | RTSemEventMultiDestroy(pEvent->hEvtMulSem);
|
---|
| 300 | pEvent->hEvtMulSem = NIL_RTSEMEVENTMULTI;
|
---|
[82527] | 301 | RTMemFree(pEvent);
|
---|
[92735] | 302 | return rc;
|
---|
[80444] | 303 | }
|
---|
| 304 |
|
---|
| 305 | /**
|
---|
[92735] | 306 | * Destroys an event.
|
---|
| 307 | *
|
---|
| 308 | * @param pEvent Event to destroy.
|
---|
| 309 | */
|
---|
| 310 | static void shClEventDestroy(PSHCLEVENT pEvent)
|
---|
| 311 | {
|
---|
| 312 | if (!pEvent)
|
---|
| 313 | return;
|
---|
| 314 |
|
---|
| 315 | LogFlowFunc(("Event %RU32\n", pEvent->idEvent));
|
---|
| 316 |
|
---|
| 317 | if (pEvent->hEvtMulSem != NIL_RTSEMEVENT)
|
---|
| 318 | {
|
---|
| 319 | RTSemEventMultiDestroy(pEvent->hEvtMulSem);
|
---|
| 320 | pEvent->hEvtMulSem = NIL_RTSEMEVENT;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | ShClPayloadFree(pEvent->pPayload);
|
---|
[99974] | 324 | pEvent->pPayload = NULL;
|
---|
[92735] | 325 |
|
---|
| 326 | pEvent->idEvent = NIL_SHCLEVENTID;
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 | /**
|
---|
| 330 | * Unregisters an event.
|
---|
| 331 | *
|
---|
| 332 | * @returns VBox status code.
|
---|
| 333 | * @param pSource Event source to unregister event for.
|
---|
[100641] | 334 | * @param pEvent Event to unregister.
|
---|
[92735] | 335 | */
|
---|
[100641] | 336 | static int shClEventSourceUnregisterEvent(PSHCLEVENTSOURCE pSource, PSHCLEVENT pEvent)
|
---|
[92735] | 337 | {
|
---|
[100641] | 338 | RT_NOREF(pSource);
|
---|
| 339 |
|
---|
[92735] | 340 | LogFlowFunc(("idEvent=%RU32, cRefs=%RU32\n", pEvent->idEvent, pEvent->cRefs));
|
---|
| 341 |
|
---|
[100641] | 342 | RTListNodeRemove(&pEvent->Node);
|
---|
| 343 | pEvent->pParent = NULL;
|
---|
[92735] | 344 |
|
---|
[100641] | 345 | return VINF_SUCCESS;
|
---|
[92735] | 346 | }
|
---|
| 347 |
|
---|
| 348 | /**
|
---|
[86000] | 349 | * Returns a specific event of a event source. Inlined version.
|
---|
| 350 | *
|
---|
| 351 | * @returns Pointer to event if found, or NULL if not found.
|
---|
| 352 | * @param pSource Event source to get event from.
|
---|
| 353 | * @param uID Event ID to get.
|
---|
| 354 | */
|
---|
| 355 | DECLINLINE(PSHCLEVENT) shclEventGet(PSHCLEVENTSOURCE pSource, SHCLEVENTID idEvent)
|
---|
| 356 | {
|
---|
| 357 | PSHCLEVENT pEvent;
|
---|
| 358 | RTListForEach(&pSource->lstEvents, pEvent, SHCLEVENT, Node)
|
---|
| 359 | {
|
---|
| 360 | if (pEvent->idEvent == idEvent)
|
---|
| 361 | return pEvent;
|
---|
| 362 | }
|
---|
| 363 |
|
---|
| 364 | return NULL;
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | /**
|
---|
| 368 | * Returns a specific event of a event source.
|
---|
| 369 | *
|
---|
| 370 | * @returns Pointer to event if found, or NULL if not found.
|
---|
| 371 | * @param pSource Event source to get event from.
|
---|
[92735] | 372 | * @param idEvent ID of event to return.
|
---|
[86000] | 373 | */
|
---|
[92735] | 374 | PSHCLEVENT ShClEventSourceGetFromId(PSHCLEVENTSOURCE pSource, SHCLEVENTID idEvent)
|
---|
[86000] | 375 | {
|
---|
[92735] | 376 | AssertPtrReturn(pSource, NULL);
|
---|
| 377 |
|
---|
| 378 | int rc = RTCritSectEnter(&pSource->CritSect);
|
---|
| 379 | if (RT_SUCCESS(rc))
|
---|
| 380 | {
|
---|
| 381 | PSHCLEVENT pEvent = shclEventGet(pSource, idEvent);
|
---|
| 382 |
|
---|
| 383 | rc = RTCritSectLeave(&pSource->CritSect);
|
---|
| 384 | AssertRC(rc);
|
---|
| 385 |
|
---|
| 386 | return pEvent;
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | return NULL;
|
---|
[86000] | 390 | }
|
---|
| 391 |
|
---|
| 392 | /**
|
---|
[80623] | 393 | * Returns the last (newest) event ID which has been registered for an event source.
|
---|
| 394 | *
|
---|
[92735] | 395 | * @returns Pointer to last registered event, or NULL if not found.
|
---|
[80623] | 396 | * @param pSource Event source to get last registered event from.
|
---|
| 397 | */
|
---|
[92735] | 398 | PSHCLEVENT ShClEventSourceGetLast(PSHCLEVENTSOURCE pSource)
|
---|
[80623] | 399 | {
|
---|
[92735] | 400 | AssertPtrReturn(pSource, NULL);
|
---|
[80623] | 401 |
|
---|
[92735] | 402 | int rc = RTCritSectEnter(&pSource->CritSect);
|
---|
| 403 | if (RT_SUCCESS(rc))
|
---|
| 404 | {
|
---|
| 405 | PSHCLEVENT pEvent = RTListGetLast(&pSource->lstEvents, SHCLEVENT, Node);
|
---|
| 406 |
|
---|
| 407 | rc = RTCritSectLeave(&pSource->CritSect);
|
---|
| 408 | AssertRC(rc);
|
---|
| 409 |
|
---|
| 410 | return pEvent;
|
---|
| 411 | }
|
---|
| 412 |
|
---|
| 413 | return NULL;
|
---|
[80623] | 414 | }
|
---|
| 415 |
|
---|
| 416 | /**
|
---|
[85985] | 417 | * Returns the current reference count for a specific event.
|
---|
| 418 | *
|
---|
| 419 | * @returns Reference count.
|
---|
| 420 | * @param pSource Event source the specific event is part of.
|
---|
| 421 | * @param idEvent Event ID to return reference count for.
|
---|
| 422 | */
|
---|
[92735] | 423 | uint32_t ShClEventGetRefs(PSHCLEVENT pEvent)
|
---|
[85985] | 424 | {
|
---|
[92735] | 425 | AssertPtrReturn(pEvent, 0);
|
---|
[85985] | 426 |
|
---|
[92735] | 427 | return ASMAtomicReadU32(&pEvent->cRefs);
|
---|
[85985] | 428 | }
|
---|
| 429 |
|
---|
| 430 | /**
|
---|
[80845] | 431 | * Detaches a payload from an event, internal version.
|
---|
| 432 | *
|
---|
[100204] | 433 | * @returns Pointer to the detached payload. Can be NULL if the event has no payload.
|
---|
[80845] | 434 | * @param pEvent Event to detach payload for.
|
---|
| 435 | */
|
---|
[85986] | 436 | static PSHCLEVENTPAYLOAD shclEventPayloadDetachInternal(PSHCLEVENT pEvent)
|
---|
[80845] | 437 | {
|
---|
[85986] | 438 | #ifdef VBOX_STRICT
|
---|
| 439 | AssertPtrReturn(pEvent, NULL);
|
---|
| 440 | #endif
|
---|
[80845] | 441 |
|
---|
[85986] | 442 | PSHCLEVENTPAYLOAD pPayload = pEvent->pPayload;
|
---|
| 443 |
|
---|
[80845] | 444 | pEvent->pPayload = NULL;
|
---|
[85986] | 445 |
|
---|
| 446 | return pPayload;
|
---|
[80845] | 447 | }
|
---|
| 448 |
|
---|
| 449 | /**
|
---|
[80444] | 450 | * Waits for an event to get signalled.
|
---|
| 451 | *
|
---|
| 452 | * @returns VBox status code.
|
---|
[100566] | 453 | * @retval VERR_SHCLPB_EVENT_FAILED if the event has a set error code.
|
---|
[92735] | 454 | * @param pEvent Event to wait for.
|
---|
[80444] | 455 | * @param uTimeoutMs Timeout (in ms) to wait.
|
---|
[100566] | 456 | * @param pRc Where to return the event rc. Optional and can be NULL.
|
---|
[80444] | 457 | * @param ppPayload Where to store the (allocated) event payload on success. Needs to be free'd with
|
---|
[80845] | 458 | * SharedClipboardPayloadFree(). Optional.
|
---|
[80444] | 459 | */
|
---|
[100566] | 460 | int ShClEventWaitEx(PSHCLEVENT pEvent, RTMSINTERVAL uTimeoutMs, int *pRc, PSHCLEVENTPAYLOAD *ppPayload)
|
---|
[80444] | 461 | {
|
---|
[92735] | 462 | AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
|
---|
[91625] | 463 | AssertPtrNullReturn(ppPayload, VERR_INVALID_POINTER);
|
---|
[80444] | 464 | LogFlowFuncEnter();
|
---|
| 465 |
|
---|
[92735] | 466 | int rc = RTSemEventMultiWait(pEvent->hEvtMulSem, uTimeoutMs);
|
---|
| 467 | if (RT_SUCCESS(rc))
|
---|
[80444] | 468 | {
|
---|
[100566] | 469 | if (RT_FAILURE(pEvent->rc))
|
---|
| 470 | rc = VERR_SHCLPB_EVENT_FAILED;
|
---|
| 471 |
|
---|
| 472 | if (pRc)
|
---|
| 473 | *pRc = pEvent->rc;
|
---|
| 474 |
|
---|
[92735] | 475 | if (ppPayload)
|
---|
[80444] | 476 | {
|
---|
[92735] | 477 | /* Make sure to detach payload here, as the caller now owns the data. */
|
---|
| 478 | *ppPayload = shclEventPayloadDetachInternal(pEvent);
|
---|
[80444] | 479 | }
|
---|
| 480 | }
|
---|
| 481 |
|
---|
[92735] | 482 | if (RT_FAILURE(rc))
|
---|
| 483 | LogRel2(("Shared Clipboard: Waiting for event %RU32 failed, rc=%Rrc\n", pEvent->idEvent, rc));
|
---|
| 484 |
|
---|
[80444] | 485 | LogFlowFuncLeaveRC(rc);
|
---|
| 486 | return rc;
|
---|
| 487 | }
|
---|
| 488 |
|
---|
| 489 | /**
|
---|
[100566] | 490 | * Waits for an event to get signalled.
|
---|
| 491 | *
|
---|
| 492 | * @returns VBox status code.
|
---|
| 493 | * @retval VERR_SHCLPB_EVENT_FAILED if the event has a set error code.
|
---|
| 494 | * @param pEvent Event to wait for.
|
---|
| 495 | * @param uTimeoutMs Timeout (in ms) to wait.
|
---|
| 496 | * @param ppPayload Where to store the (allocated) event payload on success. Needs to be free'd with
|
---|
| 497 | * SharedClipboardPayloadFree(). Optional.
|
---|
| 498 | */
|
---|
| 499 | int ShClEventWait(PSHCLEVENT pEvent, RTMSINTERVAL uTimeoutMs, PSHCLEVENTPAYLOAD *ppPayload)
|
---|
| 500 | {
|
---|
| 501 | return ShClEventWaitEx(pEvent, uTimeoutMs, NULL /* pRc */, ppPayload);
|
---|
| 502 | }
|
---|
| 503 |
|
---|
| 504 | /**
|
---|
[82874] | 505 | * Retains an event by increasing its reference count.
|
---|
| 506 | *
|
---|
| 507 | * @returns New reference count, or UINT32_MAX if failed.
|
---|
[92735] | 508 | * @param pEvent Event to retain.
|
---|
[82874] | 509 | */
|
---|
[92735] | 510 | uint32_t ShClEventRetain(PSHCLEVENT pEvent)
|
---|
[82874] | 511 | {
|
---|
[92735] | 512 | AssertPtrReturn(pEvent, UINT32_MAX);
|
---|
| 513 | AssertReturn(ASMAtomicReadU32(&pEvent->cRefs) < 64, UINT32_MAX);
|
---|
[82874] | 514 | return ASMAtomicIncU32(&pEvent->cRefs);
|
---|
| 515 | }
|
---|
| 516 |
|
---|
| 517 | /**
|
---|
[100641] | 518 | * Releases event by decreasing its reference count. Will be destroyed once the reference count reaches 0.
|
---|
[82874] | 519 | *
|
---|
| 520 | * @returns New reference count, or UINT32_MAX if failed.
|
---|
[92735] | 521 | * @param pEvent Event to release.
|
---|
| 522 | * If the reference count reaches 0, the event will
|
---|
| 523 | * be destroyed and \a pEvent will be invalid.
|
---|
[82874] | 524 | */
|
---|
[92735] | 525 | uint32_t ShClEventRelease(PSHCLEVENT pEvent)
|
---|
[82874] | 526 | {
|
---|
[92735] | 527 | if (!pEvent)
|
---|
| 528 | return 0;
|
---|
[82874] | 529 |
|
---|
[92735] | 530 | AssertReturn(ASMAtomicReadU32(&pEvent->cRefs) > 0, UINT32_MAX);
|
---|
| 531 |
|
---|
| 532 | uint32_t const cRefs = ASMAtomicDecU32(&pEvent->cRefs);
|
---|
| 533 | if (cRefs == 0)
|
---|
| 534 | {
|
---|
[100641] | 535 | int rc;
|
---|
| 536 | PSHCLEVENTSOURCE pParent = pEvent->pParent;
|
---|
| 537 | if ( pParent
|
---|
| 538 | && RTCritSectIsInitialized(&pParent->CritSect))
|
---|
| 539 | {
|
---|
| 540 | rc = RTCritSectEnter(&pParent->CritSect);
|
---|
| 541 | if (RT_SUCCESS(rc))
|
---|
| 542 | {
|
---|
| 543 | rc = shClEventSourceUnregisterEvent(pParent, pEvent);
|
---|
[92735] | 544 |
|
---|
[100641] | 545 | int rc2 = RTCritSectLeave(&pParent->CritSect);
|
---|
| 546 | if (RT_SUCCESS(rc))
|
---|
| 547 | rc = rc2;
|
---|
| 548 | }
|
---|
| 549 | }
|
---|
| 550 | else
|
---|
| 551 | rc = VINF_SUCCESS;
|
---|
| 552 |
|
---|
| 553 | if (RT_SUCCESS(rc))
|
---|
| 554 | {
|
---|
| 555 | shClEventDestroy(pEvent);
|
---|
| 556 |
|
---|
| 557 | RTMemFree(pEvent);
|
---|
| 558 | pEvent = NULL;
|
---|
| 559 | }
|
---|
| 560 |
|
---|
| 561 | return RT_SUCCESS(rc) ? 0 : UINT32_MAX;
|
---|
[92735] | 562 | }
|
---|
| 563 |
|
---|
| 564 | return cRefs;
|
---|
[82874] | 565 | }
|
---|
| 566 |
|
---|
| 567 | /**
|
---|
[100566] | 568 | * Signals an event, extended version.
|
---|
[80444] | 569 | *
|
---|
| 570 | * @returns VBox status code.
|
---|
[92735] | 571 | * @param pEvent Event to signal.
|
---|
[100566] | 572 | * @param rc Result code to set.
|
---|
[91625] | 573 | * @param pPayload Event payload to associate. Takes ownership on
|
---|
| 574 | * success. Optional.
|
---|
[80444] | 575 | */
|
---|
[100566] | 576 | int ShClEventSignalEx(PSHCLEVENT pEvent, int rc, PSHCLEVENTPAYLOAD pPayload)
|
---|
[80444] | 577 | {
|
---|
[92735] | 578 | AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
|
---|
[80444] | 579 |
|
---|
[92735] | 580 | Assert(pEvent->pPayload == NULL);
|
---|
[80444] | 581 |
|
---|
[100566] | 582 | pEvent->rc = rc;
|
---|
[92735] | 583 | pEvent->pPayload = pPayload;
|
---|
[80444] | 584 |
|
---|
[100566] | 585 | int rc2 = RTSemEventMultiSignal(pEvent->hEvtMulSem);
|
---|
| 586 | if (RT_FAILURE(rc2))
|
---|
[92735] | 587 | pEvent->pPayload = NULL; /* (no race condition if consumer also enters the critical section) */
|
---|
[80444] | 588 |
|
---|
[100566] | 589 | LogFlowFuncLeaveRC(rc2);
|
---|
| 590 | return rc2;
|
---|
[80444] | 591 | }
|
---|
| 592 |
|
---|
[100566] | 593 | /**
|
---|
| 594 | * Signals an event.
|
---|
| 595 | *
|
---|
| 596 | * @returns VBox status code.
|
---|
| 597 | * @param pEvent Event to signal.
|
---|
| 598 | * @param pPayload Event payload to associate. Takes ownership on
|
---|
| 599 | * success. Optional.
|
---|
| 600 | */
|
---|
| 601 | int ShClEventSignal(PSHCLEVENT pEvent, PSHCLEVENTPAYLOAD pPayload)
|
---|
| 602 | {
|
---|
| 603 | return ShClEventSignalEx(pEvent, VINF_SUCCESS, pPayload);
|
---|
| 604 | }
|
---|
| 605 |
|
---|
[85828] | 606 | int ShClUtf16LenUtf8(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pchLen)
|
---|
| 607 | {
|
---|
| 608 | AssertPtrReturn(pcwszSrc, VERR_INVALID_POINTER);
|
---|
| 609 | AssertPtrReturn(pchLen, VERR_INVALID_POINTER);
|
---|
[7117] | 610 |
|
---|
[85828] | 611 | size_t chLen = 0;
|
---|
| 612 | int rc = RTUtf16CalcUtf8LenEx(pcwszSrc, cwcSrc, &chLen);
|
---|
| 613 | if (RT_SUCCESS(rc))
|
---|
[85845] | 614 | *pchLen = chLen;
|
---|
[85828] | 615 | return rc;
|
---|
| 616 | }
|
---|
| 617 |
|
---|
[85836] | 618 | int ShClConvUtf16CRLFToUtf8LF(PCRTUTF16 pcwszSrc, size_t cwcSrc,
|
---|
[85828] | 619 | char *pszBuf, size_t cbBuf, size_t *pcbLen)
|
---|
[7073] | 620 | {
|
---|
[85836] | 621 | AssertPtrReturn(pcwszSrc, VERR_INVALID_POINTER);
|
---|
| 622 | AssertReturn (cwcSrc, VERR_INVALID_PARAMETER);
|
---|
| 623 | AssertPtrReturn(pszBuf, VERR_INVALID_POINTER);
|
---|
| 624 | AssertPtrReturn(pcbLen, VERR_INVALID_POINTER);
|
---|
[7073] | 625 |
|
---|
[85828] | 626 | int rc;
|
---|
| 627 |
|
---|
| 628 | PRTUTF16 pwszTmp = NULL;
|
---|
| 629 | size_t cchTmp = 0;
|
---|
| 630 |
|
---|
| 631 | size_t cbLen = 0;
|
---|
| 632 |
|
---|
| 633 | /* How long will the converted text be? */
|
---|
[85836] | 634 | rc = ShClUtf16CRLFLenUtf8(pcwszSrc, cwcSrc, &cchTmp);
|
---|
[85828] | 635 | if (RT_SUCCESS(rc))
|
---|
[19505] | 636 | {
|
---|
[85845] | 637 | cchTmp++; /* Add space for terminator. */
|
---|
| 638 |
|
---|
| 639 | pwszTmp = (PRTUTF16)RTMemAlloc(cchTmp * sizeof(RTUTF16));
|
---|
| 640 | if (pwszTmp)
|
---|
[85828] | 641 | {
|
---|
[85845] | 642 | rc = ShClConvUtf16CRLFToLF(pcwszSrc, cwcSrc, pwszTmp, cchTmp);
|
---|
| 643 | if (RT_SUCCESS(rc))
|
---|
| 644 | rc = RTUtf16ToUtf8Ex(pwszTmp + 1, cchTmp - 1, &pszBuf, cbBuf, &cbLen);
|
---|
[85828] | 645 |
|
---|
[85845] | 646 | RTMemFree(reinterpret_cast<void *>(pwszTmp));
|
---|
[85828] | 647 | }
|
---|
| 648 | else
|
---|
[85845] | 649 | rc = VERR_NO_MEMORY;
|
---|
[19505] | 650 | }
|
---|
[85828] | 651 |
|
---|
| 652 | if (RT_SUCCESS(rc))
|
---|
[7073] | 653 | {
|
---|
[85845] | 654 | *pcbLen = cbLen;
|
---|
[7073] | 655 | }
|
---|
[85828] | 656 |
|
---|
| 657 | return rc;
|
---|
| 658 | }
|
---|
| 659 |
|
---|
[85836] | 660 | int ShClConvUtf16LFToCRLFA(PCRTUTF16 pcwszSrc, size_t cwcSrc,
|
---|
[85828] | 661 | PRTUTF16 *ppwszDst, size_t *pcwDst)
|
---|
| 662 | {
|
---|
[85836] | 663 | AssertPtrReturn(pcwszSrc, VERR_INVALID_POINTER);
|
---|
[85828] | 664 | AssertPtrReturn(ppwszDst, VERR_INVALID_POINTER);
|
---|
[85836] | 665 | AssertPtrReturn(pcwDst, VERR_INVALID_POINTER);
|
---|
[85828] | 666 |
|
---|
| 667 | PRTUTF16 pwszDst = NULL;
|
---|
| 668 | size_t cchDst;
|
---|
| 669 |
|
---|
[85836] | 670 | int rc = ShClUtf16LFLenUtf8(pcwszSrc, cwcSrc, &cchDst);
|
---|
[85828] | 671 | if (RT_SUCCESS(rc))
|
---|
| 672 | {
|
---|
[85845] | 673 | pwszDst = (PRTUTF16)RTMemAlloc((cchDst + 1 /* Leave space for terminator */) * sizeof(RTUTF16));
|
---|
[85828] | 674 | if (pwszDst)
|
---|
| 675 | {
|
---|
[85845] | 676 | rc = ShClConvUtf16LFToCRLF(pcwszSrc, cwcSrc, pwszDst, cchDst + 1 /* Include terminator */);
|
---|
[85828] | 677 | }
|
---|
| 678 | else
|
---|
| 679 | rc = VERR_NO_MEMORY;
|
---|
| 680 | }
|
---|
| 681 |
|
---|
| 682 | if (RT_SUCCESS(rc))
|
---|
| 683 | {
|
---|
| 684 | *ppwszDst = pwszDst;
|
---|
| 685 | *pcwDst = cchDst;
|
---|
| 686 | }
|
---|
| 687 | else
|
---|
| 688 | RTMemFree(pwszDst);
|
---|
| 689 |
|
---|
| 690 | LogFlowFuncLeaveRC(rc);
|
---|
| 691 | return rc;
|
---|
| 692 | }
|
---|
| 693 |
|
---|
[85845] | 694 | int ShClConvUtf8LFToUtf16CRLF(const char *pcszSrc, size_t cbSrc,
|
---|
[85828] | 695 | PRTUTF16 *ppwszDst, size_t *pcwDst)
|
---|
| 696 | {
|
---|
[85836] | 697 | AssertPtrReturn(pcszSrc, VERR_INVALID_POINTER);
|
---|
| 698 | AssertReturn(cbSrc, VERR_INVALID_PARAMETER);
|
---|
[85828] | 699 | AssertPtrReturn(ppwszDst, VERR_INVALID_POINTER);
|
---|
[85836] | 700 | AssertPtrReturn(pcwDst, VERR_INVALID_POINTER);
|
---|
[85828] | 701 |
|
---|
| 702 | /* Intermediate conversion to UTF-16. */
|
---|
| 703 | size_t cwcTmp;
|
---|
| 704 | PRTUTF16 pwcTmp = NULL;
|
---|
[85836] | 705 | int rc = RTStrToUtf16Ex(pcszSrc, cbSrc, &pwcTmp, 0, &cwcTmp);
|
---|
[85828] | 706 | if (RT_SUCCESS(rc))
|
---|
| 707 | {
|
---|
| 708 | rc = ShClConvUtf16LFToCRLFA(pwcTmp, cwcTmp, ppwszDst, pcwDst);
|
---|
| 709 | RTUtf16Free(pwcTmp);
|
---|
| 710 | }
|
---|
| 711 |
|
---|
| 712 | return rc;
|
---|
| 713 | }
|
---|
| 714 |
|
---|
[97253] | 715 | /**
|
---|
| 716 | * Converts a Latin-1 string with LF line endings into an UTF-16 string with CRLF endings.
|
---|
| 717 | *
|
---|
| 718 | * @returns VBox status code.
|
---|
| 719 | * @param pcszSrc Latin-1 string to convert.
|
---|
| 720 | * @param cbSrc Size (in bytes) of Latin-1 string to convert.
|
---|
| 721 | * @param ppwszDst Where to return the converted UTF-16 string on success.
|
---|
| 722 | * @param pcwDst Where to return the length (in UTF-16 characters) on success.
|
---|
| 723 | *
|
---|
| 724 | * @note Only converts the source until the string terminator is found (or length limit is hit).
|
---|
| 725 | */
|
---|
[85845] | 726 | int ShClConvLatin1LFToUtf16CRLF(const char *pcszSrc, size_t cbSrc,
|
---|
[85828] | 727 | PRTUTF16 *ppwszDst, size_t *pcwDst)
|
---|
| 728 | {
|
---|
[85836] | 729 | AssertPtrReturn(pcszSrc, VERR_INVALID_POINTER);
|
---|
| 730 | AssertReturn(cbSrc, VERR_INVALID_PARAMETER);
|
---|
[85828] | 731 | AssertPtrReturn(ppwszDst, VERR_INVALID_POINTER);
|
---|
[85836] | 732 | AssertPtrReturn(pcwDst, VERR_INVALID_POINTER);
|
---|
[85828] | 733 |
|
---|
[97253] | 734 | size_t chSrc = 0;
|
---|
[85828] | 735 |
|
---|
| 736 | PRTUTF16 pwszDst = NULL;
|
---|
| 737 |
|
---|
| 738 | /* Calculate the space needed. */
|
---|
[97253] | 739 | size_t cwDst = 0;
|
---|
| 740 | for (size_t i = 0; i < cbSrc && pcszSrc[i] != '\0'; ++i)
|
---|
[85828] | 741 | {
|
---|
[85836] | 742 | if (pcszSrc[i] == VBOX_SHCL_LINEFEED)
|
---|
[85845] | 743 | cwDst += 2; /* Space for VBOX_SHCL_CARRIAGERETURN + VBOX_SHCL_LINEFEED. */
|
---|
[85828] | 744 | else
|
---|
[85845] | 745 | ++cwDst;
|
---|
[97253] | 746 | chSrc++;
|
---|
[85828] | 747 | }
|
---|
| 748 |
|
---|
[85845] | 749 | pwszDst = (PRTUTF16)RTMemAlloc((cwDst + 1 /* Leave space for the terminator */) * sizeof(RTUTF16));
|
---|
[97253] | 750 | AssertPtrReturn(pwszDst, VERR_NO_MEMORY);
|
---|
[85828] | 751 |
|
---|
| 752 | /* Do the conversion, bearing in mind that Latin-1 expands "naturally" to UTF-16. */
|
---|
[97253] | 753 | for (size_t i = 0, j = 0; i < chSrc; ++i, ++j)
|
---|
[85828] | 754 | {
|
---|
[97253] | 755 | AssertMsg(j <= cwDst, ("cbSrc=%zu, j=%u vs. cwDst=%u\n", cbSrc, j, cwDst));
|
---|
| 756 | if (pcszSrc[i] != VBOX_SHCL_LINEFEED)
|
---|
| 757 | pwszDst[j] = pcszSrc[i];
|
---|
| 758 | else
|
---|
[85828] | 759 | {
|
---|
[97253] | 760 | pwszDst[j] = VBOX_SHCL_CARRIAGERETURN;
|
---|
| 761 | pwszDst[j + 1] = VBOX_SHCL_LINEFEED;
|
---|
| 762 | ++j;
|
---|
[85828] | 763 | }
|
---|
| 764 | }
|
---|
| 765 |
|
---|
[97253] | 766 | pwszDst[cwDst] = '\0'; /* Make sure we are zero-terminated. */
|
---|
[85828] | 767 |
|
---|
[97253] | 768 | *ppwszDst = pwszDst;
|
---|
| 769 | *pcwDst = cwDst;
|
---|
| 770 |
|
---|
| 771 | return VINF_SUCCESS;
|
---|
[85828] | 772 | }
|
---|
| 773 |
|
---|
[85836] | 774 | int ShClConvUtf16ToUtf8HTML(PCRTUTF16 pcwszSrc, size_t cwcSrc, char **ppszDst, size_t *pcbDst)
|
---|
[85828] | 775 | {
|
---|
[85836] | 776 | AssertPtrReturn(pcwszSrc, VERR_INVALID_POINTER);
|
---|
| 777 | AssertReturn (cwcSrc, VERR_INVALID_PARAMETER);
|
---|
| 778 | AssertPtrReturn(ppszDst, VERR_INVALID_POINTER);
|
---|
| 779 | AssertPtrReturn(pcbDst, VERR_INVALID_POINTER);
|
---|
[85828] | 780 |
|
---|
[85829] | 781 | int rc = VINF_SUCCESS;
|
---|
[85828] | 782 |
|
---|
[85836] | 783 | size_t cwTmp = cwcSrc;
|
---|
| 784 | PCRTUTF16 pwTmp = pcwszSrc;
|
---|
[85828] | 785 |
|
---|
| 786 | char *pchDst = NULL;
|
---|
| 787 | size_t cbDst = 0;
|
---|
| 788 |
|
---|
| 789 | size_t i = 0;
|
---|
| 790 | while (i < cwTmp)
|
---|
| 791 | {
|
---|
| 792 | /* Find zero symbol (end of string). */
|
---|
[85836] | 793 | for (; i < cwTmp && pcwszSrc[i] != 0; i++)
|
---|
[85828] | 794 | ;
|
---|
| 795 |
|
---|
| 796 | /* Convert found string. */
|
---|
| 797 | char *psz = NULL;
|
---|
| 798 | size_t cch = 0;
|
---|
[85836] | 799 | rc = RTUtf16ToUtf8Ex(pwTmp, cwTmp, &psz, pwTmp - pcwszSrc, &cch);
|
---|
[85828] | 800 | if (RT_FAILURE(rc))
|
---|
| 801 | break;
|
---|
| 802 |
|
---|
| 803 | /* Append new substring. */
|
---|
| 804 | char *pchNew = (char *)RTMemRealloc(pchDst, cbDst + cch + 1);
|
---|
| 805 | if (!pchNew)
|
---|
| 806 | {
|
---|
| 807 | RTStrFree(psz);
|
---|
| 808 | rc = VERR_NO_MEMORY;
|
---|
| 809 | break;
|
---|
| 810 | }
|
---|
| 811 |
|
---|
| 812 | pchDst = pchNew;
|
---|
| 813 | memcpy(pchDst + cbDst, psz, cch + 1);
|
---|
| 814 |
|
---|
| 815 | RTStrFree(psz);
|
---|
| 816 |
|
---|
| 817 | cbDst += cch + 1;
|
---|
| 818 |
|
---|
| 819 | /* Skip zero symbols. */
|
---|
[85836] | 820 | for (; i < cwTmp && pcwszSrc[i] == 0; i++)
|
---|
[85828] | 821 | ;
|
---|
| 822 |
|
---|
| 823 | /* Remember start of string. */
|
---|
| 824 | pwTmp += i;
|
---|
| 825 | }
|
---|
| 826 |
|
---|
| 827 | if (RT_SUCCESS(rc))
|
---|
| 828 | {
|
---|
| 829 | *ppszDst = pchDst;
|
---|
| 830 | *pcbDst = cbDst;
|
---|
| 831 |
|
---|
| 832 | return VINF_SUCCESS;
|
---|
| 833 | }
|
---|
| 834 |
|
---|
| 835 | RTMemFree(pchDst);
|
---|
| 836 |
|
---|
| 837 | return rc;
|
---|
| 838 | }
|
---|
| 839 |
|
---|
| 840 | int ShClUtf16LFLenUtf8(PCRTUTF16 pcwszSrc, size_t cwSrc, size_t *pchLen)
|
---|
| 841 | {
|
---|
| 842 | AssertPtrReturn(pcwszSrc, VERR_INVALID_POINTER);
|
---|
| 843 | AssertPtrReturn(pchLen, VERR_INVALID_POINTER);
|
---|
| 844 |
|
---|
| 845 | AssertMsgReturn(pcwszSrc[0] != VBOX_SHCL_UTF16BEMARKER,
|
---|
| 846 | ("Big endian UTF-16 not supported yet\n"), VERR_NOT_SUPPORTED);
|
---|
| 847 |
|
---|
| 848 | size_t cLen = 0;
|
---|
| 849 |
|
---|
| 850 | /* Don't copy the endian marker. */
|
---|
| 851 | size_t i = pcwszSrc[0] == VBOX_SHCL_UTF16LEMARKER ? 1 : 0;
|
---|
| 852 |
|
---|
[7073] | 853 | /* Calculate the size of the destination text string. */
|
---|
| 854 | /* Is this Utf16 or Utf16-LE? */
|
---|
[85828] | 855 | for (; i < cwSrc; ++i, ++cLen)
|
---|
[7073] | 856 | {
|
---|
[8268] | 857 | /* Check for a single line feed */
|
---|
[82280] | 858 | if (pcwszSrc[i] == VBOX_SHCL_LINEFEED)
|
---|
[85828] | 859 | ++cLen;
|
---|
[20966] | 860 | #ifdef RT_OS_DARWIN
|
---|
[8268] | 861 | /* Check for a single carriage return (MacOS) */
|
---|
[82280] | 862 | if (pcwszSrc[i] == VBOX_SHCL_CARRIAGERETURN)
|
---|
[85828] | 863 | ++cLen;
|
---|
[20966] | 864 | #endif
|
---|
[82280] | 865 | if (pcwszSrc[i] == 0)
|
---|
[7073] | 866 | {
|
---|
| 867 | /* Don't count this, as we do so below. */
|
---|
| 868 | break;
|
---|
| 869 | }
|
---|
| 870 | }
|
---|
[85828] | 871 |
|
---|
| 872 | *pchLen = cLen;
|
---|
| 873 |
|
---|
[7073] | 874 | return VINF_SUCCESS;
|
---|
| 875 | }
|
---|
| 876 |
|
---|
[85828] | 877 | int ShClUtf16CRLFLenUtf8(PCRTUTF16 pcwszSrc, size_t cwSrc, size_t *pchLen)
|
---|
[7073] | 878 | {
|
---|
[85828] | 879 | AssertPtrReturn(pcwszSrc, VERR_INVALID_POINTER);
|
---|
| 880 | AssertReturn(cwSrc, VERR_INVALID_PARAMETER);
|
---|
| 881 | AssertPtrReturn(pchLen, VERR_INVALID_POINTER);
|
---|
| 882 |
|
---|
| 883 | AssertMsgReturn(pcwszSrc[0] != VBOX_SHCL_UTF16BEMARKER,
|
---|
| 884 | ("Big endian UTF-16 not supported yet\n"), VERR_NOT_SUPPORTED);
|
---|
| 885 |
|
---|
| 886 | size_t cLen = 0;
|
---|
| 887 |
|
---|
| 888 | /* Calculate the size of the destination text string. */
|
---|
| 889 | /* Is this Utf16 or Utf16-LE? */
|
---|
| 890 | if (pcwszSrc[0] == VBOX_SHCL_UTF16LEMARKER)
|
---|
| 891 | cLen = 0;
|
---|
| 892 | else
|
---|
| 893 | cLen = 1;
|
---|
| 894 |
|
---|
| 895 | for (size_t i = 0; i < cwSrc; ++i, ++cLen)
|
---|
[7073] | 896 | {
|
---|
[85828] | 897 | if ( (i + 1 < cwSrc)
|
---|
| 898 | && (pcwszSrc[i] == VBOX_SHCL_CARRIAGERETURN)
|
---|
| 899 | && (pcwszSrc[i + 1] == VBOX_SHCL_LINEFEED))
|
---|
[7073] | 900 | {
|
---|
[85828] | 901 | ++i;
|
---|
[7073] | 902 | }
|
---|
[85828] | 903 | if (pcwszSrc[i] == 0)
|
---|
| 904 | break;
|
---|
[7073] | 905 | }
|
---|
[85828] | 906 |
|
---|
| 907 | *pchLen = cLen;
|
---|
| 908 |
|
---|
| 909 | return VINF_SUCCESS;
|
---|
| 910 | }
|
---|
| 911 |
|
---|
[85836] | 912 | int ShClConvUtf16LFToCRLF(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pu16Dst, size_t cwDst)
|
---|
[85828] | 913 | {
|
---|
| 914 | AssertPtrReturn(pcwszSrc, VERR_INVALID_POINTER);
|
---|
[85845] | 915 | AssertPtrReturn(pu16Dst, VERR_INVALID_POINTER);
|
---|
| 916 | AssertReturn(cwDst, VERR_INVALID_PARAMETER);
|
---|
[85828] | 917 |
|
---|
| 918 | AssertMsgReturn(pcwszSrc[0] != VBOX_SHCL_UTF16BEMARKER,
|
---|
| 919 | ("Big endian UTF-16 not supported yet\n"), VERR_NOT_SUPPORTED);
|
---|
| 920 |
|
---|
| 921 | int rc = VINF_SUCCESS;
|
---|
| 922 |
|
---|
[7073] | 923 | /* Don't copy the endian marker. */
|
---|
[85828] | 924 | size_t i = pcwszSrc[0] == VBOX_SHCL_UTF16LEMARKER ? 1 : 0;
|
---|
| 925 | size_t j = 0;
|
---|
| 926 |
|
---|
[85836] | 927 | for (; i < cwcSrc; ++i, ++j)
|
---|
[7073] | 928 | {
|
---|
| 929 | /* Don't copy the null byte, as we add it below. */
|
---|
[82280] | 930 | if (pcwszSrc[i] == 0)
|
---|
[7073] | 931 | break;
|
---|
[85828] | 932 |
|
---|
| 933 | /* Not enough space in destination? */
|
---|
| 934 | if (j == cwDst)
|
---|
[7073] | 935 | {
|
---|
[85828] | 936 | rc = VERR_BUFFER_OVERFLOW;
|
---|
| 937 | break;
|
---|
[7073] | 938 | }
|
---|
[85828] | 939 |
|
---|
[82280] | 940 | if (pcwszSrc[i] == VBOX_SHCL_LINEFEED)
|
---|
[7073] | 941 | {
|
---|
[85828] | 942 | pu16Dst[j] = VBOX_SHCL_CARRIAGERETURN;
|
---|
[7073] | 943 | ++j;
|
---|
[85828] | 944 |
|
---|
| 945 | /* Not enough space in destination? */
|
---|
| 946 | if (j == cwDst)
|
---|
[7073] | 947 | {
|
---|
[85828] | 948 | rc = VERR_BUFFER_OVERFLOW;
|
---|
| 949 | break;
|
---|
[7073] | 950 | }
|
---|
| 951 | }
|
---|
[20966] | 952 | #ifdef RT_OS_DARWIN
|
---|
[8280] | 953 | /* Check for a single carriage return (MacOS) */
|
---|
[82280] | 954 | else if (pcwszSrc[i] == VBOX_SHCL_CARRIAGERETURN)
|
---|
[8280] | 955 | {
|
---|
[85828] | 956 | /* Set CR.r */
|
---|
| 957 | pu16Dst[j] = VBOX_SHCL_CARRIAGERETURN;
|
---|
[8280] | 958 | ++j;
|
---|
[85828] | 959 |
|
---|
| 960 | /* Not enough space in destination? */
|
---|
| 961 | if (j == cwDst)
|
---|
[8268] | 962 | {
|
---|
[85828] | 963 | rc = VERR_BUFFER_OVERFLOW;
|
---|
| 964 | break;
|
---|
[8268] | 965 | }
|
---|
[85828] | 966 |
|
---|
| 967 | /* Add line feed. */
|
---|
| 968 | pu16Dst[j] = VBOX_SHCL_LINEFEED;
|
---|
[8280] | 969 | continue;
|
---|
| 970 | }
|
---|
[20966] | 971 | #endif
|
---|
[85828] | 972 | pu16Dst[j] = pcwszSrc[i];
|
---|
[7073] | 973 | }
|
---|
| 974 |
|
---|
[85828] | 975 | if (j == cwDst)
|
---|
| 976 | rc = VERR_BUFFER_OVERFLOW;
|
---|
[7073] | 977 |
|
---|
[85828] | 978 | if (RT_SUCCESS(rc))
|
---|
[7073] | 979 | {
|
---|
[85828] | 980 | /* Add terminator. */
|
---|
| 981 | pu16Dst[j] = 0;
|
---|
[7073] | 982 | }
|
---|
[85828] | 983 |
|
---|
| 984 | return rc;
|
---|
[7073] | 985 | }
|
---|
| 986 |
|
---|
[85836] | 987 | int ShClConvUtf16CRLFToLF(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pu16Dst, size_t cwDst)
|
---|
[7073] | 988 | {
|
---|
[85828] | 989 | AssertPtrReturn(pcwszSrc, VERR_INVALID_POINTER);
|
---|
[85836] | 990 | AssertReturn(cwcSrc, VERR_INVALID_PARAMETER);
|
---|
| 991 | AssertPtrReturn(pu16Dst, VERR_INVALID_POINTER);
|
---|
| 992 | AssertReturn(cwDst, VERR_INVALID_PARAMETER);
|
---|
[7073] | 993 |
|
---|
[85828] | 994 | AssertMsgReturn(pcwszSrc[0] != VBOX_SHCL_UTF16BEMARKER,
|
---|
| 995 | ("Big endian UTF-16 not supported yet\n"), VERR_NOT_SUPPORTED);
|
---|
| 996 |
|
---|
[7073] | 997 | /* Prepend the Utf16 byte order marker if it is missing. */
|
---|
[85828] | 998 | size_t cwDstPos;
|
---|
[82280] | 999 | if (pcwszSrc[0] == VBOX_SHCL_UTF16LEMARKER)
|
---|
[7073] | 1000 | {
|
---|
[85828] | 1001 | cwDstPos = 0;
|
---|
[7073] | 1002 | }
|
---|
| 1003 | else
|
---|
| 1004 | {
|
---|
[85828] | 1005 | pu16Dst[0] = VBOX_SHCL_UTF16LEMARKER;
|
---|
| 1006 | cwDstPos = 1;
|
---|
[7073] | 1007 | }
|
---|
[85828] | 1008 |
|
---|
[85836] | 1009 | for (size_t i = 0; i < cwcSrc; ++i, ++cwDstPos)
|
---|
[7073] | 1010 | {
|
---|
[82280] | 1011 | if (pcwszSrc[i] == 0)
|
---|
[7073] | 1012 | break;
|
---|
[85828] | 1013 |
|
---|
| 1014 | if (cwDstPos == cwDst)
|
---|
[7073] | 1015 | return VERR_BUFFER_OVERFLOW;
|
---|
[85828] | 1016 |
|
---|
[85836] | 1017 | if ( (i + 1 < cwcSrc)
|
---|
[85828] | 1018 | && (pcwszSrc[i] == VBOX_SHCL_CARRIAGERETURN)
|
---|
[82280] | 1019 | && (pcwszSrc[i + 1] == VBOX_SHCL_LINEFEED))
|
---|
[7073] | 1020 | {
|
---|
| 1021 | ++i;
|
---|
| 1022 | }
|
---|
[85828] | 1023 |
|
---|
| 1024 | pu16Dst[cwDstPos] = pcwszSrc[i];
|
---|
[7073] | 1025 | }
|
---|
[85828] | 1026 |
|
---|
| 1027 | if (cwDstPos == cwDst)
|
---|
[7073] | 1028 | return VERR_BUFFER_OVERFLOW;
|
---|
[85828] | 1029 |
|
---|
| 1030 | /* Add terminating zero. */
|
---|
| 1031 | pu16Dst[cwDstPos] = 0;
|
---|
| 1032 |
|
---|
[7073] | 1033 | return VINF_SUCCESS;
|
---|
| 1034 | }
|
---|
| 1035 |
|
---|
[81223] | 1036 | int ShClDibToBmp(const void *pvSrc, size_t cbSrc, void **ppvDest, size_t *pcbDest)
|
---|
[41083] | 1037 | {
|
---|
[85828] | 1038 | AssertPtrReturn(pvSrc, VERR_INVALID_POINTER);
|
---|
| 1039 | AssertReturn(cbSrc, VERR_INVALID_PARAMETER);
|
---|
| 1040 | AssertPtrReturn(ppvDest, VERR_INVALID_POINTER);
|
---|
| 1041 | AssertPtrReturn(pcbDest, VERR_INVALID_POINTER);
|
---|
[41083] | 1042 |
|
---|
[85864] | 1043 | PBMPWIN3XINFOHDR coreHdr = (PBMPWIN3XINFOHDR)pvSrc;
|
---|
[41083] | 1044 | /** @todo Support all the many versions of the DIB headers. */
|
---|
[85864] | 1045 | if ( cbSrc < sizeof(BMPWIN3XINFOHDR)
|
---|
| 1046 | || RT_LE2H_U32(coreHdr->cbSize) < sizeof(BMPWIN3XINFOHDR)
|
---|
| 1047 | || RT_LE2H_U32(coreHdr->cbSize) != sizeof(BMPWIN3XINFOHDR))
|
---|
[41083] | 1048 | {
|
---|
| 1049 | return VERR_INVALID_PARAMETER;
|
---|
| 1050 | }
|
---|
[41210] | 1051 |
|
---|
[85864] | 1052 | size_t offPixel = sizeof(BMPFILEHDR)
|
---|
| 1053 | + RT_LE2H_U32(coreHdr->cbSize)
|
---|
| 1054 | + RT_LE2H_U32(coreHdr->cClrUsed) * sizeof(uint32_t);
|
---|
[41210] | 1055 | if (cbSrc < offPixel)
|
---|
[41083] | 1056 | return VERR_INVALID_PARAMETER;
|
---|
| 1057 |
|
---|
[85864] | 1058 | size_t cbDst = sizeof(BMPFILEHDR) + cbSrc;
|
---|
[85828] | 1059 |
|
---|
| 1060 | void *pvDest = RTMemAlloc(cbDst);
|
---|
[41210] | 1061 | if (!pvDest)
|
---|
[41083] | 1062 | return VERR_NO_MEMORY;
|
---|
| 1063 |
|
---|
[85864] | 1064 | PBMPFILEHDR fileHdr = (PBMPFILEHDR)pvDest;
|
---|
[85828] | 1065 |
|
---|
[85864] | 1066 | fileHdr->uType = BMP_HDR_MAGIC;
|
---|
| 1067 | fileHdr->cbFileSize = (uint32_t)RT_H2LE_U32(cbDst);
|
---|
| 1068 | fileHdr->Reserved1 = 0;
|
---|
| 1069 | fileHdr->Reserved2 = 0;
|
---|
| 1070 | fileHdr->offBits = (uint32_t)RT_H2LE_U32(offPixel);
|
---|
[85828] | 1071 |
|
---|
[85864] | 1072 | memcpy((uint8_t *)pvDest + sizeof(BMPFILEHDR), pvSrc, cbSrc);
|
---|
[85828] | 1073 |
|
---|
[41210] | 1074 | *ppvDest = pvDest;
|
---|
[85828] | 1075 | *pcbDest = cbDst;
|
---|
| 1076 |
|
---|
[41083] | 1077 | return VINF_SUCCESS;
|
---|
| 1078 | }
|
---|
| 1079 |
|
---|
[81223] | 1080 | int ShClBmpGetDib(const void *pvSrc, size_t cbSrc, const void **ppvDest, size_t *pcbDest)
|
---|
[41083] | 1081 | {
|
---|
[85828] | 1082 | AssertPtrReturn(pvSrc, VERR_INVALID_POINTER);
|
---|
| 1083 | AssertReturn(cbSrc, VERR_INVALID_PARAMETER);
|
---|
| 1084 | AssertPtrReturn(ppvDest, VERR_INVALID_POINTER);
|
---|
| 1085 | AssertPtrReturn(pcbDest, VERR_INVALID_POINTER);
|
---|
[41083] | 1086 |
|
---|
[85864] | 1087 | PBMPFILEHDR pBmpHdr = (PBMPFILEHDR)pvSrc;
|
---|
| 1088 | if ( cbSrc < sizeof(BMPFILEHDR)
|
---|
| 1089 | || pBmpHdr->uType != BMP_HDR_MAGIC
|
---|
| 1090 | || RT_LE2H_U32(pBmpHdr->cbFileSize) != cbSrc)
|
---|
[41083] | 1091 | {
|
---|
| 1092 | return VERR_INVALID_PARAMETER;
|
---|
| 1093 | }
|
---|
[41210] | 1094 |
|
---|
[85864] | 1095 | *ppvDest = ((uint8_t *)pvSrc) + sizeof(BMPFILEHDR);
|
---|
| 1096 | *pcbDest = cbSrc - sizeof(BMPFILEHDR);
|
---|
[85828] | 1097 |
|
---|
[41083] | 1098 | return VINF_SUCCESS;
|
---|
| 1099 | }
|
---|
| 1100 |
|
---|
[79178] | 1101 | #ifdef LOG_ENABLED
|
---|
[86247] | 1102 |
|
---|
[82280] | 1103 | int ShClDbgDumpHtml(const char *pcszSrc, size_t cbSrc)
|
---|
[79174] | 1104 | {
|
---|
[86247] | 1105 | int rc = VINF_SUCCESS;
|
---|
| 1106 | char *pszBuf = (char *)RTMemTmpAllocZ(cbSrc + 1);
|
---|
| 1107 | if (pszBuf)
|
---|
[79174] | 1108 | {
|
---|
[86247] | 1109 | memcpy(pszBuf, pcszSrc, cbSrc);
|
---|
| 1110 | pszBuf[cbSrc] = '\0';
|
---|
| 1111 | for (size_t off = 0; off < cbSrc; ++off)
|
---|
| 1112 | if (pszBuf[off] == '\n' || pszBuf[off] == '\r')
|
---|
| 1113 | pszBuf[off] = ' ';
|
---|
| 1114 | LogFunc(("Removed \\r\\n: %s\n", pszBuf));
|
---|
| 1115 | RTMemTmpFree(pszBuf);
|
---|
[79174] | 1116 | }
|
---|
[86247] | 1117 | else
|
---|
| 1118 | rc = VERR_NO_MEMORY;
|
---|
[79174] | 1119 | return rc;
|
---|
| 1120 | }
|
---|
| 1121 |
|
---|
[82279] | 1122 | void ShClDbgDumpData(const void *pv, size_t cb, SHCLFORMAT uFormat)
|
---|
[79178] | 1123 | {
|
---|
[86247] | 1124 | if (LogIsEnabled())
|
---|
[79178] | 1125 | {
|
---|
[86247] | 1126 | if (uFormat & VBOX_SHCL_FMT_UNICODETEXT)
|
---|
[79178] | 1127 | {
|
---|
[86247] | 1128 | LogFunc(("VBOX_SHCL_FMT_UNICODETEXT:\n"));
|
---|
| 1129 | if (pv && cb)
|
---|
| 1130 | LogFunc(("%ls\n", pv));
|
---|
| 1131 | else
|
---|
| 1132 | LogFunc(("%p %zu\n", pv, cb));
|
---|
| 1133 | }
|
---|
| 1134 | else if (uFormat & VBOX_SHCL_FMT_BITMAP)
|
---|
| 1135 | LogFunc(("VBOX_SHCL_FMT_BITMAP\n"));
|
---|
| 1136 | else if (uFormat & VBOX_SHCL_FMT_HTML)
|
---|
| 1137 | {
|
---|
| 1138 | LogFunc(("VBOX_SHCL_FMT_HTML:\n"));
|
---|
| 1139 | if (pv && cb)
|
---|
[79178] | 1140 | {
|
---|
[86247] | 1141 | LogFunc(("%s\n", pv));
|
---|
| 1142 | ShClDbgDumpHtml((const char *)pv, cb);
|
---|
[79178] | 1143 | }
|
---|
[86247] | 1144 | else
|
---|
| 1145 | LogFunc(("%p %zu\n", pv, cb));
|
---|
[79178] | 1146 | }
|
---|
| 1147 | else
|
---|
[86247] | 1148 | LogFunc(("Invalid format %02X\n", uFormat));
|
---|
[79178] | 1149 | }
|
---|
| 1150 | }
|
---|
[86247] | 1151 |
|
---|
[80285] | 1152 | #endif /* LOG_ENABLED */
|
---|
[80283] | 1153 |
|
---|
| 1154 | /**
|
---|
[80990] | 1155 | * Translates a Shared Clipboard host function number to a string.
|
---|
| 1156 | *
|
---|
| 1157 | * @returns Function ID string name.
|
---|
| 1158 | * @param uFn The function to translate.
|
---|
| 1159 | */
|
---|
[81223] | 1160 | const char *ShClHostFunctionToStr(uint32_t uFn)
|
---|
[80990] | 1161 | {
|
---|
| 1162 | switch (uFn)
|
---|
| 1163 | {
|
---|
| 1164 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_SET_MODE);
|
---|
[81286] | 1165 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_SET_TRANSFER_MODE);
|
---|
[80990] | 1166 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_SET_HEADLESS);
|
---|
| 1167 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_CANCEL);
|
---|
| 1168 | RT_CASE_RET_STR(VBOX_SHCL_HOST_FN_ERROR);
|
---|
| 1169 | }
|
---|
| 1170 | return "Unknown";
|
---|
| 1171 | }
|
---|
| 1172 |
|
---|
| 1173 | /**
|
---|
[80283] | 1174 | * Translates a Shared Clipboard host message enum to a string.
|
---|
| 1175 | *
|
---|
| 1176 | * @returns Message ID string name.
|
---|
| 1177 | * @param uMsg The message to translate.
|
---|
| 1178 | */
|
---|
[81223] | 1179 | const char *ShClHostMsgToStr(uint32_t uMsg)
|
---|
[80283] | 1180 | {
|
---|
| 1181 | switch (uMsg)
|
---|
| 1182 | {
|
---|
[80847] | 1183 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_QUIT);
|
---|
| 1184 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_READ_DATA);
|
---|
| 1185 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_FORMATS_REPORT);
|
---|
[83621] | 1186 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_CANCELED);
|
---|
| 1187 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_READ_DATA_CID);
|
---|
[80907] | 1188 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_STATUS);
|
---|
[80858] | 1189 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_ROOT_LIST_HDR_READ);
|
---|
| 1190 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_ROOT_LIST_HDR_WRITE);
|
---|
| 1191 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_ROOT_LIST_ENTRY_READ);
|
---|
| 1192 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_ROOT_LIST_ENTRY_WRITE);
|
---|
| 1193 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_OPEN);
|
---|
| 1194 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_CLOSE);
|
---|
| 1195 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_HDR_READ);
|
---|
| 1196 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_HDR_WRITE);
|
---|
| 1197 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_ENTRY_READ);
|
---|
| 1198 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_ENTRY_WRITE);
|
---|
| 1199 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_OPEN);
|
---|
| 1200 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_CLOSE);
|
---|
| 1201 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_READ);
|
---|
| 1202 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_WRITE);
|
---|
| 1203 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_CANCEL);
|
---|
| 1204 | RT_CASE_RET_STR(VBOX_SHCL_HOST_MSG_TRANSFER_ERROR);
|
---|
[80283] | 1205 | }
|
---|
| 1206 | return "Unknown";
|
---|
| 1207 | }
|
---|
| 1208 |
|
---|
| 1209 | /**
|
---|
| 1210 | * Translates a Shared Clipboard guest message enum to a string.
|
---|
| 1211 | *
|
---|
| 1212 | * @returns Message ID string name.
|
---|
| 1213 | * @param uMsg The message to translate.
|
---|
| 1214 | */
|
---|
[81223] | 1215 | const char *ShClGuestMsgToStr(uint32_t uMsg)
|
---|
[80283] | 1216 | {
|
---|
| 1217 | switch (uMsg)
|
---|
| 1218 | {
|
---|
[82526] | 1219 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_MSG_OLD_GET_WAIT);
|
---|
[82513] | 1220 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_REPORT_FORMATS);
|
---|
[80847] | 1221 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_DATA_READ);
|
---|
| 1222 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_DATA_WRITE);
|
---|
| 1223 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_CONNECT);
|
---|
[81352] | 1224 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_REPORT_FEATURES);
|
---|
| 1225 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_QUERY_FEATURES);
|
---|
[80847] | 1226 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_MSG_PEEK_NOWAIT);
|
---|
| 1227 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_MSG_PEEK_WAIT);
|
---|
| 1228 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_MSG_GET);
|
---|
[82526] | 1229 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_MSG_CANCEL);
|
---|
[80847] | 1230 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_REPLY);
|
---|
| 1231 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_ROOT_LIST_HDR_READ);
|
---|
| 1232 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_ROOT_LIST_HDR_WRITE);
|
---|
| 1233 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_ROOT_LIST_ENTRY_READ);
|
---|
| 1234 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_ROOT_LIST_ENTRY_WRITE);
|
---|
| 1235 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_LIST_OPEN);
|
---|
| 1236 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_LIST_CLOSE);
|
---|
| 1237 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_LIST_HDR_READ);
|
---|
| 1238 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_LIST_HDR_WRITE);
|
---|
| 1239 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_LIST_ENTRY_READ);
|
---|
| 1240 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_LIST_ENTRY_WRITE);
|
---|
| 1241 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_OBJ_OPEN);
|
---|
| 1242 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_OBJ_CLOSE);
|
---|
| 1243 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_OBJ_READ);
|
---|
| 1244 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_OBJ_WRITE);
|
---|
| 1245 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_ERROR);
|
---|
[93494] | 1246 | RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_NEGOTIATE_CHUNK_SIZE);
|
---|
[80283] | 1247 | }
|
---|
| 1248 | return "Unknown";
|
---|
| 1249 | }
|
---|
[86959] | 1250 |
|
---|
| 1251 | /**
|
---|
| 1252 | * Converts Shared Clipboard formats to a string.
|
---|
| 1253 | *
|
---|
| 1254 | * @returns Stringified Shared Clipboard formats, or NULL on failure. Must be free'd with RTStrFree().
|
---|
| 1255 | * @param fFormats Shared Clipboard formats to convert.
|
---|
| 1256 | *
|
---|
| 1257 | */
|
---|
| 1258 | char *ShClFormatsToStrA(SHCLFORMATS fFormats)
|
---|
| 1259 | {
|
---|
| 1260 | #define APPEND_FMT_TO_STR(_aFmt) \
|
---|
| 1261 | if (fFormats & VBOX_SHCL_FMT_##_aFmt) \
|
---|
| 1262 | { \
|
---|
| 1263 | if (pszFmts) \
|
---|
| 1264 | { \
|
---|
| 1265 | rc2 = RTStrAAppend(&pszFmts, ", "); \
|
---|
| 1266 | if (RT_FAILURE(rc2)) \
|
---|
| 1267 | break; \
|
---|
| 1268 | } \
|
---|
| 1269 | \
|
---|
| 1270 | rc2 = RTStrAAppend(&pszFmts, #_aFmt); \
|
---|
| 1271 | if (RT_FAILURE(rc2)) \
|
---|
| 1272 | break; \
|
---|
| 1273 | }
|
---|
| 1274 |
|
---|
| 1275 | char *pszFmts = NULL;
|
---|
| 1276 | int rc2 = VINF_SUCCESS;
|
---|
| 1277 |
|
---|
| 1278 | do
|
---|
| 1279 | {
|
---|
| 1280 | APPEND_FMT_TO_STR(UNICODETEXT);
|
---|
| 1281 | APPEND_FMT_TO_STR(BITMAP);
|
---|
| 1282 | APPEND_FMT_TO_STR(HTML);
|
---|
| 1283 | # ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
| 1284 | APPEND_FMT_TO_STR(URI_LIST);
|
---|
| 1285 | # endif
|
---|
| 1286 |
|
---|
| 1287 | } while (0);
|
---|
| 1288 |
|
---|
| 1289 | if (!pszFmts)
|
---|
| 1290 | rc2 = RTStrAAppend(&pszFmts, "NONE");
|
---|
| 1291 |
|
---|
| 1292 | if ( RT_FAILURE(rc2)
|
---|
| 1293 | && pszFmts)
|
---|
| 1294 | {
|
---|
| 1295 | RTStrFree(pszFmts);
|
---|
| 1296 | pszFmts = NULL;
|
---|
| 1297 | }
|
---|
| 1298 |
|
---|
| 1299 | #undef APPEND_FMT_TO_STR
|
---|
| 1300 |
|
---|
| 1301 | return pszFmts;
|
---|
| 1302 | }
|
---|
| 1303 |
|
---|
[100328] | 1304 |
|
---|
| 1305 | /*********************************************************************************************************************************
|
---|
| 1306 | * Shared Clipboard Cache *
|
---|
| 1307 | *********************************************************************************************************************************/
|
---|
| 1308 |
|
---|
| 1309 | /**
|
---|
| 1310 | * Returns (mutable) data of a cache entry.
|
---|
| 1311 | *
|
---|
| 1312 | * @param pCacheEntry Cache entry to return data for.
|
---|
| 1313 | * @param pvData Where to return the (mutable) data pointer.
|
---|
| 1314 | * @param pcbData Where to return the data size.
|
---|
| 1315 | */
|
---|
| 1316 | void ShClCacheEntryGet(PSHCLCACHEENTRY pCacheEntry, void **pvData, size_t *pcbData)
|
---|
| 1317 | {
|
---|
| 1318 | AssertPtrReturnVoid(pCacheEntry);
|
---|
| 1319 | AssertPtrReturnVoid(pvData);
|
---|
| 1320 | AssertReturnVoid(pcbData);
|
---|
| 1321 |
|
---|
| 1322 | *pvData = pCacheEntry->pvData;
|
---|
| 1323 | *pcbData = pCacheEntry->cbData;
|
---|
| 1324 | }
|
---|
| 1325 |
|
---|
| 1326 | /**
|
---|
| 1327 | * Initializes a cache entry.
|
---|
| 1328 | *
|
---|
| 1329 | * @returns VBox status code.
|
---|
| 1330 | * @param pCacheEntry Cache entry to init.
|
---|
| 1331 | * @param pvData Data to copy to entry. Can be NULL to initialize an emptry entry.
|
---|
| 1332 | * @param cbData Size (in bytes) of \a pvData to copy to entry. Must be 0 if \a pvData is NULL.
|
---|
| 1333 | */
|
---|
| 1334 | static int shClCacheEntryInit(PSHCLCACHEENTRY pCacheEntry, const void *pvData, size_t cbData)
|
---|
| 1335 | {
|
---|
| 1336 | AssertReturn(RT_VALID_PTR(pvData) || cbData == 0, VERR_INVALID_PARAMETER);
|
---|
| 1337 |
|
---|
| 1338 | RT_BZERO(pCacheEntry, sizeof(SHCLCACHEENTRY));
|
---|
| 1339 |
|
---|
| 1340 | if (pvData)
|
---|
| 1341 | {
|
---|
| 1342 | pCacheEntry->pvData = RTMemDup(pvData, cbData);
|
---|
| 1343 | AssertPtrReturn(pCacheEntry->pvData, VERR_NO_MEMORY);
|
---|
| 1344 | pCacheEntry->cbData = cbData;
|
---|
| 1345 | }
|
---|
| 1346 |
|
---|
| 1347 | return VINF_SUCCESS;
|
---|
| 1348 | }
|
---|
| 1349 |
|
---|
| 1350 | /**
|
---|
| 1351 | * Returns whether a cache entry is valid (cache hit) or not.
|
---|
| 1352 | *
|
---|
| 1353 | * @returns \c true if valid, or \c false if not.
|
---|
| 1354 | * @param pCacheEntry Cache entry to check for.
|
---|
| 1355 | */
|
---|
| 1356 | DECLINLINE(bool) shClCacheEntryIsValid(PSHCLCACHEENTRY pCacheEntry)
|
---|
| 1357 | {
|
---|
| 1358 | return pCacheEntry->pvData != NULL;
|
---|
| 1359 | }
|
---|
| 1360 |
|
---|
| 1361 | /**
|
---|
| 1362 | * Destroys a cache entry.
|
---|
| 1363 | *
|
---|
| 1364 | * @param pCacheEntry Cache entry to destroy.
|
---|
| 1365 | */
|
---|
| 1366 | DECLINLINE(void) shClCacheEntryDestroy(PSHCLCACHEENTRY pCacheEntry)
|
---|
| 1367 | {
|
---|
| 1368 | if (pCacheEntry->pvData)
|
---|
| 1369 | {
|
---|
| 1370 | Assert(pCacheEntry->cbData);
|
---|
| 1371 | RTMemFree(pCacheEntry->pvData);
|
---|
| 1372 | pCacheEntry->pvData = NULL;
|
---|
| 1373 | pCacheEntry->cbData = 0;
|
---|
| 1374 | }
|
---|
| 1375 | }
|
---|
| 1376 |
|
---|
| 1377 | /**
|
---|
| 1378 | * Initializes a cache.
|
---|
| 1379 | *
|
---|
| 1380 | * @param pCache Cache to init.
|
---|
| 1381 | */
|
---|
| 1382 | void ShClCacheInit(PSHCLCACHE pCache)
|
---|
| 1383 | {
|
---|
| 1384 | AssertPtrReturnVoid(pCache);
|
---|
| 1385 |
|
---|
| 1386 | RT_BZERO(pCache, sizeof(SHCLCACHE));
|
---|
| 1387 |
|
---|
| 1388 | for (size_t i = 0; i < RT_ELEMENTS(pCache->aEntries); i++)
|
---|
| 1389 | shClCacheEntryInit(&pCache->aEntries[i], NULL, 0);
|
---|
| 1390 | }
|
---|
| 1391 |
|
---|
| 1392 | /**
|
---|
| 1393 | * Destroys all entries of a cache.
|
---|
| 1394 | *
|
---|
| 1395 | * @param pCache Cache to destroy entries for.
|
---|
| 1396 | */
|
---|
| 1397 | DECLINLINE(void) shClCacheDestroyEntries(PSHCLCACHE pCache)
|
---|
| 1398 | {
|
---|
| 1399 | for (size_t i = 0; i < RT_ELEMENTS(pCache->aEntries); i++)
|
---|
| 1400 | shClCacheEntryDestroy(&pCache->aEntries[i]);
|
---|
| 1401 | }
|
---|
| 1402 |
|
---|
| 1403 | /**
|
---|
| 1404 | * Destroys a cache.
|
---|
| 1405 | *
|
---|
| 1406 | * @param pCache Cache to destroy.
|
---|
| 1407 | */
|
---|
| 1408 | void ShClCacheDestroy(PSHCLCACHE pCache)
|
---|
| 1409 | {
|
---|
| 1410 | AssertPtrReturnVoid(pCache);
|
---|
| 1411 |
|
---|
| 1412 | shClCacheDestroyEntries(pCache);
|
---|
| 1413 |
|
---|
| 1414 | RT_BZERO(pCache, sizeof(SHCLCACHE));
|
---|
| 1415 | }
|
---|
| 1416 |
|
---|
| 1417 | /**
|
---|
| 1418 | * Invalidates a cache.
|
---|
| 1419 | *
|
---|
| 1420 | * @param pCache Cache to invalidate.
|
---|
| 1421 | */
|
---|
| 1422 | void ShClCacheInvalidate(PSHCLCACHE pCache)
|
---|
| 1423 | {
|
---|
| 1424 | AssertPtrReturnVoid(pCache);
|
---|
| 1425 |
|
---|
| 1426 | shClCacheDestroyEntries(pCache);
|
---|
| 1427 | }
|
---|
| 1428 |
|
---|
| 1429 | /**
|
---|
| 1430 | * Invalidates a specific cache entry.
|
---|
| 1431 | *
|
---|
| 1432 | * @param pCache Cache to invalidate.
|
---|
| 1433 | * @param uFmt Format to invalidate entry for.
|
---|
| 1434 | */
|
---|
| 1435 | void ShClCacheInvalidateEntry(PSHCLCACHE pCache, SHCLFORMAT uFmt)
|
---|
| 1436 | {
|
---|
| 1437 | AssertPtrReturnVoid(pCache);
|
---|
| 1438 | AssertReturnVoid(uFmt < VBOX_SHCL_FMT_MAX);
|
---|
| 1439 | shClCacheEntryDestroy(&pCache->aEntries[uFmt]);
|
---|
| 1440 | }
|
---|
| 1441 |
|
---|
| 1442 | /**
|
---|
| 1443 | * Gets an entry for a Shared Clipboard format.
|
---|
| 1444 | *
|
---|
| 1445 | * @returns Pointer to entry if cached, or NULL if not in cache (cache miss).
|
---|
| 1446 | * @param pCache Cache to get entry for.
|
---|
| 1447 | * @param uFmt Format to get entry for.
|
---|
| 1448 | */
|
---|
| 1449 | PSHCLCACHEENTRY ShClCacheGet(PSHCLCACHE pCache, SHCLFORMAT uFmt)
|
---|
| 1450 | {
|
---|
| 1451 | AssertReturn(uFmt < VBOX_SHCL_FMT_MAX, NULL);
|
---|
| 1452 | return shClCacheEntryIsValid(&pCache->aEntries[uFmt]) ? &pCache->aEntries[uFmt] : NULL;
|
---|
| 1453 | }
|
---|
| 1454 |
|
---|
| 1455 | /**
|
---|
[102815] | 1456 | * Sets data to cache for a specific clipboard format, internal version.
|
---|
| 1457 | *
|
---|
| 1458 | * @returns VBox status code.
|
---|
| 1459 | * @param pCache Cache to set data for.
|
---|
| 1460 | * @param uFmt Clipboard format to set data for.
|
---|
| 1461 | * @param pvData Data to set.
|
---|
| 1462 | * @param cbData Size (in bytes) of data to set.
|
---|
| 1463 | */
|
---|
| 1464 | DECLINLINE(int) shClCacheSet(PSHCLCACHE pCache, SHCLFORMAT uFmt, const void *pvData, size_t cbData)
|
---|
| 1465 | {
|
---|
| 1466 | AssertReturn(uFmt < VBOX_SHCL_FMT_MAX, VERR_INVALID_PARAMETER);
|
---|
| 1467 | AssertReturn(shClCacheEntryIsValid(&pCache->aEntries[uFmt]) == false, VERR_ALREADY_EXISTS);
|
---|
| 1468 |
|
---|
| 1469 | return shClCacheEntryInit(&pCache->aEntries[uFmt], pvData, cbData);
|
---|
| 1470 | }
|
---|
| 1471 |
|
---|
| 1472 | /**
|
---|
[100328] | 1473 | * Sets data to cache for a specific clipboard format.
|
---|
| 1474 | *
|
---|
| 1475 | * @returns VBox status code.
|
---|
| 1476 | * @param pCache Cache to set data for.
|
---|
| 1477 | * @param uFmt Clipboard format to set data for.
|
---|
| 1478 | * @param pvData Data to set.
|
---|
| 1479 | * @param cbData Size (in bytes) of data to set.
|
---|
| 1480 | */
|
---|
| 1481 | int ShClCacheSet(PSHCLCACHE pCache, SHCLFORMAT uFmt, const void *pvData, size_t cbData)
|
---|
| 1482 | {
|
---|
| 1483 | AssertPtrReturn(pCache, VERR_INVALID_POINTER);
|
---|
| 1484 |
|
---|
| 1485 | if (!pvData) /* Nothing to cache? */
|
---|
| 1486 | return VINF_SUCCESS;
|
---|
| 1487 |
|
---|
| 1488 | AssertReturn(cbData, VERR_INVALID_PARAMETER);
|
---|
| 1489 |
|
---|
[102815] | 1490 | return shClCacheSet(pCache, uFmt, pvData, cbData);
|
---|
[100328] | 1491 | }
|
---|
| 1492 |
|
---|
[102815] | 1493 | /**
|
---|
| 1494 | * Sets data to cache for multiple clipboard formats.
|
---|
| 1495 | *
|
---|
| 1496 | * Will bail out if a given format cannot be handled with the data given.
|
---|
| 1497 | *
|
---|
| 1498 | * @returns VBox status code.
|
---|
| 1499 | * @param pCache Cache to set data for.
|
---|
| 1500 | * @param uFmt Clipboard format to set data for.
|
---|
| 1501 | * @param pvData Data to set.
|
---|
| 1502 | * @param cbData Size (in bytes) of data to set.
|
---|
| 1503 | */
|
---|
| 1504 | int ShClCacheSetMultiple(PSHCLCACHE pCache, SHCLFORMATS uFmts, const void *pvData, size_t cbData)
|
---|
| 1505 | {
|
---|
| 1506 | AssertPtrReturn(pCache, VERR_INVALID_POINTER);
|
---|
| 1507 |
|
---|
| 1508 | if (!pvData) /* Nothing to cache? */
|
---|
| 1509 | return VINF_SUCCESS;
|
---|
| 1510 |
|
---|
| 1511 | AssertReturn(cbData, VERR_INVALID_PARAMETER);
|
---|
| 1512 |
|
---|
| 1513 | int rc = VINF_SUCCESS;
|
---|
| 1514 |
|
---|
| 1515 | SHCLFORMATS uFmtsLeft = uFmts;
|
---|
| 1516 | while (uFmtsLeft)
|
---|
| 1517 | {
|
---|
| 1518 | SHCLFORMAT uFmt = VBOX_SHCL_FMT_NONE;
|
---|
| 1519 | void *pvConv = NULL;
|
---|
| 1520 | size_t cbConv = 0;
|
---|
| 1521 | if (uFmtsLeft & VBOX_SHCL_FMT_UNICODETEXT)
|
---|
| 1522 | {
|
---|
| 1523 | uFmt = VBOX_SHCL_FMT_UNICODETEXT;
|
---|
| 1524 |
|
---|
| 1525 | rc = RTStrValidateEncoding((const char *)pvData);
|
---|
| 1526 | if (RT_SUCCESS(rc))
|
---|
| 1527 | {
|
---|
| 1528 | rc = RTStrToUtf16((const char *)pvData, (PRTUTF16 *)&pvConv);
|
---|
| 1529 | if (RT_SUCCESS(rc))
|
---|
| 1530 | cbConv = (RTUtf16Len((const PRTUTF16)pvConv) + 1) * sizeof(RTUTF16);
|
---|
| 1531 | }
|
---|
| 1532 | else if (!RTUtf16ValidateEncoding((const PRTUTF16)pvData))
|
---|
| 1533 | {
|
---|
| 1534 | AssertFailedBreakStmt(rc = VERR_INVALID_PARAMETER);
|
---|
| 1535 | }
|
---|
| 1536 | }
|
---|
| 1537 | else if (uFmtsLeft & VBOX_SHCL_FMT_BITMAP)
|
---|
| 1538 | uFmt = VBOX_SHCL_FMT_BITMAP;
|
---|
| 1539 | else if (uFmtsLeft & VBOX_SHCL_FMT_HTML)
|
---|
| 1540 | uFmt = VBOX_SHCL_FMT_HTML;
|
---|
| 1541 | else if (uFmtsLeft & VBOX_SHCL_FMT_URI_LIST)
|
---|
| 1542 | uFmt = VBOX_SHCL_FMT_URI_LIST;
|
---|
| 1543 | else
|
---|
| 1544 | AssertFailedBreakStmt(rc = VERR_NOT_SUPPORTED);
|
---|
| 1545 |
|
---|
| 1546 | uFmtsLeft &= ~uFmt; /* Remove from list. */
|
---|
| 1547 | Assert(RT_VALID_PTR(pvConv) || cbConv == 0); /* Sanity. */
|
---|
| 1548 |
|
---|
| 1549 | if (RT_SUCCESS(rc))
|
---|
| 1550 | rc = shClCacheSet(pCache, uFmt,
|
---|
| 1551 | pvConv ? pvConv : pvData,
|
---|
| 1552 | cbConv ? cbConv : cbData);
|
---|
| 1553 | RTMemFree(pvConv);
|
---|
| 1554 | AssertRCBreak(rc);
|
---|
| 1555 | }
|
---|
| 1556 |
|
---|
| 1557 | return rc;
|
---|
| 1558 | }
|
---|
| 1559 |
|
---|