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