Conversion to new libguac API.

This commit is contained in:
Michael Jumper 2011-11-26 15:35:45 -08:00
parent ff8e245028
commit 3515ec9021
8 changed files with 59 additions and 87 deletions

View File

@ -35,7 +35,7 @@
# ***** END LICENSE BLOCK *****
AC_INIT(src/ssh_client.c)
AM_INIT_AUTOMAKE([libguac-client-ssh], 0.4.0)
AM_INIT_AUTOMAKE([libguac-client-ssh], 0.5.0)
AC_CONFIG_MACRO_DIR([m4])
# Checks for programs.
@ -44,7 +44,7 @@ AC_PROG_CC_C99
AC_PROG_LIBTOOL
# Checks for libraries.
AC_CHECK_LIB([guac], [guac_get_client],, AC_MSG_ERROR("libguac is required for communication via the guacamole protocol"))
AC_CHECK_LIB([guac], [guac_client_plugin_open],, AC_MSG_ERROR("libguac must be installed first"))
AC_CHECK_LIB([cairo], [cairo_create],, AC_MSG_ERROR("cairo is required for drawing instructions"))
AC_CHECK_LIB([ssh], [ssh_new],, AC_MSG_ERROR("libssh is required"))
PKG_CHECK_MODULES([PANGO], pango);

View File

@ -38,17 +38,8 @@
#ifndef _SSH_GUAC_CLIENT_H
#define _SSH_GUAC_CLIENT_H
#include <stdlib.h>
#include <string.h>
#include <libssh/libssh.h>
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
#include <guacamole/log.h>
#include <guacamole/guacio.h>
#include <guacamole/protocol.h>
#include <guacamole/client.h>
#include "ssh_client.h"

View File

@ -40,9 +40,6 @@
#include <pango/pangocairo.h>
#include <guacamole/log.h>
#include <guacamole/guacio.h>
#include <guacamole/protocol.h>
#include <guacamole/client.h>
typedef struct ssh_guac_terminal ssh_guac_terminal;

View File

@ -38,17 +38,6 @@
#ifndef _SSH_GUAC_TERMINAL_HANDLERS
#define _SSH_GUAC_TERMINAL_HANDLERS
#include <stdlib.h>
#include <string.h>
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
#include <guacamole/log.h>
#include <guacamole/guacio.h>
#include <guacamole/protocol.h>
#include <guacamole/client.h>
#include "ssh_terminal.h"
int ssh_guac_terminal_echo(ssh_guac_terminal* term, char c);

View File

