GUACAMOLE-1538: Improve code style and cleanliness.
This commit is contained in:
parent
6dd33a8d90
commit
ce2ffdf75f
@ -54,8 +54,8 @@ int guac_kubernetes_argv_callback(guac_user* user, const char* mimetype,
|
|||||||
|
|
||||||
/* Update Kubernetes terminal size */
|
/* Update Kubernetes terminal size */
|
||||||
guac_kubernetes_resize(client,
|
guac_kubernetes_resize(client,
|
||||||
guac_terminal_term_height(terminal),
|
guac_terminal_get_rows(terminal),
|
||||||
guac_terminal_term_width(terminal));
|
guac_terminal_get_columns(terminal));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -87,8 +87,8 @@ int guac_kubernetes_user_size_handler(guac_user* user, int width, int height) {
|
|||||||
|
|
||||||
/* Update Kubernetes terminal window size if connected */
|
/* Update Kubernetes terminal window size if connected */
|
||||||
guac_kubernetes_resize(client,
|
guac_kubernetes_resize(client,
|
||||||
guac_terminal_term_height(terminal),
|
guac_terminal_get_rows(terminal),
|
||||||
guac_terminal_term_width(terminal));
|
guac_terminal_get_columns(terminal));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ void* guac_kubernetes_client_thread(void* data) {
|
|||||||
|
|
||||||
/* Create terminal options with required parameters */
|
/* Create terminal options with required parameters */
|
||||||
guac_terminal_options* options = guac_terminal_options_create(
|
guac_terminal_options* options = guac_terminal_options_create(
|
||||||
client, settings->width, settings->height, settings->resolution);
|
settings->width, settings->height, settings->resolution);
|
||||||
|
|
||||||
/* Set optional parameters */
|
/* Set optional parameters */
|
||||||
options->disable_copy = settings->disable_copy;
|
options->disable_copy = settings->disable_copy;
|
||||||
@ -252,7 +252,7 @@ void* guac_kubernetes_client_thread(void* data) {
|
|||||||
options->backspace = settings->backspace;
|
options->backspace = settings->backspace;
|
||||||
|
|
||||||
/* Create terminal */
|
/* Create terminal */
|
||||||
kubernetes_client->term = guac_terminal_create(options);
|
kubernetes_client->term = guac_terminal_create(client, options);
|
||||||
|
|
||||||
/* Free options struct now that it's been used */
|
/* Free options struct now that it's been used */
|
||||||
free(options);
|
free(options);
|
||||||
@ -413,8 +413,8 @@ void guac_kubernetes_force_redraw(guac_client* client) {
|
|||||||
|
|
||||||
/* Get current terminal dimensions */
|
/* Get current terminal dimensions */
|
||||||
guac_terminal* term = kubernetes_client->term;
|
guac_terminal* term = kubernetes_client->term;
|
||||||
int rows = guac_terminal_term_height(term);
|
int rows = guac_terminal_get_rows(term);
|
||||||
int columns = guac_terminal_term_width(term);
|
int columns = guac_terminal_get_columns(term);
|
||||||
|
|
||||||
/* Force a redraw by increasing the terminal size by one character in
|
/* Force a redraw by increasing the terminal size by one character in
|
||||||
* each dimension and then resizing it back to normal (the same technique
|
* each dimension and then resizing it back to normal (the same technique
|
||||||
|
@ -54,8 +54,8 @@ int guac_ssh_argv_callback(guac_user* user, const char* mimetype,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Update SSH pty size if connected */
|
/* Update SSH pty size if connected */
|
||||||
int term_width = guac_terminal_term_width(terminal);
|
int term_width = guac_terminal_get_columns(terminal);
|
||||||
int term_height = guac_terminal_term_height(terminal);
|
int term_height = guac_terminal_get_rows(terminal);
|
||||||
if (ssh_client->term_channel != NULL) {
|
if (ssh_client->term_channel != NULL) {
|
||||||
pthread_mutex_lock(&(ssh_client->term_channel_lock));
|
pthread_mutex_lock(&(ssh_client->term_channel_lock));
|
||||||
libssh2_channel_request_pty_size(ssh_client->term_channel,
|
libssh2_channel_request_pty_size(ssh_client->term_channel,
|
||||||
|
@ -88,8 +88,8 @@ int guac_ssh_user_size_handler(guac_user* user, int width, int height) {
|
|||||||
if (ssh_client->term_channel != NULL) {
|
if (ssh_client->term_channel != NULL) {
|
||||||
pthread_mutex_lock(&(ssh_client->term_channel_lock));
|
pthread_mutex_lock(&(ssh_client->term_channel_lock));
|
||||||
libssh2_channel_request_pty_size(ssh_client->term_channel,
|
libssh2_channel_request_pty_size(ssh_client->term_channel,
|
||||||
guac_terminal_term_width(terminal),
|
guac_terminal_get_columns(terminal),
|
||||||
guac_terminal_term_height(terminal));
|
guac_terminal_get_rows(terminal));
|
||||||
pthread_mutex_unlock(&(ssh_client->term_channel_lock));
|
pthread_mutex_unlock(&(ssh_client->term_channel_lock));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ void* ssh_client_thread(void* data) {
|
|||||||
|
|
||||||
/* Create terminal options with required parameters */
|
/* Create terminal options with required parameters */
|
||||||
guac_terminal_options* options = guac_terminal_options_create(
|
guac_terminal_options* options = guac_terminal_options_create(
|
||||||
client, settings->width, settings->height, settings->resolution);
|
settings->width, settings->height, settings->resolution);
|
||||||
|
|
||||||
/* Set optional parameters */
|
/* Set optional parameters */
|
||||||
options->disable_copy = settings->disable_copy;
|
options->disable_copy = settings->disable_copy;
|
||||||
@ -251,7 +251,7 @@ void* ssh_client_thread(void* data) {
|
|||||||
options->backspace = settings->backspace;
|
options->backspace = settings->backspace;
|
||||||
|
|
||||||
/* Create terminal */
|
/* Create terminal */
|
||||||
ssh_client->term = guac_terminal_create(options);
|
ssh_client->term = guac_terminal_create(client, options);
|
||||||
|
|
||||||
/* Free options struct now that it's been used */
|
/* Free options struct now that it's been used */
|
||||||
free(options);
|
free(options);
|
||||||
@ -377,8 +377,8 @@ void* ssh_client_thread(void* data) {
|
|||||||
" Backspace may not work as expected.");
|
" Backspace may not work as expected.");
|
||||||
|
|
||||||
/* Request PTY */
|
/* Request PTY */
|
||||||
int term_height = guac_terminal_term_height(ssh_client->term);
|
int term_height = guac_terminal_get_rows(ssh_client->term);
|
||||||
int term_width = guac_terminal_term_width(ssh_client->term);
|
int term_width = guac_terminal_get_columns(ssh_client->term);
|
||||||
if (libssh2_channel_request_pty_ex(ssh_client->term_channel,
|
if (libssh2_channel_request_pty_ex(ssh_client->term_channel,
|
||||||
settings->terminal_type, strlen(settings->terminal_type),
|
settings->terminal_type, strlen(settings->terminal_type),
|
||||||
ssh_ttymodes, ttymodeBytes, term_width, term_height, 0, 0)) {
|
ssh_ttymodes, ttymodeBytes, term_width, term_height, 0, 0)) {
|
||||||
|
@ -55,8 +55,8 @@ int guac_telnet_argv_callback(guac_user* user, const char* mimetype,
|
|||||||
/* Update terminal window size if connected */
|
/* Update terminal window size if connected */
|
||||||
if (telnet_client->telnet != NULL && telnet_client->naws_enabled)
|
if (telnet_client->telnet != NULL && telnet_client->naws_enabled)
|
||||||
guac_telnet_send_naws(telnet_client->telnet,
|
guac_telnet_send_naws(telnet_client->telnet,
|
||||||
guac_terminal_term_width(terminal),
|
guac_terminal_get_columns(terminal),
|
||||||
guac_terminal_term_height(terminal));
|
guac_terminal_get_rows(terminal));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -136,8 +136,8 @@ int guac_telnet_user_size_handler(guac_user* user, int width, int height) {
|
|||||||
/* Update terminal window size if connected */
|
/* Update terminal window size if connected */
|
||||||
if (telnet_client->telnet != NULL && telnet_client->naws_enabled)
|
if (telnet_client->telnet != NULL && telnet_client->naws_enabled)
|
||||||
guac_telnet_send_naws(telnet_client->telnet,
|
guac_telnet_send_naws(telnet_client->telnet,
|
||||||
guac_terminal_term_width(terminal),
|
guac_terminal_get_columns(terminal),
|
||||||
guac_terminal_term_height(terminal));
|
guac_terminal_get_rows(terminal));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -303,8 +303,8 @@ static void __guac_telnet_event_handler(telnet_t* telnet, telnet_event_t* event,
|
|||||||
if (event->neg.telopt == TELNET_TELOPT_NAWS) {
|
if (event->neg.telopt == TELNET_TELOPT_NAWS) {
|
||||||
telnet_client->naws_enabled = 1;
|
telnet_client->naws_enabled = 1;
|
||||||
guac_telnet_send_naws(telnet,
|
guac_telnet_send_naws(telnet,
|
||||||
guac_terminal_term_width(telnet_client->term),
|
guac_terminal_get_columns(telnet_client->term),
|
||||||
guac_terminal_term_height(telnet_client->term));
|
guac_terminal_get_rows(telnet_client->term));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -589,7 +589,7 @@ void* guac_telnet_client_thread(void* data) {
|
|||||||
|
|
||||||
/* Create terminal options with required parameters */
|
/* Create terminal options with required parameters */
|
||||||
guac_terminal_options* options = guac_terminal_options_create(
|
guac_terminal_options* options = guac_terminal_options_create(
|
||||||
client, settings->width, settings->height, settings->resolution);
|
settings->width, settings->height, settings->resolution);
|
||||||
|
|
||||||
/* Set optional parameters */
|
/* Set optional parameters */
|
||||||
options->disable_copy = settings->disable_copy;
|
options->disable_copy = settings->disable_copy;
|
||||||
@ -600,7 +600,7 @@ void* guac_telnet_client_thread(void* data) {
|
|||||||
options->backspace = settings->backspace;
|
options->backspace = settings->backspace;
|
||||||
|
|
||||||
/* Create terminal */
|
/* Create terminal */
|
||||||
telnet_client->term = guac_terminal_create(options);
|
telnet_client->term = guac_terminal_create(client, options);
|
||||||
|
|
||||||
/* Free options struct now that it's been used */
|
/* Free options struct now that it's been used */
|
||||||
free(options);
|
free(options);
|
||||||
|
@ -190,11 +190,11 @@ int guac_terminal_available_scroll(guac_terminal* term) {
|
|||||||
return guac_terminal_effective_buffer_length(term) - term->term_height;
|
return guac_terminal_effective_buffer_length(term) - term->term_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
int guac_terminal_term_height(guac_terminal* term) {
|
int guac_terminal_get_rows(guac_terminal* term) {
|
||||||
return term->term_height;
|
return term->term_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
int guac_terminal_term_width(guac_terminal* term) {
|
int guac_terminal_get_columns(guac_terminal* term) {
|
||||||
return term->term_width;
|
return term->term_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,14 +315,12 @@ void* guac_terminal_thread(void* data) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
guac_terminal_options* guac_terminal_options_create(guac_client* client,
|
guac_terminal_options* guac_terminal_options_create(
|
||||||
int width, int height, int dpi) {
|
int width, int height, int dpi) {
|
||||||
|
|
||||||
|
|
||||||
guac_terminal_options* options = malloc(sizeof(guac_terminal_options));
|
guac_terminal_options* options = malloc(sizeof(guac_terminal_options));
|
||||||
|
|
||||||
/* Set all required parameters */
|
/* Set all required parameters */
|
||||||
options->client = client;
|
|
||||||
options->width = width;
|
options->width = width;
|
||||||
options->height = height;
|
options->height = height;
|
||||||
options->dpi = dpi;
|
options->dpi = dpi;
|
||||||
@ -338,7 +336,8 @@ guac_terminal_options* guac_terminal_options_create(guac_client* client,
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
guac_terminal* guac_terminal_create(guac_terminal_options* options) {
|
guac_terminal* guac_terminal_create(guac_client* client,
|
||||||
|
guac_terminal_options* options) {
|
||||||
|
|
||||||
/* The width and height may need to be changed from what's requested */
|
/* The width and height may need to be changed from what's requested */
|
||||||
int width = options->width;
|
int width = options->width;
|
||||||
@ -360,7 +359,7 @@ guac_terminal* guac_terminal_create(guac_terminal_options* options) {
|
|||||||
guac_terminal_color (*default_palette)[256] = (guac_terminal_color(*)[256])
|
guac_terminal_color (*default_palette)[256] = (guac_terminal_color(*)[256])
|
||||||
malloc(sizeof(guac_terminal_color[256]));
|
malloc(sizeof(guac_terminal_color[256]));
|
||||||
|
|
||||||
guac_terminal_parse_color_scheme(options->client, options->color_scheme,
|
guac_terminal_parse_color_scheme(client, options->color_scheme,
|
||||||
&default_char.attributes.foreground,
|
&default_char.attributes.foreground,
|
||||||
&default_char.attributes.background,
|
&default_char.attributes.background,
|
||||||
default_palette);
|
default_palette);
|
||||||
@ -372,7 +371,7 @@ guac_terminal* guac_terminal_create(guac_terminal_options* options) {
|
|||||||
|
|
||||||
guac_terminal* term = malloc(sizeof(guac_terminal));
|
guac_terminal* term = malloc(sizeof(guac_terminal));
|
||||||
term->started = false;
|
term->started = false;
|
||||||
term->client = options->client;
|
term->client = client;
|
||||||
term->upload_path_handler = NULL;
|
term->upload_path_handler = NULL;
|
||||||
term->file_download_handler = NULL;
|
term->file_download_handler = NULL;
|
||||||
|
|
||||||
@ -405,7 +404,7 @@ guac_terminal* guac_terminal_create(guac_terminal_options* options) {
|
|||||||
&default_char);
|
&default_char);
|
||||||
|
|
||||||
/* Init display */
|
/* Init display */
|
||||||
term->display = guac_terminal_display_alloc(options->client,
|
term->display = guac_terminal_display_alloc(client,
|
||||||
options->font_name, options->font_size, options->dpi,
|
options->font_name, options->font_size, options->dpi,
|
||||||
&default_char.attributes.foreground,
|
&default_char.attributes.foreground,
|
||||||
&default_char.attributes.background,
|
&default_char.attributes.background,
|
||||||
@ -413,13 +412,13 @@ guac_terminal* guac_terminal_create(guac_terminal_options* options) {
|
|||||||
|
|
||||||
/* Fail if display init failed */
|
/* Fail if display init failed */
|
||||||
if (term->display == NULL) {
|
if (term->display == NULL) {
|
||||||
guac_client_log(options->client, GUAC_LOG_DEBUG, "Display initialization failed");
|
guac_client_log(client, GUAC_LOG_DEBUG, "Display initialization failed");
|
||||||
free(term);
|
free(term);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Init common cursor */
|
/* Init common cursor */
|
||||||
term->cursor = guac_common_cursor_alloc(options->client);
|
term->cursor = guac_common_cursor_alloc(client);
|
||||||
|
|
||||||
/* Init terminal state */
|
/* Init terminal state */
|
||||||
term->current_attributes = default_char.attributes;
|
term->current_attributes = default_char.attributes;
|
||||||
|
@ -167,11 +167,6 @@ typedef guac_stream* guac_terminal_file_download_handler(guac_client* client, ch
|
|||||||
*/
|
*/
|
||||||
typedef struct guac_terminal_options {
|
typedef struct guac_terminal_options {
|
||||||
|
|
||||||
/**
|
|
||||||
* The client to which the terminal will be rendered.
|
|
||||||
*/
|
|
||||||
guac_client* client;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether copying from the terminal clipboard should be blocked. If set,
|
* Whether copying from the terminal clipboard should be blocked. If set,
|
||||||
* the contents of the terminal can still be copied, but will be usable
|
* the contents of the terminal can still be copied, but will be usable
|
||||||
@ -242,6 +237,9 @@ typedef struct guac_terminal_options {
|
|||||||
* either the underlying connection has truly succeeded, or until visible
|
* either the underlying connection has truly succeeded, or until visible
|
||||||
* terminal output or user input is required.
|
* terminal output or user input is required.
|
||||||
*
|
*
|
||||||
|
* @param client
|
||||||
|
* The client to which the terminal will be rendered.
|
||||||
|
*
|
||||||
* @param terminal_options
|
* @param terminal_options
|
||||||
* The configuration used for instantiating the terminal. For information
|
* The configuration used for instantiating the terminal. For information
|
||||||
* about the options, see the guac_terminal_options definition.
|
* about the options, see the guac_terminal_options definition.
|
||||||
@ -250,7 +248,8 @@ typedef struct guac_terminal_options {
|
|||||||
* A new guac_terminal having the given font, dimensions, and attributes
|
* A new guac_terminal having the given font, dimensions, and attributes
|
||||||
* which renders all text to the given client.
|
* which renders all text to the given client.
|
||||||
*/
|
*/
|
||||||
guac_terminal* guac_terminal_create(guac_terminal_options* terminal_options);
|
guac_terminal* guac_terminal_create(guac_client* client,
|
||||||
|
guac_terminal_options* terminal_options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new guac_terminal_options struct. All parameters are required.
|
* Create a new guac_terminal_options struct. All parameters are required.
|
||||||
@ -260,9 +259,6 @@ guac_terminal* guac_terminal_create(guac_terminal_options* terminal_options);
|
|||||||
* The guac_terminal_options struct should only be created using this
|
* The guac_terminal_options struct should only be created using this
|
||||||
* constructor.
|
* constructor.
|
||||||
*
|
*
|
||||||
* @param guac_client
|
|
||||||
* The client to which the terminal will be rendered.
|
|
||||||
*
|
|
||||||
* @param width
|
* @param width
|
||||||
* The width of the terminal, in pixels.
|
* The width of the terminal, in pixels.
|
||||||
*
|
*
|
||||||
@ -277,7 +273,7 @@ guac_terminal* guac_terminal_create(guac_terminal_options* terminal_options);
|
|||||||
* A new terminal options struct with all required options populated,
|
* A new terminal options struct with all required options populated,
|
||||||
* ready to have any defaults overriden as needed.
|
* ready to have any defaults overriden as needed.
|
||||||
*/
|
*/
|
||||||
guac_terminal_options* guac_terminal_options_create(guac_client* client,
|
guac_terminal_options* guac_terminal_options_create(
|
||||||
int width, int height, int dpi);
|
int width, int height, int dpi);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -533,7 +529,7 @@ int guac_terminal_available_scroll(guac_terminal* term);
|
|||||||
* @return
|
* @return
|
||||||
* The height of the terminal, in characters.
|
* The height of the terminal, in characters.
|
||||||
*/
|
*/
|
||||||
int guac_terminal_term_height(guac_terminal* term);
|
int guac_terminal_get_rows(guac_terminal* term);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the width of the given terminal, in characters.
|
* Returns the width of the given terminal, in characters.
|
||||||
@ -544,14 +540,16 @@ int guac_terminal_term_height(guac_terminal* term);
|
|||||||
* @return
|
* @return
|
||||||
* The width of the terminal, in characters.
|
* The width of the terminal, in characters.
|
||||||
*/
|
*/
|
||||||
int guac_terminal_term_width(guac_terminal* term);
|
int guac_terminal_get_columns(guac_terminal* term);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the clipboard contents for a given terminal, and assigns a new
|
* Clears the clipboard contents for a given terminal, and assigns a new
|
||||||
* mimetype for future data.
|
* mimetype for future data.
|
||||||
*
|
*
|
||||||
* @param terminal The terminal whose clipboard is being reset.
|
* @param terminal
|
||||||
* @param mimetype The mimetype of future data.
|
* The terminal whose clipboard is being reset.
|
||||||
|
* @param mimetype
|
||||||
|
* The mimetype of future data.
|
||||||
*/
|
*/
|
||||||
void guac_terminal_clipboard_reset(guac_terminal* terminal,
|
void guac_terminal_clipboard_reset(guac_terminal* terminal,
|
||||||
const char* mimetype);
|
const char* mimetype);
|
||||||
@ -561,9 +559,12 @@ void guac_terminal_clipboard_reset(guac_terminal* terminal,
|
|||||||
* terminal. The data must match the mimetype chosen for the clipboard data by
|
* terminal. The data must match the mimetype chosen for the clipboard data by
|
||||||
* guac_terminal_clipboard_reset().
|
* guac_terminal_clipboard_reset().
|
||||||
*
|
*
|
||||||
* @param terminal The terminal whose clipboard is being appended to.
|
* @param terminal
|
||||||
* @param data The data to append.
|
* The terminal whose clipboard is being appended to.
|
||||||
* @param length The number of bytes to append from the data given.
|
* @param data
|
||||||
|
* The data to append.
|
||||||
|
* @param length
|
||||||
|
* The number of bytes to append from the data given.
|
||||||
*/
|
*/
|
||||||
void guac_terminal_clipboard_append(guac_terminal* terminal,
|
void guac_terminal_clipboard_append(guac_terminal* terminal,
|
||||||
const char* data, int length);
|
const char* data, int length);
|
||||||
@ -573,8 +574,10 @@ void guac_terminal_clipboard_append(guac_terminal* terminal,
|
|||||||
* given terminal. This function must be called whenever a user leaves a
|
* given terminal. This function must be called whenever a user leaves a
|
||||||
* terminal connection.
|
* terminal connection.
|
||||||
*
|
*
|
||||||
* @param terminal The terminal that the given user is leaving.
|
* @param terminal
|
||||||
* @param user The user who is disconnecting.
|
* The terminal that the given user is leaving.
|
||||||
|
* @param user
|
||||||
|
* The user who is disconnecting.
|
||||||
*/
|
*/
|
||||||
void guac_terminal_remove_user(guac_terminal* terminal, guac_user* user);
|
void guac_terminal_remove_user(guac_terminal* terminal, guac_user* user);
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef _GUAC_TERMINAL_PRIV_H
|
#ifndef GUAC_TERMINAL_PRIV_H
|
||||||
#define _GUAC_TERMINAL_PRIV_H
|
#define GUAC_TERMINAL_PRIV_H
|
||||||
|
|
||||||
#include "common/clipboard.h"
|
#include "common/clipboard.h"
|
||||||
#include "terminal/terminal.h"
|
#include "terminal/terminal.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user