VirtualBox

source: vbox/trunk/include/VBox/GuestHost/SharedClipboard-uri.h@ 78570

Last change on this file since 78570 was 78501, 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: 10.8 KB
Line 
1/* $Id: SharedClipboard-uri.h 78501 2019-05-14 11:36:25Z vboxsync $ */
2/** @file
3 * Shared Clipboard - Shared URI functions between host and guest.
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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef VBOX_INCLUDED_GuestHost_SharedClipboard_uri_h
28#define VBOX_INCLUDED_GuestHost_SharedClipboard_uri_h
29#ifndef RT_WITHOUT_PRAGMA_ONCE
30# pragma once
31#endif
32
33#include <iprt/assert.h>
34#include <iprt/critsect.h>
35#include <iprt/fs.h>
36
37#include <iprt/cpp/list.h>
38#include <iprt/cpp/ministring.h>
39
40/** SharedClipboardCache flags. */
41typedef uint32_t SHAREDCLIPBOARDCACHEFLAGS;
42
43/** No flags specified. */
44#define SHAREDCLIPBOARDCACHE_FLAGS_NONE 0
45
46/**
47 * Class for maintaining a Shared Clipboard cache
48 * on the host or guest. This will contain all received files & directories
49 * for a single Shared Clipboard operation.
50 *
51 * In case of a failed Shared Clipboard operation this class can also
52 * perform a gentle rollback if required.
53 */
54class SharedClipboardCache
55{
56
57public:
58
59 SharedClipboardCache(void);
60 SharedClipboardCache(const char *pszPath, SHAREDCLIPBOARDCACHEFLAGS fFlags = SHAREDCLIPBOARDCACHE_FLAGS_NONE);
61 virtual ~SharedClipboardCache(void);
62
63public:
64
65 uint16_t AddRef(void);
66 uint16_t Release(void);
67
68 int Lock(void);
69 int Unlock(void);
70
71 int AddFile(const char *pszFile);
72 int AddDir(const char *pszDir);
73 int Close(void);
74 bool IsOpen(void) const;
75 int OpenEx(const char *pszPath, SHAREDCLIPBOARDCACHEFLAGS fFlags = SHAREDCLIPBOARDCACHE_FLAGS_NONE);
76 int OpenTemp(SHAREDCLIPBOARDCACHEFLAGS fFlags = SHAREDCLIPBOARDCACHE_FLAGS_NONE);
77 const char *GetDirAbs(void) const;
78 int Reopen(void);
79 int Reset(bool fDeleteContent);
80 int Rollback(void);
81
82protected:
83
84 int initInternal(void);
85 int destroyInternal(void);
86 int closeInternal(void);
87
88protected:
89
90 /** Number of references to this instance. */
91 volatile uint16_t m_cRefs;
92 /** Critical section for serializing access. */
93 RTCRITSECT m_CritSect;
94 /** Open flags. */
95 uint32_t m_fOpen;
96 /** Directory handle for drop directory. */
97 RTDIR m_hDir;
98 /** Absolute path to drop directory. */
99 RTCString m_strPathAbs;
100 /** List for holding created directories in the case of a rollback. */
101 RTCList<RTCString> m_lstDirs;
102 /** List for holding created files in the case of a rollback. */
103 RTCList<RTCString> m_lstFiles;
104};
105
106int SharedClipboardPathSanitizeFilename(char *pszPath, size_t cbPath);
107int SharedClipboardPathSanitize(char *pszPath, size_t cbPath);
108
109/** SharedClipboardURIObject flags. */
110typedef uint32_t SHAREDCLIPBOARDURIOBJECTFLAGS;
111
112/** No flags specified. */
113#define SHAREDCLIPBOARDURIOBJECT_FLAGS_NONE 0
114
115/** Mask of all valid Shared Clipboard URI object flags. */
116#define SHAREDCLIPBOARDURIOBJECT_FLAGS_VALID_MASK UINT32_C(0x0)
117
118/**
119 * Class for handling Shared Clipboard URI objects.
120 * This class abstracts the access and handling objects when performing Shared Clipboard actions.
121 */
122class SharedClipboardURIObject
123{
124public:
125
126 /**
127 * Enumeration for specifying an URI object type.
128 */
129 enum Type
130 {
131 /** Unknown type, do not use. */
132 Type_Unknown = 0,
133 /** Object is a file. */
134 Type_File,
135 /** Object is a directory. */
136 Type_Directory,
137 /** The usual 32-bit hack. */
138 Type_32Bit_Hack = 0x7fffffff
139 };
140
141 /**
142 * Enumeration for specifying an URI object view
143 * for representing its data accordingly.
144 */
145 enum View
146 {
147 /** Unknown view, do not use. */
148 View_Unknown = 0,
149 /** Handle data from the source point of view. */
150 View_Source,
151 /** Handle data from the destination point of view. */
152 View_Target,
153 /** The usual 32-bit hack. */
154 View_Dest_32Bit_Hack = 0x7fffffff
155 };
156
157 SharedClipboardURIObject(void);
158 SharedClipboardURIObject(Type type,
159 const RTCString &strSrcPathAbs = "",
160 const RTCString &strDstPathAbs = "");
161 virtual ~SharedClipboardURIObject(void);
162
163public:
164
165 /**
166 * Returns the given absolute source path of the object.
167 *
168 * @return Absolute source path of the object.
169 */
170 const RTCString &GetSourcePathAbs(void) const { return m_strSrcPathAbs; }
171
172 /**
173 * Returns the given, absolute destination path of the object.
174 *
175 * @return Absolute destination path of the object.
176 */
177 const RTCString &GetDestPathAbs(void) const { return m_strTgtPathAbs; }
178
179 RTFMODE GetMode(void) const;
180
181 uint64_t GetProcessed(void) const;
182
183 uint64_t GetSize(void) const;
184
185 /**
186 * Returns the object's type.
187 *
188 * @return The object's type.
189 */
190 Type GetType(void) const { return m_enmType; }
191
192 /**
193 * Returns the object's view.
194 *
195 * @return The object's view.
196 */
197 View GetView(void) const { return m_enmView; }
198
199public:
200
201 int SetSize(uint64_t cbSize);
202
203public:
204
205 void Close(void);
206 bool IsComplete(void) const;
207 bool IsOpen(void) const;
208 int Open(View enmView, uint64_t fOpen, RTFMODE fMode = 0);
209 int OpenEx(const RTCString &strPath, View enmView, uint64_t fOpen = 0, RTFMODE fMode = 0, SHAREDCLIPBOARDURIOBJECTFLAGS = SHAREDCLIPBOARDURIOBJECT_FLAGS_NONE);
210 int QueryInfo(View enmView);
211 int Read(void *pvBuf, size_t cbBuf, uint32_t *pcbRead);
212 void Reset(void);
213 int Write(const void *pvBuf, size_t cbBuf, uint32_t *pcbWritten);
214
215public:
216
217 static int RebaseURIPath(RTCString &strPath, const RTCString &strBaseOld = "", const RTCString &strBaseNew = "");
218
219protected:
220
221 void closeInternal(void);
222 int queryInfoInternal(View enmView);
223
224protected:
225
226 /** The object's type. */
227 Type m_enmType;
228 /** The object's view. */
229 View m_enmView;
230 /** Absolute path (base) for the source. */
231 RTCString m_strSrcPathAbs;
232 /** Absolute path (base) for the target. */
233 RTCString m_strTgtPathAbs;
234
235 /** Union containing data depending on the object's type. */
236 union
237 {
238 /** Structure containing members for objects that
239 * are files. */
240 struct
241 {
242 /** File handle. */
243 RTFILE hFile;
244 /** File system object information of this file. */
245 RTFSOBJINFO objInfo;
246 /** Bytes to proces for reading/writing. */
247 uint64_t cbToProcess;
248 /** Bytes processed reading/writing. */
249 uint64_t cbProcessed;
250 } File;
251 struct
252 {
253 /** Directory handle. */
254 RTDIR hDir;
255 /** File system object information of this directory. */
256 RTFSOBJINFO objInfo;
257 } Dir;
258 } u;
259};
260
261/** SharedClipboardURIList flags. */
262typedef uint32_t SHAREDCLIPBOARDURILISTFLAGS;
263
264/** No flags specified. */
265#define SHAREDCLIPBOARDURILIST_FLAGS_NONE 0
266/** Keep the original paths, don't convert paths to relative ones. */
267#define SHAREDCLIPBOARDURILIST_FLAGS_ABSOLUTE_PATHS RT_BIT(0)
268/** Resolve all symlinks. */
269#define SHAREDCLIPBOARDURILIST_FLAGS_RESOLVE_SYMLINKS RT_BIT(1)
270/** Keep the files + directory entries open while
271 * being in this list. */
272#define SHAREDCLIPBOARDURILIST_FLAGS_KEEP_OPEN RT_BIT(2)
273/** Lazy loading: Only enumerate sub directories when needed.
274 ** @todo Implement lazy loading. */
275#define SHAREDCLIPBOARDURILIST_FLAGS_LAZY RT_BIT(3)
276
277/** Mask of all valid Shared Clipboard URI list flags. */
278#define SHAREDCLIPBOARDURILIST_FLAGS_VALID_MASK UINT32_C(0xF)
279
280class SharedClipboardURIList
281{
282public:
283
284 SharedClipboardURIList(void);
285 virtual ~SharedClipboardURIList(void);
286
287public:
288
289 int AppendNativePath(const char *pszPath, SHAREDCLIPBOARDURILISTFLAGS fFlags);
290 int AppendNativePathsFromList(const char *pszNativePaths, size_t cbNativePaths, SHAREDCLIPBOARDURILISTFLAGS fFlags);
291 int AppendNativePathsFromList(const RTCList<RTCString> &lstNativePaths, SHAREDCLIPBOARDURILISTFLAGS fFlags);
292 int AppendURIPath(const char *pszURI, SHAREDCLIPBOARDURILISTFLAGS fFlags);
293 int AppendURIPathsFromList(const char *pszURIPaths, size_t cbURIPaths, SHAREDCLIPBOARDURILISTFLAGS fFlags);
294 int AppendURIPathsFromList(const RTCList<RTCString> &lstURI, SHAREDCLIPBOARDURILISTFLAGS fFlags);
295
296 void Clear(void);
297 SharedClipboardURIObject *First(void) { return m_lstTree.first(); }
298 bool IsEmpty(void) const { return m_lstTree.isEmpty(); }
299 void RemoveFirst(void);
300 int SetFromURIData(const void *pvData, size_t cbData, SHAREDCLIPBOARDURILISTFLAGS fFlags);
301
302 RTCString GetRootEntries(const RTCString &strPathBase = "", const RTCString &strSeparator = "\r\n") const;
303 uint64_t GetRootCount(void) const { return m_lstRoot.size(); }
304 uint64_t GetTotalCount(void) const { return m_cTotal; }
305 uint64_t GetTotalBytes(void) const { return m_cbTotal; }
306
307protected:
308
309 int addEntry(const char *pcszSource, const char *pcszTarget, SHAREDCLIPBOARDURILISTFLAGS fFlags);
310 int appendPathRecursive(const char *pcszSrcPath, const char *pcszDstPath, const char *pcszDstBase, size_t cchDstBase, SHAREDCLIPBOARDURILISTFLAGS fFlags);
311
312protected:
313
314 /** List of all top-level file/directory entries.
315 * Note: All paths are kept internally as UNIX paths for
316 * easier conversion/handling! */
317 RTCList<RTCString> m_lstRoot;
318 /** List of all URI objects added. The list's content
319 * might vary depending on how the objects are being
320 * added (lazy or not). */
321 RTCList<SharedClipboardURIObject *> m_lstTree;
322 /** Total number of all URI objects. */
323 uint64_t m_cTotal;
324 /** Total size of all URI objects, that is, the file
325 * size of all objects (in bytes).
326 * Note: Do *not* size_t here, as we also want to support large files
327 * on 32-bit guests. */
328 uint64_t m_cbTotal;
329};
330
331#endif /* !VBOX_INCLUDED_GuestHost_SharedClipboard_uri_h */
332
Note: See TracBrowser for help on using the repository browser.

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