Fixed handlers and segfaults.

This commit is contained in:
Michael Jumper 2012-01-03 01:01:33 -08:00
parent 54d815f258
commit c39e00a129
3 changed files with 74 additions and 66 deletions

View File

@ -39,7 +39,6 @@
#define _GUAC_RDP_CLIENT_H #define _GUAC_RDP_CLIENT_H
#include <freerdp/freerdp.h> #include <freerdp/freerdp.h>
#include <freerdp/channels/channels.h>
#include <guacamole/client.h> #include <guacamole/client.h>
@ -54,7 +53,6 @@ typedef struct guac_rdp_color {
typedef struct rdp_guac_client_data { typedef struct rdp_guac_client_data {
freerdp* rdp_inst; freerdp* rdp_inst;
rdpChannels* channels;
rdpSettings* settings; rdpSettings* settings;
int mouse_button_mask; int mouse_button_mask;

View File

@ -63,8 +63,59 @@ const char* GUAC_CLIENT_ARGS[] = {
NULL NULL
}; };
boolean rdp_freerdp_pre_connect(freerdp* instance) {
rdpContext* context = instance->context;
guac_client* client = ((rdp_freerdp_context*) context)->client;
rdpChannels* channels = context->channels;
rdpBitmap* bitmap;
/* Set up bitmap handling */
bitmap = xnew(rdpBitmap);
bitmap->size = sizeof(guac_rdp_bitmap);
bitmap->New = guac_rdp_bitmap_new;
/* bitmap->Free = guac_rdp_bitmap_free; */
/* bitmap->Paint = guac_rdp_bitmap_paint; */
/* bitmap->Decompress = guac_rdp_bitmap_decompress; */
/* bitmap->SetSurface = guac_rdp_bitmap_setsurface; */
graphics_register_bitmap(context->graphics, bitmap);
/* Init channels (pre-connect) */
if (freerdp_channels_pre_connect(channels, instance)) {
guac_protocol_send_error(client->socket, "Error initializing RDP client channel manager");
guac_socket_flush(client->socket);
return false;
}
return true;
}
boolean rdp_freerdp_post_connect(freerdp* instance) {
rdpContext* context = instance->context;
guac_client* client = ((rdp_freerdp_context*) context)->client;
rdpChannels* channels = instance->context->channels;
/* Init channels (post-connect) */
if (freerdp_channels_post_connect(channels, instance)) {
guac_protocol_send_error(client->socket, "Error initializing RDP client channel manager");
guac_socket_flush(client->socket);
return false;
}
/* Client handlers */
client->free_handler = rdp_guac_client_free_handler;
client->handle_messages = rdp_guac_client_handle_messages;
client->mouse_handler = rdp_guac_client_mouse_handler;
client->key_handler = rdp_guac_client_key_handler;
return true;
}
void rdp_freerdp_context_new(freerdp* instance, rdpContext* context) { void rdp_freerdp_context_new(freerdp* instance, rdpContext* context) {
/* EMPTY */ context->channels = freerdp_channels_new();
} }
void rdp_freerdp_context_free(freerdp* instance, rdpContext* context) { void rdp_freerdp_context_free(freerdp* instance, rdpContext* context) {
@ -76,9 +127,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
rdp_guac_client_data* guac_client_data; rdp_guac_client_data* guac_client_data;
freerdp* rdp_inst; freerdp* rdp_inst;
rdpChannels* channels;
rdpSettings* settings; rdpSettings* settings;
rdpBitmap* bitmap;
char* hostname; char* hostname;
int port = RDP_DEFAULT_PORT; int port = RDP_DEFAULT_PORT;
@ -98,37 +147,11 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
/* Allocate client data */ /* Allocate client data */
guac_client_data = malloc(sizeof(rdp_guac_client_data)); guac_client_data = malloc(sizeof(rdp_guac_client_data));
/* Get channel manager */
channels = freerdp_channels_new();
guac_client_data->channels = channels;
/* INIT SETTINGS */
settings = malloc(sizeof(rdpSettings));
memset(settings, 0, sizeof(rdpSettings));
guac_client_data->settings = settings;
/* Set hostname */
strncpy(settings->hostname, hostname, sizeof(settings->hostname) - 1);
/* Default size */
settings->width = 1024;
settings->height = 768;
strncpy(settings->window_title, hostname, sizeof(settings->window_title));
strcpy(settings->username, "guest");
/* FIXME: Set RDP settings->* */
/* Init client */ /* Init client */
rdp_inst = freerdp_new(settings); freerdp_channels_global_init();
if (rdp_inst == NULL) { rdp_inst = freerdp_new();
guac_protocol_send_error(client->socket, "Error initializing RDP client"); rdp_inst->PreConnect = rdp_freerdp_pre_connect;
guac_socket_flush(client->socket); rdp_inst->PostConnect = rdp_freerdp_post_connect;
return 1;
}
guac_client_data->rdp_inst = rdp_inst;
guac_client_data->mouse_button_mask = 0;
guac_client_data->current_surface = GUAC_DEFAULT_LAYER;
/* Allocate FreeRDP context */ /* Allocate FreeRDP context */
rdp_inst->context_size = sizeof(rdp_freerdp_context); rdp_inst->context_size = sizeof(rdp_freerdp_context);
@ -136,27 +159,27 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
rdp_inst->ContextFree = (pContextFree) rdp_freerdp_context_free; rdp_inst->ContextFree = (pContextFree) rdp_freerdp_context_free;
freerdp_context_new(rdp_inst); freerdp_context_new(rdp_inst);
/* Set settings */
settings = rdp_inst->settings;
/* Default size */
settings->width = 1024;
settings->height = 768;
/* Set hostname */
settings->hostname = strdup(hostname);
settings->window_title = strdup(hostname);
settings->username = "guest";
/* Store client data */ /* Store client data */
guac_client_data->rdp_inst = rdp_inst;
guac_client_data->mouse_button_mask = 0;
guac_client_data->current_surface = GUAC_DEFAULT_LAYER;
((rdp_freerdp_context*) rdp_inst->context)->client = client; ((rdp_freerdp_context*) rdp_inst->context)->client = client;
client->data = guac_client_data; client->data = guac_client_data;
/* Set up bitmap handling */
bitmap = xnew(rdpBitmap);
bitmap->size = sizeof(guac_rdp_bitmap);
bitmap->New = guac_rdp_bitmap_new;
/* bitmap->Free = guac_rdp_bitmap_free; */
/* bitmap->Paint = guac_rdp_bitmap_paint; */
/* bitmap->Decompress = guac_rdp_bitmap_decompress; */
/* bitmap->SetSurface = guac_rdp_bitmap_setsurface; */
graphics_register_bitmap(rdp_inst->context->graphics, bitmap);
/* Init channels (pre-connect) */
if (freerdp_channels_pre_connect(channels, rdp_inst)) {
guac_protocol_send_error(client->socket, "Error initializing RDP client channel manager");
guac_socket_flush(client->socket);
return 1;
}
/* Connect to RDP server */ /* Connect to RDP server */
if (!freerdp_connect(rdp_inst)) { if (!freerdp_connect(rdp_inst)) {
guac_protocol_send_error(client->socket, "Error connecting to RDP server"); guac_protocol_send_error(client->socket, "Error connecting to RDP server");
@ -164,19 +187,6 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
return 1; return 1;
} }
/* Init channels (post-connect) */
if (freerdp_channels_post_connect(channels, rdp_inst)) {
guac_protocol_send_error(client->socket, "Error initializing RDP client channel manager");
guac_socket_flush(client->socket);
return 1;
}
/* Client handlers */
client->free_handler = rdp_guac_client_free_handler;
client->handle_messages = rdp_guac_client_handle_messages;
client->mouse_handler = rdp_guac_client_mouse_handler;
client->key_handler = rdp_guac_client_key_handler;
/* Success */ /* Success */
return 0; return 0;

View File

@ -67,7 +67,7 @@ int rdp_guac_client_handle_messages(guac_client* client) {
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data; rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
freerdp* rdp_inst = guac_client_data->rdp_inst; freerdp* rdp_inst = guac_client_data->rdp_inst;
rdpChannels* channels = guac_client_data->channels; rdpChannels* channels = rdp_inst->context->channels;
int index; int index;
int max_fd, fd; int max_fd, fd;