From cc7cd78e5be2d80e2fff6ef1f6a8e121f6a765cb Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 8 Oct 2019 11:44:26 -0700 Subject: [PATCH] GUACAMOLE-249: Centralize handling of connected channels. --- src/protocols/rdp/channels.c | 18 +++++++++++++++++ src/protocols/rdp/channels.h | 14 +++++++++++++ src/protocols/rdp/rdp.c | 39 ------------------------------------ src/protocols/rdp/rdp_disp.c | 23 ++++++++++++++++++++- src/protocols/rdp/rdp_disp.h | 20 ++++++++++-------- 5 files changed, 66 insertions(+), 48 deletions(-) diff --git a/src/protocols/rdp/channels.c b/src/protocols/rdp/channels.c index 6719f49b..ac474304 100644 --- a/src/protocols/rdp/channels.c +++ b/src/protocols/rdp/channels.c @@ -18,9 +18,27 @@ */ #include "config.h" +#include "rdp.h" #include #include +#include + +void guac_rdp_channel_connected(rdpContext* context, + ChannelConnectedEventArgs* e) { + + guac_client* client = ((rdp_freerdp_context*) context)->client; + guac_rdp_client* rdp_client = (guac_rdp_client*) client->data; + + guac_client_log(client, GUAC_LOG_DEBUG, "Channel \"%s\" connected.", e->name); + + /* Display update channel */ + if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0) { + DispClientContext* disp = (DispClientContext*) e->pInterface; + guac_rdp_disp_connect(rdp_client->disp, context, disp); + } + +} int guac_freerdp_channels_load_plugin(rdpChannels* channels, rdpSettings* settings, const char* name, void* data) { diff --git a/src/protocols/rdp/channels.h b/src/protocols/rdp/channels.h index 1e7fb6b1..f8c7bcc6 100644 --- a/src/protocols/rdp/channels.h +++ b/src/protocols/rdp/channels.h @@ -25,6 +25,20 @@ #include #include +/** + * Called whenever a channel connects via the PubSub event system within + * FreeRDP. + * + * @param context + * The rdpContext associated with the active RDP session. + * + * @param e + * Event-specific arguments, mainly the name of the channel, and a + * reference to the associated plugin loaded for that channel by FreeRDP. + */ +void guac_rdp_channel_connected(rdpContext* context, + ChannelConnectedEventArgs* e); + /** * Loads the FreeRDP plugin having the given name. This function is a drop-in * replacement for freerdp_channels_load_plugin() which additionally loads diff --git a/src/protocols/rdp/rdp.c b/src/protocols/rdp/rdp.c index d62c05aa..ad490b8b 100644 --- a/src/protocols/rdp/rdp.c +++ b/src/protocols/rdp/rdp.c @@ -80,45 +80,6 @@ #include #include -/** - * Called whenever a channel connects via the PubSub event system within - * FreeRDP. - * - * @param context - * The rdpContext associated with the active RDP session. - * - * @param e - * Event-specific arguments, mainly the name of the channel, and a - * reference to the associated plugin loaded for that channel by FreeRDP. - */ -static void guac_rdp_channel_connected(rdpContext* context, - ChannelConnectedEventArgs* e) { - - guac_client* client = ((rdp_freerdp_context*) context)->client; - guac_rdp_client* rdp_client = (guac_rdp_client*) client->data; - guac_rdp_settings* settings = rdp_client->settings; - - if (settings->resize_method == GUAC_RESIZE_DISPLAY_UPDATE) { - /* Store reference to the display update plugin once it's connected */ - if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0) { - - DispClientContext* disp = (DispClientContext*) e->pInterface; - - /* Init module with current display size */ - guac_rdp_disp_set_size(rdp_client->disp, rdp_client->settings, - context->instance, guac_rdp_get_width(context->instance), - guac_rdp_get_height(context->instance)); - - /* Store connected channel */ - guac_rdp_disp_connect(rdp_client->disp, disp); - guac_client_log(client, GUAC_LOG_DEBUG, - "Display update channel connected."); - - } - } - -} - BOOL rdp_freerdp_pre_connect(freerdp* instance) { rdpContext* context = instance->context; diff --git a/src/protocols/rdp/rdp_disp.c b/src/protocols/rdp/rdp_disp.c index b26806e1..f152fa53 100644 --- a/src/protocols/rdp/rdp_disp.c +++ b/src/protocols/rdp/rdp_disp.c @@ -59,8 +59,29 @@ void guac_rdp_disp_load_plugin(rdpContext* context, guac_rdp_dvc_list* list) { } -void guac_rdp_disp_connect(guac_rdp_disp* guac_disp, DispClientContext* disp) { +void guac_rdp_disp_connect(guac_rdp_disp* guac_disp, rdpContext* context, + DispClientContext* disp) { + + guac_client* client = ((rdp_freerdp_context*) context)->client; + guac_rdp_client* rdp_client = (guac_rdp_client*) client->data; + guac_rdp_settings* settings = rdp_client->settings; + + /* Ignore connected channel if not configured to use the display update + * channel for resize */ + if (settings->resize_method != GUAC_RESIZE_DISPLAY_UPDATE) + return; + + /* Init module with current display size */ + guac_rdp_disp_set_size(rdp_client->disp, rdp_client->settings, + context->instance, guac_rdp_get_width(context->instance), + guac_rdp_get_height(context->instance)); + + /* Store reference to the display update plugin once it's connected */ guac_disp->disp = disp; + + guac_client_log(client, GUAC_LOG_DEBUG, "Display update channel " + "will be used for display size changes."); + } /** diff --git a/src/protocols/rdp/rdp_disp.h b/src/protocols/rdp/rdp_disp.h index 562ffb65..fa39b491 100644 --- a/src/protocols/rdp/rdp_disp.h +++ b/src/protocols/rdp/rdp_disp.h @@ -91,9 +91,6 @@ guac_rdp_disp* guac_rdp_disp_alloc(); */ void guac_rdp_disp_free(guac_rdp_disp* disp); -/** - * @param context The rdpContext associated with the active RDP session. - */ /** * Adds FreeRDP's "disp" plugin to the list of dynamic virtual channel plugins * to be loaded by FreeRDP's "drdynvc" plugin. The plugin will only be loaded @@ -117,12 +114,19 @@ void guac_rdp_disp_load_plugin(rdpContext* context, guac_rdp_dvc_list* list); * display updates can be properly sent. Until this is called, changes to the * display size will be deferred. * - * @param guac_disp The display update module to associate with the connected - * display update channel. - * @param disp The DispClientContext associated by FreeRDP with the connected - * display update channel. + * @param guac_disp + * The display update module to associate with the connected display update + * channel. + * + * @param context + * The rdpContext associated with the active RDP session. + * + * @param disp + * The DispClientContext associated by FreeRDP with the connected display + * update channel. */ -void guac_rdp_disp_connect(guac_rdp_disp* guac_disp, DispClientContext* disp); +void guac_rdp_disp_connect(guac_rdp_disp* guac_disp, rdpContext* context, + DispClientContext* disp); /** * Requests a display size update, which may then be sent immediately to the