From 3a922355e34f9ef9e493c110e9198dd3e3557913 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 2 Jan 2014 23:41:16 -0800 Subject: [PATCH] Implement keymap find. --- src/protocols/rdp/Makefile.am | 5 ----- src/protocols/rdp/client.c | 40 ++++++---------------------------- src/protocols/rdp/rdp_keymap.c | 18 +++++++++++++++ src/protocols/rdp/rdp_keymap.h | 10 +++++++++ 4 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/protocols/rdp/Makefile.am b/src/protocols/rdp/Makefile.am index 8a510b73..1b3f74ad 100644 --- a/src/protocols/rdp/Makefile.am +++ b/src/protocols/rdp/Makefile.am @@ -37,12 +37,7 @@ libguac_client_rdp_la_SOURCES = \ rdp_fs.c \ rdp_gdi.c \ rdp_glyph.c \ - rdp_keymap_base.c \ rdp_keymap.c \ - rdp_keymap_de_de.c \ - rdp_keymap_failsafe.c \ - rdp_keymap_fr_fr.c \ - rdp_keymap_en_us.c \ rdp_pointer.c \ rdp_settings.c \ unicode.c diff --git a/src/protocols/rdp/client.c b/src/protocols/rdp/client.c index f0da066f..ef07e943 100644 --- a/src/protocols/rdp/client.c +++ b/src/protocols/rdp/client.c @@ -569,40 +569,14 @@ int guac_client_init(guac_client* client, int argc, char** argv) { ((rdp_freerdp_context*) rdp_inst->context)->client = client; /* Pick keymap based on argument */ - if (argv[IDX_SERVER_LAYOUT][0] != '\0') { + settings->server_layout = NULL; + if (argv[IDX_SERVER_LAYOUT][0] != '\0') + settings->server_layout = + guac_rdp_keymap_find(argv[IDX_SERVER_LAYOUT]); - /* US English Qwerty */ - if (strcmp("en-us-qwerty", argv[IDX_SERVER_LAYOUT]) == 0) - settings->server_layout = &guac_rdp_keymap_en_us; - - /* German Qwertz */ - else if (strcmp("de-de-qwertz", argv[IDX_SERVER_LAYOUT]) == 0) - settings->server_layout = &guac_rdp_keymap_de_de; - - /* French Azerty */ - else if (strcmp("fr-fr-azerty", argv[IDX_SERVER_LAYOUT]) == 0) - settings->server_layout = &guac_rdp_keymap_fr_fr; - - /* Failsafe (Unicode) keymap */ - else if (strcmp("failsafe", argv[IDX_SERVER_LAYOUT]) == 0) - settings->server_layout = &guac_rdp_keymap_failsafe; - - /* If keymap unknown, resort to failsafe */ - else { - - guac_client_log_error(client, - "Unknown layout \"%s\". Using the failsafe layout instead.", - argv[IDX_SERVER_LAYOUT]); - - settings->server_layout = &guac_rdp_keymap_failsafe; - - } - - } - - /* If no keymap requested, assume US */ - else - settings->server_layout = &guac_rdp_keymap_en_us; + /* If no keymap requested, use default */ + if (settings->server_layout == NULL); + settings->server_layout = guac_rdp_keymap_find(GUAC_DEFAULT_KEYMAP); /* Load keymap into client */ __guac_rdp_client_load_keymap(client, settings->server_layout); diff --git a/src/protocols/rdp/rdp_keymap.c b/src/protocols/rdp/rdp_keymap.c index 63a78cec..5dc45f47 100644 --- a/src/protocols/rdp/rdp_keymap.c +++ b/src/protocols/rdp/rdp_keymap.c @@ -46,3 +46,21 @@ const int GUAC_KEYSYMS_ALL_MODIFIERS[] = { 0 }; +const guac_rdp_keymap* guac_rdp_keymap_find(const char* name) { + + /* For each keymap */ + const guac_rdp_keymap** current = GUAC_KEYMAPS; + while (current != NULL) { + + /* If name matches, done */ + if (strcmp((*current)->name, name) == 0) + return *current; + + current++; + } + + /* Failure */ + return NULL; + +} + diff --git a/src/protocols/rdp/rdp_keymap.h b/src/protocols/rdp/rdp_keymap.h index c83078ba..4d4cf167 100644 --- a/src/protocols/rdp/rdp_keymap.h +++ b/src/protocols/rdp/rdp_keymap.h @@ -133,6 +133,11 @@ typedef int guac_rdp_keysym_state_map[0x200][0x100]; [(keysym) & 0xFF] \ ) +/** + * The name of the default keymap, which MUST exist. + */ +#define GUAC_DEFAULT_KEYMAP "en-us-qwerty" + /** * Keysym string containing only the left "shift" key. */ @@ -195,5 +200,10 @@ extern const int GUAC_KEYSYMS_ALL_MODIFIERS[]; */ extern const guac_rdp_keymap* GUAC_KEYMAPS[]; +/** + * Return the keymap having the given name, if any, or NULL otherwise. + */ +const guac_rdp_keymap* guac_rdp_keymap_find(const char* name); + #endif