From ce7302a999ad04a1f1b647c2aec3e7927368d21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Wed, 22 Oct 2014 22:32:55 -0400 Subject: [PATCH] wfreerdp: cleanup clipboard --- client/Windows/wf_cliprdr.c | 282 +++++++++++----------- client/Windows/wf_cliprdr.h | 33 +-- client/Windows/wf_cliprdr_DataObject.c | 181 +++++++------- client/Windows/wf_cliprdr_EnumFORMATETC.c | 34 +-- client/Windows/wf_cliprdr_Stream.c | 116 ++++----- libfreerdp/crypto/test/CMakeLists.txt | 2 + winpr/libwinpr/clipboard/synthetic.c | 5 +- 7 files changed, 343 insertions(+), 310 deletions(-) diff --git a/client/Windows/wf_cliprdr.c b/client/Windows/wf_cliprdr.c index de035e425..91de25e4e 100644 --- a/client/Windows/wf_cliprdr.c +++ b/client/Windows/wf_cliprdr.c @@ -26,11 +26,8 @@ #include #include -#include -#include #include #include -#include #include #include @@ -60,17 +57,18 @@ extern BOOL WINAPI RemoveClipboardFormatListener(_In_ HWND hwnd); *(_p + 2) = ((_v) >> 16) & 0xFF; \ *(_p + 3) = ((_v) >> 24) & 0xFF; } while (0) -BOOL wf_create_file_obj(cliprdrContext *cliprdr, IDataObject **ppDataObject); -void wf_destroy_file_obj(IDataObject *instance); +BOOL wf_create_file_obj(cliprdrContext* cliprdr, IDataObject** ppDataObject); +void wf_destroy_file_obj(IDataObject* instance); -static UINT32 get_local_format_id_by_name(cliprdrContext *cliprdr, void *format_name) +static UINT32 get_local_format_id_by_name(cliprdrContext* cliprdr, void *format_name) { - formatMapping *map; int i; + formatMapping* map; for (i = 0; i < cliprdr->map_size; i++) { map = &cliprdr->format_mappings[i]; + if ((cliprdr->capabilities & CB_USE_LONG_FORMAT_NAMES) != 0) { if (map->name) @@ -84,19 +82,20 @@ static UINT32 get_local_format_id_by_name(cliprdrContext *cliprdr, void *format_ return 0; } -static INLINE BOOL file_transferring(cliprdrContext *cliprdr) +static INLINE BOOL file_transferring(cliprdrContext* cliprdr) { return !!get_local_format_id_by_name(cliprdr, L"FileGroupDescriptorW"); } -static UINT32 get_remote_format_id(cliprdrContext *cliprdr, UINT32 local_format) +static UINT32 get_remote_format_id(cliprdrContext* cliprdr, UINT32 local_format) { - formatMapping *map; int i; + formatMapping* map; for (i = 0; i < cliprdr->map_size; i++) { map = &cliprdr->format_mappings[i]; + if (map->local_format_id == local_format) { return map->remote_format_id; @@ -106,7 +105,7 @@ static UINT32 get_remote_format_id(cliprdrContext *cliprdr, UINT32 local_format) return local_format; } -static void map_ensure_capacity(cliprdrContext *cliprdr) +static void map_ensure_capacity(cliprdrContext* cliprdr) { if (cliprdr->map_size >= cliprdr->map_capacity) { @@ -116,10 +115,10 @@ static void map_ensure_capacity(cliprdrContext *cliprdr) } } -static void clear_format_map(cliprdrContext *cliprdr) +static void clear_format_map(cliprdrContext* cliprdr) { - formatMapping *map; int i; + formatMapping* map; if (cliprdr->format_mappings) { @@ -137,7 +136,7 @@ static void clear_format_map(cliprdrContext *cliprdr) } } - cliprdr->map_size= 0; + cliprdr->map_size = 0; } /* 2.2.2.3 Client Temporary Directory PDU (CLIPRDR_TEMP_DIRECTORY) @@ -147,11 +146,11 @@ static void clear_format_map(cliprdrContext *cliprdr) by the server to be useful. Section 3.1.1.3 specifies how direct file access impacts file copy and paste. */ -int cliprdr_send_tempdir(cliprdrContext *cliprdr) +int cliprdr_send_tempdir(cliprdrContext* cliprdr) { - RDP_CB_TEMPDIR_EVENT *cliprdr_event; + RDP_CB_TEMPDIR_EVENT* cliprdr_event; - cliprdr_event = (RDP_CB_TEMPDIR_EVENT *)freerdp_event_new(CliprdrChannel_Class, + cliprdr_event = (RDP_CB_TEMPDIR_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_TemporaryDirectory, NULL, NULL); if (!cliprdr_event) @@ -160,21 +159,21 @@ int cliprdr_send_tempdir(cliprdrContext *cliprdr) /* Sending the TEMP path would only be valid iff the path is accessible from the server. This should perhaps to change to a command line parameter value */ - GetEnvironmentVariableW(L"TEMP", (LPWSTR)cliprdr_event->dirname, 260); + GetEnvironmentVariableW(L"TEMP", (LPWSTR) cliprdr_event->dirname, 260); - return freerdp_channels_send_event(cliprdr->channels, (wMessage *)cliprdr_event); + return freerdp_channels_send_event(cliprdr->channels, (wMessage*) cliprdr_event); } -static void cliprdr_send_format_list(cliprdrContext *cliprdr) +static void cliprdr_send_format_list(cliprdrContext* cliprdr) { - RDP_CB_FORMAT_LIST_EVENT *cliprdr_event; - BYTE *format_data; + BYTE* format_data; int format = 0; int data_size; int format_count; int len = 0; int namelen; int stream_file_transferring = FALSE; + RDP_CB_FORMAT_LIST_EVENT* cliprdr_event; if (!OpenClipboard(cliprdr->hwndClipboard)) { @@ -211,11 +210,13 @@ static void cliprdr_send_format_list(cliprdrContext *cliprdr) { if (format >= CF_MAX) { - static WCHAR wName[MAX_PATH] = {0}; int wLen; + static WCHAR wName[MAX_PATH] = { 0 }; + + ZeroMemory(wName, MAX_PATH * 2); - ZeroMemory(wName, MAX_PATH*2); wLen = GetClipboardFormatNameW(format, wName, MAX_PATH); + if (wLen < 16) { memcpy(format_data + len, wName, wLen * sizeof(WCHAR)); @@ -256,12 +257,12 @@ static void cliprdr_send_format_list(cliprdrContext *cliprdr) freerdp_channels_send_event(cliprdr->channels, (wMessage*) cliprdr_event); } -int cliprdr_send_data_request(cliprdrContext *cliprdr, UINT32 format) +int cliprdr_send_data_request(cliprdrContext* cliprdr, UINT32 format) { - RDP_CB_DATA_REQUEST_EVENT *cliprdr_event; int ret; + RDP_CB_DATA_REQUEST_EVENT* cliprdr_event; - cliprdr_event = (RDP_CB_DATA_REQUEST_EVENT *)freerdp_event_new(CliprdrChannel_Class, + cliprdr_event = (RDP_CB_DATA_REQUEST_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_DataRequest, NULL, NULL); if (!cliprdr_event) @@ -269,7 +270,7 @@ int cliprdr_send_data_request(cliprdrContext *cliprdr, UINT32 format) cliprdr_event->format = get_remote_format_id(cliprdr, format); - ret = freerdp_channels_send_event(cliprdr->channels, (wMessage *)cliprdr_event); + ret = freerdp_channels_send_event(cliprdr->channels, (wMessage*) cliprdr_event); if (ret != 0) return -1; @@ -280,13 +281,14 @@ int cliprdr_send_data_request(cliprdrContext *cliprdr, UINT32 format) return 0; } -int cliprdr_send_lock(cliprdrContext *cliprdr) +int cliprdr_send_lock(cliprdrContext* cliprdr) { - RDP_CB_LOCK_CLIPDATA_EVENT *cliprdr_event; int ret; + RDP_CB_LOCK_CLIPDATA_EVENT* cliprdr_event; - if ((cliprdr->capabilities & CB_CAN_LOCK_CLIPDATA) == 1) { - cliprdr_event = (RDP_CB_LOCK_CLIPDATA_EVENT *)freerdp_event_new(CliprdrChannel_Class, + if ((cliprdr->capabilities & CB_CAN_LOCK_CLIPDATA) == 1) + { + cliprdr_event = (RDP_CB_LOCK_CLIPDATA_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_LockClipdata, NULL, NULL); if (!cliprdr_event) @@ -294,7 +296,7 @@ int cliprdr_send_lock(cliprdrContext *cliprdr) cliprdr_event->clipDataId = 0; - ret = freerdp_channels_send_event(cliprdr->channels, (wMessage *)cliprdr_event); + ret = freerdp_channels_send_event(cliprdr->channels, (wMessage*) cliprdr_event); if (ret != 0) return -1; @@ -303,13 +305,14 @@ int cliprdr_send_lock(cliprdrContext *cliprdr) return 0; } -int cliprdr_send_unlock(cliprdrContext *cliprdr) +int cliprdr_send_unlock(cliprdrContext* cliprdr) { - RDP_CB_UNLOCK_CLIPDATA_EVENT *cliprdr_event; int ret; + RDP_CB_UNLOCK_CLIPDATA_EVENT* cliprdr_event; - if ((cliprdr->capabilities & CB_CAN_LOCK_CLIPDATA) == 1) { - cliprdr_event = (RDP_CB_UNLOCK_CLIPDATA_EVENT *)freerdp_event_new(CliprdrChannel_Class, + if ((cliprdr->capabilities & CB_CAN_LOCK_CLIPDATA) == 1) + { + cliprdr_event = (RDP_CB_UNLOCK_CLIPDATA_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_UnLockClipdata, NULL, NULL); if (!cliprdr_event) @@ -317,7 +320,7 @@ int cliprdr_send_unlock(cliprdrContext *cliprdr) cliprdr_event->clipDataId = 0; - ret = freerdp_channels_send_event(cliprdr->channels, (wMessage *)cliprdr_event); + ret = freerdp_channels_send_event(cliprdr->channels, (wMessage*) cliprdr_event); if (ret != 0) return -1; @@ -326,27 +329,27 @@ int cliprdr_send_unlock(cliprdrContext *cliprdr) return 0; } -int cliprdr_send_request_filecontents(cliprdrContext *cliprdr, void *streamid, +int cliprdr_send_request_filecontents(cliprdrContext* cliprdr, void* streamid, int index, int flag, DWORD positionhigh, DWORD positionlow, ULONG nreq) { - RDP_CB_FILECONTENTS_REQUEST_EVENT *cliprdr_event; int ret; + RDP_CB_FILECONTENTS_REQUEST_EVENT* cliprdr_event; - cliprdr_event = (RDP_CB_FILECONTENTS_REQUEST_EVENT *)freerdp_event_new(CliprdrChannel_Class, + cliprdr_event = (RDP_CB_FILECONTENTS_REQUEST_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_FilecontentsRequest, NULL, NULL); if (!cliprdr_event) return -1; - cliprdr_event->streamId = (UINT32)streamid; - cliprdr_event->lindex = index; - cliprdr_event->dwFlags = flag; - cliprdr_event->nPositionLow = positionlow; + cliprdr_event->streamId = (UINT32)streamid; + cliprdr_event->lindex = index; + cliprdr_event->dwFlags = flag; + cliprdr_event->nPositionLow = positionlow; cliprdr_event->nPositionHigh = positionhigh; - cliprdr_event->cbRequested = nreq; - cliprdr_event->clipDataId = 0; + cliprdr_event->cbRequested = nreq; + cliprdr_event->clipDataId = 0; - ret = freerdp_channels_send_event(cliprdr->channels, (wMessage *)cliprdr_event); + ret = freerdp_channels_send_event(cliprdr->channels, (wMessage*) cliprdr_event); if (ret != 0) return -1; @@ -357,12 +360,12 @@ int cliprdr_send_request_filecontents(cliprdrContext *cliprdr, void *streamid, return 0; } -int cliprdr_send_response_filecontents(cliprdrContext *cliprdr, UINT32 streamid, UINT32 size, BYTE *data) +int cliprdr_send_response_filecontents(cliprdrContext* cliprdr, UINT32 streamid, UINT32 size, BYTE* data) { - RDP_CB_FILECONTENTS_RESPONSE_EVENT *cliprdr_event; int ret; + RDP_CB_FILECONTENTS_RESPONSE_EVENT* cliprdr_event; - cliprdr_event = (RDP_CB_FILECONTENTS_RESPONSE_EVENT *)freerdp_event_new(CliprdrChannel_Class, + cliprdr_event = (RDP_CB_FILECONTENTS_RESPONSE_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_FilecontentsResponse, NULL, NULL); if (!cliprdr_event) @@ -382,7 +385,7 @@ int cliprdr_send_response_filecontents(cliprdrContext *cliprdr, UINT32 streamid, static LRESULT CALLBACK cliprdr_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { - static cliprdrContext *cliprdr = NULL; + static cliprdrContext* cliprdr = NULL; switch (Msg) { @@ -471,7 +474,7 @@ static LRESULT CALLBACK cliprdr_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM return 0; } -static int create_cliprdr_window(cliprdrContext *cliprdr) +static int create_cliprdr_window(cliprdrContext* cliprdr) { WNDCLASSEX wnd_cls; @@ -504,7 +507,7 @@ static int create_cliprdr_window(cliprdrContext *cliprdr) return 0; } -static void *cliprdr_thread_func(void *arg) +static void* cliprdr_thread_func(void* arg) { int ret; MSG msg; @@ -538,7 +541,7 @@ static void *cliprdr_thread_func(void *arg) return NULL; } -static void clear_file_array(cliprdrContext *cliprdr) +static void clear_file_array(cliprdrContext* cliprdr) { int i; @@ -573,7 +576,7 @@ static void clear_file_array(cliprdrContext *cliprdr) void wf_cliprdr_init(wfContext* wfc, rdpChannels* channels) { - cliprdrContext *cliprdr; + cliprdrContext* cliprdr; if (!wfc->instance->settings->RedirectClipboard) { @@ -582,8 +585,8 @@ void wf_cliprdr_init(wfContext* wfc, rdpChannels* channels) return; } - wfc->cliprdr_context = (cliprdrContext *) calloc(1, sizeof(cliprdrContext)); - cliprdr = (cliprdrContext *) wfc->cliprdr_context; + wfc->cliprdr_context = (cliprdrContext*) calloc(1, sizeof(cliprdrContext)); + cliprdr = (cliprdrContext*) wfc->cliprdr_context; assert(cliprdr != NULL); cliprdr->channels = channels; @@ -592,12 +595,12 @@ void wf_cliprdr_init(wfContext* wfc, rdpChannels* channels) cliprdr->map_capacity = 32; cliprdr->map_size = 0; - cliprdr->format_mappings = (formatMapping *)calloc(1, sizeof(formatMapping) * cliprdr->map_capacity); + cliprdr->format_mappings = (formatMapping*) calloc(1, sizeof(formatMapping) * cliprdr->map_capacity); assert(cliprdr->format_mappings != NULL); cliprdr->file_array_size = 32; - cliprdr->file_names = (wchar_t **)calloc(1, cliprdr->file_array_size * sizeof(wchar_t *)); - cliprdr->fileDescriptor = (FILEDESCRIPTORW **)calloc(1, cliprdr->file_array_size * sizeof(FILEDESCRIPTORW *)); + cliprdr->file_names = (WCHAR**) calloc(1, cliprdr->file_array_size * sizeof(WCHAR*)); + cliprdr->fileDescriptor = (FILEDESCRIPTORW**) calloc(1, cliprdr->file_array_size * sizeof(FILEDESCRIPTORW*)); cliprdr->response_data_event = CreateEvent(NULL, TRUE, FALSE, L"response_data_event"); assert(cliprdr->response_data_event != NULL); @@ -613,7 +616,7 @@ void wf_cliprdr_init(wfContext* wfc, rdpChannels* channels) void wf_cliprdr_uninit(wfContext* wfc) { - cliprdrContext *cliprdr = (cliprdrContext *) wfc->cliprdr_context; + cliprdrContext* cliprdr = (cliprdrContext*) wfc->cliprdr_context; if (!cliprdr) return; @@ -643,16 +646,16 @@ void wf_cliprdr_uninit(wfContext* wfc) free(cliprdr); } -static void wf_cliprdr_process_cb_clip_caps_event(wfContext *wfc, RDP_CB_CLIP_CAPS *caps_event) +static void wf_cliprdr_process_cb_clip_caps_event(wfContext* wfc, RDP_CB_CLIP_CAPS* caps_event) { - cliprdrContext *cliprdr = (cliprdrContext *)wfc->cliprdr_context; + cliprdrContext* cliprdr = (cliprdrContext*) wfc->cliprdr_context; cliprdr->capabilities = caps_event->capabilities; } -static void wf_cliprdr_process_cb_monitor_ready_event(wfContext *wfc, RDP_CB_MONITOR_READY_EVENT *ready_event) +static void wf_cliprdr_process_cb_monitor_ready_event(wfContext* wfc, RDP_CB_MONITOR_READY_EVENT* ready_event) { - cliprdrContext *cliprdr = (cliprdrContext *)wfc->cliprdr_context; + cliprdrContext* cliprdr = (cliprdrContext*) wfc->cliprdr_context; #if 0 /*Disabled since the current function only sends the temp directory which is not guaranteed to be accessible to the server @@ -664,29 +667,34 @@ static void wf_cliprdr_process_cb_monitor_ready_event(wfContext *wfc, RDP_CB_MON cliprdr_send_format_list(wfc->cliprdr_context); } -static BOOL wf_cliprdr_get_file_contents(wchar_t *file_name, BYTE *buffer, int positionLow, int positionHigh, int nRequested, unsigned int *puSize) +static BOOL wf_cliprdr_get_file_contents(WCHAR* file_name, BYTE* buffer, + int positionLow, int positionHigh, int nRequested, unsigned int* puSize) { HANDLE hFile; DWORD nGet; - if (file_name == NULL || buffer == NULL || puSize == NULL) + if (!file_name || !buffer || !puSize) { WLog_ERR(TAG, "get file contents Invalid Arguments."); return FALSE; } - hFile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL); + + hFile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (hFile == INVALID_HANDLE_VALUE) { return FALSE; } - SetFilePointer(hFile, positionLow, (PLONG)&positionHigh, FILE_BEGIN); + SetFilePointer(hFile, positionLow, (PLONG) &positionHigh, FILE_BEGIN); if (!ReadFile(hFile, buffer, nRequested, &nGet, NULL)) { DWORD err = GetLastError(); DEBUG_CLIPRDR("ReadFile failed with 0x%x.", err); } + CloseHandle(hFile); *puSize = nGet; @@ -695,18 +703,16 @@ static BOOL wf_cliprdr_get_file_contents(wchar_t *file_name, BYTE *buffer, int p } /* path_name has a '\' at the end. e.g. c:\newfolder\, file_name is c:\newfolder\new.txt */ -static FILEDESCRIPTORW *wf_cliprdr_get_file_descriptor(WCHAR* file_name, int pathLen) +static FILEDESCRIPTORW* wf_cliprdr_get_file_descriptor(WCHAR* file_name, int pathLen) { - FILEDESCRIPTORW *fd; HANDLE hFile; + FILEDESCRIPTORW* fd; - fd = (FILEDESCRIPTORW*) malloc(sizeof(FILEDESCRIPTORW)); + fd = (FILEDESCRIPTORW*) calloc(1, sizeof(FILEDESCRIPTORW)); if (!fd) return NULL; - ZeroMemory(fd, sizeof(FILEDESCRIPTORW)); - hFile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL); @@ -733,17 +739,17 @@ static FILEDESCRIPTORW *wf_cliprdr_get_file_descriptor(WCHAR* file_name, int pat return fd; } -static void wf_cliprdr_array_ensure_capacity(cliprdrContext *cliprdr) +static void wf_cliprdr_array_ensure_capacity(cliprdrContext* cliprdr) { if (cliprdr->nFiles == cliprdr->file_array_size) { cliprdr->file_array_size *= 2; - cliprdr->fileDescriptor = (FILEDESCRIPTORW **)realloc(cliprdr->fileDescriptor, cliprdr->file_array_size * sizeof(FILEDESCRIPTORW *)); - cliprdr->file_names = (wchar_t **)realloc(cliprdr->file_names, cliprdr->file_array_size * sizeof(wchar_t *)); + cliprdr->fileDescriptor = (FILEDESCRIPTORW**) realloc(cliprdr->fileDescriptor, cliprdr->file_array_size * sizeof(FILEDESCRIPTORW*)); + cliprdr->file_names = (WCHAR**) realloc(cliprdr->file_names, cliprdr->file_array_size * sizeof(WCHAR*)); } } -static void wf_cliprdr_add_to_file_arrays(cliprdrContext *cliprdr, WCHAR *full_file_name, int pathLen) +static void wf_cliprdr_add_to_file_arrays(cliprdrContext* cliprdr, WCHAR *full_file_name, int pathLen) { /* add to name array */ cliprdr->file_names[cliprdr->nFiles] = (LPWSTR) malloc(MAX_PATH); @@ -757,24 +763,24 @@ static void wf_cliprdr_add_to_file_arrays(cliprdrContext *cliprdr, WCHAR *full_f wf_cliprdr_array_ensure_capacity(cliprdr); } -static void wf_cliprdr_traverse_directory(cliprdrContext *cliprdr, wchar_t *Dir, int pathLen) +static void wf_cliprdr_traverse_directory(cliprdrContext* cliprdr, WCHAR* Dir, int pathLen) { - WIN32_FIND_DATA FindFileData; HANDLE hFind; - wchar_t DirSpec[MAX_PATH]; + WCHAR DirSpec[MAX_PATH]; + WIN32_FIND_DATA FindFileData; StringCchCopy(DirSpec,MAX_PATH,Dir); StringCchCat(DirSpec,MAX_PATH,TEXT("\\*")); - hFind = FindFirstFile(DirSpec,&FindFileData); + hFind = FindFirstFile(DirSpec, &FindFileData); - if(hFind == INVALID_HANDLE_VALUE) + if (hFind == INVALID_HANDLE_VALUE) { DEBUG_CLIPRDR("FindFirstFile failed with 0x%x.", GetLastError()); return; } - while(FindNextFile(hFind, &FindFileData)) + while (FindNextFile(hFind, &FindFileData)) { if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 && wcscmp(FindFileData.cFileName,L".") == 0 @@ -783,10 +789,9 @@ static void wf_cliprdr_traverse_directory(cliprdrContext *cliprdr, wchar_t *Dir, continue; } - if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) !=0 ) { - wchar_t DirAdd[MAX_PATH]; + WCHAR DirAdd[MAX_PATH]; StringCchCopy(DirAdd,MAX_PATH,Dir); StringCchCat(DirAdd,MAX_PATH,TEXT("\\")); @@ -833,19 +838,20 @@ static void wf_cliprdr_process_cb_data_request_event(wfContext* wfc, RDP_CB_DATA } else if (local_format == RegisterClipboardFormatW(L"FileGroupDescriptorW")) { + int len; + int i; + WCHAR* wFileName; + unsigned int uSize; HRESULT result; LPDATAOBJECT dataObj; FORMATETC format_etc; STGMEDIUM stg_medium; - DROPFILES *dropFiles; - - int len; - int i; - wchar_t *wFileName; - unsigned int uSize; + DROPFILES* dropFiles; DEBUG_CLIPRDR("file descriptors request."); + result = OleGetClipboard(&dataObj); + if (!SUCCEEDED(result)) { DEBUG_CLIPRDR("OleGetClipboard failed."); @@ -866,7 +872,7 @@ static void wf_cliprdr_process_cb_data_request_event(wfContext* wfc, RDP_CB_DATA if (SUCCEEDED(result)) { DEBUG_CLIPRDR("Got FileGroupDescriptorW."); - globlemem = (char *)GlobalLock(stg_medium.hGlobal); + globlemem = (char*) GlobalLock(stg_medium.hGlobal); uSize = GlobalSize(stg_medium.hGlobal); size = uSize; buff = (char*) malloc(uSize); @@ -914,13 +920,13 @@ static void wf_cliprdr_process_cb_data_request_event(wfContext* wfc, RDP_CB_DATA if (dropFiles->fWide) { - wchar_t *p; + WCHAR* p; int str_len; int offset; int pathLen; /* dropFiles contains file names */ - for (wFileName = (wchar_t *)((char *)dropFiles + dropFiles->pFiles); (len = wcslen(wFileName)) > 0; wFileName += len + 1) + for (wFileName = (WCHAR*)((char *)dropFiles + dropFiles->pFiles); (len = wcslen(wFileName)) > 0; wFileName += len + 1) { /* get path name */ str_len = wcslen(wFileName); @@ -950,21 +956,21 @@ static void wf_cliprdr_process_cb_data_request_event(wfContext* wfc, RDP_CB_DATA int cchWideChar; cchWideChar = MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, NULL, 0); - cliprdr->file_names[cliprdr->nFiles] = (LPWSTR)malloc(cchWideChar); + cliprdr->file_names[cliprdr->nFiles] = (LPWSTR) malloc(cchWideChar); MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, cliprdr->file_names[cliprdr->nFiles], cchWideChar); if (cliprdr->nFiles == cliprdr->file_array_size) { cliprdr->file_array_size *= 2; - cliprdr->fileDescriptor = (FILEDESCRIPTORW **)realloc(cliprdr->fileDescriptor, cliprdr->file_array_size * sizeof(FILEDESCRIPTORW *)); - cliprdr->file_names = (wchar_t **)realloc(cliprdr->file_names, cliprdr->file_array_size * sizeof(wchar_t *)); + cliprdr->fileDescriptor = (FILEDESCRIPTORW**) realloc(cliprdr->fileDescriptor, cliprdr->file_array_size * sizeof(FILEDESCRIPTORW*)); + cliprdr->file_names = (WCHAR**) realloc(cliprdr->file_names, cliprdr->file_array_size * sizeof(WCHAR*)); } } } exit: size = 4 + cliprdr->nFiles * sizeof(FILEDESCRIPTORW); - buff = (char *)malloc(size); + buff = (char*) malloc(size); Write_UINT32(buff, cliprdr->nFiles); @@ -1010,7 +1016,7 @@ exit: response_event = (RDP_CB_DATA_RESPONSE_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_DataResponse, NULL, NULL); - response_event->data = (BYTE *)buff; + response_event->data = (BYTE*) buff; response_event->size = size; freerdp_channels_send_event(cliprdr->channels, (wMessage*) response_event); @@ -1018,9 +1024,9 @@ exit: /* Note: don't free buffer here. */ } -static void wf_cliprdr_process_cb_format_list_event(wfContext *wfc, RDP_CB_FORMAT_LIST_EVENT *event) +static void wf_cliprdr_process_cb_format_list_event(wfContext* wfc, RDP_CB_FORMAT_LIST_EVENT* event) { - cliprdrContext *cliprdr = (cliprdrContext *)wfc->cliprdr_context; + cliprdrContext* cliprdr = (cliprdrContext *)wfc->cliprdr_context; UINT32 left_size = event->raw_format_data_size; int i = 0; BYTE *p; @@ -1145,21 +1151,25 @@ static void wf_cliprdr_process_cb_format_list_event(wfContext *wfc, RDP_CB_FORMA return; if (EmptyClipboard()) + { for (i = 0; i < cliprdr->map_size; i++) + { SetClipboardData(cliprdr->format_mappings[i].local_format_id, NULL); + } + } CloseClipboard(); } } -static void wf_cliprdr_process_cb_data_response_event(wfContext *wfc, RDP_CB_DATA_RESPONSE_EVENT *event) +static void wf_cliprdr_process_cb_data_response_event(wfContext* wfc, RDP_CB_DATA_RESPONSE_EVENT* event) { - cliprdrContext *cliprdr = (cliprdrContext *)wfc->cliprdr_context; + char* buff; HANDLE hMem; - char *buff; + cliprdrContext* cliprdr = (cliprdrContext*) wfc->cliprdr_context; hMem = GlobalAlloc(GMEM_FIXED, event->size); - buff = (char *) GlobalLock(hMem); + buff = (char*) GlobalLock(hMem); memcpy(buff, event->data, event->size); GlobalUnlock(hMem); @@ -1167,25 +1177,27 @@ static void wf_cliprdr_process_cb_data_response_event(wfContext *wfc, RDP_CB_DAT SetEvent(cliprdr->response_data_event); } -static void wf_cliprdr_process_cb_filecontents_request_event(wfContext *wfc, RDP_CB_FILECONTENTS_REQUEST_EVENT *event) +static void wf_cliprdr_process_cb_filecontents_request_event(wfContext* wfc, RDP_CB_FILECONTENTS_REQUEST_EVENT* event) { - cliprdrContext *cliprdr = (cliprdrContext *)wfc->cliprdr_context; - 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; + cliprdrContext* cliprdr = (cliprdrContext*) wfc->cliprdr_context; + 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; - pData = (BYTE *)calloc(1, event->cbRequested); + pData = (BYTE*) calloc(1, event->cbRequested); + if (!pData) goto error; hRet = OleGetClipboard(&pDataObj); + if (!SUCCEEDED(hRet)) { WLog_ERR(TAG, "filecontents: get ole clipboard failed."); @@ -1322,65 +1334,65 @@ error: return; } -static void wf_cliprdr_process_cb_filecontents_response_event(wfContext *wfc, RDP_CB_FILECONTENTS_RESPONSE_EVENT *event) +static void wf_cliprdr_process_cb_filecontents_response_event(wfContext* wfc, RDP_CB_FILECONTENTS_RESPONSE_EVENT* event) { - cliprdrContext *cliprdr = (cliprdrContext *)wfc->cliprdr_context; + cliprdrContext* cliprdr = (cliprdrContext*) wfc->cliprdr_context; cliprdr->req_fsize = event->size; - cliprdr->req_fdata = (char *)malloc(event->size); + cliprdr->req_fdata = (char*) malloc(event->size); memcpy(cliprdr->req_fdata, event->data, event->size); SetEvent(cliprdr->req_fevent); } -static void wf_cliprdr_process_cb_lock_clipdata_event(wfContext *wfc, RDP_CB_LOCK_CLIPDATA_EVENT *event) +static void wf_cliprdr_process_cb_lock_clipdata_event(wfContext* wfc, RDP_CB_LOCK_CLIPDATA_EVENT* event) { } -static void wf_cliprdr_process_cb_unlock_clipdata_event(wfContext *wfc, RDP_CB_UNLOCK_CLIPDATA_EVENT *event) +static void wf_cliprdr_process_cb_unlock_clipdata_event(wfContext* wfc, RDP_CB_UNLOCK_CLIPDATA_EVENT* event) { } -void wf_process_cliprdr_event(wfContext *wfc, wMessage *event) +void wf_process_cliprdr_event(wfContext* wfc, wMessage* event) { switch (GetMessageType(event->id)) { case CliprdrChannel_ClipCaps: - wf_cliprdr_process_cb_clip_caps_event(wfc, (RDP_CB_CLIP_CAPS *)event); + wf_cliprdr_process_cb_clip_caps_event(wfc, (RDP_CB_CLIP_CAPS*) event); break; case CliprdrChannel_MonitorReady: - wf_cliprdr_process_cb_monitor_ready_event(wfc, (RDP_CB_MONITOR_READY_EVENT *)event); + wf_cliprdr_process_cb_monitor_ready_event(wfc, (RDP_CB_MONITOR_READY_EVENT*) event); break; case CliprdrChannel_FormatList: - wf_cliprdr_process_cb_format_list_event(wfc, (RDP_CB_FORMAT_LIST_EVENT *) event); + wf_cliprdr_process_cb_format_list_event(wfc, (RDP_CB_FORMAT_LIST_EVENT*) event); break; case CliprdrChannel_DataRequest: - wf_cliprdr_process_cb_data_request_event(wfc, (RDP_CB_DATA_REQUEST_EVENT *) event); + wf_cliprdr_process_cb_data_request_event(wfc, (RDP_CB_DATA_REQUEST_EVENT*) event); break; case CliprdrChannel_DataResponse: - wf_cliprdr_process_cb_data_response_event(wfc, (RDP_CB_DATA_RESPONSE_EVENT *) event); + wf_cliprdr_process_cb_data_response_event(wfc, (RDP_CB_DATA_RESPONSE_EVENT*) event); break; case CliprdrChannel_FilecontentsRequest: - wf_cliprdr_process_cb_filecontents_request_event(wfc, (RDP_CB_FILECONTENTS_REQUEST_EVENT *) event); + wf_cliprdr_process_cb_filecontents_request_event(wfc, (RDP_CB_FILECONTENTS_REQUEST_EVENT*) event); break; case CliprdrChannel_FilecontentsResponse: - wf_cliprdr_process_cb_filecontents_response_event(wfc, (RDP_CB_FILECONTENTS_RESPONSE_EVENT *) event); + wf_cliprdr_process_cb_filecontents_response_event(wfc, (RDP_CB_FILECONTENTS_RESPONSE_EVENT*) event); break; case CliprdrChannel_LockClipdata: - wf_cliprdr_process_cb_lock_clipdata_event(wfc, (RDP_CB_LOCK_CLIPDATA_EVENT *) event); + wf_cliprdr_process_cb_lock_clipdata_event(wfc, (RDP_CB_LOCK_CLIPDATA_EVENT*) event); break; case CliprdrChannel_UnLockClipdata: - wf_cliprdr_process_cb_unlock_clipdata_event(wfc, (RDP_CB_UNLOCK_CLIPDATA_EVENT *) event); + wf_cliprdr_process_cb_unlock_clipdata_event(wfc, (RDP_CB_UNLOCK_CLIPDATA_EVENT*) event); break; default: diff --git a/client/Windows/wf_cliprdr.h b/client/Windows/wf_cliprdr.h index aaa5b8ce7..e464f1a18 100644 --- a/client/Windows/wf_cliprdr.h +++ b/client/Windows/wf_cliprdr.h @@ -35,22 +35,24 @@ #define DEBUG_CLIPRDR(fmt, ...) do { } while (0) #endif -typedef struct format_mapping formatMapping; -struct format_mapping { +struct format_mapping +{ UINT32 remote_format_id; UINT32 local_format_id; - void *name; /* Unicode or ASCII characters with NULL terminate */ + void *name; /* Unicode or ASCII characters with NULL terminator */ }; +typedef struct format_mapping formatMapping; typedef struct cliprdr_context cliprdrContext; -struct cliprdr_context { - rdpChannels *channels; +struct cliprdr_context +{ + rdpChannels* channels; UINT32 capabilities; - formatMapping *format_mappings; - int map_capacity; int map_size; + int map_capacity; + formatMapping* format_mappings; UINT32 request_format; BOOL channel_initialized; @@ -68,13 +70,13 @@ struct cliprdr_context { LPDATAOBJECT data_obj; ULONG req_fsize; - char *req_fdata; + char* req_fdata; HANDLE req_fevent; int nFiles; int file_array_size; - wchar_t **file_names; - FILEDESCRIPTORW **fileDescriptor; + WCHAR** file_names; + FILEDESCRIPTORW** fileDescriptor; }; void wf_cliprdr_init(wfContext* wfc, rdpChannels* channels); @@ -86,11 +88,10 @@ BOOL wf_cliprdr_process_selection_clear(wfContext* wfc, HWND hWnd, UINT Msg, WPA BOOL wf_cliprdr_process_property_notify(wfContext* wfc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); void wf_cliprdr_check_owner(wfContext* wfc); -int cliprdr_send_data_request(cliprdrContext *cliprdr, UINT32 format); -int cliprdr_send_lock(cliprdrContext *cliprdr); -int cliprdr_send_unlock(cliprdrContext *cliprdr); -int cliprdr_send_request_filecontents(cliprdrContext *cliprdr, void *streamid, - int index, int flag, DWORD positionhigh, - DWORD positionlow, ULONG request); +int cliprdr_send_data_request(cliprdrContext* cliprdr, UINT32 format); +int cliprdr_send_lock(cliprdrContext* cliprdr); +int cliprdr_send_unlock(cliprdrContext* cliprdr); +int cliprdr_send_request_filecontents(cliprdrContext* cliprdr, void* streamid, + int index, int flag, DWORD positionhigh, DWORD positionlow, ULONG request); #endif /* __WF_CLIPRDR_H */ diff --git a/client/Windows/wf_cliprdr_DataObject.c b/client/Windows/wf_cliprdr_DataObject.c index 7dafbb28e..f79ef9c10 100644 --- a/client/Windows/wf_cliprdr_DataObject.c +++ b/client/Windows/wf_cliprdr_DataObject.c @@ -22,12 +22,13 @@ #include "wf_cliprdr_DataObject.h" #include "wf_cliprdr_EnumFORMATETC.h" -static int cliprdr_lookup_format(CliprdrDataObject *instance, FORMATETC *pFormatEtc) +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) && + if ((pFormatEtc->tymed & instance->m_pFormatEtc[i].tymed) && pFormatEtc->cfFormat == instance->m_pFormatEtc[i].cfFormat && pFormatEtc->dwAspect == instance->m_pFormatEtc[i].dwAspect) { @@ -38,9 +39,9 @@ static int cliprdr_lookup_format(CliprdrDataObject *instance, FORMATETC *pFormat return -1; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryInterface(IDataObject *This, REFIID riid, void **ppvObject) +HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryInterface(IDataObject* This, REFIID riid, void** ppvObject) { - CliprdrDataObject *instance = (CliprdrDataObject *)This; + CliprdrDataObject* instance = (CliprdrDataObject*) This; if (IsEqualIID(riid, &IID_IDataObject) || IsEqualIID(riid, &IID_IUnknown)) { @@ -55,21 +56,21 @@ HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryInterface(IDataObject *This, RE } } -ULONG STDMETHODCALLTYPE CliprdrDataObject_AddRef(IDataObject *This) +ULONG STDMETHODCALLTYPE CliprdrDataObject_AddRef(IDataObject* This) { - CliprdrDataObject *instance = (CliprdrDataObject *)This; + CliprdrDataObject* instance = (CliprdrDataObject*) This; return InterlockedIncrement(&instance->m_lRefCount); } -ULONG STDMETHODCALLTYPE CliprdrDataObject_Release(IDataObject *This) +ULONG STDMETHODCALLTYPE CliprdrDataObject_Release(IDataObject* This) { - CliprdrDataObject *instance = (CliprdrDataObject *)This; LONG count; + CliprdrDataObject* instance = (CliprdrDataObject*) This; count = InterlockedDecrement(&instance->m_lRefCount); - if(count == 0) + if (count == 0) { CliprdrDataObject_Delete(instance); return 0; @@ -80,19 +81,18 @@ ULONG STDMETHODCALLTYPE CliprdrDataObject_Release(IDataObject *This) } } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData(IDataObject *This, FORMATETC *pFormatEtc, STGMEDIUM *pMedium) +HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData(IDataObject* This, FORMATETC* pFormatEtc, STGMEDIUM* pMedium) { - CliprdrDataObject *instance = (CliprdrDataObject *)This; - cliprdrContext *cliprdr = (cliprdrContext *)instance->m_pData; - int idx; - int i; + int i, idx; + CliprdrDataObject* instance = (CliprdrDataObject*) This; + cliprdrContext* cliprdr = (cliprdrContext*) instance->m_pData; if (pFormatEtc == NULL || pMedium == NULL) { return E_INVALIDARG; } - if((idx = cliprdr_lookup_format(instance, pFormatEtc)) == -1) + if ((idx = cliprdr_lookup_format(instance, pFormatEtc)) == -1) { return DV_E_FORMATETC; } @@ -117,10 +117,15 @@ HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData(IDataObject *This, FORMATETC { if (!instance->m_pStream) { - instance->m_pStream = (LPSTREAM *)calloc(instance->m_nStreams, sizeof(LPSTREAM)); + instance->m_pStream = (LPSTREAM*) calloc(instance->m_nStreams, sizeof(LPSTREAM)); + if (instance->m_pStream) - for(i = 0; i < instance->m_nStreams; i++) - instance->m_pStream[i] = (IStream *)CliprdrStream_New(i, cliprdr); + { + for (i = 0; i < instance->m_nStreams; i++) + { + instance->m_pStream[i] = (IStream*) CliprdrStream_New(i, cliprdr); + } + } } } @@ -158,16 +163,16 @@ HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData(IDataObject *This, FORMATETC return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetDataHere(IDataObject *This, FORMATETC *pformatetc, STGMEDIUM *pmedium) +HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetDataHere(IDataObject* This, FORMATETC *pformatetc, STGMEDIUM *pmedium) { - CliprdrDataObject *instance = (CliprdrDataObject *)This; + CliprdrDataObject* instance = (CliprdrDataObject*) This; return DATA_E_FORMATETC; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryGetData(IDataObject *This, FORMATETC *pformatetc) +HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryGetData(IDataObject* This, FORMATETC *pformatetc) { - CliprdrDataObject *instance = (CliprdrDataObject *)This; + CliprdrDataObject* instance = (CliprdrDataObject*) This; if (!pformatetc) return E_INVALIDARG; @@ -175,9 +180,9 @@ HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryGetData(IDataObject *This, FORM return (cliprdr_lookup_format(instance, pformatetc) == -1) ? DV_E_FORMATETC : S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetCanonicalFormatEtc(IDataObject *This, FORMATETC *pformatectIn, FORMATETC *pformatetcOut) +HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetCanonicalFormatEtc(IDataObject* This, FORMATETC *pformatectIn, FORMATETC *pformatetcOut) { - CliprdrDataObject *instance = (CliprdrDataObject *)This; + CliprdrDataObject* instance = (CliprdrDataObject*) This; if (!pformatetcOut) return E_INVALIDARG; @@ -187,23 +192,23 @@ HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetCanonicalFormatEtc(IDataObject *T return E_NOTIMPL; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_SetData(IDataObject *This, FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease) +HRESULT STDMETHODCALLTYPE CliprdrDataObject_SetData(IDataObject* This, FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease) { - CliprdrDataObject *instance = (CliprdrDataObject *)This; + CliprdrDataObject* instance = (CliprdrDataObject*) This; return E_NOTIMPL; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumFormatEtc(IDataObject *This, DWORD dwDirection, IEnumFORMATETC **ppenumFormatEtc) +HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumFormatEtc(IDataObject* This, DWORD dwDirection, IEnumFORMATETC **ppenumFormatEtc) { - CliprdrDataObject *instance = (CliprdrDataObject *)This; + CliprdrDataObject* instance = (CliprdrDataObject*) This; if (!ppenumFormatEtc) return E_INVALIDARG; if(dwDirection == DATADIR_GET) { - *ppenumFormatEtc = (IEnumFORMATETC *)CliprdrEnumFORMATETC_New(instance->m_nNumFormats, instance->m_pFormatEtc); + *ppenumFormatEtc = (IEnumFORMATETC*) CliprdrEnumFORMATETC_New(instance->m_nNumFormats, instance->m_pFormatEtc); return (*ppenumFormatEtc) ? S_OK : E_OUTOFMEMORY; } else @@ -212,65 +217,66 @@ HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumFormatEtc(IDataObject *This, DWO } } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_DAdvise(IDataObject *This, FORMATETC *pformatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection) +HRESULT STDMETHODCALLTYPE CliprdrDataObject_DAdvise(IDataObject* This, FORMATETC *pformatetc, DWORD advf, IAdviseSink* pAdvSink, DWORD *pdwConnection) { - CliprdrDataObject *instance = (CliprdrDataObject *)This; + CliprdrDataObject* instance = (CliprdrDataObject*) This; return OLE_E_ADVISENOTSUPPORTED; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_DUnadvise(IDataObject *This, DWORD dwConnection) +HRESULT STDMETHODCALLTYPE CliprdrDataObject_DUnadvise(IDataObject* This, DWORD dwConnection) { - CliprdrDataObject *instance = (CliprdrDataObject *)This; + CliprdrDataObject* instance = (CliprdrDataObject*) This; return OLE_E_ADVISENOTSUPPORTED; } -HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumDAdvise(IDataObject *This, IEnumSTATDATA **ppenumAdvise) +HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumDAdvise(IDataObject* This, IEnumSTATDATA** ppenumAdvise) { - CliprdrDataObject *instance = (CliprdrDataObject *)This; + CliprdrDataObject* instance = (CliprdrDataObject*) This; return OLE_E_ADVISENOTSUPPORTED; } -CliprdrDataObject *CliprdrDataObject_New(FORMATETC *fmtetc, STGMEDIUM *stgmed, int count, void *data) +CliprdrDataObject* CliprdrDataObject_New(FORMATETC* fmtetc, STGMEDIUM* stgmed, int count, void* data) { - CliprdrDataObject *instance; - IDataObject *iDataObject; int i; + CliprdrDataObject* instance; + IDataObject* iDataObject; - instance = (CliprdrDataObject *)calloc(1, sizeof(CliprdrDataObject)); + instance = (CliprdrDataObject*) calloc(1, sizeof(CliprdrDataObject)); if (instance) { iDataObject = &instance->iDataObject; - iDataObject->lpVtbl = (IDataObjectVtbl *)calloc(1, sizeof(IDataObjectVtbl)); + 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->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; + 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_lRefCount = 1; instance->m_nNumFormats = count; - instance->m_pData = data; - instance->m_nStreams = 0; - instance->m_pStream = NULL; + 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)); + instance->m_pFormatEtc = (FORMATETC*) calloc(count, sizeof(FORMATETC)); + instance->m_pStgMedium = (STGMEDIUM*) calloc(count, sizeof(STGMEDIUM)); - for(i = 0; i < count; i++) + for (i = 0; i < count; i++) { instance->m_pFormatEtc[i] = fmtetc[i]; instance->m_pStgMedium[i] = stgmed[i]; @@ -286,7 +292,7 @@ CliprdrDataObject *CliprdrDataObject_New(FORMATETC *fmtetc, STGMEDIUM *stgmed, i return instance; } -void CliprdrDataObject_Delete(CliprdrDataObject *instance) +void CliprdrDataObject_Delete(CliprdrDataObject* instance) { if (instance) { @@ -304,7 +310,9 @@ void CliprdrDataObject_Delete(CliprdrDataObject *instance) int i; for (i = 0; i < instance->m_nStreams; i++) + { CliprdrStream_Release(instance->m_pStream[i]); + } free(instance->m_pStream); } @@ -314,48 +322,51 @@ void CliprdrDataObject_Delete(CliprdrDataObject *instance) } -BOOL wf_create_file_obj(cliprdrContext *cliprdr, IDataObject **ppDataObject) +BOOL wf_create_file_obj(cliprdrContext* cliprdr, IDataObject** ppDataObject) { FORMATETC fmtetc[3]; STGMEDIUM stgmeds[3]; - if(!ppDataObject) + 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; + 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; + 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; + 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; - *ppDataObject = (IDataObject *)CliprdrDataObject_New(fmtetc, stgmeds, 3, cliprdr); + *ppDataObject = (IDataObject*) CliprdrDataObject_New(fmtetc, stgmeds, 3, cliprdr); return (*ppDataObject) ? TRUE : FALSE; } -void wf_destroy_file_obj(IDataObject *instance) +void wf_destroy_file_obj(IDataObject* instance) { - if(instance) + if (instance) IDataObject_Release(instance); } diff --git a/client/Windows/wf_cliprdr_EnumFORMATETC.c b/client/Windows/wf_cliprdr_EnumFORMATETC.c index 595132915..4bdefdc1a 100644 --- a/client/Windows/wf_cliprdr_EnumFORMATETC.c +++ b/client/Windows/wf_cliprdr_EnumFORMATETC.c @@ -21,20 +21,20 @@ #include "wf_cliprdr_EnumFORMATETC.h" -static void cliprdr_format_deep_copy(FORMATETC *dest, FORMATETC *source) +static void cliprdr_format_deep_copy(FORMATETC* dest, FORMATETC* source) { *dest = *source; if (source->ptd) { - dest->ptd = (DVTARGETDEVICE *)CoTaskMemAlloc(sizeof(DVTARGETDEVICE)); + dest->ptd = (DVTARGETDEVICE*) CoTaskMemAlloc(sizeof(DVTARGETDEVICE)); *(dest->ptd) = *(source->ptd); } } -HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_QueryInterface(IEnumFORMATETC *This, REFIID riid, void **ppvObject) +HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_QueryInterface(IEnumFORMATETC* This, REFIID riid, void** ppvObject) { - CliprdrEnumFORMATETC *instance = (CliprdrEnumFORMATETC *)This; + CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; if (IsEqualIID(riid, &IID_IEnumFORMATETC) || IsEqualIID(riid, &IID_IUnknown)) { @@ -49,17 +49,17 @@ HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_QueryInterface(IEnumFORMATETC *Th } } -ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_AddRef(IEnumFORMATETC *This) +ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_AddRef(IEnumFORMATETC* This) { - CliprdrEnumFORMATETC *instance = (CliprdrEnumFORMATETC *)This; + CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; return InterlockedIncrement(&instance->m_lRefCount); } -ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_Release(IEnumFORMATETC *This) +ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_Release(IEnumFORMATETC* This) { - CliprdrEnumFORMATETC *instance = (CliprdrEnumFORMATETC *)This; LONG count; + CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; count = InterlockedDecrement(&instance->m_lRefCount); @@ -74,16 +74,18 @@ ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_Release(IEnumFORMATETC *This) } } -HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Next(IEnumFORMATETC *This, ULONG celt, FORMATETC *rgelt, ULONG *pceltFetched) +HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Next(IEnumFORMATETC* This, ULONG celt, FORMATETC *rgelt, ULONG *pceltFetched) { - CliprdrEnumFORMATETC *instance = (CliprdrEnumFORMATETC *)This; ULONG copied = 0; + CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; if (celt == 0 || !rgelt) return E_INVALIDARG; while (instance->m_nIndex < instance->m_nNumFormats && copied < celt) + { cliprdr_format_deep_copy(&rgelt[copied++], &instance->m_pFormatEtc[instance->m_nIndex++]); + } if (pceltFetched != 0) *pceltFetched = copied; @@ -91,9 +93,9 @@ HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Next(IEnumFORMATETC *This, ULONG return (copied == celt) ? S_OK : S_FALSE; } -HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Skip(IEnumFORMATETC *This, ULONG celt) +HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Skip(IEnumFORMATETC* This, ULONG celt) { - CliprdrEnumFORMATETC *instance = (CliprdrEnumFORMATETC *)This; + CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; if (instance->m_nIndex + (LONG) celt > instance->m_nNumFormats) return S_FALSE; @@ -103,18 +105,18 @@ HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Skip(IEnumFORMATETC *This, ULONG return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Reset(IEnumFORMATETC *This) +HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Reset(IEnumFORMATETC* This) { - CliprdrEnumFORMATETC *instance = (CliprdrEnumFORMATETC *)This; + CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; instance->m_nIndex = 0; return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Clone(IEnumFORMATETC *This, IEnumFORMATETC **ppEnum) +HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Clone(IEnumFORMATETC* This, IEnumFORMATETC **ppEnum) { - CliprdrEnumFORMATETC *instance = (CliprdrEnumFORMATETC *)This; + CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*) This; if (!ppEnum) return E_INVALIDARG; diff --git a/client/Windows/wf_cliprdr_Stream.c b/client/Windows/wf_cliprdr_Stream.c index 308ed3696..3486a494d 100644 --- a/client/Windows/wf_cliprdr_Stream.c +++ b/client/Windows/wf_cliprdr_Stream.c @@ -20,9 +20,9 @@ #include "wf_cliprdr.h" #include "wf_cliprdr_Stream.h" -HRESULT STDMETHODCALLTYPE CliprdrStream_QueryInterface(IStream *This, REFIID riid, void **ppvObject) +HRESULT STDMETHODCALLTYPE CliprdrStream_QueryInterface(IStream* This, REFIID riid, void** ppvObject) { - CliprdrStream *instance = (CliprdrStream *)This; + CliprdrStream* instance = (CliprdrStream*) This; if (IsEqualIID(riid, &IID_IStream) || IsEqualIID(riid, &IID_IUnknown)) { @@ -37,17 +37,17 @@ HRESULT STDMETHODCALLTYPE CliprdrStream_QueryInterface(IStream *This, REFIID rii } } -ULONG STDMETHODCALLTYPE CliprdrStream_AddRef(IStream *This) +ULONG STDMETHODCALLTYPE CliprdrStream_AddRef(IStream* This) { - CliprdrStream *instance = (CliprdrStream *)This; + CliprdrStream* instance = (CliprdrStream*) This; return InterlockedIncrement(&instance->m_lRefCount); } -ULONG STDMETHODCALLTYPE CliprdrStream_Release(IStream * This) +ULONG STDMETHODCALLTYPE CliprdrStream_Release(IStream* This) { - CliprdrStream *instance = (CliprdrStream *)This; LONG count; + CliprdrStream* instance = (CliprdrStream*) This; count = InterlockedDecrement(&instance->m_lRefCount); @@ -65,9 +65,9 @@ ULONG STDMETHODCALLTYPE CliprdrStream_Release(IStream * This) #define FILECONTENTS_SIZE 0x00000001 #define FILECONTENTS_RANGE 0x00000002 -HRESULT STDMETHODCALLTYPE CliprdrStream_Read(IStream *This, void *pv, ULONG cb, ULONG *pcbRead) +HRESULT STDMETHODCALLTYPE CliprdrStream_Read(IStream* This, void *pv, ULONG cb, ULONG *pcbRead) { - CliprdrStream *instance = (CliprdrStream *)This; + CliprdrStream* instance = (CliprdrStream*) This; cliprdrContext *cliprdr = (cliprdrContext *)instance->m_pData; int ret; @@ -100,16 +100,16 @@ HRESULT STDMETHODCALLTYPE CliprdrStream_Read(IStream *This, void *pv, ULONG cb, return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrStream_Write(IStream *This, const void *pv, ULONG cb, ULONG *pcbWritten) +HRESULT STDMETHODCALLTYPE CliprdrStream_Write(IStream* This, const void *pv, ULONG cb, ULONG *pcbWritten) { - CliprdrStream *instance = (CliprdrStream *)This; + CliprdrStream* instance = (CliprdrStream*) This; return STG_E_ACCESSDENIED; } -HRESULT STDMETHODCALLTYPE CliprdrStream_Seek(IStream *This, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition) +HRESULT STDMETHODCALLTYPE CliprdrStream_Seek(IStream* This, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition) { - CliprdrStream *instance = (CliprdrStream *)This; + CliprdrStream* instance = (CliprdrStream*) This; ULONGLONG newoffset; newoffset = instance->m_lOffset.QuadPart; @@ -139,51 +139,51 @@ HRESULT STDMETHODCALLTYPE CliprdrStream_Seek(IStream *This, LARGE_INTEGER dlibMo return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrStream_SetSize(IStream *This, ULARGE_INTEGER libNewSize) +HRESULT STDMETHODCALLTYPE CliprdrStream_SetSize(IStream* This, ULARGE_INTEGER libNewSize) { - CliprdrStream *instance = (CliprdrStream *)This; + 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) +HRESULT STDMETHODCALLTYPE CliprdrStream_CopyTo(IStream* This, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER *pcbWritten) { - CliprdrStream *instance = (CliprdrStream *)This; + CliprdrStream* instance = (CliprdrStream*) This; return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrStream_Commit(IStream *This, DWORD grfCommitFlags) +HRESULT STDMETHODCALLTYPE CliprdrStream_Commit(IStream* This, DWORD grfCommitFlags) { - CliprdrStream *instance = (CliprdrStream *)This; + CliprdrStream* instance = (CliprdrStream*) This; return STG_E_MEDIUMFULL; } -HRESULT STDMETHODCALLTYPE CliprdrStream_Revert(IStream *This) +HRESULT STDMETHODCALLTYPE CliprdrStream_Revert(IStream* This) { - CliprdrStream *instance = (CliprdrStream *)This; + CliprdrStream* instance = (CliprdrStream*) This; return STG_E_INSUFFICIENTMEMORY; } -HRESULT STDMETHODCALLTYPE CliprdrStream_LockRegion(IStream *This, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) +HRESULT STDMETHODCALLTYPE CliprdrStream_LockRegion(IStream* This, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) { - CliprdrStream *instance = (CliprdrStream *)This; + CliprdrStream* instance = (CliprdrStream*) This; return STG_E_INSUFFICIENTMEMORY; } -HRESULT STDMETHODCALLTYPE CliprdrStream_UnlockRegion(IStream *This, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) +HRESULT STDMETHODCALLTYPE CliprdrStream_UnlockRegion(IStream* This, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) { - CliprdrStream *instance = (CliprdrStream *)This; + CliprdrStream* instance = (CliprdrStream*) This; return STG_E_INSUFFICIENTMEMORY; } -HRESULT STDMETHODCALLTYPE CliprdrStream_Stat(IStream *This, STATSTG *pstatstg, DWORD grfStatFlag) +HRESULT STDMETHODCALLTYPE CliprdrStream_Stat(IStream* This, STATSTG* pstatstg, DWORD grfStatFlag) { - CliprdrStream *instance = (CliprdrStream *)This; + CliprdrStream* instance = (CliprdrStream*) This; if (pstatstg == NULL) return STG_E_INVALIDPOINTER; @@ -196,11 +196,11 @@ HRESULT STDMETHODCALLTYPE CliprdrStream_Stat(IStream *This, STATSTG *pstatstg, D return STG_E_INSUFFICIENTMEMORY; case STATFLAG_NONAME: - pstatstg->cbSize.QuadPart = instance->m_lSize.QuadPart; + pstatstg->cbSize.QuadPart = instance->m_lSize.QuadPart; pstatstg->grfLocksSupported = LOCK_EXCLUSIVE; - pstatstg->grfMode = GENERIC_READ; - pstatstg->grfStateBits = 0; - pstatstg->type = STGTY_STREAM; + pstatstg->grfMode = GENERIC_READ; + pstatstg->grfStateBits = 0; + pstatstg->type = STGTY_STREAM; break; case STATFLAG_NOOPEN: @@ -213,51 +213,52 @@ HRESULT STDMETHODCALLTYPE CliprdrStream_Stat(IStream *This, STATSTG *pstatstg, D return S_OK; } -HRESULT STDMETHODCALLTYPE CliprdrStream_Clone(IStream *This, IStream **ppstm) +HRESULT STDMETHODCALLTYPE CliprdrStream_Clone(IStream* This, IStream** ppstm) { - CliprdrStream *instance = (CliprdrStream *)This; + CliprdrStream* instance = (CliprdrStream*) This; return STG_E_INSUFFICIENTMEMORY; } -CliprdrStream *CliprdrStream_New(LONG index, void *pData) +CliprdrStream *CliprdrStream_New(LONG index, void* pData) { - cliprdrContext *cliprdr = (cliprdrContext *)pData; - CliprdrStream *instance; - IStream *iStream; + cliprdrContext* cliprdr = (cliprdrContext*) pData; + CliprdrStream* instance; + IStream* iStream; - instance = (CliprdrStream *)calloc(1, sizeof(CliprdrStream)); + instance = (CliprdrStream*) calloc(1, sizeof(CliprdrStream)); if (instance) { iStream = &instance->iStream; - iStream->lpVtbl = (IStreamVtbl *)calloc(1, sizeof(IStreamVtbl)); + 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; + 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_lRefCount = 1; + instance->m_lIndex = index; + instance->m_pData = pData; instance->m_lOffset.QuadPart = 0; /* get content size of this stream */ - cliprdr_send_request_filecontents(cliprdr, (void *)instance, instance->m_lIndex, FILECONTENTS_SIZE, 0, 0, 8); - instance->m_lSize.QuadPart = *(LONGLONG *)cliprdr->req_fdata; + cliprdr_send_request_filecontents(cliprdr, (void*) instance, instance->m_lIndex, FILECONTENTS_SIZE, 0, 0, 8); + instance->m_lSize.QuadPart = *(LONGLONG*)cliprdr->req_fdata; free(cliprdr->req_fdata); } else @@ -270,12 +271,13 @@ CliprdrStream *CliprdrStream_New(LONG index, void *pData) return instance; } -void CliprdrStream_Delete(CliprdrStream *instance) +void CliprdrStream_Delete(CliprdrStream* instance) { if (instance) { if (instance->iStream.lpVtbl) free(instance->iStream.lpVtbl); + free(instance); } } diff --git a/libfreerdp/crypto/test/CMakeLists.txt b/libfreerdp/crypto/test/CMakeLists.txt index 56023e08f..86f5faf23 100644 --- a/libfreerdp/crypto/test/CMakeLists.txt +++ b/libfreerdp/crypto/test/CMakeLists.txt @@ -11,6 +11,8 @@ create_test_sourcelist(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_DRIVER} ${${MODULE_PREFIX}_TESTS}) +include_directories(${OPENSSL_INCLUDE_DIR}) + add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) target_link_libraries(${MODULE_NAME} freerdp) diff --git a/winpr/libwinpr/clipboard/synthetic.c b/winpr/libwinpr/clipboard/synthetic.c index 2878cb92b..bffa2315e 100644 --- a/winpr/libwinpr/clipboard/synthetic.c +++ b/winpr/libwinpr/clipboard/synthetic.c @@ -331,6 +331,7 @@ static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 form char* body; BYTE bom[2]; char num[11]; + WCHAR* wstr; if (SrcSize > 2) { @@ -343,7 +344,9 @@ static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 form if ((bom[0] == 0xFF) && (bom[1] == 0xFE)) { - ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) (data + 2), + wstr = (WCHAR*) &((BYTE*) data)[2]; + + ConvertFromUnicode(CP_UTF8, 0, wstr, (SrcSize - 2) / 2, &pSrcData, 0, NULL, NULL); } }