Refactored, removed functionality. Fixed most errors on compile. Will likely not...
authorMichael Jumper <zhangmaike@users.sourceforge.net>
Fri, 30 Dec 2011 08:10:28 +0000 (00:10 -0800)
committerMichael Jumper <zhangmaike@users.sourceforge.net>
Fri, 30 Dec 2011 08:10:28 +0000 (00:10 -0800)
Makefile.am
configure.in
include/client.h [new file with mode: 0644]
include/guac_handlers.h [new file with mode: 0644]
include/rdp_client.h [deleted file]
include/rdp_handlers.h
include/rdp_keymap.h
src/client.c [new file with mode: 0644]
src/guac_handlers.c [new file with mode: 0644]
src/rdp_client.c [deleted file]
src/rdp_handlers.c

index 109d801..c4e42dc 100644 (file)
@@ -41,7 +41,7 @@ AM_CFLAGS = -Werror -Wall -pedantic -Iinclude
 
 lib_LTLIBRARIES = libguac-client-rdp.la
 
-libguac_client_rdp_la_SOURCES = src/rdp_client.c src/rdp_handlers.c src/rdp_keymap.c
+libguac_client_rdp_la_SOURCES = src/client.c src/rdp_handlers.c src/rdp_keymap.c
 
 libguac_client_rdp_la_LDFLAGS = -version-info 0:0:0
 
index 076567f..48d1c20 100644 (file)
@@ -34,7 +34,7 @@
 #
 # ***** END LICENSE BLOCK *****
 
-AC_INIT(src/rdp_client.c)
+AC_INIT(src/client.c)
 AM_INIT_AUTOMAKE([libguac-client-rdp], 0.5.0)
 AC_CONFIG_MACRO_DIR([m4])
 
@@ -47,7 +47,7 @@ AC_PROG_LIBTOOL
 AC_CHECK_LIB([guac], [guac_client_plugin_open],, AC_MSG_ERROR("libguac must be installed first"))
 AC_CHECK_LIB([cairo], [cairo_create],, AC_MSG_ERROR("cairo is required for drawing instructions"))
 AC_CHECK_LIB([freerdp-core], [freerdp_new],, AC_MSG_ERROR("libfreerdp is required"))
-AC_CHECK_LIB([freerdp-chanman], [freerdp_chanman_new],, AC_MSG_ERROR("libfreerdp is required"))
+AC_CHECK_LIB([freerdp-channels], [freerdp_channels_new],, AC_MSG_ERROR("libfreerdp is required"))
 
 # Checks for header files.
 AC_CHECK_HEADERS([guacamole/client.h guacamole/guacio.h guacamole/protocol.h])
diff --git a/include/client.h b/include/client.h
new file mode 100644 (file)
index 0000000..42a0a17
--- /dev/null
@@ -0,0 +1,78 @@
+
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is libguac-client-rdp.
+ *
+ * The Initial Developer of the Original Code is
+ * Michael Jumper.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef _GUAC_RDP_CLIENT_H
+#define _GUAC_RDP_CLIENT_H
+
+#include <freerdp/freerdp.h>
+#include <freerdp/channels/channels.h>
+
+#include <guacamole/client.h>
+
+#define RDP_DEFAULT_PORT 3389
+
+typedef struct guac_rdp_color {
+    int red;
+    int green;
+    int blue;
+} guac_rdp_color;
+
+typedef struct rdp_guac_client_data {
+
+    freerdp* rdp_inst;
+    rdpChannels* channels;
+       rdpSettings* settings;
+
+    int mouse_button_mask;
+
+    guac_rdp_color foreground;
+    guac_rdp_color background;
+
+    const guac_layer* current_surface;
+
+} rdp_guac_client_data;
+
+typedef struct rdp_freerdp_context {
+
+    rdpContext _p;
+
+    guac_client* client;
+
+} rdp_freerdp_context;
+
+#endif
+
diff --git a/include/guac_handlers.h b/include/guac_handlers.h
new file mode 100644 (file)
index 0000000..e7914fa
--- /dev/null
@@ -0,0 +1,49 @@
+
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is libguac-client-rdp.
+ *
+ * The Initial Developer of the Original Code is
+ * Michael Jumper.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef _GUAC_RDP_GUAC_HANDLERS_H
+#define _GUAC_RDP_GUAC_HANDLERS_H
+
+#include <guacamole/client.h>
+
+int rdp_guac_client_free_handler(guac_client* client);
+int rdp_guac_client_handle_messages(guac_client* client);
+int rdp_guac_client_mouse_handler(guac_client* client, int x, int y, int mask);
+int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed);
+
+#endif
+
diff --git a/include/rdp_client.h b/include/rdp_client.h
deleted file mode 100644 (file)
index be0dc8d..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (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.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is libguac-client-rdp.
- *
- * The Initial Developer of the Original Code is
- * Michael Jumper.
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef _GUAC_CLIENT_RDP_CLIENT
-#define _GUAC_CLIENT_RDP_CLIENT
-
-#include <freerdp/freerdp.h>
-#include <freerdp/chanman.h>
-
-#include <guacamole/client.h>
-
-
-#define RDP_DEFAULT_PORT 3389
-
-typedef struct guac_rdp_color {
-    int red;
-    int green;
-    int blue;
-} guac_rdp_color;
-
-typedef struct rdp_guac_client_data {
-
-    rdpInst* rdp_inst;
-    rdpChanMan* chanman;
-       rdpSet* settings;
-
-    int mouse_button_mask;
-
-    guac_rdp_color foreground;
-    guac_rdp_color background;
-
-    const guac_layer* current_surface;
-
-} rdp_guac_client_data;
-
-int rdp_guac_client_free_handler(guac_client* client);
-int rdp_guac_client_handle_messages(guac_client* client);
-int rdp_guac_client_mouse_handler(guac_client* client, int x, int y, int mask);
-int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed);
-
-#endif
-
index 3b78392..67cb27e 100644 (file)
  *
  * ***** END LICENSE BLOCK ***** */
 
-#ifndef _GUAC_CLIENT_RDP_HANDLERS
-#define _GUAC_CLIENT_RDP_HANDLERS
+#ifndef _GUAC_RDP_RDP_HANDLERS_H
+#define _GUAC_RDP_RDP_HANDLERS_H
 
 #include <freerdp/freerdp.h>
+#include <freerdp/codec/bitmap.h>
 
