82391de567696f10b21a762fde6a06fe3c266d28vboxsync/* $Id$ */
82391de567696f10b21a762fde6a06fe3c266d28vboxsync/** @file
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync * DnD: Shared functions between host and guest.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync */
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsync/*
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * Copyright (C) 2014 Oracle Corporation
82391de567696f10b21a762fde6a06fe3c266d28vboxsync *
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * available from http://www.virtualbox.org. This file is free software;
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * you can redistribute it and/or modify it under the terms of the GNU
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * General Public License (GPL) as published by the Free Software
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c7b9f4e0d8324ad9cb496da805f90da2d24b6b1cvboxsync *
c7b9f4e0d8324ad9cb496da805f90da2d24b6b1cvboxsync * The contents of this file may alternatively be used under the terms
c7b9f4e0d8324ad9cb496da805f90da2d24b6b1cvboxsync * of the Common Development and Distribution License Version 1.0
c7b9f4e0d8324ad9cb496da805f90da2d24b6b1cvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
c7b9f4e0d8324ad9cb496da805f90da2d24b6b1cvboxsync * VirtualBox OSE distribution, in which case the provisions of the
c7b9f4e0d8324ad9cb496da805f90da2d24b6b1cvboxsync * CDDL are applicable instead of those of the GPL.
c7b9f4e0d8324ad9cb496da805f90da2d24b6b1cvboxsync *
c7b9f4e0d8324ad9cb496da805f90da2d24b6b1cvboxsync * You may elect to license modified versions of this file under the
c7b9f4e0d8324ad9cb496da805f90da2d24b6b1cvboxsync * terms and conditions of either the GPL or the CDDL or both.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync */
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsync#ifndef ___VBox_GuestHost_DragAndDrop_h
82391de567696f10b21a762fde6a06fe3c266d28vboxsync#define ___VBox_GuestHost_DragAndDrop_h
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsync#include <iprt/assert.h>
82391de567696f10b21a762fde6a06fe3c266d28vboxsync#include <iprt/cdefs.h>
82391de567696f10b21a762fde6a06fe3c266d28vboxsync#include <iprt/err.h>
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync#include <iprt/file.h>
82391de567696f10b21a762fde6a06fe3c266d28vboxsync#include <iprt/types.h>
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsync#include <iprt/cpp/list.h>
82391de567696f10b21a762fde6a06fe3c266d28vboxsync#include <iprt/cpp/ministring.h>
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncint DnDDirCreateDroppedFilesEx(const char *pszPath, char *pszDropDir, size_t cbDropDir);
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncint DnDDirCreateDroppedFiles(char *pszDropDir, size_t cbDropDir);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncbool DnDMIMEHasFileURLs(const char *pcszFormat, size_t cchFormatMax);
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncbool DnDMIMENeedsDropDir(const char *pcszFormat, size_t cchFormatMax);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncint DnDPathSanitizeFilename(char *pszPath, size_t cbPath);
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncint DnDPathSanitize(char *pszPath, size_t cbPath);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
8c71acd3714d92a0602a95d19fbb2aef0cf5fd5dvboxsync/** Keep the original paths, don't convert paths to relative ones. */
8c71acd3714d92a0602a95d19fbb2aef0cf5fd5dvboxsync#define DNDURILIST_FLAGS_ABSOLUTE_PATHS RT_BIT(0)
8c71acd3714d92a0602a95d19fbb2aef0cf5fd5dvboxsync
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncclass DnDURIObject
82391de567696f10b21a762fde6a06fe3c266d28vboxsync{
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncpublic:
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync enum Type
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync {
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync Unknown = 0,
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync File,
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync Directory
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync };
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync DnDURIObject(Type type,
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync const RTCString &strSrcPath,
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync const RTCString &strDstPath,
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync uint32_t fMode, uint64_t cbSize);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync virtual ~DnDURIObject(void);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncpublic:
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync
2ad9f8a731c73f6ac74044d42d47bbaf6f44a566vboxsync const RTCString &GetSourcePath(void) const { return m_strSrcPath; }
2ad9f8a731c73f6ac74044d42d47bbaf6f44a566vboxsync const RTCString &GetDestPath(void) const { return m_strDstPath; }
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync uint32_t GetMode(void) const { return m_fMode; }
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync uint64_t GetSize(void) const { return m_cbSize; }
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync Type GetType(void) const { return m_Type; }
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncpublic:
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync bool IsComplete(void) const;
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync static int RebaseURIPath(RTCString &strPath, const RTCString &strBaseOld, const RTCString &strBaseNew);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync int Read(void *pvBuf, uint32_t cbToRead, uint32_t *pcbRead);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncprotected:
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync void closeInternal(void);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncprotected:
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync Type m_Type;
82391de567696f10b21a762fde6a06fe3c266d28vboxsync RTCString m_strSrcPath;
82391de567696f10b21a762fde6a06fe3c266d28vboxsync RTCString m_strDstPath;
82391de567696f10b21a762fde6a06fe3c266d28vboxsync uint32_t m_fMode;
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync /** Size (in bytes) to read/write. */
82391de567696f10b21a762fde6a06fe3c266d28vboxsync uint64_t m_cbSize;
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync /** Bytes processed reading/writing. */
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync uint64_t m_cbProcessed;
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync union
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync {
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync RTFILE m_hFile;
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync } u;
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync};
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncclass DnDURIList
82391de567696f10b21a762fde6a06fe3c266d28vboxsync{
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncpublic:
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsync DnDURIList(void);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync virtual ~DnDURIList(void);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncpublic:
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync int AppendNativePath(const char *pszPath, uint32_t fFlags);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync int AppendNativePathsFromList(const char *pszNativePaths, size_t cbNativePaths, uint32_t fFlags);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync int AppendNativePathsFromList(const RTCList<RTCString> &lstNativePaths, uint32_t fFlags);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync int AppendURIPath(const char *pszURI, uint32_t fFlags);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync int AppendURIPathsFromList(const char *pszURIPaths, size_t cbURIPaths, uint32_t fFlags);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync int AppendURIPathsFromList(const RTCList<RTCString> &lstURI, uint32_t fFlags);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsync void Clear(void);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync DnDURIObject &First(void) { return m_lstTree.first(); }
82391de567696f10b21a762fde6a06fe3c266d28vboxsync bool IsEmpty(void) { return m_lstTree.isEmpty(); }
82391de567696f10b21a762fde6a06fe3c266d28vboxsync void RemoveFirst(void);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync int RootFromURIData(const void *pvData, size_t cbData, uint32_t fFlags);
2ad9f8a731c73f6ac74044d42d47bbaf6f44a566vboxsync RTCString RootToString(const RTCString &strBasePath = "", const RTCString &strSeparator = "\r\n");
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync size_t RootCount(void) { return m_lstRoot.size(); }
82391de567696f10b21a762fde6a06fe3c266d28vboxsync size_t TotalBytes(void) { return m_cbTotal; }
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncprotected:
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsync int appendPathRecursive(const char *pcszPath, size_t cbBaseLen, uint32_t fFlags);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncprotected:
82391de567696f10b21a762fde6a06fe3c266d28vboxsync
8c71acd3714d92a0602a95d19fbb2aef0cf5fd5dvboxsync /** List of all top-level file/directory entries.
8c71acd3714d92a0602a95d19fbb2aef0cf5fd5dvboxsync * Note: All paths are kept internally as UNIX paths for
8c71acd3714d92a0602a95d19fbb2aef0cf5fd5dvboxsync * easier conversion/handling! */
82391de567696f10b21a762fde6a06fe3c266d28vboxsync RTCList<RTCString> m_lstRoot;
82391de567696f10b21a762fde6a06fe3c266d28vboxsync /** List of all URI objects added. */
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync RTCList<DnDURIObject> m_lstTree;
82391de567696f10b21a762fde6a06fe3c266d28vboxsync /** Total size of all URI objects, that is, the file
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * size of all objects (in bytes). */
82391de567696f10b21a762fde6a06fe3c266d28vboxsync size_t m_cbTotal;
82391de567696f10b21a762fde6a06fe3c266d28vboxsync};
82391de567696f10b21a762fde6a06fe3c266d28vboxsync#endif /* ___VBox_GuestHost_DragAndDrop_h */
82391de567696f10b21a762fde6a06fe3c266d28vboxsync