1 | /* $Id*/
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard - Meta data handling functions.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD
|
---|
23 | #include <VBox/GuestHost/SharedClipboard-uri.h>
|
---|
24 |
|
---|
25 | int SharedClipboardMetaDataInit(PSHAREDCLIPBOARDMETADATA pMeta)
|
---|
26 | {
|
---|
27 | AssertPtrReturn(pMeta, VERR_INVALID_POINTER);
|
---|
28 |
|
---|
29 | Assert(pMeta->cbMeta == 0);
|
---|
30 | Assert(pMeta->pvMeta == NULL);
|
---|
31 |
|
---|
32 | pMeta->pvMeta = NULL;
|
---|
33 | pMeta->cbMeta = 0;
|
---|
34 |
|
---|
35 | return VINF_SUCCESS;
|
---|
36 | }
|
---|
37 |
|
---|
38 | void SharedClipboardMetaDataDestroy(PSHAREDCLIPBOARDMETADATA pMeta)
|
---|
39 | {
|
---|
40 | AssertPtrReturnVoid(pMeta);
|
---|
41 |
|
---|
42 | if (!pMeta)
|
---|
43 | return;
|
---|
44 |
|
---|
45 | if (pMeta->pvMeta)
|
---|
46 | {
|
---|
47 | Assert(pMeta->cbMeta);
|
---|
48 |
|
---|
49 | RTMemFree(pMeta->pvMeta);
|
---|
50 |
|
---|
51 | pMeta->pvMeta = NULL;
|
---|
52 | pMeta->cbMeta = 0;
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | int SharedClipboardMetaDataAdd(PSHAREDCLIPBOARDMETADATA pMeta, const void *pvDataAdd, uint32_t cbDataAdd)
|
---|
57 | {
|
---|
58 | AssertPtrReturn(pMeta, VERR_INVALID_POINTER);
|
---|
59 |
|
---|
60 | if (!cbDataAdd)
|
---|
61 | return VINF_SUCCESS;
|
---|
62 | AssertPtrReturn(pvDataAdd, VERR_INVALID_POINTER);
|
---|
63 |
|
---|
64 | int rc = SharedClipboardMetaDataResize(pMeta, pMeta->cbMeta + cbDataAdd);
|
---|
65 | if (RT_FAILURE(rc))
|
---|
66 | return rc;
|
---|
67 |
|
---|
68 | Assert(pMeta->cbMeta >= pMeta->cbUsed + cbDataAdd);
|
---|
69 | memcpy((uint8_t *)pMeta->pvMeta + pMeta->cbUsed, pvDataAdd, cbDataAdd);
|
---|
70 |
|
---|
71 | pMeta->cbUsed += cbDataAdd;
|
---|
72 |
|
---|
73 | return cbDataAdd;
|
---|
74 | }
|
---|
75 |
|
---|
76 | int SharedClipboardMetaDataResize(PSHAREDCLIPBOARDMETADATA pMeta, size_t cbNewSize)
|
---|
77 | {
|
---|
78 | AssertPtrReturn(pMeta, VERR_INVALID_POINTER);
|
---|
79 |
|
---|
80 | if (!cbNewSize)
|
---|
81 | {
|
---|
82 | SharedClipboardMetaDataDestroy(pMeta);
|
---|
83 | return VINF_SUCCESS;
|
---|
84 | }
|
---|
85 |
|
---|
86 | if (cbNewSize == pMeta->cbMeta)
|
---|
87 | return VINF_SUCCESS;
|
---|
88 |
|
---|
89 | void *pvTmp = NULL;
|
---|
90 | if (!pMeta->cbMeta)
|
---|
91 | {
|
---|
92 | Assert(pMeta->cbUsed == 0);
|
---|
93 | pvTmp = RTMemAllocZ(cbNewSize);
|
---|
94 | }
|
---|
95 | else
|
---|
96 | {
|
---|
97 | AssertPtr(pMeta->pvMeta);
|
---|
98 | pvTmp = RTMemRealloc(pMeta->pvMeta, cbNewSize);
|
---|
99 | RT_BZERO(pvTmp, cbNewSize);
|
---|
100 | }
|
---|
101 |
|
---|
102 | if (pvTmp)
|
---|
103 | {
|
---|
104 | pMeta->pvMeta = pvTmp;
|
---|
105 | pMeta->cbMeta = cbNewSize;
|
---|
106 | return VINF_SUCCESS;
|
---|
107 | }
|
---|
108 |
|
---|
109 | return VERR_NO_MEMORY;
|
---|
110 | }
|
---|
111 |
|
---|
112 | size_t SharedClipboardMetaDataGetUsed(PSHAREDCLIPBOARDMETADATA pMeta)
|
---|
113 | {
|
---|
114 | AssertPtrReturn(pMeta, VERR_INVALID_POINTER);
|
---|
115 | return pMeta->cbUsed;
|
---|
116 | }
|
---|
117 |
|
---|
118 | size_t SharedClipboardMetaDataGetSize(PSHAREDCLIPBOARDMETADATA pMeta)
|
---|
119 | {
|
---|
120 | AssertPtrReturn(pMeta, VERR_INVALID_POINTER);
|
---|
121 | return pMeta->cbMeta;
|
---|
122 | }
|
---|
123 |
|
---|
124 | const void *SharedClipboardMetaDataRaw(PSHAREDCLIPBOARDMETADATA pMeta)
|
---|
125 | {
|
---|
126 | return pMeta->pvMeta;
|
---|
127 | }
|
---|
128 |
|
---|