diff --git a/protocols/vnc/Makefile.am b/protocols/vnc/Makefile.am index 8bdef3e1..5490eb8c 100644 --- a/protocols/vnc/Makefile.am +++ b/protocols/vnc/Makefile.am @@ -37,11 +37,13 @@ AUTOMAKE_OPTIONS = foreign ACLOCAL_AMFLAGS = -I m4 -AM_CFLAGS = -Werror -Wall -pedantic +AM_CFLAGS = -Werror -Wall -pedantic -Iinclude lib_LTLIBRARIES = libguac-client-vnc.la -libguac_client_vnc_la_SOURCES = src/vnc_client.c +libguac_client_vnc_la_SOURCES = src/client.c src/vnc_handlers.c src/guac_handlers.c +noinst_HEADERS = include/client.h include/vnc_handlers.h include/guac_handlers.h + libguac_client_vnc_la_LDFLAGS = -version-info 0:0:0 diff --git a/protocols/vnc/configure.in b/protocols/vnc/configure.in index 18ac46bd..8cb63fab 100644 --- a/protocols/vnc/configure.in +++ b/protocols/vnc/configure.in @@ -34,7 +34,7 @@ # # ***** END LICENSE BLOCK ***** -AC_INIT(src/vnc_client.c) +AC_INIT(src/client.c) AM_INIT_AUTOMAKE([libguac-client-vnc], 0.5.0) AC_CONFIG_MACRO_DIR([m4]) diff --git a/protocols/vnc/include/client.h b/protocols/vnc/include/client.h new file mode 100644 index 00000000..1eba8537 --- /dev/null +++ b/protocols/vnc/include/client.h @@ -0,0 +1,57 @@ + +/* ***** 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-vnc. + * + * The Initial Developer of the Original Code is + * Michael Jumper. + * Portions created by the Initial Developer are Copyright (C) 2010 + * 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_VNC_CLIENT_H +#define __GUAC_VNC_CLIENT_H + +#include + +extern char* __GUAC_CLIENT; + +typedef struct vnc_guac_client_data { + + rfbClient* rfb_client; + MallocFrameBufferProc rfb_MallocFrameBuffer; + + int copy_rect_used; + char* password; + char* encodings; + +} vnc_guac_client_data; + +#endif + diff --git a/protocols/vnc/include/guac_handlers.h b/protocols/vnc/include/guac_handlers.h new file mode 100644 index 00000000..90ed4c1c --- /dev/null +++ b/protocols/vnc/include/guac_handlers.h @@ -0,0 +1,60 @@ + +/* ***** 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-vnc. + * + * The Initial Developer of the Original Code is + * Michael Jumper. + * Portions created by the Initial Developer are Copyright (C) 2010 + * 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_VNC_GUAC_HANDLERS_H +#define __GUAC_VNC_GUAC_HANDLERS_H + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +int vnc_guac_client_handle_messages(guac_client* client); +int vnc_guac_client_mouse_handler(guac_client* client, int x, int y, int mask); +int vnc_guac_client_key_handler(guac_client* client, int keysym, int pressed); +int vnc_guac_client_clipboard_handler(guac_client* client, char* data); +int vnc_guac_client_free_handler(guac_client* client); + +#endif + diff --git a/protocols/vnc/include/vnc_handlers.h b/protocols/vnc/include/vnc_handlers.h new file mode 100644 index 00000000..87dd8824 --- /dev/null +++ b/protocols/vnc/include/vnc_handlers.h @@ -0,0 +1,60 @@ + +/* ***** 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-vnc. + * + * The Initial Developer of the Original Code is + * Michael Jumper. + * Portions created by the Initial Developer are Copyright (C) 2010 + * 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 +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include + +void guac_vnc_cursor(rfbClient* client, int x, int y, int w, int h, int bpp); +void guac_vnc_update(rfbClient* client, int x, int y, int w, int h); +void guac_vnc_copyrect(rfbClient* client, int src_x, int src_y, int w, int h, int dest_x, int dest_y); +char* guac_vnc_get_password(rfbClient* client); +rfbBool guac_vnc_malloc_framebuffer(rfbClient* rfb_client); +void guac_vnc_cut_text(rfbClient* client, const char* text, int textlen); +void guac_vnc_client_log_info(const char* format, ...); +void guac_vnc_client_log_error(const char* format, ...); + diff --git a/protocols/vnc/src/client.c b/protocols/vnc/src/client.c index bad597b8..9e0755f3 100644 --- a/protocols/vnc/src/client.c +++ b/protocols/vnc/src/client.c @@ -41,14 +41,16 @@ #include #include -#include - #include #include #include #include +#include "client.h" +#include "vnc_handlers.h" +#include "guac_handlers.h" + /* Client plugin arguments */ const char* GUAC_CLIENT_ARGS[] = { "hostname", @@ -59,128 +61,7 @@ const char* GUAC_CLIENT_ARGS[] = { NULL }; -static char* __GUAC_CLIENT = "GUAC_CLIENT"; - -typedef struct vnc_guac_client_data { - - rfbClient* rfb_client; - MallocFrameBufferProc rfb_MallocFrameBuffer; - - int copy_rect_used; - char* password; - char* encodings; - -} vnc_guac_client_data; - -int vnc_guac_client_handle_messages(guac_client* client) { - - int wait_result; - rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client; - - wait_result = WaitForMessage(rfb_client, 1000000); - if (wait_result < 0) { - guac_client_log_error(client, "Error waiting for VNC server message\n"); - return 1; - } - - if (wait_result > 0) { - - if (!HandleRFBServerMessage(rfb_client)) { - guac_client_log_error(client, "Error handling VNC server message\n"); - return 1; - } - - } - - return 0; - -} - - -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; -} - -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; -} - -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; -} - -int vnc_guac_client_free_handler(guac_client* client) { - - vnc_guac_client_data* guac_client_data = (vnc_guac_client_data*) client->data; - rfbClient* rfb_client = guac_client_data->rfb_client; - - /* Free encodings string, if used */ - if (guac_client_data->encodings != NULL) - free(guac_client_data->encodings); - - /* Free generic data struct */ - free(client->data); - - /* Free memory not free'd by libvncclient's rfbClientCleanup() */ - if (rfb_client->frameBuffer != NULL) free(rfb_client->frameBuffer); - if (rfb_client->raw_buffer != NULL) free(rfb_client->raw_buffer); - if (rfb_client->rcSource != NULL) free(rfb_client->rcSource); - - /* Free VNC rfbClientData linked list (not free'd by rfbClientCleanup()) */ - while (rfb_client->clientData != NULL) { - rfbClientData* next = rfb_client->clientData->next; - free(rfb_client->clientData); - rfb_client->clientData = next; - } - - /* Clean up VNC client*/ - rfbClientCleanup(rfb_client); - - return 0; -} - - -/* - * Logging, required as libvncclient does not pass the client - * to its logging functions, thus we cannot use guac_client_log*() - */ -void vnc_guac_client_log_info(const char* format, ...) { - - va_list args; - va_start(args, format); - - vsyslog(LOG_INFO, format, args); - - va_end(args); - -} - -void vnc_guac_client_log_error(const char* format, ...) { - - va_list args; - va_start(args, format); - - vsyslog(LOG_ERR, format, args); - - va_end(args); - -} - +char* __GUAC_CLIENT = "GUAC_CLIENT"; int guac_client_init(guac_client* client, int argc, char** argv) { @@ -191,8 +72,8 @@ int guac_client_init(guac_client* client, int argc, char** argv) { int read_only = 0; /* Set up libvncclient logging */ - rfbClientLog = vnc_guac_client_log_info; - rfbClientErr = vnc_guac_client_log_error; + rfbClientLog = guac_vnc_client_log_info; + rfbClientErr = guac_vnc_client_log_error; /*** PARSE ARGUMENTS ***/ diff --git a/protocols/vnc/src/guac_handlers.c b/protocols/vnc/src/guac_handlers.c index 7c5f4466..a7c2704b 100644 --- a/protocols/vnc/src/guac_handlers.c +++ b/protocols/vnc/src/guac_handlers.c @@ -41,26 +41,13 @@ #include #include -#include - #include #include #include #include -static char* __GUAC_CLIENT = "GUAC_CLIENT"; - -typedef struct vnc_guac_client_data { - - rfbClient* rfb_client; - MallocFrameBufferProc rfb_MallocFrameBuffer; - - int copy_rect_used; - char* password; - char* encodings; - -} vnc_guac_client_data; +#include "client.h" int vnc_guac_client_handle_messages(guac_client* client) { @@ -144,9 +131,3 @@ int vnc_guac_client_free_handler(guac_client* client) { return 0; } - -/* - * Logging, required as libvncclient does not pass the client - * to its logging functions, thus we cannot use guac_client_log*() - */ - diff --git a/protocols/vnc/src/vnc_handlers.c b/protocols/vnc/src/vnc_handlers.c index 90183603..b40046ed 100644 --- a/protocols/vnc/src/vnc_handlers.c +++ b/protocols/vnc/src/vnc_handlers.c @@ -49,6 +49,8 @@ #include #include +#include "client.h" + void guac_vnc_cursor(rfbClient* client, int x, int y, int w, int h, int bpp) { guac_client* gc = rfbClientGetClientData(client, __GUAC_CLIENT);