From 9d627e0df232f7307e17d7287c062770a208a50f Mon Sep 17 00:00:00 2001 From: Pascal Nowack Date: Wed, 8 Jun 2022 13:35:52 +0200 Subject: [PATCH] channels/server: Add APIs for DVCs to get notified of channel id This allows server implementations to watch these channel ids for their creation statuses. --- channels/ainput/server/ainput_main.c | 14 ++++++++++++++ channels/audin/server/audin.c | 13 ++++++++++++- channels/disp/server/disp_main.c | 12 ++++++++++++ channels/echo/server/echo_main.c | 14 ++++++++++++++ channels/rdpei/server/rdpei_main.c | 11 +++++++++++ channels/rdpgfx/server/rdpgfx_main.c | 11 +++++++++++ include/freerdp/server/ainput.h | 7 +++++++ include/freerdp/server/audin.h | 7 +++++++ include/freerdp/server/disp.h | 7 +++++++ include/freerdp/server/echo.h | 7 +++++++ include/freerdp/server/rdpei.h | 5 +++++ include/freerdp/server/rdpgfx.h | 7 +++++++ 12 files changed, 114 insertions(+), 1 deletion(-) diff --git a/channels/ainput/server/ainput_main.c b/channels/ainput/server/ainput_main.c index 6aaf87fe1..7a2311a18 100644 --- a/channels/ainput/server/ainput_main.c +++ b/channels/ainput/server/ainput_main.c @@ -120,7 +120,21 @@ static UINT ainput_server_open_channel(ainput_server* ainput) WTS_CHANNEL_OPTION_DYNAMIC); if (ainput->ainput_channel) + { + UINT32 channelId; + BOOL status = TRUE; + + channelId = WTSChannelGetIdByHandle(ainput->ainput_channel); + + IFCALLRET(ainput->context.ChannelIdAssigned, status, &ainput->context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->ChannelIdAssigned failed!"); + return ERROR_INTERNAL_ERROR; + } + break; + } Error = GetLastError(); diff --git a/channels/audin/server/audin.c b/channels/audin/server/audin.c index e9f56012d..fc14d6094 100644 --- a/channels/audin/server/audin.c +++ b/channels/audin/server/audin.c @@ -262,7 +262,7 @@ static UINT audin_server_send_open(audin_server* audin, wStream* s) audin->opened = TRUE; Stream_SetPosition(s, 0); Stream_Write_UINT8(s, MSG_SNDIN_OPEN); - Stream_Write_UINT32(s, audin->context.frames_per_packet); /* FramesPerPacket (4 bytes) */ + Stream_Write_UINT32(s, audin->context.frames_per_packet); /* FramesPerPacket (4 bytes) */ WINPR_ASSERT(audin->context.selected_client_format >= 0); WINPR_ASSERT(audin->context.selected_client_format <= UINT32_MAX); Stream_Write_UINT32( @@ -578,6 +578,8 @@ static BOOL audin_server_open(audin_server_context* context) PULONG pSessionId = NULL; DWORD BytesReturned = 0; audin->SessionId = WTS_CURRENT_SESSION; + UINT32 channelId; + BOOL status = TRUE; if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId, (LPSTR*)&pSessionId, &BytesReturned)) @@ -595,6 +597,15 @@ static BOOL audin_server_open(audin_server_context* context) return FALSE; } + channelId = WTSChannelGetIdByHandle(audin->audin_channel); + + IFCALLRET(context->ChannelIdAssigned, status, context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->ChannelIdAssigned failed!"); + return ERROR_INTERNAL_ERROR; + } + if (!(audin->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) { WLog_ERR(TAG, "CreateEvent failed!"); diff --git a/channels/disp/server/disp_main.c b/channels/disp/server/disp_main.c index 5232df640..adbb6f046 100644 --- a/channels/disp/server/disp_main.c +++ b/channels/disp/server/disp_main.c @@ -392,6 +392,8 @@ static UINT disp_server_open(DispServerContext* context) DWORD BytesReturned = 0; PULONG pSessionId = NULL; void* buffer = NULL; + UINT32 channelId; + BOOL status = TRUE; WINPR_ASSERT(context); @@ -420,6 +422,16 @@ static UINT disp_server_open(DispServerContext* context) goto out_close; } + channelId = WTSChannelGetIdByHandle(priv->disp_channel); + + IFCALLRET(context->ChannelIdAssigned, status, context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->ChannelIdAssigned failed!"); + rc = ERROR_INTERNAL_ERROR; + goto out_close; + } + /* Query for channel event handle */ if (!WTSVirtualChannelQuery(priv->disp_channel, WTSVirtualEventHandle, &buffer, &BytesReturned) || diff --git a/channels/echo/server/echo_main.c b/channels/echo/server/echo_main.c index d2021e499..cd389ff8e 100644 --- a/channels/echo/server/echo_main.c +++ b/channels/echo/server/echo_main.c @@ -91,7 +91,21 @@ static UINT echo_server_open_channel(echo_server* echo) WTS_CHANNEL_OPTION_DYNAMIC); if (echo->echo_channel) + { + UINT32 channelId; + BOOL status = TRUE; + + channelId = WTSChannelGetIdByHandle(echo->echo_channel); + + IFCALLRET(echo->context.ChannelIdAssigned, status, &echo->context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->ChannelIdAssigned failed!"); + return ERROR_INTERNAL_ERROR; + } + break; + } Error = GetLastError(); diff --git a/channels/rdpei/server/rdpei_main.c b/channels/rdpei/server/rdpei_main.c index 5048d2c70..d6ebcb522 100644 --- a/channels/rdpei/server/rdpei_main.c +++ b/channels/rdpei/server/rdpei_main.c @@ -96,6 +96,8 @@ UINT rdpei_server_init(RdpeiServerContext* context) void* buffer = NULL; DWORD bytesReturned; RdpeiServerPrivate* priv = context->priv; + UINT32 channelId; + BOOL status = TRUE; priv->channelHandle = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, RDPEI_DVC_CHANNEL_NAME, WTS_CHANNEL_OPTION_DYNAMIC); @@ -105,6 +107,15 @@ UINT rdpei_server_init(RdpeiServerContext* context) return CHANNEL_RC_INITIALIZATION_ERROR; } + channelId = WTSChannelGetIdByHandle(priv->channelHandle); + + IFCALLRET(context->onChannelIdAssigned, status, context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->onChannelIdAssigned failed!"); + goto out_close; + } + if (!WTSVirtualChannelQuery(priv->channelHandle, WTSVirtualEventHandle, &buffer, &bytesReturned) || (bytesReturned != sizeof(HANDLE))) diff --git a/channels/rdpgfx/server/rdpgfx_main.c b/channels/rdpgfx/server/rdpgfx_main.c index 6e0d49108..b07f82ae3 100644 --- a/channels/rdpgfx/server/rdpgfx_main.c +++ b/channels/rdpgfx/server/rdpgfx_main.c @@ -1423,6 +1423,8 @@ static BOOL rdpgfx_server_open(RdpgfxServerContext* context) PULONG pSessionId = NULL; DWORD BytesReturned = 0; priv->SessionId = WTS_CURRENT_SESSION; + UINT32 channelId; + BOOL status = TRUE; if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId, (LPSTR*)&pSessionId, &BytesReturned) == FALSE) @@ -1442,6 +1444,15 @@ static BOOL rdpgfx_server_open(RdpgfxServerContext* context) return FALSE; } + channelId = WTSChannelGetIdByHandle(priv->rdpgfx_channel); + + IFCALLRET(context->ChannelIdAssigned, status, context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->ChannelIdAssigned failed!"); + goto out_close; + } + /* Query for channel event handle */ if (!WTSVirtualChannelQuery(priv->rdpgfx_channel, WTSVirtualEventHandle, &buffer, &BytesReturned) || diff --git a/include/freerdp/server/ainput.h b/include/freerdp/server/ainput.h index 799c6ae8e..200de567a 100644 --- a/include/freerdp/server/ainput.h +++ b/include/freerdp/server/ainput.h @@ -34,6 +34,8 @@ typedef enum AINPUT_SERVER_OPEN_RESULT typedef struct _ainput_server_context ainput_server_context; +typedef BOOL (*psAInputChannelIdAssigned)(ainput_server_context* context, UINT32 channelId); + typedef UINT (*psAInputServerInitialize)(ainput_server_context* context, BOOL externalThread); typedef UINT (*psAInputServerPoll)(ainput_server_context* context); typedef BOOL (*psAInputServerChannelHandle)(ainput_server_context* context, HANDLE* handle); @@ -98,6 +100,11 @@ struct _ainput_server_context psAInputServerMouseEvent MouseEvent; rdpContext* rdpcontext; + + /** + * Callback, when the channel got its id assigned. + */ + psAInputChannelIdAssigned ChannelIdAssigned; }; #ifdef __cplusplus diff --git a/include/freerdp/server/audin.h b/include/freerdp/server/audin.h index 6522ec070..acae2c8a4 100644 --- a/include/freerdp/server/audin.h +++ b/include/freerdp/server/audin.h @@ -28,6 +28,8 @@ typedef struct s_audin_server_context audin_server_context; +typedef BOOL (*psAudinServerChannelIdAssigned)(audin_server_context* context, UINT32 channelId); + typedef UINT (*psAudinServerSelectFormat)(audin_server_context* context, size_t client_format_index); typedef BOOL (*psAudinServerOpen)(audin_server_context* context); @@ -99,6 +101,11 @@ struct s_audin_server_context psAudinServerReceiveSamples ReceiveSamples; rdpContext* rdpcontext; + + /** + * Callback, when the channel got its id assigned. + */ + psAudinServerChannelIdAssigned ChannelIdAssigned; }; #ifdef __cplusplus diff --git a/include/freerdp/server/disp.h b/include/freerdp/server/disp.h index 4af429630..37e8fdeb7 100644 --- a/include/freerdp/server/disp.h +++ b/include/freerdp/server/disp.h @@ -29,6 +29,8 @@ typedef struct s_disp_server_private DispServerPrivate; typedef struct s_disp_server_context DispServerContext; +typedef BOOL (*psDispChannelIdAssigned)(DispServerContext* context, UINT32 channelId); + typedef UINT (*psDispMonitorLayout)(DispServerContext* context, const DISPLAY_CONTROL_MONITOR_LAYOUT_PDU* pdu); typedef UINT (*psDispCaps)(DispServerContext* context); @@ -53,6 +55,11 @@ struct s_disp_server_context DispServerPrivate* priv; rdpContext* rdpcontext; + + /** + * Callback, when the channel got its id assigned. + */ + psDispChannelIdAssigned ChannelIdAssigned; }; #ifdef __cplusplus diff --git a/include/freerdp/server/echo.h b/include/freerdp/server/echo.h index c11637165..776fbfd19 100644 --- a/include/freerdp/server/echo.h +++ b/include/freerdp/server/echo.h @@ -34,6 +34,8 @@ typedef enum ECHO_SERVER_OPEN_RESULT typedef struct s_echo_server_context echo_server_context; +typedef BOOL (*psEchoServerChannelIdAssigned)(echo_server_context* context, UINT32 channelId); + typedef UINT (*psEchoServerOpen)(echo_server_context* context); typedef UINT (*psEchoServerClose)(echo_server_context* context); typedef BOOL (*psEchoServerRequest)(echo_server_context* context, const BYTE* buffer, @@ -76,6 +78,11 @@ struct s_echo_server_context psEchoServerResponse Response; rdpContext* rdpcontext; + + /** + * Callback, when the channel got its id assigned. + */ + psEchoServerChannelIdAssigned ChannelIdAssigned; }; #ifdef __cplusplus diff --git a/include/freerdp/server/rdpei.h b/include/freerdp/server/rdpei.h index bb8b22272..63aa709d6 100644 --- a/include/freerdp/server/rdpei.h +++ b/include/freerdp/server/rdpei.h @@ -46,6 +46,11 @@ struct s_rdpei_server_context UINT (*onTouchReleased)(RdpeiServerContext* context, BYTE contactId); void* user_data; /* user data, useful for callbacks */ + + /** + * Callback, when the channel got its id assigned. + */ + BOOL (*onChannelIdAssigned)(RdpeiServerContext* context, UINT32 channelId); }; #ifdef __cplusplus diff --git a/include/freerdp/server/rdpgfx.h b/include/freerdp/server/rdpgfx.h index 756ac18d5..f0fc11762 100644 --- a/include/freerdp/server/rdpgfx.h +++ b/include/freerdp/server/rdpgfx.h @@ -29,6 +29,8 @@ typedef struct s_rdpgfx_server_private RdpgfxServerPrivate; typedef BOOL (*psRdpgfxServerOpen)(RdpgfxServerContext* context); typedef BOOL (*psRdpgfxServerClose)(RdpgfxServerContext* context); +typedef BOOL (*psRdpgfxServerChannelIdAssigned)(RdpgfxServerContext* context, UINT32 channelId); + typedef UINT (*psRdpgfxResetGraphics)(RdpgfxServerContext* context, const RDPGFX_RESET_GRAPHICS_PDU* resetGraphics); typedef UINT (*psRdpgfxStartFrame)(RdpgfxServerContext* context, @@ -112,6 +114,11 @@ struct s_rdpgfx_server_context RdpgfxServerPrivate* priv; rdpContext* rdpcontext; + + /** + * Callback, when the channel got its id assigned. + */ + psRdpgfxServerChannelIdAssigned ChannelIdAssigned; }; #ifdef __cplusplus