From b50d89d8303e41954863f20cc8ee4787b3798ee3 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 20 Nov 2011 23:09:02 -0800 Subject: [PATCH] Revert "Refactor of prototypes, partial continuation of refactor into client." This reverts commit a7a4a126c2a670c78bef4bc34d8823f98754bc5c. --- libguac/include/client-handlers.h | 13 +++---- libguac/include/client.h | 16 +++----- libguac/include/error.h | 6 --- libguac/include/guacio.h | 12 +++--- libguac/include/protocol.h | 63 +++++++++++++++---------------- libguac/src/client.c | 16 ++++---- libguac/src/error.c | 21 ++++------- 7 files changed, 64 insertions(+), 83 deletions(-) diff --git a/libguac/include/client-handlers.h b/libguac/include/client-handlers.h index 8ad48435..de7603ae 100644 --- a/libguac/include/client-handlers.h +++ b/libguac/include/client-handlers.h @@ -40,7 +40,6 @@ #include "client.h" #include "protocol.h" -#include "error.h" /** * Provides initial handler functions and a lookup structure for automatically @@ -53,7 +52,7 @@ /** * Internal handler for Guacamole instructions. */ -typedef guac_status __guac_instruction_handler(guac_client* client, guac_instruction* copied); +typedef int __guac_instruction_handler(guac_client* client, guac_instruction* copied); /** * Structure mapping an instruction opcode to an instruction handler. @@ -77,35 +76,35 @@ typedef struct __guac_instruction_handler_mapping { * is received, this handler will be called. Sync instructions are automatically * handled, thus there is no client handler for sync instruction. */ -guac_status __guac_handle_sync(guac_client* client, guac_instruction* instruction); +int __guac_handle_sync(guac_client* client, guac_instruction* instruction); /** * Internal initial handler for the mouse instruction. When a mouse instruction * is received, this handler will be called. The client's mouse handler will * be invoked if defined. */ -guac_status __guac_handle_mouse(guac_client* client, guac_instruction* instruction); +int __guac_handle_mouse(guac_client* client, guac_instruction* instruction); /** * Internal initial handler for the key instruction. When a key instruction * is received, this handler will be called. The client's key handler will * be invoked if defined. */ -guac_status __guac_handle_key(guac_client* client, guac_instruction* instruction); +int __guac_handle_key(guac_client* client, guac_instruction* instruction); /** * Internal initial handler for the clipboard instruction. When a clipboard instruction * is received, this handler will be called. The client's clipboard handler will * be invoked if defined. */ -guac_status __guac_handle_clipboard(guac_client* client, guac_instruction* instruction); +int __guac_handle_clipboard(guac_client* client, guac_instruction* instruction); /** * Internal initial handler for the disconnect instruction. When a disconnect instruction * is received, this handler will be called. Disconnect instructions are automatically * handled, thus there is no client handler for disconnect instruction. */ -guac_status __guac_handle_disconnect(guac_client* client, guac_instruction* instruction); +int __guac_handle_disconnect(guac_client* client, guac_instruction* instruction); /** * Instruction handler mapping table. This is a NULL-terminated array of diff --git a/libguac/include/client.h b/libguac/include/client.h index 3c3e5387..3483ce01 100644 --- a/libguac/include/client.h +++ b/libguac/include/client.h @@ -312,10 +312,9 @@ guac_client* guac_get_client(int client_fd); * Enter the main network message handling loop for the given client. * * @param client The proxy client to start handling messages of/for. - * @return GUAC_STATUS_SUCCESS if the client successfully started, or any - * other status code if an error occurs during startup. Note that - * this function will still return GUAC_STATUS_SUCCESS - * if an error occurs while the client is running. + * @return Zero if the client successfully started, non-zero if an error + * occurs during startup. Note that this function will still return + * zero if an error occurs while the client is running. */ guac_status guac_start_client(guac_client* client); @@ -324,7 +323,7 @@ guac_status guac_start_client(guac_client* client); * * @param client The proxy client to free all reasources of. */ -void guac_free_client(guac_client* client); +guac_status guac_free_client(guac_client* client); /** * Call the appropriate handler defined by the given client for the given @@ -335,9 +334,6 @@ void guac_free_client(guac_client* client); * @param client The proxy client whose handlers should be called. * @param instruction The instruction to pass to the proxy client via the * appropriate handler. - * @return GUAC_STATUS_SUCCESS if no handler was defined or if the handler - * was called successfully, or any other status code if an error - * occurs while calling the defined handler. */ guac_status guac_client_handle_instruction(guac_client* client, guac_instruction* instruction); @@ -348,7 +344,7 @@ guac_status guac_client_handle_instruction(guac_client* client, guac_instruction * * @param client The proxy client to stop. */ -void guac_client_stop(guac_client* client); +guac_status guac_client_stop(guac_client* client); /** * Allocates a new buffer (invisible layer). An arbitrary index is @@ -376,7 +372,7 @@ guac_layer* guac_client_alloc_layer(guac_client* client, int index); * @param client The proxy client to return the buffer to. * @param layer The buffer to return to the pool of available buffers. */ -void guac_client_free_buffer(guac_client* client, guac_layer* layer); +guac_status guac_client_free_buffer(guac_client* client, guac_layer* layer); /** * The default Guacamole client layer, layer 0. diff --git a/libguac/include/error.h b/libguac/include/error.h index b6c569d6..29ac594d 100644 --- a/libguac/include/error.h +++ b/libguac/include/error.h @@ -67,12 +67,6 @@ typedef enum guac_status { */ GUAC_STATUS_NO_INPUT, - /** - * No data could be read from an input stream, but data may be available - * if the operation is retried. - */ - GUAC_STATUS_INPUT_UNAVAILABLE, - /** * A timeout occurred while reading from the input stream associated * with the operation. diff --git a/libguac/include/guacio.h b/libguac/include/guacio.h index c5ba5afb..f0ee209d 100644 --- a/libguac/include/guacio.h +++ b/libguac/include/guacio.h @@ -151,7 +151,7 @@ int64_t guac_parse_int(const char* str); * @param i The unsigned int to write. * @return Zero on success, or non-zero if an error occurs while writing. */ -guac_status guac_write_int(GUACIO* io, int64_t i); +ssize_t guac_write_int(GUACIO* io, int64_t i); /** * Writes the given string to the given GUACIO object. The data @@ -164,7 +164,7 @@ guac_status guac_write_int(GUACIO* io, int64_t i); * @param str The string to write. * @return Zero on success, or non-zero if an error occurs while writing. */ -guac_status guac_write_string(GUACIO* io, const char* str); +ssize_t guac_write_string(GUACIO* io, const char* str); /** * Writes the given binary data to the given GUACIO object as base64-encoded @@ -179,7 +179,7 @@ guac_status guac_write_string(GUACIO* io, const char* str); * @param count The number of bytes to write. * @return Zero on success, or non-zero if an error occurs while writing. */ -guac_status guac_write_base64(GUACIO* io, const void* buf, size_t count); +ssize_t guac_write_base64(GUACIO* io, const void* buf, size_t count); /** * Flushes the base64 buffer, writing padding characters as necessary. @@ -187,7 +187,7 @@ guac_status guac_write_base64(GUACIO* io, const void* buf, size_t count); * @param io The GUACIO object to flush * @return Zero on success, or non-zero if an error occurs during flush. */ -guac_status guac_flush_base64(GUACIO* io); +ssize_t guac_flush_base64(GUACIO* io); /** * Flushes the write buffer. @@ -195,7 +195,7 @@ guac_status guac_flush_base64(GUACIO* io); * @param io The GUACIO object to flush * @return Zero on success, or non-zero if an error occurs during flush. */ -guac_status guac_flush(GUACIO* io); +ssize_t guac_flush(GUACIO* io); /** @@ -208,7 +208,7 @@ guac_status guac_flush(GUACIO* io); * @return Positive on success, zero if the timeout elapsed and no data is * available, negative on error. */ -guac_status guac_select(GUACIO* io, int usec_timeout); +int guac_select(GUACIO* io, int usec_timeout); /** * Frees resources allocated to the given GUACIO object. Note that this diff --git a/libguac/include/protocol.h b/libguac/include/protocol.h index 8ae52846..5f73191f 100644 --- a/libguac/include/protocol.h +++ b/libguac/include/protocol.h @@ -176,18 +176,18 @@ void guac_free_instruction(guac_instruction* instruction); * * @param io The GUACIO connection to use. * @param args The NULL-terminated array of argument names (strings). - * @return GUAC_STATUS_SUCCESS on success, any other status code on error. + * @return Zero on success, non-zero on error. */ -guac_status guac_send_args(GUACIO* io, const char** name); +int guac_send_args(GUACIO* io, const char** name); /** * Sends a name instruction over the given GUACIO connection. * * @param io The GUACIO connection to use. * @param name The name to send within the name instruction. - * @return GUAC_STATUS_SUCCESS on success, any other status code on error. + * @return Zero on success, non-zero on error. */ -guac_status guac_send_name(GUACIO* io, const char* name); +int guac_send_name(GUACIO* io, const char* name); /** * Sends a sync instruction over the given GUACIO connection. The @@ -195,27 +195,27 @@ guac_status guac_send_name(GUACIO* io, const char* name); * * @param io The GUACIO connection to use. * @param timestamp The current timestamp (in milliseconds). - * @return GUAC_STATUS_SUCCESS on success, any other status code on error. + * @return Zero on success, non-zero on error. */ -guac_status guac_send_sync(GUACIO* io, guac_timestamp timestamp); +int guac_send_sync(GUACIO* io, guac_timestamp timestamp); /** * Sends an error instruction over the given GUACIO connection. * * @param io The GUACIO connection to use. * @param error The description associated with the error. - * @return GUAC_STATUS_SUCCESS on success, any other status code on error. + * @return Zero on success, non-zero on error. */ -guac_status guac_send_error(GUACIO* io, const char* error); +int guac_send_error(GUACIO* io, const char* error); /** * Sends a clipboard instruction over the given GUACIO connection. * * @param io The GUACIO connection to use. * @param data The clipboard data to send. - * @return GUAC_STATUS_SUCCESS on success, any other status code on error. + * @return Zero on success, non-zero on error. */ -guac_status guac_send_clipboard(GUACIO* io, const char* data); +int guac_send_clipboard(GUACIO* io, const char* data); /** * Sends a size instruction over the given GUACIO connection. @@ -223,9 +223,9 @@ guac_status guac_send_clipboard(GUACIO* io, const char* data); * @param io The GUACIO connection to use. * @param w The width of the display. * @param h The height of the display. - * @return GUAC_STATUS_SUCCESS on success, any other status code on error. + * @return Zero on success, non-zero on error. */ -guac_status guac_send_size(GUACIO* io, int w, int h); +int guac_send_size(GUACIO* io, int w, int h); /** * Sends a copy instruction over the given GUACIO connection. @@ -242,9 +242,9 @@ guac_status guac_send_size(GUACIO* io, int w, int h); * should be copied. * @param dsty The Y coordinate of the destination, where the source rectangle * should be copied. - * @return GUAC_STATUS_SUCCESS on success, any other status code on error. + * @return Zero on success, non-zero on error. */ -guac_status guac_send_copy(GUACIO* io, +int guac_send_copy(GUACIO* io, const guac_layer* srcl, int srcx, int srcy, int w, int h, guac_composite_mode mode, const guac_layer* dstl, int dstx, int dsty); @@ -262,9 +262,9 @@ guac_status guac_send_copy(GUACIO* io, * @param g The green component of the color of the rectangle. * @param b The blue component of the color of the rectangle. * @param a The alpha (transparency) component of the color of the rectangle. - * @return GUAC_STATUS_SUCCESS on success, any other status code on error. + * @return Zero on success, non-zero on error. */ -guac_status guac_send_rect(GUACIO* io, +int guac_send_rect(GUACIO* io, guac_composite_mode mode, const guac_layer* layer, int x, int y, int width, int height, int r, int g, int b, int a); @@ -278,9 +278,9 @@ guac_status guac_send_rect(GUACIO* io, * @param y The Y coordinate of the clipping rectangle. * @param width The width of the clipping rectangle. * @param height The height of the clipping rectangle. - * @return GUAC_STATUS_SUCCESS on success, any other status code on error. + * @return Zero on success, non-zero on error. */ -guac_status guac_send_clip(GUACIO* io, const guac_layer* layer, +int guac_send_clip(GUACIO* io, const guac_layer* layer, int x, int y, int width, int height); /** @@ -293,9 +293,9 @@ guac_status guac_send_clip(GUACIO* io, const guac_layer* layer, * @param x The destination X coordinate. * @param y The destination Y coordinate. * @param surface A cairo surface containing the image data to send. - * @return GUAC_STATUS_SUCCESS on success, any other status code on error. + * @return Zero on success, non-zero on error. */ -guac_status guac_send_png(GUACIO* io, guac_composite_mode mode, +int guac_send_png(GUACIO* io, guac_composite_mode mode, const guac_layer* layer, int x, int y, cairo_surface_t* surface); /** @@ -306,20 +306,19 @@ guac_status guac_send_png(GUACIO* io, guac_composite_mode mode, * @param x The X coordinate of the cursor hotspot. * @param y The Y coordinate of the cursor hotspot. * @param surface A cairo surface containing the image data to send. - * @return GUAC_STATUS_SUCCESS on success, any other status code on error. + * @return Zero on success, non-zero on error. */ -guac_status guac_send_cursor(GUACIO* io, int x, int y, cairo_surface_t* surface); +int guac_send_cursor(GUACIO* io, int x, int y, cairo_surface_t* surface); /** * Returns whether new instruction data is available on the given GUACIO * connection for parsing. * * @param io The GUACIO connection to use. - * @return GUAC_STATUS_SUCCESS if data is available, - * GUAC_STATUS_NO_INPUT if no data is currently available, - * or any other status code on error. + * @return A positive value if data is available, negative on error, or + * zero if no data is currently available. */ -guac_status guac_instructions_waiting(GUACIO* io); +int guac_instructions_waiting(GUACIO* io); /** * Reads a single instruction from the given GUACIO connection. @@ -328,13 +327,13 @@ guac_status guac_instructions_waiting(GUACIO* io); * @param parsed_instruction A pointer to a guac_instruction structure which * will be populated with data read from the given * GUACIO connection. - * @return GUAC_STATUS_SUCCESS if data was successfully read, - * GUAC_STATUS_INPUT_UNAVAILABLE if the instruction could not be read - * completely because GUAC_TIMEOUT elapsed, in which case subsequent - * calls to guac_read_instruction() will return the parsed instruction - * once enough data is available, or any other status code on error. + * @return A positive value if data was successfully read, negative on + * error, or zero if the instruction could not be read completely + * because GUAC_TIMEOUT elapsed, in which case subsequent calls to + * guac_read_instruction() will return the parsed instruction once + * enough data is available. */ -guac_status guac_read_instruction(GUACIO* io, guac_instruction* parsed_instruction); +int guac_read_instruction(GUACIO* io, guac_instruction* parsed_instruction); guac_timestamp guac_current_timestamp(); void guac_sleep(int millis); diff --git a/libguac/src/client.c b/libguac/src/client.c index ba5a2d4d..a1cafa18 100644 --- a/libguac/src/client.c +++ b/libguac/src/client.c @@ -161,22 +161,26 @@ guac_client* guac_get_client(int client_fd) { /* Wait for data until timeout */ result = guac_instructions_waiting(io); - if (result == GUAC_STATUS_TIMEOUT) { + if (result == 0) { guac_send_error(io, "Select timeout."); guac_close(io); return NULL; } /* If error occurs while waiting, exit with failure */ - if (result != GUAC_STATUS_SUCCESS) { + if (result < 0) { guac_close(io); return NULL; } result = guac_read_instruction(io, &instruction); + if (result < 0) { + guac_close(io); + return NULL; + } /* Select instruction read */ - if (result == GUAC_STATUS_SUCCESS) { + if (result > 0) { if (strcmp(instruction.opcode, "select") == 0) { @@ -243,12 +247,6 @@ guac_client* guac_get_client(int client_fd) { guac_free_instruction_data(&instruction); } - /* Give up on any legitimate error */ - else if (result != GUAC_STATUS_INPUT_UNAVAILABLE) { - guac_close(io); - return NULL; - } - } /* Wait for connect instruction */ diff --git a/libguac/src/error.c b/libguac/src/error.c index c48204fa..3ceedf43 100644 --- a/libguac/src/error.c +++ b/libguac/src/error.c @@ -45,15 +45,14 @@ /* Error strings */ -const char* __GUAC_STATUS_SUCCESS_STR = "Success"; -const char* __GUAC_STATUS_NO_MEMORY_STR = "Insufficient memory"; -const char* __GUAC_STATUS_NO_INPUT_STR = "End of input stream"; -const char* __GUAC_STATUS_INPUT_UNAVAILABLE_STR = "Input unavailable"; -const char* __GUAC_STATUS_INPUT_TIMEOUT_STR = "Read timeout"; -const char* __GUAC_STATUS_OUTPUT_ERROR_STR = "Output error"; -const char* __GUAC_STATUS_BAD_ARGUMENT_STR = "Invalid argument"; -const char* __GUAC_STATUS_BAD_STATE_STR = "Illegal state"; -const char* __GUAC_STATUS_INVALID_STATUS_STR = "UNKNOWN STATUS CODE"; +const char* __GUAC_STATUS_SUCCESS_STR = "Success"; +const char* __GUAC_STATUS_NO_MEMORY_STR = "Insufficient memory"; +const char* __GUAC_STATUS_NO_INPUT_STR = "End of input stream"; +const char* __GUAC_STATUS_INPUT_TIMEOUT_STR = "Read timeout"; +const char* __GUAC_STATUS_OUTPUT_ERROR_STR = "Output error"; +const char* __GUAC_STATUS_BAD_ARGUMENT_STR = "Invalid argument"; +const char* __GUAC_STATUS_BAD_STATE_STR = "Illegal state"; +const char* __GUAC_STATUS_INVALID_STATUS_STR = "UNKNOWN STATUS CODE"; const char* guac_status_string(guac_status status) { @@ -72,10 +71,6 @@ const char* guac_status_string(guac_status status) { case GUAC_STATUS_NO_INPUT: return __GUAC_STATUS_NO_INPUT_STR; - /* Input unavailable */ - case GUAC_STATUS_INPUT_UNAVAILABLE: - return __GUAC_STATUS_INPUT_UNAVAILABLE_STR; - /* Input timeout */ case GUAC_STATUS_INPUT_TIMEOUT: return __GUAC_STATUS_INPUT_TIMEOUT_STR;