Add port and font options.
This commit is contained in:
parent
6d33be152c
commit
2a6de3aaed
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user