1 | /* $Id: ClipboardProvider-VbglR3.cpp 78942 2019-06-03 19:10:19Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard - Provider implementation for VbglR3 (guest side).
|
---|
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 | #include <VBox/VBoxGuestLib.h>
|
---|
25 |
|
---|
26 | #include <iprt/asm.h>
|
---|
27 | #include <iprt/assert.h>
|
---|
28 | #include <iprt/dir.h>
|
---|
29 | #include <iprt/errcore.h>
|
---|
30 | #include <iprt/file.h>
|
---|
31 | #include <iprt/path.h>
|
---|
32 | #include <iprt/string.h>
|
---|
33 |
|
---|
34 | #include <VBox/log.h>
|
---|
35 |
|
---|
36 |
|
---|
37 | SharedClipboardProviderVbglR3::SharedClipboardProviderVbglR3(uint32_t uClientID)
|
---|
38 | : m_uClientID(uClientID)
|
---|
39 | {
|
---|
40 | LogFlowFunc(("m_uClientID=%RU32\n", m_uClientID));
|
---|
41 | }
|
---|
42 |
|
---|
43 | SharedClipboardProviderVbglR3::~SharedClipboardProviderVbglR3(void)
|
---|
44 | {
|
---|
45 | m_URIList.Clear();
|
---|
46 | }
|
---|
47 |
|
---|
48 | int SharedClipboardProviderVbglR3::ReadMetaData(uint32_t fFlags /* = 0 */)
|
---|
49 | {
|
---|
50 | RT_NOREF(fFlags);
|
---|
51 |
|
---|
52 | LogFlowFuncEnter();
|
---|
53 |
|
---|
54 | int rc = VbglR3ClipboardReadMetaData(m_uClientID, m_URIList);
|
---|
55 |
|
---|
56 | #ifdef DEBUG_andy_disabled
|
---|
57 | SharedClipboardURIObject *pObj1 = new SharedClipboardURIObject(SharedClipboardURIObject::Type_File, "foobar1.baz");
|
---|
58 | pObj1->SetSize(_64M);
|
---|
59 | m_URIList.AppendURIObject(pObj1);
|
---|
60 |
|
---|
61 | SharedClipboardURIObject *pObj2 = new SharedClipboardURIObject(SharedClipboardURIObject::Type_File, "foobar2.baz");
|
---|
62 | pObj2->SetSize(_32M);
|
---|
63 | m_URIList.AppendURIObject(pObj2);
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | LogFlowFuncLeaveRC(rc);
|
---|
67 | return rc;
|
---|
68 | }
|
---|
69 |
|
---|
70 | int SharedClipboardProviderVbglR3::WriteMetaData(const void *pvBuf, size_t cbBuf, size_t *pcbWritten, uint32_t fFlags /* = 0 */)
|
---|
71 | {
|
---|
72 | RT_NOREF(pcbWritten, fFlags);
|
---|
73 |
|
---|
74 | SHAREDCLIPBOARDURILISTFLAGS fURIListFlags = SHAREDCLIPBOARDURILIST_FLAGS_NONE;
|
---|
75 |
|
---|
76 | int rc = m_URIList.SetFromURIData(pvBuf, cbBuf, fURIListFlags);
|
---|
77 | if (RT_SUCCESS(rc))
|
---|
78 | rc = VbglR3ClipboardWriteMetaData(m_uClientID, m_URIList);
|
---|
79 |
|
---|
80 | LogFlowFuncLeaveRC(rc);
|
---|
81 | return rc;
|
---|
82 | }
|
---|
83 |
|
---|
84 | int SharedClipboardProviderVbglR3::ReadDirectory(PVBOXCLIPBOARDDIRDATA pDirData)
|
---|
85 | {
|
---|
86 | LogFlowFuncEnter();
|
---|
87 |
|
---|
88 | int rc;
|
---|
89 |
|
---|
90 | SharedClipboardURIObject *pObj = m_URIList.First();
|
---|
91 | if (pObj)
|
---|
92 | {
|
---|
93 | rc = VbglR3ClipboardReadDir(m_uClientID, pDirData->pszPath, pDirData->cbPath, &pDirData->cbPath, &pDirData->fMode);
|
---|
94 | }
|
---|
95 | else
|
---|
96 | rc = VERR_WRONG_ORDER;
|
---|
97 |
|
---|
98 | LogFlowFuncLeaveRC(rc);
|
---|
99 | return rc;
|
---|
100 | }
|
---|
101 |
|
---|
102 | int SharedClipboardProviderVbglR3::WriteDirectory(const PVBOXCLIPBOARDDIRDATA pDirData)
|
---|
103 | {
|
---|
104 | LogFlowFuncEnter();
|
---|
105 |
|
---|
106 | int rc;
|
---|
107 |
|
---|
108 | SharedClipboardURIObject *pObj = m_URIList.First();
|
---|
109 | if (pObj)
|
---|
110 | {
|
---|
111 | rc = VbglR3ClipboardWriteDir(m_uClientID, pDirData->pszPath, pDirData->cbPath, pDirData->fMode);
|
---|
112 | }
|
---|
113 | else
|
---|
114 | rc = VERR_WRONG_ORDER;
|
---|
115 |
|
---|
116 | LogFlowFuncLeaveRC(rc);
|
---|
117 | return rc;
|
---|
118 | }
|
---|
119 |
|
---|
120 | int SharedClipboardProviderVbglR3::ReadFileHdr(PVBOXCLIPBOARDFILEHDR pFileHdr)
|
---|
121 | {
|
---|
122 | LogFlowFuncEnter();
|
---|
123 |
|
---|
124 | int rc;
|
---|
125 |
|
---|
126 | SharedClipboardURIObject *pObj = m_URIList.First();
|
---|
127 | if (pObj)
|
---|
128 | {
|
---|
129 | rc = VbglR3ClipboardReadFileHdr(m_uClientID, pFileHdr->pszFilePath, pFileHdr->cbFilePath,
|
---|
130 | &pFileHdr->fFlags, &pFileHdr->fMode, &pFileHdr->cbSize);
|
---|
131 | if (RT_SUCCESS(rc))
|
---|
132 | {
|
---|
133 | rc = pObj->SetFileData(pFileHdr->pszFilePath, SharedClipboardURIObject::View_Target,
|
---|
134 | RTFILE_O_CREATE_REPLACE | RTFILE_O_WRITE, pFileHdr->fMode);
|
---|
135 | if (RT_SUCCESS(rc))
|
---|
136 | rc = pObj->SetSize(pFileHdr->cbSize);
|
---|
137 | }
|
---|
138 | }
|
---|
139 | else
|
---|
140 | rc = VERR_WRONG_ORDER;
|
---|
141 |
|
---|
142 | LogFlowFuncLeaveRC(rc);
|
---|
143 | return rc;
|
---|
144 | }
|
---|
145 |
|
---|
146 | int SharedClipboardProviderVbglR3::WriteFileHdr(const PVBOXCLIPBOARDFILEHDR pFileHdr)
|
---|
147 | {
|
---|
148 | LogFlowFuncEnter();
|
---|
149 |
|
---|
150 | int rc;
|
---|
151 |
|
---|
152 | SharedClipboardURIObject *pObj = m_URIList.First();
|
---|
153 | if (pObj)
|
---|
154 | {
|
---|
155 | rc = VbglR3ClipboardWriteFileHdr(m_uClientID, pFileHdr->pszFilePath, pFileHdr->cbFilePath,
|
---|
156 | pFileHdr->fFlags, pFileHdr->fMode, pFileHdr->cbSize);
|
---|
157 | }
|
---|
158 | else
|
---|
159 | rc = VERR_WRONG_ORDER;
|
---|
160 |
|
---|
161 | LogFlowFuncLeaveRC(rc);
|
---|
162 | return rc;
|
---|
163 | }
|
---|
164 |
|
---|
165 | int SharedClipboardProviderVbglR3::ReadFileData(PVBOXCLIPBOARDFILEDATA pFileData)
|
---|
166 | {
|
---|
167 | LogFlowFuncEnter();
|
---|
168 |
|
---|
169 | int rc;
|
---|
170 |
|
---|
171 | SharedClipboardURIObject *pObj = m_URIList.First();
|
---|
172 | if (pObj)
|
---|
173 | {
|
---|
174 | rc = VbglR3ClipboardReadFileData(m_uClientID, pFileData->pvData, pFileData->cbData, &pFileData->cbData);
|
---|
175 | }
|
---|
176 | else
|
---|
177 | rc = VERR_WRONG_ORDER;
|
---|
178 |
|
---|
179 | LogFlowFuncLeaveRC(rc);
|
---|
180 | return rc;
|
---|
181 | }
|
---|
182 |
|
---|
183 | int SharedClipboardProviderVbglR3::WriteFileData(const PVBOXCLIPBOARDFILEDATA pFileData)
|
---|
184 | {
|
---|
185 | LogFlowFuncEnter();
|
---|
186 |
|
---|
187 | int rc;
|
---|
188 |
|
---|
189 | SharedClipboardURIObject *pObj = m_URIList.First();
|
---|
190 | if (pObj)
|
---|
191 | {
|
---|
192 | uint32_t cbWrittenIgnored;
|
---|
193 | rc = VbglR3ClipboardWriteFileData(m_uClientID, pFileData->pvData, pFileData->cbData, &cbWrittenIgnored);
|
---|
194 | }
|
---|
195 | else
|
---|
196 | rc = VERR_WRONG_ORDER;
|
---|
197 |
|
---|
198 | LogFlowFuncLeaveRC(rc);
|
---|
199 | return rc;
|
---|
200 | }
|
---|
201 |
|
---|
202 | void SharedClipboardProviderVbglR3::Reset(void)
|
---|
203 | {
|
---|
204 | LogFlowFuncEnter();
|
---|
205 |
|
---|
206 | m_URIList.Clear();
|
---|
207 |
|
---|
208 | /* Don't clear the refcount here. */
|
---|
209 | }
|
---|
210 |
|
---|