Revert "Refactor of prototypes, partial continuation of refactor into client."

This reverts commit a7a4a126c2a670c78bef4bc34d8823f98754bc5c.
This commit is contained in:
Michael Jumper 2011-11-20 23:09:02 -08:00
parent ca34a2f4a2
commit b50d89d830
7 changed files with 64 additions and 83 deletions

View File

@ -40,7 +40,6 @@
#include "client.h" #include "client.h"
#include "protocol.h" #include "protocol.h"
#include "error.h"
/** /**
* Provides initial handler functions and a lookup structure for automatically * Provides initial handler functions and a lookup structure for automatically
@ -53,7 +52,7 @@
/** /**
* Internal handler for Guacamole instructions. * 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. * 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 * is received, this handler will be called. Sync instructions are automatically
* handled, thus there is no client handler for sync instruction. * 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 * Internal initial handler for the mouse instruction. When a mouse instruction
* is received, this handler will be called. The client's mouse handler will * is received, this handler will be called. The client's mouse handler will
* be invoked if defined. * 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 * Internal initial handler for the key instruction. When a key instruction
* is received, this handler will be called. The client's key handler will * is received, this handler will be called. The client's key handler will
* be invoked if defined. * 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 * Internal initial handler for the clipboard instruction. When a clipboard instruction
* is received, this handler will be called. The client's clipboard handler will * is received, this handler will be called. The client's clipboard handler will
* be invoked if defined. * 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 * Internal initial handler for the disconnect instruction. When a disconnect instruction
* is received, this handler will be called. Disconnect instructions are automatically * is received, this handler will be called. Disconnect instructions are automatically
* handled, thus there is no client handler for disconnect instruction. * 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 * Instruction handler mapping table. This is a NULL-terminated array of

View File

@ -312,10 +312,9 @@ guac_client* guac_get_client(int client_fd);
* Enter the main network message handling loop for the given client. * Enter the main network message handling loop for the given client.
* *
* @param client The proxy client to start handling messages of/for. * @param client The proxy client to start handling messages of/for.
* @return GUAC_STATUS_SUCCESS if the client successfully started, or any * @return Zero if the client successfully started, non-zero if an error
* other status code if an error occurs during startup. Note that * occurs during startup. Note that this function will still return
* this function will still return GUAC_STATUS_SUCCESS * zero if an error occurs while the client is running.
* if an error occurs while the client is running.
*/ */
guac_status guac_start_client(guac_client* client); 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. * @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 * 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 client The proxy client whose handlers should be called.
* @param instruction The instruction to pass to the proxy client via the * @param instruction The instruction to pass to the proxy client via the
* appropriate handler. * 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); 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. * @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 * 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 client The proxy client to return the buffer to.
* @param layer The buffer to return to the pool of available buffers. * @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. * The default Guacamole client layer, layer 0.

View File

