From b7257d9ae45287a8a9e1b80920c677d75863698c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 8 Dec 2017 13:10:32 -0800 Subject: [PATCH] GUACAMOLE-313: Include unknown keys within log. --- src/guaclog/keydef.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/guaclog/keydef.c b/src/guaclog/keydef.c index 427e3cae..6b979faa 100644 --- a/src/guaclog/keydef.c +++ b/src/guaclog/keydef.c @@ -21,6 +21,7 @@ #include "keydef.h" #include "log.h" +#include #include #include #include @@ -168,6 +169,36 @@ static guaclog_keydef* guaclog_get_known_key(int keysym) { } +/** + * Returns a statically-allocated guaclog_keydef representing an unknown key, + * deriving the name of the key from the hexadecimal value of the keysym. + * + * @param keysym + * The X11 keysym of the key. + * + * @return + * A statically-allocated guaclog_keydef representing the key associated + * with the given keysym. + */ +static guaclog_keydef* guaclog_get_unknown_key(int keysym) { + + static char unknown_keydef_name[64]; + static guaclog_keydef unknown_keydef; + + /* Write keysym as hex */ + int size = snprintf(unknown_keydef_name, sizeof(unknown_keydef_name), + "0x%X", keysym); + + /* Hex string is guaranteed to fit within the provided 64 bytes */ + assert(size < sizeof(unknown_keydef_name)); + + /* Return static key definition */ + unknown_keydef.keysym = keysym; + unknown_keydef.name = unknown_keydef_name; + return &unknown_keydef; + +} + /** * Returns a statically-allocated guaclog_keydef representing the key * associated with the given keysym, deriving the name and value of the key @@ -286,7 +317,7 @@ guaclog_keydef* guaclog_keydef_alloc(int keysym) { /* Key not known */ guaclog_log(GUAC_LOG_DEBUG, "Definition not found for key 0x%X.", keysym); - return NULL; + return guaclog_copy_key(guaclog_get_unknown_key(keysym)); }