From cb7ae25177cdfab3b45c9246c8425872ad820c49 Mon Sep 17 00:00:00 2001 From: Virtually Nick Date: Sat, 25 Dec 2021 19:14:51 -0500 Subject: [PATCH] GUACAMOLE-1293: Add support for the name handshake instruction. --- src/libguac/guacamole/protocol-types.h | 3 ++- src/libguac/guacamole/user.h | 6 ++++++ src/libguac/user-handlers.c | 16 ++++++++++++++++ src/libguac/user-handlers.h | 7 +++++++ src/libguac/user-handshake.c | 4 +++- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/libguac/guacamole/protocol-types.h b/src/libguac/guacamole/protocol-types.h index 1cb1de25..074ab97f 100644 --- a/src/libguac/guacamole/protocol-types.h +++ b/src/libguac/guacamole/protocol-types.h @@ -310,7 +310,8 @@ typedef enum guac_protocol_version { /** * Protocol version 1.5.0, which supports the "msg" instruction, allowing - * messages to be sent to the client. + * messages to be sent to the client, and adds support for the "name" + * handshake instruction. */ GUAC_PROTOCOL_VERSION_1_5_0 = 0x010500 diff --git a/src/libguac/guacamole/user.h b/src/libguac/guacamole/user.h index 8f6a2721..06db8fd6 100644 --- a/src/libguac/guacamole/user.h +++ b/src/libguac/guacamole/user.h @@ -89,6 +89,12 @@ struct guac_user_info { */ int optimal_resolution; + /** + * The human-readable name of the Guacamole user. If the client does not + * provide a name then this will be NULL. + */ + const char* name; + /** * The timezone of the remote system. If the client does not provide * a specific timezone then this will be NULL. The format of the timezone diff --git a/src/libguac/user-handlers.c b/src/libguac/user-handlers.c index c5cad9df..0c084457 100644 --- a/src/libguac/user-handlers.c +++ b/src/libguac/user-handlers.c @@ -64,6 +64,7 @@ __guac_instruction_handler_mapping __guac_handshake_handler_map[] = { {"video", __guac_handshake_video_handler}, {"image", __guac_handshake_image_handler}, {"timezone", __guac_handshake_timezone_handler}, + {"name", __guac_handshake_name_handler}, {NULL, NULL} }; @@ -676,6 +677,21 @@ int __guac_handshake_image_handler(guac_user* user, int argc, char** argv) { } +int __guac_handshake_name_handler(guac_user* user, int argc, char** argv) { + + /* Free any past value */ + free((char *) user->info.name); + + if (argc > 0 && strcmp(argv[0], "")) + user->info.name = (const char*) strdup(argv[0]); + + else + user->info.name = NULL; + + return 0; + +} + int __guac_handshake_timezone_handler(guac_user* user, int argc, char** argv) { /* Free any past value */ diff --git a/src/libguac/user-handlers.h b/src/libguac/user-handlers.h index a51a3f89..7f82302b 100644 --- a/src/libguac/user-handlers.h +++ b/src/libguac/user-handlers.h @@ -218,6 +218,13 @@ __guac_instruction_handler __guac_handshake_video_handler; */ __guac_instruction_handler __guac_handshake_image_handler; +/** + * Internal handler function that is called when the name instruction is + * received during the handshake process, specifying the name of the Guacamole + * user establishing the connection. + */ +__guac_instruction_handler __guac_handshake_name_handler; + /** * Internal handler function that is called when the timezone instruction is * received during the handshake process, specifying the timezone of the diff --git a/src/libguac/user-handshake.c b/src/libguac/user-handshake.c index 4e0fa446..0863325f 100644 --- a/src/libguac/user-handshake.c +++ b/src/libguac/user-handshake.c @@ -296,6 +296,7 @@ int guac_user_handle_connection(guac_user* user, int usec_timeout) { user->info.audio_mimetypes = NULL; user->info.image_mimetypes = NULL; user->info.video_mimetypes = NULL; + user->info.name = NULL; user->info.timezone = NULL; /* Count number of arguments. */ @@ -370,7 +371,8 @@ int guac_user_handle_connection(guac_user* user, int usec_timeout) { guac_free_mimetypes((char **) user->info.image_mimetypes); guac_free_mimetypes((char **) user->info.video_mimetypes); - /* Free timezone info. */ + /* Free name and timezone info. */ + free((char *) user->info.name); free((char *) user->info.timezone); guac_parser_free(parser);