21 #include "remdesk_common.h"
23 #include <freerdp/channels/log.h>
24 #define TAG CHANNELS_TAG("remdesk.common")
28 WCHAR ChannelNameW[32] = { 0 };
33 for (
size_t index = 0; index < 32; index++)
35 ChannelNameW[index] = (WCHAR)header->ChannelName[index];
38 const size_t ChannelNameLen =
39 (strnlen(header->ChannelName,
sizeof(header->ChannelName)) + 1) * 2;
40 WINPR_ASSERT(ChannelNameLen <= ARRAYSIZE(header->ChannelName));
42 Stream_Write_UINT32(s, (UINT32)ChannelNameLen);
43 Stream_Write_UINT32(s, header->DataLength);
44 Stream_Write(s, ChannelNameW, ChannelNameLen);
50 WINPR_ASSERT(ctlHeader);
51 const UINT error = remdesk_write_channel_header(s, &ctlHeader->ch);
55 WLog_ERR(TAG,
"remdesk_write_channel_header failed with error %" PRIu32
"!", error);
59 Stream_Write_UINT32(s, ctlHeader->msgType);
65 UINT32 ChannelNameLen = 0;
67 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
68 return CHANNEL_RC_NO_MEMORY;
70 Stream_Read_UINT32(s, ChannelNameLen);
71 Stream_Read_UINT32(s, header->DataLength);
73 if (ChannelNameLen > 64)
75 WLog_ERR(TAG,
"ChannelNameLen > 64!");
76 return ERROR_INVALID_DATA;
79 if ((ChannelNameLen % 2) != 0)
81 WLog_ERR(TAG,
"(ChannelNameLen %% 2) != 0!");
82 return ERROR_INVALID_DATA;
85 if (Stream_Read_UTF16_String_As_UTF8_Buffer(s, ChannelNameLen /
sizeof(WCHAR),
87 ARRAYSIZE(header->ChannelName)) < 0)
88 return ERROR_INVALID_DATA;
93 UINT remdesk_prepare_ctl_header(
REMDESK_CTL_HEADER* ctlHeader, UINT32 msgType,
size_t msgSize)
95 WINPR_ASSERT(ctlHeader);
97 if (msgSize > UINT32_MAX - 4)
98 return ERROR_INVALID_PARAMETER;
100 ctlHeader->msgType = msgType;
101 (void)sprintf_s(ctlHeader->ch.ChannelName, ARRAYSIZE(ctlHeader->ch.ChannelName),
102 REMDESK_CHANNEL_CTL_NAME);
103 ctlHeader->ch.DataLength = (UINT32)(4UL + msgSize);
104 return CHANNEL_RC_OK;