GUACAMOLE-269: Remove unnecessary data structure and array size, and update comments.

This commit is contained in:
Nick Couchman 2018-04-02 09:22:51 -04:00
parent ea946f2492
commit b441181c18
3 changed files with 17 additions and 43 deletions

View File

@ -192,8 +192,7 @@ void* ssh_client_thread(void* data) {
return NULL; return NULL;
} }
const int num_tty_opcodes = 1; char ssh_ttymodes[GUAC_SSH_TTYMODES_SIZE(1)];
char ssh_ttymodes[(GUAC_SSH_TTY_OPCODE_SIZE * num_tty_opcodes) + 1];
/* Set up screen recording, if requested */ /* Set up screen recording, if requested */
if (settings->recording_path != NULL) { if (settings->recording_path != NULL) {
@ -301,7 +300,7 @@ void* ssh_client_thread(void* data) {
} }
/* Set up the ttymode array prior to requesting the PTY */ /* Set up the ttymode array prior to requesting the PTY */
int ttymodeBytes = guac_ssh_ttymodes_init(ssh_ttymodes, sizeof(ssh_ttymodes), int ttymodeBytes = guac_ssh_ttymodes_init(ssh_ttymodes,
GUAC_SSH_TTY_OP_VERASE, settings->backspace, GUAC_SSH_TTY_OP_END); GUAC_SSH_TTY_OP_VERASE, settings->backspace, GUAC_SSH_TTY_OP_END);
if (ttymodeBytes < 1) if (ttymodeBytes < 1)
guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Error storing TTY mode encoding \ guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Error storing TTY mode encoding \

View File

@ -25,12 +25,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
int guac_ssh_ttymodes_init(char opcode_array[], const int array_size, int guac_ssh_ttymodes_init(char opcode_array[], ...) {
...) {
/* Initialize the variable argument list. */ /* Initialize the variable argument list. */
va_list args; va_list args;
va_start(args, array_size); va_start(args, opcode_array);
/* Initialize array pointer and byte counter. */ /* Initialize array pointer and byte counter. */
char *current = opcode_array; char *current = opcode_array;
@ -39,10 +38,6 @@ int guac_ssh_ttymodes_init(char opcode_array[], const int array_size,
/* Loop through variable argument list. */ /* Loop through variable argument list. */
while (true) { while (true) {
/* Check to make sure we don't overrun array. */
if (bytes >= array_size)
return -1;
/* Next argument should be an opcode. */ /* Next argument should be an opcode. */
char opcode = (char)va_arg(args, int); char opcode = (char)va_arg(args, int);
*(current++) = opcode; *(current++) = opcode;

View File

@ -46,46 +46,27 @@
#define GUAC_SSH_TTY_OP_VERASE 3 #define GUAC_SSH_TTY_OP_VERASE 3
/** /**
* The SSH protocol attempts to configure the remote * Macro for calculating the number of bytes required
* terminal by sending pairs of opcodes and values, as * to pass a given number of opcodes, which calculates
* described in Section 8 of RFC 4254. These are * the size of the number of opcodes plus the single byte
* comprised of a single byte opcode and a 4-byte * end opcode.
* value. This data structure stores a single opcode
* and value pair.
*/ */
typedef struct guac_ssh_ttymode { #define GUAC_SSH_TTYMODES_SIZE(num_opcodes) ((GUAC_SSH_TTY_OPCODE_SIZE * num_opcodes) + 1)
/**
* The single byte opcode for defining the TTY
* encoding setting for the remote terminal. The
* stadard codes are defined in Section 8 of
* the SSH RFC (4254).
*/
char opcode;
/**
* The four byte value of the setting for the
* defined opcode.
*/
uint32_t value;
} guac_ssh_ttymode;
/** /**
* Opcodes and value pairs are passed to the SSH connection * Opcodes and value pairs are passed to the SSH connection
* in a single array, beginning with the opcode and followed * in a single array, beginning with the opcode and followed
* by a four byte value, repeating until the end opcode is * by a four byte value, repeating until the end opcode is
* encountered. This function takes the array, the array * encountered. This function takes the array that will be
* size, and a variable number of opcode and value pair * sent and a variable number of opcode and value pair
* arguments and puts them in the array expected by the * arguments and places the opcode and values in the array
* SSH connection. * as expected by the SSH connection.
* *
* @param opcode_array * @param opcode_array
* Pointer to the opcode array that will ultimately * Pointer to the opcode array that will ultimately
* be passed to the SSH connection. * be passed to the SSH connection. The array must
* * be size to handle 5 bytes for each opcode and value
* @param array_size * pair, plus one additional byte for the end opcode.
* Size, in bytes, of the array.
* *
* @params ... * @params ...
* A variable number of opcode and value pairs * A variable number of opcode and value pairs
@ -95,7 +76,6 @@ typedef struct guac_ssh_ttymode {
* Number of bytes written to the array, or zero * Number of bytes written to the array, or zero
* if a failure occurs. * if a failure occurs.
*/ */
int guac_ssh_ttymodes_init(char opcode_array[], const int array_size, int guac_ssh_ttymodes_init(char opcode_array[], ...);
...);
#endif #endif