@ -67,12 +67,6 @@ typedef enum guac_status {
*/ */
GUAC_STATUS_NO_INPUT, 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 * A timeout occurred while reading from the input stream associated
* with the operation. * with the operation.

View File

@ -151,7 +151,7 @@ int64_t guac_parse_int(const char* str);
* @param i The unsigned int to write. * @param i The unsigned int to write.
* @return Zero on success, or non-zero if an error occurs while writing. * @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 * 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. * @param str The string to write.
* @return Zero on success, or non-zero if an error occurs while writing. * @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 * 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. * @param count The number of bytes to write.
* @return Zero on success, or non-zero if an error occurs while writing. * @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. * 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 * @param io The GUACIO object to flush
* @return Zero on success, or non-zero if an error occurs during 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. * Flushes the write buffer.
@ -195,7 +195,7 @@ guac_status guac_flush_base64(GUACIO* io);
* @param io The GUACIO object to flush * @param io The GUACIO object to flush
* @return Zero on success, or non-zero if an error occurs during 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 * @return Positive on success, zero if the timeout elapsed and no data is
* available, negative on error. * 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 * Frees resources allocated to the given GUACIO object. Note that this

View File

@ -176,18 +176,18 @@ void guac_free_instruction(guac_instruction* instruction);
* *
* @param io The GUACIO connection to use. * @param io The GUACIO connection to use.
* @param args The NULL-terminated array of argument names (strings). * @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. * Sends a name instruction over the given GUACIO connection.
* *
* @param io The GUACIO connection to use. * @param io The GUACIO connection to use.
* @param name The name to send within the name instruction. * @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 * 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 io The GUACIO connection to use.
* @param timestamp The current timestamp (in milliseconds). * @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. * Sends an error instruction over the given GUACIO connection.
* *
* @param io The GUACIO connection to use. * @param io The GUACIO connection to use.
* @param error The description associated with the error. * @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. * Sends a clipboard instruction over the given GUACIO connection.
* *
* @param io The GUACIO connection to use. * @param io The GUACIO connection to use.
* @param data The clipboard data to send. * @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. * 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 io The GUACIO connection to use.
* @param w The width of the display. * @param w The width of the display.
* @param h The height 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. * 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. * should be copied.
* @param dsty The Y coordinate of the destination, where the source rectangle * @param dsty The Y coordinate of the destination, where the source rectangle
* should be copied. * 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, const guac_layer* srcl, int srcx, int srcy, int w, int h,
guac_composite_mode mode, const guac_layer* dstl, int dstx, int dsty); 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 g The green component of the color of the rectangle.
* @param b The blue 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. * @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, guac_composite_mode mode, const guac_layer* layer,
int x, int y, int width, int height, int x, int y, int width, int height,
int r, int g, int b, int a); 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 y The Y coordinate of the clipping rectangle.
* @param width The width of the clipping rectangle. * @param width The width of the clipping rectangle.
* @param height The height 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); 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 x The destination X coordinate.
* @param y The destination Y coordinate. * @param y The destination Y coordinate.
* @param surface A cairo surface containing the image data to send. * @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); 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 x The X coordinate of the cursor hotspot.
* @param y The Y 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. * @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 * Returns whether new instruction data is available on the given GUACIO
* connection for parsing. * connection for parsing.
* *
* @param io The GUACIO connection to use. * @param io The GUACIO connection to use.
* @return GUAC_STATUS_SUCCESS if data is available, * @return A positive value if data is available, negative on error, or
* GUAC_STATUS_NO_INPUT if no data is currently available, * zero if no data is currently available.
* or any other status code on error.
*/ */
guac_status guac_instructions_waiting(GUACIO* io); int guac_instructions_waiting(GUACIO* io);
/** /**
* Reads a single instruction from the given GUACIO connection. * 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 * @param parsed_instruction A pointer to a guac_instruction structure which
* will be populated with data read from the given * will be populated with data read from the given
* GUACIO connection. * GUACIO connection.
* @return GUAC_STATUS_SUCCESS if data was successfully read, * @return A positive value if data was successfully read, negative on
* GUAC_STATUS_INPUT_UNAVAILABLE if the instruction could not be read * error, or zero if the instruction could not be read completely
* completely because GUAC_TIMEOUT elapsed, in which case subsequent * because GUAC_TIMEOUT elapsed, in which case subsequent calls to
* calls to guac_read_instruction() will return the parsed instruction * guac_read_instruction() will return the parsed instruction once
* once enough data is available, or any other status code on error. * 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(); guac_timestamp guac_current_timestamp();
void guac_sleep(int millis); void guac_sleep(int millis);

View File

@ -161,22 +161,26 @@ guac_client* guac_get_client(int client_fd) {
/* Wait for data until timeout */ /* Wait for data until timeout */
result = guac_instructions_waiting(io); result = guac_instructions_waiting(io);
if (result == GUAC_STATUS_TIMEOUT) { if (result == 0) {
guac_send_error(io, "Select timeout."); guac_send_error(io, "Select timeout.");
guac_close(io); guac_close(io);
return NULL; return NULL;
} }
/* If error occurs while waiting, exit with failure */ /* If error occurs while waiting, exit with failure */
if (result != GUAC_STATUS_SUCCESS) { if (result < 0) {
guac_close(io); guac_close(io);
return NULL; return NULL;
} }
result = guac_read_instruction(io, &instruction); result = guac_read_instruction(io, &instruction);
if (result < 0) {
guac_close(io);
return NULL;
}
/* Select instruction read */ /* Select instruction read */
if (result == GUAC_STATUS_SUCCESS) { if (result > 0) {
if (strcmp(instruction.opcode, "select") == 0) { if (strcmp(instruction.opcode, "select") == 0) {
@ -243,12 +247,6 @@ guac_client* guac_get_client(int client_fd) {
guac_free_instruction_data(&instruction); 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 */ /* Wait for connect instruction */

View File

@ -45,15 +45,14 @@
/* Error strings */ /* Error strings */
const char* __GUAC_STATUS_SUCCESS_STR = "Success"; const char* __GUAC_STATUS_SUCCESS_STR = "Success";
const char* __GUAC_STATUS_NO_MEMORY_STR = "Insufficient memory"; const char* __GUAC_STATUS_NO_MEMORY_STR = "Insufficient memory";
const char* __GUAC_STATUS_NO_INPUT_STR = "End of input stream"; 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_INPUT_TIMEOUT_STR = "Read timeout"; const char* __GUAC_STATUS_OUTPUT_ERROR_STR = "Output error";
const char* __GUAC_STATUS_OUTPUT_ERROR_STR = "Output error"; const char* __GUAC_STATUS_BAD_ARGUMENT_STR = "Invalid argument";
const char* __GUAC_STATUS_BAD_ARGUMENT_STR = "Invalid argument"; const char* __GUAC_STATUS_BAD_STATE_STR = "Illegal state";
const char* __GUAC_STATUS_BAD_STATE_STR = "Illegal state"; const char* __GUAC_STATUS_INVALID_STATUS_STR = "UNKNOWN STATUS CODE";
const char* __GUAC_STATUS_INVALID_STATUS_STR = "UNKNOWN STATUS CODE";
const char* guac_status_string(guac_status status) { 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: case GUAC_STATUS_NO_INPUT:
return __GUAC_STATUS_NO_INPUT_STR; return __GUAC_STATUS_NO_INPUT_STR;
/* Input unavailable */
case GUAC_STATUS_INPUT_UNAVAILABLE:
return __GUAC_STATUS_INPUT_UNAVAILABLE_STR;
/* Input timeout */ /* Input timeout */
case GUAC_STATUS_INPUT_TIMEOUT: case GUAC_STATUS_INPUT_TIMEOUT:
return __GUAC_STATUS_INPUT_TIMEOUT_STR; return __GUAC_STATUS_INPUT_TIMEOUT_STR;