Implementations of server-side streaming instructions.

This commit is contained in:
Michael Jumper 2012-08-27 14:07:02 -07:00
parent 5f1b67fb02
commit af490aafbe
2 changed files with 65 additions and 1 deletions

View File

@ -348,10 +348,12 @@ int guac_protocol_send_connect(guac_socket* socket, const char** args);
* @param socket The guac_socket connection to use. * @param socket The guac_socket connection to use.
* @param resource The resource associated with the data being sent. * @param resource The resource associated with the data being sent.
* @param data The data to send. * @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. * @return Zero on success, non-zero on error.
*/ */
int guac_protocol_send_data(guac_socket* socket, guac_resource* resource, 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. * Sends a disconnect instruction over the given guac_socket connection.

View File

@ -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) { int guac_protocol_send_disconnect(guac_socket* socket) {
return guac_socket_write_string(socket, "10.disconnect;"); 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) { int guac_protocol_send_error(guac_socket* socket, const char* error) {
return 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, int guac_protocol_send_set(guac_socket* socket, const guac_layer* layer,
const char* name, const char* value) { const char* name, const char* value) {