From 5b163b7918dbc05e0e428ac959d91db45c7e20f3 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Wed, 22 Jun 2022 12:54:58 +0200 Subject: [PATCH] Add GetRdpContext function pointer for dynamic channels --- channels/audin/client/audin_main.c | 3 +-- channels/drdynvc/client/drdynvc_main.c | 27 ++++++++++++++++++------ channels/drdynvc/client/drdynvc_main.h | 2 +- channels/rdpei/client/rdpei_main.c | 4 +--- channels/rdpgfx/client/rdpgfx_main.c | 3 +-- channels/sshagent/client/sshagent_main.c | 4 +--- channels/tsmf/client/tsmf_main.c | 4 +--- include/freerdp/dvc.h | 6 +++++- 8 files changed, 32 insertions(+), 21 deletions(-) diff --git a/channels/audin/client/audin_main.c b/channels/audin/client/audin_main.c index 90cf9052f..fecd4b805 100644 --- a/channels/audin/client/audin_main.c +++ b/channels/audin/client/audin_main.c @@ -1026,8 +1026,7 @@ UINT audin_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) audin->iface.Attached = audin_plugin_attached; audin->iface.Detached = audin_plugin_detached; args = pEntryPoints->GetPluginData(pEntryPoints); - audin->rdpcontext = - ((freerdp*)((rdpSettings*)pEntryPoints->GetRdpSettings(pEntryPoints))->instance)->context; + audin->rdpcontext = pEntryPoints->GetRdpContext(pEntryPoints); if (args) { diff --git a/channels/drdynvc/client/drdynvc_main.c b/channels/drdynvc/client/drdynvc_main.c index 26d0d8b07..ae960b2ac 100644 --- a/channels/drdynvc/client/drdynvc_main.c +++ b/channels/drdynvc/client/drdynvc_main.c @@ -172,9 +172,19 @@ static const ADDIN_ARGV* dvcman_get_plugin_data(IDRDYNVC_ENTRY_POINTS* pEntryPoi return ((DVCMAN_ENTRY_POINTS*)pEntryPoints)->args; } -static void* dvcman_get_rdp_settings(IDRDYNVC_ENTRY_POINTS* pEntryPoints) +static rdpContext* dvcman_get_rdp_context(IDRDYNVC_ENTRY_POINTS* pEntryPoints) { - return (void*)((DVCMAN_ENTRY_POINTS*)pEntryPoints)->settings; + DVCMAN_ENTRY_POINTS* entry = (DVCMAN_ENTRY_POINTS*)pEntryPoints; + WINPR_ASSERT(entry); + return entry->context; +} + +static rdpSettings* dvcman_get_rdp_settings(IDRDYNVC_ENTRY_POINTS* pEntryPoints) +{ + rdpContext* context = dvcman_get_rdp_context(pEntryPoints); + WINPR_ASSERT(context); + + return context->settings; } static UINT32 dvcman_get_channel_id(IWTSVirtualChannel* channel) @@ -280,23 +290,28 @@ fail: * @return 0 on success, otherwise a Win32 error code */ static UINT dvcman_load_addin(drdynvcPlugin* drdynvc, IWTSVirtualChannelManager* pChannelMgr, - const ADDIN_ARGV* args, rdpSettings* settings) + const ADDIN_ARGV* args, rdpContext* context) { - DVCMAN_ENTRY_POINTS entryPoints; PDVC_PLUGIN_ENTRY pDVCPluginEntry = NULL; + WINPR_ASSERT(drdynvc); + WINPR_ASSERT(pChannelMgr); + WINPR_ASSERT(args); + WINPR_ASSERT(context); WLog_Print(drdynvc->log, WLOG_INFO, "Loading Dynamic Virtual Channel %s", args->argv[0]); pDVCPluginEntry = (PDVC_PLUGIN_ENTRY)freerdp_load_channel_addin_entry( args->argv[0], NULL, NULL, FREERDP_ADDIN_CHANNEL_DYNAMIC); if (pDVCPluginEntry) { + DVCMAN_ENTRY_POINTS entryPoints = { 0 }; entryPoints.iface.RegisterPlugin = dvcman_register_plugin; entryPoints.iface.GetPlugin = dvcman_get_plugin; entryPoints.iface.GetPluginData = dvcman_get_plugin_data; entryPoints.iface.GetRdpSettings = dvcman_get_rdp_settings; + entryPoints.iface.GetRdpContext = dvcman_get_rdp_context; entryPoints.dvcman = (DVCMAN*)pChannelMgr; entryPoints.args = args; - entryPoints.settings = settings; + entryPoints.context = context; return pDVCPluginEntry(&entryPoints.iface); } @@ -1520,7 +1535,7 @@ static UINT drdynvc_virtual_channel_event_connected(drdynvcPlugin* drdynvc, LPVO index++) { const ADDIN_ARGV* args = settings->DynamicChannelArray[index]; - error = dvcman_load_addin(drdynvc, drdynvc->channel_mgr, args, settings); + error = dvcman_load_addin(drdynvc, drdynvc->channel_mgr, args, drdynvc->rdpcontext); if (CHANNEL_RC_OK != error) goto error; diff --git a/channels/drdynvc/client/drdynvc_main.h b/channels/drdynvc/client/drdynvc_main.h index 7f8d2c3f4..89d3f3c63 100644 --- a/channels/drdynvc/client/drdynvc_main.h +++ b/channels/drdynvc/client/drdynvc_main.h @@ -67,7 +67,7 @@ typedef struct DVCMAN* dvcman; const ADDIN_ARGV* args; - rdpSettings* settings; + rdpContext* context; } DVCMAN_ENTRY_POINTS; typedef struct diff --git a/channels/rdpei/client/rdpei_main.c b/channels/rdpei/client/rdpei_main.c index 5fa362d96..495628ece 100644 --- a/channels/rdpei/client/rdpei_main.c +++ b/channels/rdpei/client/rdpei_main.c @@ -1467,9 +1467,7 @@ UINT rdpei_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) rdpei->previousFrameTime = 0; rdpei->maxTouchContacts = MAX_CONTACTS; rdpei->maxPenContacts = MAX_PEN_CONTACTS; - rdpei->rdpcontext = - ((freerdp*)((rdpSettings*)pEntryPoints->GetRdpSettings(pEntryPoints))->instance) - ->context; + rdpei->rdpcontext = pEntryPoints->GetRdpContext(pEntryPoints); context = (RdpeiClientContext*)calloc(1, sizeof(RdpeiClientContext)); diff --git a/channels/rdpgfx/client/rdpgfx_main.c b/channels/rdpgfx/client/rdpgfx_main.c index a07a84c85..65995dcec 100644 --- a/channels/rdpgfx/client/rdpgfx_main.c +++ b/channels/rdpgfx/client/rdpgfx_main.c @@ -2399,8 +2399,7 @@ UINT rdpgfx_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) if (!gfx) { - context = - rdpgfx_client_context_new((rdpSettings*)pEntryPoints->GetRdpSettings(pEntryPoints)); + context = rdpgfx_client_context_new(pEntryPoints->GetRdpSettings(pEntryPoints)); if (!context) { diff --git a/channels/sshagent/client/sshagent_main.c b/channels/sshagent/client/sshagent_main.c index c7c999c8e..12559990f 100644 --- a/channels/sshagent/client/sshagent_main.c +++ b/channels/sshagent/client/sshagent_main.c @@ -365,9 +365,7 @@ UINT sshagent_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) sshagent->iface.Connected = NULL; sshagent->iface.Disconnected = NULL; sshagent->iface.Terminated = sshagent_plugin_terminated; - sshagent->rdpcontext = - ((freerdp*)((rdpSettings*)pEntryPoints->GetRdpSettings(pEntryPoints))->instance) - ->context; + sshagent->rdpcontext = pEntryPoints->GetRdpContext(pEntryPoints); status = pEntryPoints->RegisterPlugin(pEntryPoints, "sshagent", &sshagent->iface); } diff --git a/channels/tsmf/client/tsmf_main.c b/channels/tsmf/client/tsmf_main.c index 27677d4a1..be8a827d4 100644 --- a/channels/tsmf/client/tsmf_main.c +++ b/channels/tsmf/client/tsmf_main.c @@ -575,9 +575,7 @@ UINT tsmf_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) tsmf->iface.Connected = NULL; tsmf->iface.Disconnected = NULL; tsmf->iface.Terminated = tsmf_plugin_terminated; - tsmf->rdpcontext = - ((freerdp*)((rdpSettings*)pEntryPoints->GetRdpSettings(pEntryPoints))->instance) - ->context; + tsmf->rdpcontext = pEntryPoints->GetRdpContext(pEntryPoints); context = (TsmfClientContext*)calloc(1, sizeof(TsmfClientContext)); if (!context) diff --git a/include/freerdp/dvc.h b/include/freerdp/dvc.h index d38caf3bd..7d38b74b4 100644 --- a/include/freerdp/dvc.h +++ b/include/freerdp/dvc.h @@ -139,6 +139,9 @@ struct s_IWTSVirtualChannelCallback }; /* The DVC Plugin entry points */ +typedef struct rdp_context rdpContext; /* forward declaration, necessary to avoid + * circular includes */ + typedef struct S_IDRDYNVC_ENTRY_POINTS IDRDYNVC_ENTRY_POINTS; struct S_IDRDYNVC_ENTRY_POINTS { @@ -146,7 +149,8 @@ struct S_IDRDYNVC_ENTRY_POINTS (IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* name, IWTSPlugin* pPlugin); IWTSPlugin* (*GetPlugin)(IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* name); const ADDIN_ARGV* (*GetPluginData)(IDRDYNVC_ENTRY_POINTS* pEntryPoints); - void* (*GetRdpSettings)(IDRDYNVC_ENTRY_POINTS* pEntryPoints); + rdpSettings* (*GetRdpSettings)(IDRDYNVC_ENTRY_POINTS* pEntryPoints); + rdpContext* (*GetRdpContext)(IDRDYNVC_ENTRY_POINTS* pEntryPoints); }; typedef UINT (*PDVC_PLUGIN_ENTRY)(IDRDYNVC_ENTRY_POINTS*);