-void guac_rdp_ui_error(rdpInst* inst, const char* text);
-void guac_rdp_ui_warning(rdpInst* inst, const char* text);
-void guac_rdp_ui_unimpl(rdpInst* inst, const char* text);
-void guac_rdp_ui_begin_update(rdpInst* inst);
-void guac_rdp_ui_end_update(rdpInst* inst);
-void guac_rdp_ui_desktop_save(rdpInst* inst, int offset, int x, int y, int cx, int cy);
-void guac_rdp_ui_desktop_restore(rdpInst* inst, int offset, int x, int y, int cx, int cy);
-RD_HBITMAP guac_rdp_ui_create_bitmap(rdpInst* inst, int width, int height, uint8* data);
-void guac_rdp_ui_paint_bitmap(rdpInst* inst, int x, int y, int cx, int cy, int width, int height, uint8* data);
-void guac_rdp_ui_destroy_bitmap(rdpInst* inst, RD_HBITMAP bmp);
-void guac_rdp_ui_line(rdpInst* inst, uint8 opcode, int startx, int starty, int endx, int endy, RD_PEN* pen);
-void guac_rdp_ui_rect(rdpInst* inst, int x, int y, int cx, int cy, uint32 colour);
-void guac_rdp_ui_polygon(rdpInst* inst, uint8 opcode, uint8 fillmode, RD_POINT* point, int npoints, RD_BRUSH* brush, uint32 bgcolor, uint32 fgcolor);
-void guac_rdp_ui_polyline(rdpInst* inst, uint8 opcode, RD_POINT* points, int npoints, RD_PEN* pen);
-void guac_rdp_ui_ellipse(rdpInst* inst, uint8 opcode, uint8 fillmode, int x, int y, int cx, int cy, RD_BRUSH* brush, uint32 bgcolor, uint32 fgcolor);
-void guac_rdp_ui_start_draw_glyphs(rdpInst* inst, uint32 bgcolor, uint32 fgcolor);
-void guac_rdp_ui_draw_glyph(rdpInst* inst, int x, int y, int cx, int cy, RD_HGLYPH glyph);
-void guac_rdp_ui_end_draw_glyphs(rdpInst* inst, int x, int y, int cx, int cy);
-uint32 guac_rdp_ui_get_toggle_keys_state(rdpInst* inst);
-void guac_rdp_ui_bell(rdpInst* inst);
-void guac_rdp_ui_destblt(rdpInst* inst, uint8 opcode, int x, int y, int cx, int cy);
-void guac_rdp_ui_patblt(rdpInst* inst, uint8 opcode, int x, int y, int cx, int cy, RD_BRUSH* brush, uint32 bgcolor, uint32 fgcolor);
-void guac_rdp_ui_screenblt(rdpInst* inst, uint8 opcode, int x, int y, int cx, int cy, int srcx, int srcy);
-void guac_rdp_ui_memblt(rdpInst* inst, uint8 opcode, int x, int y, int width, int height, RD_HBITMAP src, int srcx, int srcy);
-void guac_rdp_ui_triblt(rdpInst* inst, uint8 opcode, int x, int y, int cx, int cy, RD_HBITMAP src, int srcx, int srcy, RD_BRUSH* brush, uint32 bgcolor,  uint32 fgcolor);
-RD_HGLYPH guac_rdp_ui_create_glyph(rdpInst* inst, int width, int height, uint8* data);
-void guac_rdp_ui_destroy_glyph(rdpInst* inst, RD_HGLYPH glyph);
-int guac_rdp_ui_select(rdpInst* inst, int rdp_socket);
-void guac_rdp_ui_set_clip(rdpInst* inst, int x, int y, int cx, int cy);
-void guac_rdp_ui_reset_clip(rdpInst* inst);
-void guac_rdp_ui_resize_window(rdpInst* inst);
-void guac_rdp_ui_set_cursor(rdpInst* inst, RD_HCURSOR cursor);
-void guac_rdp_ui_destroy_cursor(rdpInst* inst, RD_HCURSOR cursor);
-RD_HCURSOR guac_rdp_ui_create_cursor(rdpInst* inst, unsigned int x, unsigned int y, int width, int height, uint8* andmask, uint8* xormask, int bpp);
-void guac_rdp_ui_set_null_cursor(rdpInst* inst);
-void guac_rdp_ui_set_default_cursor(rdpInst* inst);
-void guac_rdp_ui_move_pointer(rdpInst* inst, int x, int y);
-RD_HBITMAP guac_rdp_ui_create_surface(rdpInst* inst, int width, int height, RD_HBITMAP old);
-void guac_rdp_ui_set_surface(rdpInst* inst, RD_HBITMAP surface);
-void guac_rdp_ui_destroy_surface(rdpInst* inst, RD_HBITMAP surface);
-void guac_rdp_ui_channel_data(rdpInst* inst, int chan_id, char* data, int data_size, int flags, int total_size);
-RD_HPALETTE guac_rdp_ui_create_palette(rdpInst* inst, RD_PALETTE* colours);
-void guac_rdp_ui_set_palette(rdpInst* inst, RD_HPALETTE map);
+int guac_rdp_ui_select(freerdp* inst, int rdp_socket);
 
-extern const int guac_rdp_letter_scancodes[];
+void guac_rdp_ui_resize_window(freerdp* inst);
+
+void guac_rdp_ui_move_pointer(freerdp* inst, int x, int y);
+
+void guac_rdp_ui_set_clip(freerdp* inst, int x, int y, int cx, int cy);
+void guac_rdp_ui_reset_clip(freerdp* inst);
+
+void guac_rdp_ui_rect(freerdp* inst, int x, int y, int cx, int cy, uint32 colour);
+
+rdpBitmap* guac_rdp_ui_create_bitmap(freerdp* inst, int width, int height, uint8* data);
+void guac_rdp_ui_paint_bitmap(freerdp* inst, int x, int y, int cx, int cy, int width, int height, uint8* data);
+void guac_rdp_ui_destroy_bitmap(freerdp* inst, rdpBitmap* bmp);
+
+void guac_rdp_ui_destblt(freerdp* inst, uint8 opcode, int x, int y, int cx, int cy);
+void guac_rdp_ui_patblt(freerdp* inst, uint8 opcode, int x, int y, int cx, int cy, rdpBrush* brush, uint32 bgcolor, uint32 fgcolor);
+void guac_rdp_ui_screenblt(freerdp* inst, uint8 opcode, int x, int y, int cx, int cy, int srcx, int srcy);
+void guac_rdp_ui_memblt(freerdp* inst, uint8 opcode, int x, int y, int width, int height, rdpBitmap* src, int srcx, int srcy);
+void guac_rdp_ui_triblt(freerdp* inst, uint8 opcode, int x, int y, int cx, int cy, rdpBitmap* src, int srcx, int srcy, rdpBrush* brush, uint32 bgcolor,  uint32 fgcolor);
+
+void guac_rdp_ui_start_draw_glyphs(freerdp* inst, uint32 bgcolor, uint32 fgcolor);
+void guac_rdp_ui_draw_glyph(freerdp* inst, int x, int y, int cx, int cy, rdpGlyph* glyph);
+void guac_rdp_ui_end_draw_glyphs(freerdp* inst, int x, int y, int cx, int cy);
+rdpGlyph* guac_rdp_ui_create_glyph(freerdp* inst, int width, int height, uint8* data);
+void guac_rdp_ui_destroy_glyph(freerdp* inst, rdpGlyph* glyph);
+
+void guac_rdp_ui_set_pointer(freerdp* inst, rdpPointer pointer);
+void guac_rdp_ui_destroy_pointer(freerdp* inst, rdpPointer pointer);
+rdpPointer guac_rdp_ui_create_pointer(freerdp* inst, unsigned int x, unsigned int y, int width, int height, uint8* andmask, uint8* xormask, int bpp);
+void guac_rdp_ui_set_null_pointer(freerdp* inst);
+void guac_rdp_ui_set_default_pointer(freerdp* inst);
+
+rdpBitmap* guac_rdp_ui_create_surface(freerdp* inst, int width, int height, rdpBitmap* old);
+void guac_rdp_ui_set_surface(freerdp* inst, rdpBitmap* surface);
+void guac_rdp_ui_destroy_surface(freerdp* inst, rdpBitmap* surface);
 
 #endif
 
