2013-12-29 04:53:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Glyptodon LLC
|
2011-08-04 18:46:21 +00:00
|
|
|
*
|
2013-12-29 04:53:12 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2011-08-04 18:46:21 +00:00
|
|
|
*
|
2013-12-29 04:53:12 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2011-08-04 18:46:21 +00:00
|
|
|
*
|
2013-12-29 04:53:12 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2011-08-04 18:46:21 +00:00
|
|
|
|
2011-08-10 07:02:06 +00:00
|
|
|
#include <sys/select.h>
|
2013-10-19 01:20:46 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2011-08-10 07:02:06 +00:00
|
|
|
|
2011-08-04 18:46:21 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <cairo/cairo.h>
|
|
|
|
#include <pango/pangocairo.h>
|
|
|
|
|
2011-11-26 23:35:45 +00:00
|
|
|
#include <guacamole/socket.h>
|
2011-08-04 18:46:21 +00:00
|
|
|
#include <guacamole/protocol.h>
|
|
|
|
#include <guacamole/client.h>
|
2013-05-18 03:20:51 +00:00
|
|
|
#include <guacamole/error.h>
|
2011-08-04 18:46:21 +00:00
|
|
|
|
2013-12-01 23:39:29 +00:00
|
|
|
#include <libssh2.h>
|
2013-05-26 06:05:58 +00:00
|
|
|
|
2013-05-18 03:28:26 +00:00
|
|
|
#include "guac_handlers.h"
|
|
|
|
#include "client.h"
|
2013-05-13 08:51:16 +00:00
|
|
|
#include "common.h"
|
2013-04-09 20:58:55 +00:00
|
|
|
#include "cursor.h"
|
2011-08-04 18:46:21 +00:00
|
|
|
|
|
|
|
int ssh_guac_client_handle_messages(guac_client* client) {
|
|
|
|
|
2011-11-26 23:35:45 +00:00
|
|
|
guac_socket* socket = client->socket;
|
2011-08-04 18:46:21 +00:00
|
|
|
ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data;
|
|
|
|
char buffer[8192];
|
|
|
|
|
2013-05-18 03:20:51 +00:00
|
|
|
int ret_val;
|
2013-05-22 05:02:11 +00:00
|
|
|
int fd = client_data->term->stdout_pipe_fd[0];
|
2011-08-04 18:46:21 +00:00
|
|
|
struct timeval timeout;
|
2011-08-10 07:02:06 +00:00
|
|
|
fd_set fds;
|
|
|
|
|
|
|
|
/* Build fd_set */
|
|
|
|
FD_ZERO(&fds);
|
2013-05-18 03:20:51 +00:00
|
|
|
FD_SET(fd, &fds);
|
2011-08-04 18:46:21 +00:00
|
|
|
|
|
|
|
/* Time to wait */
|
2011-11-26 23:35:45 +00:00
|
|
|
timeout.tv_sec = 1;
|
|
|
|
timeout.tv_usec = 0;
|
2011-08-04 18:46:21 +00:00
|
|
|
|
|
|
|
/* Wait for data to be available */
|
2013-05-18 03:20:51 +00:00
|
|
|
ret_val = select(fd+1, &fds, NULL, NULL, &timeout);
|
|
|
|
if (ret_val > 0) {
|
2011-08-04 18:46:21 +00:00
|
|
|
|
|
|
|
int bytes_read = 0;
|
|
|
|
|
2013-04-07 23:55:06 +00:00
|
|
|
/* Lock terminal access */
|
|
|
|
pthread_mutex_lock(&(client_data->term->lock));
|
|
|
|
|
2013-05-18 03:20:51 +00:00
|
|
|
/* Read data, write to terminal */
|
|
|
|
if ((bytes_read = read(fd, buffer, sizeof(buffer))) > 0) {
|
2011-08-04 18:46:21 +00:00
|
|
|
|
2013-05-18 03:20:51 +00:00
|
|
|
if (guac_terminal_write(client_data->term, buffer, bytes_read))
|
2011-08-10 01:32:54 +00:00
|
|
|
return 1;
|
2011-08-04 18:46:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Notify on error */
|
|
|
|
if (bytes_read < 0) {
|
2013-09-28 02:26:37 +00:00
|
|
|
guac_protocol_send_error(socket, "Error reading data.",
|
|
|
|
GUAC_PROTOCOL_STATUS_INTERNAL_ERROR);
|
2011-11-26 23:35:45 +00:00
|
|
|
guac_socket_flush(socket);
|
2011-08-04 18:46:21 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-05-15 19:46:26 +00:00
|
|
|
/* Update cursor */
|
|
|
|
guac_terminal_commit_cursor(client_data->term);
|
2013-03-27 11:11:56 +00:00
|
|
|
|
2013-04-25 18:55:50 +00:00
|
|
|
/* Flush terminal display */
|
|
|
|
guac_terminal_display_flush(client_data->term->display);
|
2013-03-29 09:51:31 +00:00
|
|
|
|
2013-04-07 23:55:06 +00:00
|
|
|
/* Unlock terminal access */
|
|
|
|
pthread_mutex_unlock(&(client_data->term->lock));
|
|
|
|
|
2013-03-29 09:51:31 +00:00
|
|
|
}
|
2013-05-18 03:20:51 +00:00
|
|
|
else if (ret_val < 0) {
|
|
|
|
guac_error_message = "Error waiting for pipe";
|
|
|
|
guac_error = GUAC_STATUS_SEE_ERRNO;
|
|
|
|
return 1;
|
|
|
|
}
|
2013-03-27 11:11:56 +00:00
|
|
|
|
2011-08-04 18:46:21 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-12-30 22:34:04 +00:00
|
|
|
int ssh_guac_client_clipboard_handler(guac_client* client, char* data) {
|
|
|
|
|
|
|
|
ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data;
|
|
|
|
|
|
|
|
free(client_data->clipboard_data);
|
|
|
|
|
|
|
|
client_data->clipboard_data = strdup(data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ssh_guac_client_mouse_handler(guac_client* client, int x, int y, int mask) {
|
|
|
|
|
|
|
|
ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data;
|
2013-04-05 08:32:33 +00:00
|
|
|
guac_terminal* term = client_data->term;
|
2011-12-30 22:34:04 +00:00
|
|
|
|
2013-04-15 08:22:05 +00:00
|
|
|
/* Determine which buttons were just released and pressed */
|
|
|
|
int released_mask = client_data->mouse_mask & ~mask;
|
|
|
|
int pressed_mask = ~client_data->mouse_mask & mask;
|
|
|
|
|
2011-12-30 22:34:04 +00:00
|
|
|
client_data->mouse_mask = mask;
|
|
|
|
|
2013-04-09 21:09:41 +00:00
|
|
|
/* Show mouse cursor if not already shown */
|
|
|
|
if (client_data->current_cursor != client_data->ibar_cursor) {
|
|
|
|
pthread_mutex_lock(&(term->lock));
|
|
|
|
|
|
|
|
client_data->current_cursor = client_data->ibar_cursor;
|
|
|
|
guac_ssh_set_cursor(client, client_data->ibar_cursor);
|
|
|
|
guac_socket_flush(client->socket);
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&(term->lock));
|
|
|
|
}
|
|
|
|
|
2013-05-26 07:17:31 +00:00
|
|
|
/* Paste contents of clipboard on right or middle mouse button up */
|
|
|
|
if ((released_mask & GUAC_CLIENT_MOUSE_RIGHT) || (released_mask & GUAC_CLIENT_MOUSE_MIDDLE)) {
|
|
|
|
if (client_data->clipboard_data != NULL)
|
|
|
|
return guac_terminal_send_string(term, client_data->clipboard_data);
|
|
|
|
else
|
|
|
|
return 0;
|
2013-04-01 08:59:15 +00:00
|
|
|
}
|
2011-12-30 22:34:04 +00:00
|
|
|
|
2013-04-15 08:22:05 +00:00
|
|
|
/* If text selected, change state based on left mouse mouse button */
|
|
|
|
if (term->text_selected) {
|
|
|
|
pthread_mutex_lock(&(term->lock));
|
|
|
|
|
|
|
|
/* If mouse button released, stop selection */
|
2013-05-06 18:06:21 +00:00
|
|
|
if (released_mask & GUAC_CLIENT_MOUSE_LEFT) {
|
|
|
|
|
|
|
|
/* End selection and get selected text */
|
|
|
|
char* string = malloc(term->term_width * term->term_height * sizeof(char));
|
|
|
|
guac_terminal_select_end(term, string);
|
|
|
|
|
|
|
|
/* Store new data */
|
|
|
|
free(client_data->clipboard_data);
|
|
|
|
client_data->clipboard_data = string;
|
|
|
|
|
|
|
|
/* Send data */
|
|
|
|
guac_protocol_send_clipboard(client->socket, string);
|
|
|
|
guac_socket_flush(client->socket);
|
|
|
|
|
|
|
|
}
|
2013-04-15 08:22:05 +00:00
|
|
|
|
|
|
|
/* Otherwise, just update */
|
|
|
|
else
|
|
|
|
guac_terminal_select_update(term,
|
2013-04-25 18:55:50 +00:00
|
|
|
y / term->display->char_height - term->scroll_offset,
|
|
|
|
x / term->display->char_width);
|
2013-04-15 08:22:05 +00:00
|
|
|
|
|
|
|
pthread_mutex_unlock(&(term->lock));
|
|
|
|
}
|
|
|
|
|
2013-05-15 19:08:05 +00:00
|
|
|
/* Otherwise, if mouse button pressed AND moved, start selection */
|
|
|
|
else if (!(pressed_mask & GUAC_CLIENT_MOUSE_LEFT) &&
|
|
|
|
mask & GUAC_CLIENT_MOUSE_LEFT) {
|
2013-04-15 08:22:05 +00:00
|
|
|
pthread_mutex_lock(&(term->lock));
|
|
|
|
|
|
|
|
guac_terminal_select_start(term,
|
2013-04-25 18:55:50 +00:00
|
|
|
y / term->display->char_height - term->scroll_offset,
|
|
|
|
x / term->display->char_width);
|
2013-04-15 08:22:05 +00:00
|
|
|
|
|
|
|
pthread_mutex_unlock(&(term->lock));
|
|
|
|
}
|
|
|
|
|
2013-04-01 08:59:15 +00:00
|
|
|
/* Scroll up if wheel moved up */
|
|
|
|
if (released_mask & GUAC_CLIENT_MOUSE_SCROLL_UP) {
|
2013-04-07 23:55:06 +00:00
|
|
|
pthread_mutex_lock(&(term->lock));
|
2013-04-08 07:47:08 +00:00
|
|
|
guac_terminal_scroll_display_up(term, GUAC_SSH_WHEEL_SCROLL_AMOUNT);
|
2013-04-07 23:55:06 +00:00
|
|
|
pthread_mutex_unlock(&(term->lock));
|
2013-04-01 08:59:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Scroll down if wheel moved down */
|
|
|
|
if (released_mask & GUAC_CLIENT_MOUSE_SCROLL_DOWN) {
|
2013-04-07 23:55:06 +00:00
|
|
|
pthread_mutex_lock(&(term->lock));
|
2013-04-08 07:47:08 +00:00
|
|
|
guac_terminal_scroll_display_down(term, GUAC_SSH_WHEEL_SCROLL_AMOUNT);
|
2013-04-07 23:55:06 +00:00
|
|
|
pthread_mutex_unlock(&(term->lock));
|
2011-12-30 22:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2013-04-01 08:59:15 +00:00
|
|
|
|
2011-12-30 22:34:04 +00:00
|
|
|
}
|
|
|
|
|
2011-08-04 18:46:21 +00:00
|
|
|
int ssh_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
|
|
|
|
|
|
|
|
ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data;
|
2013-04-08 07:47:08 +00:00
|
|
|
guac_terminal* term = client_data->term;
|
2011-08-04 18:46:21 +00:00
|
|
|
|
2013-04-09 21:09:41 +00:00
|
|
|
/* Hide mouse cursor if not already hidden */
|
|
|
|
if (client_data->current_cursor != client_data->blank_cursor) {
|
|
|
|
pthread_mutex_lock(&(term->lock));
|
|
|
|
|
|
|
|
client_data->current_cursor = client_data->blank_cursor;
|
|
|
|
guac_ssh_set_cursor(client, client_data->blank_cursor);
|
|
|
|
guac_socket_flush(client->socket);
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&(term->lock));
|
|
|
|
}
|
|
|
|
|
2011-08-22 06:24:40 +00:00
|
|
|
/* Track modifiers */
|
2013-05-26 05:45:26 +00:00
|
|
|
if (keysym == 0xFFE3)
|
2011-08-22 06:24:40 +00:00
|
|
|
client_data->mod_ctrl = pressed;
|
2013-05-26 05:45:26 +00:00
|
|
|
else if (keysym == 0xFFE9)
|
|
|
|
client_data->mod_alt = pressed;
|
2013-05-26 07:17:31 +00:00
|
|
|
else if (keysym == 0xFFE1)
|
|
|
|
client_data->mod_shift = pressed;
|
2011-08-22 06:24:40 +00:00
|
|
|
|
2011-08-04 18:46:21 +00:00
|
|
|
/* If key pressed */
|
2011-08-22 06:24:40 +00:00
|
|
|
else if (pressed) {
|
2011-08-04 18:46:21 +00:00
|
|
|
|
2013-05-26 07:17:31 +00:00
|
|
|
/* Ctrl+Shift+V shortcut for paste */
|
|
|
|
if (keysym == 'V' && client_data->mod_ctrl) {
|
|
|
|
if (client_data->clipboard_data != NULL)
|
|
|
|
return guac_terminal_send_string(term, client_data->clipboard_data);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Shift+PgUp / Shift+PgDown shortcuts for scrolling */
|
|
|
|
if (client_data->mod_shift) {
|
|
|
|
|
|
|
|
/* Page up */
|
|
|
|
if (keysym == 0xFF55) {
|
|
|
|
pthread_mutex_lock(&(term->lock));
|
|
|
|
guac_terminal_scroll_display_up(term, term->term_height);
|
|
|
|
pthread_mutex_unlock(&(term->lock));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Page down */
|
|
|
|
if (keysym == 0xFF56) {
|
|
|
|
pthread_mutex_lock(&(term->lock));
|
|
|
|
guac_terminal_scroll_display_down(term, term->term_height);
|
|
|
|
pthread_mutex_unlock(&(term->lock));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-08 07:47:08 +00:00
|
|
|
/* Reset scroll */
|
|
|
|
if (term->scroll_offset != 0) {
|
|
|
|
pthread_mutex_lock(&(term->lock));
|
|
|
|
guac_terminal_scroll_display_down(term, term->scroll_offset);
|
|
|
|
pthread_mutex_unlock(&(term->lock));
|
|
|
|
}
|
|
|
|
|
2013-05-26 05:45:26 +00:00
|
|
|
/* If alt being held, also send escape character */
|
|
|
|
if (client_data->mod_alt)
|
|
|
|
return guac_terminal_send_string(term, "\x1B");
|
|
|
|
|
2013-05-13 08:51:16 +00:00
|
|
|
/* Translate Ctrl+letter to control code */
|
|
|
|
if (client_data->mod_ctrl) {
|
2011-08-22 06:24:40 +00:00
|
|
|
|
2013-05-13 08:51:16 +00:00
|
|
|
char data;
|
|
|
|
|
|
|
|
/* If valid control code, send it */
|
|
|
|
if (keysym >= 'A' && keysym <= 'Z')
|
|
|
|
data = (char) (keysym - 'A' + 1);
|
|
|
|
else if (keysym >= 'a' && keysym <= 'z')
|
|
|
|
data = (char) (keysym - 'a' + 1);
|
|
|
|
|
|
|
|
/* Otherwise ignore */
|
|
|
|
else
|
|
|
|
return 0;
|
2011-08-22 06:24:40 +00:00
|
|
|
|
2013-05-26 05:45:26 +00:00
|
|
|
return guac_terminal_send_data(term, &data, 1);
|
2011-08-22 06:24:40 +00:00
|
|
|
|
2011-08-10 18:03:38 +00:00
|
|
|
}
|
|
|
|
|
2013-05-13 08:51:16 +00:00
|
|
|
/* Translate Unicode to UTF-8 */
|
|
|
|
else if ((keysym >= 0x00 && keysym <= 0xFF) || ((keysym & 0xFFFF0000) == 0x01000000)) {
|
|
|
|
|
|
|
|
int length;
|
|
|
|
char data[5];
|
|
|
|
|
|
|
|
length = guac_terminal_encode_utf8(keysym & 0xFFFF, data);
|
2013-05-26 05:45:26 +00:00
|
|
|
return guac_terminal_send_data(term, data, length);
|
2013-05-13 08:51:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-26 05:45:26 +00:00
|
|
|
/* Non-printable keys */
|
2011-08-10 18:03:38 +00:00
|
|
|
else {
|
2011-08-04 18:46:21 +00:00
|
|
|
|
2013-05-26 05:45:26 +00:00
|
|
|
if (keysym == 0xFF08) return guac_terminal_send_string(term, "\x7F"); /* Backspace */
|
|
|
|
if (keysym == 0xFF09) return guac_terminal_send_string(term, "\x09"); /* Tab */
|
|
|
|
if (keysym == 0xFF0D) return guac_terminal_send_string(term, "\x0D"); /* Enter */
|
|
|
|
if (keysym == 0xFF1B) return guac_terminal_send_string(term, "\x1B"); /* Esc */
|
2011-08-04 18:46:21 +00:00
|
|
|
|
2013-05-26 07:49:06 +00:00
|
|
|
if (keysym == 0xFF50) return guac_terminal_send_string(term, "\x1B[1~"); /* Home */
|
2011-08-04 18:46:21 +00:00
|
|
|
|
2013-05-26 05:45:26 +00:00
|
|
|
/* Arrow keys w/ application cursor */
|
|
|
|
if (term->application_cursor_keys) {
|
|
|
|
if (keysym == 0xFF51) return guac_terminal_send_string(term, "\x1BOD"); /* Left */
|
|
|
|
if (keysym == 0xFF52) return guac_terminal_send_string(term, "\x1BOA"); /* Up */
|
|
|
|
if (keysym == 0xFF53) return guac_terminal_send_string(term, "\x1BOC"); /* Right */
|
|
|
|
if (keysym == 0xFF54) return guac_terminal_send_string(term, "\x1BOB"); /* Down */
|
2013-05-22 18:08:38 +00:00
|
|
|
}
|
2013-05-26 05:45:26 +00:00
|
|
|
else {
|
|
|
|
if (keysym == 0xFF51) return guac_terminal_send_string(term, "\x1B[D"); /* Left */
|
|
|
|
if (keysym == 0xFF52) return guac_terminal_send_string(term, "\x1B[A"); /* Up */
|
|
|
|
if (keysym == 0xFF53) return guac_terminal_send_string(term, "\x1B[C"); /* Right */
|
|
|
|
if (keysym == 0xFF54) return guac_terminal_send_string(term, "\x1B[B"); /* Down */
|
2013-05-22 18:08:38 +00:00
|
|
|
}
|
|
|
|
|
2013-05-26 07:49:06 +00:00
|
|
|
if (keysym == 0xFF55) return guac_terminal_send_string(term, "\x1B[5~"); /* Page up */
|
|
|
|
if (keysym == 0xFF56) return guac_terminal_send_string(term, "\x1B[6~"); /* Page down */
|
|
|
|
if (keysym == 0xFF57) return guac_terminal_send_string(term, "\x1B[4~"); /* End */
|
2013-05-22 18:08:38 +00:00
|
|
|
|
2013-05-26 05:45:26 +00:00
|
|
|
if (keysym == 0xFF63) return guac_terminal_send_string(term, "\x1B[2~"); /* Insert */
|
|
|
|
|
2013-05-26 07:49:06 +00:00
|
|
|
if (keysym == 0xFFBE) return guac_terminal_send_string(term, "\x1B[[A"); /* F1 */
|
|
|
|
if (keysym == 0xFFBF) return guac_terminal_send_string(term, "\x1B[[B"); /* F2 */
|
|
|
|
if (keysym == 0xFFC0) return guac_terminal_send_string(term, "\x1B[[C"); /* F3 */
|
|
|
|
if (keysym == 0xFFC1) return guac_terminal_send_string(term, "\x1B[[D"); /* F4 */
|
|
|
|
if (keysym == 0xFFC2) return guac_terminal_send_string(term, "\x1B[[E"); /* F5 */
|
2013-05-22 18:08:38 +00:00
|
|
|
|
2013-05-26 05:45:26 +00:00
|
|
|
if (keysym == 0xFFC3) return guac_terminal_send_string(term, "\x1B[17~"); /* F6 */
|
|
|
|
if (keysym == 0xFFC4) return guac_terminal_send_string(term, "\x1B[18~"); /* F7 */
|
|
|
|
if (keysym == 0xFFC5) return guac_terminal_send_string(term, "\x1B[19~"); /* F8 */
|
|
|
|
if (keysym == 0xFFC6) return guac_terminal_send_string(term, "\x1B[20~"); /* F9 */
|
|
|
|
if (keysym == 0xFFC7) return guac_terminal_send_string(term, "\x1B[21~"); /* F10 */
|
|
|
|
if (keysym == 0xFFC8) return guac_terminal_send_string(term, "\x1B[22~"); /* F11 */
|
|
|
|
if (keysym == 0xFFC9) return guac_terminal_send_string(term, "\x1B[23~"); /* F12 */
|
2011-08-10 18:03:38 +00:00
|
|
|
|
2013-05-26 05:45:26 +00:00
|
|
|
if (keysym == 0xFFFF) return guac_terminal_send_string(term, "\x1B[3~"); /* Delete */
|
2012-12-17 01:51:49 +00:00
|
|
|
|
2013-05-26 05:45:26 +00:00
|
|
|
/* Ignore unknown keys */
|
2011-08-10 18:03:38 +00:00
|
|
|
}
|
2011-08-04 18:46:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-01 23:54:29 +00:00
|
|
|
int ssh_guac_client_size_handler(guac_client* client, int width, int height) {
|
|
|
|
|
|
|
|
/* Get terminal */
|
|
|
|
ssh_guac_client_data* guac_client_data = (ssh_guac_client_data*) client->data;
|
|
|
|
guac_terminal* terminal = guac_client_data->term;
|
|
|
|
|
|
|
|
/* Calculate dimensions */
|
|
|
|
int rows = height / terminal->display->char_height;
|
|
|
|
int columns = width / terminal->display->char_width;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&(terminal->lock));
|
|
|
|
|
|
|
|
/* If size has changed */
|
|
|
|
if (columns != terminal->term_width || rows != terminal->term_height) {
|
|
|
|
|
|
|
|
/* Resize terminal */
|
|
|
|
guac_terminal_resize(terminal, columns, rows);
|
2013-05-18 03:20:51 +00:00
|
|
|
|
2013-05-20 17:27:53 +00:00
|
|
|
/* Update SSH pty size if connected */
|
|
|
|
if (guac_client_data->term_channel != NULL)
|
2013-12-01 23:39:29 +00:00
|
|
|
libssh2_channel_request_pty_size(guac_client_data->term_channel,
|
2013-05-20 17:27:53 +00:00
|
|
|
terminal->term_width, terminal->term_height);
|
2013-05-01 23:54:29 +00:00
|
|
|
|
|
|
|
/* Reset scroll region */
|
|
|
|
terminal->scroll_end = rows - 1;
|
|
|
|
|
2013-05-20 17:27:53 +00:00
|
|
|
guac_terminal_display_flush(terminal->display);
|
2013-08-22 22:16:49 +00:00
|
|
|
guac_protocol_send_sync(terminal->client->socket,
|
|
|
|
client->last_sent_timestamp);
|
2013-05-20 17:27:53 +00:00
|
|
|
guac_socket_flush(terminal->client->socket);
|
2013-05-01 23:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&(terminal->lock));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-30 22:34:04 +00:00
|
|
|
int ssh_guac_client_free_handler(guac_client* client) {
|
|
|
|
|
|
|
|
ssh_guac_client_data* guac_client_data = (ssh_guac_client_data*) client->data;
|
|
|
|
|
2013-05-26 06:05:58 +00:00
|
|
|
/* Close SSH channel */
|
2013-05-26 06:50:13 +00:00
|
|
|
if (guac_client_data->term_channel != NULL) {
|
2013-12-01 23:39:29 +00:00
|
|
|
libssh2_channel_send_eof(guac_client_data->term_channel);
|
|
|
|
libssh2_channel_close(guac_client_data->term_channel);
|
2013-05-26 06:50:13 +00:00
|
|
|
}
|
2013-05-26 06:05:58 +00:00
|
|
|
|
2011-12-30 22:34:04 +00:00
|
|
|
/* Free terminal */
|
2012-12-09 08:35:37 +00:00
|
|
|
guac_terminal_free(guac_client_data->term);
|
2013-05-22 05:02:11 +00:00
|
|
|
pthread_join(guac_client_data->client_thread, NULL);
|
2011-12-30 22:34:04 +00:00
|
|
|
|
2013-05-26 06:05:58 +00:00
|
|
|
/* Free channels */
|
2013-12-01 23:39:29 +00:00
|
|
|
libssh2_channel_free(guac_client_data->term_channel);
|
2013-05-26 06:05:58 +00:00
|
|
|
|
2013-10-18 22:37:16 +00:00
|
|
|
/* Clean up SFTP */
|
|
|
|
if (guac_client_data->sftp_session)
|
2013-12-01 23:39:29 +00:00
|
|
|
libssh2_sftp_shutdown(guac_client_data->sftp_session);
|
2013-10-18 22:37:16 +00:00
|
|
|
|
2013-12-01 23:39:29 +00:00
|
|
|
if (guac_client_data->sftp_ssh_session) {
|
|
|
|
libssh2_session_disconnect(guac_client_data->sftp_ssh_session, "Bye");
|
|
|
|
libssh2_session_free(guac_client_data->sftp_ssh_session);
|
|
|
|
}
|
2013-10-19 05:05:03 +00:00
|
|
|
|
2013-05-26 06:05:58 +00:00
|
|
|
/* Free session */
|
2013-12-02 00:09:48 +00:00
|
|
|
if (guac_client_data->session != NULL)
|
|
|
|
libssh2_session_free(guac_client_data->session);
|
2013-05-26 06:05:58 +00:00
|
|
|
|
2013-10-30 22:46:13 +00:00
|
|
|
/* Free auth key */
|
|
|
|
if (guac_client_data->key != NULL)
|
|
|
|
ssh_key_free(guac_client_data->key);
|
|
|
|
|
2011-12-30 22:34:04 +00:00
|
|
|
/* Free clipboard data */
|
|
|
|
free(guac_client_data->clipboard_data);
|
|
|
|
|
2013-04-09 20:58:55 +00:00
|
|
|
/* Free cursors */
|
|
|
|
guac_ssh_cursor_free(client, guac_client_data->ibar_cursor);
|
2013-04-09 21:02:52 +00:00
|
|
|
guac_ssh_cursor_free(client, guac_client_data->blank_cursor);
|
2013-04-09 20:58:55 +00:00
|
|
|
|
2011-12-30 22:34:04 +00:00
|
|
|
/* Free generic data struct */
|
|
|
|
free(client->data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|