From 1fc7a9a8cdfe513f5647c19803b3bf036b7411b0 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 20 Mar 2012 19:47:41 -0700 Subject: [PATCH] Do not use addressof in lookup macro. Update keysym state in event handler. --- protocols/rdp/include/rdp_keymap.h | 2 +- protocols/rdp/src/guac_handlers.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/protocols/rdp/include/rdp_keymap.h b/protocols/rdp/include/rdp_keymap.h index 39c9be4c..85eb8f41 100644 --- a/protocols/rdp/include/rdp_keymap.h +++ b/protocols/rdp/include/rdp_keymap.h @@ -111,7 +111,7 @@ extern const guac_rdp_keysym_altcode_map guac_rdp_keysym_altcode; /** * Simple macro for referencing the mapped value of an altcode or scancode for a given keysym. */ -#define GUAC_RDP_KEYSYM_LOOKUP(keysym_mapping, keysym) (&((keysym_mapping)[((keysym) & 0xFF00) >> 8][(keysym) & 0xFF])) +#define GUAC_RDP_KEYSYM_LOOKUP(keysym_mapping, keysym) ((keysym_mapping)[((keysym) & 0xFF00) >> 8][(keysym) & 0xFF]) /** * Keysym string containing only the left "shift" key. diff --git a/protocols/rdp/src/guac_handlers.c b/protocols/rdp/src/guac_handlers.c index 1f986cbc..488af41a 100644 --- a/protocols/rdp/src/guac_handlers.c +++ b/protocols/rdp/src/guac_handlers.c @@ -234,7 +234,7 @@ void __guac_rdp_send_altcode(guac_client* client, const char* altcode) { const guac_rdp_keysym_scancode_map* keysym_scancodes = guac_client_data->keysym_scancodes; /* Lookup scancode for Alt */ - int alt = GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, 0xFFE9 /* Alt_L */)->scancode; + int alt = GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, 0xFFE9 /* Alt_L */).scancode; /* Press Alt */ rdp_inst->input->KeyboardEvent(rdp_inst->input, KBD_FLAGS_DOWN, alt); @@ -243,7 +243,7 @@ void __guac_rdp_send_altcode(guac_client* client, const char* altcode) { while (*altcode != '\0') { /* Get scancode of keypad digit */ - int scancode = GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, 0xFFB0 + (*altcode) - '0')->scancode; + int scancode = GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, 0xFFB0 + (*altcode) - '0').scancode; /* Press and release digit */ rdp_inst->input->KeyboardEvent(rdp_inst->input, KBD_FLAGS_DOWN, scancode); @@ -268,7 +268,7 @@ int __guac_rdp_send_keysym(guac_client* client, int keysym, int pressed) { if (keysym <= 0xFFFF) { /* Look up scancode mapping */ - const guac_rdp_scancode_map* scancode_map = GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, keysym); + const guac_rdp_scancode_map* scancode_map = &GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, keysym); /* If defined, send event */ if (scancode_map->scancode != 0) { @@ -293,7 +293,7 @@ int __guac_rdp_send_keysym(guac_client* client, int keysym, int pressed) { /* If undefined, try to type using Alt-code */ else { - const guac_rdp_altcode_map* altcode_map = GUAC_RDP_KEYSYM_LOOKUP(guac_rdp_keysym_altcode, keysym); + const guac_rdp_altcode_map* altcode_map = &GUAC_RDP_KEYSYM_LOOKUP(guac_rdp_keysym_altcode, keysym); if (altcode_map->altcode != NULL) { /* Only send Alt-code on press */ @@ -323,7 +323,12 @@ void __guac_rdp_send_keysym_string(guac_client* client, const int* keysym_string int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed) { - return __guac_rdp_send_keysym(client, keysym, pressed);; + rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data; + + /* Update keysym state */ + GUAC_RDP_KEYSYM_LOOKUP(guac_client_data->keysym_state, keysym) = pressed; + + return __guac_rdp_send_keysym(client, keysym, pressed); }