More renaming

This commit is contained in:
Michael Jumper
2010-12-08 13:14:04 -08:00
parent e47bcaf0c1
commit 7341826547
82 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,242 @@
/*
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CLIENT_H
#define _CLIENT_H
#include <png.h>
#include "guacio.h"
/**
* Provides functions and structures required for defining (and handling) a proxy client.
*
* @file client.h
*/
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, char* copied);
/**
* Handler for freeing up any extra data allocated by the client
* implementation.
*/
typedef int guac_client_free_handler(void* client);
/**
* 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 {
/**
* The GUACIO structure to be used to communicate with the web-client. It is
* expected that the implementor of any Guacamole proxy client will provide
* their own mechanism of I/O for their protocol. The GUACIO structure is
* used only to communicate conveniently with the Guacamole web-client.
*/
GUACIO* io;
/**
* Reference to dlopen'd client plugin.
*/
void* client_plugin_handle;
/**
* Arbitrary reference to proxy client-specific data. Implementors of a
* Guacamole proxy client can store any data they want here, which can then
* be retrieved as necessary in the message handlers.
*/
void* data;
/**
* Handler for server messages. If set, this function will be called
* occasionally by the Guacamole proxy to give the client a chance to
* handle messages from whichever server it is connected to.
*
* Example:
* @code
* void handle_messages(guac_client* client);
*
* int guac_client_init(guac_client* client, int argc, char** argv) {
* client->handle_messages = handle_messages;
* }
* @endcode
*/
guac_client_handle_messages* handle_messages;
/**
* Handler for mouse events sent by the Gaucamole web-client.
*
* The handler takes the integer mouse X and Y coordinates, as well as
* a button mask containing the bitwise OR of all button values currently
* being pressed. Those values are:
*
* <table>
* <tr><th>Button</th> <th>Value</th></tr>
* <tr><td>Left</td> <td>1</td></tr>
* <tr><td>Middle</td> <td>2</td></tr>
* <tr><td>Right</td> <td>4</td></tr>
* <tr><td>Scrollwheel Up</td> <td>8</td></tr>
* <tr><td>Scrollwheel Down</td><td>16</td></tr>
* </table>
* Example:
* @code
* void mouse_handler(guac_client* client, int x, int y, int button_mask);
*
* int guac_client_init(guac_client* client, int argc, char** argv) {
* client->mouse_handler = mouse_handler;
* }
* @endcode
*/
guac_client_mouse_handler* mouse_handler;
/**
* Handler for key events sent by the Guacamole web-client.
*
* The handler takes the integer X11 keysym associated with the key
* being pressed/released, and an integer representing whether the key
* is being pressed (1) or released (0).
*
* Example:
* @code
* void key_handler(guac_client* client, int keysym, int pressed);
*
* int guac_client_init(guac_client* client, int argc, char** argv) {
* client->key_handler = key_handler;
* }
* @endcode
*/
guac_client_key_handler* key_handler;
/**
* Handler for clipboard events sent by the Guacamole web-client. This
* handler will be called whenever the web-client sets the data of the
* clipboard.
*
* This handler takes a single string which contains the text which
* has been set in the clipboard. This text is already unescaped from
* the Guacamole escaped version sent within the clipboard message
* in the protocol.
*
* Example:
* @code
* void clipboard_handler(guac_client* client, char* copied);
*
* int guac_client_init(guac_client* client, int argc, char** argv) {
* client->clipboard_handler = clipboard_handler;
* }
* @endcode
*/
guac_client_clipboard_handler* clipboard_handler;
/**
* Handler for freeing data when the client is being unloaded.
*
* This handler will be called when the client needs to be unloaded
* by the proxy, and any data allocated by the proxy client should be
* freed.
*
* Implement this handler if you store data inside the client.
*
* Example:
* @code
* void free_handler(guac_client* client);
*
* int guac_client_init(guac_client* client, int argc, char** argv) {
* client->free_handler = free_handler;
* }
* @endcode
*/
guac_client_free_handler* free_handler;
};
/**
* Handler which should initialize the given guac_client.
*/
typedef int guac_client_init_handler(guac_client* client, int argc, char** argv);
/**
* Initialize and return a new guac_client. The pluggable client will be chosen based on
* the first connect message received on the given file descriptor.
*
* @param client_fd The file descriptor associated with the socket associated with the connection to the
* web-client tunnel.
* @return A pointer to the newly initialized client.
*/
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.
*/
void guac_start_client(guac_client* client);
/**
* Free all resources associated with the given client.
*
* @param client The proxy client to free all reasources of.
*/
void guac_free_client(guac_client* client);
/**
* Allocate a libpng-compatible buffer to hold raw image data.
*
* @param w The width of the buffer to allocate, in pixels.
* @param h The height of the buffer to allocate, in pixels.
* @param bpp The number of bytes per pixel (3 for RGB images, 4 for RGBA).
* @return A pointer to the newly allocated buffer.
*/
png_byte** guac_alloc_png_buffer(int w, int h, int bpp);
/**
* Free all memory associated with the given libpng-compatible buffer
* as allocated by guac_alloc_png_buffer.
*
* @param png_buffer The buffer to free.
* @param h The height of the buffer to free.
*/
void guac_free_png_buffer(png_byte** png_buffer, int h);
#endif

