VirtualBox

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

Last change on this file since 85746 was 85746, checked in by vboxsync, 4 years ago

DnD: Renaming -- DND_FORMATS_SEPARATOR -> DND_FORMATS_SEPARATOR_STR and DND_PATH_SEPARATOR -> DND_PATH_SEPARATOR_STR.

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