Renamed io to socket (in vars)

This commit is contained in:
Michael Jumper 2011-11-25 16:34:43 -08:00
parent 059ddc0448
commit 24a2ad6d12
6 changed files with 254 additions and 254 deletions

View File

@ -152,7 +152,7 @@ struct guac_client {
* structure is used only to communicate conveniently with the Guacamole
* web-client.
*/
guac_socket* io;
guac_socket* socket;
/**
* The current state of the client. When the client is first allocated,
@ -382,13 +382,13 @@ int guac_client_plugin_close(guac_client_plugin* plugin);
* initialized using the arguments provided.
*
* @param plugin The client plugin to use to create the new client.
* @param io The guac_socket the client should use for communication.
* @param socket The guac_socket the client should use for communication.
* @param argc The number of arguments being passed to the client.
* @param argv All arguments to be passed to the client.
* @return A pointer to the newly initialized client.
*/
guac_client* guac_client_plugin_get_client(guac_client_plugin* plugin,
guac_socket* io, int argc, char** argv);
guac_socket* socket, int argc, char** argv);
/**
* Free all resources associated with the given client.

View File

@ -155,20 +155,20 @@ void guac_instruction_free(guac_instruction* instruction);
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @param args The NULL-terminated array of argument names (strings).
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_args(guac_socket* io, const char** name);
int guac_protocol_send_args(guac_socket* socket, const char** name);
/**
* Sends a name instruction over the given guac_socket connection.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @param name The name to send within the name instruction.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_name(guac_socket* io, const char* name);
int guac_protocol_send_name(guac_socket* socket, const char* name);
/**
* Sends a sync instruction over the given guac_socket connection. The
@ -177,11 +177,11 @@ int guac_protocol_send_name(guac_socket* io, const char* name);
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @param timestamp The current timestamp (in milliseconds).
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_sync(guac_socket* io, guac_timestamp timestamp);
int guac_protocol_send_sync(guac_socket* socket, guac_timestamp timestamp);
/**
* Sends an error instruction over the given guac_socket connection.
@ -189,11 +189,11 @@ int guac_protocol_send_sync(guac_socket* io, guac_timestamp timestamp);
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @param error The description associated with the error.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_error(guac_socket* io, const char* error);
int guac_protocol_send_error(guac_socket* socket, const char* error);
/**
* Sends a clipboard instruction over the given guac_socket connection.
@ -201,11 +201,11 @@ int guac_protocol_send_error(guac_socket* io, const char* error);
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @param data The clipboard data to send.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_clipboard(guac_socket* io, const char* data);
int guac_protocol_send_clipboard(guac_socket* socket, const char* data);
/**
* Sends a size instruction over the given guac_socket connection.
@ -213,12 +213,12 @@ int guac_protocol_send_clipboard(guac_socket* io, const char* data);
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @param w The width of the display.
* @param h The height of the display.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_size(guac_socket* io, int w, int h);
int guac_protocol_send_size(guac_socket* socket, int w, int h);
/**
* Sends a copy instruction over the given guac_socket connection.
@ -226,7 +226,7 @@ int guac_protocol_send_size(guac_socket* io, int w, int h);
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @param srcl The source layer.
* @param srcx The X coordinate of the source rectangle.
* @param srcy The Y coordinate of the source rectangle.
@ -240,7 +240,7 @@ int guac_protocol_send_size(guac_socket* io, int w, int h);
* should be copied.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_copy(guac_socket* io,
int guac_protocol_send_copy(guac_socket* socket,
const guac_layer* srcl, int srcx, int srcy, int w, int h,
guac_composite_mode mode, const guac_layer* dstl, int dstx, int dsty);
@ -250,7 +250,7 @@ int guac_protocol_send_copy(guac_socket* io,
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @param mode The composite mode to use.
* @param layer The destination layer.
* @param x The X coordinate of the rectangle.
@ -263,7 +263,7 @@ int guac_protocol_send_copy(guac_socket* io,
* @param a The alpha (transparency) component of the color of the rectangle.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_rect(guac_socket* io,
int guac_protocol_send_rect(guac_socket* socket,
guac_composite_mode mode, const guac_layer* layer,
int x, int y, int width, int height,
int r, int g, int b, int a);
@ -274,7 +274,7 @@ int guac_protocol_send_rect(guac_socket* io,
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @param layer The layer to set the clipping region of.
* @param x The X coordinate of the clipping rectangle.
* @param y The Y coordinate of the clipping rectangle.
@ -282,7 +282,7 @@ int guac_protocol_send_rect(guac_socket* io,
* @param height The height of the clipping rectangle.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_clip(guac_socket* io, const guac_layer* layer,
int guac_protocol_send_clip(guac_socket* socket, const guac_layer* layer,
int x, int y, int width, int height);
/**
@ -292,7 +292,7 @@ int guac_protocol_send_clip(guac_socket* io, const guac_layer* layer,
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @param mode The composite mode to use.
* @param layer The destination layer.
* @param x The destination X coordinate.
@ -300,7 +300,7 @@ int guac_protocol_send_clip(guac_socket* io, const guac_layer* layer,
* @param surface A cairo surface containing the image data to send.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_png(guac_socket* io, guac_composite_mode mode,
int guac_protocol_send_png(guac_socket* socket, guac_composite_mode mode,
const guac_layer* layer, int x, int y, cairo_surface_t* surface);
/**
@ -310,25 +310,25 @@ int guac_protocol_send_png(guac_socket* io, guac_composite_mode mode,
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @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 Zero on success, non-zero on error.
*/
int guac_protocol_send_cursor(guac_socket* io, int x, int y, cairo_surface_t* surface);
int guac_protocol_send_cursor(guac_socket* socket, int x, int y, cairo_surface_t* surface);
/**
* Returns whether new instruction data is available on the given guac_socket
* connection for parsing.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @param usec_timeout The maximum number of microseconds to wait before
* giving up.
* @return A positive value if data is available, negative on error, or
* zero if no data is currently available.
*/
int guac_protocol_instructions_waiting(guac_socket* io, int usec_timeout);
int guac_protocol_instructions_waiting(guac_socket* socket, int usec_timeout);
/**
* Reads a single instruction from the given guac_socket connection.
@ -336,7 +336,7 @@ int guac_protocol_instructions_waiting(guac_socket* io, int usec_timeout);
* If an error occurs reading the instruction, NULL is returned,
* and guac_error is set appropriately.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @param usec_timeout The maximum number of microseconds to wait before
* giving up.
* @return A new instruction if data was successfully read, NULL on
@ -346,7 +346,7 @@ int guac_protocol_instructions_waiting(guac_socket* io, int usec_timeout);
* guac_protocol_read_instruction() will return the parsed instruction once
* enough data is available.
*/
guac_instruction* guac_protocol_read_instruction(guac_socket* io, int usec_timeout);
guac_instruction* guac_protocol_read_instruction(guac_socket* socket, int usec_timeout);
/**
* Reads a single instruction with the given opcode from the given guac_socket
@ -358,7 +358,7 @@ guac_instruction* guac_protocol_read_instruction(guac_socket* io, int usec_timeo
* If the instruction read is not the expected instruction, NULL is returned,
* and guac_error is set to GUAC_STATUS_BAD_STATE.
*
* @param io The guac_socket connection to use.
* @param socket The guac_socket connection to use.
* @param usec_timeout The maximum number of microseconds to wait before
* giving up.
* @param opcode The opcode of the instruction to read.
@ -367,7 +367,7 @@ guac_instruction* guac_protocol_read_instruction(guac_socket* io, int usec_timeo
* a different opcode, NULL is returned and guac_error is set to
* GUAC_STATUS_BAD_STATE.
*/
guac_instruction* guac_protocol_expect_instruction(guac_socket* io, int usec_timeout,
guac_instruction* guac_protocol_expect_instruction(guac_socket* socket, int usec_timeout,
const char* opcode);
/**

View File

@ -138,11 +138,11 @@ guac_socket* guac_socket_open(int fd);
* If an error occurs while writing, a non-zero value is returned, and
* guac_error is set appropriately.
*
* @param io The guac_socket object to write to.
* @param socket The guac_socket object to write to.
* @param i The unsigned int to write.
* @return Zero on success, or non-zero if an error occurs while writing.
*/
ssize_t guac_socket_write_int(guac_socket* io, int64_t i);
ssize_t guac_socket_write_int(guac_socket* socket, int64_t i);
/**
* Writes the given string to the given guac_socket object. The data
@ -154,11 +154,11 @@ ssize_t guac_socket_write_int(guac_socket* io, int64_t i);
* If an error occurs while writing, a non-zero value is returned, and
* guac_error is set appropriately.
*
* @param io The guac_socket object to write to.
* @param socket The guac_socket object to write to.
* @param str The string to write.
* @return Zero on success, or non-zero if an error occurs while writing.
*/
ssize_t guac_socket_write_string(guac_socket* io, const char* str);
ssize_t guac_socket_write_string(guac_socket* socket, const char* str);
/**
* Writes the given binary data to the given guac_socket object as base64-encoded
@ -171,12 +171,12 @@ ssize_t guac_socket_write_string(guac_socket* io, const char* str);
* If an error occurs while writing, a non-zero value is returned, and
* guac_error is set appropriately.
*
* @param io The guac_socket object to write to.
* @param socket The guac_socket object to write to.
* @param buf A buffer containing the data to write.
* @param count The number of bytes to write.
* @return Zero on success, or non-zero if an error occurs while writing.
*/
ssize_t guac_socket_write_base64(guac_socket* io, const void* buf, size_t count);
ssize_t guac_socket_write_base64(guac_socket* socket, const void* buf, size_t count);
/**
* Flushes the base64 buffer, writing padding characters as necessary.
@ -184,10 +184,10 @@ ssize_t guac_socket_write_base64(guac_socket* io, const void* buf, size_t count)
* If an error occurs while writing, a non-zero value is returned, and
* guac_error is set appropriately.
*
* @param io The guac_socket object to flush
* @param socket The guac_socket object to flush
* @return Zero on success, or non-zero if an error occurs during flush.
*/
ssize_t guac_socket_flush_base64(guac_socket* io);
ssize_t guac_socket_flush_base64(guac_socket* socket);
/**
* Flushes the write buffer.
@ -195,10 +195,10 @@ ssize_t guac_socket_flush_base64(guac_socket* io);
* If an error occurs while writing, a non-zero value is returned, and
* guac_error is set appropriately.
*
* @param io The guac_socket object to flush
* @param socket The guac_socket object to flush
* @return Zero on success, or non-zero if an error occurs during flush.
*/
ssize_t guac_socket_flush(guac_socket* io);
ssize_t guac_socket_flush(guac_socket* socket);
/**
@ -211,22 +211,22 @@ ssize_t guac_socket_flush(guac_socket* io);
* If a timeout occurs while waiting, zero value is returned, and
* guac_error is set to GUAC_STATUS_INPUT_TIMEOUT.
*
* @param io The guac_socket object to wait for.
* @param socket The guac_socket object to wait for.
* @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.
*/
int guac_socket_select(guac_socket* io, int usec_timeout);
int guac_socket_select(guac_socket* socket, int usec_timeout);
/**
* Frees resources allocated to the given guac_socket object. Note that this
* implicitly flush all buffers, but will NOT close the associated file
* descriptor.
*
* @param io The guac_socket object to close.
* @param socket The guac_socket object to close.
*/
void guac_socket_close(guac_socket* io);
void guac_socket_close(guac_socket* socket);
#endif

View File

@ -182,7 +182,7 @@ int guac_client_plugin_close(guac_client_plugin* plugin) {
}
guac_client* guac_client_plugin_get_client(guac_client_plugin* plugin,
guac_socket* io, int argc, char** argv) {
guac_socket* socket, int argc, char** argv) {
/* Allocate new client */
guac_client* client = malloc(sizeof(guac_client));
@ -194,7 +194,7 @@ guac_client* guac_client_plugin_get_client(guac_client_plugin* plugin,
/* Init new client */
memset(client, 0, sizeof(guac_client));
client->io = io;
client->socket = socket;
client->last_received_timestamp =
client->last_sent_timestamp = guac_protocol_get_timestamp();

View File

@ -64,167 +64,167 @@
#include "protocol.h"
#include "error.h"
ssize_t __guac_socket_write_length_string(guac_socket* io, const char* str) {
ssize_t __guac_socket_write_length_string(guac_socket* socket, const char* str) {
return
guac_socket_write_int(io, strlen(str))
|| guac_socket_write_string(io, ".")
|| guac_socket_write_string(io, str);
guac_socket_write_int(socket, strlen(str))
|| guac_socket_write_string(socket, ".")
|| guac_socket_write_string(socket, str);
}
ssize_t __guac_socket_write_length_int(guac_socket* io, int64_t i) {
ssize_t __guac_socket_write_length_int(guac_socket* socket, int64_t i) {
char buffer[128];
snprintf(buffer, sizeof(buffer), "%"PRIi64, i);
return __guac_socket_write_length_string(io, buffer);
return __guac_socket_write_length_string(socket, buffer);
}
int guac_protocol_send_args(guac_socket* io, const char** args) {
int guac_protocol_send_args(guac_socket* socket, const char** args) {
int i;
if (guac_socket_write_string(io, "4.args")) return -1;
if (guac_socket_write_string(socket, "4.args")) return -1;
for (i=0; args[i] != NULL; i++) {
if (guac_socket_write_string(io, ","))
if (guac_socket_write_string(socket, ","))
return -1;
if (__guac_socket_write_length_string(io, args[i]))
if (__guac_socket_write_length_string(socket, args[i]))
return -1;
}
return guac_socket_write_string(io, ";");
return guac_socket_write_string(socket, ";");
}
int guac_protocol_send_name(guac_socket* io, const char* name) {
int guac_protocol_send_name(guac_socket* socket, const char* name) {
return
guac_socket_write_string(io, "4.name,")
|| __guac_socket_write_length_string(io, name)
|| guac_socket_write_string(io, ";");
guac_socket_write_string(socket, "4.name,")
|| __guac_socket_write_length_string(socket, name)
|| guac_socket_write_string(socket, ";");
}
int guac_protocol_send_size(guac_socket* io, int w, int h) {
int guac_protocol_send_size(guac_socket* socket, int w, int h) {
return
guac_socket_write_string(io, "4.size,")
|| __guac_socket_write_length_int(io, w)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, h)
|| guac_socket_write_string(io, ";");
guac_socket_write_string(socket, "4.size,")
|| __guac_socket_write_length_int(socket, w)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, h)
|| guac_socket_write_string(socket, ";");
}
int guac_protocol_send_clipboard(guac_socket* io, const char* data) {
int guac_protocol_send_clipboard(guac_socket* socket, const char* data) {
return
guac_socket_write_string(io, "9.clipboard,")
|| __guac_socket_write_length_string(io, data)
|| guac_socket_write_string(io, ";");
guac_socket_write_string(socket, "9.clipboard,")
|| __guac_socket_write_length_string(socket, data)
|| guac_socket_write_string(socket, ";");
}
int guac_protocol_send_error(guac_socket* io, const char* error) {
int guac_protocol_send_error(guac_socket* socket, const char* error) {
return
guac_socket_write_string(io, "5.error,")
|| __guac_socket_write_length_string(io, error)
|| guac_socket_write_string(io, ";");
guac_socket_write_string(socket, "5.error,")
|| __guac_socket_write_length_string(socket, error)
|| guac_socket_write_string(socket, ";");
}
int guac_protocol_send_sync(guac_socket* io, guac_timestamp timestamp) {
int guac_protocol_send_sync(guac_socket* socket, guac_timestamp timestamp) {
return
guac_socket_write_string(io, "4.sync,")
|| __guac_socket_write_length_int(io, timestamp)
|| guac_socket_write_string(io, ";");
guac_socket_write_string(socket, "4.sync,")
|| __guac_socket_write_length_int(socket, timestamp)
|| guac_socket_write_string(socket, ";");
}
int guac_protocol_send_copy(guac_socket* io,
int guac_protocol_send_copy(guac_socket* socket,
const guac_layer* srcl, int srcx, int srcy, int w, int h,
guac_composite_mode mode, const guac_layer* dstl, int dstx, int dsty) {
return
guac_socket_write_string(io, "4.copy,")
|| __guac_socket_write_length_int(io, srcl->index)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, srcx)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, srcy)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, w)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, h)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, mode)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, dstl->index)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, dstx)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, dsty)
|| guac_socket_write_string(io, ";");
guac_socket_write_string(socket, "4.copy,")
|| __guac_socket_write_length_int(socket, srcl->index)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, srcx)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, srcy)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, w)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, h)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, mode)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, dstl->index)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, dstx)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, dsty)
|| guac_socket_write_string(socket, ";");
}
int guac_protocol_send_rect(guac_socket* io,
int guac_protocol_send_rect(guac_socket* socket,
guac_composite_mode mode, const guac_layer* layer,
int x, int y, int width, int height,
int r, int g, int b, int a) {
return
guac_socket_write_string(io, "4.rect,")
|| __guac_socket_write_length_int(io, mode)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, layer->index)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, x)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, y)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, width)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, height)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, r)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, g)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, b)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, a)
|| guac_socket_write_string(io, ";");
guac_socket_write_string(socket, "4.rect,")
|| __guac_socket_write_length_int(socket, mode)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, layer->index)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, x)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, y)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, width)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, height)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, r)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, g)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, b)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, a)
|| guac_socket_write_string(socket, ";");
}
int guac_protocol_send_clip(guac_socket* io, const guac_layer* layer,
int guac_protocol_send_clip(guac_socket* socket, const guac_layer* layer,
int x, int y, int width, int height) {
return
guac_socket_write_string(io, "4.clip,")
|| __guac_socket_write_length_int(io, layer->index)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, x)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, y)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, width)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, height)
|| guac_socket_write_string(io, ";");
guac_socket_write_string(socket, "4.clip,")
|| __guac_socket_write_length_int(socket, layer->index)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, x)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, y)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, width)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, height)
|| guac_socket_write_string(socket, ";");
}
typedef struct __guac_socket_write_png_data {
guac_socket* io;
guac_socket* socket;
char* buffer;
int buffer_size;
@ -262,14 +262,14 @@ cairo_status_t __guac_socket_write_png(void* closure, const unsigned char* data,
}
int __guac_socket_write_length_png(guac_socket* io, cairo_surface_t* surface) {
int __guac_socket_write_length_png(guac_socket* socket, cairo_surface_t* surface) {
__guac_socket_write_png_data png_data;
int base64_length;
/* Write surface */
png_data.io = io;
png_data.socket = socket;
png_data.buffer_size = 8192;
png_data.buffer = malloc(png_data.buffer_size);
png_data.data_size = 0;
@ -282,10 +282,10 @@ int __guac_socket_write_length_png(guac_socket* io, cairo_surface_t* surface) {
/* Write length and data */
if (
guac_socket_write_int(io, base64_length)
|| guac_socket_write_string(io, ".")
|| guac_socket_write_base64(io, png_data.buffer, png_data.data_size)
|| guac_socket_flush_base64(io)) {
guac_socket_write_int(socket, base64_length)
|| guac_socket_write_string(socket, ".")
|| guac_socket_write_base64(socket, png_data.buffer, png_data.data_size)
|| guac_socket_flush_base64(socket)) {
free(png_data.buffer);
return -1;
}
@ -296,60 +296,60 @@ int __guac_socket_write_length_png(guac_socket* io, cairo_surface_t* surface) {
}
int guac_protocol_send_png(guac_socket* io, guac_composite_mode mode,
int guac_protocol_send_png(guac_socket* socket, guac_composite_mode mode,
const guac_layer* layer, int x, int y, cairo_surface_t* surface) {
return
guac_socket_write_string(io, "3.png,")
|| __guac_socket_write_length_int(io, mode)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, layer->index)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, x)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, y)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_png(io, surface)
|| guac_socket_write_string(io, ";");
guac_socket_write_string(socket, "3.png,")
|| __guac_socket_write_length_int(socket, mode)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, layer->index)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, x)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, y)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_png(socket, surface)
|| guac_socket_write_string(socket, ";");
}
int guac_protocol_send_cursor(guac_socket* io, int x, int y, cairo_surface_t* surface) {
int guac_protocol_send_cursor(guac_socket* socket, int x, int y, cairo_surface_t* surface) {
return
guac_socket_write_string(io, "6.cursor,")
|| __guac_socket_write_length_int(io, x)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_int(io, y)
|| guac_socket_write_string(io, ",")
|| __guac_socket_write_length_png(io, surface)
|| guac_socket_write_string(io, ";");
guac_socket_write_string(socket, "6.cursor,")
|| __guac_socket_write_length_int(socket, x)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_int(socket, y)
|| guac_socket_write_string(socket, ",")
|| __guac_socket_write_length_png(socket, surface)
|| guac_socket_write_string(socket, ";");
}
int __guac_fill_instructionbuf(guac_socket* io) {
int __guac_fill_instructionbuf(guac_socket* socket) {
int retval;
/* Attempt to fill buffer */
retval = recv(
io->fd,
io->__instructionbuf + io->__instructionbuf_used_length,
io->__instructionbuf_size - io->__instructionbuf_used_length,
socket->fd,
socket->__instructionbuf + socket->__instructionbuf_used_length,
socket->__instructionbuf_size - socket->__instructionbuf_used_length,
0
);
if (retval < 0)
return retval;
io->__instructionbuf_used_length += retval;
socket->__instructionbuf_used_length += retval;
/* Expand buffer if necessary */
if (io->__instructionbuf_used_length > io->__instructionbuf_size / 2) {
io->__instructionbuf_size *= 2;
io->__instructionbuf = realloc(io->__instructionbuf, io->__instructionbuf_size);
if (socket->__instructionbuf_used_length > socket->__instructionbuf_size / 2) {
socket->__instructionbuf_size *= 2;
socket->__instructionbuf = realloc(socket->__instructionbuf, socket->__instructionbuf_size);
}
return retval;
@ -357,10 +357,10 @@ int __guac_fill_instructionbuf(guac_socket* io) {
}
/* Returns new instruction if one exists, or NULL if no more instructions. */
guac_instruction* guac_protocol_read_instruction(guac_socket* io, int usec_timeout) {
guac_instruction* guac_protocol_read_instruction(guac_socket* socket, int usec_timeout) {
int retval;
int i = io->__instructionbuf_parse_start;
int i = socket->__instructionbuf_parse_start;
/* Loop until a instruction is read */
for (;;) {
@ -369,10 +369,10 @@ guac_instruction* guac_protocol_read_instruction(guac_socket* io, int usec_timeo
int element_length = 0;
/* Parse instruction in buffe */
while (i < io->__instructionbuf_used_length) {
while (i < socket->__instructionbuf_used_length) {
/* Read character from buffer */
char c = io->__instructionbuf[i++];
char c = socket->__instructionbuf[i++];
/* If digit, calculate element length */
if (c >= '0' && c <= '9')
@ -382,10 +382,10 @@ guac_instruction* guac_protocol_read_instruction(guac_socket* io, int usec_timeo
else if (c == '.') {
/* Verify element is fully read */
if (i + element_length < io->__instructionbuf_used_length) {
if (i + element_length < socket->__instructionbuf_used_length) {
/* Get element value */
char* elementv = &(io->__instructionbuf[i]);
char* elementv = &(socket->__instructionbuf[i]);
/* Get terminator, set null terminator of elementv */
char terminator = elementv[element_length];
@ -399,10 +399,10 @@ guac_instruction* guac_protocol_read_instruction(guac_socket* io, int usec_timeo
/* As element has been read successfully, update
* parse start */
io->__instructionbuf_parse_start = i;
socket->__instructionbuf_parse_start = i;
/* Save element */
io->__instructionbuf_elementv[io->__instructionbuf_elementc++] = elementv;
socket->__instructionbuf_elementv[socket->__instructionbuf_elementc++] = elementv;
/* Finish parse if terminator is a semicolon */
if (terminator == ';') {
@ -418,7 +418,7 @@ guac_instruction* guac_protocol_read_instruction(guac_socket* io, int usec_timeo
}
/* Init parsed instruction */
parsed_instruction->argc = io->__instructionbuf_elementc - 1;
parsed_instruction->argc = socket->__instructionbuf_elementc - 1;
parsed_instruction->argv = malloc(sizeof(char*) * parsed_instruction->argc);
/* Fail if memory could not be alloc'd for argv */
@ -429,7 +429,7 @@ guac_instruction* guac_protocol_read_instruction(guac_socket* io, int usec_timeo
}
/* Set opcode */
parsed_instruction->opcode = strdup(io->__instructionbuf_elementv[0]);
parsed_instruction->opcode = strdup(socket->__instructionbuf_elementv[0]);
/* Fail if memory could not be alloc'd for opcode */
if (parsed_instruction->opcode == NULL) {
@ -442,7 +442,7 @@ guac_instruction* guac_protocol_read_instruction(guac_socket* io, int usec_timeo
/* Copy element values to parsed instruction */
for (j=0; j<parsed_instruction->argc; j++) {
parsed_instruction->argv[j] = strdup(io->__instructionbuf_elementv[j+1]);
parsed_instruction->argv[j] = strdup(socket->__instructionbuf_elementv[j+1]);
/* Free memory and fail if out of mem */
if (parsed_instruction->argv[j] == NULL) {
@ -461,10 +461,10 @@ guac_instruction* guac_protocol_read_instruction(guac_socket* io, int usec_timeo
}
/* Reset buffer */
memmove(io->__instructionbuf, io->__instructionbuf + i + 1, io->__instructionbuf_used_length - i - 1);
io->__instructionbuf_used_length -= i + 1;
io->__instructionbuf_parse_start = 0;
io->__instructionbuf_elementc = 0;
memmove(socket->__instructionbuf, socket->__instructionbuf + i + 1, socket->__instructionbuf_used_length - i - 1);
socket->__instructionbuf_used_length -= i + 1;
socket->__instructionbuf_parse_start = 0;
socket->__instructionbuf_elementc = 0;
/* Done */
return parsed_instruction;
@ -482,12 +482,12 @@ guac_instruction* guac_protocol_read_instruction(guac_socket* io, int usec_timeo
}
/* No instruction yet? Get more data ... */
retval = guac_socket_select(io, usec_timeout);
retval = guac_socket_select(socket, usec_timeout);
if (retval <= 0)
return NULL;
/* If more data is available, fill into buffer */
retval = __guac_fill_instructionbuf(io);
retval = __guac_fill_instructionbuf(socket);
/* Error, guac_error already set */
if (retval < 0)
@ -503,17 +503,17 @@ guac_instruction* guac_protocol_read_instruction(guac_socket* io, int usec_timeo
}
guac_instruction* guac_protocol_expect_instruction(guac_socket* io, int usec_timeout,
guac_instruction* guac_protocol_expect_instruction(guac_socket* socket, int usec_timeout,
const char* opcode) {
guac_instruction* instruction;
/* Wait for data until timeout */
if (guac_protocol_instructions_waiting(io, usec_timeout) <= 0)
if (guac_protocol_instructions_waiting(socket, usec_timeout) <= 0)
return NULL;
/* Read available instruction */
instruction = guac_protocol_read_instruction(io, usec_timeout);
instruction = guac_protocol_read_instruction(socket, usec_timeout);
if (instruction == NULL)
return NULL;
@ -542,12 +542,12 @@ void guac_instruction_free(guac_instruction* instruction) {
}
int guac_protocol_instructions_waiting(guac_socket* io, int usec_timeout) {
int guac_protocol_instructions_waiting(guac_socket* socket, int usec_timeout) {
if (io->__instructionbuf_used_length > 0)
if (socket->__instructionbuf_used_length > 0)
return 1;
return guac_socket_select(io, usec_timeout);
return guac_socket_select(socket, usec_timeout);
}
guac_timestamp guac_protocol_get_timestamp() {

View File

@ -64,55 +64,55 @@ char __guac_socket_BASE64_CHARACTERS[64] = {
guac_socket* guac_socket_open(int fd) {
guac_socket* io = malloc(sizeof(guac_socket));
guac_socket* socket = malloc(sizeof(guac_socket));
/* If no memory available, return with error */
if (io == NULL) {
if (socket == NULL) {
guac_error = GUAC_STATUS_NO_MEMORY;
return NULL;
}
io->__ready = 0;
io->__written = 0;
io->fd = fd;
socket->__ready = 0;
socket->__written = 0;
socket->fd = fd;
/* Allocate instruction buffer */
io->__instructionbuf_size = 1024;
io->__instructionbuf = malloc(io->__instructionbuf_size);
socket->__instructionbuf_size = 1024;
socket->__instructionbuf = malloc(socket->__instructionbuf_size);
/* If no memory available, return with error */
if (io->__instructionbuf == NULL) {
if (socket->__instructionbuf == NULL) {
guac_error = GUAC_STATUS_NO_MEMORY;
free(io);
free(socket);
return NULL;
}
/* Init members */
io->__instructionbuf_used_length = 0;
io->__instructionbuf_parse_start = 0;
io->__instructionbuf_elementc = 0;
socket->__instructionbuf_used_length = 0;
socket->__instructionbuf_parse_start = 0;
socket->__instructionbuf_elementc = 0;
return io;
return socket;
}
void guac_socket_close(guac_socket* io) {
guac_socket_flush(io);
free(io->__instructionbuf);
free(io);
void guac_socket_close(guac_socket* socket) {
guac_socket_flush(socket);
free(socket->__instructionbuf);
free(socket);
}
/* Write bytes, limit rate */
ssize_t __guac_socket_write(guac_socket* io, const char* buf, int count) {
ssize_t __guac_socket_write(guac_socket* socket, const char* buf, int count) {
int retval;
#ifdef __MINGW32__
/* MINGW32 WINSOCK only works with send() */
retval = send(io->fd, buf, count, 0);
retval = send(socket->fd, buf, count, 0);
#else
/* Use write() for all other platforms */
retval = write(io->fd, buf, count);
retval = write(socket->fd, buf, count);
#endif
/* Record errors in guac_error */
@ -122,33 +122,33 @@ ssize_t __guac_socket_write(guac_socket* io, const char* buf, int count) {
return retval;
}
ssize_t guac_socket_write_int(guac_socket* io, int64_t i) {
ssize_t guac_socket_write_int(guac_socket* socket, int64_t i) {
char buffer[128];
snprintf(buffer, sizeof(buffer), "%"PRIi64, i);
return guac_socket_write_string(io, buffer);
return guac_socket_write_string(socket, buffer);
}
ssize_t guac_socket_write_string(guac_socket* io, const char* str) {
ssize_t guac_socket_write_string(guac_socket* socket, const char* str) {
char* __out_buf = io->__out_buf;
char* __out_buf = socket->__out_buf;
int retval;
for (; *str != '\0'; str++) {
__out_buf[io->__written++] = *str;
__out_buf[socket->__written++] = *str;
/* Flush when necessary, return on error */
if (io->__written > 8188 /* sizeof(__out_buf) - 4 */) {
if (socket->__written > 8188 /* sizeof(__out_buf) - 4 */) {
retval = __guac_socket_write(io, __out_buf, io->__written);
retval = __guac_socket_write(socket, __out_buf, socket->__written);
if (retval < 0)
return retval;
io->__written = 0;
socket->__written = 0;
}
}
@ -157,42 +157,42 @@ ssize_t guac_socket_write_string(guac_socket* io, const char* str) {
}
ssize_t __guac_socket_write_base64_triplet(guac_socket* io, int a, int b, int c) {
ssize_t __guac_socket_write_base64_triplet(guac_socket* socket, int a, int b, int c) {
char* __out_buf = io->__out_buf;
char* __out_buf = socket->__out_buf;
int retval;
/* Byte 1 */
__out_buf[io->__written++] = __guac_socket_BASE64_CHARACTERS[(a & 0xFC) >> 2]; /* [AAAAAA]AABBBB BBBBCC CCCCCC */
__out_buf[socket->__written++] = __guac_socket_BASE64_CHARACTERS[(a & 0xFC) >> 2]; /* [AAAAAA]AABBBB BBBBCC CCCCCC */
if (b >= 0) {
__out_buf[io->__written++] = __guac_socket_BASE64_CHARACTERS[((a & 0x03) << 4) | ((b & 0xF0) >> 4)]; /* AAAAAA[AABBBB]BBBBCC CCCCCC */
__out_buf[socket->__written++] = __guac_socket_BASE64_CHARACTERS[((a & 0x03) << 4) | ((b & 0xF0) >> 4)]; /* AAAAAA[AABBBB]BBBBCC CCCCCC */
if (c >= 0) {
__out_buf[io->__written++] = __guac_socket_BASE64_CHARACTERS[((b & 0x0F) << 2) | ((c & 0xC0) >> 6)]; /* AAAAAA AABBBB[BBBBCC]CCCCCC */
__out_buf[io->__written++] = __guac_socket_BASE64_CHARACTERS[c & 0x3F]; /* AAAAAA AABBBB BBBBCC[CCCCCC] */
__out_buf[socket->__written++] = __guac_socket_BASE64_CHARACTERS[((b & 0x0F) << 2) | ((c & 0xC0) >> 6)]; /* AAAAAA AABBBB[BBBBCC]CCCCCC */
__out_buf[socket->__written++] = __guac_socket_BASE64_CHARACTERS[c & 0x3F]; /* AAAAAA AABBBB BBBBCC[CCCCCC] */
}
else {
__out_buf[io->__written++] = __guac_socket_BASE64_CHARACTERS[((b & 0x0F) << 2)]; /* AAAAAA AABBBB[BBBB--]------ */
__out_buf[io->__written++] = '='; /* AAAAAA AABBBB BBBB--[------] */
__out_buf[socket->__written++] = __guac_socket_BASE64_CHARACTERS[((b & 0x0F) << 2)]; /* AAAAAA AABBBB[BBBB--]------ */
__out_buf[socket->__written++] = '='; /* AAAAAA AABBBB BBBB--[------] */
}
}
else {
__out_buf[io->__written++] = __guac_socket_BASE64_CHARACTERS[((a & 0x03) << 4)]; /* AAAAAA[AA----]------ ------ */
__out_buf[io->__written++] = '='; /* AAAAAA AA----[------]------ */
__out_buf[io->__written++] = '='; /* AAAAAA AA---- ------[------] */
__out_buf[socket->__written++] = __guac_socket_BASE64_CHARACTERS[((a & 0x03) << 4)]; /* AAAAAA[AA----]------ ------ */
__out_buf[socket->__written++] = '='; /* AAAAAA AA----[------]------ */
__out_buf[socket->__written++] = '='; /* AAAAAA AA---- ------[------] */
}
/* At this point, 4 bytes have been io->__written */
/* At this point, 4 bytes have been socket->__written */
/* Flush when necessary, return on error */
if (io->__written > 8188 /* sizeof(__out_buf) - 4 */) {
retval = __guac_socket_write(io, __out_buf, io->__written);
if (socket->__written > 8188 /* sizeof(__out_buf) - 4 */) {
retval = __guac_socket_write(socket, __out_buf, socket->__written);
if (retval < 0)
return retval;
io->__written = 0;
socket->__written = 0;
}
if (b < 0)
@ -205,27 +205,27 @@ ssize_t __guac_socket_write_base64_triplet(guac_socket* io, int a, int b, int c)
}
ssize_t __guac_socket_write_base64_byte(guac_socket* io, char buf) {
ssize_t __guac_socket_write_base64_byte(guac_socket* socket, char buf) {
int* __ready_buf = io->__ready_buf;
int* __ready_buf = socket->__ready_buf;
int retval;
__ready_buf[io->__ready++] = buf & 0xFF;
__ready_buf[socket->__ready++] = buf & 0xFF;
/* Flush triplet */
if (io->__ready == 3) {
retval = __guac_socket_write_base64_triplet(io, __ready_buf[0], __ready_buf[1], __ready_buf[2]);
if (socket->__ready == 3) {
retval = __guac_socket_write_base64_triplet(socket, __ready_buf[0], __ready_buf[1], __ready_buf[2]);
if (retval < 0)
return retval;
io->__ready = 0;
socket->__ready = 0;
}
return 1;
}
ssize_t guac_socket_write_base64(guac_socket* io, const void* buf, size_t count) {
ssize_t guac_socket_write_base64(guac_socket* socket, const void* buf, size_t count) {
int retval;
@ -234,7 +234,7 @@ ssize_t guac_socket_write_base64(guac_socket* io, const void* buf, size_t count)
while (char_buf < end) {
retval = __guac_socket_write_base64_byte(io, *(char_buf++));
retval = __guac_socket_write_base64_byte(socket, *(char_buf++));
if (retval < 0)
return retval;
@ -244,30 +244,30 @@ ssize_t guac_socket_write_base64(guac_socket* io, const void* buf, size_t count)
}
ssize_t guac_socket_flush(guac_socket* io) {
ssize_t guac_socket_flush(guac_socket* socket) {
int retval;
/* Flush remaining bytes in buffer */
if (io->__written > 0) {
retval = __guac_socket_write(io, io->__out_buf, io->__written);
if (socket->__written > 0) {
retval = __guac_socket_write(socket, socket->__out_buf, socket->__written);
if (retval < 0)
return retval;
io->__written = 0;
socket->__written = 0;
}
return 0;
}
ssize_t guac_socket_flush_base64(guac_socket* io) {
ssize_t guac_socket_flush_base64(guac_socket* socket) {
int retval;
/* Flush triplet to output buffer */
while (io->__ready > 0) {
retval = __guac_socket_write_base64_byte(io, -1);
while (socket->__ready > 0) {
retval = __guac_socket_write_base64_byte(socket, -1);
if (retval < 0)
return retval;
}
@ -277,7 +277,7 @@ ssize_t guac_socket_flush_base64(guac_socket* io) {
}
int guac_socket_select(guac_socket* io, int usec_timeout) {
int guac_socket_select(guac_socket* socket, int usec_timeout) {
fd_set fds;
struct timeval timeout;
@ -285,7 +285,7 @@ int guac_socket_select(guac_socket* io, int usec_timeout) {
/* No timeout if usec_timeout is negative */
if (usec_timeout < 0)
retval = select(io->fd + 1, &fds, NULL, NULL, NULL);
retval = select(socket->fd + 1, &fds, NULL, NULL, NULL);
/* Handle timeout if specified */
else {
@ -293,9 +293,9 @@ int guac_socket_select(guac_socket* io, int usec_timeout) {
timeout.tv_usec = usec_timeout%1000000;
FD_ZERO(&fds);
FD_SET(io->fd, &fds);
FD_SET(socket->fd, &fds);
retval = select(io->fd + 1, &fds, NULL, NULL, &timeout);
retval = select(socket->fd + 1, &fds, NULL, NULL, &timeout);
}
/* Properly set guac_error */