diff --git a/src/common-ssh/guac_sftp.h b/src/common-ssh/guac_sftp.h index c43c00c6..fdc1e72e 100644 --- a/src/common-ssh/guac_sftp.h +++ b/src/common-ssh/guac_sftp.h @@ -20,7 +20,7 @@ #ifndef GUAC_COMMON_SSH_SFTP_H #define GUAC_COMMON_SSH_SFTP_H -#include "guac_json.h" +#include "common/json.h" #include "guac_ssh.h" #include diff --git a/src/common-ssh/guac_ssh.c b/src/common-ssh/guac_ssh.c index 2c59e1d7..488eea24 100644 --- a/src/common-ssh/guac_ssh.c +++ b/src/common-ssh/guac_ssh.c @@ -48,7 +48,7 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL; /** * Array of mutexes, used by OpenSSL. */ -static pthread_mutex_t* guac_common_ssh_openssl_locks; +static pthread_mutex_t* guac_common_ssh_openssl_locks = NULL; /** * Called by OpenSSL when locking or unlocking the Nth mutex. @@ -103,7 +103,7 @@ static void guac_common_ssh_openssl_init_locks(int count) { /* Allocate required number of locks */ guac_common_ssh_openssl_locks = - malloc(sizeof(pthread_mutex_t) * CRYPTO_num_locks()); + malloc(sizeof(pthread_mutex_t) * count); /* Initialize each lock */ for (i=0; i < count; i++) @@ -121,6 +121,10 @@ static void guac_common_ssh_openssl_free_locks(int count) { int i; + /* SSL lock array was not initialized */ + if (guac_common_ssh_openssl_locks == NULL) + return; + /* Free all locks */ for (i=0; i < count; i++) pthread_mutex_destroy(&(guac_common_ssh_openssl_locks[i])); diff --git a/src/common/Makefile.am b/src/common/Makefile.am index f36d9037..32d12836 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -22,39 +22,39 @@ ACLOCAL_AMFLAGS = -I m4 noinst_LTLIBRARIES = libguac_common.la -noinst_HEADERS = \ - guac_io.h \ - guac_blank_cursor.h \ - guac_clipboard.h \ - guac_cursor.h \ - guac_display.h \ - guac_dot_cursor.h \ - guac_ibar_cursor.h \ - guac_iconv.h \ - guac_json.h \ - guac_list.h \ - guac_pointer_cursor.h \ - guac_recording.h \ - guac_rect.h \ - guac_string.h \ - guac_surface.h +noinst_HEADERS = \ + common/io.h \ + common/blank_cursor.h \ + common/clipboard.h \ + common/cursor.h \ + common/display.h \ + common/dot_cursor.h \ + common/ibar_cursor.h \ + common/iconv.h \ + common/json.h \ + common/list.h \ + common/pointer_cursor.h \ + common/recording.h \ + common/rect.h \ + common/string.h \ + common/surface.h libguac_common_la_SOURCES = \ - guac_io.c \ - guac_blank_cursor.c \ - guac_clipboard.c \ - guac_cursor.c \ - guac_display.c \ - guac_dot_cursor.c \ - guac_ibar_cursor.c \ - guac_iconv.c \ - guac_json.c \ - guac_list.c \ - guac_pointer_cursor.c \ - guac_recording.c \ - guac_rect.c \ - guac_string.c \ - guac_surface.c + io.c \ + blank_cursor.c \ + clipboard.c \ + cursor.c \ + display.c \ + dot_cursor.c \ + ibar_cursor.c \ + iconv.c \ + json.c \ + list.c \ + pointer_cursor.c \ + recording.c \ + rect.c \ + string.c \ + surface.c libguac_common_la_CFLAGS = \ -Werror -Wall -pedantic \ diff --git a/src/common/guac_blank_cursor.c b/src/common/blank_cursor.c similarity index 100% rename from src/common/guac_blank_cursor.c rename to src/common/blank_cursor.c diff --git a/src/common/guac_clipboard.c b/src/common/clipboard.c similarity index 99% rename from src/common/guac_clipboard.c rename to src/common/clipboard.c index 15cdd840..4452bee7 100644 --- a/src/common/guac_clipboard.c +++ b/src/common/clipboard.c @@ -18,7 +18,7 @@ */ #include "config.h" -#include "guac_clipboard.h" +#include "common/clipboard.h" #include #include diff --git a/src/common/guac_blank_cursor.h b/src/common/common/blank_cursor.h similarity index 100% rename from src/common/guac_blank_cursor.h rename to src/common/common/blank_cursor.h diff --git a/src/common/guac_clipboard.h b/src/common/common/clipboard.h similarity index 100% rename from src/common/guac_clipboard.h rename to src/common/common/clipboard.h diff --git a/src/common/guac_cursor.h b/src/common/common/cursor.h similarity index 99% rename from src/common/guac_cursor.h rename to src/common/common/cursor.h index a6d9681e..86a7f14a 100644 --- a/src/common/guac_cursor.h +++ b/src/common/common/cursor.h @@ -21,7 +21,7 @@ #ifndef GUAC_COMMON_CURSOR_H #define GUAC_COMMON_CURSOR_H -#include "guac_surface.h" +#include "surface.h" #include #include diff --git a/src/common/guac_display.h b/src/common/common/display.h similarity index 99% rename from src/common/guac_display.h rename to src/common/common/display.h index 4bac8ea6..0b54338c 100644 --- a/src/common/guac_display.h +++ b/src/common/common/display.h @@ -20,8 +20,8 @@ #ifndef GUAC_COMMON_DISPLAY_H #define GUAC_COMMON_DISPLAY_H -#include "guac_cursor.h" -#include "guac_surface.h" +#include "cursor.h" +#include "surface.h" #include #include diff --git a/src/common/guac_dot_cursor.h b/src/common/common/dot_cursor.h similarity index 100% rename from src/common/guac_dot_cursor.h rename to src/common/common/dot_cursor.h diff --git a/src/common/guac_ibar_cursor.h b/src/common/common/ibar_cursor.h similarity index 100% rename from src/common/guac_ibar_cursor.h rename to src/common/common/ibar_cursor.h diff --git a/src/common/guac_iconv.h b/src/common/common/iconv.h similarity index 100% rename from src/common/guac_iconv.h rename to src/common/common/iconv.h diff --git a/src/common/guac_io.h b/src/common/common/io.h similarity index 100% rename from src/common/guac_io.h rename to src/common/common/io.h diff --git a/src/common/guac_json.h b/src/common/common/json.h similarity index 100% rename from src/common/guac_json.h rename to src/common/common/json.h diff --git a/src/common/guac_list.h b/src/common/common/list.h similarity index 100% rename from src/common/guac_list.h rename to src/common/common/list.h diff --git a/src/common/guac_pointer_cursor.h b/src/common/common/pointer_cursor.h similarity index 100% rename from src/common/guac_pointer_cursor.h rename to src/common/common/pointer_cursor.h diff --git a/src/common/guac_recording.h b/src/common/common/recording.h similarity index 100% rename from src/common/guac_recording.h rename to src/common/common/recording.h diff --git a/src/common/guac_rect.h b/src/common/common/rect.h similarity index 100% rename from src/common/guac_rect.h rename to src/common/common/rect.h diff --git a/src/common/guac_string.h b/src/common/common/string.h similarity index 100% rename from src/common/guac_string.h rename to src/common/common/string.h diff --git a/src/common/guac_surface.h b/src/common/common/surface.h similarity index 99% rename from src/common/guac_surface.h rename to src/common/common/surface.h index 144d45ab..3da3f175 100644 --- a/src/common/guac_surface.h +++ b/src/common/common/surface.h @@ -21,7 +21,7 @@ #define __GUAC_COMMON_SURFACE_H #include "config.h" -#include "guac_rect.h" +#include "rect.h" #include #include diff --git a/src/common/guac_cursor.c b/src/common/cursor.c similarity index 98% rename from src/common/guac_cursor.c rename to src/common/cursor.c index 4ed66b1d..6dd000f5 100644 --- a/src/common/guac_cursor.c +++ b/src/common/cursor.c @@ -17,12 +17,12 @@ * under the License. */ -#include "guac_blank_cursor.h" -#include "guac_dot_cursor.h" -#include "guac_cursor.h" -#include "guac_ibar_cursor.h" -#include "guac_pointer_cursor.h" -#include "guac_surface.h" +#include "common/blank_cursor.h" +#include "common/dot_cursor.h" +#include "common/cursor.h" +#include "common/ibar_cursor.h" +#include "common/pointer_cursor.h" +#include "common/surface.h" #include #include diff --git a/src/common/guac_display.c b/src/common/display.c similarity index 99% rename from src/common/guac_display.c rename to src/common/display.c index a81ff241..38a2ad42 100644 --- a/src/common/guac_display.c +++ b/src/common/display.c @@ -17,9 +17,9 @@ * under the License. */ -#include "guac_cursor.h" -#include "guac_display.h" -#include "guac_surface.h" +#include "common/cursor.h" +#include "common/display.h" +#include "common/surface.h" #include #include diff --git a/src/common/guac_dot_cursor.c b/src/common/dot_cursor.c similarity index 100% rename from src/common/guac_dot_cursor.c rename to src/common/dot_cursor.c diff --git a/src/common/guac_ibar_cursor.c b/src/common/ibar_cursor.c similarity index 100% rename from src/common/guac_ibar_cursor.c rename to src/common/ibar_cursor.c diff --git a/src/common/guac_iconv.c b/src/common/iconv.c similarity index 99% rename from src/common/guac_iconv.c rename to src/common/iconv.c index f9182263..f4cc6c50 100644 --- a/src/common/guac_iconv.c +++ b/src/common/iconv.c @@ -18,7 +18,7 @@ */ #include "config.h" -#include "guac_iconv.h" +#include "common/iconv.h" #include #include diff --git a/src/common/guac_io.c b/src/common/io.c similarity index 98% rename from src/common/guac_io.c rename to src/common/io.c index 0cefd7a7..2e2a5ad7 100644 --- a/src/common/guac_io.c +++ b/src/common/io.c @@ -18,7 +18,7 @@ */ #include "config.h" -#include "guac_io.h" +#include "common/io.h" #include diff --git a/src/common/guac_json.c b/src/common/json.c similarity index 99% rename from src/common/guac_json.c rename to src/common/json.c index 4bd1140e..6dad60be 100644 --- a/src/common/guac_json.c +++ b/src/common/json.c @@ -19,7 +19,7 @@ #include "config.h" -#include "guac_json.h" +#include "common/json.h" #include #include diff --git a/src/common/guac_list.c b/src/common/list.c similarity index 98% rename from src/common/guac_list.c rename to src/common/list.c index 869d59c5..072ef89f 100644 --- a/src/common/guac_list.c +++ b/src/common/list.c @@ -18,7 +18,7 @@ */ #include "config.h" -#include "guac_list.h" +#include "common/list.h" #include #include diff --git a/src/common/guac_pointer_cursor.c b/src/common/pointer_cursor.c similarity index 100% rename from src/common/guac_pointer_cursor.c rename to src/common/pointer_cursor.c diff --git a/src/common/guac_recording.c b/src/common/recording.c similarity index 99% rename from src/common/guac_recording.c rename to src/common/recording.c index 5d30fa98..2c953b5a 100644 --- a/src/common/guac_recording.c +++ b/src/common/recording.c @@ -17,7 +17,7 @@ * under the License. */ -#include "guac_recording.h" +#include "common/recording.h" #include #include diff --git a/src/common/guac_rect.c b/src/common/rect.c similarity index 99% rename from src/common/guac_rect.c rename to src/common/rect.c index 2d7fca68..a7ca7da5 100644 --- a/src/common/guac_rect.c +++ b/src/common/rect.c @@ -18,7 +18,7 @@ */ #include "config.h" -#include "guac_rect.h" +#include "common/rect.h" void guac_common_rect_init(guac_common_rect* rect, int x, int y, int width, int height) { rect->x = x; diff --git a/src/common/guac_string.c b/src/common/string.c similarity index 98% rename from src/common/guac_string.c rename to src/common/string.c index 437cd77a..b2479998 100644 --- a/src/common/guac_string.c +++ b/src/common/string.c @@ -19,7 +19,7 @@ #include "config.h" -#include "guac_string.h" +#include "common/string.h" #include #include diff --git a/src/common/guac_surface.c b/src/common/surface.c similarity index 99% rename from src/common/guac_surface.c rename to src/common/surface.c index 64726a9a..5a680937 100644 --- a/src/common/guac_surface.c +++ b/src/common/surface.c @@ -18,8 +18,8 @@ */ #include "config.h" -#include "guac_rect.h" -#include "guac_surface.h" +#include "common/rect.h" +#include "common/surface.h" #include #include diff --git a/src/guacd/proc-map.c b/src/guacd/proc-map.c index 410ac459..c09c06a3 100644 --- a/src/guacd/proc-map.c +++ b/src/guacd/proc-map.c @@ -18,7 +18,7 @@ */ #include "config.h" -#include "guac_list.h" +#include "common/list.h" #include "proc.h" #include "proc-map.h" #include "user.h" diff --git a/src/guacd/proc-map.h b/src/guacd/proc-map.h index 2078f5a5..123449dd 100644 --- a/src/guacd/proc-map.h +++ b/src/guacd/proc-map.h @@ -22,7 +22,7 @@ #define _GUACD_PROC_MAP_H #include "config.h" -#include "guac_list.h" +#include "common/list.h" #include "proc.h" #include "user.h" diff --git a/src/protocols/rdp/dvc.c b/src/protocols/rdp/dvc.c index 10c65d7f..34406c9b 100644 --- a/src/protocols/rdp/dvc.c +++ b/src/protocols/rdp/dvc.c @@ -18,8 +18,8 @@ */ #include "config.h" +#include "common/list.h" #include "dvc.h" -#include "guac_list.h" #include "rdp.h" #include diff --git a/src/protocols/rdp/dvc.h b/src/protocols/rdp/dvc.h index 02ca6437..63694f53 100644 --- a/src/protocols/rdp/dvc.h +++ b/src/protocols/rdp/dvc.h @@ -21,7 +21,7 @@ #define GUAC_RDP_DVC_H #include "config.h" -#include "guac_list.h" +#include "common/list.h" #include diff --git a/src/protocols/rdp/rdp.c b/src/protocols/rdp/rdp.c index e759888a..893fde5e 100644 --- a/src/protocols/rdp/rdp.c +++ b/src/protocols/rdp/rdp.c @@ -21,10 +21,10 @@ #include "audio_input.h" #include "client.h" +#include "common/cursor.h" +#include "common/display.h" +#include "common/recording.h" #include "dvc.h" -#include "guac_cursor.h" -#include "guac_display.h" -#include "guac_recording.h" #include "keyboard.h" #include "rdp.h" #include "rdp_bitmap.h" diff --git a/src/protocols/rdp/rdp.h b/src/protocols/rdp/rdp.h index 247ec131..af26408f 100644 --- a/src/protocols/rdp/rdp.h +++ b/src/protocols/rdp/rdp.h @@ -23,10 +23,10 @@ #include "config.h" #include "audio_input.h" -#include "guac_clipboard.h" -#include "guac_display.h" -#include "guac_surface.h" -#include "guac_list.h" +#include "common/clipboard.h" +#include "common/display.h" +#include "common/list.h" +#include "common/surface.h" #include "keyboard.h" #include "rdp_disp.h" #include "rdp_fs.h" diff --git a/src/protocols/rdp/rdp_bitmap.c b/src/protocols/rdp/rdp_bitmap.c index 351d5a32..f77bbaea 100644 --- a/src/protocols/rdp/rdp_bitmap.c +++ b/src/protocols/rdp/rdp_bitmap.c @@ -20,8 +20,8 @@ #include "config.h" #include "client.h" -#include "guac_display.h" -#include "guac_surface.h" +#include "common/display.h" +#include "common/surface.h" #include "rdp.h" #include "rdp_bitmap.h" #include "rdp_settings.h" diff --git a/src/protocols/rdp/rdp_bitmap.h b/src/protocols/rdp/rdp_bitmap.h index dbf452ae..dda3f763 100644 --- a/src/protocols/rdp/rdp_bitmap.h +++ b/src/protocols/rdp/rdp_bitmap.h @@ -22,7 +22,7 @@ #define _GUAC_RDP_RDP_BITMAP_H #include "config.h" -#include "guac_display.h" +#include "common/display.h" #include #include diff --git a/src/protocols/rdp/rdp_cliprdr.c b/src/protocols/rdp/rdp_cliprdr.c index 6f45387f..647dddab 100644 --- a/src/protocols/rdp/rdp_cliprdr.c +++ b/src/protocols/rdp/rdp_cliprdr.c @@ -20,10 +20,10 @@ #include "config.h" #include "client.h" +#include "common/clipboard.h" +#include "common/iconv.h" #include "rdp.h" #include "rdp_cliprdr.h" -#include "guac_clipboard.h" -#include "guac_iconv.h" #include #include diff --git a/src/protocols/rdp/rdp_gdi.c b/src/protocols/rdp/rdp_gdi.c index 7bf495b2..1805319e 100644 --- a/src/protocols/rdp/rdp_gdi.c +++ b/src/protocols/rdp/rdp_gdi.c @@ -20,7 +20,7 @@ #include "config.h" #include "client.h" -#include "guac_surface.h" +#include "common/surface.h" #include "rdp.h" #include "rdp_bitmap.h" #include "rdp_color.h" diff --git a/src/protocols/rdp/rdp_glyph.c b/src/protocols/rdp/rdp_glyph.c index ddbf2d03..68ce7a26 100644 --- a/src/protocols/rdp/rdp_glyph.c +++ b/src/protocols/rdp/rdp_glyph.c @@ -20,7 +20,7 @@ #include "config.h" #include "client.h" -#include "guac_surface.h" +#include "common/surface.h" #include "rdp.h" #include "rdp_color.h" #include "rdp_glyph.h" diff --git a/src/protocols/rdp/rdp_pointer.c b/src/protocols/rdp/rdp_pointer.c index 1f497a3e..f510b578 100644 --- a/src/protocols/rdp/rdp_pointer.c +++ b/src/protocols/rdp/rdp_pointer.c @@ -20,8 +20,8 @@ #include "config.h" #include "client.h" -#include "guac_cursor.h" -#include "guac_display.h" +#include "common/cursor.h" +#include "common/display.h" #include "rdp.h" #include "rdp_pointer.h" diff --git a/src/protocols/rdp/rdp_pointer.h b/src/protocols/rdp/rdp_pointer.h index 8818f52e..995c8d6f 100644 --- a/src/protocols/rdp/rdp_pointer.h +++ b/src/protocols/rdp/rdp_pointer.h @@ -22,7 +22,7 @@ #define _GUAC_RDP_RDP_POINTER_H #include "config.h" -#include "guac_display.h" +#include "common/display.h" #include diff --git a/src/protocols/rdp/rdp_settings.c b/src/protocols/rdp/rdp_settings.c index fd77e92a..e8161b13 100644 --- a/src/protocols/rdp/rdp_settings.c +++ b/src/protocols/rdp/rdp_settings.c @@ -20,7 +20,7 @@ #include "config.h" #include "client.h" -#include "guac_string.h" +#include "common/string.h" #include "rdp.h" #include "rdp_settings.h" #include "resolution.h" diff --git a/src/protocols/rdp/rdp_stream.c b/src/protocols/rdp/rdp_stream.c index eb5b9f3a..5dae3667 100644 --- a/src/protocols/rdp/rdp_stream.c +++ b/src/protocols/rdp/rdp_stream.c @@ -20,7 +20,7 @@ #include "config.h" #include "client.h" -#include "guac_clipboard.h" +#include "common/clipboard.h" #include "rdp.h" #include "rdp_fs.h" #include "rdp_svc.h" diff --git a/src/protocols/rdp/rdp_stream.h b/src/protocols/rdp/rdp_stream.h index 1bd490e0..c9c3838e 100644 --- a/src/protocols/rdp/rdp_stream.h +++ b/src/protocols/rdp/rdp_stream.h @@ -22,7 +22,7 @@ #define _GUAC_RDP_STREAM_H #include "config.h" -#include "guac_json.h" +#include "common/json.h" #include "rdp_svc.h" #include diff --git a/src/protocols/rdp/rdp_svc.c b/src/protocols/rdp/rdp_svc.c index 0d20746b..83537a86 100644 --- a/src/protocols/rdp/rdp_svc.c +++ b/src/protocols/rdp/rdp_svc.c @@ -19,7 +19,7 @@ #include "config.h" #include "client.h" -#include "guac_list.h" +#include "common/list.h" #include "rdp.h" #include "rdp_svc.h" diff --git a/src/protocols/rdp/user.c b/src/protocols/rdp/user.c index ae02a106..6aa71ae9 100644 --- a/src/protocols/rdp/user.c +++ b/src/protocols/rdp/user.c @@ -20,8 +20,8 @@ #include "config.h" #include "audio_input.h" +#include "common/display.h" #include "input.h" -#include "guac_display.h" #include "user.h" #include "rdp.h" #include "rdp_settings.h" diff --git a/src/protocols/ssh/input.c b/src/protocols/ssh/input.c index 240f729a..e0267e20 100644 --- a/src/protocols/ssh/input.c +++ b/src/protocols/ssh/input.c @@ -19,8 +19,8 @@ #include "config.h" -#include "guac_cursor.h" -#include "guac_display.h" +#include "common/cursor.h" +#include "common/display.h" #include "ssh.h" #include "terminal.h" diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index db3cea96..53835c85 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -19,7 +19,7 @@ #include "config.h" -#include "guac_recording.h" +#include "common/recording.h" #include "guac_sftp.h" #include "guac_ssh.h" #include "settings.h" @@ -339,7 +339,7 @@ void* ssh_client_thread(void* data) { /* Attempt to write data received. Exit on failure. */ if (bytes_read > 0) { - int written = guac_terminal_write_stdout(ssh_client->term, buffer, bytes_read); + int written = guac_terminal_write(ssh_client->term, buffer, bytes_read); if (written < 0) break; diff --git a/src/protocols/ssh/user.c b/src/protocols/ssh/user.c index 4ebbab2f..24d0fbb1 100644 --- a/src/protocols/ssh/user.c +++ b/src/protocols/ssh/user.c @@ -20,8 +20,8 @@ #include "config.h" #include "clipboard.h" +#include "common/display.h" #include "input.h" -#include "guac_display.h" #include "user.h" #include "sftp.h" #include "ssh.h" diff --git a/src/protocols/telnet/telnet.c b/src/protocols/telnet/telnet.c index 6ca9aba7..b80c959e 100644 --- a/src/protocols/telnet/telnet.c +++ b/src/protocols/telnet/telnet.c @@ -18,7 +18,7 @@ */ #include "config.h" -#include "guac_recording.h" +#include "common/recording.h" #include "telnet.h" #include "terminal.h" @@ -150,7 +150,7 @@ static void __guac_telnet_event_handler(telnet_t* telnet, telnet_event_t* event, /* Terminal output received */ case TELNET_EV_DATA: - guac_terminal_write_stdout(telnet_client->term, event->data.buffer, event->data.size); + guac_terminal_write(telnet_client->term, event->data.buffer, event->data.size); /* Continue search for username prompt */ if (settings->username_regex != NULL) { @@ -267,7 +267,7 @@ static void* __guac_telnet_input_thread(void* data) { while ((bytes_read = guac_terminal_read_stdin(telnet_client->term, buffer, sizeof(buffer))) > 0) { telnet_send(telnet_client->telnet, buffer, bytes_read); if (telnet_client->echo_enabled) - guac_terminal_write_stdout(telnet_client->term, buffer, bytes_read); + guac_terminal_write(telnet_client->term, buffer, bytes_read); } return NULL; diff --git a/src/protocols/vnc/clipboard.c b/src/protocols/vnc/clipboard.c index eab708da..8a802234 100644 --- a/src/protocols/vnc/clipboard.c +++ b/src/protocols/vnc/clipboard.c @@ -20,8 +20,8 @@ #include "config.h" #include "client.h" #include "clipboard.h" -#include "guac_clipboard.h" -#include "guac_iconv.h" +#include "common/clipboard.h" +#include "common/iconv.h" #include "user.h" #include "vnc.h" diff --git a/src/protocols/vnc/cursor.c b/src/protocols/vnc/cursor.c index fd075bc1..22d45ebe 100644 --- a/src/protocols/vnc/cursor.c +++ b/src/protocols/vnc/cursor.c @@ -20,9 +20,9 @@ #include "config.h" #include "client.h" -#include "guac_cursor.h" -#include "guac_display.h" -#include "guac_surface.h" +#include "common/cursor.h" +#include "common/display.h" +#include "common/surface.h" #include "vnc.h" #include diff --git a/src/protocols/vnc/display.c b/src/protocols/vnc/display.c index 99edb77a..22de084a 100644 --- a/src/protocols/vnc/display.c +++ b/src/protocols/vnc/display.c @@ -20,8 +20,8 @@ #include "config.h" #include "client.h" -#include "guac_iconv.h" -#include "guac_surface.h" +#include "common/iconv.h" +#include "common/surface.h" #include "vnc.h" #include diff --git a/src/protocols/vnc/input.c b/src/protocols/vnc/input.c index 08f3ec30..d8fcda58 100644 --- a/src/protocols/vnc/input.c +++ b/src/protocols/vnc/input.c @@ -19,8 +19,8 @@ #include "config.h" -#include "guac_cursor.h" -#include "guac_display.h" +#include "common/cursor.h" +#include "common/display.h" #include "vnc.h" #include diff --git a/src/protocols/vnc/log.c b/src/protocols/vnc/log.c index 84e28ad0..ba593e81 100644 --- a/src/protocols/vnc/log.c +++ b/src/protocols/vnc/log.c @@ -20,8 +20,8 @@ #include "config.h" #include "client.h" -#include "guac_iconv.h" -#include "guac_surface.h" +#include "common/iconv.h" +#include "common/surface.h" #include #include diff --git a/src/protocols/vnc/log.h b/src/protocols/vnc/log.h index 829d60f9..65f3dc2d 100644 --- a/src/protocols/vnc/log.h +++ b/src/protocols/vnc/log.h @@ -23,8 +23,8 @@ #include "config.h" #include "client.h" -#include "guac_iconv.h" -#include "guac_surface.h" +#include "common/iconv.h" +#include "common/surface.h" #include #include diff --git a/src/protocols/vnc/user.c b/src/protocols/vnc/user.c index e01ee758..aecf4e90 100644 --- a/src/protocols/vnc/user.c +++ b/src/protocols/vnc/user.c @@ -21,9 +21,9 @@ #include "clipboard.h" #include "input.h" -#include "guac_display.h" -#include "guac_dot_cursor.h" -#include "guac_pointer_cursor.h" +#include "common/display.h" +#include "common/dot_cursor.h" +#include "common/pointer_cursor.h" #include "user.h" #include "sftp.h" #include "vnc.h" diff --git a/src/protocols/vnc/vnc.c b/src/protocols/vnc/vnc.c index f9ab6873..9238ef13 100644 --- a/src/protocols/vnc/vnc.c +++ b/src/protocols/vnc/vnc.c @@ -22,12 +22,12 @@ #include "auth.h" #include "client.h" #include "clipboard.h" +#include "common/clipboard.h" +#include "common/cursor.h" +#include "common/display.h" +#include "common/recording.h" #include "cursor.h" #include "display.h" -#include "guac_clipboard.h" -#include "guac_cursor.h" -#include "guac_display.h" -#include "guac_recording.h" #include "log.h" #include "settings.h" #include "vnc.h" diff --git a/src/protocols/vnc/vnc.h b/src/protocols/vnc/vnc.h index cf9895b7..7938d846 100644 --- a/src/protocols/vnc/vnc.h +++ b/src/protocols/vnc/vnc.h @@ -22,10 +22,10 @@ #include "config.h" -#include "guac_clipboard.h" -#include "guac_display.h" -#include "guac_iconv.h" -#include "guac_surface.h" +#include "common/clipboard.h" +#include "common/display.h" +#include "common/iconv.h" +#include "common/surface.h" #include "settings.h" #include diff --git a/src/terminal/Makefile.am b/src/terminal/Makefile.am index 19cbf949..59bcd123 100644 --- a/src/terminal/Makefile.am +++ b/src/terminal/Makefile.am @@ -27,7 +27,6 @@ noinst_HEADERS = \ char_mappings.h \ common.h \ display.h \ - packet.h \ scrollbar.h \ terminal.h \ terminal_handlers.h \ @@ -39,7 +38,6 @@ libguac_terminal_la_SOURCES = \ char_mappings.c \ common.c \ display.c \ - packet.c \ scrollbar.c \ terminal.c \ terminal_handlers.c \ diff --git a/src/terminal/common.c b/src/terminal/common.c index cc982767..4018e771 100644 --- a/src/terminal/common.c +++ b/src/terminal/common.c @@ -105,23 +105,3 @@ int guac_terminal_write_all(int fd, const char* buffer, int size) { } -int guac_terminal_fill_buffer(int fd, char* buffer, int size) { - - int remaining = size; - while (remaining > 0) { - - /* Attempt to read data */ - int ret_val = read(fd, buffer, remaining); - if (ret_val <= 0) - return -1; - - /* If successful, continue with what space remains (if any) */ - remaining -= ret_val; - buffer += ret_val; - - } - - return size; - -} - diff --git a/src/terminal/common.h b/src/terminal/common.h index 495bf30b..f7eda619 100644 --- a/src/terminal/common.h +++ b/src/terminal/common.h @@ -49,26 +49,5 @@ bool guac_terminal_has_glyph(int codepoint); */ int guac_terminal_write_all(int fd, const char* buffer, int size); -/** - * Similar to read, but automatically retries the read until an error occurs, - * filling all available space within the buffer. Unless it is known that the - * given amount of space is available on the file descriptor, there is a good - * chance this function will block. - * - * @param fd - * The file descriptor to read data from. - * - * @param buffer - * The buffer to store data within. - * - * @param size - * The number of bytes available within the buffer. - * - * @return - * The number of bytes read if successful, or a negative value if an error - * occurs. - */ -int guac_terminal_fill_buffer(int fd, char* buffer, int size); - #endif diff --git a/src/terminal/display.c b/src/terminal/display.c index fdb19431..da1a8d98 100644 --- a/src/terminal/display.c +++ b/src/terminal/display.c @@ -20,8 +20,8 @@ #include "config.h" #include "common.h" +#include "common/surface.h" #include "display.h" -#include "guac_surface.h" #include "types.h" #include diff --git a/src/terminal/display.h b/src/terminal/display.h index 440d809a..655d1aa0 100644 --- a/src/terminal/display.h +++ b/src/terminal/display.h @@ -23,7 +23,7 @@ #include "config.h" -#include "guac_surface.h" +#include "common/surface.h" #include "types.h" #include diff --git a/src/terminal/packet.c b/src/terminal/packet.c deleted file mode 100644 index ad828ceb..00000000 --- a/src/terminal/packet.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#include "common.h" -#include "packet.h" - -#include - -int guac_terminal_packet_write(int fd, const void* data, int length) { - - guac_terminal_packet out; - - /* Do not attempt to write packets beyond maximum size */ - if (length > GUAC_TERMINAL_PACKET_SIZE) - return -1; - - /* Calculate final packet length */ - int packet_length = sizeof(int) + length; - - /* Copy data into packet */ - out.length = length; - memcpy(out.data, data, length); - - /* Write packet */ - return guac_terminal_write_all(fd, (const char*) &out, packet_length); - -} - -int guac_terminal_packet_read(int fd, void* data, int length) { - - int bytes; - - /* Read buffers MUST be at least GUAC_TERMINAL_PACKET_SIZE */ - if (length < GUAC_TERMINAL_PACKET_SIZE) - return -1; - - /* Read length */ - if (guac_terminal_fill_buffer(fd, (char*) &bytes, sizeof(int)) < 0) - return -1; - - /* Read body */ - if (guac_terminal_fill_buffer(fd, (char*) data, bytes) < 0) - return -1; - - return bytes; - -} - diff --git a/src/terminal/packet.h b/src/terminal/packet.h deleted file mode 100644 index 00d30520..00000000 --- a/src/terminal/packet.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef GUAC_TERMINAL_PACKET_H -#define GUAC_TERMINAL_PACKET_H - -/** - * The maximum size of a packet written or read by the - * guac_terminal_packet_write() or guac_terminal_packet_read() functions. - */ -#define GUAC_TERMINAL_PACKET_SIZE 4096 - -/** - * An arbitrary data packet with minimal framing. - */ -typedef struct guac_terminal_packet { - - /** - * The number of bytes in the data portion of this packet. - */ - int length; - - /** - * Arbitrary data. - */ - char data[GUAC_TERMINAL_PACKET_SIZE]; - -} guac_terminal_packet; - -/** - * Writes a single packet of data to the given file descriptor. The provided - * length MUST be no greater than GUAC_TERMINAL_PACKET_SIZE. Zero-length - * writes are legal and do result in a packet being written to the file - * descriptor. - * - * @param fd - * The file descriptor to write to. - * - * @param data - * A buffer containing the data to write. - * - * @param length - * The number of bytes to write to the file descriptor. - * - * @return - * The number of bytes written on success, which may be zero if the data - * length is zero, or a negative value on error. - */ -int guac_terminal_packet_write(int fd, const void* data, int length); - -/** - * Reads a single packet of data from the given file descriptor. The provided - * length MUST be at least GUAC_TERMINAL_PACKET_SIZE to ensure any packet - * read will fit in the buffer. Zero-length reads are possible if a zero-length - * packet was written. - * - * @param fd - * The file descriptor to read from. - * - * @param data - * The buffer to store data within. - * - * @param length - * The number of bytes available within the buffer. - * - * @return - * The number of bytes read on success, which may be zero if the read - * packet had a length of zero, or a negative value on error. - */ -int guac_terminal_packet_read(int fd, void* data, int length); - -#endif - diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 598a3852..50571234 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -21,18 +21,15 @@ #include "buffer.h" #include "common.h" +#include "common/clipboard.h" +#include "common/cursor.h" #include "display.h" -#include "guac_clipboard.h" -#include "guac_cursor.h" -#include "packet.h" -#include "scrollbar.h" #include "terminal.h" #include "terminal_handlers.h" #include "types.h" #include "typescript.h" #include -#include #include #include #include @@ -318,6 +315,11 @@ guac_terminal* guac_terminal_create(guac_client* client, term->upload_path_handler = NULL; term->file_download_handler = NULL; + /* Init modified flag and conditional */ + term->modified = 0; + pthread_cond_init(&(term->modified_cond), NULL); + pthread_mutex_init(&(term->modified_lock), NULL); + /* Init buffer */ term->buffer = guac_terminal_buffer_alloc(1000, &default_char); @@ -349,14 +351,6 @@ guac_terminal* guac_terminal_create(guac_client* client, term->term_width = available_width / term->display->char_width; term->term_height = height / term->display->char_height; - /* Open STDOUT pipe */ - if (pipe(term->stdout_pipe_fd)) { - guac_error = GUAC_STATUS_SEE_ERRNO; - guac_error_message = "Unable to open pipe for STDOUT"; - free(term); - return NULL; - } - /* Open STDIN pipe */ if (pipe(term->stdin_pipe_fd)) { guac_error = GUAC_STATUS_SEE_ERRNO; @@ -414,10 +408,6 @@ guac_terminal* guac_terminal_create(guac_client* client, void guac_terminal_free(guac_terminal* term) { - /* Close terminal output pipe */ - close(term->stdout_pipe_fd[1]); - close(term->stdout_pipe_fd[0]); - /* Close user input pipe */ close(term->stdin_pipe_fd[1]); close(term->stdin_pipe_fd[0]); @@ -449,84 +439,110 @@ void guac_terminal_free(guac_terminal* term) { } /** - * Waits for data to become available on the given file descriptor. + * Populate the given timespec with the current time, plus the given offset. * - * @param fd - * The file descriptor to wait on. + * @param ts + * The timespec structure to populate. + * + * @param offset_sec + * The offset from the current time to use when populating the given + * timespec, in seconds. + * + * @param offset_usec + * The offset from the current time to use when populating the given + * timespec, in microseconds. + */ +static void guac_terminal_get_absolute_time(struct timespec* ts, + int offset_sec, int offset_usec) { + + /* Get timeval */ + struct timeval tv; + gettimeofday(&tv, NULL); + + /* Update with offset */ + tv.tv_sec += offset_sec; + tv.tv_usec += offset_usec; + + /* Wrap to next second if necessary */ + if (tv.tv_usec >= 1000000) { + tv.tv_sec++; + tv.tv_usec -= 1000000; + } + + /* Convert to timespec */ + ts->tv_sec = tv.tv_sec; + ts->tv_nsec = tv.tv_usec * 1000; + +} + +/** + * Waits for the terminal state to be modified, returning only when the + * specified timeout has elapsed or a frame flush is desired. Note that the + * modified flag of the terminal will only be reset if no data remains to be + * read from STDOUT. + * + * @param terminal + * The terminal to wait on. * * @param msec_timeout * The maximum amount of time to wait, in milliseconds. * * @return - * A positive if data is available, zero if the timeout has elapsed without - * data becoming available, or negative if an error occurred. + * Non-zero if the terminal has been modified, zero if the timeout has + * elapsed without the terminal being modified. */ -static int guac_terminal_wait_for_data(int fd, int msec_timeout) { +static int guac_terminal_wait(guac_terminal* terminal, int msec_timeout) { - /* Build array of file descriptors */ - struct pollfd fds[] = {{ - .fd = fd, - .events = POLLIN, - .revents = 0, - }}; + int retval = 1; - /* Wait for data */ - return poll(fds, 1, msec_timeout); + pthread_mutex_t* mod_lock = &(terminal->modified_lock); + pthread_cond_t* mod_cond = &(terminal->modified_cond); + + /* Split provided milliseconds into microseconds and whole seconds */ + int secs = msec_timeout / 1000; + int usecs = (msec_timeout % 1000) * 1000; + + /* Calculate absolute timestamp from provided relative timeout */ + struct timespec timeout; + guac_terminal_get_absolute_time(&timeout, secs, usecs); + + /* Test for terminal modification */ + pthread_mutex_lock(mod_lock); + if (terminal->modified) + goto wait_complete; + + /* If not yet modified, wait for modification condition to be signaled */ + retval = pthread_cond_timedwait(mod_cond, mod_lock, &timeout) != ETIMEDOUT; + +wait_complete: + + /* Terminal is no longer modified */ + terminal->modified = 0; + pthread_mutex_unlock(mod_lock); + return retval; } int guac_terminal_render_frame(guac_terminal* terminal) { - guac_client* client = terminal->client; - char buffer[GUAC_TERMINAL_PACKET_SIZE]; - int wait_result; - int fd = terminal->stdout_pipe_fd[0]; /* Wait for data to be available */ - wait_result = guac_terminal_wait_for_data(fd, 1000); - if (wait_result > 0) { + wait_result = guac_terminal_wait(terminal, 1000); + if (wait_result) { - guac_terminal_lock(terminal); guac_timestamp frame_start = guac_timestamp_current(); do { - guac_timestamp frame_end; - int frame_remaining; - - int bytes_read; - - /* Read data, write to terminal */ - if ((bytes_read = guac_terminal_packet_read(fd, - buffer, sizeof(buffer))) > 0) { - - if (guac_terminal_write(terminal, buffer, bytes_read)) { - guac_client_abort(client, - GUAC_PROTOCOL_STATUS_SERVER_ERROR, - "Error writing data"); - guac_terminal_unlock(terminal); - return 1; - } - - } - - /* Notify on error */ - if (bytes_read < 0) { - guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, - "Error reading data"); - guac_terminal_unlock(terminal); - return 1; - } - /* Calculate time remaining in frame */ - frame_end = guac_timestamp_current(); - frame_remaining = frame_start + GUAC_TERMINAL_FRAME_DURATION - - frame_end; + guac_timestamp frame_end = guac_timestamp_current(); + int frame_remaining = frame_start + GUAC_TERMINAL_FRAME_DURATION + - frame_end; /* Wait again if frame remaining */ if (frame_remaining > 0) - wait_result = guac_terminal_wait_for_data(fd, + wait_result = guac_terminal_wait(terminal, GUAC_TERMINAL_FRAME_TIMEOUT); else break; @@ -534,18 +550,12 @@ int guac_terminal_render_frame(guac_terminal* terminal) { } while (wait_result > 0); /* Flush terminal */ + guac_terminal_lock(terminal); guac_terminal_flush(terminal); guac_terminal_unlock(terminal); } - /* Notify of any errors */ - if (wait_result < 0) { - guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, - "Error waiting for data"); - return 1; - } - return 0; } @@ -555,28 +565,19 @@ int guac_terminal_read_stdin(guac_terminal* terminal, char* c, int size) { return read(stdin_fd, c, size); } -int guac_terminal_write_stdout(guac_terminal* terminal, const char* c, - int size) { +void guac_terminal_notify(guac_terminal* terminal) { - /* Write maximally-sized packets until only one packet remains */ - while (size > GUAC_TERMINAL_PACKET_SIZE) { + pthread_mutex_t* mod_lock = &(terminal->modified_lock); + pthread_cond_t* mod_cond = &(terminal->modified_cond); - /* Write maximally-sized packet */ - if (guac_terminal_packet_write(terminal->stdout_pipe_fd[1], c, - GUAC_TERMINAL_PACKET_SIZE) < 0) - return -1; + pthread_mutex_lock(mod_lock); - /* Advance to next packet */ - c += GUAC_TERMINAL_PACKET_SIZE; - size -= GUAC_TERMINAL_PACKET_SIZE; + /* Signal modification */ + terminal->modified = 1; + pthread_cond_signal(mod_cond); - } + pthread_mutex_unlock(mod_lock); - return guac_terminal_packet_write(terminal->stdout_pipe_fd[1], c, size); -} - -int guac_terminal_notify(guac_terminal* terminal) { - return guac_terminal_packet_write(terminal->stdout_pipe_fd[1], NULL, 0); } int guac_terminal_printf(guac_terminal* terminal, const char* format, ...) { @@ -595,7 +596,7 @@ int guac_terminal_printf(guac_terminal* terminal, const char* format, ...) { return written; /* Write to STDOUT */ - return guac_terminal_write_stdout(terminal, buffer, written); + return guac_terminal_write(terminal, buffer, written); } @@ -711,6 +712,7 @@ void guac_terminal_commit_cursor(guac_terminal* term) { int guac_terminal_write(guac_terminal* term, const char* c, int size) { + guac_terminal_lock(term); while (size > 0) { /* Read and advance to next character */ @@ -725,7 +727,9 @@ int guac_terminal_write(guac_terminal* term, const char* c, int size) { term->char_handler(term, current); } + guac_terminal_unlock(term); + guac_terminal_notify(term); return 0; } diff --git a/src/terminal/terminal.h b/src/terminal/terminal.h index 7598fcef..965d7eac 100644 --- a/src/terminal/terminal.h +++ b/src/terminal/terminal.h @@ -24,9 +24,9 @@ #include "config.h" #include "buffer.h" +#include "common/clipboard.h" +#include "common/cursor.h" #include "display.h" -#include "guac_clipboard.h" -#include "guac_cursor.h" #include "scrollbar.h" #include "types.h" #include "typescript.h" @@ -159,13 +159,24 @@ struct guac_terminal { pthread_mutex_t lock; /** - * Pipe which should be written to (and read from) to provide output to - * this terminal. Another thread should read from this pipe when writing - * data to the terminal. It would make sense for the terminal to provide - * this thread, but for simplicity, that logic is left to the guac - * message handler (to give the message handler something to block with). + * The mutex associated with the modified condition and flag, locked + * whenever a thread is waiting on the modified condition, the modified + * condition is being signalled, or the modified flag is being changed. */ - int stdout_pipe_fd[2]; + pthread_mutex_t modified_lock; + + /** + * Flag set whenever an operation has affected the terminal in a way that + * will require a frame flush. When this flag is set, the modified_cond + * condition will be signalled. The modified_lock will always be + * acquired before this flag is altered. + */ + int modified; + + /** + * Condition which is signalled when the modified flag has been set + */ + pthread_cond_t modified_cond; /** * Pipe which will be the source of user input. When a terminal code @@ -473,24 +484,14 @@ int guac_terminal_render_frame(guac_terminal* terminal); */ int guac_terminal_read_stdin(guac_terminal* terminal, char* c, int size); -/** - * Writes to this terminal's STDOUT. This function may block until space - * is freed in the output buffer by guac_terminal_render_frame(). - */ -int guac_terminal_write_stdout(guac_terminal* terminal, const char* c, int size); - /** * Notifies the terminal that an event has occurred and the terminal should * flush itself when reasonable. * * @param terminal * The terminal to notify. - * - * @return - * Zero if notification succeeded, non-zero if an error occurred while - * notifying the terminal. */ -int guac_terminal_notify(guac_terminal* terminal); +void guac_terminal_notify(guac_terminal* terminal); /** * Reads a single line from this terminal's STDIN, storing the result in a diff --git a/src/terminal/typescript.c b/src/terminal/typescript.c index 0cf5edf0..aa922f0a 100644 --- a/src/terminal/typescript.c +++ b/src/terminal/typescript.c @@ -18,7 +18,7 @@ */ #include "config.h" -#include "guac_io.h" +#include "common/io.h" #include "typescript.h" #include diff --git a/tests/common/guac_iconv.c b/tests/common/guac_iconv.c index 6f7726af..6af706f9 100644 --- a/tests/common/guac_iconv.c +++ b/tests/common/guac_iconv.c @@ -20,7 +20,7 @@ #include "config.h" #include "common_suite.h" -#include "guac_iconv.h" +#include "common/iconv.h" #include #include diff --git a/tests/common/guac_rect.c b/tests/common/guac_rect.c index 97a71962..a45ee385 100644 --- a/tests/common/guac_rect.c +++ b/tests/common/guac_rect.c @@ -20,7 +20,7 @@ #include "config.h" #include "common_suite.h" -#include "guac_rect.h" +#include "common/rect.h" #include #include diff --git a/tests/common/guac_string.c b/tests/common/guac_string.c index 2ba7f04b..543a41b8 100644 --- a/tests/common/guac_string.c +++ b/tests/common/guac_string.c @@ -20,7 +20,7 @@ #include "config.h" #include "common_suite.h" -#include "guac_string.h" +#include "common/string.h" #include #include