@ -40,8 +40,7 @@
#include <libssh/libssh.h>
#include <guacamole/log.h>
#include <guacamole/guacio.h>
#include <guacamole/socket.h>
#include <guacamole/protocol.h>
#include <guacamole/client.h>
@ -70,7 +69,7 @@ int ssh_guac_client_password_key_handler(guac_client* client, int keysym, int pr
client_data->password[client_data->password_length++] = keysym;
ssh_guac_terminal_write(client_data->term, "*", 1);
ssh_guac_terminal_redraw_cursor(client_data->term);
guac_flush(client->io);
guac_socket_flush(client->socket);
}
else if (keysym == 0xFF08) {
@ -80,7 +79,7 @@ int ssh_guac_client_password_key_handler(guac_client* client, int keysym, int pr
/* Backspace */
ssh_guac_terminal_write(client_data->term, "\x08\x1B[K", 4);
ssh_guac_terminal_redraw_cursor(client_data->term);
guac_flush(client->io);
guac_socket_flush(client->socket);
}
}
@ -92,7 +91,7 @@ int ssh_guac_client_password_key_handler(guac_client* client, int keysym, int pr
/* Clear screen */
ssh_guac_terminal_write(client_data->term, "\x1B[2J\x1B[1;1H", 10);
ssh_guac_terminal_redraw_cursor(client_data->term);
guac_flush(client->io);
guac_socket_flush(client->socket);
return ssh_guac_client_auth(client, client_data->password);
@ -106,7 +105,7 @@ int ssh_guac_client_password_key_handler(guac_client* client, int keysym, int pr
int guac_client_init(guac_client* client, int argc, char** argv) {
GUACIO* io = client->io;
guac_socket* socket = client->socket;
ssh_guac_client_data* client_data = malloc(sizeof(ssh_guac_client_data));
ssh_guac_terminal* term = ssh_guac_terminal_create(client);
@ -117,18 +116,18 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
client_data->mod_ctrl = 0;
/* Send name and dimensions */
guac_send_name(io, "SSH TEST");
guac_send_size(io,
guac_protocol_send_name(socket, "SSH TEST");
guac_protocol_send_size(socket,
term->char_width * term->term_width,
term->char_height * term->term_height);
guac_flush(io);
guac_socket_flush(socket);
/* Open SSH session */
client_data->session = ssh_new();
if (client_data->session == NULL) {
guac_send_error(io, "Unable to create SSH session.");
guac_flush(io);
guac_protocol_send_error(socket, "Unable to create SSH session.");
guac_socket_flush(socket);
return 1;
}
@ -138,8 +137,8 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
/* Connect */
if (ssh_connect(client_data->session) != SSH_OK) {
guac_send_error(io, "Unable to connect via SSH.");
guac_flush(io);
guac_protocol_send_error(socket, "Unable to connect via SSH.");
guac_socket_flush(socket);
return 1;
}
@ -153,7 +152,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
client_data->password_length = 0;
ssh_guac_terminal_write(client_data->term, "Password: ", 10);
ssh_guac_terminal_redraw_cursor(client_data->term);
guac_flush(client->io);
guac_socket_flush(client->socket);
client->key_handler = ssh_guac_client_password_key_handler;
@ -166,54 +165,54 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
int ssh_guac_client_auth(guac_client* client, const char* password) {
GUACIO* io = client->io;
guac_socket* socket = client->socket;
ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data;
ssh_guac_terminal* term = client_data->term;
/* Authenticate */
if (ssh_userauth_password(client_data->session, NULL, password) != SSH_AUTH_SUCCESS) {
guac_send_error(io, "SSH auth failed.");
guac_flush(io);
guac_protocol_send_error(socket, "SSH auth failed.");
guac_socket_flush(socket);
return 1;
}
/* Open channel for terminal */
client_data->term_channel = channel_new(client_data->session);
if (client_data->term_channel == NULL) {
guac_send_error(io, "Unable to open channel.");
guac_flush(io);
guac_protocol_send_error(socket, "Unable to open channel.");
guac_socket_flush(socket);
return 1;
}
/* Open session for channel */
if (channel_open_session(client_data->term_channel) != SSH_OK) {
guac_send_error(io, "Unable to open channel session.");
guac_flush(io);
guac_protocol_send_error(socket, "Unable to open channel session.");
guac_socket_flush(socket);
return 1;
}
/* Request PTY */
if (channel_request_pty(client_data->term_channel) != SSH_OK) {
guac_send_error(io, "Unable to allocate PTY for channel.");
guac_flush(io);
guac_protocol_send_error(socket, "Unable to allocate PTY for channel.");
guac_socket_flush(socket);
return 1;
}
/* Request PTY size */
if (channel_change_pty_size(client_data->term_channel, term->term_width, term->term_height) != SSH_OK) {
guac_send_error(io, "Unable to change PTY size.");
guac_flush(io);
guac_protocol_send_error(socket, "Unable to change PTY size.");
guac_socket_flush(socket);
return 1;
}
/* Request shell */
if (channel_request_shell(client_data->term_channel) != SSH_OK) {
guac_send_error(io, "Unable to associate shell with PTY.");
guac_flush(io);
guac_protocol_send_error(socket, "Unable to associate shell with PTY.");
guac_socket_flush(socket);
return 1;
}
guac_log_info("SSH connection successful.");
guac_client_log_info(client, "SSH connection successful.");
/* Set handlers */
client->handle_messages = ssh_guac_client_handle_messages;

View File

@ -45,8 +45,7 @@
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
#include <guacamole/log.h>
#include <guacamole/guacio.h>
#include <guacamole/socket.h>
#include <guacamole/protocol.h>
#include <guacamole/client.h>
@ -55,7 +54,7 @@
int ssh_guac_client_handle_messages(guac_client* client) {
GUACIO* io = client->io;
guac_socket* socket = client->socket;
ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data;
char buffer[8192];
@ -76,8 +75,8 @@ int ssh_guac_client_handle_messages(guac_client* client) {
FD_SET(ssh_fd, &fds);
/* Time to wait */
timeout.tv_sec = GUAC_SYNC_FREQUENCY / 1000;
timeout.tv_usec = (GUAC_SYNC_FREQUENCY % 1000) * 1000;
timeout.tv_sec = 1;
timeout.tv_usec = 0;
/* Wait for data to be available */
if (ssh_select(channels, out_channels, ssh_fd+1, &fds, &timeout)
@ -92,15 +91,15 @@ int ssh_guac_client_handle_messages(guac_client* client) {
if (ssh_guac_terminal_write(client_data->term, buffer, bytes_read)
|| ssh_guac_terminal_redraw_cursor(client_data->term)
|| guac_flush(io))
|| guac_socket_flush(socket))
return 1;
}
/* Notify on error */
if (bytes_read < 0) {
guac_send_error(io, "Error reading data.");
guac_flush(io);
guac_protocol_send_error(socket, "Error reading data.");
guac_socket_flush(socket);
return 1;
}
}

View File

@ -41,8 +41,7 @@
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
#include <guacamole/log.h>
#include <guacamole/guacio.h>
#include <guacamole/socket.h>
#include <guacamole/protocol.h>
#include <guacamole/client.h>
@ -139,13 +138,13 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client) {
font = pango_font_map_load_font(font_map, context, term->font_desc);
if (font == NULL) {
guac_log_error("Unable to get font.");
guac_client_log_error(term->client, "Unable to get font.");
return NULL;
}
metrics = pango_font_get_metrics(font, NULL);
if (metrics == NULL) {
guac_log_error("Unable to get font metrics.");
guac_client_log_error(term->client, "Unable to get font metrics.");
return NULL;
}
@ -171,7 +170,7 @@ void ssh_guac_terminal_free(ssh_guac_terminal* term) {
int __ssh_guac_terminal_get_glyph(ssh_guac_terminal* term, char c) {
GUACIO* io = term->client->io;
guac_socket* socket = term->client->socket;
int location;
/* Use foreground color */
@ -219,9 +218,9 @@ int __ssh_guac_terminal_get_glyph(ssh_guac_terminal* term, char c) {
cairo_destroy(cairo);
/* Send glyph and update filled flyphs */
guac_send_png(io, GUAC_COMP_OVER, term->glyph_stroke, location * term->char_width, 0, surface);
guac_protocol_send_png(socket, GUAC_COMP_OVER, term->glyph_stroke, location * term->char_width, 0, surface);
guac_send_rect(io, GUAC_COMP_OVER, term->filled_glyphs,
guac_protocol_send_rect(socket, GUAC_COMP_OVER, term->filled_glyphs,
location * term->char_width, 0,
term->char_width, term->char_height,
background->red,
@ -229,7 +228,7 @@ int __ssh_guac_terminal_get_glyph(ssh_guac_terminal* term, char c) {
background->blue,
0xFF);
guac_send_copy(io, term->glyph_stroke,
guac_protocol_send_copy(socket, term->glyph_stroke,
location * term->char_width, 0, term->char_width, term->char_height,
GUAC_COMP_OVER, term->filled_glyphs, location * term->char_width, 0);
@ -244,11 +243,11 @@ int __ssh_guac_terminal_get_glyph(ssh_guac_terminal* term, char c) {
int ssh_guac_terminal_redraw_cursor(ssh_guac_terminal* term) {
GUACIO* io = term->client->io;
guac_socket* socket = term->client->socket;
/* Erase old cursor */
return
guac_send_rect(io,
guac_protocol_send_rect(socket,
GUAC_COMP_ROUT, term->cursor_layer,
0, 0,
@ -257,7 +256,7 @@ int ssh_guac_terminal_redraw_cursor(ssh_guac_terminal* term) {
0, 0, 0, 0xFF)
|| guac_send_rect(io,
|| guac_protocol_send_rect(socket,
GUAC_COMP_OVER, term->cursor_layer,
term->char_width * term->cursor_col,
@ -272,7 +271,7 @@ int ssh_guac_terminal_redraw_cursor(ssh_guac_terminal* term) {
int ssh_guac_terminal_set_colors(ssh_guac_terminal* term,
int foreground, int background) {
GUACIO* io = term->client->io;
guac_socket* socket = term->client->socket;
const ssh_guac_terminal_color* background_color;
/* Get background color */
@ -286,7 +285,7 @@ int ssh_guac_terminal_set_colors(ssh_guac_terminal* term,
&ssh_guac_terminal_palette[foreground];
/* Colorize letter */
guac_send_rect(io,
guac_protocol_send_rect(socket,
GUAC_COMP_ATOP, term->glyph_stroke,
0, 0,
@ -303,7 +302,7 @@ int ssh_guac_terminal_set_colors(ssh_guac_terminal* term,
if (foreground != term->glyph_foreground || background != term->glyph_background) {
/* Set background */
guac_send_rect(io,
guac_protocol_send_rect(socket,
GUAC_COMP_OVER, term->filled_glyphs,
0, 0,
@ -315,7 +314,7 @@ int ssh_guac_terminal_set_colors(ssh_guac_terminal* term,
255);
/* Copy stroke */
guac_send_copy(io, term->glyph_stroke,
guac_protocol_send_copy(socket, term->glyph_stroke,
0, 0,
term->char_width * term->next_glyph, term->char_height,
@ -334,10 +333,10 @@ int ssh_guac_terminal_set_colors(ssh_guac_terminal* term,
int ssh_guac_terminal_set(ssh_guac_terminal* term, int row, int col, char c) {
GUACIO* io = term->client->io;
guac_socket* socket = term->client->socket;
int location = __ssh_guac_terminal_get_glyph(term, c);
return guac_send_copy(io,
return guac_protocol_send_copy(socket,
term->filled_glyphs,
location * term->char_width, 0, term->char_width, term->char_height,
GUAC_COMP_OVER, GUAC_DEFAULT_LAYER,
@ -361,10 +360,10 @@ int ssh_guac_terminal_copy(ssh_guac_terminal* term,
int src_row, int src_col, int rows, int cols,
int dst_row, int dst_col) {
GUACIO* io = term->client->io;
guac_socket* socket = term->client->socket;
/* Send copy instruction */
return guac_send_copy(io,
return guac_protocol_send_copy(socket,
GUAC_DEFAULT_LAYER,
src_col * term->char_width, src_row * term->char_height,
@ -379,12 +378,12 @@ int ssh_guac_terminal_copy(ssh_guac_terminal* term,
int ssh_guac_terminal_clear(ssh_guac_terminal* term,
int row, int col, int rows, int cols, int background_color) {
GUACIO* io = term->client->io;
guac_socket* socket = term->client->socket;
const ssh_guac_terminal_color* color =
&ssh_guac_terminal_palette[background_color];
/* Fill with color */
return guac_send_rect(io,
return guac_protocol_send_rect(socket,
GUAC_COMP_OVER, GUAC_DEFAULT_LAYER,
col * term->char_width, row * term->char_height,

View File

@ -37,8 +37,6 @@
#include <stdlib.h>
#include <guacamole/log.h>
#include "ssh_terminal.h"
#include "ssh_terminal_handlers.h"
@ -146,7 +144,7 @@ int ssh_guac_terminal_escape(ssh_guac_terminal* term, char c) {
break;
default:
guac_log_info("Unhandled ESC sequence: %c", c);
guac_client_log_info(term->client, "Unhandled ESC sequence: %c", c);
term->char_handler = ssh_guac_terminal_echo;
}
@ -323,7 +321,7 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
term->bold = 0;
else
guac_log_info("Unhandled graphics rendition: %i", value);
guac_client_log_info(term->client, "Unhandled graphics rendition: %i", value);
}
@ -478,7 +476,7 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
/* Warn of unhandled codes */
default:
if (c != ';')
guac_log_info("Unhandled CSI sequence: %c", c);
guac_client_log_info(term->client, "Unhandled CSI sequence: %c", c);
}