From 275741cc756628a5e50803e39a3ad266c19f5686 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 12 Jan 2023 13:58:47 +0100 Subject: [PATCH] [core,utils] add drdynvc stringification functions --- channels/drdynvc/client/drdynvc_main.c | 5 ++- include/freerdp/utils/drdynvc.h | 39 +++++++++++++++++ libfreerdp/core/server.c | 4 +- libfreerdp/utils/CMakeLists.txt | 1 + libfreerdp/utils/drdynvc.c | 50 ++++++++++++++++++++++ server/proxy/channels/pf_channel_drdynvc.c | 36 +++------------- 6 files changed, 101 insertions(+), 34 deletions(-) create mode 100644 include/freerdp/utils/drdynvc.h create mode 100644 libfreerdp/utils/drdynvc.c diff --git a/channels/drdynvc/client/drdynvc_main.c b/channels/drdynvc/client/drdynvc_main.c index adbaed2ef..7619a19a1 100644 --- a/channels/drdynvc/client/drdynvc_main.c +++ b/channels/drdynvc/client/drdynvc_main.c @@ -26,6 +26,7 @@ #include #include +#include #include "drdynvc_main.h" @@ -1398,8 +1399,8 @@ static UINT drdynvc_order_recv(drdynvcPlugin* drdynvc, wStream* s, UINT32 Thread Cmd = (value & 0xf0) >> 4; Sp = (value & 0x0c) >> 2; cbChId = (value & 0x03) >> 0; - WLog_Print(drdynvc->log, WLOG_TRACE, - "order_recv: Cmd=0x02" PRIx8 ", Sp=%" PRIu8 " cbChId=%" PRIu8, Cmd, Sp, cbChId); + WLog_Print(drdynvc->log, WLOG_TRACE, "order_recv: Cmd=%s, Sp=%" PRIu8 " cbChId=%" PRIu8, + drdynvc_get_packet_type(Cmd), Sp, cbChId); switch (Cmd) { diff --git a/include/freerdp/utils/drdynvc.h b/include/freerdp/utils/drdynvc.h new file mode 100644 index 000000000..cc96d95ab --- /dev/null +++ b/include/freerdp/utils/drdynvc.h @@ -0,0 +1,39 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * GFX Utils - Helper functions converting something to string + * + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * 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. + */ + +#ifndef FREERDP_UTILS_DRDYNVC_H +#define FREERDP_UTILS_DRDYNVC_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API const char* drdynvc_get_packet_type(BYTE cmd); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libfreerdp/core/server.c b/libfreerdp/core/server.c index 1fb722cb7..b20ee8eff 100644 --- a/libfreerdp/core/server.c +++ b/libfreerdp/core/server.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "rdp.h" @@ -318,7 +319,8 @@ static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel) length -= value; - DEBUG_DVC("Cmd %d ChannelId %" PRIu32 " length %" PRIu32 "", Cmd, ChannelId, length); + DEBUG_DVC("Cmd %s ChannelId %" PRIu32 " length %" PRIu32 "", + drdynvc_get_packet_type(Cmd), ChannelId, length); dvc = wts_get_dvc_channel_by_id(channel->vcm, ChannelId); if (!dvc) { diff --git a/libfreerdp/utils/CMakeLists.txt b/libfreerdp/utils/CMakeLists.txt index 8d953a1db..e16ea3bfa 100644 --- a/libfreerdp/utils/CMakeLists.txt +++ b/libfreerdp/utils/CMakeLists.txt @@ -28,6 +28,7 @@ set(${MODULE_PREFIX}_SRCS signal.c string.c gfx.c + drdynvc.c smartcard_operations.c smartcard_pack.c smartcard_call.c diff --git a/libfreerdp/utils/drdynvc.c b/libfreerdp/utils/drdynvc.c new file mode 100644 index 000000000..ba9bf5adc --- /dev/null +++ b/libfreerdp/utils/drdynvc.c @@ -0,0 +1,50 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * drdynvc Utils - Helper functions converting something to string + * + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * 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. + */ + +#include +#include + +const char* drdynvc_get_packet_type(BYTE cmd) +{ + switch (cmd) + { + case CREATE_REQUEST_PDU: + return "CREATE_REQUEST_PDU"; + case DATA_FIRST_PDU: + return "DATA_FIRST_PDU"; + case DATA_PDU: + return "DATA_PDU"; + case CLOSE_REQUEST_PDU: + return "CLOSE_REQUEST_PDU"; + case CAPABILITY_REQUEST_PDU: + return "CAPABILITY_REQUEST_PDU"; + case DATA_FIRST_COMPRESSED_PDU: + return "DATA_FIRST_COMPRESSED_PDU"; + case DATA_COMPRESSED_PDU: + return "DATA_COMPRESSED_PDU"; + case SOFT_SYNC_REQUEST_PDU: + return "SOFT_SYNC_REQUEST_PDU"; + case SOFT_SYNC_RESPONSE_PDU: + return "SOFT_SYNC_RESPONSE_PDU"; + default: + return "UNKNOWN"; + } +} diff --git a/server/proxy/channels/pf_channel_drdynvc.c b/server/proxy/channels/pf_channel_drdynvc.c index e6cc568bc..326020e1f 100644 --- a/server/proxy/channels/pf_channel_drdynvc.c +++ b/server/proxy/channels/pf_channel_drdynvc.c @@ -19,6 +19,7 @@ #include #include +#include #include #include "pf_channel_drdynvc.h" @@ -169,33 +170,6 @@ static DynvcReadResult dynvc_read_varInt(wStream* s, size_t len, UINT64* varInt, return DYNCVC_READ_OK; } -static const char* get_packet_type(BYTE cmd) -{ - switch (cmd) - { - case CREATE_REQUEST_PDU: - return "CREATE_REQUEST_PDU"; - case DATA_FIRST_PDU: - return "DATA_FIRST_PDU"; - case DATA_PDU: - return "DATA_PDU"; - case CLOSE_REQUEST_PDU: - return "CLOSE_REQUEST_PDU"; - case CAPABILITY_REQUEST_PDU: - return "CAPABILITY_REQUEST_PDU"; - case DATA_FIRST_COMPRESSED_PDU: - return "DATA_FIRST_COMPRESSED_PDU"; - case DATA_COMPRESSED_PDU: - return "DATA_COMPRESSED_PDU"; - case SOFT_SYNC_REQUEST_PDU: - return "SOFT_SYNC_REQUEST_PDU"; - case SOFT_SYNC_RESPONSE_PDU: - return "SOFT_SYNC_RESPONSE_PDU"; - default: - return "UNKNOWN"; - } -} - static PfChannelResult DynvcTrackerPeekFn(ChannelStateTracker* tracker, BOOL firstPacket, BOOL lastPacket) { @@ -427,14 +401,14 @@ static PfChannelResult DynvcTrackerPeekFn(ChannelStateTracker* tracker, BOOL fir if (dynChannel->openStatus != CHANNEL_OPENSTATE_OPENED) { WLog_ERR(TAG, "DynvcTracker(%s [%s]): channel is not opened", dynChannel->channelName, - get_packet_type(cmd)); + drdynvc_get_packet_type(cmd)); return PF_CHANNEL_RESULT_ERROR; } if ((cmd == DATA_FIRST_PDU) || (cmd == DATA_FIRST_COMPRESSED_PDU)) { WLog_DBG(TAG, "DynvcTracker(%s [%s]): %s DATA_FIRST currentPacketLength=%" PRIu64 "", - dynChannel->channelName, get_packet_type(cmd), direction, Length); + dynChannel->channelName, drdynvc_get_packet_type(cmd), direction, Length); trackerState->currentDataLength = Length; trackerState->CurrentDataReceived = 0; trackerState->CurrentDataFragments = 0; @@ -475,7 +449,7 @@ static PfChannelResult DynvcTrackerPeekFn(ChannelStateTracker* tracker, BOOL fir } WLog_DBG(TAG, "DynvcTracker(%s [%s]): %s frags=%" PRIu32 " received=%" PRIu32 "(%" PRIu32 ")", - dynChannel->channelName, get_packet_type(cmd), direction, + dynChannel->channelName, drdynvc_get_packet_type(cmd), direction, trackerState->CurrentDataFragments, trackerState->CurrentDataReceived, trackerState->currentDataLength); } @@ -489,7 +463,7 @@ static PfChannelResult DynvcTrackerPeekFn(ChannelStateTracker* tracker, BOOL fir WLog_ERR(TAG, "DynvcTracker (%s [%s]): reassembled packet (%" PRIu32 ") is bigger than announced length (%" PRIu32 ")", - dynChannel->channelName, get_packet_type(cmd), + dynChannel->channelName, drdynvc_get_packet_type(cmd), trackerState->CurrentDataReceived, trackerState->currentDataLength); return PF_CHANNEL_RESULT_ERROR; }