mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Added improved logging, all handlers now return int, much more stable
This commit is contained in:
@@ -22,6 +22,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <uuid/uuid.h>
|
#include <uuid/uuid.h>
|
||||||
|
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
#include "guacio.h"
|
#include "guacio.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "client.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) {
|
void guac_free_client(guac_client* client, guac_client_registry* registry) {
|
||||||
|
|
||||||
if (client->free_handler)
|
if (client->free_handler) {
|
||||||
client->free_handler(client);
|
if (client->free_handler(client))
|
||||||
|
syslog(LOG_ERR, "Error calling client free handler");
|
||||||
|
}
|
||||||
|
|
||||||
guac_close(client->io);
|
guac_close(client->io);
|
||||||
|
|
||||||
@@ -158,7 +162,13 @@ void guac_start_client(guac_client* client) {
|
|||||||
|
|
||||||
/* Handle server messages */
|
/* Handle server messages */
|
||||||
if (client->handle_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);
|
guac_flush(client->io);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,49 +184,77 @@ void guac_start_client(guac_client* client) {
|
|||||||
|
|
||||||
if (strcmp(instruction.opcode, "mouse") == 0) {
|
if (strcmp(instruction.opcode, "mouse") == 0) {
|
||||||
if (client->mouse_handler)
|
if (client->mouse_handler)
|
||||||
client->mouse_handler(
|
if (
|
||||||
client,
|
client->mouse_handler(
|
||||||
atoi(instruction.argv[0]), /* x */
|
client,
|
||||||
atoi(instruction.argv[1]), /* y */
|
atoi(instruction.argv[0]), /* x */
|
||||||
atoi(instruction.argv[2]) /* mask */
|
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) {
|
else if (strcmp(instruction.opcode, "key") == 0) {
|
||||||
if (client->key_handler)
|
if (client->key_handler)
|
||||||
client->key_handler(
|
if (
|
||||||
client,
|
client->key_handler(
|
||||||
atoi(instruction.argv[0]), /* keysym */
|
client,
|
||||||
atoi(instruction.argv[1]) /* pressed */
|
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) {
|
else if (strcmp(instruction.opcode, "clipboard") == 0) {
|
||||||
if (client->clipboard_handler)
|
if (client->clipboard_handler)
|
||||||
client->clipboard_handler(
|
if (
|
||||||
client,
|
client->clipboard_handler(
|
||||||
guac_unescape_string_inplace(instruction.argv[0]) /* data */
|
client,
|
||||||
);
|
guac_unescape_string_inplace(instruction.argv[0]) /* data */
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
|
||||||
|
syslog(LOG_ERR, "Error handling clipboard instruction");
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(instruction.opcode, "disconnect") == 0) {
|
else if (strcmp(instruction.opcode, "disconnect") == 0) {
|
||||||
|
syslog(LOG_INFO, "Client requested disconnect");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
} while ((retval = guac_read_instruction(io, &instruction)) > 0);
|
} while ((retval = guac_read_instruction(io, &instruction)) > 0);
|
||||||
|
|
||||||
if (retval < 0)
|
if (retval < 0) {
|
||||||
|
syslog(LOG_ERR, "Error reading instruction from stream");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval < 0)
|
if (retval < 0) {
|
||||||
|
syslog(LOG_ERR, "Error or end of stream");
|
||||||
return; /* EOF or error */
|
return; /* EOF or error */
|
||||||
|
}
|
||||||
|
|
||||||
/* Otherwise, retval == 0 implies unfinished instruction */
|
/* 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;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,11 +35,11 @@
|
|||||||
typedef struct guac_client guac_client;
|
typedef struct guac_client guac_client;
|
||||||
typedef struct guac_client_registry guac_client_registry;
|
typedef struct guac_client_registry guac_client_registry;
|
||||||
|
|
||||||
typedef void guac_client_handle_messages(guac_client* client);
|
typedef int guac_client_handle_messages(guac_client* client);
|
||||||
typedef void guac_client_mouse_handler(guac_client* client, int x, int y, int button_mask);
|
typedef int 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 int guac_client_key_handler(guac_client* client, int keysym, int pressed);
|
||||||
typedef void guac_client_clipboard_handler(guac_client* client, char* copied);
|
typedef int guac_client_clipboard_handler(guac_client* client, char* copied);
|
||||||
typedef void guac_client_free_handler(void* client);
|
typedef int guac_client_free_handler(void* client);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guacamole proxy client.
|
* Guacamole proxy client.
|
||||||
|
@@ -23,6 +23,8 @@
|
|||||||
#include <png.h>
|
#include <png.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
#include <rfb/rfbclient.h>
|
#include <rfb/rfbclient.h>
|
||||||
|
|
||||||
#include "guacio.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;
|
int wait_result;
|
||||||
rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client;
|
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);
|
wait_result = WaitForMessage(rfb_client, 2000);
|
||||||
if (wait_result < 0) {
|
if (wait_result < 0) {
|
||||||
fprintf(stderr, "WAIT FAIL\n");
|
syslog(LOG_ERR, "Error waiting for VNC server message\n");
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wait_result > 0) {
|
if (wait_result > 0) {
|
||||||
@@ -209,8 +211,8 @@ void vnc_guac_client_handle_messages(guac_client* client) {
|
|||||||
struct timespec sleep_period;
|
struct timespec sleep_period;
|
||||||
|
|
||||||
if (!HandleRFBServerMessage(rfb_client)) {
|
if (!HandleRFBServerMessage(rfb_client)) {
|
||||||
fprintf(stderr, "HANDLE FAIL\n");
|
syslog(LOG_ERR, "Error handling VNC server message\n");
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait before returning ... don't want to handle
|
/* 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;
|
rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client;
|
||||||
|
|
||||||
SendPointerEvent(rfb_client, x, y, mask);
|
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;
|
rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client;
|
||||||
|
|
||||||
SendKeyEvent(rfb_client, keysym, pressed);
|
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;
|
rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client;
|
||||||
|
|
||||||
SendClientCutText(rfb_client, data, strlen(data));
|
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;
|
rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client;
|
||||||
png_byte** png_buffer = ((vnc_guac_client_data*) client->data)->png_buffer;
|
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*/
|
/* Clean up VNC client*/
|
||||||
rfbClientCleanup(rfb_client);
|
rfbClientCleanup(rfb_client);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user