From 2a6de3aaed6ee6ce8e0a3b6439f4b24626feab1d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 25 May 2013 23:50:13 -0700 Subject: [PATCH] Add port and font options. --- protocols/ssh/include/client.h | 4 ++ protocols/ssh/include/display.h | 4 +- protocols/ssh/include/terminal.h | 1 + protocols/ssh/src/client.c | 65 ++++++++++++++++++++++++++++--- protocols/ssh/src/display.c | 12 +++--- protocols/ssh/src/guac_handlers.c | 6 ++- protocols/ssh/src/ssh_client.c | 1 + protocols/ssh/src/terminal.c | 2 + 8 files changed, 81 insertions(+), 14 deletions(-) diff --git a/protocols/ssh/include/client.h b/protocols/ssh/include/client.h index 2a38c1c6..09cffac5 100644 --- a/protocols/ssh/include/client.h +++ b/protocols/ssh/include/client.h @@ -51,9 +51,13 @@ typedef struct ssh_guac_client_data { char hostname[1024]; + int port; char username[1024]; char password[1024]; + char font_name[1024]; + int font_size; + pthread_t client_thread; ssh_session session; diff --git a/protocols/ssh/include/display.h b/protocols/ssh/include/display.h index e5a2568e..c0f5c520 100644 --- a/protocols/ssh/include/display.h +++ b/protocols/ssh/include/display.h @@ -237,7 +237,9 @@ typedef struct guac_terminal_display { * Allocates a new display having the given default foreground and background * colors. */ -guac_terminal_display* guac_terminal_display_alloc(guac_client* client, int foreground, int background); +guac_terminal_display* guac_terminal_display_alloc(guac_client* client, + const char* font_name, int font_size, + int foreground, int background); /** * Frees the given display. diff --git a/protocols/ssh/include/terminal.h b/protocols/ssh/include/terminal.h index ac50b616..2208aa78 100644 --- a/protocols/ssh/include/terminal.h +++ b/protocols/ssh/include/terminal.h @@ -240,6 +240,7 @@ struct guac_terminal { * rendering to the given client. */ guac_terminal* guac_terminal_create(guac_client* client, + const char* font_name, int font_size, int width, int height); /** diff --git a/protocols/ssh/src/client.c b/protocols/ssh/src/client.c index 76697e10..b23dbdc5 100644 --- a/protocols/ssh/src/client.c +++ b/protocols/ssh/src/client.c @@ -53,20 +53,53 @@ #include "ibar.h" #include "ssh_client.h" +#define GUAC_SSH_DEFAULT_FONT_NAME "monospace" +#define GUAC_SSH_DEFAULT_FONT_SIZE 12 +#define GUAC_SSH_DEFAULT_PORT 22 + /* Client plugin arguments */ const char* GUAC_CLIENT_ARGS[] = { "hostname", "port", "username", "password", + "font-name", + "font-size", NULL }; enum __SSH_ARGS_IDX { + + /** + * The hostname to connect to. Required. + */ IDX_HOSTNAME, + + /** + * The port to connect to. Optional. + */ IDX_PORT, + + /** + * The name of the user to login as. Optional. + */ IDX_USERNAME, + + /** + * The password to use when logging in. Optional. + */ IDX_PASSWORD, + + /** + * The name of the font to use within the terminal. + */ + IDX_FONT_NAME, + + /** + * The size of the font to use within the terminal, in points. + */ + IDX_FONT_SIZE, + SSH_ARGS_COUNT }; @@ -75,12 +108,9 @@ int guac_client_init(guac_client* client, int argc, char** argv) { guac_socket* socket = client->socket; ssh_guac_client_data* client_data = malloc(sizeof(ssh_guac_client_data)); - guac_terminal* term = guac_terminal_create(client, - client->info.optimal_width, client->info.optimal_height); /* Init client data */ client->data = client_data; - client_data->term = term; client_data->mod_alt = 0; client_data->mod_ctrl = 0; client_data->clipboard_data = NULL; @@ -92,9 +122,32 @@ int guac_client_init(guac_client* client, int argc, char** argv) { } /* Read parameters */ - strcpy(client_data->hostname, argv[IDX_HOSTNAME]); - strcpy(client_data->username, argv[IDX_USERNAME]); - strcpy(client_data->password, argv[IDX_PASSWORD]); + strcpy(client_data->hostname, argv[IDX_HOSTNAME]); + strcpy(client_data->username, argv[IDX_USERNAME]); + strcpy(client_data->password, argv[IDX_PASSWORD]); + + /* Read font name */ + if (argv[IDX_FONT_NAME][0] != 0) + strcpy(client_data->font_name, argv[IDX_FONT_NAME]); + else + strcpy(client_data->font_name, GUAC_SSH_DEFAULT_FONT_NAME ); + + /* Read font size */ + if (argv[IDX_FONT_SIZE][0] != 0) + client_data->font_size = atoi(argv[IDX_FONT_SIZE]); + else + client_data->font_size = GUAC_SSH_DEFAULT_FONT_SIZE; + + /* Read port */ + if (argv[IDX_PORT][0] != 0) + client_data->port = atoi(argv[IDX_PORT]); + else + client_data->port = GUAC_SSH_DEFAULT_PORT; + + /* Create terminal */ + client_data->term = guac_terminal_create(client, + client_data->font_name, client_data->font_size, + client->info.optimal_width, client->info.optimal_height); /* Set up I-bar pointer */ client_data->ibar_cursor = guac_ssh_create_ibar(client); diff --git a/protocols/ssh/src/display.c b/protocols/ssh/src/display.c index 11d98e03..5cd4c2a5 100644 --- a/protocols/ssh/src/display.c +++ b/protocols/ssh/src/display.c @@ -339,7 +339,9 @@ int __guac_terminal_set(guac_terminal_display* display, int row, int col, int co } -guac_terminal_display* guac_terminal_display_alloc(guac_client* client, int foreground, int background) { +guac_terminal_display* guac_terminal_display_alloc(guac_client* client, + const char* font_name, int font_size, + int foreground, int background) { PangoFontMap* font_map; PangoFont* font; @@ -358,22 +360,22 @@ guac_terminal_display* guac_terminal_display_alloc(guac_client* client, int fore /* Get font */ display->font_desc = pango_font_description_new(); - pango_font_description_set_family(display->font_desc, "monospace"); + pango_font_description_set_family(display->font_desc, font_name); pango_font_description_set_weight(display->font_desc, PANGO_WEIGHT_NORMAL); - pango_font_description_set_size(display->font_desc, 12*PANGO_SCALE); + pango_font_description_set_size(display->font_desc, font_size*PANGO_SCALE); font_map = pango_cairo_font_map_get_default(); context = pango_font_map_create_context(font_map); font = pango_font_map_load_font(font_map, context, display->font_desc); if (font == NULL) { - guac_client_log_error(display->client, "Unable to get font."); + guac_client_log_error(display->client, "Unable to get font \"%s\"", font_name); return NULL; } metrics = pango_font_get_metrics(font, NULL); if (metrics == NULL) { - guac_client_log_error(display->client, "Unable to get font metrics."); + guac_client_log_error(display->client, "Unable to get font metrics for font \"%s\"", font_name); return NULL; } diff --git a/protocols/ssh/src/guac_handlers.c b/protocols/ssh/src/guac_handlers.c index de658067..d57c7251 100644 --- a/protocols/ssh/src/guac_handlers.c +++ b/protocols/ssh/src/guac_handlers.c @@ -386,8 +386,10 @@ int ssh_guac_client_free_handler(guac_client* client) { ssh_guac_client_data* guac_client_data = (ssh_guac_client_data*) client->data; /* Close SSH channel */ - ssh_channel_close(guac_client_data->term_channel); - ssh_channel_send_eof(guac_client_data->term_channel); + if (guac_client_data->term_channel != NULL) { + ssh_channel_close(guac_client_data->term_channel); + ssh_channel_send_eof(guac_client_data->term_channel); + } /* Free terminal */ guac_terminal_free(guac_client_data->term); diff --git a/protocols/ssh/src/ssh_client.c b/protocols/ssh/src/ssh_client.c index 960eedec..3d352d29 100644 --- a/protocols/ssh/src/ssh_client.c +++ b/protocols/ssh/src/ssh_client.c @@ -169,6 +169,7 @@ void* ssh_client_thread(void* data) { /* Set session options */ ssh_options_set(client_data->session, SSH_OPTIONS_HOST, client_data->hostname); + ssh_options_set(client_data->session, SSH_OPTIONS_PORT, &(client_data->port)); ssh_options_set(client_data->session, SSH_OPTIONS_USER, client_data->username); /* Connect */ diff --git a/protocols/ssh/src/terminal.c b/protocols/ssh/src/terminal.c index f7bd7fc0..fc3c50b1 100644 --- a/protocols/ssh/src/terminal.c +++ b/protocols/ssh/src/terminal.c @@ -90,6 +90,7 @@ void guac_terminal_reset(guac_terminal* term) { } guac_terminal* guac_terminal_create(guac_client* client, + const char* font_name, int font_size, int width, int height) { guac_terminal_char default_char = { @@ -110,6 +111,7 @@ guac_terminal* guac_terminal_create(guac_client* client, /* Init display */ term->display = guac_terminal_display_alloc(client, + font_name, font_size, default_char.attributes.foreground, default_char.attributes.background);