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;
}
const int num_tty_opcodes = 1;
char ssh_ttymodes[(GUAC_SSH_TTY_OPCODE_SIZE * num_tty_opcodes) + 1];
char ssh_ttymodes[GUAC_SSH_TTYMODES_SIZE(1)];
/* Set up screen recording, if requested */
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 */
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);
if (ttymodeBytes < 1)
guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Error storing TTY mode encoding \

View File

@ -25,12 +25,11 @@
#include <stdlib.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. */
va_list args;
va_start(args, array_size);
va_start(args, opcode_array);
/* Initialize array pointer and byte counter. */
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. */
while (true) {
/* Check to make sure we don't overrun array. */
if (bytes >= array_size)
return -1;
/* Next argument should be an opcode. */
char opcode = (char)va_arg(args, int);
*(current++) = opcode;

View File

@ -46,46 +46,27 @@
#define GUAC_SSH_TTY_OP_VERASE 3
/**
* The SSH protocol attempts to configure the remote
* terminal by sending pairs of opcodes and values, as
* described in Section 8 of RFC 4254. These are
* comprised of a single byte opcode and a 4-byte
* value. This data structure stores a single opcode
* and value pair.
* Macro for calculating the number of bytes required
* to pass a given number of opcodes, which calculates
* the size of the number of opcodes plus the single byte
* end opcode.
*/
typedef struct guac_ssh_ttymode {
/**
* 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;
#define GUAC_SSH_TTYMODES_SIZE(num_opcodes) ((GUAC_SSH_TTY_OPCODE_SIZE * num_opcodes) + 1)
/**
* Opcodes and value pairs are passed to the SSH connection
* in a single array, beginning with the opcode and followed
* by a four byte value, repeating until the end opcode is
* encountered. This function takes the array, the array
* size, and a variable number of opcode and value pair
* arguments and puts them in the array expected by the
* SSH connection.
* encountered. This function takes the array that will be
* sent and a variable number of opcode and value pair
* arguments and places the opcode and values in the array
* as expected by the SSH connection.
*
* @param opcode_array
* Pointer to the opcode array that will ultimately
* be passed to the SSH connection.
*
* @param array_size
* Size, in bytes, of the array.
* be passed to the SSH connection. The array must
* be size to handle 5 bytes for each opcode and value
* pair, plus one additional byte for the end opcode.
*
* @params ...
* 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
* 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