cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

protocol.h (40363B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20#ifndef _GUAC_PROTOCOL_H
     21#define _GUAC_PROTOCOL_H
     22
     23/**
     24 * Provides functions and structures required for communicating using the
     25 * Guacamole protocol over a guac_socket connection, such as that provided by
     26 * guac_client objects.
     27 *
     28 * @file protocol.h
     29 */
     30
     31#include "layer-types.h"
     32#include "object-types.h"
     33#include "protocol-constants.h"
     34#include "protocol-types.h"
     35#include "socket-types.h"
     36#include "stream-types.h"
     37#include "timestamp-types.h"
     38
     39#include <cairo/cairo.h>
     40#include <stdarg.h>
     41
     42/* CONTROL INSTRUCTIONS */
     43
     44/**
     45 * Sends an ack instruction over the given guac_socket connection.
     46 *
     47 * If an error occurs sending the instruction, a non-zero value is
     48 * returned, and guac_error is set appropriately.
     49 *
     50 * @param socket The guac_socket connection to use.
     51 * @param stream The guac_stream associated with the operation this ack is
     52 *               acknowledging.
     53 * @param error The human-readable description associated with the error or
     54 *              status update.
     55 * @param status The status code related to the error or status.
     56 * @return Zero on success, non-zero on error.
     57 */
     58int guac_protocol_send_ack(guac_socket* socket, guac_stream* stream,
     59        const char* error, guac_protocol_status status);
     60
     61/**
     62 * Sends an args instruction over the given guac_socket connection.
     63 *
     64 * If an error occurs sending the instruction, a non-zero value is
     65 * returned, and guac_error is set appropriately.
     66 *
     67 * @param socket The guac_socket connection to use.
     68 * @param args The NULL-terminated array of argument names (strings).
     69 * @return Zero on success, non-zero on error.
     70 */
     71int guac_protocol_send_args(guac_socket* socket, const char** args);
     72
     73/**
     74 * Sends a connect instruction over the given guac_socket connection.
     75 *
     76 * If an error occurs sending the instruction, a non-zero value is
     77 * returned, and guac_error is set appropriately.
     78 *
     79 * @param socket The guac_socket connection to use.
     80 * @param args The NULL-terminated array of argument values (strings).
     81 * @return Zero on success, non-zero on error.
     82 */
     83int guac_protocol_send_connect(guac_socket* socket, const char** args);
     84
     85/**
     86 * Sends a disconnect instruction over the given guac_socket connection.
     87 *
     88 * If an error occurs sending the instruction, a non-zero value is
     89 * returned, and guac_error is set appropriately.
     90 *
     91 * @param socket The guac_socket connection to use.
     92 * @return Zero on success, non-zero on error.
     93 */
     94int guac_protocol_send_disconnect(guac_socket* socket);
     95
     96/**
     97 * Sends an error instruction over the given guac_socket connection.
     98 *
     99 * If an error occurs sending the instruction, a non-zero value is
    100 * returned, and guac_error is set appropriately.
    101 *
    102 * @param socket The guac_socket connection to use.
    103 * @param error The human-readable description associated with the error.
    104 * @param status The status code related to the error.
    105 * @return Zero on success, non-zero on error.
    106 */
    107int guac_protocol_send_error(guac_socket* socket, const char* error,
    108        guac_protocol_status status);
    109
    110/**
    111 * Sends a key instruction over the given guac_socket connection.
    112 *
    113 * If an error occurs sending the instruction, a non-zero value is
    114 * returned, and guac_error is set appropriately.
    115 *
    116 * @param socket
    117 *     The guac_socket connection to use.
    118 *
    119 * @param keysym
    120 *     The X11 keysym of the key that was pressed or released.
    121 *
    122 * @param pressed
    123 *     Non-zero if the key represented by the given keysym is currently
    124 *     pressed, zero if it is released.
    125 *
    126 * @param timestamp
    127 *     The server timestamp (in milliseconds) at the point in time this key
    128 *     event was acknowledged.
    129 *
    130 * @return
    131 *     Zero on success, non-zero on error.
    132 */
    133int guac_protocol_send_key(guac_socket* socket, int keysym, int pressed,
    134        guac_timestamp timestamp);
    135
    136/**
    137 * Sends a log instruction over the given guac_socket connection. This is
    138 * mainly useful in debugging.
    139 *
    140 * If an error occurs sending the instruction, a non-zero value is
    141 * returned, and guac_error is set appropriately.
    142 *
    143 * @param socket The guac_socket connection to use.
    144 * @param format A printf-style format string to log.
    145 * @param ... Arguments to use when filling the format string for printing.
    146 * @return Zero on success, non-zero on error.
    147 */
    148int guac_protocol_send_log(guac_socket* socket, const char* format, ...);
    149
    150/**
    151 * Sends a log instruction over the given guac_socket connection. This is
    152 * mainly useful in debugging.
    153 *
    154 * If an error occurs sending the instruction, a non-zero value is
    155 * returned, and guac_error is set appropriately.
    156 *
    157 * @param socket
    158 *     The guac_socket connection to use.
    159 *
    160 * @param format
    161 *     A printf-style format string to log.
    162 *
    163 * @param args
    164 *     The va_list containing the arguments to be used when filling the
    165 *     format string for printing.
    166 *
    167 * @return
    168 *     Zero if the instruction was sent successfully, non-zero if an error
    169 *     occurs.
    170 */
    171int vguac_protocol_send_log(guac_socket* socket, const char* format,
    172        va_list args);
    173
    174/**
    175 * Sends the given string over the socket to be displayed on the client. Returns
    176 * zero if the message was sent successfully or non-zero if an error occurs.
    177 *
    178 * @param socket
    179 *     The guac_socket connection to send the message to.
    180 *
    181 * @param msg
    182 *     The message code to send to the client.
    183 *
    184 * @param args
    185 *     A null-terminated array of strings that will be provided to the client
    186 *     as part of the message, that the client may then place in the message,
    187 *     or null if the message requires no arguments.
    188 *
    189 * @return
    190 *     Zero if the message is sent successfully; otherwise non-zero.
    191 */
    192int guac_protocol_send_msg(guac_socket* socket, guac_message_type msg,
    193        const char** args);
    194
    195/**
    196 * Sends a mouse instruction over the given guac_socket connection.
    197 *
    198 * If an error occurs sending the instruction, a non-zero value is
    199 * returned, and guac_error is set appropriately.
    200 *
    201 * @param socket
    202 *     The guac_socket connection to use.
    203 *
    204 * @param x
    205 *     The X coordinate of the current mouse position.
    206 *
    207 * @param y
    208 *     The Y coordinate of the current mouse position.
    209 *
    210 * @param button_mask
    211 *     An integer value representing the current state of each button, where
    212 *     the Nth bit within the integer is set to 1 if and only if the Nth mouse
    213 *     button is currently pressed. The lowest-order bit is the left mouse
    214 *     button, followed by the middle button, right button, and finally the up
    215 *     and down buttons of the scroll wheel.
    216 *
    217 *     @see GUAC_CLIENT_MOUSE_LEFT
    218 *     @see GUAC_CLIENT_MOUSE_MIDDLE
    219 *     @see GUAC_CLIENT_MOUSE_RIGHT
    220 *     @see GUAC_CLIENT_MOUSE_SCROLL_UP
    221 *     @see GUAC_CLIENT_MOUSE_SCROLL_DOWN
    222 *
    223 * @param timestamp
    224 *     The server timestamp (in milliseconds) at the point in time this mouse
    225 *     position was acknowledged.
    226 *
    227 * @return
    228 *     Zero on success, non-zero on error.
    229 */
    230int guac_protocol_send_mouse(guac_socket* socket, int x, int y,
    231        int button_mask, guac_timestamp timestamp);
    232
    233/**
    234 * Sends a touch instruction over the given guac_socket connection.
    235 *
    236 * If an error occurs sending the instruction, a non-zero value is
    237 * returned, and guac_error is set appropriately.
    238 *
    239 * @param socket
    240 *     The guac_socket connection to use.
    241 *
    242 * @param id
    243 *     An arbitrary integer ID which uniquely identifies this contact relative
    244 *     to other active contacts.
    245 *
    246 * @param x
    247 *     The X coordinate of the center of the touch contact.
    248 *
    249 * @param y
    250 *     The Y coordinate of the center of the touch contact.
    251 *
    252 * @param x_radius
    253 *     The X radius of the ellipse covering the general area of the touch
    254 *     contact, in pixels.
    255 *
    256 * @param y_radius
    257 *     The Y radius of the ellipse covering the general area of the touch
    258 *     contact, in pixels.
    259 *
    260 * @param angle
    261 *     The rough angle of clockwise rotation of the general area of the touch
    262 *     contact, in degrees.
    263 *
    264 * @param force
    265 *     The relative force exerted by the touch contact, where 0 is no force
    266 *     (the touch has been lifted) and 1 is maximum force (the maximum amount
    267 *     of force representable by the device).
    268 *
    269 * @param timestamp
    270 *     The server timestamp (in milliseconds) at the point in time this touch
    271 *     event was acknowledged.
    272 *
    273 * @return
    274 *     Zero on success, non-zero on error.
    275 */
    276int guac_protocol_send_touch(guac_socket* socket, int id, int x, int y,
    277        int x_radius, int y_radius, double angle, double force,
    278        guac_timestamp timestamp);
    279
    280/**
    281 * Sends a nest instruction over the given guac_socket connection.
    282 *
    283 * If an error occurs sending the instruction, a non-zero value is
    284 * returned, and guac_error is set appropriately.
    285 *
    286 * @deprecated
    287 *     The "nest" instruction and the corresponding guac_socket
    288 *     implementation are no longer necessary, having been replaced by
    289 *     the streaming instructions ("blob", "ack", "end"). Code using nested
    290 *     sockets or the "nest" instruction should instead write to a normal
    291 *     socket directly.
    292 *
    293 * @param socket The guac_socket connection to use.
    294 * @param index The integer index of the stram to send the protocol
    295 *              data over.
    296 * @param data A string containing protocol data, which must be UTF-8
    297 *             encoded and null-terminated.
    298 * @return Zero on success, non-zero on error.
    299 */
    300int guac_protocol_send_nest(guac_socket* socket, int index,
    301        const char* data);
    302
    303/**
    304 * Sends a nop instruction (null-operation) over the given guac_socket
    305 * connection.
    306 *
    307 * If an error occurs sending the instruction, a non-zero value is
    308 * returned, and guac_error is set appropriately.
    309 *
    310 * @param socket The guac_socket connection to use.
    311 * @return Zero on success, non-zero on error.
    312 */
    313int guac_protocol_send_nop(guac_socket* socket);
    314
    315/**
    316 * Sends a ready instruction over the given guac_socket connection.
    317 *
    318 * If an error occurs sending the instruction, a non-zero value is
    319 * returned, and guac_error is set appropriately.
    320 *
    321 * @param socket The guac_socket connection to use.
    322 * @param id The connection ID of the connection that is ready.
    323 * @return Zero on success, non-zero on error.
    324 */
    325int guac_protocol_send_ready(guac_socket* socket, const char* id);
    326
    327/**
    328 * Sends a set instruction over the given guac_socket connection.
    329 *
    330 * If an error occurs sending the instruction, a non-zero value is
    331 * returned, and guac_error is set appropriately.
    332 *
    333 * @param socket The guac_socket connection to use.
    334 * @param layer The layer to set the parameter of.
    335 * @param name The name of the parameter to set.
    336 * @param value The value to set the parameter to.
    337 * @return Zero on success, non-zero on error.
    338 */
    339int guac_protocol_send_set(guac_socket* socket, const guac_layer* layer,
    340        const char* name, const char* value);
    341
    342/**
    343 * Sends a set instruction over the given guac_socket connection. This function
    344 * behavies identically to guac_protocol_send_set() except that the provided
    345 * parameter value is an integer, rather than a string.
    346 *
    347 * If an error occurs sending the instruction, a non-zero value is
    348 * returned, and guac_error is set appropriately.
    349 *
    350 * @param socket
    351 *     The guac_socket connection to use.
    352 *
    353 * @param layer
    354 *     The layer to set the parameter of.
    355 *
    356 * @param name
    357 *     The name of the parameter to set.
    358 *
    359 * @param value
    360 *     The value to set the parameter to.
    361 *
    362 * @return
    363 *     Zero on success, non-zero on error.
    364 */
    365int guac_protocol_send_set_int(guac_socket* socket, const guac_layer* layer,
    366        const char* name, int value);
    367
    368/**
    369 * Sends a select instruction over the given guac_socket connection.
    370 *
    371 * If an error occurs sending the instruction, a non-zero value is
    372 * returned, and guac_error is set appropriately.
    373 *
    374 * @param socket The guac_socket connection to use.
    375 * @param protocol The protocol to request.
    376 * @return Zero on success, non-zero on error.
    377 */
    378int guac_protocol_send_select(guac_socket* socket, const char* protocol);
    379
    380/**
    381 * Sends a sync instruction over the given guac_socket connection. The
    382 * current time in milliseconds should be passed in as the timestamp.
    383 *
    384 * If an error occurs sending the instruction, a non-zero value is
    385 * returned, and guac_error is set appropriately.
    386 *
    387 * @param socket The guac_socket connection to use.
    388 * @param timestamp The current timestamp (in milliseconds).
    389 * @return Zero on success, non-zero on error.
    390 */
    391int guac_protocol_send_sync(guac_socket* socket, guac_timestamp timestamp);
    392
    393/* OBJECT INSTRUCTIONS */
    394
    395/**
    396 * Sends a body instruction over the given guac_socket connection.
    397 *
    398 * If an error occurs sending the instruction, a non-zero value is
    399 * returned, and guac_error is set appropriately.
    400 *
    401 * @param socket
    402 *     The guac_socket connection to use.
    403 *
    404 * @param object
    405 *     The object to associated with the stream being used.
    406 *
    407 * @param stream
    408 *     The stream to use.
    409 *
    410 * @param mimetype
    411 *     The mimetype of the data being sent.
    412 *
    413 * @param name
    414 *     The name of the stream whose body is being sent, as requested by a "get"
    415 *     instruction.
    416 *
    417 * @return
    418 *     Zero on success, non-zero on error.
    419 */
    420int guac_protocol_send_body(guac_socket* socket, const guac_object* object,
    421        const guac_stream* stream, const char* mimetype, const char* name);
    422
    423/**
    424 * Sends a filesystem instruction over the given guac_socket connection.
    425 *
    426 * If an error occurs sending the instruction, a non-zero value is
    427 * returned, and guac_error is set appropriately.
    428 *
    429 * @param socket
    430 *     The guac_socket connection to use.
    431 *
    432 * @param object
    433 *     The object representing the filesystem being exposed.
    434 *
    435 * @param name
    436 *     A name describing the filesystem being exposed.
    437 *
    438 * @return
    439 *     Zero on success, non-zero on error.
    440 */
    441int guac_protocol_send_filesystem(guac_socket* socket,
    442        const guac_object* object, const char* name);
    443
    444/**
    445 * Sends an undefine instruction over the given guac_socket connection.
    446 *
    447 * If an error occurs sending the instruction, a non-zero value is
    448 * returned, and guac_error is set appropriately.
    449 *
    450 * @param socket
    451 *     The guac_socket connection to use.
    452 *
    453 * @param object
    454 *     The object being undefined.
    455 *
    456 * @return
    457 *     Zero on success, non-zero on error.
    458 */
    459int guac_protocol_send_undefine(guac_socket* socket,
    460        const guac_object* object);
    461
    462/* MEDIA INSTRUCTIONS */
    463
    464/**
    465 * Sends an audio instruction over the given guac_socket connection.
    466 *
    467 * If an error occurs sending the instruction, a non-zero value is
    468 * returned, and guac_error is set appropriately.
    469 *
    470 * @param socket
    471 *     The guac_socket connection to use when sending the audio instruction.
    472 *
    473 * @param stream
    474 *     The stream to use for future audio data.
    475 *
    476 * @param mimetype
    477 *     The mimetype of the audio data which will be sent over the given stream.
    478 *
    479 * @return
    480 *     Zero on success, non-zero on error.
    481 */
    482int guac_protocol_send_audio(guac_socket* socket, const guac_stream* stream,
    483        const char* mimetype);
    484
    485/**
    486 * Sends a file instruction over the given guac_socket connection.
    487 *
    488 * If an error occurs sending the instruction, a non-zero value is
    489 * returned, and guac_error is set appropriately.
    490 *
    491 * @param socket The guac_socket connection to use.
    492 * @param stream The stream to use.
    493 * @param mimetype The mimetype of the data being sent.
    494 * @param name A name describing the file being sent.
    495 * @return Zero on success, non-zero on error.
    496 */
    497int guac_protocol_send_file(guac_socket* socket, const guac_stream* stream,
    498        const char* mimetype, const char* name);
    499
    500/**
    501 * Sends a pipe instruction over the given guac_socket connection.
    502 *
    503 * If an error occurs sending the instruction, a non-zero value is
    504 * returned, and guac_error is set appropriately.
    505 *
    506 * @param socket The guac_socket connection to use.
    507 * @param stream The stream to use.
    508 * @param mimetype The mimetype of the data being sent.
    509 * @param name An arbitrary name uniquely identifying this pipe.
    510 * @return Zero on success, non-zero on error.
    511 */
    512int guac_protocol_send_pipe(guac_socket* socket, const guac_stream* stream,
    513        const char* mimetype, const char* name);
    514
    515/**
    516 * Writes a block of data to the currently in-progress blob which was already
    517 * created.
    518 *
    519 * If an error occurs sending the instruction, a non-zero value is
    520 * returned, and guac_error is set appropriately.
    521 *
    522 * @param socket The guac_socket connection to use.
    523 * @param stream The stream to use.
    524 * @param data The file data to write.
    525 * @param count The number of bytes within the given buffer of file data
    526 *              that must be written.
    527 * @return Zero on success, non-zero on error.
    528 */
    529int guac_protocol_send_blob(guac_socket* socket, const guac_stream* stream,
    530        const void* data, int count);
    531
    532/**
    533 * Sends a series of blob instructions, splitting the given data across the
    534 * number of instructions required to ensure the size of each blob does not
    535 * exceed GUAC_PROTOCOL_BLOB_MAX_LENGTH. If the size of data provided is zero,
    536 * no blob instructions are sent.
    537 *
    538 * If an error occurs sending any blob instruction, a non-zero value is
    539 * returned, guac_error is set appropriately, and no further blobs are sent.
    540 *
    541 * @see GUAC_PROTOCOL_BLOB_MAX_LENGTH
    542 *
    543 * @param socket
    544 *     The guac_socket connection to use to send the blob instructions.
    545 *
    546 * @param stream
    547 *     The stream to associate with each blob sent.
    548 *
    549 * @param data
    550 *     The data which should be sent using the required number of blob
    551 *     instructions.
    552 *
    553 * @param count
    554 *     The number of bytes within the given buffer of data that must be
    555 *     written.
    556 *
    557 * @return
    558 *     Zero on success, non-zero on error.
    559 */
    560int guac_protocol_send_blobs(guac_socket* socket, const guac_stream* stream,
    561        const void* data, int count);
    562
    563/**
    564 * Sends an end instruction over the given guac_socket connection.
    565 *
    566 * If an error occurs sending the instruction, a non-zero value is
    567 * returned, and guac_error is set appropriately.
    568 *
    569 * @param socket The guac_socket connection to use.
    570 * @param stream The stream to use.
    571 * @return Zero on success, non-zero on error.
    572 */
    573int guac_protocol_send_end(guac_socket* socket, const guac_stream* stream);
    574
    575/**
    576 * Sends a video instruction over the given guac_socket connection.
    577 *
    578 * If an error occurs sending the instruction, a non-zero value is
    579 * returned, and guac_error is set appropriately.
    580 *
    581 * @param socket
    582 *     The guac_socket connection to use when sending the video instruction.
    583 *
    584 * @param stream
    585 *     The stream to use for future video data.
    586 *
    587 * @param layer
    588 *     The destination layer on which the streamed video should be played.
    589 *
    590 * @param mimetype
    591 *     The mimetype of the video data which will be sent over the given stream.
    592 *
    593 * @return
    594 *     Zero on success, non-zero on error.
    595 */
    596int guac_protocol_send_video(guac_socket* socket, const guac_stream* stream,
    597        const guac_layer* layer, const char* mimetype);
    598
    599/* DRAWING INSTRUCTIONS */
    600
    601/**
    602 * Sends an arc instruction over the given guac_socket connection.
    603 *
    604 * If an error occurs sending the instruction, a non-zero value is
    605 * returned, and guac_error is set appropriately.
    606 *
    607 * @param socket The guac_socket connection to use.
    608 * @param layer The destination layer.
    609 * @param x The X coordinate of the center of the circle containing the arc.
    610 * @param y The Y coordinate of the center of the circle containing the arc. 
    611 * @param radius The radius of the circle containing the arc.
    612 * @param startAngle The starting angle, in radians.
    613 * @param endAngle The ending angle, in radians.
    614 * @param negative Zero if the arc should be drawn in order of increasing
    615 *                 angle, non-zero otherwise.
    616 * @return Zero on success, non-zero on error.
    617 */
    618int guac_protocol_send_arc(guac_socket* socket, const guac_layer* layer,
    619        int x, int y, int radius, double startAngle, double endAngle,
    620        int negative);
    621
    622/**
    623 * Sends a cfill instruction over the given guac_socket connection.
    624 *
    625 * If an error occurs sending the instruction, a non-zero value is
    626 * returned, and guac_error is set appropriately.
    627 *
    628 * @param socket The guac_socket connection to use.
    629 * @param mode The composite mode to use.
    630 * @param layer The destination layer.
    631 * @param r The red component of the color of the rectangle.
    632 * @param g The green component of the color of the rectangle.
    633 * @param b The blue component of the color of the rectangle.
    634 * @param a The alpha (transparency) component of the color of the rectangle.
    635 * @return Zero on success, non-zero on error.
    636 */
    637int guac_protocol_send_cfill(guac_socket* socket,
    638        guac_composite_mode mode, const guac_layer* layer,
    639        int r, int g, int b, int a);
    640
    641/**
    642 * Sends a clip instruction over the given guac_socket connection.
    643 *
    644 * If an error occurs sending the instruction, a non-zero value is
    645 * returned, and guac_error is set appropriately.
    646 *
    647 * @param socket The guac_socket connection to use.
    648 * @param layer The layer to set the clipping region of.
    649 * @return Zero on success, non-zero on error.
    650 */
    651int guac_protocol_send_clip(guac_socket* socket, const guac_layer* layer);
    652
    653/**
    654 * Sends a close instruction over the given guac_socket connection.
    655 *
    656 * If an error occurs sending the instruction, a non-zero value is
    657 * returned, and guac_error is set appropriately.
    658 *
    659 * @param socket The guac_socket connection to use.
    660 * @param layer The destination layer.
    661 * @return Zero on success, non-zero on error.
    662 */
    663int guac_protocol_send_close(guac_socket* socket, const guac_layer* layer);
    664
    665/**
    666 * Sends a copy instruction over the given guac_socket connection.
    667 *
    668 * If an error occurs sending the instruction, a non-zero value is
    669 * returned, and guac_error is set appropriately.
    670 *
    671 * @param socket The guac_socket connection to use.
    672 * @param srcl The source layer.
    673 * @param srcx The X coordinate of the source rectangle.
    674 * @param srcy The Y coordinate of the source rectangle.
    675 * @param w The width of the source rectangle.
    676 * @param h The height of the source rectangle.
    677 * @param mode The composite mode to use.
    678 * @param dstl The destination layer.
    679 * @param dstx The X coordinate of the destination, where the source rectangle
    680 *             should be copied.
    681 * @param dsty The Y coordinate of the destination, where the source rectangle
    682 *             should be copied.
    683 * @return Zero on success, non-zero on error.
    684 */
    685int guac_protocol_send_copy(guac_socket* socket, 
    686        const guac_layer* srcl, int srcx, int srcy, int w, int h,
    687        guac_composite_mode mode, const guac_layer* dstl, int dstx, int dsty);
    688
    689/**
    690 * Sends a cstroke instruction over the given guac_socket connection.
    691 *
    692 * If an error occurs sending the instruction, a non-zero value is
    693 * returned, and guac_error is set appropriately.
    694 *
    695 * @param socket The guac_socket connection to use.
    696 * @param mode The composite mode to use.
    697 * @param layer The destination layer.
    698 * @param cap The style of line cap to use when drawing the stroke.
    699 * @param join The style of line join to use when drawing the stroke.
    700 * @param thickness The thickness of the stroke in pixels.
    701 * @param r The red component of the color of the rectangle.
    702 * @param g The green component of the color of the rectangle.
    703 * @param b The blue component of the color of the rectangle.
    704 * @param a The alpha (transparency) component of the color of the rectangle.
    705 * @return Zero on success, non-zero on error.
    706 */
    707int guac_protocol_send_cstroke(guac_socket* socket,
    708        guac_composite_mode mode, const guac_layer* layer,
    709        guac_line_cap_style cap, guac_line_join_style join, int thickness,
    710        int r, int g, int b, int a);
    711
    712/**
    713 * Sends a cursor instruction over the given guac_socket connection.
    714 *
    715 * If an error occurs sending the instruction, a non-zero value is
    716 * returned, and guac_error is set appropriately.
    717 *
    718 * @param socket The guac_socket connection to use.
    719 * @param x The X coordinate of the cursor hotspot.
    720 * @param y The Y coordinate of the cursor hotspot.
    721 * @param srcl The source layer.
    722 * @param srcx The X coordinate of the source rectangle.
    723 * @param srcy The Y coordinate of the source rectangle.
    724 * @param w The width of the source rectangle.
    725 * @param h The height of the source rectangle.
    726 * @return Zero on success, non-zero on error.
    727 */
    728int guac_protocol_send_cursor(guac_socket* socket, int x, int y,
    729        const guac_layer* srcl, int srcx, int srcy, int w, int h);
    730
    731/**
    732 * Sends a curve instruction over the given guac_socket connection.
    733 *
    734 * If an error occurs sending the instruction, a non-zero value is
    735 * returned, and guac_error is set appropriately.
    736 *
    737 * @param socket The guac_socket connection to use.
    738 * @param layer The destination layer.
    739 * @param cp1x The X coordinate of the first control point.
    740 * @param cp1y The Y coordinate of the first control point.
    741 * @param cp2x The X coordinate of the second control point.
    742 * @param cp2y The Y coordinate of the second control point.
    743 * @param x The X coordinate of the endpoint of the curve.
    744 * @param y The Y coordinate of the endpoint of the curve.
    745 * @return Zero on success, non-zero on error.
    746 */
    747int guac_protocol_send_curve(guac_socket* socket, const guac_layer* layer,
    748        int cp1x, int cp1y, int cp2x, int cp2y, int x, int y);
    749
    750/**
    751 * Sends an identity instruction over the given guac_socket connection.
    752 *
    753 * If an error occurs sending the instruction, a non-zero value is
    754 * returned, and guac_error is set appropriately.
    755 *
    756 * @param socket The guac_socket connection to use.
    757 * @param layer The destination layer.
    758 * @return Zero on success, non-zero on error.
    759 */
    760int guac_protocol_send_identity(guac_socket* socket, const guac_layer* layer);
    761
    762/**
    763 * Sends an lfill instruction over the given guac_socket connection.
    764 *
    765 * If an error occurs sending the instruction, a non-zero value is
    766 * returned, and guac_error is set appropriately.
    767 *
    768 * @param socket The guac_socket connection to use.
    769 * @param mode The composite mode to use.
    770 * @param layer The destination layer.
    771 * @param srcl The source layer.
    772 * @return Zero on success, non-zero on error.
    773 */
    774int guac_protocol_send_lfill(guac_socket* socket,
    775        guac_composite_mode mode, const guac_layer* layer,
    776        const guac_layer* srcl);
    777
    778/**
    779 * Sends a line instruction over the given guac_socket connection.
    780 *
    781 * If an error occurs sending the instruction, a non-zero value is
    782 * returned, and guac_error is set appropriately.
    783 *
    784 * @param socket The guac_socket connection to use.
    785 * @param layer The destination layer.
    786 * @param x The X coordinate of the endpoint of the line.
    787 * @param y The Y coordinate of the endpoint of the line.
    788 * @return Zero on success, non-zero on error.
    789 */
    790int guac_protocol_send_line(guac_socket* socket, const guac_layer* layer,
    791        int x, int y);
    792
    793/**
    794 * Sends an lstroke instruction over the given guac_socket connection.
    795 *
    796 * If an error occurs sending the instruction, a non-zero value is
    797 * returned, and guac_error is set appropriately.
    798 *
    799 * @param socket The guac_socket connection to use.
    800 * @param mode The composite mode to use.
    801 * @param layer The destination layer.
    802 * @param cap The style of line cap to use when drawing the stroke.
    803 * @param join The style of line join to use when drawing the stroke.
    804 * @param thickness The thickness of the stroke in pixels.
    805 * @param srcl The source layer.
    806 * @return Zero on success, non-zero on error.
    807 */
    808int guac_protocol_send_lstroke(guac_socket* socket,
    809        guac_composite_mode mode, const guac_layer* layer,
    810        guac_line_cap_style cap, guac_line_join_style join, int thickness,
    811        const guac_layer* srcl);
    812
    813/**
    814 * Sends an img instruction over the given guac_socket connection.
    815 *
    816 * If an error occurs sending the instruction, a non-zero value is
    817 * returned, and guac_error is set appropriately.
    818 *
    819 * @param socket
    820 *     The guac_socket connection to use when sending the img instruction.
    821 *
    822 * @param stream
    823 *     The stream over which the image data will be sent.
    824 *
    825 * @param mode
    826 *     The composite mode to use when drawing the image over the destination
    827 *     layer.
    828 *
    829 * @param layer
    830 *     The destination layer.
    831 *
    832 * @param mimetype
    833 *     The mimetype of the image data being sent.
    834 *
    835 * @param x
    836 *     The X coordinate of the upper-left corner of the destination rectangle
    837 *     within the destination layer, in pixels.
    838 *
    839 * @param y
    840 *     The Y coordinate of the upper-left corner of the destination rectangle
    841 *     within the destination layer, in pixels.
    842 *
    843 * @return
    844 *     Zero if the instruction was successfully sent, non-zero on error.
    845 */
    846int guac_protocol_send_img(guac_socket* socket, const guac_stream* stream,
    847        guac_composite_mode mode, const guac_layer* layer,
    848        const char* mimetype, int x, int y);
    849
    850/**
    851 * Sends a pop instruction over the given guac_socket connection.
    852 *
    853 * If an error occurs sending the instruction, a non-zero value is
    854 * returned, and guac_error is set appropriately.
    855 *
    856 * @param socket The guac_socket connection to use.
    857 * @param layer The layer to set the clipping region of.
    858 * @return Zero on success, non-zero on error.
    859 */
    860int guac_protocol_send_pop(guac_socket* socket, const guac_layer* layer);
    861
    862/**
    863 * Sends a push instruction over the given guac_socket connection.
    864 *
    865 * If an error occurs sending the instruction, a non-zero value is
    866 * returned, and guac_error is set appropriately.
    867 *
    868 * @param socket The guac_socket connection to use.
    869 * @param layer The layer to set the clipping region of.
    870 * @return Zero on success, non-zero on error.
    871 */
    872int guac_protocol_send_push(guac_socket* socket, const guac_layer* layer);
    873
    874/**
    875 * Sends a rect instruction over the given guac_socket connection.
    876 *
    877 * If an error occurs sending the instruction, a non-zero value is
    878 * returned, and guac_error is set appropriately.
    879 *
    880 * @param socket The guac_socket connection to use.
    881 * @param layer The destination layer.
    882 * @param x The X coordinate of the rectangle.
    883 * @param y The Y coordinate of the rectangle.
    884 * @param width The width of the rectangle.
    885 * @param height The height of the rectangle.
    886 * @return Zero on success, non-zero on error.
    887 */
    888int guac_protocol_send_rect(guac_socket* socket, const guac_layer* layer,
    889        int x, int y, int width, int height);
    890
    891/**
    892 * Sends a "required" instruction over the given guac_socket connection.  This
    893 * instruction indicates to the client that one or more additional parameters
    894 * are needed to continue the connection.
    895 * 
    896 * @param socket
    897 *     The guac_socket connection to which to send the instruction.
    898 * 
    899 * @param required
    900 *     A NULL-terminated array of required parameters.
    901 * 
    902 * @return
    903 *     Zero on success, non-zero on error.
    904 */
    905int guac_protocol_send_required(guac_socket* socket, const char** required);
    906
    907/**
    908 * Sends a reset instruction over the given guac_socket connection.
    909 *
    910 * If an error occurs sending the instruction, a non-zero value is
    911 * returned, and guac_error is set appropriately.
    912 *
    913 * @param socket The guac_socket connection to use.
    914 * @param layer The layer to set the clipping region of.
    915 * @return Zero on success, non-zero on error.
    916 */
    917int guac_protocol_send_reset(guac_socket* socket, const guac_layer* layer);
    918
    919/**
    920 * Sends a start instruction over the given guac_socket connection.
    921 *
    922 * If an error occurs sending the instruction, a non-zero value is
    923 * returned, and guac_error is set appropriately.
    924 *
    925 * @param socket The guac_socket connection to use.
    926 * @param layer The destination layer.
    927 * @param x The X coordinate of the first point of the subpath.
    928 * @param y The Y coordinate of the first point of the subpath.
    929 * @return Zero on success, non-zero on error.
    930 */
    931int guac_protocol_send_start(guac_socket* socket, const guac_layer* layer,
    932        int x, int y);
    933
    934/**
    935 * Sends a transfer instruction over the given guac_socket connection.
    936 *
    937 * If an error occurs sending the instruction, a non-zero value is
    938 * returned, and guac_error is set appropriately.
    939 *
    940 * @param socket The guac_socket connection to use.
    941 * @param srcl The source layer.
    942 * @param srcx The X coordinate of the source rectangle.
    943 * @param srcy The Y coordinate of the source rectangle.
    944 * @param w The width of the source rectangle.
    945 * @param h The height of the source rectangle.
    946 * @param fn The transfer function to use.
    947 * @param dstl The destination layer.
    948 * @param dstx The X coordinate of the destination, where the source rectangle
    949 *             should be copied.
    950 * @param dsty The Y coordinate of the destination, where the source rectangle
    951 *             should be copied.
    952 * @return Zero on success, non-zero on error.
    953 */
    954int guac_protocol_send_transfer(guac_socket* socket, 
    955        const guac_layer* srcl, int srcx, int srcy, int w, int h,
    956        guac_transfer_function fn, const guac_layer* dstl, int dstx, int dsty);
    957
    958/**
    959 * Sends a transform instruction over the given guac_socket connection.
    960 *
    961 * If an error occurs sending the instruction, a non-zero value is
    962 * returned, and guac_error is set appropriately.
    963 *
    964 * @param socket The guac_socket connection to use.
    965 * @param layer The layer to apply the given transform matrix to.
    966 * @param a The first value of the affine transform matrix.
    967 * @param b The second value of the affine transform matrix.
    968 * @param c The third value of the affine transform matrix.
    969 * @param d The fourth value of the affine transform matrix.
    970 * @param e The fifth value of the affine transform matrix.
    971 * @param f The sixth value of the affine transform matrix.
    972 * @return Zero on success, non-zero on error.
    973 */
    974int guac_protocol_send_transform(guac_socket* socket, 
    975        const guac_layer* layer,
    976        double a, double b, double c,
    977        double d, double e, double f);
    978
    979/* LAYER INSTRUCTIONS */
    980
    981/**
    982 * Sends a dispose instruction over the given guac_socket connection.
    983 *
    984 * If an error occurs sending the instruction, a non-zero value is
    985 * returned, and guac_error is set appropriately.
    986 *
    987 * @param socket The guac_socket connection to use.
    988 * @param layer The layer to dispose.
    989 * @return Zero on success, non-zero on error.
    990 */
    991int guac_protocol_send_dispose(guac_socket* socket, const guac_layer* layer);
    992
    993/**
    994 * Sends a distort instruction over the given guac_socket connection.
    995 *
    996 * If an error occurs sending the instruction, a non-zero value is
    997 * returned, and guac_error is set appropriately.
    998 *
    999 * @param socket The guac_socket connection to use.
   1000 * @param layer The layer to distort with the given transform matrix.
   1001 * @param a The first value of the affine transform matrix.
   1002 * @param b The second value of the affine transform matrix.
   1003 * @param c The third value of the affine transform matrix.
   1004 * @param d The fourth value of the affine transform matrix.
   1005 * @param e The fifth value of the affine transform matrix.
   1006 * @param f The sixth value of the affine transform matrix.
   1007 * @return Zero on success, non-zero on error.
   1008 */
   1009int guac_protocol_send_distort(guac_socket* socket, 
   1010        const guac_layer* layer,
   1011        double a, double b, double c,
   1012        double d, double e, double f);
   1013
   1014/**
   1015 * Sends a move instruction over the given guac_socket connection.
   1016 *
   1017 * If an error occurs sending the instruction, a non-zero value is
   1018 * returned, and guac_error is set appropriately.
   1019 *
   1020 * @param socket The guac_socket connection to use.
   1021 * @param layer The layer to move.
   1022 * @param parent The parent layer the specified layer will be positioned
   1023 *               relative to.
   1024 * @param x The X coordinate of the layer.
   1025 * @param y The Y coordinate of the layer.
   1026 * @param z The Z index of the layer, relative to other layers in its parent.
   1027 * @return Zero on success, non-zero on error.
   1028 */
   1029int guac_protocol_send_move(guac_socket* socket, const guac_layer* layer,
   1030        const guac_layer* parent, int x, int y, int z);
   1031
   1032/**
   1033 * Sends a shade instruction over the given guac_socket connection.
   1034 *
   1035 * If an error occurs sending the instruction, a non-zero value is
   1036 * returned, and guac_error is set appropriately.
   1037 *
   1038 * @param socket The guac_socket connection to use.
   1039 * @param layer The layer to shade.
   1040 * @param a The alpha value of the layer.
   1041 * @return Zero on success, non-zero on error.
   1042 */
   1043int guac_protocol_send_shade(guac_socket* socket, const guac_layer* layer,
   1044        int a);
   1045
   1046/**
   1047 * Sends a size instruction over the given guac_socket connection.
   1048 *
   1049 * If an error occurs sending the instruction, a non-zero value is
   1050 * returned, and guac_error is set appropriately.
   1051 *
   1052 * @param socket The guac_socket connection to use.
   1053 * @param layer The layer to resize.
   1054 * @param w The new width of the layer.
   1055 * @param h The new height of the layer.
   1056 * @return Zero on success, non-zero on error.
   1057 */
   1058int guac_protocol_send_size(guac_socket* socket, const guac_layer* layer,
   1059        int w, int h);
   1060
   1061/* TEXT INSTRUCTIONS */
   1062
   1063/**
   1064 * Sends an argv instruction over the given guac_socket connection.
   1065 *
   1066 * If an error occurs sending the instruction, a non-zero value is
   1067 * returned, and guac_error is set appropriately.
   1068 *
   1069 * @param socket
   1070 *     The guac_socket connection to use to send the connection parameter
   1071 *     value.
   1072 *
   1073 * @param stream
   1074 *     The stream to use to send the connection parameter value.
   1075 *
   1076 * @param mimetype
   1077 *     The mimetype of the connection parameter value being sent.
   1078 *
   1079 * @param name
   1080 *     The name of the connection parameter whose current value is being sent.
   1081 *
   1082 * @return
   1083 *     Zero on success, non-zero on error.
   1084 */
   1085int guac_protocol_send_argv(guac_socket* socket, guac_stream* stream,
   1086        const char* mimetype, const char* name);
   1087
   1088/**
   1089 * Sends a clipboard instruction over the given guac_socket connection.
   1090 *
   1091 * If an error occurs sending the instruction, a non-zero value is
   1092 * returned, and guac_error is set appropriately.
   1093 *
   1094 * @param socket The guac_socket connection to use.
   1095 * @param stream The stream to use.
   1096 * @param mimetype The mimetype of the clipboard data being sent.
   1097 * @return Zero on success, non-zero on error.
   1098 */
   1099int guac_protocol_send_clipboard(guac_socket* socket, const guac_stream* stream,
   1100        const char* mimetype);
   1101
   1102/**
   1103 * Sends a name instruction over the given guac_socket connection.
   1104 *
   1105 * @param socket The guac_socket connection to use.
   1106 * @param name The name to send within the name instruction.
   1107 * @return Zero on success, non-zero on error.
   1108 */
   1109int guac_protocol_send_name(guac_socket* socket, const char* name);
   1110
   1111/**
   1112 * Decodes the given base64-encoded string in-place. The base64 string must
   1113 * be NULL-terminated.
   1114 *
   1115 * @param base64 The base64-encoded string to decode.
   1116 * @return The number of bytes resulting from the decode operation.
   1117 */
   1118int guac_protocol_decode_base64(char* base64);
   1119
   1120/**
   1121 * Given a string representation of a protocol version, return the enum value of
   1122 * that protocol version, or GUAC_PROTOCOL_VERSION_UNKNOWN if the value is not a
   1123 * known version.
   1124 * 
   1125 * @param version_string
   1126 *     The string representation of the protocol version.
   1127 * 
   1128 * @return 
   1129 *     The enum value of the protocol version, or GUAC_PROTOCOL_VERSION_UNKNOWN
   1130 *     if the provided version is not known.
   1131 */
   1132guac_protocol_version guac_protocol_string_to_version(const char* version_string);
   1133
   1134/**
   1135 * Given the enum value of the protocol version, return a pointer to the string
   1136 * representation of the version, or NULL if the version is unknown.
   1137 * 
   1138 * @param version
   1139 *     The enum value of the protocol version.
   1140 * 
   1141 * @return 
   1142 *     A pointer to the string representation of the protocol version, or NULL
   1143 *     if the version is unknown.
   1144 */
   1145const char* guac_protocol_version_to_string(guac_protocol_version version);
   1146
   1147#endif
   1148