2012-07-21 01:05:06 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-07-21 01:05:06 +04:00
|
|
|
* Windows Clipboard Redirection
|
|
|
|
*
|
|
|
|
* Copyright 2012 Jason Champion
|
2014-10-24 17:55:48 +04:00
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2012-07-21 01:05:06 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2014-09-13 00:30:57 +04:00
|
|
|
|
2013-11-05 06:52:17 +04:00
|
|
|
#include <assert.h>
|
2014-09-13 00:30:57 +04:00
|
|
|
|
2012-12-17 19:20:25 +04:00
|
|
|
#include <winpr/crt.h>
|
2014-10-23 23:38:19 +04:00
|
|
|
#include <winpr/tchar.h>
|
2014-09-13 00:30:57 +04:00
|
|
|
#include <winpr/stream.h>
|
2012-12-17 19:20:25 +04:00
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#include <freerdp/log.h>
|
2012-10-09 04:33:58 +04:00
|
|
|
#include <freerdp/client/cliprdr.h>
|
2012-07-21 01:05:06 +04:00
|
|
|
|
2014-03-10 10:20:53 +04:00
|
|
|
#include <Strsafe.h>
|
|
|
|
|
2012-07-21 01:05:06 +04:00
|
|
|
#include "wf_cliprdr.h"
|
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#define TAG CLIENT_TAG("windows")
|
|
|
|
|
2014-07-23 17:35:42 +04:00
|
|
|
extern BOOL WINAPI AddClipboardFormatListener(_In_ HWND hwnd);
|
|
|
|
extern BOOL WINAPI RemoveClipboardFormatListener(_In_ HWND hwnd);
|
|
|
|
|
2014-03-10 10:20:53 +04:00
|
|
|
#define WM_CLIPRDR_MESSAGE (WM_USER + 156)
|
|
|
|
#define OLE_SETCLIPBOARD 1
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
BOOL wf_create_file_obj(wfClipboard* cliprdrrdr, IDataObject** ppDataObject);
|
2014-10-23 06:32:55 +04:00
|
|
|
void wf_destroy_file_obj(IDataObject* instance);
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-10-23 21:11:20 +04:00
|
|
|
/**
|
|
|
|
* IStream
|
|
|
|
*/
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrStream_QueryInterface(IStream* This, REFIID riid, void** ppvObject)
|
|
|
|
{
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IStream) || IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
IStream_AddRef(This);
|
|
|
|
*ppvObject = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppvObject = 0;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE CliprdrStream_AddRef(IStream* This)
|
|
|
|
{
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
|
|
|
|
|
|
|
return InterlockedIncrement(&instance->m_lRefCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE CliprdrStream_Release(IStream* This)
|
|
|
|
{
|
|
|
|
LONG count;
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
|
|
|
|
|
|
|
count = InterlockedDecrement(&instance->m_lRefCount);
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
CliprdrStream_Delete(instance);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrStream_Read(IStream* This, void *pv, ULONG cb, ULONG *pcbRead)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
2014-10-23 23:38:19 +04:00
|
|
|
wfClipboard* clipboard = (wfClipboard*) instance->m_pData;
|
2014-10-23 21:11:20 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
if (!pv || !pcbRead)
|
2014-10-23 21:11:20 +04:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*pcbRead = 0;
|
|
|
|
|
|
|
|
if (instance->m_lOffset.QuadPart >= instance->m_lSize.QuadPart)
|
2015-06-02 22:15:46 +03:00
|
|
|
return E_FAIL;
|
2014-10-23 21:11:20 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
ret = cliprdr_send_request_filecontents(clipboard, (void*) This,
|
2014-10-23 21:11:20 +04:00
|
|
|
instance->m_lIndex, FILECONTENTS_RANGE,
|
|
|
|
instance->m_lOffset.HighPart, instance->m_lOffset.LowPart, cb);
|
|
|
|
|
|
|
|
if (ret < 0)
|
2015-06-02 22:15:46 +03:00
|
|
|
return E_FAIL;
|
2014-10-23 21:11:20 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
if (clipboard->req_fdata)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
2014-10-24 17:55:48 +04:00
|
|
|
CopyMemory(pv, clipboard->req_fdata, clipboard->req_fsize);
|
2014-10-23 23:38:19 +04:00
|
|
|
free(clipboard->req_fdata);
|
2014-10-23 21:11:20 +04:00
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
*pcbRead = clipboard->req_fsize;
|
|
|
|
instance->m_lOffset.QuadPart += clipboard->req_fsize;
|
2014-10-23 21:11:20 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
if (clipboard->req_fsize < cb)
|
2015-06-02 22:15:46 +03:00
|
|
|
return E_FAIL;
|
2014-10-23 21:11:20 +04:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-24 17:55:48 +04:00
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrStream_Write(IStream* This, const void* pv, ULONG cb, ULONG *pcbWritten)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
|
|
|
|
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
}
|
|
|
|
|
2014-10-24 17:55:48 +04:00
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrStream_Seek(IStream* This, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
|
|
|
ULONGLONG newoffset;
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
|
|
|
|
|
|
|
newoffset = instance->m_lOffset.QuadPart;
|
|
|
|
|
|
|
|
switch (dwOrigin)
|
|
|
|
{
|
|
|
|
case STREAM_SEEK_SET:
|
|
|
|
newoffset = dlibMove.QuadPart;
|
|
|
|
break;
|
|
|
|
case STREAM_SEEK_CUR:
|
|
|
|
newoffset += dlibMove.QuadPart;
|
|
|
|
break;
|
|
|
|
case STREAM_SEEK_END:
|
|
|
|
newoffset = instance->m_lSize.QuadPart + dlibMove.QuadPart;
|
|
|
|
break;
|
|
|
|
default:
|
2015-06-02 22:15:46 +03:00
|
|
|
return E_INVALIDARG;
|
2014-10-23 21:11:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (newoffset < 0 || newoffset >= instance->m_lSize.QuadPart)
|
2015-06-02 22:15:46 +03:00
|
|
|
return E_FAIL;
|
2014-10-23 21:11:20 +04:00
|
|
|
|
|
|
|
instance->m_lOffset.QuadPart = newoffset;
|
2014-10-24 17:55:48 +04:00
|
|
|
|
2014-10-23 21:11:20 +04:00
|
|
|
if (plibNewPosition)
|
|
|
|
plibNewPosition->QuadPart = instance->m_lOffset.QuadPart;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrStream_SetSize(IStream* This, ULARGE_INTEGER libNewSize)
|
|
|
|
{
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
|
|
|
|
|
|
|
return STG_E_INSUFFICIENTMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrStream_CopyTo(IStream* This, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER *pcbWritten)
|
|
|
|
{
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrStream_Commit(IStream* This, DWORD grfCommitFlags)
|
|
|
|
{
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
|
|
|
|
|
|
|
return STG_E_MEDIUMFULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrStream_Revert(IStream* This)
|
|
|
|
{
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
|
|
|
|
|
|
|
return STG_E_INSUFFICIENTMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrStream_LockRegion(IStream* This, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
|
|
|
|
{
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
|
|
|
|
|
|
|
return STG_E_INSUFFICIENTMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrStream_UnlockRegion(IStream* This, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
|
|
|
|
{
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
|
|
|
|
|
|
|
return STG_E_INSUFFICIENTMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrStream_Stat(IStream* This, STATSTG* pstatstg, DWORD grfStatFlag)
|
|
|
|
{
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
|
|
|
|
|
|
|
if (pstatstg == NULL)
|
|
|
|
return STG_E_INVALIDPOINTER;
|
|
|
|
|
|
|
|
ZeroMemory(pstatstg, sizeof(STATSTG));
|
|
|
|
|
|
|
|
switch (grfStatFlag)
|
|
|
|
{
|
|
|
|
case STATFLAG_DEFAULT:
|
|
|
|
return STG_E_INSUFFICIENTMEMORY;
|
|
|
|
|
|
|
|
case STATFLAG_NONAME:
|
|
|
|
pstatstg->cbSize.QuadPart = instance->m_lSize.QuadPart;
|
|
|
|
pstatstg->grfLocksSupported = LOCK_EXCLUSIVE;
|
|
|
|
pstatstg->grfMode = GENERIC_READ;
|
|
|
|
pstatstg->grfStateBits = 0;
|
|
|
|
pstatstg->type = STGTY_STREAM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATFLAG_NOOPEN:
|
|
|
|
return STG_E_INVALIDFLAG;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return STG_E_INVALIDFLAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrStream_Clone(IStream* This, IStream** ppstm)
|
|
|
|
{
|
|
|
|
CliprdrStream* instance = (CliprdrStream*) This;
|
|
|
|
|
|
|
|
return STG_E_INSUFFICIENTMEMORY;
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
CliprdrStream* CliprdrStream_New(LONG index, void* pData)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
|
|
|
IStream* iStream;
|
|
|
|
CliprdrStream* instance;
|
2014-10-23 23:38:19 +04:00
|
|
|
wfClipboard* clipboard = (wfClipboard*) pData;
|
2014-10-23 21:11:20 +04:00
|
|
|
|
|
|
|
instance = (CliprdrStream*) calloc(1, sizeof(CliprdrStream));
|
|
|
|
|
|
|
|
if (instance)
|
|
|
|
{
|
|
|
|
iStream = &instance->iStream;
|
|
|
|
|
|
|
|
iStream->lpVtbl = (IStreamVtbl*) calloc(1, sizeof(IStreamVtbl));
|
|
|
|
|
|
|
|
if (iStream->lpVtbl)
|
|
|
|
{
|
|
|
|
iStream->lpVtbl->QueryInterface = CliprdrStream_QueryInterface;
|
|
|
|
iStream->lpVtbl->AddRef = CliprdrStream_AddRef;
|
|
|
|
iStream->lpVtbl->Release = CliprdrStream_Release;
|
|
|
|
iStream->lpVtbl->Read = CliprdrStream_Read;
|
|
|
|
iStream->lpVtbl->Write = CliprdrStream_Write;
|
|
|
|
iStream->lpVtbl->Seek = CliprdrStream_Seek;
|
|
|
|
iStream->lpVtbl->SetSize = CliprdrStream_SetSize;
|
|
|
|
iStream->lpVtbl->CopyTo = CliprdrStream_CopyTo;
|
|
|
|
iStream->lpVtbl->Commit = CliprdrStream_Commit;
|
|
|
|
iStream->lpVtbl->Revert = CliprdrStream_Revert;
|
|
|
|
iStream->lpVtbl->LockRegion = CliprdrStream_LockRegion;
|
|
|
|
iStream->lpVtbl->UnlockRegion = CliprdrStream_UnlockRegion;
|
|
|
|
iStream->lpVtbl->Stat = CliprdrStream_Stat;
|
|
|
|
iStream->lpVtbl->Clone = CliprdrStream_Clone;
|
|
|
|
|
|
|
|
instance->m_lRefCount = 1;
|
|
|
|
instance->m_lIndex = index;
|
|
|
|
instance->m_pData = pData;
|
|
|
|
instance->m_lOffset.QuadPart = 0;
|
|
|
|
|
|
|
|
/* get content size of this stream */
|
2014-10-23 23:38:19 +04:00
|
|
|
cliprdr_send_request_filecontents(clipboard, (void*) instance,
|
2014-10-23 21:11:20 +04:00
|
|
|
instance->m_lIndex, FILECONTENTS_SIZE, 0, 0, 8);
|
2014-10-23 23:38:19 +04:00
|
|
|
instance->m_lSize.QuadPart = *((LONGLONG*) clipboard->req_fdata);
|
|
|
|
free(clipboard->req_fdata);
|
2014-10-23 21:11:20 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(instance);
|
|
|
|
instance = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CliprdrStream_Delete(CliprdrStream* instance)
|
|
|
|
{
|
|
|
|
if (instance)
|
|
|
|
{
|
2015-05-11 10:07:39 +03:00
|
|
|
free(instance->iStream.lpVtbl);
|
2014-10-23 21:11:20 +04:00
|
|
|
free(instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IDataObject
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int cliprdr_lookup_format(CliprdrDataObject* instance, FORMATETC* pFormatEtc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < instance->m_nNumFormats; i++)
|
|
|
|
{
|
|
|
|
if ((pFormatEtc->tymed & instance->m_pFormatEtc[i].tymed) &&
|
|
|
|
pFormatEtc->cfFormat == instance->m_pFormatEtc[i].cfFormat &&
|
|
|
|
pFormatEtc->dwAspect == instance->m_pFormatEtc[i].dwAspect)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryInterface(IDataObject* This, REFIID riid, void** ppvObject)
|
|
|
|
{
|
|
|
|
CliprdrDataObject* instance = (CliprdrDataObject*) This;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IDataObject) || IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
IDataObject_AddRef(This);
|
|
|
|
*ppvObject = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppvObject = 0;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE CliprdrDataObject_AddRef(IDataObject* This)
|
|
|
|
{
|
|
|
|
CliprdrDataObject* instance = (CliprdrDataObject*) This;
|
|
|
|
|
|
|
|
return InterlockedIncrement(&instance->m_lRefCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE CliprdrDataObject_Release(IDataObject* This)
|
|
|
|
{
|
|
|
|
LONG count;
|
|
|
|
CliprdrDataObject* instance = (CliprdrDataObject*) This;
|
|
|
|
|
|
|
|
count = InterlockedDecrement(&instance->m_lRefCount);
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
CliprdrDataObject_Delete(instance);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData(IDataObject* This, FORMATETC* pFormatEtc, STGMEDIUM* pMedium)
|
|
|
|
{
|
|
|
|
int i, idx;
|
|
|
|
CliprdrDataObject* instance = (CliprdrDataObject*) This;
|
2014-10-23 23:38:19 +04:00
|
|
|
wfClipboard* clipboard = (wfClipboard*) instance->m_pData;
|
2014-10-23 21:11:20 +04:00
|
|
|
|
|
|
|
if (!pFormatEtc || !pMedium)
|
|
|
|
{
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((idx = cliprdr_lookup_format(instance, pFormatEtc)) == -1)
|
|
|
|
{
|
|
|
|
return DV_E_FORMATETC;
|
|
|
|
}
|
|
|
|
|
|
|
|
pMedium->tymed = instance->m_pFormatEtc[idx].tymed;
|
|
|
|
pMedium->pUnkForRelease = 0;
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
if (instance->m_pFormatEtc[idx].cfFormat == clipboard->ID_FILEDESCRIPTORW)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
if (cliprdr_send_data_request(clipboard, instance->m_pFormatEtc[idx].cfFormat) != 0)
|
2014-10-23 21:11:20 +04:00
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
pMedium->hGlobal = clipboard->hmem; /* points to a FILEGROUPDESCRIPTOR structure */
|
2014-10-23 21:11:20 +04:00
|
|
|
|
|
|
|
/* GlobalLock returns a pointer to the first byte of the memory block,
|
|
|
|
* in which is a FILEGROUPDESCRIPTOR structure, whose first UINT member
|
|
|
|
* is the number of FILEDESCRIPTOR's */
|
2014-10-23 23:38:19 +04:00
|
|
|
instance->m_nStreams = *((PUINT) GlobalLock(clipboard->hmem));
|
|
|
|
GlobalUnlock(clipboard->hmem);
|
2014-10-23 21:11:20 +04:00
|
|
|
|
|
|
|
if (instance->m_nStreams > 0)
|
|
|
|
{
|
|
|
|
if (!instance->m_pStream)
|
|
|
|
{
|
|
|
|
instance->m_pStream = (LPSTREAM*) calloc(instance->m_nStreams, sizeof(LPSTREAM));
|
|
|
|
|
|
|
|
if (instance->m_pStream)
|
|
|
|
{
|
|
|
|
for (i = 0; i < instance->m_nStreams; i++)
|
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
instance->m_pStream[i] = (IStream*) CliprdrStream_New(i, clipboard);
|
2014-10-23 21:11:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!instance->m_pStream)
|
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
if (clipboard->hmem)
|
|
|
|
{
|
|
|
|
GlobalFree(clipboard->hmem);
|
|
|
|
clipboard->hmem = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pMedium->hGlobal = NULL;
|
|
|
|
|
2014-10-23 21:11:20 +04:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
2014-10-23 23:38:19 +04:00
|
|
|
else if (instance->m_pFormatEtc[idx].cfFormat == clipboard->ID_FILECONTENTS)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
|
|
|
if (pFormatEtc->lindex < instance->m_nStreams)
|
|
|
|
{
|
|
|
|
pMedium->pstm = instance->m_pStream[pFormatEtc->lindex];
|
|
|
|
IDataObject_AddRef(instance->m_pStream[pFormatEtc->lindex]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
}
|
2014-10-23 23:38:19 +04:00
|
|
|
else if (instance->m_pFormatEtc[idx].cfFormat == clipboard->ID_PREFERREDDROPEFFECT)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
if (cliprdr_send_data_request(clipboard, instance->m_pFormatEtc[idx].cfFormat) != 0)
|
2014-10-23 21:11:20 +04:00
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
pMedium->hGlobal = clipboard->hmem;
|
2014-10-23 21:11:20 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-24 17:55:48 +04:00
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetDataHere(IDataObject* This, FORMATETC* pformatetc, STGMEDIUM* pmedium)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
|
|
|
CliprdrDataObject* instance = (CliprdrDataObject*) This;
|
|
|
|
|
|
|
|
return DATA_E_FORMATETC;
|
|
|
|
}
|
|
|
|
|
2014-10-24 17:55:48 +04:00
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryGetData(IDataObject* This, FORMATETC* pformatetc)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
|
|
|
CliprdrDataObject* instance = (CliprdrDataObject*) This;
|
|
|
|
|
|
|
|
if (!pformatetc)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
return (cliprdr_lookup_format(instance, pformatetc) == -1) ? DV_E_FORMATETC : S_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetCanonicalFormatEtc(IDataObject* This, FORMATETC* pformatectIn, FORMATETC* pformatetcOut)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
|
|
|
CliprdrDataObject* instance = (CliprdrDataObject*) This;
|
|
|
|
|
|
|
|
if (!pformatetcOut)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
pformatetcOut->ptd = NULL;
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrDataObject_SetData(IDataObject* This, FORMATETC* pformatetc, STGMEDIUM* pmedium, BOOL fRelease)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
|
|
|
CliprdrDataObject* instance = (CliprdrDataObject*) This;
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumFormatEtc(IDataObject* This, DWORD dwDirection, IEnumFORMATETC** ppenumFormatEtc)
|
|
|
|
{
|
|
|
|
CliprdrDataObject* instance = (CliprdrDataObject*) This;
|
|
|
|
|
|
|
|
if (!ppenumFormatEtc)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (dwDirection == DATADIR_GET)
|
|
|
|
{
|
|
|
|
*ppenumFormatEtc = (IEnumFORMATETC*) CliprdrEnumFORMATETC_New(instance->m_nNumFormats, instance->m_pFormatEtc);
|
|
|
|
return (*ppenumFormatEtc) ? S_OK : E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrDataObject_DAdvise(IDataObject* This, FORMATETC* pformatetc, DWORD advf, IAdviseSink* pAdvSink, DWORD* pdwConnection)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
|
|
|
CliprdrDataObject* instance = (CliprdrDataObject*) This;
|
|
|
|
|
|
|
|
return OLE_E_ADVISENOTSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrDataObject_DUnadvise(IDataObject* This, DWORD dwConnection)
|
|
|
|
{
|
|
|
|
CliprdrDataObject* instance = (CliprdrDataObject*) This;
|
|
|
|
|
|
|
|
return OLE_E_ADVISENOTSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumDAdvise(IDataObject* This, IEnumSTATDATA** ppenumAdvise)
|
|
|
|
{
|
|
|
|
CliprdrDataObject* instance = (CliprdrDataObject*) This;
|
|
|
|
|
|
|
|
return OLE_E_ADVISENOTSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
CliprdrDataObject* CliprdrDataObject_New(FORMATETC* fmtetc, STGMEDIUM* stgmed, int count, void* data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CliprdrDataObject* instance;
|
|
|
|
IDataObject* iDataObject;
|
|
|
|
|
|
|
|
instance = (CliprdrDataObject*) calloc(1, sizeof(CliprdrDataObject));
|
|
|
|
|
|
|
|
if (instance)
|
|
|
|
{
|
|
|
|
iDataObject = &instance->iDataObject;
|
|
|
|
|
|
|
|
iDataObject->lpVtbl = (IDataObjectVtbl*) calloc(1, sizeof(IDataObjectVtbl));
|
|
|
|
|
|
|
|
if (iDataObject->lpVtbl)
|
|
|
|
{
|
|
|
|
iDataObject->lpVtbl->QueryInterface = CliprdrDataObject_QueryInterface;
|
|
|
|
iDataObject->lpVtbl->AddRef = CliprdrDataObject_AddRef;
|
|
|
|
iDataObject->lpVtbl->Release = CliprdrDataObject_Release;
|
|
|
|
iDataObject->lpVtbl->GetData = CliprdrDataObject_GetData;
|
|
|
|
iDataObject->lpVtbl->GetDataHere = CliprdrDataObject_GetDataHere;
|
|
|
|
iDataObject->lpVtbl->QueryGetData = CliprdrDataObject_QueryGetData;
|
|
|
|
iDataObject->lpVtbl->GetCanonicalFormatEtc = CliprdrDataObject_GetCanonicalFormatEtc;
|
|
|
|
iDataObject->lpVtbl->SetData = CliprdrDataObject_SetData;
|
|
|
|
iDataObject->lpVtbl->EnumFormatEtc = CliprdrDataObject_EnumFormatEtc;
|
|
|
|
iDataObject->lpVtbl->DAdvise = CliprdrDataObject_DAdvise;
|
|
|
|
iDataObject->lpVtbl->DUnadvise = CliprdrDataObject_DUnadvise;
|
|
|
|
iDataObject->lpVtbl->EnumDAdvise = CliprdrDataObject_EnumDAdvise;
|
|
|
|
|
|
|
|
instance->m_lRefCount = 1;
|
|
|
|
instance->m_nNumFormats = count;
|
|
|
|
instance->m_pData = data;
|
|
|
|
instance->m_nStreams = 0;
|
|
|
|
instance->m_pStream = NULL;
|
|
|
|
|
|
|
|
instance->m_pFormatEtc = (FORMATETC*) calloc(count, sizeof(FORMATETC));
|
|
|
|
instance->m_pStgMedium = (STGMEDIUM*) calloc(count, sizeof(STGMEDIUM));
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
instance->m_pFormatEtc[i] = fmtetc[i];
|
|
|
|
instance->m_pStgMedium[i] = stgmed[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(instance);
|
|
|
|
instance = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CliprdrDataObject_Delete(CliprdrDataObject* instance)
|
|
|
|
{
|
|
|
|
if (instance)
|
|
|
|
{
|
2015-05-11 10:07:39 +03:00
|
|
|
free(instance->iDataObject.lpVtbl);
|
|
|
|
free(instance->m_pFormatEtc);
|
|
|
|
free(instance->m_pStgMedium);
|
2014-10-23 21:11:20 +04:00
|
|
|
|
|
|
|
if (instance->m_pStream)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < instance->m_nStreams; i++)
|
|
|
|
{
|
|
|
|
CliprdrStream_Release(instance->m_pStream[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(instance->m_pStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
BOOL wf_create_file_obj(wfClipboard* clipboard, IDataObject** ppDataObject)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
|
|
|
FORMATETC fmtetc[3];
|
|
|
|
STGMEDIUM stgmeds[3];
|
|
|
|
|
|
|
|
if (!ppDataObject)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
fmtetc[0].cfFormat = RegisterClipboardFormatW(CFSTR_FILEDESCRIPTORW);
|
|
|
|
fmtetc[0].dwAspect = DVASPECT_CONTENT;
|
|
|
|
fmtetc[0].lindex = 0;
|
|
|
|
fmtetc[0].ptd = NULL;
|
|
|
|
fmtetc[0].tymed = TYMED_HGLOBAL;
|
|
|
|
|
|
|
|
stgmeds[0].tymed = TYMED_HGLOBAL;
|
|
|
|
stgmeds[0].hGlobal = NULL;
|
|
|
|
stgmeds[0].pUnkForRelease = NULL;
|
|
|
|
|
|
|
|
fmtetc[1].cfFormat = RegisterClipboardFormatW(CFSTR_FILECONTENTS);
|
|
|
|
fmtetc[1].dwAspect = DVASPECT_CONTENT;
|
|
|
|
fmtetc[1].lindex = 0;
|
|
|
|
fmtetc[1].ptd = NULL;
|
|
|
|
fmtetc[1].tymed = TYMED_ISTREAM;
|
|
|
|
|
|
|
|
stgmeds[1].tymed = TYMED_ISTREAM;
|
|
|
|
stgmeds[1].pstm = NULL;
|
|
|
|
stgmeds[1].pUnkForRelease = NULL;
|
|
|
|
|
|
|
|
fmtetc[2].cfFormat = RegisterClipboardFormatW(CFSTR_PREFERREDDROPEFFECT);
|
|
|
|
fmtetc[2].dwAspect = DVASPECT_CONTENT;
|
|
|
|
fmtetc[2].lindex = 0;
|
|
|
|
fmtetc[2].ptd = NULL;
|
|
|
|
fmtetc[2].tymed = TYMED_HGLOBAL;
|
|
|
|
|
|
|
|
stgmeds[2].tymed = TYMED_HGLOBAL;
|
|
|
|
stgmeds[2].hGlobal = NULL;
|
|
|
|
stgmeds[2].pUnkForRelease = NULL;
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
*ppDataObject = (IDataObject*) CliprdrDataObject_New(fmtetc, stgmeds, 3, clipboard);
|
2014-10-23 21:11:20 +04:00
|
|
|
|
|
|
|
return (*ppDataObject) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wf_destroy_file_obj(IDataObject* instance)
|
|
|
|
{
|
|
|
|
if (instance)
|
|
|
|
IDataObject_Release(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IEnumFORMATETC
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void cliprdr_format_deep_copy(FORMATETC* dest, FORMATETC* source)
|
|
|
|
{
|
|
|
|
*dest = *source;
|
|
|
|
|
|
|
|
if (source->ptd)
|
|
|
|
{
|
|
|
|
dest->ptd = (DVTARGETDEVICE*) CoTaskMemAlloc(sizeof(DVTARGETDEVICE));
|
|
|
|
*(dest->ptd) = *(source->ptd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_QueryInterface(IEnumFORMATETC* This, REFIID riid, void** ppvObject)
|
|
|
|
{
|
|
|
|
CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IEnumFORMATETC) || IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
IEnumFORMATETC_AddRef(This);
|
|
|
|
*ppvObject = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppvObject = 0;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_AddRef(IEnumFORMATETC* This)
|
|
|
|
{
|
|
|
|
CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This;
|
|
|
|
|
|
|
|
return InterlockedIncrement(&instance->m_lRefCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_Release(IEnumFORMATETC* This)
|
|
|
|
{
|
|
|
|
LONG count;
|
|
|
|
CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This;
|
|
|
|
|
|
|
|
count = InterlockedDecrement(&instance->m_lRefCount);
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
CliprdrEnumFORMATETC_Delete(instance);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Next(IEnumFORMATETC* This, ULONG celt, FORMATETC* rgelt, ULONG* pceltFetched)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
|
|
|
ULONG copied = 0;
|
|
|
|
CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This;
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
if (!celt || !rgelt)
|
2014-10-23 21:11:20 +04:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
while ((instance->m_nIndex < instance->m_nNumFormats) && (copied < celt))
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
|
|
|
cliprdr_format_deep_copy(&rgelt[copied++], &instance->m_pFormatEtc[instance->m_nIndex++]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pceltFetched != 0)
|
|
|
|
*pceltFetched = copied;
|
|
|
|
|
2015-06-02 22:15:46 +03:00
|
|
|
return (copied == celt) ? S_OK : E_FAIL;
|
2014-10-23 21:11:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Skip(IEnumFORMATETC* This, ULONG celt)
|
|
|
|
{
|
|
|
|
CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This;
|
|
|
|
|
|
|
|
if (instance->m_nIndex + (LONG) celt > instance->m_nNumFormats)
|
2015-06-02 22:15:46 +03:00
|
|
|
return E_FAIL;
|
2014-10-23 21:11:20 +04:00
|
|
|
|
|
|
|
instance->m_nIndex += celt;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Reset(IEnumFORMATETC* This)
|
|
|
|
{
|
|
|
|
CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This;
|
|
|
|
|
|
|
|
instance->m_nIndex = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Clone(IEnumFORMATETC* This, IEnumFORMATETC **ppEnum)
|
|
|
|
{
|
|
|
|
CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This;
|
|
|
|
|
|
|
|
if (!ppEnum)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppEnum = (IEnumFORMATETC*) CliprdrEnumFORMATETC_New(instance->m_nNumFormats, instance->m_pFormatEtc);
|
|
|
|
|
|
|
|
if (!*ppEnum)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
((CliprdrEnumFORMATETC*) *ppEnum)->m_nIndex = instance->m_nIndex;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
CliprdrEnumFORMATETC* CliprdrEnumFORMATETC_New(int nFormats, FORMATETC* pFormatEtc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CliprdrEnumFORMATETC* instance;
|
|
|
|
IEnumFORMATETC* iEnumFORMATETC;
|
|
|
|
|
|
|
|
if (!pFormatEtc)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
instance = (CliprdrEnumFORMATETC*) calloc(1, sizeof(CliprdrEnumFORMATETC));
|
|
|
|
|
|
|
|
if (instance)
|
|
|
|
{
|
|
|
|
iEnumFORMATETC = &instance->iEnumFORMATETC;
|
|
|
|
|
|
|
|
iEnumFORMATETC->lpVtbl = (IEnumFORMATETCVtbl*) calloc(1, sizeof(IEnumFORMATETCVtbl));
|
|
|
|
|
|
|
|
if (iEnumFORMATETC->lpVtbl)
|
|
|
|
{
|
|
|
|
iEnumFORMATETC->lpVtbl->QueryInterface = CliprdrEnumFORMATETC_QueryInterface;
|
|
|
|
iEnumFORMATETC->lpVtbl->AddRef = CliprdrEnumFORMATETC_AddRef;
|
|
|
|
iEnumFORMATETC->lpVtbl->Release = CliprdrEnumFORMATETC_Release;
|
|
|
|
iEnumFORMATETC->lpVtbl->Next = CliprdrEnumFORMATETC_Next;
|
|
|
|
iEnumFORMATETC->lpVtbl->Skip = CliprdrEnumFORMATETC_Skip;
|
|
|
|
iEnumFORMATETC->lpVtbl->Reset = CliprdrEnumFORMATETC_Reset;
|
|
|
|
iEnumFORMATETC->lpVtbl->Clone = CliprdrEnumFORMATETC_Clone;
|
|
|
|
|
|
|
|
instance->m_lRefCount = 0;
|
|
|
|
instance->m_nIndex = 0;
|
|
|
|
instance->m_nNumFormats = nFormats;
|
|
|
|
instance->m_pFormatEtc = (FORMATETC*) calloc(nFormats, sizeof(FORMATETC));
|
|
|
|
|
|
|
|
for (i = 0; i < nFormats; i++)
|
|
|
|
{
|
|
|
|
cliprdr_format_deep_copy(&instance->m_pFormatEtc[i], &pFormatEtc[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(instance);
|
|
|
|
instance = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CliprdrEnumFORMATETC_Delete(CliprdrEnumFORMATETC* instance)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (instance)
|
|
|
|
{
|
2015-05-11 10:07:39 +03:00
|
|
|
free(instance->iEnumFORMATETC.lpVtbl);
|
2014-10-23 21:11:20 +04:00
|
|
|
|
|
|
|
if (instance->m_pFormatEtc)
|
|
|
|
{
|
|
|
|
for (i = 0; i < instance->m_nNumFormats; i++)
|
|
|
|
{
|
|
|
|
if (instance->m_pFormatEtc[i].ptd)
|
|
|
|
CoTaskMemFree(instance->m_pFormatEtc[i].ptd);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(instance->m_pFormatEtc);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************************/
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
static UINT32 get_local_format_id_by_name(wfClipboard* clipboard, void* format_name)
|
2013-11-05 06:52:17 +04:00
|
|
|
{
|
|
|
|
int i;
|
2014-10-23 06:32:55 +04:00
|
|
|
formatMapping* map;
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
for (i = 0; i < clipboard->map_size; i++)
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
map = &clipboard->format_mappings[i];
|
2014-10-23 06:32:55 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
if ((clipboard->capabilities & CB_USE_LONG_FORMAT_NAMES) != 0)
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
|
|
|
if (map->name)
|
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
if (memcmp(map->name, format_name, wcslen((LPCWSTR) format_name)) == 0)
|
2013-11-05 06:52:17 +04:00
|
|
|
return map->local_format_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
static INLINE BOOL file_transferring(wfClipboard* clipboard)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
return get_local_format_id_by_name(clipboard, _T("FileGroupDescriptorW")) ? TRUE : FALSE;
|
2014-03-10 10:20:53 +04:00
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
static UINT32 get_remote_format_id(wfClipboard* clipboard, UINT32 local_format)
|
2013-11-05 06:52:17 +04:00
|
|
|
{
|
|
|
|
int i;
|
2014-10-23 06:32:55 +04:00
|
|
|
formatMapping* map;
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
for (i = 0; i < clipboard->map_size; i++)
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
map = &clipboard->format_mappings[i];
|
2014-10-23 06:32:55 +04:00
|
|
|
|
2013-11-21 09:45:16 +04:00
|
|
|
if (map->local_format_id == local_format)
|
|
|
|
{
|
2013-11-05 06:52:17 +04:00
|
|
|
return map->remote_format_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-10 10:20:53 +04:00
|
|
|
return local_format;
|
2013-11-05 06:52:17 +04:00
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
static void map_ensure_capacity(wfClipboard* clipboard)
|
2013-11-05 06:52:17 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
if (clipboard->map_size >= clipboard->map_capacity)
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2015-03-11 06:27:39 +03:00
|
|
|
int new_size;
|
|
|
|
formatMapping *new_map;
|
|
|
|
|
2015-03-13 05:32:21 +03:00
|
|
|
new_size = clipboard->map_capacity * 2;
|
2015-03-11 06:27:39 +03:00
|
|
|
new_map = (formatMapping*) realloc(clipboard->format_mappings,
|
|
|
|
sizeof(formatMapping) * new_size);
|
|
|
|
if (!new_map)
|
|
|
|
return;
|
|
|
|
clipboard->format_mappings = new_map;
|
|
|
|
clipboard->map_capacity = new_size;
|
2013-11-05 06:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
static void clear_format_map(wfClipboard* clipboard)
|
2013-11-05 06:52:17 +04:00
|
|
|
{
|
|
|
|
int i;
|
2014-10-23 06:32:55 +04:00
|
|
|
formatMapping* map;
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
if (clipboard->format_mappings)
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
for (i = 0; i < clipboard->map_capacity; i++)
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
map = &clipboard->format_mappings[i];
|
2013-11-05 06:52:17 +04:00
|
|
|
map->remote_format_id = 0;
|
|
|
|
map->local_format_id = 0;
|
|
|
|
|
2015-05-11 10:07:39 +03:00
|
|
|
free(map->name);
|
|
|
|
map->name = NULL;
|
2013-11-05 06:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
clipboard->map_size = 0;
|
2013-11-05 06:52:17 +04:00
|
|
|
}
|
2014-10-23 23:38:19 +04:00
|
|
|
|
|
|
|
int cliprdr_send_tempdir(wfClipboard* clipboard)
|
2014-03-04 12:32:47 +04:00
|
|
|
{
|
2014-10-24 18:30:54 +04:00
|
|
|
CLIPRDR_TEMP_DIRECTORY tempDirectory;
|
2014-10-24 17:55:48 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
GetEnvironmentVariableA("TEMP", tempDirectory.szTempDir, sizeof(tempDirectory.szTempDir));
|
2014-03-04 12:32:47 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
clipboard->context->TempDirectory(clipboard->context, &tempDirectory);
|
2014-03-04 12:32:47 +04:00
|
|
|
|
2014-10-24 17:55:48 +04:00
|
|
|
return 1;
|
2014-03-04 12:32:47 +04:00
|
|
|
}
|
|
|
|
|
2014-10-24 17:55:48 +04:00
|
|
|
static int cliprdr_send_format_list(wfClipboard* clipboard)
|
2013-11-05 06:52:17 +04:00
|
|
|
{
|
2014-10-24 18:30:54 +04:00
|
|
|
int count;
|
|
|
|
int length;
|
|
|
|
UINT32 index;
|
|
|
|
UINT32 numFormats;
|
|
|
|
UINT32 formatId = 0;
|
|
|
|
char formatName[1024];
|
|
|
|
CLIPRDR_FORMAT* format;
|
|
|
|
CLIPRDR_FORMAT* formats;
|
|
|
|
CLIPRDR_FORMAT_LIST formatList;
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
ZeroMemory(&formatList, sizeof(CLIPRDR_FORMAT_LIST));
|
2014-10-23 06:32:55 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
if (!OpenClipboard(clipboard->hwnd))
|
|
|
|
return -1;
|
2014-10-24 17:55:48 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
count = CountClipboardFormats();
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
numFormats = (UINT32) count;
|
|
|
|
formats = (CLIPRDR_FORMAT*) calloc(numFormats, sizeof(CLIPRDR_FORMAT));
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
index = 0;
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
while (formatId = EnumClipboardFormats(formatId))
|
|
|
|
{
|
|
|
|
format = &formats[index++];
|
2014-10-24 17:55:48 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
format->formatId = formatId;
|
2014-10-24 17:55:48 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
length = 0;
|
|
|
|
format->formatName = NULL;
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
if (formatId >= CF_MAX)
|
2014-10-24 17:55:48 +04:00
|
|
|
{
|
2014-10-24 18:30:54 +04:00
|
|
|
length = GetClipboardFormatNameA(formatId, formatName, sizeof(formatName) - 1);
|
2014-10-24 17:55:48 +04:00
|
|
|
}
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
if (length > 0)
|
2014-10-24 17:55:48 +04:00
|
|
|
{
|
2014-10-24 18:30:54 +04:00
|
|
|
format->formatName = _strdup(formatName);
|
2014-10-24 17:55:48 +04:00
|
|
|
}
|
2014-10-24 18:30:54 +04:00
|
|
|
}
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
CloseClipboard();
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
formatList.msgFlags = 0;
|
|
|
|
formatList.numFormats = numFormats;
|
|
|
|
formatList.formats = formats;
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
clipboard->context->ClientFormatList(clipboard->context, &formatList);
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
for (index = 0; index < numFormats; index++)
|
|
|
|
{
|
|
|
|
format = &formats[index];
|
|
|
|
free(format->formatName);
|
2014-03-10 10:20:53 +04:00
|
|
|
}
|
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
free(formats);
|
|
|
|
|
2014-10-24 17:55:48 +04:00
|
|
|
return 1;
|
2014-03-10 10:20:53 +04:00
|
|
|
}
|
|
|
|
|
2014-10-24 17:55:48 +04:00
|
|
|
int cliprdr_send_data_request(wfClipboard* clipboard, UINT32 formatId)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
2014-10-24 18:30:54 +04:00
|
|
|
CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest;
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
formatDataRequest.msgType = CB_FORMAT_DATA_REQUEST;
|
|
|
|
formatDataRequest.msgFlags = CB_RESPONSE_OK;
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
formatDataRequest.requestedFormatId = formatId;
|
|
|
|
clipboard->requestedFormatId = formatId;
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
clipboard->context->ClientFormatDataRequest(clipboard->context, &formatDataRequest);
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-24 17:55:48 +04:00
|
|
|
WaitForSingleObject(clipboard->response_data_event, INFINITE);
|
|
|
|
ResetEvent(clipboard->response_data_event);
|
|
|
|
|
2014-03-10 10:20:53 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
int cliprdr_send_request_filecontents(wfClipboard* clipboard, void* streamid,
|
2014-03-10 10:20:53 +04:00
|
|
|
int index, int flag, DWORD positionhigh, DWORD positionlow, ULONG nreq)
|
|
|
|
{
|
2014-10-24 18:30:54 +04:00
|
|
|
CLIPRDR_FILE_CONTENTS_REQUEST fileContentsRequest;
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
ZeroMemory(&fileContentsRequest, sizeof(CLIPRDR_FILE_CONTENTS_REQUEST));
|
2014-10-24 17:55:48 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
fileContentsRequest.streamId = (UINT32) streamid;
|
|
|
|
fileContentsRequest.listIndex = index;
|
|
|
|
fileContentsRequest.dwFlags = flag;
|
|
|
|
fileContentsRequest.nPositionLow = positionlow;
|
|
|
|
fileContentsRequest.nPositionHigh = positionhigh;
|
|
|
|
fileContentsRequest.cbRequested = nreq;
|
|
|
|
fileContentsRequest.clipDataId = 0;
|
2014-10-24 17:55:48 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
clipboard->context->ClientFileContentsRequest(clipboard->context, &fileContentsRequest);
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
WaitForSingleObject(clipboard->req_fevent, INFINITE);
|
|
|
|
ResetEvent(clipboard->req_fevent);
|
2014-03-10 10:20:53 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 17:55:48 +04:00
|
|
|
int cliprdr_send_response_filecontents(wfClipboard* clipboard, UINT32 streamId, UINT32 size, BYTE* data)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
2014-10-24 18:30:54 +04:00
|
|
|
CLIPRDR_FILE_CONTENTS_RESPONSE fileContentsResponse;
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
ZeroMemory(&fileContentsResponse, sizeof(CLIPRDR_FILE_CONTENTS_RESPONSE));
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
fileContentsResponse.streamId = streamId;
|
|
|
|
fileContentsResponse.cbRequested = size;
|
|
|
|
fileContentsResponse.requestedData = data;
|
2014-10-24 17:55:48 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
clipboard->context->ClientFileContentsResponse(clipboard->context, &fileContentsResponse);
|
2014-03-10 10:20:53 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-05 06:52:17 +04:00
|
|
|
static LRESULT CALLBACK cliprdr_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
static wfClipboard* clipboard = NULL;
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2013-11-21 09:45:16 +04:00
|
|
|
switch (Msg)
|
|
|
|
{
|
2013-11-05 06:52:17 +04:00
|
|
|
case WM_CREATE:
|
2015-01-20 13:26:08 +03:00
|
|
|
DEBUG_CLIPRDR("info: WM_CREATE");
|
2014-10-23 23:38:19 +04:00
|
|
|
clipboard = (wfClipboard*)((CREATESTRUCT*) lParam)->lpCreateParams;
|
2014-07-23 17:35:42 +04:00
|
|
|
if (!AddClipboardFormatListener(hWnd)) {
|
|
|
|
DEBUG_CLIPRDR("error: AddClipboardFormatListener failed with %#x.", GetLastError());
|
2013-11-05 06:52:17 +04:00
|
|
|
}
|
2014-10-23 23:38:19 +04:00
|
|
|
clipboard->hwnd = hWnd;
|
2013-11-05 06:52:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
2015-01-20 13:26:08 +03:00
|
|
|
DEBUG_CLIPRDR("info: WM_CLOSE");
|
2014-07-23 17:35:42 +04:00
|
|
|
RemoveClipboardFormatListener(hWnd);
|
2013-11-05 06:52:17 +04:00
|
|
|
break;
|
|
|
|
|
2014-07-23 17:35:42 +04:00
|
|
|
case WM_CLIPBOARDUPDATE:
|
2015-01-20 13:26:08 +03:00
|
|
|
DEBUG_CLIPRDR("info: WM_CLIPBOARDUPDATE");
|
2014-10-24 02:17:53 +04:00
|
|
|
if (clipboard->sync)
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
if ((GetClipboardOwner() != clipboard->hwnd) &&
|
|
|
|
(S_FALSE == OleIsCurrentClipboard(clipboard->data_obj)))
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
if (clipboard->hmem)
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
GlobalFree(clipboard->hmem);
|
|
|
|
clipboard->hmem = NULL;
|
2013-11-05 06:52:17 +04:00
|
|
|
}
|
2014-10-23 23:38:19 +04:00
|
|
|
|
|
|
|
cliprdr_send_format_list(clipboard);
|
2013-11-05 06:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_RENDERALLFORMATS:
|
2015-01-20 13:26:08 +03:00
|
|
|
DEBUG_CLIPRDR("info: WM_RENDERALLFORMATS");
|
2013-11-05 06:52:17 +04:00
|
|
|
/* discard all contexts in clipboard */
|
2014-10-23 23:38:19 +04:00
|
|
|
if (!OpenClipboard(clipboard->hwnd))
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2013-11-05 06:52:17 +04:00
|
|
|
DEBUG_CLIPRDR("OpenClipboard failed with 0x%x", GetLastError());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
EmptyClipboard();
|
|
|
|
CloseClipboard();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_RENDERFORMAT:
|
2015-01-20 13:26:08 +03:00
|
|
|
DEBUG_CLIPRDR("info: WM_RENDERFORMAT");
|
2014-10-23 23:38:19 +04:00
|
|
|
if (cliprdr_send_data_request(clipboard, (UINT32) wParam) != 0)
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2013-11-05 06:52:17 +04:00
|
|
|
DEBUG_CLIPRDR("error: cliprdr_send_data_request failed.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
if (!SetClipboardData((UINT) wParam, clipboard->hmem))
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2013-11-05 06:52:17 +04:00
|
|
|
DEBUG_CLIPRDR("SetClipboardData failed with 0x%x", GetLastError());
|
2014-10-23 23:38:19 +04:00
|
|
|
|
|
|
|
if (clipboard->hmem)
|
|
|
|
{
|
|
|
|
GlobalFree(clipboard->hmem);
|
|
|
|
clipboard->hmem = NULL;
|
|
|
|
}
|
2013-11-05 06:52:17 +04:00
|
|
|
}
|
|
|
|
/* Note: GlobalFree() is not needed when success */
|
|
|
|
break;
|
|
|
|
|
2014-03-10 10:20:53 +04:00
|
|
|
case WM_CLIPRDR_MESSAGE:
|
2015-01-20 13:26:08 +03:00
|
|
|
DEBUG_CLIPRDR("info: WM_CLIPRDR_MESSAGE");
|
2014-03-10 10:20:53 +04:00
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case OLE_SETCLIPBOARD:
|
2015-01-20 13:26:08 +03:00
|
|
|
DEBUG_CLIPRDR("info: OLE_SETCLIPBOARD");
|
2014-10-23 23:38:19 +04:00
|
|
|
if (wf_create_file_obj(clipboard, &clipboard->data_obj))
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
if (OleSetClipboard(clipboard->data_obj) != S_OK)
|
2014-10-23 21:11:20 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
wf_destroy_file_obj(clipboard->data_obj);
|
|
|
|
clipboard->data_obj = NULL;
|
2014-10-23 21:11:20 +04:00
|
|
|
}
|
|
|
|
}
|
2014-03-10 10:20:53 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-11-05 06:52:17 +04:00
|
|
|
case WM_DESTROYCLIPBOARD:
|
|
|
|
case WM_ASKCBFORMATNAME:
|
|
|
|
case WM_HSCROLLCLIPBOARD:
|
|
|
|
case WM_PAINTCLIPBOARD:
|
|
|
|
case WM_SIZECLIPBOARD:
|
|
|
|
case WM_VSCROLLCLIPBOARD:
|
|
|
|
default:
|
|
|
|
return DefWindowProc(hWnd, Msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-10-23 21:11:20 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
static int create_cliprdr_window(wfClipboard* clipboard)
|
2013-11-05 06:52:17 +04:00
|
|
|
{
|
|
|
|
WNDCLASSEX wnd_cls;
|
|
|
|
|
|
|
|
ZeroMemory(&wnd_cls, sizeof(WNDCLASSEX));
|
2014-10-23 21:11:20 +04:00
|
|
|
wnd_cls.cbSize = sizeof(WNDCLASSEX);
|
|
|
|
wnd_cls.style = CS_OWNDC;
|
|
|
|
wnd_cls.lpfnWndProc = cliprdr_proc;
|
|
|
|
wnd_cls.cbClsExtra = 0;
|
|
|
|
wnd_cls.cbWndExtra = 0;
|
|
|
|
wnd_cls.hIcon = NULL;
|
|
|
|
wnd_cls.hCursor = NULL;
|
2013-11-05 06:52:17 +04:00
|
|
|
wnd_cls.hbrBackground = NULL;
|
2014-10-23 21:11:20 +04:00
|
|
|
wnd_cls.lpszMenuName = NULL;
|
2014-10-23 23:38:19 +04:00
|
|
|
wnd_cls.lpszClassName = _T("ClipboardHiddenMessageProcessor");
|
2014-10-23 21:11:20 +04:00
|
|
|
wnd_cls.hInstance = GetModuleHandle(NULL);
|
|
|
|
wnd_cls.hIconSm = NULL;
|
|
|
|
|
2013-11-05 06:52:17 +04:00
|
|
|
RegisterClassEx(&wnd_cls);
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
clipboard->hwnd = CreateWindowEx(WS_EX_LEFT,
|
|
|
|
_T("ClipboardHiddenMessageProcessor"),
|
|
|
|
_T("rdpclip"),
|
|
|
|
0, 0, 0, 0, 0, HWND_MESSAGE, NULL, GetModuleHandle(NULL), clipboard);
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
if (!clipboard->hwnd)
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2013-11-05 06:52:17 +04:00
|
|
|
DEBUG_CLIPRDR("error: CreateWindowEx failed with %x.", GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-23 06:32:55 +04:00
|
|
|
static void* cliprdr_thread_func(void* arg)
|
2013-11-05 06:52:17 +04:00
|
|
|
{
|
|
|
|
int ret;
|
2014-02-10 09:34:17 +04:00
|
|
|
MSG msg;
|
|
|
|
BOOL mcode;
|
2014-10-23 23:38:19 +04:00
|
|
|
wfClipboard* clipboard = (wfClipboard*) arg;
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-03-10 10:20:53 +04:00
|
|
|
OleInitialize(0);
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
if ((ret = create_cliprdr_window(clipboard)) != 0)
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2013-11-05 06:52:17 +04:00
|
|
|
DEBUG_CLIPRDR("error: create clipboard window failed.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-05 17:24:42 +04:00
|
|
|
while ((mcode = GetMessage(&msg, 0, 0, 0)) != 0)
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
|
|
|
if (mcode == -1)
|
|
|
|
{
|
2013-11-05 06:52:17 +04:00
|
|
|
DEBUG_CLIPRDR("error: clipboard thread GetMessage failed.");
|
|
|
|
break;
|
2013-11-21 09:45:16 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-05 06:52:17 +04:00
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-10 10:20:53 +04:00
|
|
|
OleUninitialize();
|
|
|
|
|
2013-11-05 06:52:17 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
static void clear_file_array(wfClipboard* clipboard)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* clear file_names array */
|
2014-10-23 23:38:19 +04:00
|
|
|
if (clipboard->file_names)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
for (i = 0; i < clipboard->nFiles; i++)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
2015-05-11 10:07:39 +03:00
|
|
|
free(clipboard->file_names[i]);
|
|
|
|
clipboard->file_names[i] = NULL;
|
2014-03-10 10:20:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear fileDescriptor array */
|
2014-10-23 23:38:19 +04:00
|
|
|
if (clipboard->fileDescriptor)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
for (i = 0; i < clipboard->nFiles; i++)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
2015-05-11 10:07:39 +03:00
|
|
|
free(clipboard->fileDescriptor[i]);
|
|
|
|
clipboard->fileDescriptor[i] = NULL;
|
2014-03-10 10:20:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
clipboard->nFiles = 0;
|
2012-07-21 01:05:06 +04:00
|
|
|
}
|
|
|
|
|
2014-10-23 06:32:55 +04:00
|
|
|
static BOOL wf_cliprdr_get_file_contents(WCHAR* file_name, BYTE* buffer,
|
|
|
|
int positionLow, int positionHigh, int nRequested, unsigned int* puSize)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
DWORD nGet;
|
|
|
|
|
2014-10-23 06:32:55 +04:00
|
|
|
if (!file_name || !buffer || !puSize)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "get file contents Invalid Arguments.");
|
2014-03-10 10:20:53 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-10-23 06:32:55 +04:00
|
|
|
|
|
|
|
hFile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
|
|
|
|
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
|
|
|
|
2014-03-10 10:20:53 +04:00
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-10-23 06:32:55 +04:00
|
|
|
SetFilePointer(hFile, positionLow, (PLONG) &positionHigh, FILE_BEGIN);
|
2014-03-10 10:20:53 +04:00
|
|
|
|
|
|
|
if (!ReadFile(hFile, buffer, nRequested, &nGet, NULL))
|
|
|
|
{
|
|
|
|
DWORD err = GetLastError();
|
|
|
|
DEBUG_CLIPRDR("ReadFile failed with 0x%x.", err);
|
|
|
|
}
|
2014-10-23 06:32:55 +04:00
|
|
|
|
2014-03-10 10:20:53 +04:00
|
|
|
CloseHandle(hFile);
|
|
|
|
|
|
|
|
*puSize = nGet;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* path_name has a '\' at the end. e.g. c:\newfolder\, file_name is c:\newfolder\new.txt */
|
2014-10-23 06:32:55 +04:00
|
|
|
static FILEDESCRIPTORW* wf_cliprdr_get_file_descriptor(WCHAR* file_name, int pathLen)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
|
|
|
HANDLE hFile;
|
2014-10-23 06:32:55 +04:00
|
|
|
FILEDESCRIPTORW* fd;
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-23 06:32:55 +04:00
|
|
|
fd = (FILEDESCRIPTORW*) calloc(1, sizeof(FILEDESCRIPTORW));
|
2014-05-10 17:50:36 +04:00
|
|
|
|
2014-03-10 10:20:53 +04:00
|
|
|
if (!fd)
|
|
|
|
return NULL;
|
|
|
|
|
2014-05-10 17:50:36 +04:00
|
|
|
hFile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ,
|
|
|
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
|
|
|
|
2014-03-10 10:20:53 +04:00
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
free(fd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd->dwFlags = FD_ATTRIBUTES | FD_FILESIZE | FD_WRITESTIME | FD_PROGRESSUI;
|
|
|
|
|
|
|
|
fd->dwFileAttributes = GetFileAttributes(file_name);
|
2014-05-10 17:50:36 +04:00
|
|
|
|
2014-03-10 10:20:53 +04:00
|
|
|
if (!GetFileTime(hFile, NULL, NULL, &fd->ftLastWriteTime))
|
|
|
|
{
|
|
|
|
fd->dwFlags &= ~FD_WRITESTIME;
|
|
|
|
}
|
2014-05-10 17:50:36 +04:00
|
|
|
|
2014-03-10 10:20:53 +04:00
|
|
|
fd->nFileSizeLow = GetFileSize(hFile, &fd->nFileSizeHigh);
|
|
|
|
|
2014-05-10 17:50:36 +04:00
|
|
|
wcscpy_s(fd->cFileName, sizeof(fd->cFileName) / 2, file_name + pathLen);
|
2014-03-10 10:20:53 +04:00
|
|
|
CloseHandle(hFile);
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
static void wf_cliprdr_array_ensure_capacity(wfClipboard* clipboard)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
2014-10-23 23:38:19 +04:00
|
|
|
if (clipboard->nFiles == clipboard->file_array_size)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
2015-03-11 06:27:39 +03:00
|
|
|
int new_size;
|
|
|
|
FILEDESCRIPTORW **new_fd;
|
|
|
|
WCHAR **new_name;
|
|
|
|
|
|
|
|
new_size = clipboard->file_array_size * 2;
|
2015-03-11 11:37:28 +03:00
|
|
|
|
2015-03-11 06:27:39 +03:00
|
|
|
new_fd = (FILEDESCRIPTORW**) realloc(clipboard->fileDescriptor, new_size * sizeof(FILEDESCRIPTORW*));
|
2015-03-11 11:37:28 +03:00
|
|
|
if (new_fd)
|
|
|
|
clipboard->fileDescriptor = new_fd;
|
|
|
|
|
2015-03-11 06:27:39 +03:00
|
|
|
new_name = (WCHAR**) realloc(clipboard->file_names, new_size * sizeof(WCHAR*));
|
2015-03-11 11:37:28 +03:00
|
|
|
if (new_name)
|
|
|
|
clipboard->file_names = new_name;
|
|
|
|
|
2015-03-11 06:27:39 +03:00
|
|
|
if (!new_fd || !new_name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
clipboard->file_array_size *= new_size;
|
2014-03-10 10:20:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
static void wf_cliprdr_add_to_file_arrays(wfClipboard* clipboard, WCHAR* full_file_name, int pathLen)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
|
|
|
/* add to name array */
|
2014-10-23 23:38:19 +04:00
|
|
|
clipboard->file_names[clipboard->nFiles] = (LPWSTR) malloc(MAX_PATH * 2);
|
|
|
|
wcscpy_s(clipboard->file_names[clipboard->nFiles], MAX_PATH, full_file_name);
|
2014-03-10 10:20:53 +04:00
|
|
|
|
|
|
|
/* add to descriptor array */
|
2014-10-23 23:38:19 +04:00
|
|
|
clipboard->fileDescriptor[clipboard->nFiles] = wf_cliprdr_get_file_descriptor(full_file_name, pathLen);
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
clipboard->nFiles++;
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
wf_cliprdr_array_ensure_capacity(clipboard);
|
2014-03-10 10:20:53 +04:00
|
|
|
}
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
static void wf_cliprdr_traverse_directory(wfClipboard* clipboard, WCHAR* Dir, int pathLen)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
|
|
|
HANDLE hFind;
|
2014-10-23 06:32:55 +04:00
|
|
|
WCHAR DirSpec[MAX_PATH];
|
|
|
|
WIN32_FIND_DATA FindFileData;
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-23 21:11:20 +04:00
|
|
|
StringCchCopy(DirSpec, MAX_PATH, Dir);
|
|
|
|
StringCchCat(DirSpec, MAX_PATH, TEXT("\\*"));
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-23 06:32:55 +04:00
|
|
|
hFind = FindFirstFile(DirSpec, &FindFileData);
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-23 06:32:55 +04:00
|
|
|
if (hFind == INVALID_HANDLE_VALUE)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
|
|
|
DEBUG_CLIPRDR("FindFirstFile failed with 0x%x.", GetLastError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-23 06:32:55 +04:00
|
|
|
while (FindNextFile(hFind, &FindFileData))
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
2014-10-23 21:11:20 +04:00
|
|
|
if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0
|
2014-10-23 23:38:19 +04:00
|
|
|
&& wcscmp(FindFileData.cFileName, _T(".")) == 0
|
|
|
|
|| wcscmp(FindFileData.cFileName, _T("..")) == 0)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-10-23 21:11:20 +04:00
|
|
|
if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) !=0)
|
2014-03-10 10:20:53 +04:00
|
|
|
{
|
2014-10-23 06:32:55 +04:00
|
|
|
WCHAR DirAdd[MAX_PATH];
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-23 21:11:20 +04:00
|
|
|
StringCchCopy(DirAdd, MAX_PATH, Dir);
|
2014-10-23 23:38:19 +04:00
|
|
|
StringCchCat(DirAdd, MAX_PATH, _T("\\"));
|
2014-10-23 21:11:20 +04:00
|
|
|
StringCchCat(DirAdd, MAX_PATH, FindFileData.cFileName);
|
2014-10-23 23:38:19 +04:00
|
|
|
wf_cliprdr_add_to_file_arrays(clipboard, DirAdd, pathLen);
|
|
|
|
wf_cliprdr_traverse_directory(clipboard, DirAdd, pathLen);
|
2014-03-10 10:20:53 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR fileName[MAX_PATH];
|
|
|
|
|
2014-10-23 21:11:20 +04:00
|
|
|
StringCchCopy(fileName, MAX_PATH, Dir);
|
2014-10-23 23:38:19 +04:00
|
|
|
StringCchCat(fileName, MAX_PATH, _T("\\"));
|
2014-10-23 21:11:20 +04:00
|
|
|
StringCchCat(fileName, MAX_PATH, FindFileData.cFileName);
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
wf_cliprdr_add_to_file_arrays(clipboard, fileName, pathLen);
|
2014-03-10 10:20:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FindClose(hFind);
|
|
|
|
}
|
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
int wf_cliprdr_send_client_capabilities(wfClipboard* clipboard)
|
2012-07-21 01:05:06 +04:00
|
|
|
{
|
2014-10-24 18:30:54 +04:00
|
|
|
CLIPRDR_CAPABILITIES capabilities;
|
|
|
|
CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet;
|
|
|
|
|
|
|
|
capabilities.cCapabilitiesSets = 1;
|
|
|
|
capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*) &(generalCapabilitySet);
|
|
|
|
|
|
|
|
generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
|
|
|
|
generalCapabilitySet.capabilitySetLength = 12;
|
|
|
|
|
|
|
|
generalCapabilitySet.version = CB_CAPS_VERSION_2;
|
|
|
|
generalCapabilitySet.generalFlags = CB_USE_LONG_FORMAT_NAMES;
|
|
|
|
|
|
|
|
clipboard->context->ClientCapabilities(clipboard->context, &capabilities);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wf_cliprdr_monitor_ready(CliprdrClientContext* context, CLIPRDR_MONITOR_READY* monitorReady)
|
|
|
|
{
|
|
|
|
wfClipboard* clipboard = (wfClipboard*) context->custom;
|
|
|
|
|
|
|
|
clipboard->sync = TRUE;
|
|
|
|
wf_cliprdr_send_client_capabilities(clipboard);
|
|
|
|
cliprdr_send_format_list(clipboard);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wf_cliprdr_server_capabilities(CliprdrClientContext* context, CLIPRDR_CAPABILITIES* capabilities)
|
|
|
|
{
|
|
|
|
UINT32 index;
|
|
|
|
CLIPRDR_CAPABILITY_SET* capabilitySet;
|
|
|
|
wfClipboard* clipboard = (wfClipboard*) context->custom;
|
|
|
|
|
|
|
|
for (index = 0; index < capabilities->cCapabilitiesSets; index++)
|
|
|
|
{
|
|
|
|
capabilitySet = &(capabilities->capabilitySets[index]);
|
|
|
|
|
|
|
|
if ((capabilitySet->capabilitySetType == CB_CAPSTYPE_GENERAL) &&
|
|
|
|
(capabilitySet->capabilitySetLength >= CB_CAPSTYPE_GENERAL_LEN))
|
|
|
|
{
|
|
|
|
CLIPRDR_GENERAL_CAPABILITY_SET* generalCapabilitySet
|
|
|
|
= (CLIPRDR_GENERAL_CAPABILITY_SET*) capabilitySet;
|
|
|
|
|
|
|
|
clipboard->capabilities = generalCapabilitySet->generalFlags;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wf_cliprdr_server_format_list(CliprdrClientContext* context, CLIPRDR_FORMAT_LIST* formatList)
|
|
|
|
{
|
|
|
|
UINT32 i, j;
|
|
|
|
formatMapping* mapping;
|
|
|
|
CLIPRDR_FORMAT* format;
|
|
|
|
wfClipboard* clipboard = (wfClipboard*) context->custom;
|
|
|
|
|
|
|
|
clear_format_map(clipboard);
|
|
|
|
|
|
|
|
for (i = j = 0; i < formatList->numFormats; i++)
|
|
|
|
{
|
|
|
|
format = &(formatList->formats[i]);
|
|
|
|
mapping = &(clipboard->format_mappings[j++]);
|
|
|
|
|
|
|
|
mapping->remote_format_id = format->formatId;
|
|
|
|
|
|
|
|
if (format->formatName)
|
|
|
|
{
|
|
|
|
mapping->name = _strdup(format->formatName);
|
|
|
|
mapping->local_format_id = RegisterClipboardFormatA((LPCSTR) mapping->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mapping->name = NULL;
|
|
|
|
mapping->local_format_id = mapping->remote_format_id;
|
|
|
|
}
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
clipboard->map_size++;
|
|
|
|
map_ensure_capacity(clipboard);
|
|
|
|
}
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
if (file_transferring(clipboard))
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2014-10-24 18:30:54 +04:00
|
|
|
PostMessage(clipboard->hwnd, WM_CLIPRDR_MESSAGE, OLE_SETCLIPBOARD, 0);
|
2013-11-21 09:45:16 +04:00
|
|
|
}
|
2014-10-24 18:30:54 +04:00
|
|
|
else
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2014-10-24 18:30:54 +04:00
|
|
|
if (!OpenClipboard(clipboard->hwnd))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (EmptyClipboard())
|
|
|
|
{
|
|
|
|
for (i = 0; i < (UINT32) clipboard->map_size; i++)
|
|
|
|
{
|
|
|
|
SetClipboardData(clipboard->format_mappings[i].local_format_id, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseClipboard();
|
2013-11-21 09:45:16 +04:00
|
|
|
}
|
2014-10-24 18:30:54 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wf_cliprdr_server_format_list_response(CliprdrClientContext* context, CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
|
|
|
|
{
|
|
|
|
wfClipboard* clipboard = (wfClipboard*) context->custom;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int wf_cliprdr_server_lock_clipboard_data(CliprdrClientContext* context, CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
|
|
|
|
{
|
|
|
|
wfClipboard* clipboard = (wfClipboard*) context->custom;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int wf_cliprdr_server_unlock_clipboard_data(CliprdrClientContext* context, CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
|
|
|
|
{
|
|
|
|
wfClipboard* clipboard = (wfClipboard*) context->custom;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wf_cliprdr_server_format_data_request(CliprdrClientContext* context, CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
|
|
|
|
{
|
|
|
|
int size = 0;
|
|
|
|
char* buff = NULL;
|
|
|
|
char* globlemem = NULL;
|
|
|
|
HANDLE hClipdata = NULL;
|
|
|
|
UINT32 requestedFormatId;
|
|
|
|
CLIPRDR_FORMAT_DATA_RESPONSE response;
|
|
|
|
wfClipboard* clipboard = (wfClipboard*) context->custom;
|
|
|
|
|
|
|
|
requestedFormatId = formatDataRequest->requestedFormatId;
|
|
|
|
|
|
|
|
if (requestedFormatId == RegisterClipboardFormatW(_T("FileGroupDescriptorW")))
|
2013-11-21 09:45:16 +04:00
|
|
|
{
|
2014-10-23 06:32:55 +04:00
|
|
|
int len;
|
|
|
|
int i;
|
|
|
|
WCHAR* wFileName;
|
|
|
|
unsigned int uSize;
|
2014-03-10 10:20:53 +04:00
|
|
|
HRESULT result;
|
|
|
|
LPDATAOBJECT dataObj;
|
|
|
|
FORMATETC format_etc;
|
|
|
|
STGMEDIUM stg_medium;
|
2014-10-23 06:32:55 +04:00
|
|
|
DROPFILES* dropFiles;
|
2014-03-10 10:20:53 +04:00
|
|
|
|
|
|
|
result = OleGetClipboard(&dataObj);
|
2014-10-23 06:32:55 +04:00
|
|
|
|
2015-06-02 20:52:52 +03:00
|
|
|
if (FAILED(result))
|
2014-10-24 18:30:54 +04:00
|
|
|
return -1;
|
2014-10-24 02:17:53 +04:00
|
|
|
|
|
|
|
ZeroMemory(&format_etc, sizeof(FORMATETC));
|
|
|
|
ZeroMemory(&stg_medium, sizeof(STGMEDIUM));
|
|
|
|
|
|
|
|
/* try to get FileGroupDescriptorW struct from OLE */
|
|
|
|
format_etc.cfFormat = requestedFormatId;
|
|
|
|
format_etc.tymed = TYMED_HGLOBAL;
|
|
|
|
format_etc.dwAspect = 1;
|
|
|
|
format_etc.lindex = -1;
|
|
|
|
format_etc.ptd = 0;
|
|
|
|
|
|
|
|
result = IDataObject_GetData(dataObj, &format_etc, &stg_medium);
|
|
|
|
|
|
|
|
if (SUCCEEDED(result))
|
|
|
|
{
|
|
|
|
DEBUG_CLIPRDR("Got FileGroupDescriptorW.");
|
|
|
|
globlemem = (char*) GlobalLock(stg_medium.hGlobal);
|
|
|
|
uSize = GlobalSize(stg_medium.hGlobal);
|
|
|
|
size = uSize;
|
|
|
|
buff = (char*) malloc(uSize);
|
|
|
|
CopyMemory(buff, globlemem, uSize);
|
|
|
|
GlobalUnlock(stg_medium.hGlobal);
|
|
|
|
|
|
|
|
ReleaseStgMedium(&stg_medium);
|
|
|
|
|
|
|
|
clear_file_array(clipboard);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* get DROPFILES struct from OLE */
|
|
|
|
format_etc.cfFormat = CF_HDROP;
|
|
|
|
format_etc.tymed = TYMED_HGLOBAL;
|
|
|
|
format_etc.dwAspect = 1;
|
|
|
|
format_etc.lindex = -1;
|
|
|
|
|
|
|
|
result = IDataObject_GetData(dataObj, &format_etc, &stg_medium);
|
|
|
|
|
2015-06-02 20:52:52 +03:00
|
|
|
if (FAILED(result)) {
|
2014-10-24 02:17:53 +04:00
|
|
|
DEBUG_CLIPRDR("dataObj->GetData failed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
globlemem = (char*) GlobalLock(stg_medium.hGlobal);
|
|
|
|
|
|
|
|
if (!globlemem)
|
|
|
|
{
|
|
|
|
GlobalUnlock(stg_medium.hGlobal);
|
|
|
|
|
|
|
|
ReleaseStgMedium(&stg_medium);
|
|
|
|
clipboard->nFiles = 0;
|
|
|
|
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
uSize = GlobalSize(stg_medium.hGlobal);
|
|
|
|
|
|
|
|
dropFiles = (DROPFILES*) malloc(uSize);
|
|
|
|
memcpy(dropFiles, globlemem, uSize);
|
|
|
|
|
|
|
|
GlobalUnlock(stg_medium.hGlobal);
|
|
|
|
|
|
|
|
ReleaseStgMedium(&stg_medium);
|
|
|
|
|
|
|
|
clear_file_array(clipboard);
|
|
|
|
|
|
|
|
if (dropFiles->fWide)
|
|
|
|
{
|
|
|
|
WCHAR* p;
|
|
|
|
int str_len;
|
|
|
|
int offset;
|
|
|
|
int pathLen;
|
|
|
|
|
|
|
|
/* dropFiles contains file names */
|
|
|
|
for (wFileName = (WCHAR*)((char*)dropFiles + dropFiles->pFiles); (len = wcslen(wFileName)) > 0; wFileName += len + 1)
|
|
|
|
{
|
|
|
|
/* get path name */
|
|
|
|
str_len = wcslen(wFileName);
|
|
|
|
offset = str_len;
|
|
|
|
/* find the last '\' in full file name */
|
|
|
|
for (p = wFileName + offset; *p != L'\\'; p--)
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
p += 1;
|
|
|
|
pathLen = wcslen(wFileName) - wcslen(p);
|
|
|
|
|
|
|
|
wf_cliprdr_add_to_file_arrays(clipboard, wFileName, pathLen);
|
|
|
|
|
|
|
|
if ((clipboard->fileDescriptor[clipboard->nFiles - 1]->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
|
|
|
|
{
|
|
|
|
/* this is a directory */
|
|
|
|
wf_cliprdr_traverse_directory(clipboard, wFileName, pathLen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char* p;
|
|
|
|
|
|
|
|
for (p = (char*)((char*)dropFiles + dropFiles->pFiles); (len = strlen(p)) > 0; p += len + 1, clipboard->nFiles++)
|
|
|
|
{
|
|
|
|
int cchWideChar;
|
|
|
|
|
|
|
|
cchWideChar = MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, NULL, 0);
|
|
|
|
clipboard->file_names[clipboard->nFiles] = (LPWSTR) malloc(cchWideChar * 2);
|
|
|
|
MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, clipboard->file_names[clipboard->nFiles], cchWideChar);
|
|
|
|
|
2015-03-11 06:27:39 +03:00
|
|
|
map_ensure_capacity(clipboard);
|
2014-10-24 02:17:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
size = 4 + clipboard->nFiles * sizeof(FILEDESCRIPTORW);
|
|
|
|
buff = (char*) malloc(size);
|
|
|
|
|
|
|
|
*((UINT32*) buff) = clipboard->nFiles;
|
|
|
|
|
|
|
|
for (i = 0; i < clipboard->nFiles; i++)
|
|
|
|
{
|
|
|
|
if (clipboard->fileDescriptor[i])
|
|
|
|
{
|
|
|
|
memcpy(buff + 4 + i * sizeof(FILEDESCRIPTORW), clipboard->fileDescriptor[i], sizeof(FILEDESCRIPTORW));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IDataObject_Release(dataObj);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!OpenClipboard(clipboard->hwnd))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
hClipdata = GetClipboardData(requestedFormatId);
|
|
|
|
|
|
|
|
if (!hClipdata)
|
|
|
|
{
|
|
|
|
CloseClipboard();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
globlemem = (char*) GlobalLock(hClipdata);
|
|
|
|
size = (int) GlobalSize(hClipdata);
|
|
|
|
|
|
|
|
buff = (char*) malloc(size);
|
|
|
|
CopyMemory(buff, globlemem, size);
|
|
|
|
|
|
|
|
GlobalUnlock(hClipdata);
|
|
|
|
|
|
|
|
CloseClipboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
ZeroMemory(&response, sizeof(CLIPRDR_FORMAT_DATA_RESPONSE));
|
|
|
|
|
|
|
|
response.msgFlags = CB_RESPONSE_OK;
|
|
|
|
response.dataLen = size;
|
|
|
|
response.requestedFormatData = (BYTE*) buff;
|
|
|
|
|
|
|
|
clipboard->context->ClientFormatDataResponse(clipboard->context, &response);
|
|
|
|
|
|
|
|
free(buff);
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wf_cliprdr_server_format_data_response(CliprdrClientContext* context, CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
|
2014-10-24 02:17:53 +04:00
|
|
|
{
|
|
|
|
BYTE* data;
|
|
|
|
HANDLE hMem;
|
|
|
|
wfClipboard* clipboard = (wfClipboard*) context->custom;
|
|
|
|
|
|
|
|
hMem = GlobalAlloc(GMEM_FIXED, formatDataResponse->dataLen);
|
|
|
|
data = (BYTE*) GlobalLock(hMem);
|
|
|
|
CopyMemory(data, formatDataResponse->requestedFormatData, formatDataResponse->dataLen);
|
|
|
|
GlobalUnlock(hMem);
|
|
|
|
|
|
|
|
clipboard->hmem = hMem;
|
|
|
|
SetEvent(clipboard->response_data_event);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int wf_cliprdr_server_file_contents_request(CliprdrClientContext* context, CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
|
|
|
|
{
|
2014-10-24 17:55:48 +04:00
|
|
|
UINT32 uSize = 0;
|
|
|
|
BYTE* pData = NULL;
|
|
|
|
HRESULT hRet = S_OK;
|
|
|
|
FORMATETC vFormatEtc;
|
|
|
|
LPDATAOBJECT pDataObj = NULL;
|
|
|
|
STGMEDIUM vStgMedium;
|
|
|
|
LPSTREAM pStream = NULL;
|
|
|
|
BOOL bIsStreamFile = TRUE;
|
|
|
|
static LPSTREAM pStreamStc = NULL;
|
|
|
|
static UINT32 uStreamIdStc = 0;
|
2014-10-24 02:17:53 +04:00
|
|
|
wfClipboard* clipboard = (wfClipboard*) context->custom;
|
2014-10-24 17:55:48 +04:00
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
if (fileContentsRequest->dwFlags == FILECONTENTS_SIZE)
|
|
|
|
fileContentsRequest->cbRequested = sizeof(UINT64);
|
|
|
|
|
2014-10-24 17:55:48 +04:00
|
|
|
pData = (BYTE*) calloc(1, fileContentsRequest->cbRequested);
|
|
|
|
|
|
|
|
if (!pData)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
hRet = OleGetClipboard(&pDataObj);
|
|
|
|
|
2015-06-02 20:52:52 +03:00
|
|
|
if (FAILED(hRet))
|
2014-10-24 17:55:48 +04:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "filecontents: get ole clipboard failed.");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZeroMemory(&vFormatEtc, sizeof(FORMATETC));
|
|
|
|
ZeroMemory(&vStgMedium, sizeof(STGMEDIUM));
|
|
|
|
|
|
|
|
vFormatEtc.cfFormat = clipboard->ID_FILECONTENTS;
|
|
|
|
vFormatEtc.tymed = TYMED_ISTREAM;
|
|
|
|
vFormatEtc.dwAspect = 1;
|
|
|
|
vFormatEtc.lindex = fileContentsRequest->listIndex;
|
|
|
|
vFormatEtc.ptd = NULL;
|
|
|
|
|
|
|
|
if ((uStreamIdStc != fileContentsRequest->streamId) || !pStreamStc)
|
|
|
|
{
|
|
|
|
LPENUMFORMATETC pEnumFormatEtc;
|
|
|
|
ULONG CeltFetched;
|
|
|
|
|
|
|
|
FORMATETC vFormatEtc2;
|
|
|
|
|
|
|
|
if (pStreamStc)
|
|
|
|
{
|
|
|
|
IStream_Release(pStreamStc);
|
|
|
|
pStreamStc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bIsStreamFile = FALSE;
|
|
|
|
|
|
|
|
hRet = IDataObject_EnumFormatEtc(pDataObj, DATADIR_GET, &pEnumFormatEtc);
|
|
|
|
|
|
|
|
if (hRet == S_OK)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
hRet = IEnumFORMATETC_Next(pEnumFormatEtc, 1, &vFormatEtc2, &CeltFetched);
|
|
|
|
|
|
|
|
if (hRet == S_OK)
|
|
|
|
{
|
|
|
|
if (vFormatEtc2.cfFormat == clipboard->ID_FILECONTENTS)
|
|
|
|
{
|
|
|
|
hRet = IDataObject_GetData(pDataObj, &vFormatEtc, &vStgMedium);
|
|
|
|
|
|
|
|
if (hRet == S_OK)
|
|
|
|
{
|
|
|
|
pStreamStc = vStgMedium.pstm;
|
|
|
|
uStreamIdStc = fileContentsRequest->streamId;
|
|
|
|
bIsStreamFile = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (hRet == S_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bIsStreamFile == TRUE)
|
|
|
|
{
|
|
|
|
if (fileContentsRequest->dwFlags == FILECONTENTS_SIZE)
|
|
|
|
{
|
|
|
|
STATSTG vStatStg;
|
|
|
|
|
|
|
|
ZeroMemory(&vStatStg, sizeof(STATSTG));
|
|
|
|
|
|
|
|
hRet = IStream_Stat(pStreamStc, &vStatStg, STATFLAG_NONAME);
|
|
|
|
|
|
|
|
if (hRet == S_OK)
|
|
|
|
{
|
2014-10-24 18:30:54 +04:00
|
|
|
*((UINT32*) &pData[0]) = vStatStg.cbSize.LowPart;
|
|
|
|
*((UINT32*) &pData[4]) = vStatStg.cbSize.HighPart;
|
2014-10-24 17:55:48 +04:00
|
|
|
uSize = fileContentsRequest->cbRequested;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fileContentsRequest->dwFlags == FILECONTENTS_RANGE)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER dlibMove;
|
|
|
|
ULARGE_INTEGER dlibNewPosition;
|
|
|
|
|
|
|
|
dlibMove.HighPart = fileContentsRequest->nPositionHigh;
|
|
|
|
dlibMove.LowPart = fileContentsRequest->nPositionLow;
|
|
|
|
|
|
|
|
hRet = IStream_Seek(pStreamStc, dlibMove, STREAM_SEEK_SET, &dlibNewPosition);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hRet))
|
|
|
|
{
|
|
|
|
hRet = IStream_Read(pStreamStc, pData, fileContentsRequest->cbRequested, (PULONG) &uSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fileContentsRequest->dwFlags == FILECONTENTS_SIZE)
|
|
|
|
{
|
2014-10-24 18:30:54 +04:00
|
|
|
*((UINT32*) &pData[0]) = clipboard->fileDescriptor[fileContentsRequest->listIndex]->nFileSizeLow;
|
|
|
|
*((UINT32*) &pData[4]) = clipboard->fileDescriptor[fileContentsRequest->listIndex]->nFileSizeHigh;
|
2014-10-24 17:55:48 +04:00
|
|
|
uSize = fileContentsRequest->cbRequested;
|
|
|
|
}
|
|
|
|
else if (fileContentsRequest->dwFlags == FILECONTENTS_RANGE)
|
|
|
|
{
|
|
|
|
BOOL bRet;
|
|
|
|
|
|
|
|
bRet = wf_cliprdr_get_file_contents(clipboard->file_names[fileContentsRequest->listIndex], pData,
|
|
|
|
fileContentsRequest->nPositionLow, fileContentsRequest->nPositionHigh,
|
|
|
|
fileContentsRequest->cbRequested, &uSize);
|
|
|
|
|
|
|
|
if (bRet == FALSE)
|
|
|
|
{
|
2014-10-24 18:30:54 +04:00
|
|
|
WLog_ERR(TAG, "get file contents failed.");
|
2014-10-24 17:55:48 +04:00
|
|
|
uSize = 0;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IDataObject_Release(pDataObj);
|
|
|
|
|
|
|
|
if (uSize == 0)
|
|
|
|
{
|
|
|
|
free(pData);
|
|
|
|
pData = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cliprdr_send_response_filecontents(clipboard, fileContentsRequest->streamId, uSize, pData);
|
|
|
|
|
2014-10-24 18:30:54 +04:00
|
|
|
free(pData);
|
|
|
|
|
2014-10-24 02:17:53 +04:00
|
|
|
return 1;
|
2014-10-24 17:55:48 +04:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (pData)
|
|
|
|
{
|
|
|
|
free(pData);
|
|
|
|
pData = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pDataObj)
|
|
|
|
{
|
|
|
|
IDataObject_Release(pDataObj);
|
|
|
|
pDataObj = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
WLog_ERR(TAG, "filecontents: send failed response.");
|
|
|
|
cliprdr_send_response_filecontents(clipboard, fileContentsRequest->streamId, 0, NULL);
|
|
|
|
|
|
|
|
return -1;
|
2014-10-24 02:17:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int wf_cliprdr_server_file_contents_response(CliprdrClientContext* context, CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse)
|
2014-10-23 23:38:19 +04:00
|
|
|
{
|
|
|
|
wfClipboard* clipboard = (wfClipboard*) context->custom;
|
2014-10-24 17:55:48 +04:00
|
|
|
|
|
|
|
clipboard->req_fsize = fileContentsResponse->cbRequested;
|
|
|
|
clipboard->req_fdata = (char*) malloc(fileContentsResponse->cbRequested);
|
|
|
|
CopyMemory(clipboard->req_fdata, fileContentsResponse->requestedData, fileContentsResponse->cbRequested);
|
|
|
|
|
|
|
|
SetEvent(clipboard->req_fevent);
|
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wf_cliprdr_init(wfContext* wfc, CliprdrClientContext* cliprdr)
|
|
|
|
{
|
|
|
|
wfClipboard* clipboard;
|
|
|
|
rdpContext* context = (rdpContext*) wfc;
|
|
|
|
|
|
|
|
wfc->clipboard = (wfClipboard*) calloc(1, sizeof(wfClipboard));
|
|
|
|
|
|
|
|
if (!wfc->clipboard)
|
|
|
|
return;
|
|
|
|
|
|
|
|
clipboard = wfc->clipboard;
|
|
|
|
clipboard->wfc = wfc;
|
2014-10-24 02:17:53 +04:00
|
|
|
clipboard->context = cliprdr;
|
2014-10-24 17:55:48 +04:00
|
|
|
|
2014-10-23 23:38:19 +04:00
|
|
|
clipboard->channels = context->channels;
|
2014-10-24 02:17:53 +04:00
|
|
|
clipboard->sync = FALSE;
|
2014-10-23 23:38:19 +04:00
|
|
|
|
|
|
|
clipboard->map_capacity = 32;
|
|
|
|
clipboard->map_size = 0;
|
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(clipboard->format_mappings = (formatMapping*) calloc(1, sizeof(formatMapping) * clipboard->map_capacity)))
|
|
|
|
goto fail_format_mappings;
|
2014-10-23 23:38:19 +04:00
|
|
|
|
|
|
|
clipboard->file_array_size = 32;
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(clipboard->file_names = (WCHAR**) calloc(1, clipboard->file_array_size * sizeof(WCHAR*))))
|
|
|
|
goto fail_file_names;
|
|
|
|
|
|
|
|
if (!(clipboard->fileDescriptor = (FILEDESCRIPTORW**) calloc(1, clipboard->file_array_size * sizeof(FILEDESCRIPTORW*))))
|
|
|
|
goto fail_file_descriptor;
|
2014-10-23 23:38:19 +04:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(clipboard->response_data_event = CreateEvent(NULL, TRUE, FALSE, _T("response_data_event"))))
|
|
|
|
goto fail_data_event;
|
|
|
|
|
|
|
|
if (!(clipboard->req_fevent = CreateEvent(NULL, TRUE, FALSE, _T("request_filecontents_event"))))
|
|
|
|
goto fail_filecontents_event;
|
2014-10-23 23:38:19 +04:00
|
|
|
|
|
|
|
clipboard->ID_FILEDESCRIPTORW = RegisterClipboardFormatW(CFSTR_FILEDESCRIPTORW);
|
|
|
|
clipboard->ID_FILECONTENTS = RegisterClipboardFormatW(CFSTR_FILECONTENTS);
|
|
|
|
clipboard->ID_PREFERREDDROPEFFECT = RegisterClipboardFormatW(CFSTR_PREFERREDDROPEFFECT);
|
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(clipboard->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) cliprdr_thread_func, clipboard, 0, NULL)))
|
|
|
|
goto fail_clipboard_thread;
|
|
|
|
|
|
|
|
cliprdr->MonitorReady = wf_cliprdr_monitor_ready;
|
|
|
|
cliprdr->ServerCapabilities = wf_cliprdr_server_capabilities;
|
|
|
|
cliprdr->ServerFormatList = wf_cliprdr_server_format_list;
|
|
|
|
cliprdr->ServerFormatListResponse = wf_cliprdr_server_format_list_response;
|
|
|
|
cliprdr->ServerLockClipboardData = wf_cliprdr_server_lock_clipboard_data;
|
|
|
|
cliprdr->ServerUnlockClipboardData = wf_cliprdr_server_unlock_clipboard_data;
|
|
|
|
cliprdr->ServerFormatDataRequest = wf_cliprdr_server_format_data_request;
|
|
|
|
cliprdr->ServerFormatDataResponse = wf_cliprdr_server_format_data_response;
|
|
|
|
cliprdr->ServerFileContentsRequest = wf_cliprdr_server_file_contents_request;
|
|
|
|
cliprdr->ServerFileContentsResponse = wf_cliprdr_server_file_contents_response;
|
|
|
|
cliprdr->custom = (void*) wfc->clipboard;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail_clipboard_thread:
|
|
|
|
CloseHandle(clipboard->req_fevent);
|
|
|
|
clipboard->req_fevent = NULL;
|
|
|
|
fail_filecontents_event:
|
|
|
|
CloseHandle(clipboard->response_data_event);
|
|
|
|
clipboard->response_data_event = NULL;
|
|
|
|
fail_data_event:
|
|
|
|
free(clipboard->fileDescriptor);
|
|
|
|
clipboard->fileDescriptor = NULL;
|
|
|
|
fail_file_descriptor:
|
|
|
|
free(clipboard->file_names);
|
|
|
|
clipboard->file_names = NULL;
|
|
|
|
fail_file_names:
|
|
|
|
free(clipboard->format_mappings);
|
|
|
|
clipboard->format_mappings = NULL;
|
|
|
|
fail_format_mappings:
|
|
|
|
free(wfc->clipboard);
|
|
|
|
wfc->clipboard = NULL;
|
|
|
|
|
|
|
|
return;
|
2014-10-23 23:38:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void wf_cliprdr_uninit(wfContext* wfc, CliprdrClientContext* cliprdr)
|
|
|
|
{
|
|
|
|
wfClipboard* clipboard = wfc->clipboard;
|
|
|
|
|
|
|
|
cliprdr->custom = NULL;
|
|
|
|
|
|
|
|
if (!clipboard)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (clipboard->hwnd)
|
|
|
|
PostMessage(clipboard->hwnd, WM_QUIT, 0, 0);
|
|
|
|
|
|
|
|
if (clipboard->thread)
|
|
|
|
{
|
|
|
|
WaitForSingleObject(clipboard->thread, INFINITE);
|
|
|
|
CloseHandle(clipboard->thread);
|
|
|
|
clipboard->thread = NULL;
|
2012-07-21 01:05:06 +04:00
|
|
|
}
|
2014-10-23 23:38:19 +04:00
|
|
|
|
|
|
|
if (clipboard->response_data_event)
|
|
|
|
{
|
|
|
|
CloseHandle(clipboard->response_data_event);
|
|
|
|
clipboard->response_data_event = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear_file_array(clipboard);
|
|
|
|
clear_format_map(clipboard);
|
|
|
|
|
2015-05-11 10:07:39 +03:00
|
|
|
free(clipboard->file_names);
|
|
|
|
free(clipboard->fileDescriptor);
|
|
|
|
free(clipboard->format_mappings);
|
2014-10-23 23:38:19 +04:00
|
|
|
|
|
|
|
free(clipboard);
|
2012-07-21 01:05:06 +04:00
|
|
|
}
|