From 3ba66db99d72e5a4771a44e1032d7060653a131e Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 9 Mar 2020 10:58:02 +0100 Subject: [PATCH] Unify pReceiveChannelData and psPeerReceiveChannelData Fix definitions of the two function pointers. Use and definition did not match, fix that. Will create warnings in external projects --- include/freerdp/channels/channels.h | 4 ++-- include/freerdp/freerdp.h | 4 ++-- include/freerdp/peer.h | 4 ++-- libfreerdp/core/channels.c | 10 +++++----- libfreerdp/core/client.c | 29 +++++++++++++++++------------ libfreerdp/core/server.c | 6 +++--- server/proxy/pf_client.c | 13 ++++++------- server/proxy/pf_server.c | 14 ++++++-------- 8 files changed, 43 insertions(+), 41 deletions(-) diff --git a/include/freerdp/channels/channels.h b/include/freerdp/channels/channels.h index 30f75e5d3..6cd961038 100644 --- a/include/freerdp/channels/channels.h +++ b/include/freerdp/channels/channels.h @@ -50,8 +50,8 @@ extern "C" FREERDP_API HANDLE freerdp_channels_get_event_handle(freerdp* instance); FREERDP_API int freerdp_channels_process_pending_messages(freerdp* instance); - FREERDP_API int freerdp_channels_data(freerdp* instance, UINT16 channelId, BYTE* data, - int dataSize, int flags, int totalSize); + FREERDP_API BOOL freerdp_channels_data(freerdp* instance, UINT16 channelId, const BYTE* data, + size_t dataSize, UINT32 flags, size_t totalSize); FREERDP_API UINT16 freerdp_channels_get_id_by_name(freerdp* instance, const char* channel_name); FREERDP_API const char* freerdp_channels_get_name_by_id(freerdp* instance, UINT16 channelId); diff --git a/include/freerdp/freerdp.h b/include/freerdp/freerdp.h index 5e26c269d..9156480fc 100644 --- a/include/freerdp/freerdp.h +++ b/include/freerdp/freerdp.h @@ -178,8 +178,8 @@ extern "C" typedef BOOL (*pSendChannelData)(freerdp* instance, UINT16 channelId, const BYTE* data, size_t size); - typedef int (*pReceiveChannelData)(freerdp* instance, UINT16 channelId, BYTE* data, int size, - int flags, int totalSize); + typedef BOOL (*pReceiveChannelData)(freerdp* instance, UINT16 channelId, const BYTE* data, + size_t size, UINT32 flags, size_t totalSize); typedef BOOL (*pPresentGatewayMessage)(freerdp* instance, UINT32 type, BOOL isDisplayMandatory, BOOL isConsentMandatory, size_t length, diff --git a/include/freerdp/peer.h b/include/freerdp/peer.h index a81a3b5af..a6404444d 100644 --- a/include/freerdp/peer.h +++ b/include/freerdp/peer.h @@ -53,8 +53,8 @@ typedef BOOL (*psPeerClientCapabilities)(freerdp_peer* peer); typedef BOOL (*psPeerSendChannelData)(freerdp_peer* peer, UINT16 channelId, const BYTE* data, size_t size); -typedef int (*psPeerReceiveChannelData)(freerdp_peer* peer, UINT16 channelId, const BYTE* data, - size_t size, UINT32 flags, size_t totalSize); +typedef BOOL (*psPeerReceiveChannelData)(freerdp_peer* peer, UINT16 channelId, const BYTE* data, + size_t size, UINT32 flags, size_t totalSize); typedef HANDLE (*psPeerVirtualChannelOpen)(freerdp_peer* peer, const char* name, UINT32 flags); typedef BOOL (*psPeerVirtualChannelClose)(freerdp_peer* peer, HANDLE hChannel); diff --git a/libfreerdp/core/channels.c b/libfreerdp/core/channels.c index 6cff02efb..159d8ffca 100644 --- a/libfreerdp/core/channels.c +++ b/libfreerdp/core/channels.c @@ -124,7 +124,7 @@ BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channelId, const BYTE* data, size_ BOOL freerdp_channel_process(freerdp* instance, wStream* s, UINT16 channelId, size_t packetLength) { - int rc = 0; + BOOL rc = FALSE; UINT32 length; UINT32 flags; size_t chunkLength; @@ -160,7 +160,7 @@ BOOL freerdp_channel_process(freerdp* instance, wStream* s, UINT16 channelId, si } IFCALLRET(instance->ReceiveChannelData, rc, instance, channelId, Stream_Pointer(s), chunkLength, flags, length); - if (rc != CHANNEL_RC_OK) + if (!rc) { WLog_WARN(TAG, "ReceiveChannelData returned %d", rc); return FALSE; @@ -213,9 +213,9 @@ BOOL freerdp_channel_peer_process(freerdp_peer* client, wStream* s, UINT16 chann } else if (client->ReceiveChannelData) { - int rc = client->ReceiveChannelData(client, channelId, Stream_Pointer(s), chunkLength, - flags, length); - if (rc < 0) + BOOL rc = client->ReceiveChannelData(client, channelId, Stream_Pointer(s), chunkLength, + flags, length); + if (!rc) return FALSE; } return Stream_SafeSeek(s, chunkLength); diff --git a/libfreerdp/core/client.c b/libfreerdp/core/client.c index 09b0af87c..666fcffbe 100644 --- a/libfreerdp/core/client.c +++ b/libfreerdp/core/client.c @@ -419,20 +419,25 @@ fail: return error; } -int freerdp_channels_data(freerdp* instance, UINT16 channelId, BYTE* data, int dataSize, int flags, - int totalSize) +BOOL freerdp_channels_data(freerdp* instance, UINT16 channelId, const BYTE* cdata, size_t dataSize, + UINT32 flags, size_t totalSize) { UINT32 index; rdpMcs* mcs; rdpChannels* channels; rdpMcsChannel* channel = NULL; CHANNEL_OPEN_DATA* pChannelOpenData; + union { + const BYTE* pcb; + BYTE* pb; + } data; - if (!instance || !data || (dataSize < 0) || (totalSize < 0)) + data.pcb = cdata; + if (!instance || !data.pcb) { - WLog_ERR(TAG, "%s(%p, %" PRIu16 ", %p, %d, 0x%08x, %d): Invalid arguments", __FUNCTION__, - instance, channelId, data, dataSize, flags, totalSize); - return -1; + WLog_ERR(TAG, "%s(%p, %" PRIu16 ", %p, 0x%08x): Invalid arguments", __FUNCTION__, instance, + channelId, data, flags); + return FALSE; } mcs = instance->context->rdp->mcs; @@ -440,7 +445,7 @@ int freerdp_channels_data(freerdp* instance, UINT16 channelId, BYTE* data, int d if (!channels || !mcs) { - return 1; + return FALSE; } for (index = 0; index < mcs->channelCount; index++) @@ -454,30 +459,30 @@ int freerdp_channels_data(freerdp* instance, UINT16 channelId, BYTE* data, int d if (!channel) { - return 1; + return FALSE; } pChannelOpenData = freerdp_channels_find_channel_open_data_by_name(channels, channel->Name); if (!pChannelOpenData) { - return 1; + return FALSE; } if (pChannelOpenData->pChannelOpenEventProc) { pChannelOpenData->pChannelOpenEventProc(pChannelOpenData->OpenHandle, - CHANNEL_EVENT_DATA_RECEIVED, data, dataSize, + CHANNEL_EVENT_DATA_RECEIVED, data.pb, dataSize, totalSize, flags); } else if (pChannelOpenData->pChannelOpenEventProcEx) { pChannelOpenData->pChannelOpenEventProcEx( pChannelOpenData->lpUserParam, pChannelOpenData->OpenHandle, - CHANNEL_EVENT_DATA_RECEIVED, data, dataSize, totalSize, flags); + CHANNEL_EVENT_DATA_RECEIVED, data.pb, dataSize, totalSize, flags); } - return 0; + return TRUE; } UINT16 freerdp_channels_get_id_by_name(freerdp* instance, const char* channel_name) diff --git a/libfreerdp/core/server.c b/libfreerdp/core/server.c index 66446722b..4dd99035e 100644 --- a/libfreerdp/core/server.c +++ b/libfreerdp/core/server.c @@ -400,8 +400,8 @@ static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId, con return ret; } -static int WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId, const BYTE* data, - size_t size, UINT32 flags, size_t totalSize) +static BOOL WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId, const BYTE* data, + size_t size, UINT32 flags, size_t totalSize) { UINT32 i; BOOL status = FALSE; @@ -419,7 +419,7 @@ static int WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId, const B } } - return status ? 0 : -1; + return status; } void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int* fds_count) diff --git a/server/proxy/pf_client.c b/server/proxy/pf_client.c index b8d0e25ce..b947aaceb 100644 --- a/server/proxy/pf_client.c +++ b/server/proxy/pf_client.c @@ -197,8 +197,9 @@ static BOOL pf_client_pre_connect(freerdp* instance) return TRUE; } -static int pf_client_receive_channel_data_hook(freerdp* instance, UINT16 channelId, BYTE* data, - int size, int flags, int totalSize) +static BOOL pf_client_receive_channel_data_hook(freerdp* instance, UINT16 channelId, + const BYTE* data, size_t size, UINT32 flags, + size_t totalSize) { pClientContext* pc = (pClientContext*)instance->context; pServerContext* ps = pc->pdata->ps; @@ -221,13 +222,11 @@ static int pf_client_receive_channel_data_hook(freerdp* instance, UINT16 channel ev.data_len = size; if (!pf_modules_run_filter(FILTER_TYPE_CLIENT_PASSTHROUGH_CHANNEL_DATA, pdata, &ev)) - return -1; + return FALSE; server_channel_id = (UINT64)HashTable_GetItemValue(ps->vc_ids, (void*)channel_name); - if (!ps->context.peer->SendChannelData(ps->context.peer, (UINT16)server_channel_id, - data, size)) - return -1; - return 0; + return ps->context.peer->SendChannelData(ps->context.peer, (UINT16)server_channel_id, + data, size); } } diff --git a/server/proxy/pf_server.c b/server/proxy/pf_server.c index cc32a351e..95165e0ba 100644 --- a/server/proxy/pf_server.c +++ b/server/proxy/pf_server.c @@ -198,9 +198,9 @@ static BOOL pf_server_adjust_monitor_layout(freerdp_peer* peer) return TRUE; } -static int pf_server_receive_channel_data_hook(freerdp_peer* peer, UINT16 channelId, - const BYTE* data, size_t size, UINT32 flags, - size_t totalSize) +static BOOL pf_server_receive_channel_data_hook(freerdp_peer* peer, UINT16 channelId, + const BYTE* data, size_t size, UINT32 flags, + size_t totalSize) { pServerContext* ps = (pServerContext*)peer->context; pClientContext* pc = ps->pdata->pc; @@ -222,14 +222,12 @@ static int pf_server_receive_channel_data_hook(freerdp_peer* peer, UINT16 channe ev.data_len = size; if (!pf_modules_run_filter(FILTER_TYPE_SERVER_PASSTHROUGH_CHANNEL_DATA, pdata, &ev)) - return -1; + return FALSE; client_channel_id = (UINT64)HashTable_GetItemValue(pc->vc_ids, (void*)channel_name); - if (!pc->context.instance->SendChannelData( - pc->context.instance, (UINT16)client_channel_id, (BYTE*)data, size)) - return -1; - return 0; + return pc->context.instance->SendChannelData(pc->context.instance, + (UINT16)client_channel_id, data, size); } }