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