Added improved logging, all handlers now return int, much more stable

This commit is contained in:
Michael Jumper
2010-09-20 22:09:32 -07:00
parent c1e7f19feb
commit 15cc6278fa
3 changed files with 81 additions and 35 deletions

View File

@@ -22,6 +22,8 @@
#include <string.h>
#include <uuid/uuid.h>
#include <syslog.h>
#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)
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)
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)
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;
}
}

View File

@@ -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.

View File

@@ -23,6 +23,8 @@
#include <png.h>
#include <time.h>
#include <syslog.h>
#include <rfb/rfbclient.h>
#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;
}