From 912cc4d0cf6aed26e9e9e4940d2bea67c8929042 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 2 Mar 2014 10:38:31 -0800 Subject: [PATCH] Maintain SVC list. --- src/protocols/rdp/client.c | 4 +++- src/protocols/rdp/client.h | 9 +++++++++ src/protocols/rdp/guac_handlers.c | 18 ++++++++++++++++++ src/protocols/rdp/rdp_svc.c | 17 +++++++++++------ src/protocols/rdp/rdp_svc.h | 10 ++-------- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/protocols/rdp/client.c b/src/protocols/rdp/client.c index 79f246a5..f1cbeed5 100644 --- a/src/protocols/rdp/client.c +++ b/src/protocols/rdp/client.c @@ -238,8 +238,9 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) { guac_rdp_free_svc(svc); } - /* Log success */ + /* Store and log on success */ else { + guac_rdp_add_svc(client, svc); guac_client_log_info(client, "Created static channel \"%s\"...", svc->name); } @@ -629,6 +630,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) { guac_client_data->clipboard = NULL; guac_client_data->audio = NULL; guac_client_data->filesystem = NULL; + guac_client_data->available_svc = guac_common_list_alloc(); /* Main socket needs to be threadsafe */ guac_socket_require_threadsafe(client->socket); diff --git a/src/protocols/rdp/client.h b/src/protocols/rdp/client.h index f658e678..f8fba3b1 100644 --- a/src/protocols/rdp/client.h +++ b/src/protocols/rdp/client.h @@ -26,6 +26,7 @@ #include "config.h" +#include "guac_list.h" #include "rdp_fs.h" #include "rdp_keymap.h" #include "rdp_settings.h" @@ -160,11 +161,19 @@ typedef struct rdp_guac_client_data { */ guac_rdp_fs* filesystem; + /** + * List of all available static virtual channels. + */ + guac_common_list* available_svc; + /** * Lock which is locked and unlocked for each RDP message. */ pthread_mutex_t rdp_lock; + /** + * Common attributes for locks. + */ pthread_mutexattr_t attributes; } rdp_guac_client_data; diff --git a/src/protocols/rdp/guac_handlers.c b/src/protocols/rdp/guac_handlers.c index a0d00e96..7e99d195 100644 --- a/src/protocols/rdp/guac_handlers.c +++ b/src/protocols/rdp/guac_handlers.c @@ -24,9 +24,11 @@ #include "client.h" #include "guac_handlers.h" +#include "guac_list.h" #include "rdp_cliprdr.h" #include "rdp_keymap.h" #include "rdp_rail.h" +#include "rdp_svc.h" #include #include @@ -66,6 +68,8 @@ int __guac_rdp_send_keysym(guac_client* client, int keysym, int pressed); int rdp_guac_client_free_handler(guac_client* client) { + guac_common_list_element* current; + rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data; @@ -84,6 +88,20 @@ int rdp_guac_client_free_handler(guac_client* client) { if (guac_client_data->filesystem != NULL) guac_rdp_fs_free(guac_client_data->filesystem); + /* Free any allocated SVCs */ + current = guac_client_data->available_svc->head; + while (current != NULL) { + + guac_common_list_element* next = current->next; + + guac_rdp_free_svc((guac_rdp_svc*) current->data); + guac_common_list_remove(guac_client_data->available_svc, current); + + current = next; + + } + guac_common_list_free(guac_client_data->available_svc); + /* Free client data */ cairo_surface_destroy(guac_client_data->opaque_glyph_surface); cairo_surface_destroy(guac_client_data->trans_glyph_surface); diff --git a/src/protocols/rdp/rdp_svc.c b/src/protocols/rdp/rdp_svc.c index 9580516d..9bd49f94 100644 --- a/src/protocols/rdp/rdp_svc.c +++ b/src/protocols/rdp/rdp_svc.c @@ -21,6 +21,8 @@ */ #include "config.h" +#include "client.h" +#include "guac_list.h" #include "rdp_svc.h" #include @@ -36,6 +38,7 @@ guac_rdp_svc* guac_rdp_alloc_svc(guac_client* client, char* name) { guac_rdp_svc* svc = malloc(sizeof(guac_rdp_svc)); + /* Init SVC */ svc->client = client; svc->name = strdup(name); svc->input_pipe = NULL; @@ -50,7 +53,14 @@ void guac_rdp_free_svc(guac_rdp_svc* svc) { } void guac_rdp_add_svc(guac_client* client, guac_rdp_svc* svc) { - /* STUB */ + + rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data; + + /* Add to list of available SVC */ + guac_common_list_lock(client_data->available_svc); + guac_common_list_add(client_data->available_svc, svc); + guac_common_list_unlock(client_data->available_svc); + } guac_rdp_svc* guac_rdp_get_svc(guac_client* client, char* name) { @@ -58,8 +68,3 @@ guac_rdp_svc* guac_rdp_get_svc(guac_client* client, char* name) { 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 index 8ce2a6f5..0059df07 100644 --- a/src/protocols/rdp/rdp_svc.h +++ b/src/protocols/rdp/rdp_svc.h @@ -65,8 +65,7 @@ typedef struct guac_rdp_svc { } 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. + * Allocate a new SVC with the given name. */ guac_rdp_svc* guac_rdp_alloc_svc(guac_client* client, char* name); @@ -76,7 +75,7 @@ guac_rdp_svc* guac_rdp_alloc_svc(guac_client* client, char* name); void guac_rdp_free_svc(guac_rdp_svc* svc); /** - * Add the given SVC to the list stored in the client. + * Add the given SVC to the list of all available SVCs. */ void guac_rdp_add_svc(guac_client* client, guac_rdp_svc* svc); @@ -85,10 +84,5 @@ void guac_rdp_add_svc(guac_client* client, guac_rdp_svc* svc); */ 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