diff --git a/src/guacd/client.c b/src/guacd/client.c index 2ab29be5..53fd45d6 100644 --- a/src/guacd/client.c +++ b/src/guacd/client.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include diff --git a/src/libguac/Makefile.am b/src/libguac/Makefile.am index dff58ba9..f8ed0630 100644 --- a/src/libguac/Makefile.am +++ b/src/libguac/Makefile.am @@ -25,19 +25,37 @@ ACLOCAL_AMFLAGS = -I m4 AM_CFLAGS = -Werror -Wall -pedantic -Iguacamole libguacincdir = $(includedir)/guacamole -libguacinc_HEADERS = \ - guacamole/audio.h \ - guacamole/client.h \ - guacamole/error.h \ - guacamole/hash.h \ - guacamole/instruction.h \ - guacamole/layer.h \ - guacamole/plugin.h \ - guacamole/pool.h \ - guacamole/protocol.h \ - guacamole/socket.h \ - guacamole/stream.h \ - guacamole/timestamp.h \ +libguacinc_HEADERS = \ + guacamole/audio.h \ + guacamole/audio-fntypes.h \ + guacamole/audio-types.h \ + guacamole/client-constants.h \ + guacamole/client.h \ + guacamole/client-fntypes.h \ + guacamole/client-types.h \ + guacamole/error.h \ + guacamole/error-types.h \ + guacamole/hash.h \ + guacamole/instruction-constants.h \ + guacamole/instruction.h \ + guacamole/instruction-types.h \ + guacamole/layer.h \ + guacamole/layer-types.h \ + guacamole/plugin-constants.h \ + guacamole/plugin.h \ + guacamole/plugin-types.h \ + guacamole/pool.h \ + guacamole/pool-types.h \ + guacamole/protocol.h \ + guacamole/protocol-types.h \ + guacamole/socket-constants.h \ + guacamole/socket.h \ + guacamole/socket-fntypes.h \ + guacamole/socket-types.h \ + guacamole/stream.h \ + guacamole/stream-types.h \ + guacamole/timestamp.h \ + guacamole/timestamp-types.h \ guacamole/unicode.h noinst_HEADERS = \ diff --git a/src/libguac/client-handlers.c b/src/libguac/client-handlers.c index dc418329..139362c3 100644 --- a/src/libguac/client-handlers.c +++ b/src/libguac/client-handlers.c @@ -98,10 +98,8 @@ int __guac_handle_key(guac_client* client, guac_instruction* instruction) { return 0; } -int __guac_handle_clipboard(guac_client* client, guac_instruction* instruction) { +static guac_stream* __get_input_stream(guac_client* client, int stream_index) { - /* Pull corresponding stream */ - int stream_index = atoi(instruction->argv[0]); guac_stream* stream; /* Validate stream index */ @@ -112,13 +110,63 @@ int __guac_handle_clipboard(guac_client* client, guac_instruction* instruction) guac_protocol_send_ack(client->socket, &dummy_stream, "Invalid stream index", GUAC_PROTOCOL_STATUS_CLIENT_BAD_REQUEST); - return 0; + return NULL; } + return stream; + +} + +static guac_stream* __get_open_input_stream(guac_client* client, int stream_index) { + + guac_stream* stream = __get_input_stream(client, stream_index); + + /* Fail if no such stream */ + if (stream == NULL) + return NULL; + + /* Validate initialization of stream */ + if (stream->index == GUAC_CLIENT_CLOSED_STREAM_INDEX) { + + guac_stream dummy_stream; + dummy_stream.index = stream_index; + + guac_protocol_send_ack(client->socket, &dummy_stream, + "Invalid stream index", GUAC_PROTOCOL_STATUS_CLIENT_BAD_REQUEST); + return NULL; + } + + return stream; + +} + +static guac_stream* __init_input_stream(guac_client* client, int stream_index) { + + guac_stream* stream = __get_input_stream(client, stream_index); + + /* Fail if no such stream */ + if (stream == NULL) + return NULL; + /* Initialize stream */ stream = &(client->__input_streams[stream_index]); stream->index = stream_index; stream->data = NULL; + stream->ack_handler = NULL; + stream->blob_handler = NULL; + stream->end_handler = NULL; + + return stream; + +} + +int __guac_handle_clipboard(guac_client* client, guac_instruction* instruction) { + + /* Pull corresponding stream */ + int stream_index = atoi(instruction->argv[0]); + guac_stream* stream = __init_input_stream(client, stream_index); + if (stream == NULL) + return 0; /* If supported, call handler */ if (client->clipboard_handler) @@ -149,23 +197,9 @@ int __guac_handle_file(guac_client* client, guac_instruction* instruction) { /* Pull corresponding stream */ int stream_index = atoi(instruction->argv[0]); - guac_stream* stream; - - /* Validate stream index */ - if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) { - - guac_stream dummy_stream; - dummy_stream.index = stream_index; - - guac_protocol_send_ack(client->socket, &dummy_stream, - "Invalid stream index", GUAC_PROTOCOL_STATUS_CLIENT_BAD_REQUEST); + guac_stream* stream = __init_input_stream(client, stream_index); + if (stream == NULL) return 0; - } - - /* Initialize stream */ - stream = &(client->__input_streams[stream_index]); - stream->index = stream_index; - stream->data = NULL; /* If supported, call handler */ if (client->file_handler) @@ -186,23 +220,9 @@ int __guac_handle_pipe(guac_client* client, guac_instruction* instruction) { /* Pull corresponding stream */ int stream_index = atoi(instruction->argv[0]); - guac_stream* stream; - - /* Validate stream index */ - if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) { - - guac_stream dummy_stream; - dummy_stream.index = stream_index; - - guac_protocol_send_ack(client->socket, &dummy_stream, - "Invalid stream index", GUAC_PROTOCOL_STATUS_CLIENT_BAD_REQUEST); + guac_stream* stream = __init_input_stream(client, stream_index); + if (stream == NULL) return 0; - } - - /* Initialize stream */ - stream = &(client->__input_streams[stream_index]); - stream->index = stream_index; - stream->data = NULL; /* If supported, call handler */ if (client->pipe_handler) @@ -234,7 +254,12 @@ int __guac_handle_ack(guac_client* client, guac_instruction* instruction) { if (stream->index == GUAC_CLIENT_CLOSED_STREAM_INDEX) return 0; - /* If handler defined, call it */ + /* Call stream handler if defined */ + if (stream->ack_handler) + return stream->ack_handler(client, stream, instruction->argv[1], + atoi(instruction->argv[2])); + + /* Fall back to global handler if defined */ if (client->ack_handler) return client->ack_handler(client, stream, instruction->argv[1], atoi(instruction->argv[2])); @@ -244,40 +269,25 @@ int __guac_handle_ack(guac_client* client, guac_instruction* instruction) { int __guac_handle_blob(guac_client* client, guac_instruction* instruction) { - guac_stream* stream; - - /* Validate stream index */ int stream_index = atoi(instruction->argv[0]); - if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) { + guac_stream* stream = __get_open_input_stream(client, stream_index); - guac_stream dummy_stream; - dummy_stream.index = stream_index; - - guac_protocol_send_ack(client->socket, &dummy_stream, - "Invalid stream index", GUAC_PROTOCOL_STATUS_CLIENT_BAD_REQUEST); - return 0; - } - - stream = &(client->__input_streams[stream_index]); - - /* Validate initialization of stream */ - if (stream->index == GUAC_CLIENT_CLOSED_STREAM_INDEX) { - - guac_stream dummy_stream; - dummy_stream.index = stream_index; - - guac_protocol_send_ack(client->socket, &dummy_stream, - "Invalid stream index", GUAC_PROTOCOL_STATUS_CLIENT_BAD_REQUEST); + /* Fail if no such stream */ + if (stream == NULL) return 0; + + /* Call stream handler if defined */ + if (stream->blob_handler) { + int length = guac_protocol_decode_base64(instruction->argv[1]); + return stream->blob_handler(client, stream, instruction->argv[1], + length); } + /* Fall back to global handler if defined */ if (client->blob_handler) { - - /* Decode base64 */ int length = guac_protocol_decode_base64(instruction->argv[1]); return client->blob_handler(client, stream, instruction->argv[1], length); - } guac_protocol_send_ack(client->socket, stream, @@ -287,26 +297,19 @@ int __guac_handle_blob(guac_client* client, guac_instruction* instruction) { int __guac_handle_end(guac_client* client, guac_instruction* instruction) { - guac_stream* stream; int result = 0; - - /* Pull corresponding stream */ int stream_index = atoi(instruction->argv[0]); + guac_stream* stream = __get_open_input_stream(client, stream_index); - /* Validate stream index */ - if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) { - - guac_stream dummy_stream; - dummy_stream.index = stream_index; - - guac_protocol_send_ack(client->socket, &dummy_stream, - "Invalid stream index", - GUAC_PROTOCOL_STATUS_CLIENT_BAD_REQUEST); + /* Fail if no such stream */ + if (stream == NULL) return 0; - } - stream = &(client->__input_streams[stream_index]); + /* Call stream handler if defined */ + if (stream->end_handler) + result = stream->end_handler(client, stream); + /* Fall back to global handler if defined */ if (client->end_handler) result = client->end_handler(client, stream); diff --git a/src/libguac/client.c b/src/libguac/client.c index d2ecdf65..444e71cf 100644 --- a/src/libguac/client.c +++ b/src/libguac/client.c @@ -30,7 +30,7 @@ #include "pool.h" #include "protocol.h" #include "socket.h" -#include "time.h" +#include "timestamp.h" #include #include @@ -141,6 +141,9 @@ guac_client* guac_client_alloc() { client->__stream_pool = guac_pool_alloc(0); /* Initialze streams */ + client->__input_streams = malloc(sizeof(guac_stream) * GUAC_CLIENT_MAX_STREAMS); + client->__output_streams = malloc(sizeof(guac_stream) * GUAC_CLIENT_MAX_STREAMS); + for (i=0; i__input_streams[i].index = GUAC_CLIENT_CLOSED_STREAM_INDEX; client->__output_streams[i].index = GUAC_CLIENT_CLOSED_STREAM_INDEX; @@ -163,6 +166,10 @@ void guac_client_free(guac_client* client) { guac_pool_free(client->__buffer_pool); guac_pool_free(client->__layer_pool); + /* Free streams */ + free(client->__input_streams); + free(client->__output_streams); + /* Free stream pool */ guac_pool_free(client->__stream_pool); diff --git a/src/libguac/guacamole/audio-fntypes.h b/src/libguac/guacamole/audio-fntypes.h new file mode 100644 index 00000000..0b30a7d9 --- /dev/null +++ b/src/libguac/guacamole/audio-fntypes.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __GUAC_AUDIO_FNTYPES_H +#define __GUAC_AUDIO_FNTYPES_H + +/** + * Function type definitions related to simple streaming audio. + * + * @file audio-fntypes.h + */ + +#include "audio-types.h" + +/** + * Handler which is called when the audio stream is opened. + */ +typedef void guac_audio_encoder_begin_handler(guac_audio_stream* audio); + +/** + * Handler which is called when the audio stream is closed. + */ +typedef void guac_audio_encoder_end_handler(guac_audio_stream* audio); + +/** + * Handler which is called when the audio stream is flushed. + */ +typedef void guac_audio_encoder_write_handler(guac_audio_stream* audio, + const unsigned char* pcm_data, int length); + +#endif + diff --git a/src/libguac/guacamole/audio-types.h b/src/libguac/guacamole/audio-types.h new file mode 100644 index 00000000..2294b80a --- /dev/null +++ b/src/libguac/guacamole/audio-types.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __GUAC_AUDIO_TYPES_H +#define __GUAC_AUDIO_TYPES_H + +/** + * Type definitions related to simple streaming audio. + * + * @file audio-types.h + */ + +/** + * Basic audio stream. PCM data is added to the stream. When the stream is + * flushed, a write handler receives PCM data packets and, presumably, streams + * them to the guac_stream provided. + */ +typedef struct guac_audio_stream guac_audio_stream; + +/** + * Arbitrary audio codec encoder. + */ +typedef struct guac_audio_encoder guac_audio_encoder; + +#endif + diff --git a/src/libguac/guacamole/audio.h b/src/libguac/guacamole/audio.h index 782c9a8a..36f5df09 100644 --- a/src/libguac/guacamole/audio.h +++ b/src/libguac/guacamole/audio.h @@ -30,31 +30,12 @@ * @file audio.h */ -#include -#include +#include "audio-fntypes.h" +#include "audio-types.h" +#include "client-types.h" +#include "stream-types.h" -typedef struct guac_audio_stream guac_audio_stream; - -/** - * Handler which is called when the audio stream is opened. - */ -typedef void guac_audio_encoder_begin_handler(guac_audio_stream* audio); - -/** - * Handler which is called when the audio stream is closed. - */ -typedef void guac_audio_encoder_end_handler(guac_audio_stream* audio); - -/** - * Handler which is called when the audio stream is flushed. - */ -typedef void guac_audio_encoder_write_handler(guac_audio_stream* audio, - const unsigned char* pcm_data, int length); - -/** - * Arbitrary audio codec encoder. - */ -typedef struct guac_audio_encoder { +struct guac_audio_encoder { /** * The mimetype of the audio data encoded by this audio @@ -77,13 +58,8 @@ typedef struct guac_audio_encoder { */ guac_audio_encoder_end_handler* end_handler; -} guac_audio_encoder; +}; -/** - * Basic audio stream. PCM data is added to the stream. When the stream is - * flushed, a write handler receives PCM data packets and, presumably, streams - * them to the guac_stream provided. - */ struct guac_audio_stream { /** diff --git a/src/libguac/guacamole/client-constants.h b/src/libguac/guacamole/client-constants.h new file mode 100644 index 00000000..310d5252 --- /dev/null +++ b/src/libguac/guacamole/client-constants.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_CLIENT_CONSTANTS_H +#define _GUAC_CLIENT_CONSTANTS_H + +/** + * Constants related to the Guacamole client structure, guac_client. + * + * @file client-constants.h + */ + +/** + * The maximum number of inbound streams supported by any one guac_client. + */ +#define GUAC_CLIENT_MAX_STREAMS 64 + +/** + * The index of a closed stream. + */ +#define GUAC_CLIENT_CLOSED_STREAM_INDEX -1 + +/** + * The flag set in the mouse button mask when the left mouse button is down. + */ +#define GUAC_CLIENT_MOUSE_LEFT 0x01 + +/** + * The flag set in the mouse button mask when the middle mouse button is down. + */ +#define GUAC_CLIENT_MOUSE_MIDDLE 0x02 + +/** + * The flag set in the mouse button mask when the right mouse button is down. + */ +#define GUAC_CLIENT_MOUSE_RIGHT 0x04 + +/** + * The flag set in the mouse button mask when the mouse scrollwheel is scrolled + * up. Note that mouse scrollwheels are actually sets of two buttons. One + * button is pressed and released for an upward scroll, and the other is + * pressed and released for a downward scroll. Some mice may actually implement + * these as separate buttons, not a wheel. + */ +#define GUAC_CLIENT_MOUSE_SCROLL_UP 0x08 + +/** + * The flag set in the mouse button mask when the mouse scrollwheel is scrolled + * down. Note that mouse scrollwheels are actually sets of two buttons. One + * button is pressed and released for an upward scroll, and the other is + * pressed and released for a downward scroll. Some mice may actually implement + * these as separate buttons, not a wheel. + */ +#define GUAC_CLIENT_MOUSE_SCROLL_DOWN 0x10 + +/** + * The minimum number of buffers to create before allowing free'd buffers to + * be reclaimed. In the case a protocol rapidly creates, uses, and destroys + * buffers, this can prevent unnecessary reuse of the same buffer (which + * would make draw operations unnecessarily synchronous). + */ +#define GUAC_BUFFER_POOL_INITIAL_SIZE 1024 + +#endif + diff --git a/src/libguac/guacamole/client-fntypes.h b/src/libguac/guacamole/client-fntypes.h new file mode 100644 index 00000000..e35218cf --- /dev/null +++ b/src/libguac/guacamole/client-fntypes.h @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_CLIENT_FNTYPES_H +#define _GUAC_CLIENT_FNTYPES_H + +/** + * Function type definitions related to the Guacamole client structure, + * guac_client. + * + * @file client-fntypes.h + */ + +#include "client-types.h" +#include "protocol-types.h" +#include "stream-types.h" + +#include + +/** + * Handler for server messages (where "server" refers to the server that + * the proxy client is connected to). + */ +typedef int guac_client_handle_messages(guac_client* client); + +/** + * Handler for Guacamole mouse events. + */ +typedef int guac_client_mouse_handler(guac_client* client, int x, int y, int button_mask); + +/** + * Handler for Guacamole key events. + */ +typedef int guac_client_key_handler(guac_client* client, int keysym, int pressed); + +/** + * Handler for Guacamole clipboard events. + */ +typedef int guac_client_clipboard_handler(guac_client* client, guac_stream* stream, + char* mimetype); +/** + * Handler for Guacamole screen size events. + */ +typedef int guac_client_size_handler(guac_client* client, + int width, int height); + +/** + * Handler for Guacamole file transfer events. + */ +typedef int guac_client_file_handler(guac_client* client, guac_stream* stream, + char* mimetype, char* filename); + +/** + * Handler for Guacamole pipe events. + */ +typedef int guac_client_pipe_handler(guac_client* client, guac_stream* stream, + char* mimetype, char* name); + +/** + * Handler for Guacamole stream blob events. + */ +typedef int guac_client_blob_handler(guac_client* client, guac_stream* stream, + void* data, int length); + +/** + * Handler for Guacamole stream ack events. + */ +typedef int guac_client_ack_handler(guac_client* client, guac_stream* stream, + char* error, guac_protocol_status status); + +/** + * Handler for Guacamole stream end events. + */ +typedef int guac_client_end_handler(guac_client* client, guac_stream* stream); + +/** + * Handler for Guacamole audio format events. + */ +typedef int guac_client_audio_handler(guac_client* client, char* mimetype); + +/** + * Handler for Guacamole video format events. + */ +typedef int guac_client_video_handler(guac_client* client, char* mimetype); + +/** + * Handler for freeing up any extra data allocated by the client + * implementation. + */ +typedef int guac_client_free_handler(guac_client* client); + +/** + * Handler for logging messages + */ +typedef void guac_client_log_handler(guac_client* client, const char* format, va_list args); + +/** + * Handler which should initialize the given guac_client. + */ +typedef int guac_client_init_handler(guac_client* client, int argc, char** argv); + +#endif + diff --git a/src/libguac/guacamole/client-types.h b/src/libguac/guacamole/client-types.h new file mode 100644 index 00000000..3cd9139f --- /dev/null +++ b/src/libguac/guacamole/client-types.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_CLIENT_TYPES_H +#define _GUAC_CLIENT_TYPES_H + +/** + * Type definitions related to the Guacamole client structure, guac_client. + * + * @file client-types.h + */ + +/** + * Guacamole proxy client. + * + * Represents a Guacamole proxy client (the client which communicates to + * a server on behalf of Guacamole, on behalf of the web-client). + */ +typedef struct guac_client guac_client; + +/** + * Possible current states of the Guacamole client. Currently, the only + * two states are GUAC_CLIENT_RUNNING and GUAC_CLIENT_STOPPING. + */ +typedef enum guac_client_state { + + /** + * The state of the client from when it has been allocated by the main + * daemon until it is killed or disconnected. + */ + GUAC_CLIENT_RUNNING, + + /** + * The state of the client when a stop has been requested, signalling the + * I/O threads to shutdown. + */ + GUAC_CLIENT_STOPPING + +} guac_client_state; + +/** + * Information exposed by the remote client during the connection handshake + * which can be used by a client plugin. + */ +typedef struct guac_client_info guac_client_info; + +#endif + diff --git a/src/libguac/guacamole/client.h b/src/libguac/guacamole/client.h index d3f5383e..e3f936a6 100644 --- a/src/libguac/guacamole/client.h +++ b/src/libguac/guacamole/client.h @@ -20,186 +20,28 @@ * THE SOFTWARE. */ - #ifndef _GUAC_CLIENT_H #define _GUAC_CLIENT_H /** - * Provides functions and structures required for defining (and handling) a proxy client. + * Functions and structure contents for the Guacamole proxy client. * * @file client.h */ -#include "instruction.h" -#include "layer.h" -#include "pool.h" -#include "protocol.h" -#include "socket.h" +#include "client-fntypes.h" +#include "client-types.h" +#include "client-constants.h" +#include "instruction-types.h" +#include "layer-types.h" +#include "pool-types.h" +#include "socket-types.h" #include "stream.h" -#include "timestamp.h" +#include "timestamp-types.h" #include -/** - * The maximum number of inbound streams supported by any one guac_client. - */ -#define GUAC_CLIENT_MAX_STREAMS 64 - -/** - * The index of a closed stream. - */ -#define GUAC_CLIENT_CLOSED_STREAM_INDEX -1 - -typedef struct guac_client guac_client; - -/** - * Handler for server messages (where "server" refers to the server that - * the proxy client is connected to). - */ -typedef int guac_client_handle_messages(guac_client* client); - -/** - * Handler for Guacamole mouse events. - */ -typedef int guac_client_mouse_handler(guac_client* client, int x, int y, int button_mask); - -/** - * Handler for Guacamole key events. - */ -typedef int guac_client_key_handler(guac_client* client, int keysym, int pressed); - -/** - * Handler for Guacamole clipboard events. - */ -typedef int guac_client_clipboard_handler(guac_client* client, guac_stream* stream, - char* mimetype); -/** - * Handler for Guacamole screen size events. - */ -typedef int guac_client_size_handler(guac_client* client, - int width, int height); - -/** - * Handler for Guacamole file transfer events. - */ -typedef int guac_client_file_handler(guac_client* client, guac_stream* stream, - char* mimetype, char* filename); - -/** - * Handler for Guacamole pipe events. - */ -typedef int guac_client_pipe_handler(guac_client* client, guac_stream* stream, - char* mimetype, char* name); - -/** - * Handler for Guacamole stream blob events. - */ -typedef int guac_client_blob_handler(guac_client* client, guac_stream* stream, - void* data, int length); - -/** - * Handler for Guacamole stream ack events. - */ -typedef int guac_client_ack_handler(guac_client* client, guac_stream* stream, - char* error, guac_protocol_status status); - -/** - * Handler for Guacamole stream end events. - */ -typedef int guac_client_end_handler(guac_client* client, guac_stream* stream); - -/** - * Handler for Guacamole audio format events. - */ -typedef int guac_client_audio_handler(guac_client* client, char* mimetype); - -/** - * Handler for Guacamole video format events. - */ -typedef int guac_client_video_handler(guac_client* client, char* mimetype); - -/** - * Handler for freeing up any extra data allocated by the client - * implementation. - */ -typedef int guac_client_free_handler(guac_client* client); - -/** - * Handler for logging messages - */ -typedef void guac_client_log_handler(guac_client* client, const char* format, va_list args); - -/** - * Handler which should initialize the given guac_client. - */ -typedef int guac_client_init_handler(guac_client* client, int argc, char** argv); - -/** - * The flag set in the mouse button mask when the left mouse button is down. - */ -#define GUAC_CLIENT_MOUSE_LEFT 0x01 - -/** - * The flag set in the mouse button mask when the middle mouse button is down. - */ -#define GUAC_CLIENT_MOUSE_MIDDLE 0x02 - -/** - * The flag set in the mouse button mask when the right mouse button is down. - */ -#define GUAC_CLIENT_MOUSE_RIGHT 0x04 - -/** - * The flag set in the mouse button mask when the mouse scrollwheel is scrolled - * up. Note that mouse scrollwheels are actually sets of two buttons. One - * button is pressed and released for an upward scroll, and the other is - * pressed and released for a downward scroll. Some mice may actually implement - * these as separate buttons, not a wheel. - */ -#define GUAC_CLIENT_MOUSE_SCROLL_UP 0x08 - -/** - * The flag set in the mouse button mask when the mouse scrollwheel is scrolled - * down. Note that mouse scrollwheels are actually sets of two buttons. One - * button is pressed and released for an upward scroll, and the other is - * pressed and released for a downward scroll. Some mice may actually implement - * these as separate buttons, not a wheel. - */ -#define GUAC_CLIENT_MOUSE_SCROLL_DOWN 0x10 - -/** - * The minimum number of buffers to create before allowing free'd buffers to - * be reclaimed. In the case a protocol rapidly creates, uses, and destroys - * buffers, this can prevent unnecessary reuse of the same buffer (which - * would make draw operations unnecessarily synchronous). - */ -#define GUAC_BUFFER_POOL_INITIAL_SIZE 1024 - -/** - * Possible current states of the Guacamole client. Currently, the only - * two states are GUAC_CLIENT_RUNNING and GUAC_CLIENT_STOPPING. - */ -typedef enum guac_client_state { - - /** - * The state of the client from when it has been allocated by the main - * daemon until it is killed or disconnected. - */ - GUAC_CLIENT_RUNNING, - - /** - * The state of the client when a stop has been requested, signalling the - * I/O threads to shutdown. - */ - GUAC_CLIENT_STOPPING - -} guac_client_state; - -/** - * Information exposed by the remote client during the connection handshake - * which can be used by a client plugin. - */ -typedef struct guac_client_info { +struct guac_client_info { /** * The number of pixels the remote client requests for the display width. @@ -238,14 +80,8 @@ typedef struct guac_client_info { */ int optimal_resolution; -} guac_client_info; +}; -/** - * Guacamole proxy client. - * - * Represents a Guacamole proxy client (the client which communicates to - * a server on behalf of Guacamole, on behalf of the web-client). - */ struct guac_client { /** @@ -576,12 +412,12 @@ struct guac_client { /** * All available output streams (data going to connected client). */ - guac_stream __output_streams[GUAC_CLIENT_MAX_STREAMS]; + guac_stream* __output_streams; /** * All available input streams (data coming from connected client). */ - guac_stream __input_streams[GUAC_CLIENT_MAX_STREAMS]; + guac_stream* __input_streams; }; @@ -760,3 +596,4 @@ void guac_client_free_stream(guac_client* client, guac_stream* stream); extern const guac_layer* GUAC_DEFAULT_LAYER; #endif + diff --git a/src/libguac/guacamole/error-types.h b/src/libguac/guacamole/error-types.h new file mode 100644 index 00000000..7b9d4655 --- /dev/null +++ b/src/libguac/guacamole/error-types.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_ERROR_TYPES_H +#define _GUAC_ERROR_TYPES_H + +/** + * Type definitions related to return values and errors. + * + * @file error-types.h + */ + +/** + * Return codes shared by all Guacamole functions which can fail. + */ +typedef enum guac_status { + + /** + * No errors occurred and the operation was successful. + */ + GUAC_STATUS_SUCCESS = 0, + + /** + * Insufficient memory to complete the operation. + */ + GUAC_STATUS_NO_MEMORY, + + /** + * The end of the input stream associated with the operation + * has been reached. + */ + GUAC_STATUS_NO_INPUT, + + /** + * A timeout occurred while reading from the input stream associated + * with the operation. + */ + GUAC_STATUS_INPUT_TIMEOUT, + + /** + * An error occurred, and further information about the error is already + * stored in errno. + */ + GUAC_STATUS_SEE_ERRNO, + + /** + * An error prevented the operation from writing to its associated + * output stream. + */ + GUAC_STATUS_OUTPUT_ERROR, + + /** + * The operation could not be performed because an invalid argument was + * given. + */ + GUAC_STATUS_BAD_ARGUMENT, + + /** + * The state of the associated system prevents an operation from being + * performed which would otherwise be allowed. + */ + GUAC_STATUS_BAD_STATE + +} guac_status; + +#endif + diff --git a/src/libguac/guacamole/error.h b/src/libguac/guacamole/error.h index 88d394a8..bad146d8 100644 --- a/src/libguac/guacamole/error.h +++ b/src/libguac/guacamole/error.h @@ -31,58 +31,37 @@ * @file error.h */ +#include "error-types.h" + /** - * Return codes shared by all Guacamole functions which can fail. + * Returns a human-readable explanation of the status code given. */ -typedef enum guac_status { +const char* guac_status_string(guac_status status); - /** - * No errors occurred and the operation was successful. - */ - GUAC_STATUS_SUCCESS = 0, +/** + * Returns the status code associated with the error which occurred during the + * last function call. This value will only be set by functions documented to + * use it (most libguac functions), and is undefined if no error occurred. + * + * The storage of this value is thread-local. Assignment of a status code to + * guac_error in one thread will not affect its value in another thread. + */ +#define guac_error (*__guac_error()) - /** - * Insufficient memory to complete the operation. - */ - GUAC_STATUS_NO_MEMORY, +guac_status* __guac_error(); - /** - * The end of the input stream associated with the operation - * has been reached. - */ - GUAC_STATUS_NO_INPUT, +/** + * Returns a message describing the error which occurred during the last + * function call. If an error occurred, but no message is associated with it, + * NULL is returned. This value is undefined if no error occurred. + * + * The storage of this value is thread-local. Assignment of a message to + * guac_error_message in one thread will not affect its value in another + * thread. + */ +#define guac_error_message (*__guac_error_message()) - /** - * A timeout occurred while reading from the input stream associated - * with the operation. - */ - GUAC_STATUS_INPUT_TIMEOUT, - - /** - * An error occurred, and further information about the error is already - * stored in errno. - */ - GUAC_STATUS_SEE_ERRNO, - - /** - * An error prevented the operation from writing to its associated - * output stream. - */ - GUAC_STATUS_OUTPUT_ERROR, - - /** - * The operation could not be performed because an invalid argument was - * given. - */ - GUAC_STATUS_BAD_ARGUMENT, - - /** - * The state of the associated system prevents an operation from being - * performed which would otherwise be allowed. - */ - GUAC_STATUS_BAD_STATE - -} guac_status; +const char** __guac_error_message(); /** * Returns a human-readable explanation of the status code given. @@ -115,3 +94,4 @@ guac_status* __guac_error(); const char** __guac_error_message(); #endif + diff --git a/src/libguac/guacamole/instruction-constants.h b/src/libguac/guacamole/instruction-constants.h new file mode 100644 index 00000000..ac295dcf --- /dev/null +++ b/src/libguac/guacamole/instruction-constants.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_INSTRUCTION_CONSTANTS_H +#define _GUAC_INSTRUCTION_CONSTANTS_H + +/** + * Constants related to Guacamole instructions. + * + * @file instruction-constants.h + */ + +/** + * The maximum number of characters per instruction. + */ +#define GUAC_INSTRUCTION_MAX_LENGTH 8192 + +/** + * The maximum number of digits to allow per length prefix. + */ +#define GUAC_INSTRUCTION_MAX_DIGITS 5 + +/** + * The maximum number of elements per instruction, including the opcode. + */ +#define GUAC_INSTRUCTION_MAX_ELEMENTS 64 + +#endif + diff --git a/src/libguac/guacamole/instruction-types.h b/src/libguac/guacamole/instruction-types.h new file mode 100644 index 00000000..fd6cc693 --- /dev/null +++ b/src/libguac/guacamole/instruction-types.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2013 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#ifndef _GUAC_INSTRUCTION_TYPES_H +#define _GUAC_INSTRUCTION_TYPES_H + +/** + * Type definitions related to Guacamole instructions. + * + * @file instruction-types.h + */ + +/** + * All possible states of the instruction parser. + */ +typedef enum guac_instruction_parse_state { + + /** + * The parser is currently waiting for data to complete the length prefix + * of the current element of the instruction. + */ + GUAC_INSTRUCTION_PARSE_LENGTH, + + /** + * The parser has finished reading the length prefix and is currently + * waiting for data to complete the content of the instruction. + */ + GUAC_INSTRUCTION_PARSE_CONTENT, + + /** + * The instruction has been fully parsed. + */ + GUAC_INSTRUCTION_PARSE_COMPLETE, + + /** + * The instruction cannot be parsed because of a protocol error. + */ + GUAC_INSTRUCTION_PARSE_ERROR + +} guac_instruction_parse_state; + +/** + * Represents a single instruction within the Guacamole protocol. + */ +typedef struct guac_instruction guac_instruction; + +#endif + diff --git a/src/libguac/guacamole/instruction.h b/src/libguac/guacamole/instruction.h index f606ec2a..9444ad93 100644 --- a/src/libguac/guacamole/instruction.h +++ b/src/libguac/guacamole/instruction.h @@ -31,56 +31,11 @@ * @file instruction.h */ -#include "socket.h" +#include "instruction-types.h" +#include "instruction-constants.h" +#include "socket-types.h" -/** - * The maximum number of characters per instruction. - */ -#define GUAC_INSTRUCTION_MAX_LENGTH 8192 - -/** - * The maximum number of digits to allow per length prefix. - */ -#define GUAC_INSTRUCTION_MAX_DIGITS 5 - -/** - * The maximum number of elements per instruction, including the opcode. - */ -#define GUAC_INSTRUCTION_MAX_ELEMENTS 64 - -/** - * All possible states of the instruction parser. - */ -typedef enum guac_instruction_parse_state { - - /** - * The parser is currently waiting for data to complete the length prefix - * of the current element of the instruction. - */ - GUAC_INSTRUCTION_PARSE_LENGTH, - - /** - * The parser has finished reading the length prefix and is currently - * waiting for data to complete the content of the instruction. - */ - GUAC_INSTRUCTION_PARSE_CONTENT, - - /** - * The instruction has been fully parsed. - */ - GUAC_INSTRUCTION_PARSE_COMPLETE, - - /** - * The instruction cannot be parsed because of a protocol error. - */ - GUAC_INSTRUCTION_PARSE_ERROR - -} guac_instruction_parse_state; - -/** - * Represents a single instruction within the Guacamole protocol. - */ -typedef struct guac_instruction { +struct guac_instruction { /** * The opcode of the instruction. @@ -117,7 +72,7 @@ typedef struct guac_instruction { */ char* __elementv[GUAC_INSTRUCTION_MAX_ELEMENTS]; -} guac_instruction; +}; /** * Allocates a new instruction. Each instruction contains within itself the diff --git a/src/libguac/guacamole/layer-types.h b/src/libguac/guacamole/layer-types.h new file mode 100644 index 00000000..2c91434a --- /dev/null +++ b/src/libguac/guacamole/layer-types.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_LAYER_TYPES_H +#define _GUAC_LAYER_TYPES_H + +/** + * Type definitions related to Guacamole layers. + * + * @file layer-types.h + */ + +/** + * Represents a single layer within the Guacamole protocol. + */ +typedef struct guac_layer guac_layer; + +#endif + diff --git a/src/libguac/guacamole/layer.h b/src/libguac/guacamole/layer.h index 27d4e98f..b6fd8db8 100644 --- a/src/libguac/guacamole/layer.h +++ b/src/libguac/guacamole/layer.h @@ -20,7 +20,6 @@ * THE SOFTWARE. */ - #ifndef _GUAC_LAYER_H #define _GUAC_LAYER_H @@ -30,7 +29,7 @@ * @file layer.h */ -typedef struct guac_layer guac_layer; +#include "layer-types.h" /** * Represents a single layer within the Guacamole protocol. diff --git a/src/libguac/guacamole/plugin-constants.h b/src/libguac/guacamole/plugin-constants.h new file mode 100644 index 00000000..65cee992 --- /dev/null +++ b/src/libguac/guacamole/plugin-constants.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_PLUGIN_CONSTANTS_H +#define _GUAC_PLUGIN_CONSTANTS_H + +/** + * Constants related to client plugins. + * + * @file plugin-constants.h + */ + +/** + * String prefix which begins the library filename of all client plugins. + */ +#define GUAC_PROTOCOL_LIBRARY_PREFIX "libguac-client-" + +/** + * String suffix which ends the library filename of all client plugins. + */ +#define GUAC_PROTOCOL_LIBRARY_SUFFIX ".so" + +/** + * The maximum number of characters (COUNTING NULL TERMINATOR) to allow + * for protocol names within the library filename of client plugins. + */ +#define GUAC_PROTOCOL_NAME_LIMIT 256 + +/** + * The maximum number of characters (INCLUDING NULL TERMINATOR) that a + * character array containing the concatenation of the library prefix, + * protocol name, and suffix can contain, assuming the protocol name is + * limited to GUAC_PROTOCOL_NAME_LIMIT characters. + */ +#define GUAC_PROTOCOL_LIBRARY_LIMIT ( \ + \ + sizeof(GUAC_PROTOCOL_LIBRARY_PREFIX) - 1 /* "libguac-client-" */ \ + + GUAC_PROTOCOL_NAME_LIMIT - 1 /* [up to 256 chars] */ \ + + sizeof(GUAC_PROTOCOL_LIBRARY_SUFFIX) - 1 /* ".so" */ \ + + 1 /* NULL terminator */ \ + \ +) + +#endif + diff --git a/src/libguac/guacamole/plugin-types.h b/src/libguac/guacamole/plugin-types.h new file mode 100644 index 00000000..69c9cc07 --- /dev/null +++ b/src/libguac/guacamole/plugin-types.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_PLUGIN_TYPES_H +#define _GUAC_PLUGIN_TYPES_H + +/** + * Type definitions related to client plugins. + * + * @file plugin-types.h + */ + +/** + * A handle to a client plugin, containing enough information about the + * plugin to complete the initial protocol handshake and instantiate a new + * client supporting the protocol provided by the client plugin. + */ +typedef struct guac_client_plugin guac_client_plugin; + +#endif + diff --git a/src/libguac/guacamole/plugin.h b/src/libguac/guacamole/plugin.h index a33dc644..52a7ba73 100644 --- a/src/libguac/guacamole/plugin.h +++ b/src/libguac/guacamole/plugin.h @@ -20,11 +20,12 @@ * THE SOFTWARE. */ - #ifndef _GUAC_PLUGIN_H #define _GUAC_PLUGIN_H -#include "client.h" +#include "client-types.h" +#include "plugin-constants.h" +#include "plugin-types.h" /** * Provides functions and structures required for handling a client plugin. @@ -32,44 +33,6 @@ * @file plugin.h */ -/** - * String prefix which begins the library filename of all client plugins. - */ -#define GUAC_PROTOCOL_LIBRARY_PREFIX "libguac-client-" - -/** - * String suffix which ends the library filename of all client plugins. - */ -#define GUAC_PROTOCOL_LIBRARY_SUFFIX ".so" - -/** - * The maximum number of characters (COUNTING NULL TERMINATOR) to allow - * for protocol names within the library filename of client plugins. - */ -#define GUAC_PROTOCOL_NAME_LIMIT 256 - -/** - * The maximum number of characters (INCLUDING NULL TERMINATOR) that a - * character array containing the concatenation of the library prefix, - * protocol name, and suffix can contain, assuming the protocol name is - * limited to GUAC_PROTOCOL_NAME_LIMIT characters. - */ -#define GUAC_PROTOCOL_LIBRARY_LIMIT ( \ - \ - sizeof(GUAC_PROTOCOL_LIBRARY_PREFIX) - 1 /* "libguac-client-" */ \ - + GUAC_PROTOCOL_NAME_LIMIT - 1 /* [up to 256 chars] */ \ - + sizeof(GUAC_PROTOCOL_LIBRARY_SUFFIX) - 1 /* ".so" */ \ - + 1 /* NULL terminator */ \ - \ -) - -typedef struct guac_client_plugin guac_client_plugin; - -/** - * A handle to a client plugin, containing enough information about the - * plugin to complete the initial protocol handshake and instantiate a new - * client supporting the protocol provided by the client plugin. - */ struct guac_client_plugin { /** diff --git a/src/libguac/guacamole/pool-types.h b/src/libguac/guacamole/pool-types.h new file mode 100644 index 00000000..c0cd0cde --- /dev/null +++ b/src/libguac/guacamole/pool-types.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_POOL_TYPES_H +#define _GUAC_POOL_TYPES_H + +/** + * Type definitions related to the guac_pool pool of unique integers. + * + * @file pool.h + */ + +/** + * Represents a single integer within a larger pool of integers. + */ +typedef struct guac_pool_int guac_pool_int; + +/** + * A pool of integers. Integers can be removed from and later free'd back + * into the pool. New integers are returned when the pool is exhausted, + * or when the pool has not met some minimum size. Old, free'd integers + * are returned otherwise. + */ +typedef struct guac_pool guac_pool; + +#endif + diff --git a/src/libguac/guacamole/pool.h b/src/libguac/guacamole/pool.h index f8d184ad..5ab99eae 100644 --- a/src/libguac/guacamole/pool.h +++ b/src/libguac/guacamole/pool.h @@ -20,7 +20,6 @@ * THE SOFTWARE. */ - #ifndef _GUAC_POOL_H #define _GUAC_POOL_H @@ -31,15 +30,9 @@ * @file pool.h */ -typedef struct guac_pool_int guac_pool_int; +#include "pool-types.h" -/** - * A pool of integers. Integers can be removed from and later free'd back - * into the pool. New integers are returned when the pool is exhausted, - * or when the pool has not met some minimum size. Old, free'd integers - * are returned otherwise. - */ -typedef struct guac_pool { +struct guac_pool { /** * The minimum number of integers which must have been returned by @@ -69,11 +62,8 @@ typedef struct guac_pool { */ guac_pool_int* __tail; -} guac_pool; +}; -/** - * Represents a single integer within a larger pool of integers. - */ struct guac_pool_int { /** diff --git a/src/libguac/guacamole/protocol-types.h b/src/libguac/guacamole/protocol-types.h new file mode 100644 index 00000000..4002c5d7 --- /dev/null +++ b/src/libguac/guacamole/protocol-types.h @@ -0,0 +1,248 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_PROTOCOL_TYPES_H +#define _GUAC_PROTOCOL_TYPES_H + +/** + * Type definitions related to the Guacamole protocol. + * + * @file protocol-types.h + */ + +/** + * Set of all possible status codes returned by protocol operations. These + * codes relate to Guacamole server/client communication, and not to internal + * communication of errors within libguac and linked software. + * + * In general: + * + * 0x0000 - 0x00FF: Successful operations. + * 0x0100 - 0x01FF: Operations that failed due to implementation status. + * 0x0200 - 0x02FF: Operations that failed due to environmental. + * 0x0300 - 0x03FF: Operations that failed due to user action. + * + * There is a general correspondence of these status codes with HTTP response + * codes. + */ +typedef enum guac_protocol_status { + + /** + * The operation succeeded. + */ + GUAC_PROTOCOL_STATUS_SUCCESS = 0x0000, + + /** + * The requested operation is unsupported. + */ + GUAC_PROTOCOL_STATUS_UNSUPPORTED = 0x0100, + + /** + * The operation could not be performed due to an internal failure. + */ + GUAC_PROTOCOL_STATUS_SERVER_ERROR = 0x0200, + + /** + * The operation could not be performed due as the server is busy. + */ + GUAC_PROTOCOL_STATUS_SERVER_BUSY = 0x0201, + + /** + * The operation could not be performed because the upstream server + * is not responding. + */ + GUAC_PROTOCOL_STATUS_UPSTREAM_TIMEOUT = 0x202, + + /** + * The operation was unsuccessful due to an error or otherwise + * unexpected condition of the upstream server. + */ + GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR = 0x203, + + /** + * The operation could not be performed as the requested resource + * does not exist. + */ + GUAC_PROTOCOL_STATUS_RESOURCE_NOT_FOUND = 0x204, + + /** + * The operation could not be performed as the requested resource is + * already in use. + */ + GUAC_PROTOCOL_STATUS_RESOURCE_CONFLICT = 0x205, + + /** + * The operation could not be performed because bad parameters were + * given. + */ + GUAC_PROTOCOL_STATUS_CLIENT_BAD_REQUEST = 0x300, + + /** + * Permission was denied to perform the operation, as the user is not + * yet authorized (not yet logged in, for example). + */ + GUAC_PROTOCOL_STATUS_CLIENT_UNAUTHORIZED = 0x0301, + + /** + * Permission was denied to perform the operation, and this permission + * will not be granted even if the user is authorized. + */ + GUAC_PROTOCOL_STATUS_CLIENT_FORBIDDEN = 0x0303, + + /** + * The client took too long to respond. + */ + GUAC_PROTOCOL_STATUS_CLIENT_TIMEOUT = 0x308, + + /** + * The client sent too much data. + */ + GUAC_PROTOCOL_STATUS_CLIENT_OVERRUN = 0x30D, + + /** + * The client sent data of an unsupported or unexpected type. + */ + GUAC_PROTOCOL_STATUS_CLIENT_BAD_TYPE = 0x30F, + + /** + * The operation failed because the current client is already + * using too many resources. + */ + GUAC_PROTOCOL_STATUS_CLIENT_TOO_MANY = 0x31D + +} guac_protocol_status; + +/** + * Composite modes used by Guacamole draw instructions. Each + * composite mode maps to a unique channel mask integer. + */ +typedef enum guac_composite_mode { + + /* + * A: Source where destination transparent = S n D' + * B: Source where destination opaque = S n D + * C: Destination where source transparent = D n S' + * D: Destination where source opaque = D n S + * + * 0 = Active, 1 = Inactive + */ + /* ABCD */ + GUAC_COMP_ROUT = 0x2, /* 0010 - Clears destination where source opaque */ + GUAC_COMP_ATOP = 0x6, /* 0110 - Fill where destination opaque only */ + GUAC_COMP_XOR = 0xA, /* 1010 - XOR */ + GUAC_COMP_ROVER = 0xB, /* 1011 - Fill where destination transparent only */ + GUAC_COMP_OVER = 0xE, /* 1110 - Draw normally */ + GUAC_COMP_PLUS = 0xF, /* 1111 - Add */ + + /* Unimplemented in client: */ + /* NOT IMPLEMENTED: 0000 - Clear */ + /* NOT IMPLEMENTED: 0011 - No operation */ + /* NOT IMPLEMENTED: 0101 - Additive IN */ + /* NOT IMPLEMENTED: 0111 - Additive ATOP */ + /* NOT IMPLEMENTED: 1101 - Additive RATOP */ + + /* Buggy in webkit browsers, as they keep channel C on in all cases: */ + GUAC_COMP_RIN = 0x1, /* 0001 */ + GUAC_COMP_IN = 0x4, /* 0100 */ + GUAC_COMP_OUT = 0x8, /* 1000 */ + GUAC_COMP_RATOP = 0x9, /* 1001 */ + GUAC_COMP_SRC = 0xC /* 1100 */ + + /* Bitwise composite operations (binary) */ + + /* + * A: S' & D' + * B: S' & D + * C: S & D' + * D: S & D + * + * 0 = Active, 1 = Inactive + */ + +} guac_composite_mode; + +/** + * Default transfer functions. There is no current facility in the + * Guacamole protocol to define custom transfer functions. + */ +typedef enum guac_transfer_function { + + /* Constant functions */ /* ABCD */ + GUAC_TRANSFER_BINARY_BLACK = 0x0, /* 0000 */ + GUAC_TRANSFER_BINARY_WHITE = 0xF, /* 1111 */ + + /* Copy functions */ + GUAC_TRANSFER_BINARY_SRC = 0x3, /* 0011 */ + GUAC_TRANSFER_BINARY_DEST = 0x5, /* 0101 */ + GUAC_TRANSFER_BINARY_NSRC = 0xC, /* 1100 */ + GUAC_TRANSFER_BINARY_NDEST = 0xA, /* 1010 */ + + /* AND / NAND */ + GUAC_TRANSFER_BINARY_AND = 0x1, /* 0001 */ + GUAC_TRANSFER_BINARY_NAND = 0xE, /* 1110 */ + + /* OR / NOR */ + GUAC_TRANSFER_BINARY_OR = 0x7, /* 0111 */ + GUAC_TRANSFER_BINARY_NOR = 0x8, /* 1000 */ + + /* XOR / XNOR */ + GUAC_TRANSFER_BINARY_XOR = 0x6, /* 0110 */ + GUAC_TRANSFER_BINARY_XNOR = 0x9, /* 1001 */ + + /* AND / NAND with inverted source */ + GUAC_TRANSFER_BINARY_NSRC_AND = 0x4, /* 0100 */ + GUAC_TRANSFER_BINARY_NSRC_NAND = 0xB, /* 1011 */ + + /* OR / NOR with inverted source */ + GUAC_TRANSFER_BINARY_NSRC_OR = 0xD, /* 1101 */ + GUAC_TRANSFER_BINARY_NSRC_NOR = 0x2, /* 0010 */ + + /* AND / NAND with inverted destination */ + GUAC_TRANSFER_BINARY_NDEST_AND = 0x2, /* 0010 */ + GUAC_TRANSFER_BINARY_NDEST_NAND = 0xD, /* 1101 */ + + /* OR / NOR with inverted destination */ + GUAC_TRANSFER_BINARY_NDEST_OR = 0xB, /* 1011 */ + GUAC_TRANSFER_BINARY_NDEST_NOR = 0x4 /* 0100 */ + +} guac_transfer_function; + +/** + * Supported line cap styles + */ +typedef enum guac_line_cap_style { + GUAC_LINE_CAP_BUTT = 0x0, + GUAC_LINE_CAP_ROUND = 0x1, + GUAC_LINE_CAP_SQUARE = 0x2 +} guac_line_cap_style; + +/** + * Supported line join styles + */ +typedef enum guac_line_join_style { + GUAC_LINE_JOIN_BEVEL = 0x0, + GUAC_LINE_JOIN_MITER = 0x1, + GUAC_LINE_JOIN_ROUND = 0x2 +} guac_line_join_style; + +#endif + diff --git a/src/libguac/guacamole/protocol.h b/src/libguac/guacamole/protocol.h index eb2b094c..685523b4 100644 --- a/src/libguac/guacamole/protocol.h +++ b/src/libguac/guacamole/protocol.h @@ -20,7 +20,6 @@ * THE SOFTWARE. */ - #ifndef _GUAC_PROTOCOL_H #define _GUAC_PROTOCOL_H @@ -32,229 +31,14 @@ * @file protocol.h */ -#include "layer.h" -#include "socket.h" -#include "stream.h" -#include "timestamp.h" - -#include +#include "layer-types.h" +#include "protocol-types.h" +#include "socket-types.h" +#include "stream-types.h" +#include "timestamp-types.h" #include - -/** - * Set of all possible status codes returned by protocol operations. These - * codes relate to Guacamole server/client communication, and not to internal - * communication of errors within libguac and linked software. - * - * In general: - * - * 0x0000 - 0x00FF: Successful operations. - * 0x0100 - 0x01FF: Operations that failed due to implementation status. - * 0x0200 - 0x02FF: Operations that failed due to environmental. - * 0x0300 - 0x03FF: Operations that failed due to user action. - * - * There is a general correspondence of these status codes with HTTP response - * codes. - */ -typedef enum guac_protocol_status { - - /** - * The operation succeeded. - */ - GUAC_PROTOCOL_STATUS_SUCCESS = 0x0000, - - /** - * The requested operation is unsupported. - */ - GUAC_PROTOCOL_STATUS_UNSUPPORTED = 0x0100, - - /** - * The operation could not be performed due to an internal failure. - */ - GUAC_PROTOCOL_STATUS_SERVER_ERROR = 0x0200, - - /** - * The operation could not be performed due as the server is busy. - */ - GUAC_PROTOCOL_STATUS_SERVER_BUSY = 0x0201, - - /** - * The operation could not be performed because the upstream server - * is not responding. - */ - GUAC_PROTOCOL_STATUS_UPSTREAM_TIMEOUT = 0x202, - - /** - * The operation was unsuccessful due to an error or otherwise - * unexpected condition of the upstream server. - */ - GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR = 0x203, - - /** - * The operation could not be performed as the requested resource - * does not exist. - */ - GUAC_PROTOCOL_STATUS_RESOURCE_NOT_FOUND = 0x204, - - /** - * The operation could not be performed as the requested resource is - * already in use. - */ - GUAC_PROTOCOL_STATUS_RESOURCE_CONFLICT = 0x205, - - /** - * The operation could not be performed because bad parameters were - * given. - */ - GUAC_PROTOCOL_STATUS_CLIENT_BAD_REQUEST = 0x300, - - /** - * Permission was denied to perform the operation, as the user is not - * yet authorized (not yet logged in, for example). - */ - GUAC_PROTOCOL_STATUS_CLIENT_UNAUTHORIZED = 0x0301, - - /** - * Permission was denied to perform the operation, and this permission - * will not be granted even if the user is authorized. - */ - GUAC_PROTOCOL_STATUS_CLIENT_FORBIDDEN = 0x0303, - - /** - * The client took too long to respond. - */ - GUAC_PROTOCOL_STATUS_CLIENT_TIMEOUT = 0x308, - - /** - * The client sent too much data. - */ - GUAC_PROTOCOL_STATUS_CLIENT_OVERRUN = 0x30D, - - /** - * The client sent data of an unsupported or unexpected type. - */ - GUAC_PROTOCOL_STATUS_CLIENT_BAD_TYPE = 0x30F, - - /** - * The operation failed because the current client is already - * using too many resources. - */ - GUAC_PROTOCOL_STATUS_CLIENT_TOO_MANY = 0x31D - -} guac_protocol_status; - -/** - * Composite modes used by Guacamole draw instructions. Each - * composite mode maps to a unique channel mask integer. - */ -typedef enum guac_composite_mode { - - /* - * A: Source where destination transparent = S n D' - * B: Source where destination opaque = S n D - * C: Destination where source transparent = D n S' - * D: Destination where source opaque = D n S - * - * 0 = Active, 1 = Inactive - */ - /* ABCD */ - GUAC_COMP_ROUT = 0x2, /* 0010 - Clears destination where source opaque */ - GUAC_COMP_ATOP = 0x6, /* 0110 - Fill where destination opaque only */ - GUAC_COMP_XOR = 0xA, /* 1010 - XOR */ - GUAC_COMP_ROVER = 0xB, /* 1011 - Fill where destination transparent only */ - GUAC_COMP_OVER = 0xE, /* 1110 - Draw normally */ - GUAC_COMP_PLUS = 0xF, /* 1111 - Add */ - - /* Unimplemented in client: */ - /* NOT IMPLEMENTED: 0000 - Clear */ - /* NOT IMPLEMENTED: 0011 - No operation */ - /* NOT IMPLEMENTED: 0101 - Additive IN */ - /* NOT IMPLEMENTED: 0111 - Additive ATOP */ - /* NOT IMPLEMENTED: 1101 - Additive RATOP */ - - /* Buggy in webkit browsers, as they keep channel C on in all cases: */ - GUAC_COMP_RIN = 0x1, /* 0001 */ - GUAC_COMP_IN = 0x4, /* 0100 */ - GUAC_COMP_OUT = 0x8, /* 1000 */ - GUAC_COMP_RATOP = 0x9, /* 1001 */ - GUAC_COMP_SRC = 0xC /* 1100 */ - - /* Bitwise composite operations (binary) */ - - /* - * A: S' & D' - * B: S' & D - * C: S & D' - * D: S & D - * - * 0 = Active, 1 = Inactive - */ - -} guac_composite_mode; - -/** - * Default transfer functions. There is no current facility in the - * Guacamole protocol to define custom transfer functions. - */ -typedef enum guac_transfer_function { - - /* Constant functions */ /* ABCD */ - GUAC_TRANSFER_BINARY_BLACK = 0x0, /* 0000 */ - GUAC_TRANSFER_BINARY_WHITE = 0xF, /* 1111 */ - - /* Copy functions */ - GUAC_TRANSFER_BINARY_SRC = 0x3, /* 0011 */ - GUAC_TRANSFER_BINARY_DEST = 0x5, /* 0101 */ - GUAC_TRANSFER_BINARY_NSRC = 0xC, /* 1100 */ - GUAC_TRANSFER_BINARY_NDEST = 0xA, /* 1010 */ - - /* AND / NAND */ - GUAC_TRANSFER_BINARY_AND = 0x1, /* 0001 */ - GUAC_TRANSFER_BINARY_NAND = 0xE, /* 1110 */ - - /* OR / NOR */ - GUAC_TRANSFER_BINARY_OR = 0x7, /* 0111 */ - GUAC_TRANSFER_BINARY_NOR = 0x8, /* 1000 */ - - /* XOR / XNOR */ - GUAC_TRANSFER_BINARY_XOR = 0x6, /* 0110 */ - GUAC_TRANSFER_BINARY_XNOR = 0x9, /* 1001 */ - - /* AND / NAND with inverted source */ - GUAC_TRANSFER_BINARY_NSRC_AND = 0x4, /* 0100 */ - GUAC_TRANSFER_BINARY_NSRC_NAND = 0xB, /* 1011 */ - - /* OR / NOR with inverted source */ - GUAC_TRANSFER_BINARY_NSRC_OR = 0xD, /* 1101 */ - GUAC_TRANSFER_BINARY_NSRC_NOR = 0x2, /* 0010 */ - - /* AND / NAND with inverted destination */ - GUAC_TRANSFER_BINARY_NDEST_AND = 0x2, /* 0010 */ - GUAC_TRANSFER_BINARY_NDEST_NAND = 0xD, /* 1101 */ - - /* OR / NOR with inverted destination */ - GUAC_TRANSFER_BINARY_NDEST_OR = 0xB, /* 1011 */ - GUAC_TRANSFER_BINARY_NDEST_NOR = 0x4 /* 0100 */ - -} guac_transfer_function; - -/** - * Supported line cap styles - */ -typedef enum guac_line_cap_style { - GUAC_LINE_CAP_BUTT = 0x0, - GUAC_LINE_CAP_ROUND = 0x1, - GUAC_LINE_CAP_SQUARE = 0x2 -} guac_line_cap_style; - -/** - * Supported line join styles - */ -typedef enum guac_line_join_style { - GUAC_LINE_JOIN_BEVEL = 0x0, - GUAC_LINE_JOIN_MITER = 0x1, - GUAC_LINE_JOIN_ROUND = 0x2 -} guac_line_join_style; +#include /* CONTROL INSTRUCTIONS */ diff --git a/src/libguac/guacamole/socket-constants.h b/src/libguac/guacamole/socket-constants.h new file mode 100644 index 00000000..3c435fa3 --- /dev/null +++ b/src/libguac/guacamole/socket-constants.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_SOCKET_CONSTANTS_H +#define _GUAC_SOCKET_CONSTANTS_H + +/** + * Constants related to the guac_socket object. + * + * @file socket-constants.h + */ + +/** + * The number of bytes to buffer within each socket before flushing. + */ +#define GUAC_SOCKET_OUTPUT_BUFFER_SIZE 8192 + +/** + * The number of milliseconds to wait between keep-alive pings on a socket + * with keep-alive enabled. + */ +#define GUAC_SOCKET_KEEP_ALIVE_INTERVAL 5000 + +#endif + diff --git a/src/libguac/guacamole/socket-fntypes.h b/src/libguac/guacamole/socket-fntypes.h new file mode 100644 index 00000000..8862c160 --- /dev/null +++ b/src/libguac/guacamole/socket-fntypes.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_SOCKET_FNTYPES_H +#define _GUAC_SOCKET_FNTYPES_H + +/** + * Function type definitions related to the guac_socket object. + * + * @file socket-fntypes.h + */ + +#include "socket-types.h" + +#include + +/** + * Generic read handler for socket read operations, modeled after the standard + * POSIX read() function. When set within a guac_socket, a handler of this type + * will be called when data needs to be read into the socket. + * + * @param socket The guac_socket being read from. + * @param buf The arbitrary buffer we must populate with data. + * @param count The maximum number of bytes to read into the buffer. + * @return The number of bytes read, or -1 if an error occurs. + */ +typedef ssize_t guac_socket_read_handler(guac_socket* socket, + void* buf, size_t count); + +/** + * Generic write handler for socket write operations, modeled after the standard + * POSIX write() function. When set within a guac_socket, a handler of this type + * will be called when data needs to be write into the socket. + * + * @param socket The guac_socket being written to. + * @param buf The arbitrary buffer containing data to be written. + * @param count The maximum number of bytes to write from the buffer. + * @return The number of bytes written, or -1 if an error occurs. + */ +typedef ssize_t guac_socket_write_handler(guac_socket* socket, + const void* buf, size_t count); + +/** + * Generic handler for socket select operations, similar to the POSIX select() + * function. When guac_socket_select() is called on a guac_socket, its + * guac_socket_select_handler will be invoked, if defined. + * + * @param socket The guac_socket being selected. + * @param usec_timeout The maximum number of microseconds to wait for data, or + * -1 to potentially wait forever. + * @return Positive on success, zero if the timeout elapsed and no data is + * available, negative on error. + */ +typedef int guac_socket_select_handler(guac_socket* socket, int usec_timeout); + +/** + * Generic handler for the closing of a socket, modeled after the standard + * POSIX close() function. When set within a guac_socket, a handler of this type + * will be called when the socket is closed. + * + * @param socket The guac_socket being closed. + * @return Zero on success, or -1 if an error occurs. + */ +typedef int guac_socket_free_handler(guac_socket* socket); + +#endif + diff --git a/src/libguac/guacamole/socket-types.h b/src/libguac/guacamole/socket-types.h new file mode 100644 index 00000000..5315f50d --- /dev/null +++ b/src/libguac/guacamole/socket-types.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_SOCKET_TYPES_H +#define _GUAC_SOCKET_TYPES_H + +/** + * Type definitions related to the guac_socket object. + * + * @file socket-types.h + */ + +/** + * The core I/O object of Guacamole. guac_socket provides buffered input and + * output as well as convenience methods for efficiently writing base64 data. + */ +typedef struct guac_socket guac_socket; + +/** + * Possible current states of a guac_socket. + */ +typedef enum guac_socket_state { + + /** + * The socket is open and can be written to / read from. + */ + GUAC_SOCKET_OPEN, + + /** + * The socket is closed. Reads and writes will fail. + */ + GUAC_SOCKET_CLOSED + +} guac_socket_state; + +#endif + diff --git a/src/libguac/guacamole/socket.h b/src/libguac/guacamole/socket.h index e3278560..50bd9344 100644 --- a/src/libguac/guacamole/socket.h +++ b/src/libguac/guacamole/socket.h @@ -20,7 +20,6 @@ * THE SOFTWARE. */ - #ifndef _GUAC_SOCKET_H #define _GUAC_SOCKET_H @@ -30,95 +29,15 @@ * @file socket.h */ -#include "timestamp.h" +#include "socket-constants.h" +#include "socket-fntypes.h" +#include "socket-types.h" +#include "timestamp-types.h" #include #include #include -/** - * The number of bytes to buffer within each socket before flushing. - */ -#define GUAC_SOCKET_OUTPUT_BUFFER_SIZE 8192 - -/** - * The number of milliseconds to wait between keep-alive pings on a socket - * with keep-alive enabled. - */ -#define GUAC_SOCKET_KEEP_ALIVE_INTERVAL 5000 - -typedef struct guac_socket guac_socket; - -/** - * Generic read handler for socket read operations, modeled after the standard - * POSIX read() function. When set within a guac_socket, a handler of this type - * will be called when data needs to be read into the socket. - * - * @param socket The guac_socket being read from. - * @param buf The arbitrary buffer we must populate with data. - * @param count The maximum number of bytes to read into the buffer. - * @return The number of bytes read, or -1 if an error occurs. - */ -typedef ssize_t guac_socket_read_handler(guac_socket* socket, - void* buf, size_t count); - -/** - * Generic write handler for socket write operations, modeled after the standard - * POSIX write() function. When set within a guac_socket, a handler of this type - * will be called when data needs to be write into the socket. - * - * @param socket The guac_socket being written to. - * @param buf The arbitrary buffer containing data to be written. - * @param count The maximum number of bytes to write from the buffer. - * @return The number of bytes written, or -1 if an error occurs. - */ -typedef ssize_t guac_socket_write_handler(guac_socket* socket, - const void* buf, size_t count); - -/** - * Generic handler for socket select operations, similar to the POSIX select() - * function. When guac_socket_select() is called on a guac_socket, its - * guac_socket_select_handler will be invoked, if defined. - * - * @param socket The guac_socket being selected. - * @param usec_timeout The maximum number of microseconds to wait for data, or - * -1 to potentially wait forever. - * @return Positive on success, zero if the timeout elapsed and no data is - * available, negative on error. - */ -typedef int guac_socket_select_handler(guac_socket* socket, int usec_timeout); - -/** - * Generic handler for the closing of a socket, modeled after the standard - * POSIX close() function. When set within a guac_socket, a handler of this type - * will be called when the socket is closed. - * - * @param socket The guac_socket being closed. - * @return Zero on success, or -1 if an error occurs. - */ -typedef int guac_socket_free_handler(guac_socket* socket); - -/** - * Possible current states of a guac_socket. - */ -typedef enum guac_socket_state { - - /** - * The socket is open and can be written to / read from. - */ - GUAC_SOCKET_OPEN, - - /** - * The socket is closed. Reads and writes will fail. - */ - GUAC_SOCKET_CLOSED - -} guac_socket_state; - -/** - * The core I/O object of Guacamole. guac_socket provides buffered input and - * output as well as convenience methods for efficiently writing base64 data. - */ struct guac_socket { /** diff --git a/src/libguac/guacamole/stream-types.h b/src/libguac/guacamole/stream-types.h new file mode 100644 index 00000000..94dbfa4e --- /dev/null +++ b/src/libguac/guacamole/stream-types.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_STREAM_TYPES_H +#define _GUAC_STREAM_TYPES_H + +/** + * Type definitions related to Guacamole protocol streams. + * + * @file stream-types.h + */ + +/** + * Represents a single stream within the Guacamole protocol. + */ +typedef struct guac_stream guac_stream; + +#endif + diff --git a/src/libguac/guacamole/stream.h b/src/libguac/guacamole/stream.h index 1a359be8..01102e17 100644 --- a/src/libguac/guacamole/stream.h +++ b/src/libguac/guacamole/stream.h @@ -20,7 +20,6 @@ * THE SOFTWARE. */ - #ifndef _GUAC_STREAM_H #define _GUAC_STREAM_H @@ -30,11 +29,9 @@ * @file stream.h */ -typedef struct guac_stream guac_stream; +#include "client-fntypes.h" +#include "stream-types.h" -/** - * Represents a single stream within the Guacamole protocol. - */ struct guac_stream { /** @@ -47,6 +44,70 @@ struct guac_stream { */ void* data; + /** + * Handler for ack events sent by the Guacamole web-client. + * + * The handler takes a guac_stream which contains the stream index and + * will persist through the duration of the transfer, a string containing + * the error or status message, and a status code. + * + * Example: + * @code + * int ack_handler(guac_client* client, guac_stream* stream, + * char* error, guac_protocol_status status); + * + * int some_function(guac_client* client) { + * + * guac_stream* stream = guac_client_alloc_stream(client); + * stream->ack_handler = ack_handler; + * + * guac_protocol_send_clipboard(client->socket, + * stream, "text/plain"); + * + * } + * @endcode + */ + guac_client_ack_handler* ack_handler; + + /** + * Handler for blob events sent by the Guacamole web-client. + * + * The handler takes a guac_stream which contains the stream index and + * will persist through the duration of the transfer, an arbitrary buffer + * containing the blob, and the length of the blob. + * + * Example: + * @code + * int blob_handler(guac_client* client, guac_stream* stream, + * void* data, int length); + * + * int my_clipboard_handler(guac_client* client, guac_stream* stream, + * char* mimetype) { + * stream->blob_handler = blob_handler; + * } + * @endcode + */ + guac_client_blob_handler* blob_handler; + + /** + * Handler for stream end events sent by the Guacamole web-client. + * + * The handler takes only a guac_stream which contains the stream index. + * This guac_stream will be disposed of immediately after this event is + * finished. + * + * Example: + * @code + * int end_handler(guac_client* client, guac_stream* stream); + * + * int my_clipboard_handler(guac_client* client, guac_stream* stream, + * char* mimetype) { + * stream->end_handler = end_handler; + * } + * @endcode + */ + guac_client_end_handler* end_handler; + }; #endif diff --git a/src/libguac/guacamole/timestamp-types.h b/src/libguac/guacamole/timestamp-types.h new file mode 100644 index 00000000..b46be30d --- /dev/null +++ b/src/libguac/guacamole/timestamp-types.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_TIMESTAMP_TYPES_H +#define _GUAC_TIMESTAMP_TYPES_H + +/** + * Type definitions related to Guacamole protocol timestamps. + * + * @file timestamp-types.h + */ + +#include + +/** + * An arbitrary timestamp denoting a relative time value in milliseconds. + */ +typedef int64_t guac_timestamp; + +#endif + diff --git a/src/libguac/guacamole/timestamp.h b/src/libguac/guacamole/timestamp.h index 6715cce8..05bb0f83 100644 --- a/src/libguac/guacamole/timestamp.h +++ b/src/libguac/guacamole/timestamp.h @@ -20,9 +20,8 @@ * THE SOFTWARE. */ - -#ifndef _GUAC_TIME_H -#define _GUAC_TIME_H +#ifndef _GUAC_TIMESTAMP_H +#define _GUAC_TIMESTAMP_H /** * Provides functions and structures for creating timestamps. @@ -30,12 +29,7 @@ * @file timestamp.h */ -#include - -/** - * An arbitrary timestamp denoting a relative time value in milliseconds. - */ -typedef int64_t guac_timestamp; +#include "timestamp-types.h" /** * Returns an arbitrary timestamp. The difference between return values of any diff --git a/src/libguac/protocol.c b/src/libguac/protocol.c index 6c19d24d..d625eb81 100644 --- a/src/libguac/protocol.c +++ b/src/libguac/protocol.c @@ -27,6 +27,7 @@ #include "palette.h" #include "protocol.h" #include "socket.h" +#include "stream.h" #include "unicode.h" #include