View File

@@ -0,0 +1,179 @@
/*
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _GUACIO_H
#define _GUACIO_H
#include <unistd.h>
/**
* Defines the GUACIO object and functionss for using and manipulating it.
*
* @file guacio.h
*/
/**
* The core I/O object of Guacamole. GUACIO provides buffered input and output
* as well as convenience methods for efficiently writing base64 data.
*/
typedef struct GUACIO {
/**
* The file descriptor to be read from / written to.
*/
int fd;
/**
* The number of bytes present in the base64 "ready" buffer.
*/
int ready;
/**
* The base64 "ready" buffer. Once this buffer is filled, base64 data is
* flushed to the main write buffer.
*/
int ready_buf[3];
/**
* The number of bytes currently in the main write buffer.
*/
int written;
/**
* The main write buffer. Bytes written go here before being flushed
* to the open file descriptor.
*/
char out_buf[8192];
/**
* The current size of the instruction buffer.
*/
int instructionbuf_size;
/**
* The number of bytes currently in the instruction buffer.
*/
int instructionbuf_used_length;
/**
* The instruction buffer. This is essentially the input buffer,
* provided as a convenience to be used to buffer instructions until
* those instructions are complete and ready to be parsed.
*/
char* instructionbuf;
/**
* The transfer limit, in kilobytes per second. If 0, there is no
* transfer limit. If non-zero, sleep calls are used at the end of
* a write to ensure output never exceeds the specified limit.
*/
unsigned int transfer_limit; /* KB/sec */
} GUACIO;
/**
* Allocates and initializes a new GUACIO object with the given open
* file descriptor.
*
* @param fd An open file descriptor that this GUACIO object should manage.
* @return A newly allocated GUACIO object associated with the given
* file descriptor.
*/
GUACIO* guac_open(int fd);
/**
* Writes the given unsigned int to the given GUACIO object. The data
* written may be buffered until the buffer is flushed automatically or
* manually.
*
* @param io The GUACIO 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_write_int(GUACIO* io, unsigned int i);
/**
* Writes the given string to the given GUACIO object. The data
* written may be buffered until the buffer is flushed automatically or
* manually. Note that if the string can contain characters used
* internally by the Guacamole protocol (commas, semicolons, or
* backslashes) it will need to be escaped.
*
* @param io The GUACIO 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_write_string(GUACIO* io, const char* str);
/**
* Writes the given binary data to the given GUACIO object as base64-encoded
* data. The data written may be buffered until the buffer is flushed
* automatically or manually. Beware that because base64 data is buffered
* on top of the write buffer already used, a call to guac_flush_base64() must
* be made before non-base64 writes (or writes of an independent block of
* base64 data) can be made.
*
* @param io The GUACIO 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_write_base64(GUACIO* io, const void* buf, size_t count);
/**
* Flushes the base64 buffer, writing padding characters as necessary.
*
* @param io The GUACIO object to flush
* @return Zero on success, or non-zero if an error occurs during flush.
*/
ssize_t guac_flush_base64(GUACIO* io);
/**
* Flushes the write buffer.
*
* @param io The GUACIO object to flush
* @return Zero on success, or non-zero if an error occurs during flush.
*/
ssize_t guac_flush(GUACIO* io);
/**
* Waits for input to be available on the given GUACIO object until the
* specified timeout elapses.
*
* @param io The GUACIO 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_select(GUACIO* io, int usec_timeout);
/**
* Frees resources allocated to the given GUACIO object. Note that this
* implicitly flush all buffers, but will NOT close the associated file
* descriptor.
*
* @param io The GUACIO object to close.
*/
void guac_close(GUACIO* io);
#endif

View File

