GUAC-654: Add negotiation and handling of NAWS (window size).

This commit is contained in:
Michael Jumper 2014-05-07 14:19:17 -07:00
parent a7d1dde24f
commit 30a31d07cf
5 changed files with 44 additions and 10 deletions

View File

@ -85,6 +85,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
client->data = client_data; client->data = client_data;
client_data->telnet = NULL; client_data->telnet = NULL;
client_data->socket_fd = -1; client_data->socket_fd = -1;
client_data->naws_enabled = 0;
if (argc != TELNET_ARGS_COUNT) { if (argc != TELNET_ARGS_COUNT) {
guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Wrong number of arguments"); guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Wrong number of arguments");

View File

@ -72,6 +72,11 @@ typedef struct telnet_client_data {
*/ */
telnet_t* telnet; telnet_t* telnet;
/**
* Whether window size should be sent when the window is resized.
*/
int naws_enabled;
/** /**
* The terminal which will render all output from the telnet client. * The terminal which will render all output from the telnet client.
*/ */

View File

@ -25,6 +25,7 @@
#include "client.h" #include "client.h"
#include "guac_handlers.h" #include "guac_handlers.h"
#include "terminal.h" #include "terminal.h"
#include "telnet_client.h"
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
@ -70,9 +71,6 @@ int telnet_guac_client_key_handler(guac_client* client, int keysym, int pressed)
int telnet_guac_client_size_handler(guac_client* client, int width, int height) { int telnet_guac_client_size_handler(guac_client* client, int width, int height) {
/* STUB */
#if 0
/* Get terminal */ /* Get terminal */
telnet_client_data* guac_client_data = (telnet_client_data*) client->data; telnet_client_data* guac_client_data = (telnet_client_data*) client->data;
guac_terminal* terminal = guac_client_data->term; guac_terminal* terminal = guac_client_data->term;
@ -80,11 +78,9 @@ int telnet_guac_client_size_handler(guac_client* client, int width, int height)
/* Resize terminal */ /* Resize terminal */
guac_terminal_resize(terminal, width, height); guac_terminal_resize(terminal, width, height);
/* Update SSH pty size if connected */ /* Update terminal window size if connected */
if (guac_client_data->term_channel != NULL) if (guac_client_data->telnet != NULL && guac_client_data->naws_enabled)
libssh2_channel_request_pty_size(guac_client_data->term_channel, guac_telnet_send_naws(guac_client_data->telnet, terminal->term_width, terminal->term_height);
terminal->term_width, terminal->term_height);
#endif
return 0; return 0;
} }

View File

@ -24,12 +24,12 @@
#include "client.h" #include "client.h"
#include "guac_handlers.h" #include "guac_handlers.h"
#include "telnet_client.h"
#include <errno.h> #include <errno.h>
#include <netdb.h> #include <netdb.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <pthread.h> #include <pthread.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/select.h> #include <sys/select.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -46,6 +46,7 @@ static const telnet_telopt_t __telnet_options[] = {
{ TELNET_TELOPT_TTYPE, TELNET_WILL, TELNET_DONT }, { TELNET_TELOPT_TTYPE, TELNET_WILL, TELNET_DONT },
{ TELNET_TELOPT_COMPRESS2, TELNET_WONT, TELNET_DO }, { TELNET_TELOPT_COMPRESS2, TELNET_WONT, TELNET_DO },
{ TELNET_TELOPT_MSSP, TELNET_WONT, TELNET_DO }, { TELNET_TELOPT_MSSP, TELNET_WONT, TELNET_DO },
{ TELNET_TELOPT_NAWS, TELNET_WILL, TELNET_DONT },
{ -1, 0, 0 } { -1, 0, 0 }
}; };
@ -87,6 +88,14 @@ static void __guac_telnet_event_handler(telnet_t* telnet, telnet_event_t* event,
guac_client_stop(client); guac_client_stop(client);
break; break;
/* Feature enable */
case TELNET_EV_DO:
if (event->neg.telopt == TELNET_TELOPT_NAWS) {
client_data->naws_enabled = 1;
guac_telnet_send_naws(telnet, client_data->term->term_width, client_data->term->term_height);
}
break;
/* Terminal type request */ /* Terminal type request */
case TELNET_EV_TTYPE: case TELNET_EV_TTYPE:
if (event->ttype.cmd == TELNET_TTYPE_SEND) if (event->ttype.cmd == TELNET_TTYPE_SEND)
@ -112,7 +121,7 @@ static void __guac_telnet_event_handler(telnet_t* telnet, telnet_event_t* event,
} }
void* telnet_input_thread(void* data) { static void* telnet_input_thread(void* data) {
guac_client* client = (guac_client*) data; guac_client* client = (guac_client*) data;
telnet_client_data* client_data = (telnet_client_data*) client->data; telnet_client_data* client_data = (telnet_client_data*) client->data;
@ -218,6 +227,23 @@ static telnet_t* __guac_telnet_create_session(guac_client* client) {
} }
static void __guac_telnet_send_uint16(telnet_t* telnet, uint16_t value) {
unsigned char buffer[2];
buffer[0] = (value >> 8) & 0xFF;
buffer[1] = value & 0xFF;
telnet_send(telnet, (char*) buffer, 2);
}
void guac_telnet_send_naws(telnet_t* telnet, uint16_t width, uint16_t height) {
telnet_begin_sb(telnet, TELNET_TELOPT_NAWS);
__guac_telnet_send_uint16(telnet, width);
__guac_telnet_send_uint16(telnet, height);
telnet_finish_sb(telnet);
}
void* telnet_client_thread(void* data) { void* telnet_client_thread(void* data) {
guac_client* client = (guac_client*) data; guac_client* client = (guac_client*) data;

View File

@ -33,5 +33,11 @@
*/ */
void* telnet_client_thread(void* data); void* telnet_client_thread(void* data);
/**
* Send a telnet NAWS message indicating the given terminal window dimensions
* in characters.
*/
void guac_telnet_send_naws(telnet_t* telnet, uint16_t width, uint16_t height);
#endif #endif