VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-internal.h@ 91749

Last change on this file since 91749 was 91749, checked in by vboxsync, 3 years ago

VRDP: Shared Clipboard: delegate clipboard processing to VRDP service when remote RDP clients are connected, bugref:10117.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.0 KB
Line 
1/* $Id: VBoxSharedClipboardSvc-internal.h 91749 2021-10-14 21:02:32Z vboxsync $ */
2/** @file
3 * Shared Clipboard Service - Internal header.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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#ifndef VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h
19#define VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <algorithm>
25#include <list>
26#include <map>
27
28#include <iprt/cpp/list.h> /* For RTCList. */
29#include <iprt/list.h>
30#include <iprt/semaphore.h>
31
32#include <VBox/hgcmsvc.h>
33#include <VBox/log.h>
34
35#include <VBox/HostServices/Service.h>
36#include <VBox/GuestHost/SharedClipboard.h>
37#include <VBox/GuestHost/SharedClipboard-transfers.h>
38
39using namespace HGCM;
40
41#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
42struct SHCLCLIENTSTATE;
43#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
44
45/**
46 * A queued message for the guest.
47 */
48typedef struct _SHCLCLIENTMSG
49{
50 /** The queue list entry. */
51 RTLISTNODE ListEntry;
52 /** Stored message ID (VBOX_SHCL_HOST_MSG_XXX). */
53 uint32_t idMsg;
54 /** Context ID. */
55 uint64_t idCtx;
56 /** Number of stored parameters in aParms. */
57 uint32_t cParms;
58 /** HGCM parameters. */
59 RT_FLEXIBLE_ARRAY_EXTENSION
60 VBOXHGCMSVCPARM aParms[RT_FLEXIBLE_ARRAY];
61} SHCLCLIENTMSG;
62/** Pointer to a queue message for the guest. */
63typedef SHCLCLIENTMSG *PSHCLCLIENTMSG;
64
65typedef struct SHCLCLIENTTRANSFERSTATE
66{
67 /** Directory of the transfer to start. */
68 SHCLTRANSFERDIR enmTransferDir;
69} SHCLCLIENTTRANSFERSTATE, *PSHCLCLIENTTRANSFERSTATE;
70
71/**
72 * Structure for holding a single POD (plain old data) transfer.
73 *
74 * This mostly is plain text, but also can be stuff like bitmap (BMP) or other binary data.
75 */
76typedef struct SHCLCLIENTPODSTATE
77{
78 /** POD transfer direction. */
79 SHCLTRANSFERDIR enmDir;
80 /** Format of the data to be read / written. */
81 SHCLFORMAT uFormat;
82 /** How much data (in bytes) to read/write for the current operation. */
83 uint64_t cbToReadWriteTotal;
84 /** How much data (in bytes) already has been read/written for the current operation. */
85 uint64_t cbReadWritten;
86 /** Timestamp (in ms) of Last read/write operation. */
87 uint64_t tsLastReadWrittenMs;
88} SHCLCLIENTPODSTATE, *PSHCLCLIENTPODSTATE;
89
90/** @name SHCLCLIENTSTATE_FLAGS_XXX
91 * @note Part of saved state!
92 * @{ */
93/** No Shared Clipboard client flags defined. */
94#define SHCLCLIENTSTATE_FLAGS_NONE 0
95/** Client has a guest read operation active. Currently unused. */
96#define SHCLCLIENTSTATE_FLAGS_READ_ACTIVE RT_BIT(0)
97/** Client has a guest write operation active. Currently unused. */
98#define SHCLCLIENTSTATE_FLAGS_WRITE_ACTIVE RT_BIT(1)
99/** @} */
100
101/**
102 * Structure needed to support backwards compatbility for old(er) Guest Additions (< 6.1),
103 * which did not know the context ID concept then.
104 */
105typedef struct SHCLCLIENTLEGACYCID
106{
107 /** List node. */
108 RTLISTNODE Node;
109 /** The actual context ID. */
110 uint64_t uCID;
111 /** Not used yet; useful to have it in the saved state though. */
112 uint32_t enmType;
113 /** @todo Add an union here as soon as we utilize \a enmType. */
114 SHCLFORMAT uFormat;
115} SHCLCLIENTLEGACYCID;
116/** Pointer to a SHCLCLIENTLEGACYCID struct. */
117typedef SHCLCLIENTLEGACYCID *PSHCLCLIENTLEGACYCID;
118
119/**
120 * Structure for keeping legacy state, required for keeping backwards compatibility
121 * to old(er) Guest Additions.
122 */
123typedef struct SHCLCLIENTLEGACYSTATE
124{
125 /** List of context IDs (of type SHCLCLIENTLEGACYCID) for older Guest Additions which (< 6.1)
126 * which did not know the concept of context IDs. */
127 RTLISTANCHOR lstCID;
128 /** Number of context IDs currently in \a lstCID. */
129 uint16_t cCID;
130} SHCLCLIENTLEGACYSTATE;
131
132/**
133 * Structure for keeping generic client state data within the Shared Clipboard host service.
134 * This structure needs to be serializable by SSM (must be a POD type).
135 */
136typedef struct SHCLCLIENTSTATE
137{
138 struct SHCLCLIENTSTATE *pNext;
139 struct SHCLCLIENTSTATE *pPrev;
140
141 SHCLCONTEXT *pCtx;
142
143 /** The client's HGCM ID. Not related to the session ID below! */
144 uint32_t uClientID;
145 /** The client's session ID. */
146 SHCLSESSIONID uSessionID;
147 /** Guest feature flags, VBOX_SHCL_GF_0_XXX. */
148 uint64_t fGuestFeatures0;
149 /** Guest feature flags, VBOX_SHCL_GF_1_XXX. */
150 uint64_t fGuestFeatures1;
151 /** Chunk size to use for data transfers. */
152 uint32_t cbChunkSize;
153 /** Where the transfer sources its data from. */
154 SHCLSOURCE enmSource;
155 /** Client state flags of type SHCLCLIENTSTATE_FLAGS_. */
156 uint32_t fFlags;
157 /** POD (plain old data) state. */
158 SHCLCLIENTPODSTATE POD;
159 /** The client's transfers state. */
160 SHCLCLIENTTRANSFERSTATE Transfers;
161} SHCLCLIENTSTATE, *PSHCLCLIENTSTATE;
162
163typedef struct _SHCLCLIENTCMDCTX
164{
165 uint64_t uContextID;
166} SHCLCLIENTCMDCTX, *PSHCLCLIENTCMDCTX;
167
168#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
169/**
170 * Structure for keeping transfer-related data per HGCM client.
171 */
172typedef struct _SHCLIENTTRANSFERS
173{
174 /** Transfer context. */
175 SHCLTRANSFERCTX Ctx;
176} SHCLIENTTRANSFERS, *PSHCLIENTTRANSFERS;
177#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
178
179/**
180 * Structure for keeping data per (connected) HGCM client.
181 */
182typedef struct _SHCLCLIENT
183{
184 /** General client state data. */
185 SHCLCLIENTSTATE State;
186 /** The critical section protecting the queue, event source and whatnot. */
187 RTCRITSECT CritSect;
188 /** The client's message queue (SHCLCLIENTMSG). */
189 RTLISTANCHOR MsgQueue;
190 /** Number of allocated messages (updated atomically, not under critsect). */
191 uint32_t volatile cMsgAllocated;
192 /** Legacy cruft we have to keep to support old(er) Guest Additions. */
193 SHCLCLIENTLEGACYSTATE Legacy;
194 /** The client's own event source.
195 * Needed for events which are not bound to a specific transfer. */
196 SHCLEVENTSOURCE EventSrc;
197#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
198 SHCLIENTTRANSFERS Transfers;
199#endif
200 /** Structure for keeping the client's pending (deferred return) state.
201 * A client is in a deferred state when it asks for the next HGCM message,
202 * but the service can't provide it yet. That way a client will block (on the guest side, does not return)
203 * until the service can complete the call. */
204 struct
205 {
206 /** The client's HGCM call handle. Needed for completing a deferred call. */
207 VBOXHGCMCALLHANDLE hHandle;
208 /** Message type (function number) to use when completing the deferred call.
209 * A non-0 value means the client is in pending mode. */
210 uint32_t uType;
211 /** Parameter count to use when completing the deferred call. */
212 uint32_t cParms;
213 /** Parameters to use when completing the deferred call. */
214 PVBOXHGCMSVCPARM paParms;
215 } Pending;
216} SHCLCLIENT, *PSHCLCLIENT;
217
218/**
219 * Structure for keeping a single event source map entry.
220 * Currently empty.
221 */
222typedef struct _SHCLEVENTSOURCEMAPENTRY
223{
224} SHCLEVENTSOURCEMAPENTRY;
225
226/** Map holding information about connected HGCM clients. Key is the (unique) HGCM client ID.
227 * The value is a weak pointer to PSHCLCLIENT, which is owned by HGCM. */
228typedef std::map<uint32_t, PSHCLCLIENT> ClipboardClientMap;
229
230/** Map holding information about event sources. Key is the (unique) event source ID. */
231typedef std::map<SHCLEVENTSOURCEID, SHCLEVENTSOURCEMAPENTRY> ClipboardEventSourceMap;
232
233/** Simple queue (list) which holds deferred (waiting) clients. */
234typedef std::list<uint32_t> ClipboardClientQueue;
235
236/**
237 * Structure for keeping the Shared Clipboard service extension state.
238 *
239 * A service extension is optional, and can be installed by a host component
240 * to communicate with the Shared Clipboard host service.
241 */
242typedef struct _SHCLEXTSTATE
243{
244 /** Pointer to the actual service extension handle. */
245 PFNHGCMSVCEXT pfnExtension;
246 /** Opaque pointer to extension-provided data. Don't touch. */
247 void *pvExtension;
248 /** The HGCM client ID currently assigned to this service extension.
249 * At the moment only one HGCM client can be assigned per extension. */
250 uint32_t uClientID;
251 /** Whether the host service is reading clipboard data currently. */
252 bool fReadingData;
253 /** Whether the service extension has sent the clipboard formats while
254 * the the host service is reading clipboard data from it. */
255 bool fDelayedAnnouncement;
256 /** The actual clipboard formats announced while the host service
257 * is reading clipboard data from the extension. */
258 uint32_t fDelayedFormats;
259} SHCLEXTSTATE, *PSHCLEXTSTATE;
260
261extern SHCLEXTSTATE g_ExtState;
262
263int shClSvcSetSource(PSHCLCLIENT pClient, SHCLSOURCE enmSource);
264
265void shClSvcMsgQueueReset(PSHCLCLIENT pClient);
266PSHCLCLIENTMSG shClSvcMsgAlloc(PSHCLCLIENT pClient, uint32_t uMsg, uint32_t cParms);
267void shClSvcMsgFree(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg);
268void shClSvcMsgAdd(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg, bool fAppend);
269int shClSvcMsgAddAndWakeupClient(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg);
270
271int shClSvcClientInit(PSHCLCLIENT pClient, uint32_t uClientID);
272void shClSvcClientDestroy(PSHCLCLIENT pClient);
273void shClSvcClientLock(PSHCLCLIENT pClient);
274void shClSvcClientUnlock(PSHCLCLIENT pClient);
275void shClSvcClientReset(PSHCLCLIENT pClient);
276
277int shClSvcClientStateInit(PSHCLCLIENTSTATE pClientState, uint32_t uClientID);
278int shClSvcClientStateDestroy(PSHCLCLIENTSTATE pClientState);
279void shclSvcClientStateReset(PSHCLCLIENTSTATE pClientState);
280
281int shClSvcClientWakeup(PSHCLCLIENT pClient);
282
283# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
284int shClSvcTransferModeSet(uint32_t fMode);
285int shClSvcTransferStart(PSHCLCLIENT pClient, SHCLTRANSFERDIR enmDir, SHCLSOURCE enmSource, PSHCLTRANSFER *ppTransfer);
286int shClSvcTransferStop(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
287bool shClSvcTransferMsgIsAllowed(uint32_t uMode, uint32_t uMsg);
288void shClSvcClientTransfersReset(PSHCLCLIENT pClient);
289#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
290
291/** @name Service functions, accessible by the backends.
292 * Locking is between the (host) service thread and the platform-dependent (window) thread.
293 * @{
294 */
295int ShClSvcGuestDataRequest(PSHCLCLIENT pClient, SHCLFORMATS fFormats, PSHCLEVENTID pidEvent);
296int ShClSvcGuestDataSignal(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData);
297int ShClSvcHostReportFormats(PSHCLCLIENT pClient, SHCLFORMATS fFormats);
298uint32_t ShClSvcGetMode(void);
299bool ShClSvcGetHeadless(void);
300bool ShClSvcLock(void);
301void ShClSvcUnlock(void);
302
303/**
304 * Checks if the backend is active (@c true), or if VRDE is in control of
305 * the host side.
306 */
307DECLINLINE(bool) ShClSvcIsBackendActive(void)
308{
309 return g_ExtState.pfnExtension == NULL;
310}
311/** @} */
312
313
314/** @name Platform-dependent implementations for the Shared Clipboard host service, called *only* by the host service.
315 * @{
316 */
317/**
318 * Called on initialization.
319 *
320 * @param pTable The HGCM service call and parameter table. Mainly for
321 * adjusting the limits.
322 */
323int ShClBackendInit(VBOXHGCMSVCFNTABLE *pTable);
324
325/**
326 * Called on destruction.
327 */
328void ShClBackendDestroy(void);
329
330/**
331 * Called when a new HGCM client connects.
332 *
333 * @returns VBox status code.
334 * @param pClient Shared Clipboard client context.
335 * @param fHeadless Whether this is a headless connection or not.
336 */
337int ShClBackendConnect(PSHCLCLIENT pClient, bool fHeadless);
338
339/**
340 * Called when a HGCM client disconnects.
341 *
342 * @returns VBox status code.
343 * @param pClient Shared Clipboard client context.
344 */
345int ShClBackendDisconnect(PSHCLCLIENT pClient);
346
347/**
348 * Called when the guest reported available clipboard formats to the host OS.
349 *
350 * @returns VBox status code.
351 * @param pClient Shared Clipboard client context.
352 * @param fFormats The announced formats from the guest,
353 * VBOX_SHCL_FMT_XXX.
354 */
355int ShClBackendFormatAnnounce(PSHCLCLIENT pClient, SHCLFORMATS fFormats);
356
357/**
358 * Called when the guest wants to read host clipboard data.
359 *
360 * @returns VBox status code.
361 * @param pClient Shared Clipboard client context.
362 * @param pCmdCtx Shared Clipboard command context.
363 * @param uFormat Clipboard format to read.
364 * @param pvData Where to return the read clipboard data.
365 * @param cbData Size (in bytes) of buffer where to return the clipboard data.
366 * @param pcbActual Where to return the amount of bytes read.
367 *
368 * @todo Document: Can return VINF_HGCM_ASYNC_EXECUTE to defer returning read
369 * data
370 */
371int ShClBackendReadData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat,
372 void *pvData, uint32_t cbData, uint32_t *pcbActual);
373
374/**
375 * Called when the guest writes clipboard data to the host.
376 *
377 * @returns VBox status code.
378 * @param pClient Shared Clipboard client context.
379 * @param pCmdCtx Shared Clipboard command context.
380 * @param uFormat Clipboard format to write.
381 * @param pvData Clipboard data to write.
382 * @param cbData Size (in bytes) of buffer clipboard data to write.
383 */
384int ShClBackendWriteData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData);
385
386/**
387 * Called when synchronization of the clipboard contents of the host clipboard with the guest is needed.
388 *
389 * @returns VBox status code.
390 * @param pClient Shared Clipboard client context.
391 */
392int ShClBackendSync(PSHCLCLIENT pClient);
393/** @} */
394
395#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
396/** @name Host implementations for Shared Clipboard transfers.
397 * @{
398 */
399/**
400 * Called after a transfer got created.
401 *
402 * @returns VBox status code.
403 * @param pClient Shared Clipboard client context.
404 * @param pTransfer Shared Clipboard transfer created.
405 */
406int ShClBackendTransferCreate(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
407/**
408 * Called before a transfer gets destroyed.
409 *
410 * @returns VBox status code.
411 * @param pClient Shared Clipboard client context.
412 * @param pTransfer Shared Clipboard transfer to destroy.
413 */
414int ShClBackendTransferDestroy(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
415/**
416 * Called when getting (determining) the transfer roots on the host side.
417 *
418 * @returns VBox status code.
419 * @param pClient Shared Clipboard client context.
420 * @param pTransfer Shared Clipboard transfer to get roots for.
421 */
422int ShClBackendTransferGetRoots(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
423/** @} */
424#endif
425
426#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
427/** @name Internal Shared Clipboard transfer host service functions.
428 * @{
429 */
430int shClSvcTransferHandler(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE callHandle, uint32_t u32Function,
431 uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival);
432int shClSvcTransferHostHandler(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
433/** @} */
434
435/** @name Shared Clipboard transfer interface implementations for the host service.
436 * @{
437 */
438#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
439
440#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP */
441
442int shClSvcTransferIfaceGetRoots(PSHCLTXPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList);
443
444int shClSvcTransferIfaceListOpen(PSHCLTXPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList);
445int shClSvcTransferIfaceListClose(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList);
446int shClSvcTransferIfaceListHdrRead(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
447int shClSvcTransferIfaceListHdrWrite(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
448int shClSvcTransferIfaceListEntryRead(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
449int shClSvcTransferIfaceListEntryWrite(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
450
451int shClSvcTransferIfaceObjOpen(PSHCLTXPROVIDERCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms,
452 PSHCLOBJHANDLE phObj);
453int shClSvcTransferIfaceObjClose(PSHCLTXPROVIDERCTX pCtx, SHCLOBJHANDLE hObj);
454int shClSvcTransferIfaceObjRead(PSHCLTXPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
455 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbRead);
456int shClSvcTransferIfaceObjWrite(PSHCLTXPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
457 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbWritten);
458/** @} */
459
460/** @name Shared Clipboard transfer callbacks for the host service.
461 * @{
462 */
463DECLCALLBACK(void) VBoxSvcClipboardTransferPrepareCallback(PSHCLTXPROVIDERCTX pCtx);
464DECLCALLBACK(void) VBoxSvcClipboardDataHeaderCompleteCallback(PSHCLTXPROVIDERCTX pCtx);
465DECLCALLBACK(void) VBoxSvcClipboardDataCompleteCallback(PSHCLTXPROVIDERCTX pCtx);
466DECLCALLBACK(void) VBoxSvcClipboardTransferCompleteCallback(PSHCLTXPROVIDERCTX pCtx, int rc);
467DECLCALLBACK(void) VBoxSvcClipboardTransferCanceledCallback(PSHCLTXPROVIDERCTX pCtx);
468DECLCALLBACK(void) VBoxSvcClipboardTransferErrorCallback(PSHCLTXPROVIDERCTX pCtx, int rc);
469/** @} */
470#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
471
472/* Host unit testing interface */
473#ifdef UNIT_TEST
474uint32_t TestClipSvcGetMode(void);
475#endif
476
477#endif /* !VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h */
478
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