diff --git a/guacamole/libguac/client.c b/guacamole/libguac/client.c index 2224e2c2c..4f6b5f6dd 100644 --- a/guacamole/libguac/client.c +++ b/guacamole/libguac/client.c @@ -22,6 +22,8 @@ #include #include +#include + #include "guacio.h" #include "protocol.h" #include "client.h" @@ -136,8 +138,10 @@ guac_client* guac_get_client(int client_fd, guac_client_registry* registry, guac void guac_free_client(guac_client* client, guac_client_registry* registry) { - if (client->free_handler) - client->free_handler(client); + if (client->free_handler) { + if (client->free_handler(client)) + syslog(LOG_ERR, "Error calling client free handler"); + } guac_close(client->io); @@ -158,7 +162,13 @@ void guac_start_client(guac_client* client) { /* Handle server messages */ if (client->handle_messages) { - client->handle_messages(client); + + int retval = client->handle_messages(client); + if (retval) { + syslog(LOG_ERR, "Error handling server messages"); + return; + } + guac_flush(client->io); } @@ -174,49 +184,77 @@ void guac_start_client(guac_client* client) { if (strcmp(instruction.opcode, "mouse") == 0) { if (client->mouse_handler) - client->mouse_handler( - client, - atoi(instruction.argv[0]), /* x */ - atoi(instruction.argv[1]), /* y */ - atoi(instruction.argv[2]) /* mask */ - ); + if ( + client->mouse_handler( + client, + atoi(instruction.argv[0]), /* x */ + atoi(instruction.argv[1]), /* y */ + atoi(instruction.argv[2]) /* mask */ + ) + ) { + + syslog(LOG_ERR, "Error handling mouse instruction"); + return; + + } } else if (strcmp(instruction.opcode, "key") == 0) { if (client->key_handler) - client->key_handler( - client, - atoi(instruction.argv[0]), /* keysym */ - atoi(instruction.argv[1]) /* pressed */ - ); + if ( + client->key_handler( + client, + atoi(instruction.argv[0]), /* keysym */ + atoi(instruction.argv[1]) /* pressed */ + ) + ) { + + syslog(LOG_ERR, "Error handling key instruction"); + return; + + } } else if (strcmp(instruction.opcode, "clipboard") == 0) { if (client->clipboard_handler) - client->clipboard_handler( - client, - guac_unescape_string_inplace(instruction.argv[0]) /* data */ - ); + if ( + client->clipboard_handler( + client, + guac_unescape_string_inplace(instruction.argv[0]) /* data */ + ) + ) { + + syslog(LOG_ERR, "Error handling clipboard instruction"); + return; + + } } else if (strcmp(instruction.opcode, "disconnect") == 0) { + syslog(LOG_INFO, "Client requested disconnect"); return; } } while ((retval = guac_read_instruction(io, &instruction)) > 0); - if (retval < 0) + if (retval < 0) { + syslog(LOG_ERR, "Error reading instruction from stream"); return; + } } - if (retval < 0) + if (retval < 0) { + syslog(LOG_ERR, "Error or end of stream"); return; /* EOF or error */ + } /* Otherwise, retval == 0 implies unfinished instruction */ } - else if (wait_result < 0) + else if (wait_result < 0) { + syslog(LOG_ERR, "Error waiting for next instruction"); return; + } } diff --git a/guacamole/libguac/include/client.h b/guacamole/libguac/include/client.h index f3c676c6d..dbd416b37 100644 --- a/guacamole/libguac/include/client.h +++ b/guacamole/libguac/include/client.h @@ -35,11 +35,11 @@ typedef struct guac_client guac_client; typedef struct guac_client_registry guac_client_registry; -typedef void guac_client_handle_messages(guac_client* client); -typedef void guac_client_mouse_handler(guac_client* client, int x, int y, int button_mask); -typedef void guac_client_key_handler(guac_client* client, int keysym, int pressed); -typedef void guac_client_clipboard_handler(guac_client* client, char* copied); -typedef void guac_client_free_handler(void* client); +typedef int guac_client_handle_messages(guac_client* client); +typedef int guac_client_mouse_handler(guac_client* client, int x, int y, int button_mask); +typedef int guac_client_key_handler(guac_client* client, int keysym, int pressed); +typedef int guac_client_clipboard_handler(guac_client* client, char* copied); +typedef int guac_client_free_handler(void* client); /** * Guacamole proxy client. diff --git a/guacamole/vnc/vnc_client.c b/guacamole/vnc/vnc_client.c index be41a8bd9..746f374f9 100644 --- a/guacamole/vnc/vnc_client.c +++ b/guacamole/vnc/vnc_client.c @@ -23,6 +23,8 @@ #include #include +#include + #include #include "guacio.h" @@ -192,7 +194,7 @@ void guac_vnc_cut_text(rfbClient* client, const char* text, int textlen) { } -void vnc_guac_client_handle_messages(guac_client* client) { +int vnc_guac_client_handle_messages(guac_client* client) { int wait_result; rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client; @@ -200,8 +202,8 @@ void vnc_guac_client_handle_messages(guac_client* client) { wait_result = WaitForMessage(rfb_client, 2000); if (wait_result < 0) { - fprintf(stderr, "WAIT FAIL\n"); - return; + syslog(LOG_ERR, "Error waiting for VNC server message\n"); + return 1; } if (wait_result > 0) { @@ -209,8 +211,8 @@ void vnc_guac_client_handle_messages(guac_client* client) { struct timespec sleep_period; if (!HandleRFBServerMessage(rfb_client)) { - fprintf(stderr, "HANDLE FAIL\n"); - return; + syslog(LOG_ERR, "Error handling VNC server message\n"); + return 1; } /* Wait before returning ... don't want to handle @@ -223,34 +225,39 @@ void vnc_guac_client_handle_messages(guac_client* client) { } + return 0; + } -void vnc_guac_client_mouse_handler(guac_client* client, int x, int y, int mask) { +int vnc_guac_client_mouse_handler(guac_client* client, int x, int y, int mask) { rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client; SendPointerEvent(rfb_client, x, y, mask); + return 0; } -void vnc_guac_client_key_handler(guac_client* client, int keysym, int pressed) { +int vnc_guac_client_key_handler(guac_client* client, int keysym, int pressed) { rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client; SendKeyEvent(rfb_client, keysym, pressed); + return 0; } -void vnc_guac_client_clipboard_handler(guac_client* client, char* data) { +int vnc_guac_client_clipboard_handler(guac_client* client, char* data) { rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client; SendClientCutText(rfb_client, data, strlen(data)); + return 0; } -void vnc_guac_client_free_handler(guac_client* client) { +int vnc_guac_client_free_handler(guac_client* client) { rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client; png_byte** png_buffer = ((vnc_guac_client_data*) client->data)->png_buffer; @@ -263,6 +270,7 @@ void vnc_guac_client_free_handler(guac_client* client) { /* Clean up VNC client*/ rfbClientCleanup(rfb_client); + return 0; }