diff --git a/libguac/include/protocol.h b/libguac/include/protocol.h index c4722b75..3ad1dc63 100644 --- a/libguac/include/protocol.h +++ b/libguac/include/protocol.h @@ -348,10 +348,12 @@ int guac_protocol_send_connect(guac_socket* socket, const char** args); * @param socket The guac_socket connection to use. * @param resource The resource associated with the data being sent. * @param data The data to send. + * @param size The number of bytes from the beginning of the given buffer + * of data to send. * @return Zero on success, non-zero on error. */ int guac_protocol_send_data(guac_socket* socket, guac_resource* resource, - const unsigned char* data); + const unsigned char* data, size_t size); /** * Sends a disconnect instruction over the given guac_socket connection. diff --git a/libguac/src/protocol.c b/libguac/src/protocol.c index ec72be25..3eddce77 100644 --- a/libguac/src/protocol.c +++ b/libguac/src/protocol.c @@ -905,6 +905,26 @@ int guac_protocol_send_curve(guac_socket* socket, const guac_layer* layer, } +int guac_protocol_send_data(guac_socket* socket, guac_resource* resource, + const unsigned char* data, size_t size) { + + /* Calculate base64 length */ + int base64_length = (size + 2) / 3 * 4; + + /* Send base64-encoded data */ + return + guac_socket_write_string(socket, "4.data,") + || __guac_socket_write_length_int(socket, resource->index) + || guac_socket_write_string(socket, ",") + || guac_socket_write_int(socket, base64_length) + || guac_socket_write_string(socket, ".") + || guac_socket_write_base64(socket, data, size) + || guac_socket_flush_base64(socket) + || guac_socket_write_string(socket, ";"); + +} + + int guac_protocol_send_disconnect(guac_socket* socket) { return guac_socket_write_string(socket, "10.disconnect;"); } @@ -944,6 +964,15 @@ int guac_protocol_send_distort(guac_socket* socket, const guac_layer* layer, } +int guac_protocol_send_end(guac_socket* socket, guac_resource* resource) { + + return + guac_socket_write_string(socket, "3.end,") + || __guac_socket_write_length_int(socket, resource->index) + || guac_socket_write_string(socket, ";"); +} + + int guac_protocol_send_error(guac_socket* socket, const char* error) { return @@ -1114,6 +1143,39 @@ int guac_protocol_send_reset(guac_socket* socket, const guac_layer* layer) { } +int guac_protocol_send_resource(guac_socket* socket, guac_resource* resource, + const char* uri, const char** mimetypes) { + + /* Write resource header */ + if ( + guac_socket_write_string(socket, "8.resource,") + || __guac_socket_write_length_int(socket, resource->index) + || guac_socket_write_string(socket, ",") + || __guac_socket_write_length_string(socket, uri) + ) + return -1; + + /* Write each mimetype */ + while (*mimetypes != NULL) { + + /* Write mimetype */ + if ( + guac_socket_write_string(socket, ",") + || __guac_socket_write_length_string(socket, *mimetypes) + ) + return -1; + + /* Next mimetype */ + mimetypes++; + + } + + /* Finish instruction */ + return guac_socket_write_string(socket, ";"); + +} + + int guac_protocol_send_set(guac_socket* socket, const guac_layer* layer, const char* name, const char* value) {