@@ -0,0 +1,203 @@
/*
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __PROTOCOL_H
#define __PROTOCOL_H
#include <png.h>
#include "guacio.h"
/**
* Provides functions and structures required for communicating using the
* Guacamole protocol over a GUACIO connection, such as that provided by
* guac_client objects.
*
* @file protocol.h
*/
/**
* Represents a single instruction within the Guacamole protocol.
*/
typedef struct guac_instruction {
/**
* The opcode of the instruction.
*/
char* opcode;
/**
* The number of arguments passed to this instruction.
*/
int argc;
/**
* Array of all arguments passed to this instruction. Strings
* are not already unescaped.
*/
char** argv;
} guac_instruction;
/**
* Frees all memory allocated to the given instruction opcode
* and arguments. The instruction structure itself will not
* be freed.
*
* @param instruction The instruction to free.
*/
void guac_free_instruction_data(guac_instruction* instruction);
/**
* Frees all memory allocated to the given instruction. This
* includes freeing memory allocated for the structure
* itself.
*
* @param instruction The instruction to free.
*/
void guac_free_instruction(guac_instruction* instruction);
/**
* Escapes the given string as necessary to be passed within
* a Guacamole instruction. The returned string must later be
* released with a call to free().
*
* @param str The string to escape.
* @return A new escaped string, which must be freed with free().
*/
char* guac_escape_string(const char* str);
/**
* Unescapes the given string in-place, as an unescaped string
* is always the same length or shorter than the original.
*
* @param str The string to unescape.
* @return A pointer to the original string, which is now unescaped.
*/
char* guac_unescape_string_inplace(char* str);
/**
* Sends a name instruction over the given GUACIO connection. The
* name given will be automatically escaped for transmission.
*
* @param io The GUACIO connection to use.
* @param name The name to send within the name instruction.
*/
void guac_send_name(GUACIO* io, const char* name);
/**
* Sends an error instruction over the given GUACIO connection. The
* error description given will be automatically escaped for
* transmission.
*
* @param io The GUACIO connection to use.
* @param error The description associated with the error.
*/
void guac_send_error(GUACIO* io, const char* error);
/**
* Sends a clipboard instruction over the given GUACIO connection. The
* clipboard data given will be automatically escaped for transmission.
*
* @param io The GUACIO connection to use.
* @param data The clipboard data to send.
*/
void guac_send_clipboard(GUACIO* io, const char* data);
/**
* Sends a size instruction over the given GUACIO connection.
*
* @param io The GUACIO connection to use.
* @param w The width of the display.
* @param h The height of the display.
*/
void guac_send_size(GUACIO* io, int w, int h);
/**
* Sends a copy instruction over the given GUACIO connection.
*
* @param io The GUACIO connection to use.
* @param srcx The X coordinate of the source rectangle.
* @param srcy The Y coordinate of the source rectangle.
* @param w The width of the source rectangle.
* @param h The height of the source rectangle.
* @param dstx The X coordinate of the destination, where the source rectangle
* should be copied.
* @param dsty The Y coordinate of the destination, where the source rectangle
* should be copied.
*/
void guac_send_copy(GUACIO* io, int srcx, int srcy, int w, int h, int dstx, int dsty);
/**
* Sends a png instruction over the given GUACIO connection. The PNG image data
* given will be automatically base64-encoded for transmission.
*
* @param io The GUACIO connection to use.
* @param x The destination X coordinate.
* @param y The destination Y coordinate.
* @param png_rows A libpng-compatible PNG image buffer containing the image
* data to send.
* @param w The width of the image in the image buffer.
* @param h The height of the image in the image buffer.
*/
void guac_send_png(GUACIO* io, int x, int y, png_byte** png_rows, int w, int h);
/**
* Sends a cursor instruction over the given GUACIO connection. The PNG image
* data given will be automatically base64-encoded for transmission.
*
* @param io The GUACIO connection to use.
* @param x The destination X coordinate.
* @param y The destination Y coordinate.
* @param png_rows A libpng-compatible PNG image buffer containing the image
* data to send.
* @param w The width of the image in the image buffer.
* @param h The height of the image in the image buffer.
*/
void guac_send_cursor(GUACIO* io, int x, int y, png_byte** png_rows, int w, int h);
/**
* Returns whether new instruction data is available on the given GUACIO
* connection for parsing.
*
* @param io The GUACIO connection to use.
* @return A positive value if data is available, negative on error, or
* zero if no data is currently available.
*/
int guac_instructions_waiting(GUACIO* io);
/**
* Reads a single instruction from the given GUACIO connection.
*
* @param io The GUACIO connection to use.
* @param parsed_instruction A pointer to a guac_instruction structure which
* will be populated with data read from the given
* GUACIO connection.
* @return A positive value if data was successfully read, negative on
* error, or zero if the instrucion could not be read completely,
* in which case, subsequent calls to guac_read_instruction() will
* return the parsed instruction once enough data is available.
*/
int guac_read_instruction(GUACIO* io, guac_instruction* parsed_instruction);
#endif