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
|
/*********************************************************
* Copyright (C) 2005 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* 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 Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*
* dnd.h --
*
* Drag and Drop library
*
*/
#ifndef _DND_H_
#define _DND_H_
#define INCLUDE_ALLOW_USERLEVEL
#ifdef _WIN32
# include <windows.h>
# include <shellapi.h>
#endif
#include "includeCheck.h"
#include "vm_basic_types.h"
#include "unicodeTypes.h"
#include "dynarray.h"
/* Error value returned when data contains illegal characters */
#define DND_ILLEGAL_CHARACTERS "data contains illegal characters"
/*
* Use the same maximum path length as Hgfs.
* XXX: Move HGFS_PATH_MAX to some header file which is more public
* and use it here.
*/
#define DND_MAX_PATH 6144
#define DNDMSG_HEADERSIZE_V3 ((3 * sizeof (uint32)) + (1 * sizeof (uint8)))
/* Hard limits we never want to exceed */
/* The maximum size of a serializied DnDMsg. Close to 4M. */
#define DNDMSG_MAX_ARGSZ ((1 << 22) - DNDMSG_HEADERSIZE_V3)
/* The maximum number of arguments we can hold */
#define DNDMSG_MAX_ARGS 64
/* Linux only defines. Should be in separate dndLinux.h */
/* Strings used for formatting various types of data */
#define DND_URI_LIST_PRE "file://"
#define DND_URI_LIST_PRE_KDE "file:"
#define DND_URI_LIST_POST "\r\n"
#define DND_TEXT_PLAIN_PRE ""
#define DND_TEXT_PLAIN_POST ""
#define DND_STRING_PRE ""
#define DND_STRING_POST ""
#define FCP_GNOME_LIST_PRE "file://"
#define FCP_GNOME_LIST_POST "\n"
/* FCP target used in gnome. */
#define FCP_TARGET_NAME_GNOME_COPIED_FILES "x-special/gnome-copied-files"
#define FCP_TARGET_INFO_GNOME_COPIED_FILES 0
/* FCP target used in KDE. */
#define FCP_TARGET_NAME_URI_LIST "text/uri-list"
#define FCP_TARGET_INFO_URI_LIST 1
/* Number of FCP targets. */
#define NR_FCP_TARGETS 2
#define VMWARE_TARGET "vmware-target"
#define FCP_COPY_DELAY 1000000 // 1 second
#define TARGET_NAME_TIMESTAMP "TIMESTAMP"
#define TARGET_NAME_STRING "STRING"
#define TARGET_NAME_TEXT_PLAIN "text/plain"
#define TARGET_NAME_UTF8_STRING "UTF8_STRING"
#define TARGET_NAME_COMPOUND_TEXT "COMPOUND_TEXT"
#define TARGET_NAME_APPLICATION_RTF "application/rtf"
#define TARGET_NAME_TEXT_RICHTEXT "text/richtext"
#define DRAG_TARGET_NAME_URI_LIST "text/uri-list"
#define DRAG_LEAVE_TIMEOUT 500
/* Guest detection window width and height. */
#define DRAG_DET_WINDOW_WIDTH 15
/* Clipboard image size limit. */
#define CLIPBOARD_IMAGE_MAX_WIDTH 4000
#define CLIPBOARD_IMAGE_MAX_HEIGHT 4000
typedef enum
{
CPFORMAT_UNKNOWN = 0,
CPFORMAT_TEXT, /* NUL terminated UTF-8. */
CPFORMAT_FILELIST,
CPFORMAT_RTF,
CPFORMAT_FILELIST_URI,
CPFORMAT_FILECONTENTS,
CPFORMAT_IMG_PNG,
CPFORMAT_MAX,
} DND_CPFORMAT;
enum DND_DROPEFFECT
{
DROP_UNKNOWN = 1<<31,
DROP_NONE = 0,
DROP_COPY = 1<<0,
DROP_MOVE = 1<<1,
DROP_LINK = 1<<2,
};
/* Clipboard item. */
typedef struct CPClipItem {
void *buf;
uint32 size;
Bool exists;
} CPClipItem;
/*
* Cross platform clipboard. The native UI will convert host clipboard content
* into cross platform clipboards.
*/
typedef struct {
Bool changed;
CPClipItem items[CPFORMAT_MAX - 1];
} CPClipboard;
/* Definitions for transport layer big buffer support (>= V3). */
typedef enum
{
DND_TRANSPORT_PACKET_TYPE_UNKNOWN = 0,
DND_TRANSPORT_PACKET_TYPE_SINGLE,
DND_TRANSPORT_PACKET_TYPE_REQUEST,
DND_TRANSPORT_PACKET_TYPE_PAYLOAD,
} DND_TRANSPORT_PACKET_TYPE;
typedef
#include "vmware_pack_begin.h"
struct DnDTransportPacketHeader {
uint32 type;
uint32 seqNum;
uint32 totalSize;
uint32 payloadSize;
uint32 offset;
uint8 payload[1];
}
#include "vmware_pack_end.h"
DnDTransportPacketHeader;
typedef struct DnDTransportBuffer {
size_t seqNum;
uint8 *buffer;
size_t totalSize;
size_t offset;
VmTimeType lastUpdateTime;
} DnDTransportBuffer;
#define DND_TRANSPORT_PACKET_HEADER_SIZE (5 * sizeof(uint32))
/* Close to 64k (maximum guestRpc message size). Leave some space for guestRpc header. */
#define DND_MAX_TRANSPORT_PACKET_SIZE ((1 << 16) - 100)
#define DND_MAX_TRANSPORT_PACKET_PAYLOAD_SIZE (DND_MAX_TRANSPORT_PACKET_SIZE - \
DND_TRANSPORT_PACKET_HEADER_SIZE)
#define DND_MAX_TRANSPORT_LATENCY_TIME 3 * 1000000 /* 3 seconds. */
/*
* Structure to access methods of currently used blocking mechanism.
*/
typedef struct DnDBlockControl {
int fd;
const char *blockRoot;
Bool (*AddBlock)(int blockFd, const char *blockPath);
Bool (*RemoveBlock)(int blockFd, const char *blockedPath);
} DnDBlockControl;
#ifdef _WIN32
/*
* Windows-specific functions
*/
EXTERN Unicode DnD_GetClipboardFormatName(UINT cf);
EXTERN HGLOBAL DnD_CopyStringToGlobal(ConstUnicode str);
EXTERN HGLOBAL DnD_CopyDWORDToGlobal(DWORD *pDWORD);
EXTERN HGLOBAL DnD_CreateHDrop(ConstUnicode path, ConstUnicode fileList);
EXTERN HGLOBAL DnD_CreateHDropForGuest(ConstUnicode path,
ConstUnicode fileList);
EXTERN size_t DnD_CPStringToLocalString(ConstUnicode bufIn,
utf16_t **bufOut);
EXTERN size_t DnD_LocalStringToCPString(utf16_t *bufIn,
char **bufOut);
EXTERN Bool DnD_SetCPClipboardFromLocalText(CPClipboard *clip,
utf16_t *bufIn);
EXTERN Bool DnD_SetCPClipboardFromLocalRtf(CPClipboard *clip,
char *bufIn);
EXTERN Bool DnD_SetCPClipboardFromBMPInfo(CPClipboard *clip,
const LPBITMAPINFOHEADER bmi,
DND_CPFORMAT fmt);
EXTERN Bool DnD_SetCPClipboardFromHBITMAP(CPClipboard *clip,
HBITMAP hBitmap,
DND_CPFORMAT fmt);
EXTERN Bool DnD_PNGToLocalFormat(const unsigned char *pngData,
unsigned int pngDataLen,
int pngReadFlags,
DynBuf *bmpData,
HBITMAP *hBitmap);
EXTERN Bool DnD_FakeMouseEvent(DWORD flag);
EXTERN Bool DnD_FakeMouseState(DWORD key, Bool isDown);
EXTERN Bool DnD_FakeEscapeKey(void);
EXTERN Bool DnD_DeleteLocalDirectory(ConstUnicode localDir);
EXTERN Bool DnD_SetClipboard(UINT format, char *buffer, int len);
EXTERN Bool DnD_GetFileList(HDROP hDrop,
char **remoteFiles,
int *remoteLength,
char **localFiles,
int *localLength,
uint64 *totalSize);
#else
/*
* Posix-specific functions
*/
EXTERN char *DnD_UriListGetNextFile(char const *uriList,
size_t *index,
size_t *length);
#endif
/*
* Shared functions
*/
ConstUnicode DnD_GetFileRoot(void);
char *DnD_CreateStagingDirectory(void);
Bool DnD_DeleteStagingFiles(ConstUnicode stagingDir, Bool onReboot);
Bool DnD_PrependFileRoot(ConstUnicode fileRoot, char **src, size_t *srcSize);
int DnD_LegacyConvertToCPName(const char *nameIn,
size_t bufOutSize,
char *bufOut);
Bool DnD_CPNameListToDynBufArray(char *fileList,
size_t listSize,
DynBufArray *dynBufArray);
Unicode DnD_GetLastDirName(const char *str);
/* vmblock support functions. */
Bool DnD_InitializeBlocking(DnDBlockControl *blkCtrl);
Bool DnD_UninitializeBlocking(DnDBlockControl *blkCtrl);
Bool DnD_CompleteBlockInitialization(int fd, DnDBlockControl *blkCtrl);
static INLINE Bool
DnD_BlockIsReady(DnDBlockControl *blkCtrl) // IN: blocking control structure
{
if (blkCtrl->fd >= 0) {
ASSERT(blkCtrl->AddBlock && blkCtrl->RemoveBlock);
return TRUE;
}
return FALSE;
}
/* Transport layer big buffer support functions. */
void DnD_TransportBufInit(DnDTransportBuffer *buf,
uint8 *msg,
size_t msgSize,
uint32 seqNum);
void DnD_TransportBufReset(DnDTransportBuffer *buf);
size_t DnD_TransportBufGetPacket(DnDTransportBuffer *buf,
DnDTransportPacketHeader **packet);
Bool DnD_TransportBufAppendPacket(DnDTransportBuffer *buf,
DnDTransportPacketHeader *packet,
size_t packetSize);
size_t DnD_TransportMsgToPacket(uint8 *msg,
size_t msgSize,
uint32 seqNum,
DnDTransportPacketHeader **packet);
size_t DnD_TransportReqPacket(DnDTransportBuffer *buf,
DnDTransportPacketHeader **packet);
#endif // _DND_H_
|