From f4475b4f0073e105b07a297b759371196262d84f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 23 May 2013 23:12:01 -0700 Subject: [PATCH] Move flags to generic function, add charset handler stubs. --- protocols/ssh/include/terminal_handlers.h | 5 +- protocols/ssh/src/terminal_handlers.c | 84 ++++++++++++++++++++--- 2 files changed, 78 insertions(+), 11 deletions(-) diff --git a/protocols/ssh/include/terminal_handlers.h b/protocols/ssh/include/terminal_handlers.h index ec796085..3b1faf68 100644 --- a/protocols/ssh/include/terminal_handlers.h +++ b/protocols/ssh/include/terminal_handlers.h @@ -42,7 +42,10 @@ int guac_terminal_echo(guac_terminal* term, char c); int guac_terminal_escape(guac_terminal* term, char c); -int guac_terminal_charset(guac_terminal* term, char c); +int guac_terminal_g0_charset(guac_terminal* term, char c); +int guac_terminal_g1_charset(guac_terminal* term, char c); +int guac_terminal_g2_charset(guac_terminal* term, char c); +int guac_terminal_g3_charset(guac_terminal* term, char c); int guac_terminal_csi(guac_terminal* term, char c); int guac_terminal_osc(guac_terminal* term, char c); int guac_terminal_ctrl_func(guac_terminal* term, char c); diff --git a/protocols/ssh/src/terminal_handlers.c b/protocols/ssh/src/terminal_handlers.c index 0a94b632..212bd78c 100644 --- a/protocols/ssh/src/terminal_handlers.c +++ b/protocols/ssh/src/terminal_handlers.c @@ -173,7 +173,19 @@ int guac_terminal_escape(guac_terminal* term, char c) { switch (c) { case '(': - term->char_handler = guac_terminal_charset; + term->char_handler = guac_terminal_g0_charset; + break; + + case ')': + term->char_handler = guac_terminal_g1_charset; + break; + + case '*': + term->char_handler = guac_terminal_g2_charset; + break; + + case '+': + term->char_handler = guac_terminal_g3_charset; break; case ']': @@ -273,9 +285,58 @@ int guac_terminal_escape(guac_terminal* term, char c) { } -int guac_terminal_charset(guac_terminal* term, char c) { +int guac_terminal_g0_charset(guac_terminal* term, char c) { + + /* STUB */ + guac_client_log_info(term->client, "Ignoring G0 charset: 0x%02x", c); term->char_handler = guac_terminal_echo; return 0; + +} + +int guac_terminal_g1_charset(guac_terminal* term, char c) { + + /* STUB */ + guac_client_log_info(term->client, "Ignoring G1 charset: 0x%02x", c); + term->char_handler = guac_terminal_echo; + return 0; + +} + +int guac_terminal_g2_charset(guac_terminal* term, char c) { + + /* STUB */ + guac_client_log_info(term->client, "Ignoring G2 charset: 0x%02x", c); + term->char_handler = guac_terminal_echo; + return 0; + +} + +int guac_terminal_g3_charset(guac_terminal* term, char c) { + + /* STUB */ + guac_client_log_info(term->client, "Ignoring G3 charset: 0x%02x", c); + term->char_handler = guac_terminal_echo; + return 0; + +} + +/** + * Looks up the flag specified by the given number and mode. Used by the Set/Reset Mode + * functions of the terminal. + */ +static bool* __guac_terminal_get_flag(guac_terminal* term, int num, char private_mode) { + + if (private_mode == '?') { + switch (num) { + case 1: return &(term->application_cursor_keys); /* DECCKM */ + } + } + + + /* Unknown flag */ + return NULL; + } int guac_terminal_csi(guac_terminal* term, char c) { @@ -304,6 +365,7 @@ int guac_terminal_csi(guac_terminal* term, char c) { else if ((c >= 0x40 && c <= 0x7E) || c == ';') { int i, row, col, amount; + bool* flag; /* At most 16 parameters */ if (argc < 16) { @@ -554,10 +616,11 @@ int guac_terminal_csi(guac_terminal* term, char c) { /* h: Set Mode */ case 'h': - - /* DECCKM */ - if (argv[0] == 1 && private_mode_character == '?') - term->application_cursor_keys = true; + + /* Look up flag and set */ + flag = __guac_terminal_get_flag(term, argv[0], private_mode_character); + if (flag != NULL) + *flag = true; else guac_client_log_info(term->client, @@ -568,10 +631,11 @@ int guac_terminal_csi(guac_terminal* term, char c) { /* l: Reset Mode */ case 'l': - - /* DECCKM */ - if (argv[0] == 1 && private_mode_character == '?') - term->application_cursor_keys = false; + + /* Look up flag and clear */ + flag = __guac_terminal_get_flag(term, argv[0], private_mode_character); + if (flag != NULL) + *flag = false; else guac_client_log_info(term->client,