index a97502a..23c9367 100644 (file)
@@ -35,8 +35,8 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
-#ifndef _GUAC_CLIENT_RDP_KEYMAP
-#define _GUAC_CLIENT_RDP_KEYMAP
+#ifndef _GUAC_RDP_RDP_KEYMAP_H
+#define _GUAC_RDP_RDP_KEYMAP_H
 
 typedef struct guac_rdp_keymap {
     int scancode;
diff --git a/src/client.c b/src/client.c
new file mode 100644 (file)
index 0000000..8a71ff6
--- /dev/null
@@ -0,0 +1,173 @@
+
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is libguac-client-rdp.
+ *
+ * The Initial Developer of the Original Code is
+ * Michael Jumper.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/select.h>
+#include <errno.h>
+
+#include <freerdp/freerdp.h>
+#include <freerdp/channels/channels.h>
+#include <freerdp/input.h>
+
+#include <guacamole/socket.h>
+#include <guacamole/protocol.h>
+#include <guacamole/client.h>
+
+#include "client.h"
+#include "guac_handlers.h"
+#include "rdp_handlers.h"
+#include "rdp_keymap.h"
+
+/* Client plugin arguments */
+const char* GUAC_CLIENT_ARGS[] = {
+    "hostname",
+    "port",
+    NULL
+};
+
+void rdp_freerdp_context_new(freerdp* instance, rdpContext* context) {
+    /* EMPTY */
+}
+
+void rdp_freerdp_context_free(freerdp* instance, rdpContext* context) {
+    /* EMPTY */
+}
+
+int guac_client_init(guac_client* client, int argc, char** argv) {
+
+    rdp_guac_client_data* guac_client_data;
+
+    freerdp* rdp_inst;
+    rdpChannels* channels;
+       rdpSettings* settings;
+
+    char* hostname;
+    int port = RDP_DEFAULT_PORT;
+
+    if (argc < 2) {
+        guac_protocol_send_error(client->socket, "Wrong argument count received.");
+        guac_socket_flush(client->socket);
+        return 1;
+    }
+
+    /* If port specified, use it */
+    if (argv[1][0] != '\0')
+        port = atoi(argv[1]);
+
+    hostname = argv[0];
+
+    /* Allocate 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 */
+    rdp_inst = freerdp_new(settings);
+    if (rdp_inst == NULL) {
+        guac_protocol_send_error(client->socket, "Error initializing RDP client");
+        guac_socket_flush(client->socket);
+        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 */
+    rdp_inst->context_size = sizeof(rdp_freerdp_context);
+    rdp_inst->ContextNew  = (pContextNew) rdp_freerdp_context_new;
+    rdp_inst->ContextFree = (pContextFree) rdp_freerdp_context_free;
+    freerdp_context_new(rdp_inst);
+
+    /* Store client data */
+    ((rdp_freerdp_context*) rdp_inst->context)->client = client;
+    client->data = guac_client_data;
+
+    /* FIXME: Set RDP handlers */
+
+    /* 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 */
+    if (!freerdp_connect(rdp_inst)) {
+        guac_protocol_send_error(client->socket, "Error connecting to RDP server");
+        guac_socket_flush(client->socket);
+        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 */
+    return 0;
+
+}
+
diff --git a/src/guac_handlers.c b/src/guac_handlers.c
new file mode 100644 (file)
index 0000000..357b572
--- /dev/null
@@ -0,0 +1,256 @@
+
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is libguac-client-rdp.
+ *
+ * The Initial Developer of the Original Code is
+ * Michael Jumper.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/select.h>
+#include <errno.h>
+
+#include <freerdp/freerdp.h>
+#include <freerdp/channels/channels.h>
+#include <freerdp/input.h>
+
+#include <guacamole/socket.h>
+#include <guacamole/protocol.h>
+#include <guacamole/client.h>
+
+#include "client.h"
+#include "rdp_handlers.h"
+#include "rdp_keymap.h"
+
+int rdp_guac_client_free_handler(guac_client* client) {
+
+    rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
+
+    /* Disconnect client */
+    guac_client_data->rdp_inst->rdp_disconnect(guac_client_data->rdp_inst);
+
+    /* Free RDP client */
+    freerdp_free(guac_client_data->rdp_inst);
+    freerdp_channels_free(guac_client_data->channels);
+    free(guac_client_data->settings);
+
+    /* Free guac client data */
+    free(guac_client_data);
+
+    return 0;
+
+}
+
+int rdp_guac_client_handle_messages(guac_client* client) {
+
+    rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
+    rdpInst* rdp_inst = guac_client_data->rdp_inst;
+    rdpChannels* channels = guac_client_data->channels;
+
+    int index;
+    int max_fd, fd;
+    void* read_fds[32];
+    void* write_fds[32];
+    int read_count = 0;
+    int write_count = 0;
+
+    fd_set rfds, wfds;
+
+    /* get rdp fds */
+    if (rdp_inst->rdp_get_fds(rdp_inst, read_fds, &read_count, write_fds, &write_count) != 0) {
+        guac_client_log_error(client, "Unable to read RDP file descriptors.");
+        return 1;
+    }
+
+    /* get channel fds */
+    if (freerdp_channels_get_fds(channels, rdp_inst, read_fds, &read_count, write_fds, &write_count) != 0) {
+        guac_client_log_error(client, "Unable to read RDP channel file descriptors.");
+        return 1;
+    }
+
+    /* Construct read fd_set */
+    max_fd = 0;
+    FD_ZERO(&rfds);
+    for (index = 0; index < read_count; index++) {
+        fd = (int)(long) (read_fds[index]);
+        if (fd > max_fd)
+            max_fd = fd;
+        FD_SET(fd, &rfds);
+    }
+
+    /* Construct write fd_set */
+    FD_ZERO(&wfds);
+    for (index = 0; index < write_count; index++) {
+        fd = (int)(long) (write_fds[index]);
+        if (fd > max_fd)
+            max_fd = fd;
+        FD_SET(fd, &wfds);
+    }
+
+    /* If no file descriptors, error */
+    if (max_fd == 0) {
+        guac_client_log_error(client, "No file descriptors");
+        return 1;
+    }
+
+    /* Otherwise, wait for file descriptors given */
+    if (select(max_fd + 1, &rfds, &wfds, NULL, NULL) == -1) {
+        /* these are not really errors */
+        if (!((errno == EAGAIN) ||
+            (errno == EWOULDBLOCK) ||
+            (errno == EINPROGRESS) ||
+            (errno == EINTR))) /* signal occurred */
+        {
+            guac_client_log_error(client, "Error waiting for file descriptor.");
+            return 1;
+        }
+    }
+
+    /* check the libfreerdp fds */
+    if (rdp_inst->rdp_check_fds(rdp_inst) != 0) {
+        guac_client_log_error(client, "Error handling RDP file descriptors.");
+        return 1;
+    }
+
+    /* check channel fds */
+    if (freerdp_channels_check_fds(channels, rdp_inst) != 0) {
+        guac_client_log_error(client, "Error handling RDP channel file descriptors.");
+        return 1;
+    }
+
+    /* Success */
+    return 0;
+
+}
+
+int rdp_guac_client_mouse_handler(guac_client* client, int x, int y, int mask) {
+
+    rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
+    rdpInst* rdp_inst = guac_client_data->rdp_inst;
+
+    /* If button mask unchanged, just send move event */
+    if (mask == guac_client_data->mouse_button_mask)
+        rdp_inst->rdp_send_input_mouse(rdp_inst, PTR_FLAGS_MOVE, x, y);
+
+    /* Otherwise, send events describing button change */
+    else {
+
+        /* Mouse buttons which have JUST become released */
+        int released_mask =  guac_client_data->mouse_button_mask & ~mask;
+
+        /* Mouse buttons which have JUST become pressed */
+        int pressed_mask  = ~guac_client_data->mouse_button_mask &  mask;
+
+        /* Release event */
+        if (released_mask & 0x07) {
+
+            /* Calculate flags */
+            int flags = 0;
+            if (released_mask & 0x01) flags |= PTR_FLAGS_BUTTON1;
+            if (released_mask & 0x02) flags |= PTR_FLAGS_BUTTON3;
+            if (released_mask & 0x04) flags |= PTR_FLAGS_BUTTON2;
+
+            rdp_inst->rdp_send_input_mouse(rdp_inst, flags, x, y);
+
+        }
+
+        /* Press event */
+        if (pressed_mask & 0x07) {
+
+            /* Calculate flags */
+            int flags = PTR_FLAGS_DOWN;
+            if (pressed_mask & 0x01) flags |= PTR_FLAGS_BUTTON1;
+            if (pressed_mask & 0x02) flags |= PTR_FLAGS_BUTTON3;
+            if (pressed_mask & 0x04) flags |= PTR_FLAGS_BUTTON2;
+            if (pressed_mask & 0x08) flags |= PTR_FLAGS_WHEEL | 0x78;
+            if (pressed_mask & 0x10) flags |= PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x88;
+
+            /* Send event */
+            rdp_inst->rdp_send_input_mouse(rdp_inst, flags, x, y);
+
+        }
+
+        /* Scroll event */
+        if (pressed_mask & 0x18) {
+
+            /* Down */
+            if (pressed_mask & 0x08)
+                rdp_inst->rdp_send_input_mouse(
+                        rdp_inst,
+                        PTR_FLAGS_WHEEL | 0x78,
+                        x, y);
+
+            /* Up */
+            if (pressed_mask & 0x10)
+                rdp_inst->rdp_send_input_mouse(
+                        rdp_inst,
+                        PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x88,
+                        x, y);
+
+        }
+
+
+        guac_client_data->mouse_button_mask = mask;
+    }
+
+    return 0;
+}
+
+int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
+
+    rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
+    rdpInst* rdp_inst = guac_client_data->rdp_inst;
+
+    /* If keysym can be in lookup table */
+    if (keysym <= 0xFFFF) {
+
+        /* Look up scancode */
+        const guac_rdp_keymap* keymap = 
+            &guac_rdp_keysym_scancode[(keysym & 0xFF00) >> 8][keysym & 0xFF];
+
+        /* If defined, send event */
+        if (keymap->scancode != 0)
+            rdp_inst->rdp_send_input_scancode(
+                    rdp_inst,
+                    !pressed,
+                    keymap->flags & KBD_FLAGS_EXTENDED,
+                    keymap->scancode);
+        else
+            guac_client_log_info(client, "unmapped keysym: 0x%x", keysym);
+
+    }
+
+    return 0;
+}
+
diff --git a/src/rdp_client.c b/src/rdp_client.c
deleted file mode 100644 (file)
index 33d575a..0000000
+++ /dev/null
@@ -1,420 +0,0 @@
-
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (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.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is libguac-client-rdp.
- *
- * The Initial Developer of the Original Code is
- * Michael Jumper.
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/select.h>
-#include <errno.h>
-
-#include <freerdp/freerdp.h>
-#include <freerdp/chanman.h>
-#include <freerdp/constants/core.h>
-
-#include <guacamole/socket.h>
-#include <guacamole/protocol.h>
-#include <guacamole/client.h>
-
-#include "rdp_handlers.h"
-#include "rdp_client.h"
-#include "rdp_keymap.h"
-
-/* Client plugin arguments */
-const char* GUAC_CLIENT_ARGS[] = {
-    "hostname",
-    "port",
-    NULL
-};
-
-int rdp_guac_client_free_handler(guac_client* client) {
-
-    rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
-
-    /* Disconnect client */
-    guac_client_data->rdp_inst->rdp_disconnect(guac_client_data->rdp_inst);
-
-    /* Free RDP client */
-    freerdp_free(guac_client_data->rdp_inst);
-    freerdp_chanman_free(guac_client_data->chanman);
-    free(guac_client_data->settings);
-
-    /* Free guac client data */
-    free(guac_client_data);
-
-    return 0;
-
-}
-
-int rdp_guac_client_handle_messages(guac_client* client) {
-
-    rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
-    rdpInst* rdp_inst = guac_client_data->rdp_inst;
-    rdpChanMan* chanman = guac_client_data->chanman;
-
-    int index;
-    int max_fd, fd;
-    void* read_fds[32];
-    void* write_fds[32];
-    int read_count = 0;
-    int write_count = 0;
-
-    fd_set rfds, wfds;
-
-    /* get rdp fds */
-    if (rdp_inst->rdp_get_fds(rdp_inst, read_fds, &read_count, write_fds, &write_count) != 0) {
-        guac_client_log_error(client, "Unable to read RDP file descriptors.");
-        return 1;
-    }
-
-    /* get channel fds */
-    if (freerdp_chanman_get_fds(chanman, rdp_inst, read_fds, &read_count, write_fds, &write_count) != 0) {
-        guac_client_log_error(client, "Unable to read RDP channel file descriptors.");
-        return 1;
-    }
-
-    /* Construct read fd_set */
-    max_fd = 0;
-    FD_ZERO(&rfds);
-    for (index = 0; index < read_count; index++) {
-        fd = (int)(long) (read_fds[index]);
-        if (fd > max_fd)
-            max_fd = fd;
-        FD_SET(fd, &rfds);
-    }
-
-    /* Construct write fd_set */
-    FD_ZERO(&wfds);
-    for (index = 0; index < write_count; index++) {
-        fd = (int)(long) (write_fds[index]);
-        if (fd > max_fd)
-            max_fd = fd;
-        FD_SET(fd, &wfds);
-    }
-
-    /* If no file descriptors, error */
-    if (max_fd == 0) {
-        guac_client_log_error(client, "No file descriptors");
-        return 1;
-    }
-
-    /* Otherwise, wait for file descriptors given */
-    if (select(max_fd + 1, &rfds, &wfds, NULL, NULL) == -1) {
-        /* these are not really errors */
-        if (!((errno == EAGAIN) ||
-            (errno == EWOULDBLOCK) ||
-            (errno == EINPROGRESS) ||
-            (errno == EINTR))) /* signal occurred */
-        {
-            guac_client_log_error(client, "Error waiting for file descriptor.");
-            return 1;
-        }
-    }
-
-    /* check the libfreerdp fds */
-    if (rdp_inst->rdp_check_fds(rdp_inst) != 0) {
-        guac_client_log_error(client, "Error handling RDP file descriptors.");
-        return 1;
-    }
-
-    /* check channel fds */
-    if (freerdp_chanman_check_fds(chanman, rdp_inst) != 0) {
-        guac_client_log_error(client, "Error handling RDP channel file descriptors.");
-        return 1;
-    }
-
-    /* Success */
-    return 0;
-
-}
-
-int guac_client_init(guac_client* client, int argc, char** argv) {
-
-    rdp_guac_client_data* guac_client_data;
-
-    rdpInst* rdp_inst;
-    rdpChanMan* chanman;
-       rdpSet* settings;
-
-    char* hostname;
-    int port = RDP_DEFAULT_PORT;
-
-    if (argc < 2) {
-        guac_protocol_send_error(client->socket, "Wrong argument count received.");
-        guac_socket_flush(client->socket);
-        return 1;
-    }
-
-    /* If port specified, use it */
-    if (argv[1][0] != '\0')
-        port = atoi(argv[1]);
-
-    hostname = argv[0];
-
-    /* Allocate client data */
-    guac_client_data = malloc(sizeof(rdp_guac_client_data));
-
-    /* Get channel manager */
-    chanman = freerdp_chanman_new();
-    guac_client_data->chanman = chanman;
-
-    /* INIT SETTINGS */
-    settings = malloc(sizeof(rdpSet));
-       memset(settings, 0, sizeof(rdpSet));
-    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->server, hostname, sizeof(settings->server));
-       strcpy(settings->username, "guest");
-
-       settings->tcp_port_rdp = port;
-       settings->encryption = 1;
-       settings->server_depth = 16;
-       settings->bitmap_cache = 1;
-       settings->bitmap_compression = 1;
-       settings->desktop_save = 0;
-       settings->performanceflags =
-               PERF_DISABLE_WALLPAPER
-        | PERF_DISABLE_FULLWINDOWDRAG
-        | PERF_DISABLE_MENUANIMATIONS;
-       settings->mouse_motion = 1;
-       settings->off_screen_bitmaps = 1;
-       settings->triblt = 0;
-       settings->software_gdi = 0;
-       settings->new_cursors = 1;
-       settings->rdp_version = 5;
-       settings->rdp_security = 1;
-
-    /* Init client */
-    rdp_inst = freerdp_new(settings);
-    if (rdp_inst == NULL) {
-        guac_protocol_send_error(client->socket, "Error initializing RDP client");
-        guac_socket_flush(client->socket);
-        return 1;
-    }
-    guac_client_data->rdp_inst = rdp_inst;
-    guac_client_data->mouse_button_mask = 0;
-    guac_client_data->current_surface = GUAC_DEFAULT_LAYER;
-
-
-    /* Store client data */
-    rdp_inst->param1 = client;
-    client->data = guac_client_data;
-
-
-    /* RDP handlers */
-    rdp_inst->ui_error = guac_rdp_ui_error;
-       rdp_inst->ui_warning = guac_rdp_ui_warning;
-       rdp_inst->ui_unimpl = guac_rdp_ui_unimpl;
-       rdp_inst->ui_begin_update = guac_rdp_ui_begin_update;
-       rdp_inst->ui_end_update = guac_rdp_ui_end_update;
-       rdp_inst->ui_desktop_save = guac_rdp_ui_desktop_save;
-       rdp_inst->ui_desktop_restore = guac_rdp_ui_desktop_restore;
-       rdp_inst->ui_create_bitmap = guac_rdp_ui_create_bitmap;
-       rdp_inst->ui_paint_bitmap = guac_rdp_ui_paint_bitmap;
-       rdp_inst->ui_destroy_bitmap = guac_rdp_ui_destroy_bitmap;
-       rdp_inst->ui_line = guac_rdp_ui_line;
-       rdp_inst->ui_rect = guac_rdp_ui_rect;
-       rdp_inst->ui_polygon = guac_rdp_ui_polygon;
-       rdp_inst->ui_polyline = guac_rdp_ui_polyline;
-       rdp_inst->ui_ellipse = guac_rdp_ui_ellipse;
-       rdp_inst->ui_start_draw_glyphs = guac_rdp_ui_start_draw_glyphs;
-       rdp_inst->ui_draw_glyph = guac_rdp_ui_draw_glyph;
-       rdp_inst->ui_end_draw_glyphs = guac_rdp_ui_end_draw_glyphs;
-       rdp_inst->ui_get_toggle_keys_state = guac_rdp_ui_get_toggle_keys_state;
-       rdp_inst->ui_bell = guac_rdp_ui_bell;
-       rdp_inst->ui_destblt = guac_rdp_ui_destblt;
-       rdp_inst->ui_patblt = guac_rdp_ui_patblt;
-       rdp_inst->ui_screenblt = guac_rdp_ui_screenblt;
-       rdp_inst->ui_memblt = guac_rdp_ui_memblt;
-       rdp_inst->ui_triblt = guac_rdp_ui_triblt;
-       rdp_inst->ui_create_glyph = guac_rdp_ui_create_glyph;
-       rdp_inst->ui_destroy_glyph = guac_rdp_ui_destroy_glyph;
-    rdp_inst->ui_select = guac_rdp_ui_select;
-       rdp_inst->ui_set_clip = guac_rdp_ui_set_clip;
-       rdp_inst->ui_reset_clip = guac_rdp_ui_reset_clip;
-       rdp_inst->ui_resize_window = guac_rdp_ui_resize_window;
-       rdp_inst->ui_set_cursor = guac_rdp_ui_set_cursor;
-       rdp_inst->ui_destroy_cursor = guac_rdp_ui_destroy_cursor;
-       rdp_inst->ui_create_cursor = guac_rdp_ui_create_cursor;
-       rdp_inst->ui_set_null_cursor = guac_rdp_ui_set_null_cursor;
-       rdp_inst->ui_set_default_cursor = guac_rdp_ui_set_default_cursor;
-       rdp_inst->ui_create_palette = guac_rdp_ui_create_palette;
-       rdp_inst->ui_move_pointer = guac_rdp_ui_move_pointer;
-       rdp_inst->ui_set_palette = guac_rdp_ui_set_palette;
-       rdp_inst->ui_create_surface = guac_rdp_ui_create_surface;
-       rdp_inst->ui_set_surface = guac_rdp_ui_set_surface;
-       rdp_inst->ui_destroy_surface = guac_rdp_ui_destroy_surface;
-       rdp_inst->ui_channel_data = guac_rdp_ui_channel_data;
-
-    /* Init chanman (pre-connect) */
-    if (freerdp_chanman_pre_connect(chanman, 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 */
-    if (rdp_inst->rdp_connect(rdp_inst)) {
-        guac_protocol_send_error(client->socket, "Error connecting to RDP server");
-        guac_socket_flush(client->socket);
-        return 1;
-    }
-
-    /* Init chanman (post-connect) */
-    if (freerdp_chanman_post_connect(chanman, 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 */
-    return 0;
-
-}
-
-int rdp_guac_client_mouse_handler(guac_client* client, int x, int y, int mask) {
-
-    rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
-    rdpInst* rdp_inst = guac_client_data->rdp_inst;
-
-    /* If button mask unchanged, just send move event */
-    if (mask == guac_client_data->mouse_button_mask)
-        rdp_inst->rdp_send_input_mouse(rdp_inst, PTRFLAGS_MOVE, x, y);
-
-    /* Otherwise, send events describing button change */
-    else {
-
-        /* Mouse buttons which have JUST become released */
-        int released_mask =  guac_client_data->mouse_button_mask & ~mask;
-
-        /* Mouse buttons which have JUST become pressed */
-        int pressed_mask  = ~guac_client_data->mouse_button_mask &  mask;
-
-        /* Release event */
-        if (released_mask & 0x07) {
-
-            /* Calculate flags */
-            int flags = 0;
-            if (released_mask & 0x01) flags |= PTRFLAGS_BUTTON1;
-            if (released_mask & 0x02) flags |= PTRFLAGS_BUTTON3;
-            if (released_mask & 0x04) flags |= PTRFLAGS_BUTTON2;
-
-            rdp_inst->rdp_send_input_mouse(rdp_inst, flags, x, y);
-
-        }
-
-        /* Press event */
-        if (pressed_mask & 0x07) {
-
-            /* Calculate flags */
-            int flags = PTRFLAGS_DOWN;
-            if (pressed_mask & 0x01) flags |= PTRFLAGS_BUTTON1;
-            if (pressed_mask & 0x02) flags |= PTRFLAGS_BUTTON3;
-            if (pressed_mask & 0x04) flags |= PTRFLAGS_BUTTON2;
-            if (pressed_mask & 0x08) flags |= PTRFLAGS_WHEEL | 0x78;
-            if (pressed_mask & 0x10) flags |= PTRFLAGS_WHEEL | PTRFLAGS_WHEEL_NEGATIVE | 0x88;
-
-            /* Send event */
-            rdp_inst->rdp_send_input_mouse(rdp_inst, flags, x, y);
-
-        }
-
-        /* Scroll event */
-        if (pressed_mask & 0x18) {
-
-            /* Down */
-            if (pressed_mask & 0x08)
-                rdp_inst->rdp_send_input_mouse(
-                        rdp_inst,
-                        PTRFLAGS_WHEEL | 0x78,
-                        x, y);
-
-            /* Up */
-            if (pressed_mask & 0x10)
-                rdp_inst->rdp_send_input_mouse(
-                        rdp_inst,
-                        PTRFLAGS_WHEEL | PTRFLAGS_WHEEL_NEGATIVE | 0x88,
-                        x, y);
-
-        }
-
-
-        guac_client_data->mouse_button_mask = mask;
-    }
-
-    return 0;
-}
-
-int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
-
-    rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
-    rdpInst* rdp_inst = guac_client_data->rdp_inst;
-
-    /* If keysym can be in lookup table */
-    if (keysym <= 0xFFFF) {
-
-        /* Look up scancode */
-        const guac_rdp_keymap* keymap = 
-            &guac_rdp_keysym_scancode[(keysym & 0xFF00) >> 8][keysym & 0xFF];
-
-        /* If defined, send event */
-        if (keymap->scancode != 0)
-            rdp_inst->rdp_send_input_scancode(
-                    rdp_inst,
-                    !pressed,
-                    keymap->flags & KBDFLAGS_EXTENDED,
-                    keymap->scancode);
-        else
-            guac_client_log_info(client, "unmapped keysym: 0x%x", keysym);
-
-    }
-
-    return 0;
-}
-
index ee1304e..dc0a3a8 100644 (file)
@@ -46,8 +46,8 @@
 
 #include <freerdp/freerdp.h>
 
+#include "client.h"
 #include "rdp_handlers.h"
-#include "rdp_client.h"
 
 void guac_rdp_convert_color(int depth, int color, guac_rdp_color* comp) {
 
@@ -73,9 +73,9 @@ void guac_rdp_convert_color(int depth, int color, guac_rdp_color* comp) {
 
 }
 
-void guac_rdp_ui_error(rdpInst* inst, const char* text) {
+void guac_rdp_ui_error(freerdp* inst, const char* text) {
 
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_socket* socket = client->socket;
 
     guac_protocol_send_error(socket, text);
@@ -83,41 +83,30 @@ void guac_rdp_ui_error(rdpInst* inst, const char* text) {
 
 }
 
-void guac_rdp_ui_warning(rdpInst* inst, const char* text) {
-    guac_client* client = (guac_client*) inst->param1;
+void guac_rdp_ui_warning(freerdp* inst, const char* text) {
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_log_info(client, "guac_rdp_ui_warning: %s\n", text);
 }
 
-void guac_rdp_ui_unimpl(rdpInst* inst, const char* text) {
-    guac_client* client = (guac_client*) inst->param1;
+void guac_rdp_ui_unimpl(freerdp* inst, const char* text) {
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_log_info(client, "guac_rdp_ui_unimpl: %s\n", text);
 }
 
-void guac_rdp_ui_begin_update(rdpInst* inst) {
+void guac_rdp_ui_begin_update(freerdp* inst) {
     /* UNUSED */
 }
 
-void guac_rdp_ui_end_update(rdpInst* inst) {
-    guac_client* client = (guac_client*) inst->param1;
+void guac_rdp_ui_end_update(freerdp* inst) {
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_socket* socket = client->socket;
     guac_socket_flush(socket);
 }
 
-void guac_rdp_ui_desktop_save(rdpInst* inst, int offset, int x, int y, int cx, int cy) {
-    guac_client* client = (guac_client*) inst->param1;
-    guac_client_log_info(client, "guac_rdp_ui_desktop_save: STUB\n");
-}
-
-void guac_rdp_ui_desktop_restore(rdpInst* inst, int offset, int x, int y, int cx, int cy) {
-    guac_client* client = (guac_client*) inst->param1;
-    guac_client_log_info(client, "guac_rdp_ui_desktop_restore: STUB\n");
-}
-
-
-RD_HBITMAP guac_rdp_ui_create_bitmap(rdpInst* inst, int width, int height, uint8* data) {
+rdpBitmap* guac_rdp_ui_create_bitmap(freerdp* inst, int width, int height, uint8* data) {
 
     /* Allocate buffer */
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_socket* socket = client->socket; 
     guac_layer* buffer = guac_client_alloc_buffer(client);
 
@@ -184,13 +173,13 @@ RD_HBITMAP guac_rdp_ui_create_bitmap(rdpInst* inst, int width, int height, uint8
     cairo_surface_destroy(surface);
     free(image_buffer);
 
-    return (RD_HBITMAP) buffer;
+    return (rdpBitmap*) buffer;
 
 }
 
-void guac_rdp_ui_paint_bitmap(rdpInst* inst, int x, int y, int cx, int cy, int width, int height, uint8* data) {
+void guac_rdp_ui_paint_bitmap(freerdp* inst, int x, int y, int cx, int cy, int width, int height, uint8* data) {
 
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
     const guac_layer* current_surface = guac_client_data->current_surface; 
     guac_socket* socket = client->socket; 
@@ -268,22 +257,17 @@ void guac_rdp_ui_paint_bitmap(rdpInst* inst, int x, int y, int cx, int cy, int w
 
 }
 
-void guac_rdp_ui_destroy_bitmap(rdpInst* inst, RD_HBITMAP bmp) {
+void guac_rdp_ui_destroy_bitmap(freerdp* inst, rdpBitmap* bmp) {
 
     /* Free buffer */
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_free_buffer(client, (guac_layer*) bmp);
 
 }
 
-void guac_rdp_ui_line(rdpInst* inst, uint8 opcode, int startx, int starty, int endx, int endy, RD_PEN* pen) {
-    guac_client* client = (guac_client*) inst->param1;
-    guac_client_log_info(client, "guac_rdp_ui_line: STUB\n");
-}
-
-void guac_rdp_ui_rect(rdpInst* inst, int x, int y, int cx, int cy, uint32 color) {
+void guac_rdp_ui_rect(freerdp* inst, int x, int y, int cx, int cy, uint32 color) {
 
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
     const guac_layer* current_surface = guac_client_data->current_surface; 
     guac_socket* socket = client->socket;
@@ -316,24 +300,9 @@ void guac_rdp_ui_rect(rdpInst* inst, int x, int y, int cx, int cy, uint32 color)
 
 }
 
-void guac_rdp_ui_polygon(rdpInst* inst, uint8 opcode, uint8 fillmode, RD_POINT* point, int npoints, RD_BRUSH* brush, uint32 bgcolor, uint32 fgcolor) {
-    guac_client* client = (guac_client*) inst->param1;
-    guac_client_log_info(client, "guac_rdp_ui_polygon: STUB\n");
-}
-
-void guac_rdp_ui_polyline(rdpInst* inst, uint8 opcode, RD_POINT* points, int npoints, RD_PEN* pen) {
-    guac_client* client = (guac_client*) inst->param1;
-    guac_client_log_info(client, "guac_rdp_ui_polyline: STUB\n");
-}
+void guac_rdp_ui_start_draw_glyphs(freerdp* inst, uint32 bgcolor, uint32 fgcolor) {
 
-void guac_rdp_ui_ellipse(rdpInst* inst, uint8 opcode, uint8 fillmode, int x, int y, int cx, int cy, RD_BRUSH*  brush, uint32 bgcolor, uint32 fgcolor) {
-    guac_client* client = (guac_client*) inst->param1;
-    guac_client_log_info(client, "guac_rdp_ui_ellipse: STUB\n");
-}
-
-void guac_rdp_ui_start_draw_glyphs(rdpInst* inst, uint32 bgcolor, uint32 fgcolor) {
-
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
 
     guac_rdp_convert_color(
@@ -348,9 +317,9 @@ void guac_rdp_ui_start_draw_glyphs(rdpInst* inst, uint32 bgcolor, uint32 fgcolor
 
 }
 
-void guac_rdp_ui_draw_glyph(rdpInst* inst, int x, int y, int width, int height, RD_HGLYPH glyph) {
+void guac_rdp_ui_draw_glyph(freerdp* inst, int x, int y, int width, int height, rdpGlyph* glyph) {
 
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
     const guac_layer* current_surface = guac_client_data->current_surface; 
     guac_socket* socket = client->socket;
@@ -359,7 +328,7 @@ void guac_rdp_ui_draw_glyph(rdpInst* inst, int x, int y, int width, int height,
     /* Temporarily removed BG drawing... */
 
     /* Foreground */
-    guac_protocol_send_rect(socket, GUAC_COMP_ATOP, glyph,
+    guac_protocol_send_rect(socket, GUAC_COMP_ATOP, (guac_layer*) glyph,
             0, 0, width, height,
             guac_client_data->foreground.red,
             guac_client_data->foreground.green,
@@ -381,34 +350,23 @@ void guac_rdp_ui_draw_glyph(rdpInst* inst, int x, int y, int width, int height,
 
 }
 
-void guac_rdp_ui_end_draw_glyphs(rdpInst* inst, int x, int y, int cx, int cy) {
+void guac_rdp_ui_end_draw_glyphs(freerdp* inst, int x, int y, int cx, int cy) {
     /* UNUSED */
 }
 
-uint32 guac_rdp_ui_get_toggle_keys_state(rdpInst* inst) {
-    guac_client* client = (guac_client*) inst->param1;
-    guac_client_log_info(client, "guac_rdp_ui_get_toggle_keys_state: STUB\n");
-    return 0;
-}
-
-void guac_rdp_ui_bell(rdpInst* inst) {
-    guac_client* client = (guac_client*) inst->param1;
-    guac_client_log_info(client, "guac_rdp_ui_bell: STUB\n");
-}
-
-void guac_rdp_ui_destblt(rdpInst* inst, uint8 opcode, int x, int y, int cx, int cy) {
-    guac_client* client = (guac_client*) inst->param1;
+void guac_rdp_ui_destblt(freerdp* inst, uint8 opcode, int x, int y, int cx, int cy) {
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_log_info(client, "guac_rdp_ui_destblt: STUB\n");
 }
 
-void guac_rdp_ui_patblt(rdpInst* inst, uint8 opcode, int x, int y, int cx, int cy, RD_BRUSH* brush, uint32 bgcolor, uint32 fgcolor) {
-    guac_client* client = (guac_client*) inst->param1;
+void guac_rdp_ui_patblt(freerdp* inst, uint8 opcode, int x, int y, int cx, int cy, rdpBrush* brush, uint32 bgcolor, uint32 fgcolor) {
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_log_info(client, "guac_rdp_ui_patblt: STUB\n");
 }
 
-void guac_rdp_ui_screenblt(rdpInst* inst, uint8 opcode, int x, int y, int cx, int cy, int srcx, int srcy) {
+void guac_rdp_ui_screenblt(freerdp* inst, uint8 opcode, int x, int y, int cx, int cy, int srcx, int srcy) {
 
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
     const guac_layer* current_surface = guac_client_data->current_surface; 
     guac_socket* socket = client->socket;
@@ -419,9 +377,9 @@ void guac_rdp_ui_screenblt(rdpInst* inst, uint8 opcode, int x, int y, int cx, in
 
 }
 
-void guac_rdp_ui_memblt(rdpInst* inst, uint8 opcode, int x, int y, int width, int height, RD_HBITMAP src, int srcx, int srcy) {
+void guac_rdp_ui_memblt(freerdp* inst, uint8 opcode, int x, int y, int width, int height, rdpBitmap* src, int srcx, int srcy) {
 
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
     const guac_layer* current_surface = guac_client_data->current_surface;
     guac_socket* socket = client->socket;
@@ -437,15 +395,15 @@ void guac_rdp_ui_memblt(rdpInst* inst, uint8 opcode, int x, int y, int width, in
 
 }
 
-void guac_rdp_ui_triblt(rdpInst* inst, uint8 opcode, int x, int y, int cx, int cy, RD_HBITMAP src, int srcx, int srcy, RD_BRUSH* brush, uint32 bgcolor,  uint32 fgcolor) {
-    guac_client* client = (guac_client*) inst->param1;
+void guac_rdp_ui_triblt(freerdp* inst, uint8 opcode, int x, int y, int cx, int cy, rdpBitmap* src, int srcx, int srcy, rdpBrush* brush, uint32 bgcolor,  uint32 fgcolor) {
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_log_info(client, "guac_rdp_ui_triblt: STUB\n");
 }
 
-RD_HGLYPH guac_rdp_ui_create_glyph(rdpInst* inst, int width, int height, uint8* data) {
+rdpGlyph* guac_rdp_ui_create_glyph(freerdp* inst, int width, int height, uint8* data) {
 
     /* Allocate buffer */
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_socket* socket = client->socket;
     guac_layer* glyph = guac_client_alloc_buffer(client);
 
@@ -501,25 +459,25 @@ RD_HGLYPH guac_rdp_ui_create_glyph(rdpInst* inst, int width, int height, uint8*
     free(image_buffer);
 
 
-    return (RD_HGLYPH) glyph;
+    return (rdpGlyph*) glyph;
 
 }
 
-void guac_rdp_ui_destroy_glyph(rdpInst* inst, RD_HGLYPH glyph) {
+void guac_rdp_ui_destroy_glyph(freerdp* inst, rdpGlyph* glyph) {
 
     /* Free buffer */
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_free_buffer(client, (guac_layer*) glyph);
 
 }
 
-int guac_rdp_ui_select(rdpInst* inst, int rdp_socket) {
+int guac_rdp_ui_select(freerdp* inst, int rdp_socket) {
     return 1;
 }
 
-void guac_rdp_ui_set_clip(rdpInst* inst, int x, int y, int cx, int cy) {
+void guac_rdp_ui_set_clip(freerdp* inst, int x, int y, int cx, int cy) {
 
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
     const guac_layer* current_surface = guac_client_data->current_surface; 
     guac_socket* socket = client->socket;
@@ -528,9 +486,9 @@ void guac_rdp_ui_set_clip(rdpInst* inst, int x, int y, int cx, int cy) {
 
 }
 
-void guac_rdp_ui_reset_clip(rdpInst* inst) {
+void guac_rdp_ui_reset_clip(freerdp* inst) {
 
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
     const guac_layer* current_surface = guac_client_data->current_surface; 
     guac_socket* socket = client->socket;
@@ -539,56 +497,45 @@ void guac_rdp_ui_reset_clip(rdpInst* inst) {
 
 }
 
-void guac_rdp_ui_resize_window(rdpInst* inst) {
-    guac_client* client = (guac_client*) inst->param1;
+void guac_rdp_ui_resize_window(freerdp* inst) {
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_log_info(client, "guac_rdp_ui_resize_window: %ix%i\n", inst->settings->width, inst->settings->height);
 }
 
-void guac_rdp_ui_set_cursor(rdpInst* inst, RD_HCURSOR cursor) {
-    guac_client* client = (guac_client*) inst->param1;
+void guac_rdp_ui_set_cursor(freerdp* inst, rdpPointer* cursor) {
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_log_info(client, "guac_rdp_ui_set_cursor: STUB\n");
 }
 
-void guac_rdp_ui_destroy_cursor(rdpInst* inst, RD_HCURSOR cursor) {
-    guac_client* client = (guac_client*) inst->param1;
+void guac_rdp_ui_destroy_cursor(freerdp* inst, rdpPointer* cursor) {
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_log_info(client, "guac_rdp_ui_destroy_cursor: STUB\n");
 }
 
-RD_HCURSOR guac_rdp_ui_create_cursor(rdpInst* inst, unsigned int x, unsigned int y, int width, int height, uint8* andmask, uint8* xormask, int bpp) {
+rdpPointer* guac_rdp_ui_create_cursor(freerdp* inst, unsigned int x, unsigned int y, int width, int height, uint8* andmask, uint8* xormask, int bpp) {
     
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_log_info(client, "guac_rdp_ui_create_cursor: STUB\n");
-    return guac_client_alloc_buffer(client);
+    return (rdpPointer*) guac_client_alloc_buffer(client);
 
 }
 
-void guac_rdp_ui_set_null_cursor(rdpInst* inst) {
-    guac_client* client = (guac_client*) inst->param1;
+void guac_rdp_ui_set_null_cursor(freerdp* inst) {
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_log_info(client, "guac_rdp_ui_set_null_cursor: STUB\n");
 }
 
-void guac_rdp_ui_set_default_cursor(rdpInst* inst) {
-    guac_client* client = (guac_client*) inst->param1;
+void guac_rdp_ui_set_default_cursor(freerdp* inst) {
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_log_info(client, "guac_rdp_ui_set_default_cursor: STUB\n");
 }
 
-RD_HPALETTE guac_rdp_ui_create_colormap(rdpInst* inst, RD_PALETTE* colors) {
-    guac_client* client = (guac_client*) inst->param1;
-    guac_client_log_info(client, "guac_rdp_ui_create_colormap: STUB\n");
-    return NULL;
-}
-
-void guac_rdp_ui_move_pointer(rdpInst* inst, int x, int y) {
-    guac_client* client = (guac_client*) inst->param1;
+void guac_rdp_ui_move_pointer(freerdp* inst, int x, int y) {
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_log_info(client, "guac_rdp_ui_move_pointer: STUB\n");
 }
 
-void guac_rdp_ui_set_colormap(rdpInst* inst, RD_HPALETTE map) {
-    guac_client* client = (guac_client*) inst->param1;
-    guac_client_log_info(client, "guac_rdp_ui_set_colormap: STUB\n");
-}
-
-RD_HBITMAP guac_rdp_ui_create_surface(rdpInst* inst, int width, int height, RD_HBITMAP old) {
+rdpBitmap* guac_rdp_ui_create_surface(freerdp* inst, int width, int height, rdpBitmap* old) {
 
     /* If old provided, just return that one ... */
     if (old != NULL)
@@ -596,15 +543,15 @@ RD_HBITMAP guac_rdp_ui_create_surface(rdpInst* inst, int width, int height, RD_H
 
     /* Otherwise allocate and return new buffer */
     else {
-        guac_client* client = (guac_client*) inst->param1;
-        return (RD_HBITMAP) guac_client_alloc_buffer(client);
+        guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
+        return (rdpBitmap*) guac_client_alloc_buffer(client);
     }
 
 }
 
-void guac_rdp_ui_set_surface(rdpInst* inst, RD_HBITMAP surface) {
+void guac_rdp_ui_set_surface(freerdp* inst, rdpBitmap* surface) {
 
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
     guac_socket* socket = client->socket;
 
@@ -620,32 +567,16 @@ void guac_rdp_ui_set_surface(rdpInst* inst, RD_HBITMAP surface) {
         guac_client_data->current_surface = GUAC_DEFAULT_LAYER;
     }
     else {
-        guac_client_data->current_surface = surface;
+        guac_client_data->current_surface = (guac_layer*) surface;
     }
 
 }
 
-void guac_rdp_ui_destroy_surface(rdpInst* inst, RD_HBITMAP surface) {
+void guac_rdp_ui_destroy_surface(freerdp* inst, rdpBitmap* surface) {
 
     /* Free buffer */
-    guac_client* client = (guac_client*) inst->param1;
+    guac_client* client = ((rdp_freerdp_context*) inst->context)->client;
     guac_client_free_buffer(client, (guac_layer*) surface);
 
 }
 
-void guac_rdp_ui_channel_data(rdpInst* inst, int chan_id, char* data, int data_size, int flags, int total_size) {
-    guac_client* client = (guac_client*) inst->param1;
-    guac_client_log_info(client, "guac_rdp_ui_channel_data: STUB\n");
-}
-
-RD_HPALETTE guac_rdp_ui_create_palette(rdpInst* inst, RD_PALETTE* colours) {
-    guac_client* client = (guac_client*) inst->param1;
-    guac_client_log_info(client, "guac_rdp_ui_create_palette: STUB\n");
-    return NULL;
-}
-
-void guac_rdp_ui_set_palette(rdpInst* inst, RD_HPALETTE map) {
-    guac_client* client = (guac_client*) inst->param1;
-    guac_client_log_info(client, "guac_rdp_ui_set_palette: STUB\n");
-}
-