1 | /* $Id: VBoxSharedClipboardSvc-utils.cpp 79630 2019-07-09 08:14:01Z 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 | */
|
---|
42 | bool 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_GUEST_FN_LIST_OPEN:
|
---|
55 | RT_FALL_THROUGH();
|
---|
56 | case VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_CLOSE:
|
---|
57 | RT_FALL_THROUGH();
|
---|
58 | case VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_HDR_READ:
|
---|
59 | RT_FALL_THROUGH();
|
---|
60 | case VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_ENTRY_READ:
|
---|
61 | RT_FALL_THROUGH();
|
---|
62 | case VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_OPEN:
|
---|
63 | RT_FALL_THROUGH();
|
---|
64 | case VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_CLOSE:
|
---|
65 | RT_FALL_THROUGH();
|
---|
66 | case VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_READ:
|
---|
67 | fAllowed = fHostToGuest;
|
---|
68 | break;
|
---|
69 |
|
---|
70 | case VBOX_SHARED_CLIPBOARD_GUEST_FN_MSG_PEEK_WAIT:
|
---|
71 | RT_FALL_THROUGH();
|
---|
72 | case VBOX_SHARED_CLIPBOARD_GUEST_FN_MSG_PEEK_NOWAIT:
|
---|
73 | RT_FALL_THROUGH();
|
---|
74 | case VBOX_SHARED_CLIPBOARD_GUEST_FN_MSG_GET:
|
---|
75 | RT_FALL_THROUGH();
|
---|
76 | case VBOX_SHARED_CLIPBOARD_GUEST_FN_STATUS:
|
---|
77 | RT_FALL_THROUGH();
|
---|
78 | case VBOX_SHARED_CLIPBOARD_GUEST_FN_CANCEL:
|
---|
79 | RT_FALL_THROUGH();
|
---|
80 | case VBOX_SHARED_CLIPBOARD_GUEST_FN_ERROR:
|
---|
81 | fAllowed = fHostToGuest || fGuestToHost;
|
---|
82 | break;
|
---|
83 |
|
---|
84 | default:
|
---|
85 | break;
|
---|
86 | }
|
---|
87 |
|
---|
88 | fAllowed = true; /** @todo FIX !!!! */
|
---|
89 |
|
---|
90 | LogFlowFunc(("uMsg=%RU32, uMode=%RU32 -> fAllowed=%RTbool\n", uMsg, uMode, fAllowed));
|
---|
91 | return fAllowed;
|
---|
92 | }
|
---|
93 |
|
---|
94 | int vboxSvcClipboardURIReportMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t uMsg, uint32_t uParm)
|
---|
95 | {
|
---|
96 | AssertPtrReturn(pClientData, VERR_INVALID_POINTER);
|
---|
97 |
|
---|
98 | int rc = VINF_SUCCESS;
|
---|
99 |
|
---|
100 | switch (uMsg)
|
---|
101 | {
|
---|
102 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_TRANSFER_START:
|
---|
103 | {
|
---|
104 | LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_TRANSFER_START\n"));
|
---|
105 |
|
---|
106 | if ( vboxSvcClipboardGetMode() != VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST
|
---|
107 | && vboxSvcClipboardGetMode() != VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL)
|
---|
108 | {
|
---|
109 | LogFlowFunc(("Wrong clipboard mode, skipping\n"));
|
---|
110 | break;
|
---|
111 | }
|
---|
112 |
|
---|
113 | pClientData->State.URI.fTransferStart = true;
|
---|
114 | pClientData->State.URI.enmTransferDir = (SHAREDCLIPBOARDURITRANSFERDIR)uParm;
|
---|
115 | break;
|
---|
116 |
|
---|
117 | }
|
---|
118 |
|
---|
119 | default:
|
---|
120 | AssertMsgFailed(("Invalid message %RU32\n", uMsg));
|
---|
121 | rc = VERR_INVALID_PARAMETER;
|
---|
122 | break;
|
---|
123 | }
|
---|
124 |
|
---|
125 | LogFlowFuncLeaveRC(rc);
|
---|
126 | return rc;
|
---|
127 | }
|
---|
128 |
|
---|
129 | bool vboxSvcClipboardURIReturnMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
|
---|
130 | {
|
---|
131 | RT_NOREF(pClientData, cParms, paParms);
|
---|
132 |
|
---|
133 | bool fHandled = false;
|
---|
134 |
|
---|
135 | if ( pClientData->State.URI.fTransferStart
|
---|
136 | && cParms >= 2)
|
---|
137 | {
|
---|
138 | HGCMSvcSetU32(&paParms[0], VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_TRANSFER_START);
|
---|
139 | HGCMSvcSetU32(&paParms[1], pClientData->State.URI.enmTransferDir);
|
---|
140 | pClientData->State.URI.fTransferStart = false;
|
---|
141 |
|
---|
142 | fHandled = true;
|
---|
143 | }
|
---|
144 |
|
---|
145 | #if 1
|
---|
146 | int rc = 0;
|
---|
147 | #else
|
---|
148 | /* Sanity. */
|
---|
149 | Assert(pTransfer->State.enmDir == SHAREDCLIPBOARDURITRANSFERDIR_READ);
|
---|
150 |
|
---|
151 | int rc;
|
---|
152 |
|
---|
153 | /* Note: Message priority / order is taken into account here. */
|
---|
154 | if (pTransfer->State.pHeader)
|
---|
155 | {
|
---|
156 | LogFlowFunc(("VBOX_SHARED_CLIPBOARD_GUEST_FN_READ_DATA_HDR\n"));
|
---|
157 | rc = VBoxSvcClipboardURIWriteListHdr(cParms, paParms, pTransfer->State.pHeader);
|
---|
158 | if (RT_SUCCESS(rc))
|
---|
159 | {
|
---|
160 | /* We're done witht the data header, destroy it. */
|
---|
161 | SharedClipboardURIListHdrFree(pTransfer->State.pHeader);
|
---|
162 | pTransfer->State.pHeader = NULL;
|
---|
163 |
|
---|
164 | fHandled = true;
|
---|
165 | }
|
---|
166 | }
|
---|
167 | else if (pTransfer->State.pMeta)
|
---|
168 | {
|
---|
169 | LogFlowFunc(("VBOX_SHARED_CLIPBOARD_GUEST_FN_READ_DATA_CHUNK\n"));
|
---|
170 |
|
---|
171 | uint32_t cbBuf = _64K;
|
---|
172 | uint8_t pvBuf[_64K]; /** @todo Improve */
|
---|
173 |
|
---|
174 | uint32_t cbRead;
|
---|
175 | rc = SharedClipboardMetaDataRead(pTransfer->State.pMeta, pvBuf, cbBuf, &cbRead);
|
---|
176 | if (RT_SUCCESS(rc))
|
---|
177 | {
|
---|
178 | Assert(cbRead <= cbBuf);
|
---|
179 |
|
---|
180 | VBOXCLIPBOARDListEntry ListEntry;
|
---|
181 | RT_ZERO(ListEntry);
|
---|
182 | ListEntry.pvData = pvBuf;
|
---|
183 | ListEntry.cbData = cbRead;
|
---|
184 |
|
---|
185 | rc = VBoxSvcClipboardURIWriteListEntry(cParms, paParms, &ListEntry);
|
---|
186 | }
|
---|
187 |
|
---|
188 | /* Has all meta data been read? */
|
---|
189 | if (RT_SUCCESS(rc))
|
---|
190 | {
|
---|
191 | if (SharedClipboardMetaDataGetUsed(pTransfer->State.pMeta) == 0)
|
---|
192 | {
|
---|
193 | SharedClipboardMetaDataFree(pTransfer->State.pMeta);
|
---|
194 | pTransfer->State.pMeta = NULL;
|
---|
195 | }
|
---|
196 |
|
---|
197 | fHandled = true;
|
---|
198 | }
|
---|
199 | }
|
---|
200 | else if (pTransfer->pURIList)
|
---|
201 | {
|
---|
202 | PSHAREDCLIPBOARDCLIENTURIOBJCTX pObjCtx = SharedClipboardURITransferGetCurrentObjCtx(pTransfer);
|
---|
203 | if (!SharedClipboardURIObjCtxIsValid(pObjCtx))
|
---|
204 | {
|
---|
205 | if (!pTransfer->pURIList->IsEmpty())
|
---|
206 | pObjCtx->pObj = pTransfer->pURIList->First();
|
---|
207 | }
|
---|
208 |
|
---|
209 | if ( pObjCtx
|
---|
210 | && pObjCtx->pObj)
|
---|
211 | {
|
---|
212 | switch (pObjCtx->pObj->GetType())
|
---|
213 | {
|
---|
214 | case SharedClipboardURIObject::Type_Directory:
|
---|
215 | {
|
---|
216 | rc = VBoxSvcClipboardURIWriteDir(cParms, paParms, &ListEntry);
|
---|
217 | break;
|
---|
218 | }
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | if (0)
|
---|
223 | {
|
---|
224 | delete pTransfer->pURIList;
|
---|
225 | pTransfer->pURIList = NULL;
|
---|
226 | }
|
---|
227 |
|
---|
228 | fHandled = true;
|
---|
229 | }
|
---|
230 | else
|
---|
231 | rc = VERR_WRONG_ORDER;
|
---|
232 | #endif
|
---|
233 |
|
---|
234 | LogFlowFunc(("rc=%Rrc, fHandled=%RTbool\n", rc, fHandled));
|
---|
235 | return fHandled;
|
---|
236 | }
|
---|
237 | #endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
|
---|
238 |
|
---|