VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-utils.cpp@ 79449

Last change on this file since 79449 was 79347, checked in by vboxsync, 6 years ago

Shared Clipboard/URI: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 8.8 KB
Line 
1/* $Id: VBoxSharedClipboardSvc-utils.cpp 79347 2019-06-26 09:15:29Z vboxsync $ */
2/** @file
3 * Shared Clipboard Service - Host service utility 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/log.h>
24
25#include <VBox/HostServices/VBoxClipboardSvc.h>
26#include <VBox/HostServices/VBoxClipboardExt.h>
27
28#include <iprt/errcore.h>
29#include <iprt/path.h>
30
31#include "VBoxSharedClipboardSvc-internal.h"
32
33
34#ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
35/**
36 * Returns whether a HGCM message is allowed in a certain service mode or not.
37 *
38 * @returns \c true if message is allowed, \c false if not.
39 * @param uMode Service mode to check allowance for.
40 * @param uMsg HGCM message to check allowance for.
41 */
42bool vboxSvcClipboardURIMsgIsAllowed(uint32_t uMode, uint32_t uMsg)
43{
44 const bool fHostToGuest = uMode == VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST
45 || uMode == VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
46
47 const bool fGuestToHost = uMode == VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST
48 || uMode == VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
49
50 bool fAllowed = false; /* If in doubt, don't allow. */
51
52 switch (uMsg)
53 {
54 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_HDR:
55 RT_FALL_THROUGH();
56 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_CHUNK:
57 RT_FALL_THROUGH();
58 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DIR:
59 RT_FALL_THROUGH();
60 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_HDR:
61 RT_FALL_THROUGH();
62 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_DATA:
63 fAllowed = fGuestToHost;
64 break;
65
66 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_HDR:
67 RT_FALL_THROUGH();
68 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_CHUNK:
69 RT_FALL_THROUGH();
70 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DIR:
71 RT_FALL_THROUGH();
72 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_HDR:
73 RT_FALL_THROUGH();
74 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_DATA:
75 fAllowed = fHostToGuest;
76 break;
77
78 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_CANCEL:
79 RT_FALL_THROUGH();
80 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ERROR:
81 fAllowed = fHostToGuest || fGuestToHost;
82 break;
83
84 default:
85 break;
86 }
87
88 LogFlowFunc(("uMsg=%RU32, uMode=%RU32 -> fAllowed=%RTbool\n", uMsg, uMode, fAllowed));
89 return fAllowed;
90}
91
92int vboxSvcClipboardURIReportMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t uMsg, uint32_t uFormats)
93{
94 AssertPtrReturn(pClientData, VERR_INVALID_POINTER);
95
96 RT_NOREF(uFormats);
97
98 if (!vboxSvcClipboardURIMsgIsAllowed(vboxSvcClipboardGetMode(), uMsg))
99 return VERR_ACCESS_DENIED;
100
101 int rc = VINF_SUCCESS;
102
103 switch (uMsg)
104 {
105 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_HDR:
106 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_HDR\n"));
107 break;
108 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_HDR:
109 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_HDR\n"));
110 break;
111 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_CHUNK:
112 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_CHUNK\n"));
113 break;
114 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_CHUNK:
115 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_CHUNK\n"));
116 break;
117 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DIR:
118 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DIR\n"));
119 break;
120 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DIR:
121 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DIR\n"));
122 break;
123 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_HDR:
124 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_HDR\n"));
125 break;
126 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_HDR:
127 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_HDR\n"));
128 break;
129 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_DATA:
130 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_DATA\n"));
131 break;
132 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_DATA:
133 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_DATA\n"));
134 break;
135 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_CANCEL:
136 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_CANCEL\n"));
137 break;
138 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ERROR:
139 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ERROR\n"));
140 break;
141
142 default:
143 AssertMsgFailed(("Invalid message %RU32\n", uMsg));
144 rc = VERR_INVALID_PARAMETER;
145 break;
146 }
147
148 LogFlowFuncLeaveRC(rc);
149 return rc;
150}
151
152static bool s_fReqHdr = false;
153
154bool vboxSvcClipboardURIReturnMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
155{
156 RT_NOREF(pClientData, cParms, paParms);
157
158 bool fHandled = false;
159
160 /* For now we only support one transfer at a time. */
161 PSHAREDCLIPBOARDURITRANSFER pTransfer = SharedClipboardURICtxGetTransfer(&pClientData->URI, 0 /* Index */);
162 if (!pTransfer)
163 return fHandled;
164
165#if 1
166 int rc = 0;
167#else
168 /* Sanity. */
169 Assert(pTransfer->State.enmDir == SHAREDCLIPBOARDURITRANSFERDIR_READ);
170
171 int rc;
172
173 /* Note: Message priority / order is taken into account here. */
174 if (pTransfer->State.pHeader)
175 {
176 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_GUEST_FN_READ_DATA_HDR\n"));
177 rc = VBoxSvcClipboardURIWriteDataHdr(cParms, paParms, pTransfer->State.pHeader);
178 if (RT_SUCCESS(rc))
179 {
180 /* We're done witht the data header, destroy it. */
181 SharedClipboardURIDataHdrFree(pTransfer->State.pHeader);
182 pTransfer->State.pHeader = NULL;
183
184 fHandled = true;
185 }
186 }
187 else if (pTransfer->State.pMeta)
188 {
189 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_GUEST_FN_READ_DATA_CHUNK\n"));
190
191 uint32_t cbBuf = _64K;
192 uint8_t pvBuf[_64K]; /** @todo Improve */
193
194 uint32_t cbRead;
195 rc = SharedClipboardMetaDataRead(pTransfer->State.pMeta, pvBuf, cbBuf, &cbRead);
196 if (RT_SUCCESS(rc))
197 {
198 Assert(cbRead <= cbBuf);
199
200 VBOXCLIPBOARDDATACHUNK dataChunk;
201 RT_ZERO(dataChunk);
202 dataChunk.pvData = pvBuf;
203 dataChunk.cbData = cbRead;
204
205 rc = VBoxSvcClipboardURIWriteDataChunk(cParms, paParms, &dataChunk);
206 }
207
208 /* Has all meta data been read? */
209 if (RT_SUCCESS(rc))
210 {
211 if (SharedClipboardMetaDataGetUsed(pTransfer->State.pMeta) == 0)
212 {
213 SharedClipboardMetaDataFree(pTransfer->State.pMeta);
214 pTransfer->State.pMeta = NULL;
215 }
216
217 fHandled = true;
218 }
219 }
220 else if (pTransfer->pURIList)
221 {
222 PSHAREDCLIPBOARDCLIENTURIOBJCTX pObjCtx = SharedClipboardURITransferGetCurrentObjCtx(pTransfer);
223 if (!SharedClipboardURIObjCtxIsValid(pObjCtx))
224 {
225 if (!pTransfer->pURIList->IsEmpty())
226 pObjCtx->pObj = pTransfer->pURIList->First();
227 }
228
229 if ( pObjCtx
230 && pObjCtx->pObj)
231 {
232 switch (pObjCtx->pObj->GetType())
233 {
234 case SharedClipboardURIObject::Type_Directory:
235 {
236 rc = VBoxSvcClipboardURIWriteDir(cParms, paParms, &dataChunk);
237 break;
238 }
239 }
240 }
241
242 if (0)
243 {
244 delete pTransfer->pURIList;
245 pTransfer->pURIList = NULL;
246 }
247
248 fHandled = true;
249 }
250 else
251 rc = VERR_WRONG_ORDER;
252#endif
253
254 LogFlowFunc(("rc=%Rrc, fHandled=%RTbool\n", rc, fHandled));
255 return fHandled;
256}
257#endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
258
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette