From cc5793a39b2a6af89f1bc0ccc7f17c33c4fb29bf Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 2 Mar 2014 09:56:47 -0800 Subject: [PATCH] Move SVC data into own structure. Add stubs for management. --- src/protocols/rdp/Makefile.am | 2 + src/protocols/rdp/guac_svc/svc_service.c | 48 ++++++------ src/protocols/rdp/guac_svc/svc_service.h | 21 +----- src/protocols/rdp/rdp_svc.c | 57 ++++++++++++++ src/protocols/rdp/rdp_svc.h | 94 ++++++++++++++++++++++++ 5 files changed, 182 insertions(+), 40 deletions(-) create mode 100644 src/protocols/rdp/rdp_svc.c create mode 100644 src/protocols/rdp/rdp_svc.h diff --git a/src/protocols/rdp/Makefile.am b/src/protocols/rdp/Makefile.am index 95c75cc2..192fede2 100644 --- a/src/protocols/rdp/Makefile.am +++ b/src/protocols/rdp/Makefile.am @@ -40,6 +40,7 @@ libguac_client_rdp_la_SOURCES = \ rdp_pointer.c \ rdp_rail.c \ rdp_settings.c \ + rdp_svc.c \ unicode.c guacsvc_sources = \ @@ -88,6 +89,7 @@ noinst_HEADERS = \ rdp_rail.h \ rdp_settings.h \ rdp_status.h \ + rdp_svc.h \ unicode.h # Add compatibility layer for WinPR if not available diff --git a/src/protocols/rdp/guac_svc/svc_service.c b/src/protocols/rdp/guac_svc/svc_service.c index 55b6c240..ae3c6e55 100644 --- a/src/protocols/rdp/guac_svc/svc_service.c +++ b/src/protocols/rdp/guac_svc/svc_service.c @@ -46,25 +46,35 @@ */ int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) { + /* Gain access to plugin data */ + CHANNEL_ENTRY_POINTS_EX* entry_points_ex = + (CHANNEL_ENTRY_POINTS_EX*) pEntryPoints; + /* Allocate plugin */ - guac_svcPlugin* svc = + guac_svcPlugin* svc_plugin = (guac_svcPlugin*) calloc(1, sizeof(guac_svcPlugin)); + /* Get SVC descriptor from plugin parameters */ + guac_rdp_svc* svc = (guac_rdp_svc*) entry_points_ex->pExtendedData; + /* Init channel def */ - strcpy(svc->plugin.channel_def.name, "FIXME"); - svc->plugin.channel_def.options = + strcpy(svc_plugin->plugin.channel_def.name, svc->name); + svc_plugin->plugin.channel_def.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP | CHANNEL_OPTION_COMPRESS_RDP; + /* Init plugin */ + svc_plugin->svc = svc; + /* Set callbacks */ - svc->plugin.connect_callback = guac_svc_process_connect; - svc->plugin.receive_callback = guac_svc_process_receive; - svc->plugin.event_callback = guac_svc_process_event; - svc->plugin.terminate_callback = guac_svc_process_terminate; + svc_plugin->plugin.connect_callback = guac_svc_process_connect; + svc_plugin->plugin.receive_callback = guac_svc_process_receive; + svc_plugin->plugin.event_callback = guac_svc_process_event; + svc_plugin->plugin.terminate_callback = guac_svc_process_terminate; /* Finish init */ - svc_plugin_init((rdpSvcPlugin*) svc, pEntryPoints); + svc_plugin_init((rdpSvcPlugin*) svc_plugin, pEntryPoints); return 1; } @@ -75,25 +85,17 @@ int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) { void guac_svc_process_connect(rdpSvcPlugin* plugin) { - /* Get SVC plugin */ - guac_svcPlugin* svc = (guac_svcPlugin*) plugin; + /* Get corresponding guac_rdp_svc */ + guac_svcPlugin* svc_plugin = (guac_svcPlugin*) plugin; + guac_rdp_svc* svc = svc_plugin->svc; - /* Get client from plugin parameters */ - guac_client* client = (guac_client*) - plugin->channel_entry_points.pExtendedData; - - /* NULL out pExtendedData so we don't lose our guac_client due to an + /* NULL out pExtendedData so we don't lose our guac_rdp_svc due to an * automatic free() within libfreerdp */ plugin->channel_entry_points.pExtendedData = NULL; - /* Get data from client */ - /*rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;*/ - - /* Init plugin */ - svc->client = client; - - /* Log that printing, etc. has been loaded */ - guac_client_log_info(client, "guacsvc connected."); + /* Log connection to static channel */ + guac_client_log_info(svc->client, + "Static channel \"%s\" connected.", svc->name); } diff --git a/src/protocols/rdp/guac_svc/svc_service.h b/src/protocols/rdp/guac_svc/svc_service.h index fe0e2165..a35cd058 100644 --- a/src/protocols/rdp/guac_svc/svc_service.h +++ b/src/protocols/rdp/guac_svc/svc_service.h @@ -24,6 +24,7 @@ #define __GUAC_SVC_SERVICE_H #include "config.h" +#include "rdp_svc.h" #include @@ -50,24 +51,10 @@ typedef struct guac_svcPlugin { rdpSvcPlugin plugin; /** - * Reference to the client owning this instance. + * The Guacamole-specific SVC structure describing the channel this + * instance represents. */ - guac_client* client; - - /** - * The name of the RDP channel in use, and the name to use for each pipe. - */ - char* name; - - /** - * The pipe opened by the Guacamole client. - */ - guac_stream* input_pipe; - - /** - * The output pipe, opened in response to the open input pipe. - */ - guac_stream* output_pipe; + guac_rdp_svc* svc; } guac_svcPlugin; diff --git a/src/protocols/rdp/rdp_svc.c b/src/protocols/rdp/rdp_svc.c new file mode 100644 index 00000000..91fbab2d --- /dev/null +++ b/src/protocols/rdp/rdp_svc.c @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2013 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "config.h" +#include "rdp_svc.h" + +#include +#include + +#ifdef ENABLE_WINPR +#include +#else +#include "compat/winpr-stream.h" +#endif + +guac_rdp_svc* guac_rdp_alloc_svc(guac_client* client, char* name) { + /* STUB */ + return NULL; +} + +void guac_rdp_free_svc(guac_rdp_svc* svc) { + /* STUB */ +} + +void guac_rdp_add_svc(guac_client* client, guac_rdp_svc* svc) { + /* STUB */ +} + +guac_rdp_svc* guac_rdp_get_svc(guac_client* client, char* name) { + /* STUB */ + return NULL; +} + +guac_rdp_svc* guac_rdp_remove_svc(guac_client* client, char* name) { + /* STUB */ + return NULL; +} + diff --git a/src/protocols/rdp/rdp_svc.h b/src/protocols/rdp/rdp_svc.h new file mode 100644 index 00000000..8ce2a6f5 --- /dev/null +++ b/src/protocols/rdp/rdp_svc.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2013 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __GUAC_RDP_RDP_SVC_H +#define __GUAC_RDP_RDP_SVC_H + +#include "config.h" + +#include +#include + +#ifdef ENABLE_WINPR +#include +#else +#include "compat/winpr-stream.h" +#endif + +/** + * Structure describing a static virtual channel, and the corresponding + * Guacamole pipes. + */ +typedef struct guac_rdp_svc { + + /** + * Reference to the client owning this static channel. + */ + guac_client* client; + + /** + * The name of the RDP channel in use, and the name to use for each pipe. + */ + char* name; + + /** + * The pipe opened by the Guacamole client, if any. This should be + * opened in response to the output pipe. + */ + guac_stream* input_pipe; + + /** + * The output pipe, opened when the RDP server receives a connection to + * the static channel. + */ + guac_stream* output_pipe; + +} guac_rdp_svc; + +/** + * Allocate a new SVC with the given name. Not that this will NOT add the + * SVC to the list stored in the client. + */ +guac_rdp_svc* guac_rdp_alloc_svc(guac_client* client, char* name); + +/** + * Free the given SVC. + */ +void guac_rdp_free_svc(guac_rdp_svc* svc); + +/** + * Add the given SVC to the list stored in the client. + */ +void guac_rdp_add_svc(guac_client* client, guac_rdp_svc* svc); + +/** + * Retrieve the SVC with the given name from the list stored in the client. + */ +guac_rdp_svc* guac_rdp_get_svc(guac_client* client, char* name); + +/** + * Remove the SVC with the given name from the list stored in the client. + */ +guac_rdp_svc* guac_rdp_remove_svc(guac_client* client, char* name); + +#endif +