Cleaned up cliprdr

This commit is contained in:
Armin Novak 2021-09-06 16:23:31 +02:00 committed by akallabeth
parent f794a8c7d4
commit cde002f460
2 changed files with 127 additions and 16 deletions

View File

@ -605,6 +605,9 @@ UINT channel_client_quit_handler(void* MsgsHandle)
/* TODO: return some error here */ /* TODO: return some error here */
return CHANNEL_RC_OK; return CHANNEL_RC_OK;
} }
WINPR_ASSERT(internals->ctx);
WINPR_ASSERT(internals->ctx->settings);
if (!(internals->ctx->settings->ThreadingFlags & THREADING_FLAGS_DISABLE_THREADS)) if (!(internals->ctx->settings->ThreadingFlags & THREADING_FLAGS_DISABLE_THREADS))
{ {
if (MessageQueue_PostQuit(internals->queue, 0) && if (MessageQueue_PostQuit(internals->queue, 0) &&

View File

@ -25,6 +25,7 @@
#endif #endif
#include <winpr/wtypes.h> #include <winpr/wtypes.h>
#include <winpr/assert.h>
#include <winpr/crt.h> #include <winpr/crt.h>
#include <winpr/print.h> #include <winpr/print.h>
@ -92,6 +93,10 @@ static UINT cliprdr_packet_send(cliprdrPlugin* cliprdr, wStream* s)
size_t pos; size_t pos;
UINT32 dataLen; UINT32 dataLen;
UINT status = CHANNEL_RC_OK; UINT status = CHANNEL_RC_OK;
WINPR_ASSERT(cliprdr);
WINPR_ASSERT(s);
pos = Stream_GetPosition(s); pos = Stream_GetPosition(s);
dataLen = pos - 8; dataLen = pos - 8;
Stream_SetPosition(s, 4); Stream_SetPosition(s, 4);
@ -108,6 +113,7 @@ static UINT cliprdr_packet_send(cliprdrPlugin* cliprdr, wStream* s)
} }
else else
{ {
WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelWriteEx);
status = cliprdr->channelEntryPoints.pVirtualChannelWriteEx( status = cliprdr->channelEntryPoints.pVirtualChannelWriteEx(
cliprdr->InitHandle, cliprdr->OpenHandle, Stream_Buffer(s), cliprdr->InitHandle, cliprdr->OpenHandle, Stream_Buffer(s),
(UINT32)Stream_GetPosition(s), s); (UINT32)Stream_GetPosition(s), s);
@ -161,6 +167,9 @@ static UINT cliprdr_process_general_capability(cliprdrPlugin* cliprdr, wStream*
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
UINT error = CHANNEL_RC_OK; UINT error = CHANNEL_RC_OK;
WINPR_ASSERT(cliprdr);
WINPR_ASSERT(s);
if (!context) if (!context)
{ {
WLog_ERR(TAG, "cliprdr_get_client_interface failed!"); WLog_ERR(TAG, "cliprdr_get_client_interface failed!");
@ -219,6 +228,9 @@ static UINT cliprdr_process_clip_caps(cliprdrPlugin* cliprdr, wStream* s, UINT32
UINT16 capabilitySetType; UINT16 capabilitySetType;
UINT error = CHANNEL_RC_OK; UINT error = CHANNEL_RC_OK;
WINPR_ASSERT(cliprdr);
WINPR_ASSERT(s);
if (Stream_GetRemainingLength(s) < 4) if (Stream_GetRemainingLength(s) < 4)
return ERROR_INVALID_DATA; return ERROR_INVALID_DATA;
@ -270,6 +282,10 @@ static UINT cliprdr_process_monitor_ready(cliprdrPlugin* cliprdr, wStream* s, UI
CLIPRDR_MONITOR_READY monitorReady; CLIPRDR_MONITOR_READY monitorReady;
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
UINT error = CHANNEL_RC_OK; UINT error = CHANNEL_RC_OK;
WINPR_ASSERT(cliprdr);
WINPR_ASSERT(s);
WLog_Print(cliprdr->log, WLOG_DEBUG, "MonitorReady"); WLog_Print(cliprdr->log, WLOG_DEBUG, "MonitorReady");
if (!context->custom) if (!context->custom)
@ -314,6 +330,10 @@ static UINT cliprdr_process_filecontents_request(cliprdrPlugin* cliprdr, wStream
CLIPRDR_FILE_CONTENTS_REQUEST request; CLIPRDR_FILE_CONTENTS_REQUEST request;
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
UINT error = CHANNEL_RC_OK; UINT error = CHANNEL_RC_OK;
WINPR_ASSERT(cliprdr);
WINPR_ASSERT(s);
WLog_Print(cliprdr->log, WLOG_DEBUG, "FileContentsRequest"); WLog_Print(cliprdr->log, WLOG_DEBUG, "FileContentsRequest");
if (!context->custom) if (!context->custom)
@ -348,6 +368,10 @@ static UINT cliprdr_process_filecontents_response(cliprdrPlugin* cliprdr, wStrea
CLIPRDR_FILE_CONTENTS_RESPONSE response; CLIPRDR_FILE_CONTENTS_RESPONSE response;
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
UINT error = CHANNEL_RC_OK; UINT error = CHANNEL_RC_OK;
WINPR_ASSERT(cliprdr);
WINPR_ASSERT(s);
WLog_Print(cliprdr->log, WLOG_DEBUG, "FileContentsResponse"); WLog_Print(cliprdr->log, WLOG_DEBUG, "FileContentsResponse");
if (!context->custom) if (!context->custom)
@ -382,6 +406,10 @@ static UINT cliprdr_process_lock_clipdata(cliprdrPlugin* cliprdr, wStream* s, UI
CLIPRDR_LOCK_CLIPBOARD_DATA lockClipboardData; CLIPRDR_LOCK_CLIPBOARD_DATA lockClipboardData;
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
UINT error = CHANNEL_RC_OK; UINT error = CHANNEL_RC_OK;
WINPR_ASSERT(cliprdr);
WINPR_ASSERT(s);
WLog_Print(cliprdr->log, WLOG_DEBUG, "LockClipData"); WLog_Print(cliprdr->log, WLOG_DEBUG, "LockClipData");
if (!context->custom) if (!context->custom)
@ -419,6 +447,10 @@ static UINT cliprdr_process_unlock_clipdata(cliprdrPlugin* cliprdr, wStream* s,
CLIPRDR_UNLOCK_CLIPBOARD_DATA unlockClipboardData; CLIPRDR_UNLOCK_CLIPBOARD_DATA unlockClipboardData;
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
UINT error = CHANNEL_RC_OK; UINT error = CHANNEL_RC_OK;
WINPR_ASSERT(cliprdr);
WINPR_ASSERT(s);
WLog_Print(cliprdr->log, WLOG_DEBUG, "UnlockClipData"); WLog_Print(cliprdr->log, WLOG_DEBUG, "UnlockClipData");
if (!context->custom) if (!context->custom)
@ -455,6 +487,9 @@ static UINT cliprdr_order_recv(LPVOID userdata, wStream* s)
UINT32 dataLen; UINT32 dataLen;
UINT error; UINT error;
WINPR_ASSERT(cliprdr);
WINPR_ASSERT(s);
if (Stream_GetRemainingLength(s) < 8) if (Stream_GetRemainingLength(s) < 8)
return ERROR_INVALID_DATA; return ERROR_INVALID_DATA;
@ -567,7 +602,12 @@ static UINT cliprdr_client_capabilities(CliprdrClientContext* context,
wStream* s; wStream* s;
UINT32 flags; UINT32 flags;
const CLIPRDR_GENERAL_CAPABILITY_SET* generalCapabilitySet; const CLIPRDR_GENERAL_CAPABILITY_SET* generalCapabilitySet;
cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle; cliprdrPlugin* cliprdr;
WINPR_ASSERT(context);
cliprdr = (cliprdrPlugin*)context->handle;
WINPR_ASSERT(cliprdr);
s = cliprdr_packet_new(CB_CLIP_CAPS, 0, 4 + CB_CAPSTYPE_GENERAL_LEN); s = cliprdr_packet_new(CB_CLIP_CAPS, 0, 4 + CB_CAPSTYPE_GENERAL_LEN);
@ -622,7 +662,14 @@ static UINT cliprdr_temp_directory(CliprdrClientContext* context,
int length; int length;
wStream* s; wStream* s;
WCHAR* wszTempDir = NULL; WCHAR* wszTempDir = NULL;
cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle; cliprdrPlugin* cliprdr;
WINPR_ASSERT(context);
WINPR_ASSERT(tempDirectory);
cliprdr = (cliprdrPlugin*)context->handle;
WINPR_ASSERT(cliprdr);
s = cliprdr_packet_new(CB_TEMP_DIRECTORY, 0, 260 * sizeof(WCHAR)); s = cliprdr_packet_new(CB_TEMP_DIRECTORY, 0, 260 * sizeof(WCHAR));
if (!s) if (!s)
@ -657,7 +704,12 @@ static UINT cliprdr_client_format_list(CliprdrClientContext* context,
const CLIPRDR_FORMAT_LIST* formatList) const CLIPRDR_FORMAT_LIST* formatList)
{ {
wStream* s; wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle; cliprdrPlugin* cliprdr;
WINPR_ASSERT(context);
cliprdr = (cliprdrPlugin*)context->handle;
WINPR_ASSERT(cliprdr);
s = cliprdr_packet_format_list_new(formatList, cliprdr->useLongFormatNames); s = cliprdr_packet_format_list_new(formatList, cliprdr->useLongFormatNames);
if (!s) if (!s)
@ -681,7 +733,14 @@ cliprdr_client_format_list_response(CliprdrClientContext* context,
const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse) const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
{ {
wStream* s; wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle; cliprdrPlugin* cliprdr;
WINPR_ASSERT(context);
WINPR_ASSERT(formatListResponse);
cliprdr = (cliprdrPlugin*)context->handle;
WINPR_ASSERT(cliprdr);
s = cliprdr_packet_new(CB_FORMAT_LIST_RESPONSE, formatListResponse->msgFlags, 0); s = cliprdr_packet_new(CB_FORMAT_LIST_RESPONSE, formatListResponse->msgFlags, 0);
if (!s) if (!s)
@ -703,7 +762,14 @@ static UINT cliprdr_client_lock_clipboard_data(CliprdrClientContext* context,
const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData) const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
{ {
wStream* s; wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle; cliprdrPlugin* cliprdr;
WINPR_ASSERT(context);
WINPR_ASSERT(lockClipboardData);
cliprdr = (cliprdrPlugin*)context->handle;
WINPR_ASSERT(cliprdr);
s = cliprdr_packet_lock_clipdata_new(lockClipboardData); s = cliprdr_packet_lock_clipdata_new(lockClipboardData);
if (!s) if (!s)
@ -727,7 +793,14 @@ cliprdr_client_unlock_clipboard_data(CliprdrClientContext* context,
const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData) const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
{ {
wStream* s; wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle; cliprdrPlugin* cliprdr;
WINPR_ASSERT(context);
WINPR_ASSERT(unlockClipboardData);
cliprdr = (cliprdrPlugin*)context->handle;
WINPR_ASSERT(cliprdr);
s = cliprdr_packet_unlock_clipdata_new(unlockClipboardData); s = cliprdr_packet_unlock_clipdata_new(unlockClipboardData);
if (!s) if (!s)
@ -750,7 +823,13 @@ static UINT cliprdr_client_format_data_request(CliprdrClientContext* context,
const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest) const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
{ {
wStream* s; wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle; cliprdrPlugin* cliprdr;
WINPR_ASSERT(context);
WINPR_ASSERT(formatDataRequest);
cliprdr = (cliprdrPlugin*)context->handle;
WINPR_ASSERT(cliprdr);
s = cliprdr_packet_new(CB_FORMAT_DATA_REQUEST, 0, 4); s = cliprdr_packet_new(CB_FORMAT_DATA_REQUEST, 0, 4);
@ -775,7 +854,13 @@ cliprdr_client_format_data_response(CliprdrClientContext* context,
const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse) const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
{ {
wStream* s; wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle; cliprdrPlugin* cliprdr;
WINPR_ASSERT(context);
WINPR_ASSERT(formatDataResponse);
cliprdr = (cliprdrPlugin*)context->handle;
WINPR_ASSERT(cliprdr);
s = cliprdr_packet_new(CB_FORMAT_DATA_RESPONSE, formatDataResponse->msgFlags, s = cliprdr_packet_new(CB_FORMAT_DATA_RESPONSE, formatDataResponse->msgFlags,
formatDataResponse->dataLen); formatDataResponse->dataLen);
@ -801,8 +886,12 @@ cliprdr_client_file_contents_request(CliprdrClientContext* context,
const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest) const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
{ {
wStream* s; wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle; cliprdrPlugin* cliprdr;
WINPR_ASSERT(context);
WINPR_ASSERT(fileContentsRequest);
cliprdr = (cliprdrPlugin*)context->handle;
if (!cliprdr) if (!cliprdr)
return ERROR_INTERNAL_ERROR; return ERROR_INTERNAL_ERROR;
@ -838,7 +927,14 @@ cliprdr_client_file_contents_response(CliprdrClientContext* context,
const CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse) const CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse)
{ {
wStream* s; wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle; cliprdrPlugin* cliprdr;
WINPR_ASSERT(context);
WINPR_ASSERT(fileContentsResponse);
cliprdr = (cliprdrPlugin*)context->handle;
WINPR_ASSERT(cliprdr);
s = cliprdr_packet_file_contents_response_new(fileContentsResponse); s = cliprdr_packet_file_contents_response_new(fileContentsResponse);
if (!s) if (!s)
@ -900,18 +996,23 @@ static VOID VCAPITYPE cliprdr_virtual_channel_open_event_ex(LPVOID lpUserParam,
static UINT cliprdr_virtual_channel_event_connected(cliprdrPlugin* cliprdr, LPVOID pData, static UINT cliprdr_virtual_channel_event_connected(cliprdrPlugin* cliprdr, LPVOID pData,
UINT32 dataLength) UINT32 dataLength)
{ {
DWORD status;
WINPR_ASSERT(cliprdr); WINPR_ASSERT(cliprdr);
WINPR_ASSERT(cliprdr->context); WINPR_ASSERT(cliprdr->context);
WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelOpenEx);
status = cliprdr->channelEntryPoints.pVirtualChannelOpenEx(
cliprdr->InitHandle, &cliprdr->OpenHandle, cliprdr->channelDef.name,
cliprdr_virtual_channel_open_event_ex);
if (status != CHANNEL_RC_OK)
return status;
cliprdr->MsgsHandle = channel_client_create_handler( cliprdr->MsgsHandle = channel_client_create_handler(
cliprdr->context->rdpcontext, cliprdr, cliprdr_order_recv, CLIPRDR_SVC_CHANNEL_NAME); cliprdr->context->rdpcontext, cliprdr, cliprdr_order_recv, CLIPRDR_SVC_CHANNEL_NAME);
if (!cliprdr->MsgsHandle) if (!cliprdr->MsgsHandle)
return ERROR_INTERNAL_ERROR; return ERROR_INTERNAL_ERROR;
WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelOpenEx); return status;
return cliprdr->channelEntryPoints.pVirtualChannelOpenEx(
cliprdr->InitHandle, &cliprdr->OpenHandle, cliprdr->channelDef.name,
cliprdr_virtual_channel_open_event_ex);
} }
/** /**
@ -923,11 +1024,15 @@ static UINT cliprdr_virtual_channel_event_disconnected(cliprdrPlugin* cliprdr)
{ {
UINT rc; UINT rc;
WINPR_ASSERT(cliprdr);
channel_client_quit_handler(cliprdr->MsgsHandle);
cliprdr->MsgsHandle = NULL;
if (cliprdr->OpenHandle == 0) if (cliprdr->OpenHandle == 0)
return CHANNEL_RC_OK; return CHANNEL_RC_OK;
channel_client_quit_handler(cliprdr->MsgsHandle); WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelCloseEx);
rc = cliprdr->channelEntryPoints.pVirtualChannelCloseEx(cliprdr->InitHandle, rc = cliprdr->channelEntryPoints.pVirtualChannelCloseEx(cliprdr->InitHandle,
cliprdr->OpenHandle); cliprdr->OpenHandle);
@ -950,6 +1055,8 @@ static UINT cliprdr_virtual_channel_event_disconnected(cliprdrPlugin* cliprdr)
*/ */
static UINT cliprdr_virtual_channel_event_terminated(cliprdrPlugin* cliprdr) static UINT cliprdr_virtual_channel_event_terminated(cliprdrPlugin* cliprdr)
{ {
WINPR_ASSERT(cliprdr);
cliprdr->InitHandle = 0; cliprdr->InitHandle = 0;
free(cliprdr->context); free(cliprdr->context);
free(cliprdr); free(cliprdr);
@ -1024,6 +1131,7 @@ BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS pEntryPoints, PVOID p
sprintf_s(cliprdr->channelDef.name, ARRAYSIZE(cliprdr->channelDef.name), sprintf_s(cliprdr->channelDef.name, ARRAYSIZE(cliprdr->channelDef.name),
CLIPRDR_SVC_CHANNEL_NAME); CLIPRDR_SVC_CHANNEL_NAME);
pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP_EX*)pEntryPoints; pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP_EX*)pEntryPoints;
WINPR_ASSERT(pEntryPointsEx);
if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX)) && if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX)) &&
(pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER)) (pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))