1 | /* $Id: VBoxSharedClipboardSvc-internal.h 79630 2019-07-09 08:14:01Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard Service - Internal header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-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 | #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/list.h>
|
---|
29 | #include <iprt/cpp/list.h> /* For RTCList. */
|
---|
30 |
|
---|
31 | #include <VBox/hgcmsvc.h>
|
---|
32 | #include <VBox/log.h>
|
---|
33 |
|
---|
34 | #include <VBox/HostServices/Service.h>
|
---|
35 | #include <VBox/GuestHost/SharedClipboard.h>
|
---|
36 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
37 | # include <iprt/semaphore.h>
|
---|
38 | # include <VBox/GuestHost/SharedClipboard-uri.h>
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | using namespace HGCM;
|
---|
42 |
|
---|
43 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
44 | /**
|
---|
45 | * Structure for handling a single URI object context.
|
---|
46 | */
|
---|
47 | typedef struct _VBOXCLIPBOARDCLIENTURIOBJCTX
|
---|
48 | {
|
---|
49 | /** Pointer to current object being processed. */
|
---|
50 | SharedClipboardURIObject *pObj;
|
---|
51 | } VBOXCLIPBOARDCLIENTURIOBJCTX, *PVBOXCLIPBOARDCLIENTURIOBJCTX;
|
---|
52 |
|
---|
53 | struct VBOXCLIPBOARDCLIENTSTATE;
|
---|
54 | #endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
|
---|
55 |
|
---|
56 | typedef struct _VBOXCLIPBOARDCLIENTMSG
|
---|
57 | {
|
---|
58 | /** Stored message type. */
|
---|
59 | uint32_t m_uMsg;
|
---|
60 | /** Number of stored HGCM parameters. */
|
---|
61 | uint32_t m_cParms;
|
---|
62 | /** Stored HGCM parameters. */
|
---|
63 | PVBOXHGCMSVCPARM m_paParms;
|
---|
64 | } VBOXCLIPBOARDCLIENTMSG, *PVBOXCLIPBOARDCLIENTMSG;
|
---|
65 |
|
---|
66 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
67 | typedef struct VBOXCLIPBOARDCLIENTURISTATE
|
---|
68 | {
|
---|
69 | /** Whether to start a new transfer. */
|
---|
70 | bool fTransferStart;
|
---|
71 | /** Directory of the transfer to start. */
|
---|
72 | SHAREDCLIPBOARDURITRANSFERDIR enmTransferDir;
|
---|
73 | } VBOXCLIPBOARDCLIENTURISTATE, *PVBOXCLIPBOARDCLIENTURISTATE;
|
---|
74 | #endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Structure for keeping generic client state data within the Shared Clipboard host service.
|
---|
78 | * This structure needs to be serializable by SSM (must be a POD type).
|
---|
79 | */
|
---|
80 | typedef struct VBOXCLIPBOARDCLIENTSTATE
|
---|
81 | {
|
---|
82 | struct VBOXCLIPBOARDCLIENTSTATE *pNext;
|
---|
83 | struct VBOXCLIPBOARDCLIENTSTATE *pPrev;
|
---|
84 |
|
---|
85 | VBOXCLIPBOARDCONTEXT *pCtx;
|
---|
86 |
|
---|
87 | uint32_t u32ClientID;
|
---|
88 |
|
---|
89 | SHAREDCLIPBOARDSOURCE enmSource;
|
---|
90 |
|
---|
91 | /** The guest is waiting for a message. */
|
---|
92 | bool fAsync;
|
---|
93 | /** The guest is waiting for data from the host */
|
---|
94 | bool fReadPending;
|
---|
95 | /** Whether the host host has sent a quit message. */
|
---|
96 | bool fHostMsgQuit;
|
---|
97 | /** Whether the host host has requested reading clipboard data from the guest. */
|
---|
98 | bool fHostMsgReadData;
|
---|
99 | /** Whether the host host has reported its available formats. */
|
---|
100 | bool fHostMsgFormats;
|
---|
101 |
|
---|
102 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
103 | /** The client's URI state. */
|
---|
104 | VBOXCLIPBOARDCLIENTURISTATE URI;
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | struct {
|
---|
108 | VBOXHGCMCALLHANDLE callHandle;
|
---|
109 | uint32_t cParms;
|
---|
110 | VBOXHGCMSVCPARM *paParms;
|
---|
111 | } async;
|
---|
112 |
|
---|
113 | struct {
|
---|
114 | VBOXHGCMCALLHANDLE callHandle;
|
---|
115 | uint32_t cParms;
|
---|
116 | VBOXHGCMSVCPARM *paParms;
|
---|
117 | } asyncRead;
|
---|
118 |
|
---|
119 | struct {
|
---|
120 | void *pv;
|
---|
121 | uint32_t cb;
|
---|
122 | uint32_t u32Format;
|
---|
123 | } data;
|
---|
124 |
|
---|
125 | uint32_t u32AvailableFormats;
|
---|
126 | uint32_t u32RequestedFormat;
|
---|
127 | } VBOXCLIPBOARDCLIENTSTATE, *PVBOXCLIPBOARDCLIENTSTATE;
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Structure for keeping a HGCM client state within the Shared Clipboard host service.
|
---|
131 | */
|
---|
132 | typedef struct _VBOXCLIPBOARDCLIENTDATA
|
---|
133 | {
|
---|
134 | /** General client state data. */
|
---|
135 | VBOXCLIPBOARDCLIENTSTATE State;
|
---|
136 | /** The client's message queue (FIFO). */
|
---|
137 | RTCList<VBOXCLIPBOARDCLIENTMSG *> queueMsg;
|
---|
138 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
139 | /** URI context data. */
|
---|
140 | SHAREDCLIPBOARDURICTX URI;
|
---|
141 | #endif
|
---|
142 | } VBOXCLIPBOARDCLIENTDATA, *PVBOXCLIPBOARDCLIENTDATA;
|
---|
143 |
|
---|
144 | typedef struct _VBOXCLIPBOARDCLIENT
|
---|
145 | {
|
---|
146 | /** The client's HGCM client ID. */
|
---|
147 | uint32_t uClientID;
|
---|
148 | /** Pointer to the client'data, owned by HGCM. */
|
---|
149 | PVBOXCLIPBOARDCLIENTDATA pData;
|
---|
150 | /** Optional protocol version the client uses. Set to 0 by default. */
|
---|
151 | uint32_t uProtocolVer;
|
---|
152 | /** Structure for keeping the client's pending (deferred return) state.
|
---|
153 | * A client is in a deferred state when it asks for the next HGCM message,
|
---|
154 | * but the service can't provide it yet. That way a client will block (on the guest side, does not return)
|
---|
155 | * until the service can complete the call. */
|
---|
156 | struct
|
---|
157 | {
|
---|
158 | /** The client's HGCM call handle. Needed for completing a deferred call. */
|
---|
159 | VBOXHGCMCALLHANDLE hHandle;
|
---|
160 | /** Message type (function number) to use when completing the deferred call.
|
---|
161 | * A non-0 value means the client is in pending mode. */
|
---|
162 | uint32_t uType;
|
---|
163 | /** Parameter count to use when completing the deferred call. */
|
---|
164 | uint32_t cParms;
|
---|
165 | /** Parameters to use when completing the deferred call. */
|
---|
166 | PVBOXHGCMSVCPARM paParms;
|
---|
167 | } Pending;
|
---|
168 | } VBOXCLIPBOARDCLIENT, *PVBOXCLIPBOARDCLIENT;
|
---|
169 |
|
---|
170 | /** Map holding pointers to drag and drop clients. Key is the (unique) HGCM client ID. */
|
---|
171 | typedef std::map<uint32_t, VBOXCLIPBOARDCLIENT *> ClipboardClientMap;
|
---|
172 |
|
---|
173 | /** Simple queue (list) which holds deferred (waiting) clients. */
|
---|
174 | typedef std::list<uint32_t> ClipboardClientQueue;
|
---|
175 |
|
---|
176 | /*
|
---|
177 | * The service functions. Locking is between the service thread and the platform-dependent (window) thread.
|
---|
178 | */
|
---|
179 | int vboxSvcClipboardCompleteReadData(PVBOXCLIPBOARDCLIENTDATA pClientData, int rc, uint32_t cbActual);
|
---|
180 | uint32_t vboxSvcClipboardGetMode(void);
|
---|
181 | int vboxSvcClipboardReportMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t uMsg, uint32_t uFormats);
|
---|
182 | int vboxSvcClipboardSetSource(PVBOXCLIPBOARDCLIENTDATA pClientData, SHAREDCLIPBOARDSOURCE enmSource);
|
---|
183 |
|
---|
184 | void vboxSvcClipboardMsgQueueReset(PVBOXCLIPBOARDCLIENTDATA pClientData);
|
---|
185 | PVBOXCLIPBOARDCLIENTMSG vboxSvcClipboardMsgAlloc(uint32_t uMsg, uint32_t cParms);
|
---|
186 | void vboxSvcClipboardMsgFree(PVBOXCLIPBOARDCLIENTMSG pMsg);
|
---|
187 | void vboxSvcClipboardMsgSetPeekReturn(PVBOXCLIPBOARDCLIENTMSG pMsg, PVBOXHGCMSVCPARM paDstParms, uint32_t cDstParms);
|
---|
188 | int vboxSvcClipboardMsgAdd(PVBOXCLIPBOARDCLIENTDATA pClientData, PVBOXCLIPBOARDCLIENTMSG pMsg, bool fAppend);
|
---|
189 | int vboxSvcClipboardMsgPeek(PVBOXCLIPBOARDCLIENT pClient, VBOXHGCMCALLHANDLE hCall, uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool fWait);
|
---|
190 | int vboxSvcClipboardMsgGet(PVBOXCLIPBOARDCLIENT pClient, VBOXHGCMCALLHANDLE hCall, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
|
---|
191 |
|
---|
192 | int vboxSvcClipboardClientWakeup(PVBOXCLIPBOARDCLIENT pClient);
|
---|
193 |
|
---|
194 | # ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
195 | bool vboxSvcClipboardURIMsgIsAllowed(uint32_t uMode, uint32_t uMsg);
|
---|
196 | int vboxSvcClipboardURIReportMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t u32Msg, uint32_t u32Formats);
|
---|
197 | bool vboxSvcClipboardURIReturnMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
|
---|
198 | # endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
|
---|
199 |
|
---|
200 | /*
|
---|
201 | * Platform-dependent implementations.
|
---|
202 | */
|
---|
203 | int VBoxClipboardSvcImplInit(void);
|
---|
204 | void VBoxClipboardSvcImplDestroy(void);
|
---|
205 |
|
---|
206 | int VBoxClipboardSvcImplConnect(PVBOXCLIPBOARDCLIENTDATA pClientData, bool fHeadless);
|
---|
207 | int VBoxClipboardSvcImplDisconnect(PVBOXCLIPBOARDCLIENTDATA pClientData);
|
---|
208 | int VBoxClipboardSvcImplFormatAnnounce(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t u32Formats);
|
---|
209 | int VBoxClipboardSvcImplReadData(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t u32Format, void *pv, uint32_t cb, uint32_t *pcbActual);
|
---|
210 | int VBoxClipboardSvcImplWriteData(PVBOXCLIPBOARDCLIENTDATA pClientData, void *pv, uint32_t cb, uint32_t u32Format);
|
---|
211 | /**
|
---|
212 | * Synchronise the contents of the host clipboard with the guest, called by the HGCM layer
|
---|
213 | * after a save and restore of the guest.
|
---|
214 | */
|
---|
215 | int VBoxClipboardSvcImplSync(PVBOXCLIPBOARDCLIENTDATA pClientData);
|
---|
216 |
|
---|
217 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
218 | int vboxSvcClipboardURITransferOpen(PSHAREDCLIPBOARDPROVIDERCTX pCtx);
|
---|
219 | int vboxSvcClipboardURITransferClose(PSHAREDCLIPBOARDPROVIDERCTX pCtx);
|
---|
220 |
|
---|
221 | int vboxSvcClipboardURIListOpen(PSHAREDCLIPBOARDPROVIDERCTX pCtx,
|
---|
222 | PVBOXCLIPBOARDLISTHDR pListHdr, PSHAREDCLIPBOARDLISTHANDLE phList);
|
---|
223 | int vboxSvcClipboardURIListClose(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDLISTHANDLE hList);
|
---|
224 | int vboxSvcClipboardURIListHdrRead(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDLISTHANDLE hList,
|
---|
225 | PVBOXCLIPBOARDLISTHDR pListHdr);
|
---|
226 | int vboxSvcClipboardURIListHdrWrite(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDLISTHANDLE hList,
|
---|
227 | PVBOXCLIPBOARDLISTHDR pListHdr);
|
---|
228 | int vboxSvcClipboardURIListEntryRead(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDLISTHANDLE hList,
|
---|
229 | PVBOXCLIPBOARDLISTENTRY pListEntry);
|
---|
230 | int vboxSvcClipboardURIListEntryWrite(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDLISTHANDLE hList,
|
---|
231 | PVBOXCLIPBOARDLISTENTRY pListEntry);
|
---|
232 |
|
---|
233 | int vboxSvcClipboardURIObjOpen(PSHAREDCLIPBOARDPROVIDERCTX pCtx, const char *pszPath,
|
---|
234 | PVBOXCLIPBOARDCREATEPARMS pCreateParms, PSHAREDCLIPBOARDOBJHANDLE phObj);
|
---|
235 | int vboxSvcClipboardURIObjClose(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDOBJHANDLE hObj);
|
---|
236 | int vboxSvcClipboardURIObjRead(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDOBJHANDLE hObj,
|
---|
237 | void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbRead);
|
---|
238 | int vboxSvcClipboardURIObjWrite(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDOBJHANDLE hObj,
|
---|
239 | void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbWritten);
|
---|
240 |
|
---|
241 | DECLCALLBACK(void) VBoxSvcClipboardURITransferPrepareCallback(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData);
|
---|
242 | DECLCALLBACK(void) VBoxSvcClipboardURIDataHeaderCompleteCallback(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData);
|
---|
243 | DECLCALLBACK(void) VBoxSvcClipboardURIDataCompleteCallback(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData);
|
---|
244 | DECLCALLBACK(void) VBoxSvcClipboardURITransferCompleteCallback(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData, int rc);
|
---|
245 | DECLCALLBACK(void) VBoxSvcClipboardURITransferCanceledCallback(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData);
|
---|
246 | DECLCALLBACK(void) VBoxSvcClipboardURITransferErrorCallback(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData, int rc);
|
---|
247 |
|
---|
248 | int VBoxClipboardSvcImplURITransferCreate(PVBOXCLIPBOARDCLIENTDATA pClientData, PSHAREDCLIPBOARDURITRANSFER pTransfer);
|
---|
249 | int VBoxClipboardSvcImplURITransferDestroy(PVBOXCLIPBOARDCLIENTDATA pClientData, PSHAREDCLIPBOARDURITRANSFER pTransfer);
|
---|
250 | #endif
|
---|
251 |
|
---|
252 | /* Host unit testing interface */
|
---|
253 | #ifdef UNIT_TEST
|
---|
254 | uint32_t TestClipSvcGetMode(void);
|
---|
255 | #endif
|
---|
256 |
|
---|
257 | #endif /* !VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h */
|
---|
258 |
|
---|