VirtualBox

source: vbox/trunk/include/VBox/GuestHost/DragAndDrop.h@ 97039

Last change on this file since 97039 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.8 KB
Line 
1/* $Id: DragAndDrop.h 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * DnD - Shared functions between host and guest.
4 */
5
6/*
7 * Copyright (C) 2014-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef VBOX_INCLUDED_GuestHost_DragAndDrop_h
38#define VBOX_INCLUDED_GuestHost_DragAndDrop_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#include <iprt/assert.h>
44#include <iprt/fs.h>
45#include <iprt/list.h>
46
47#include <VBox/GuestHost/DragAndDropDefs.h>
48
49/** DnDURIDroppedFiles flags. */
50typedef uint32_t DNDURIDROPPEDFILEFLAGS;
51
52/** No flags specified. */
53#define DNDURIDROPPEDFILE_FLAGS_NONE 0
54
55/**
56 * Structure for keeping a DnD dropped files entry.
57 */
58typedef struct DNDDROPPEDFILESENTRY
59{
60 RTLISTNODE Node;
61 char *pszPath;
62} DNDDROPPEDFILESENTRY;
63/** Pointer to a DnD dropped files entry. */
64typedef DNDDROPPEDFILESENTRY *PDNDDROPPEDFILESENTRY;
65
66/**
67 * Structure for maintaining a "dropped files" directory
68 * on the host or guest. This will contain all received files & directories
69 * for a single drag and drop operation.
70 *
71 * In case of a failed drag and drop operation this can also
72 * perform a gentle rollback if required.
73 */
74typedef struct DNDDROPPEDFILES
75{
76 /** Open flags. */
77 uint32_t m_fOpen;
78 /** Directory handle for drop directory. */
79 RTDIR m_hDir;
80 /** Absolute path to drop directory. */
81 char *pszPathAbs;
82 /** List for holding created directories in the case of a rollback. */
83 RTLISTANCHOR m_lstDirs;
84 /** List for holding created files in the case of a rollback. */
85 RTLISTANCHOR m_lstFiles;
86} DNDDROPPEDFILES;
87/** Pointer to a DnD dropped files directory. */
88typedef DNDDROPPEDFILES *PDNDDROPPEDFILES;
89
90int DnDDroppedFilesInit(PDNDDROPPEDFILES pDF);
91int DnDDroppedFilesInitEx(PDNDDROPPEDFILES pDF, const char *pszPath, DNDURIDROPPEDFILEFLAGS fFlags);
92void DnDDroppedFilesDestroy(PDNDDROPPEDFILES pDF);
93int DnDDroppedFilesAddFile(PDNDDROPPEDFILES pDF, const char *pszFile);
94int DnDDroppedFilesAddDir(PDNDDROPPEDFILES pDF, const char *pszDir);
95int DnDDroppedFilesClose(PDNDDROPPEDFILES pDF);
96bool DnDDroppedFilesIsOpen(PDNDDROPPEDFILES pDF);
97int DnDDroppedFilesOpenEx(PDNDDROPPEDFILES pDF, const char *pszPath, DNDURIDROPPEDFILEFLAGS fFlags);
98int DnDDroppedFilesOpenTemp(PDNDDROPPEDFILES pDF, DNDURIDROPPEDFILEFLAGS fFlags);
99const char *DnDDroppedFilesGetDirAbs(PDNDDROPPEDFILES pDF);
100int DnDDroppedFilesReopen(PDNDDROPPEDFILES pDF);
101int DnDDroppedFilesReset(PDNDDROPPEDFILES pDF, bool fDelete);
102int DnDDroppedFilesRollback(PDNDDROPPEDFILES pDF);
103
104const char *DnDActionToStr(VBOXDNDACTION uAction);
105
106bool DnDMIMEHasFileURLs(const char *pcszFormat, size_t cchFormatMax);
107bool DnDMIMENeedsDropDir(const char *pcszFormat, size_t cchFormatMax);
108
109int DnDPathValidate(const char *pcszPath, bool fMustExist);
110
111/** DnD path conversion flags. */
112typedef uint32_t DNDPATHCONVERTFLAGS;
113
114/** No flags specified.
115 * This will convert the path to the universal tansport style. */
116#define DNDPATHCONVERT_FLAGS_TRANSPORT 0
117/** Converts the path to a OS-dependent path. */
118#define DNDPATHCONVERT_FLAGS_TO_DOS RT_BIT(0)
119
120/** Mask of all valid DnD path conversion flags. */
121#define DNDPATHCONVERT_FLAGS_VALID_MASK UINT32_C(0x1)
122
123int DnDPathConvert(char *pszPath, size_t cbPath, DNDPATHCONVERTFLAGS fFlags);
124int DnDPathSanitizeFileName(char *pszPath, size_t cbPath);
125int DnDPathRebase(const char *pcszPathAbs, const char *pcszBaseOld, const char *pcszBaseNew, char **ppszPath);
126
127/** DnDTransferObject flags. */
128typedef uint32_t DNDTRANSFEROBJECTFLAGS;
129
130/** No flags specified. */
131#define DNDTRANSFEROBJECT_FLAGS_NONE 0
132
133/** Mask of all valid DnD transfer object flags. */
134#define DNDTRANSFEROBJECT_FLAGS_VALID_MASK UINT32_C(0x0)
135
136/**
137 * Enumeration for specifying a transfer object type.
138 */
139typedef enum DNDTRANSFEROBJTYPE
140{
141 /** Unknown type, do not use. */
142 DNDTRANSFEROBJTYPE_UNKNOWN = 0,
143 /** Object is a file. */
144 DNDTRANSFEROBJTYPE_FILE,
145 /** Object is a directory. */
146 DNDTRANSFEROBJTYPE_DIRECTORY,
147 /** The usual 32-bit hack. */
148 DNDTRANSFEROBJTYPE_32BIT_HACK = 0x7fffffff
149} DNDTRANSFEROBJTYPE;
150
151/**
152 * Enumeration for specifying a path style.
153 */
154typedef enum DNDTRANSFEROBJPATHSTYLE
155{
156 /** Transport style (UNIX-y), the default. */
157 DNDTRANSFEROBJPATHSTYLE_TRANSPORT = 0,
158 /** DOS style, containing back slashes. */
159 DNDTRANSFEROBJPATHSTYLE_DOS,
160 /** The usual 32-bit hack. */
161 DNDTRANSFEROBJPATHSTYLE_32BIT_HACK = 0x7fffffff
162} DNDTRANSFEROBJPATHSTYLE;
163
164/**
165 * Structure for keeping a DnD transfer object.
166 */
167typedef struct DNDTRANSFEROBJECT
168{
169 RTLISTNODE Node;
170 /** The object's type. */
171 DNDTRANSFEROBJTYPE enmType;
172 /** Index (in characters, UTF-8) at which the first destination segment starts. */
173 uint16_t idxDst;
174 /** Allocated path. Includdes the absolute source path (if any) + destination segments.
175 * Transport (IPRT) style. */
176 char *pszPath;
177
178 /** Union containing data depending on the object's type. */
179 union
180 {
181 /** Structure containing members for objects that
182 * are files. */
183 struct
184 {
185 /** File handle. */
186 RTFILE hFile;
187 /** File system object information of this file. */
188 RTFSOBJINFO objInfo;
189 /** Bytes to proces for reading/writing. */
190 uint64_t cbToProcess;
191 /** Bytes processed reading/writing. */
192 uint64_t cbProcessed;
193 } File;
194 struct
195 {
196 /** Directory handle. */
197 RTDIR hDir;
198 /** File system object information of this directory. */
199 RTFSOBJINFO objInfo;
200 } Dir;
201 } u;
202} DNDTRANSFEROBJECT;
203/** Pointer to a DnD transfer object. */
204typedef DNDTRANSFEROBJECT *PDNDTRANSFEROBJECT;
205
206int DnDTransferObjectInit(PDNDTRANSFEROBJECT pObj);
207int DnDTransferObjectInitEx(PDNDTRANSFEROBJECT pObj, DNDTRANSFEROBJTYPE enmType, const char *pcszPathSrcAbs, const char *pcszPathDst);
208void DnDTransferObjectDestroy(PDNDTRANSFEROBJECT pObj);
209void DnDTransferObjectClose(PDNDTRANSFEROBJECT pObj);
210void DnDTransferObjectReset(PDNDTRANSFEROBJECT pObj);
211const char *DnDTransferObjectGetSourcePath(PDNDTRANSFEROBJECT pObj);
212const char *DnDTransferObjectGetDestPath(PDNDTRANSFEROBJECT pObj);
213int DnDTransferObjectGetDestPathEx(PDNDTRANSFEROBJECT pObj, DNDTRANSFEROBJPATHSTYLE enmStyle, char *pszBuf, size_t cbBuf);
214RTFMODE DnDTransferObjectGetMode(PDNDTRANSFEROBJECT pObj);
215uint64_t DnDTransferObjectGetProcessed(PDNDTRANSFEROBJECT pObj);
216uint64_t DnDTransferObjectGetSize(PDNDTRANSFEROBJECT pObj);
217DNDTRANSFEROBJTYPE DnDTransferObjectGetType(PDNDTRANSFEROBJECT pObj);
218int DnDTransferObjectSetSize(PDNDTRANSFEROBJECT pObj, uint64_t cbSize);
219bool DnDTransferObjectIsComplete(PDNDTRANSFEROBJECT pObj);
220bool DnDTransferObjectIsOpen(PDNDTRANSFEROBJECT pObj);
221int DnDTransferObjectOpen(PDNDTRANSFEROBJECT pObj, uint64_t fOpen, RTFMODE fMode, DNDTRANSFEROBJECTFLAGS fFlags);
222int DnDTransferObjectQueryInfo(PDNDTRANSFEROBJECT pObj);
223int DnDTransferObjectRead(PDNDTRANSFEROBJECT pObj, void *pvBuf, size_t cbBuf, uint32_t *pcbRead);
224int DnDTransferObjectWrite(PDNDTRANSFEROBJECT pObj, const void *pvBuf, size_t cbBuf, uint32_t *pcbWritten);
225
226/** Defines the default chunk size of DnD data transfers.
227 * Supported on all (older) Guest Additions which also support DnD. */
228#define DND_DEFAULT_CHUNK_SIZE _64K
229
230/** Separator for a formats list. */
231#define DND_FORMATS_SEPARATOR_STR "\r\n"
232
233/** Default URI list path separator, if not specified otherwise.
234 *
235 * This is there for hysterical raisins, to not break older Guest Additions.
236 ** @todo Get rid of this. */
237#define DND_PATH_SEPARATOR_STR "\r\n"
238
239/** DnDTransferList flags. */
240typedef uint32_t DNDTRANSFERLISTFLAGS;
241
242/** No flags specified. */
243#define DNDTRANSFERLIST_FLAGS_NONE 0
244/** Enables recurisve directory handling. */
245#define DNDTRANSFERLIST_FLAGS_RECURSIVE RT_BIT(0)
246/** Resolve all symlinks. Currently not supported and will be ignored. */
247#define DNDTRANSFERLIST_FLAGS_RESOLVE_SYMLINKS RT_BIT(1)
248/** Keep the files + directory entries open while
249 * being in this list. */
250#define DNDTRANSFERLIST_FLAGS_KEEP_OPEN RT_BIT(2)
251/** Lazy loading: Only enumerate sub directories when needed. Not implemented yet.
252 ** @todo Implement lazy loading. */
253#define DNDTRANSFERLIST_FLAGS_LAZY RT_BIT(3)
254
255/** Mask of all valid DnD transfer list flags. */
256#define DNDTRANSFERLIST_FLAGS_VALID_MASK UINT32_C(0xF)
257
258/**
259 * Enumeration for specifying a transfer list format.
260 */
261typedef enum DNDTRANSFERLISTFMT
262{
263 /** Unknown format, do not use. */
264 DNDTRANSFERLISTFMT_UNKNOWN = 0,
265 /** Native format. */
266 DNDTRANSFERLISTFMT_NATIVE,
267 /** URI format. */
268 DNDTRANSFERLISTFMT_URI,
269 /** The usual 32-bit hack. */
270 DNDTRANSFERLISTFMT_32BIT_HACK = 0x7fffffff
271} DNDTRANSFERLISTFMT;
272
273/**
274 * Structure for keeping a DnD transfer list root entry.
275 *
276 * A root entry always is relative to the parent list maintaining it.
277 */
278typedef struct DNDTRANSFERLISTROOT
279{
280 /** List node. */
281 RTLISTNODE Node;
282 /** Pointer to the allocated root path.
283 * - Relative to the list's root path
284 * - Always ends with a trailing slash
285 * - Always stored in transport style (UNIX-y). */
286 char *pszPathRoot;
287} DNDTRANSFERLISTROOT;
288/** Pointer to a DnD list root entry. */
289typedef DNDTRANSFERLISTROOT *PDNDTRANSFERLISTROOT;
290
291/**
292 * Struct for keeping a DnD transfer list.
293 *
294 * All entries must share a common (absolute) root path. For different root paths another transfer list is needed.
295 */
296typedef struct DNDTRANSFERLIST
297{
298 /** Absolute root path of this transfer list, in native path style.
299 * Always ends with a separator. */
300 char *pszPathRootAbs;
301 /** List of all relative (to \a pszPathRootAbs) top-level file/directory entries, of type DNDTRANSFERLISTROOT.
302 * Note: All paths are stored internally in transport style (UNIX paths) for
303 * easier conversion/handling! */
304 RTLISTANCHOR lstRoot;
305 /** Total number of all transfer root entries. */
306 uint64_t cRoots;
307 /** List of all transfer objects added, of type DNDTRANSFEROBJECT.
308 *
309 * The order of objects being added is crucial for traversing the tree.
310 * In other words, sub directories must come first before its contents. */
311 RTLISTANCHOR lstObj;
312 /** Total number of all transfer objects. */
313 uint64_t cObj;
314 /** Total size of all transfer objects, that is, the file
315 * size of all objects (in bytes).
316 * Note: Do *not* size_t here, as we also want to support large files
317 * on 32-bit guests. */
318 uint64_t cbObjTotal;
319} DNDTRANSFERLIST;
320/** Pointer to a DNDTRANSFERLIST struct. */
321typedef DNDTRANSFERLIST *PDNDTRANSFERLIST;
322
323int DnDTransferListInit(PDNDTRANSFERLIST pList);
324int DnDTransferListInitEx(PDNDTRANSFERLIST pList, const char *pcszRootPathAbs, DNDTRANSFERLISTFMT enmFmt);
325void DnDTransferListDestroy(PDNDTRANSFERLIST pList);
326void DnDTransferListReset(PDNDTRANSFERLIST pList);
327
328int DnDTransferListAppendPath(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char *pszPath, DNDTRANSFERLISTFLAGS fFlags);
329int DnDTransferListAppendPathsFromBuffer(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char *pszPaths, size_t cbPaths, const char *pcszSeparator, DNDTRANSFERLISTFLAGS fFlags);
330int DnDTransferListAppendPathsFromArray(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char * const *papcszPaths, size_t cPaths, DNDTRANSFERLISTFLAGS fFlags);
331int DnDTransferListAppendRootsFromBuffer(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char *pszPaths, size_t cbPaths, const char *pcszSeparator, DNDTRANSFERLISTFLAGS fFlags);
332int DnDTransferListAppendRootsFromArray(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char * const *papcszPaths, size_t cPaths, DNDTRANSFERLISTFLAGS fFlags);
333
334int DnDTransferListGetRootsEx(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char *pcszPathBase, const char *pcszSeparator, char **ppszBuffer, size_t *pcbBuffer);
335int DnDTransferListGetRoots(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, char **ppszBuffer, size_t *pcbBuffer);
336uint64_t DnDTransferListGetRootCount(PDNDTRANSFERLIST pList);
337const char *DnDTransferListGetRootPathAbs(PDNDTRANSFERLIST pList);
338
339PDNDTRANSFEROBJECT DnDTransferListObjGetFirst(PDNDTRANSFERLIST pList);
340void DnDTransferListObjRemove(PDNDTRANSFERLIST pList, PDNDTRANSFEROBJECT pObj);
341void DnDTransferListObjRemoveFirst(PDNDTRANSFERLIST pList);
342uint64_t DnDTransferListObjCount(PDNDTRANSFERLIST pList);
343uint64_t DnDTransferListObjTotalBytes(PDNDTRANSFERLIST pList);
344
345#endif /* !VBOX_INCLUDED_GuestHost_DragAndDrop_h */
346
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