VirtualBox

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

Last change on this file since 85429 was 85429, checked in by vboxsync, 5 years ago

DnD: Added DnDTransferObjectInit() / DnDTransferObjectInitEx().

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.8 KB
Line 
1/* $Id: DragAndDrop.h 85429 2020-07-23 11:31:53Z 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/** Default URI list path separator, if not specified otherwrise.
213 *
214 * This is there for hysterical raisins, to not break older Guest Additions.
215 ** @todo Get rid of this. */
216#define DND_PATH_SEPARATOR "\r\n"
217
218/** DnDTransferList flags. */
219typedef uint32_t DNDTRANSFERLISTFLAGS;
220
221/** No flags specified. */
222#define DNDTRANSFERLIST_FLAGS_NONE 0
223/** Enables recurisve directory handling. */
224#define DNDTRANSFERLIST_FLAGS_RECURSIVE RT_BIT(0)
225/** Resolve all symlinks. Currently not supported and will be ignored. */
226#define DNDTRANSFERLIST_FLAGS_RESOLVE_SYMLINKS RT_BIT(1)
227/** Keep the files + directory entries open while
228 * being in this list. */
229#define DNDTRANSFERLIST_FLAGS_KEEP_OPEN RT_BIT(2)
230/** Lazy loading: Only enumerate sub directories when needed. Not implemented yet.
231 ** @todo Implement lazy loading. */
232#define DNDTRANSFERLIST_FLAGS_LAZY RT_BIT(3)
233
234/** Mask of all valid DnD transfer list flags. */
235#define DNDTRANSFERLIST_FLAGS_VALID_MASK UINT32_C(0xF)
236
237/**
238 * Enumeration for specifying a transfer list format.
239 */
240typedef enum DNDTRANSFERLISTFMT
241{
242 /** Unknown format, do not use. */
243 DNDTRANSFERLISTFMT_UNKNOWN = 0,
244 /** Native format. */
245 DNDTRANSFERLISTFMT_NATIVE,
246 /** URI format. */
247 DNDTRANSFERLISTFMT_URI,
248 /** The usual 32-bit hack. */
249 DNDTRANSFERLISTFMT_32BIT_HACK = 0x7fffffff
250} DNDTRANSFERLISTFMT;
251
252/**
253 * Structure for keeping a DnD transfer list root entry.
254 *
255 * A root entry always is relative to the parent list maintaining it.
256 */
257typedef struct DNDTRANSFERLISTROOT
258{
259 /** List node. */
260 RTLISTNODE Node;
261 /** Pointer to the allocated root path.
262 * - Relative to the list's root path
263 * - Always ends with a trailing slash
264 * - Always stored in transport style (UNIX-y). */
265 char *pszPathRoot;
266} DNDTRANSFERLISTROOT;
267/** Pointer to a DnD list root entry. */
268typedef DNDTRANSFERLISTROOT *PDNDTRANSFERLISTROOT;
269
270/**
271 * Struct for keeping a DnD transfer list.
272 *
273 * All entries must share a common (absolute) root path. For different root paths another transfer list is needed.
274 */
275typedef struct DNDTRANSFERLIST
276{
277 /** Absolute root path of this transfer list, in native path style.
278 * Always ends with a separator. */
279 char *pszPathRootAbs;
280 /** List of all relative (to \a pszPathRootAbs) top-level file/directory entries, of type DNDTRANSFERLISTROOT.
281 * Note: All paths are stored internally in transport style (UNIX paths) for
282 * easier conversion/handling! */
283 RTLISTANCHOR lstRoot;
284 /** Total number of all transfer root entries. */
285 uint64_t cRoots;
286 /** List of all transfer objects added, of type DNDTRANSFEROBJECT.
287 *
288 * The order of objects being added is crucial for traversing the tree.
289 * In other words, sub directories must come first before its contents. */
290 RTLISTANCHOR lstObj;
291 /** Total number of all transfer objects. */
292 uint64_t cObj;
293 /** Total size of all transfer objects, that is, the file
294 * size of all objects (in bytes).
295 * Note: Do *not* size_t here, as we also want to support large files
296 * on 32-bit guests. */
297 uint64_t cbObjTotal;
298} DNDTRANSFERLIST;
299/** Pointer to a DNDTRANSFERLIST struct. */
300typedef DNDTRANSFERLIST *PDNDTRANSFERLIST;
301
302int DnDTransferListInit(PDNDTRANSFERLIST pList);
303int DnDTransferListInitEx(PDNDTRANSFERLIST pList, const char *pcszRootPathAbs);
304void DnDTransferListDestroy(PDNDTRANSFERLIST pList);
305void DnDTransferListReset(PDNDTRANSFERLIST pList);
306
307int DnDTransferListAppendPath(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char *pszPath, DNDTRANSFERLISTFLAGS fFlags);
308int DnDTransferListAppendPathsFromBuffer(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char *pszPaths, size_t cbPaths, const char *pcszSeparator, DNDTRANSFERLISTFLAGS fFlags);
309int DnDTransferListAppendPathsFromArray(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char * const *papcszPaths, size_t cPaths, DNDTRANSFERLISTFLAGS fFlags);
310
311int DnDTransferListGetRootsEx(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, const char *pcszPathBase, const char *pcszSeparator, char **ppszBuffer, size_t *pcbBuffer);
312int DnDTransferListGetRoots(PDNDTRANSFERLIST pList, DNDTRANSFERLISTFMT enmFmt, char **ppszBuffer, size_t *pcbBuffer);
313uint64_t DnDTransferListGetRootCount(PDNDTRANSFERLIST pList);
314const char *DnDTransferListGetRootPathAbs(PDNDTRANSFERLIST pList);
315
316PDNDTRANSFEROBJECT DnDTransferListObjGetFirst(PDNDTRANSFERLIST pList);
317void DnDTransferListObjRemove(PDNDTRANSFERLIST pList, PDNDTRANSFEROBJECT pObj);
318void DnDTransferListObjRemoveFirst(PDNDTRANSFERLIST pList);
319uint64_t DnDTransferListObjCount(PDNDTRANSFERLIST pList);
320uint64_t DnDTransferListObjTotalBytes(PDNDTRANSFERLIST pList);
321
322#endif /* !VBOX_INCLUDED_GuestHost_DragAndDrop_h */
323
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