2010-12-08 21:14:04 +00:00
|
|
|
|
2011-02-16 02:04:36 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2010-12-08 21:14:04 +00:00
|
|
|
*
|
2011-02-16 02:04:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2010-12-08 21:14:04 +00:00
|
|
|
*
|
2011-02-16 02:04:36 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2010-12-08 21:14:04 +00:00
|
|
|
*
|
2011-02-16 02:04:36 +00:00
|
|
|
* The Original Code is libguac.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Michael Jumper.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-03-27 23:32:49 +00:00
|
|
|
#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_NANOSLEEP)
|
2011-03-18 04:16:29 +00:00
|
|
|
#include <time.h>
|
2011-03-27 23:32:49 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_CLOCK_GETTIME
|
2011-03-18 04:16:29 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
2010-12-08 21:14:04 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2011-09-10 06:59:07 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <inttypes.h>
|
2010-12-08 21:14:04 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2012-04-02 02:25:33 +00:00
|
|
|
#ifdef HAVE_PNGSTRUCT_H
|
|
|
|
#include <pngstruct.h>
|
|
|
|
#endif
|
|
|
|
|
2011-03-27 23:32:49 +00:00
|
|
|
#include <cairo/cairo.h>
|
2011-02-09 02:23:10 +00:00
|
|
|
|
2010-12-08 21:14:04 +00:00
|
|
|
#include <sys/types.h>
|
2011-02-09 02:23:10 +00:00
|
|
|
|
|
|
|
#ifdef __MINGW32__
|
|
|
|
#include <winsock2.h>
|
|
|
|
#else
|
2010-12-08 21:14:04 +00:00
|
|
|
#include <sys/socket.h>
|
2011-02-09 02:23:10 +00:00
|
|
|
#endif
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-11-25 20:17:20 +00:00
|
|
|
#include "socket.h"
|
2010-12-08 21:14:04 +00:00
|
|
|
#include "protocol.h"
|
2011-11-25 02:18:03 +00:00
|
|
|
#include "error.h"
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
/* Output formatting functions */
|
|
|
|
|
2011-11-26 00:34:43 +00:00
|
|
|
ssize_t __guac_socket_write_length_string(guac_socket* socket, const char* str) {
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-09-10 06:59:07 +00:00
|
|
|
return
|
2011-11-26 00:34:43 +00:00
|
|
|
guac_socket_write_int(socket, strlen(str))
|
|
|
|
|| guac_socket_write_string(socket, ".")
|
|
|
|
|| guac_socket_write_string(socket, str);
|
2010-12-08 21:14:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
|
2011-11-26 00:34:43 +00:00
|
|
|
ssize_t __guac_socket_write_length_int(guac_socket* socket, int64_t i) {
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-09-10 06:59:07 +00:00
|
|
|
char buffer[128];
|
|
|
|
snprintf(buffer, sizeof(buffer), "%"PRIi64, i);
|
2011-11-26 00:34:43 +00:00
|
|
|
return __guac_socket_write_length_string(socket, buffer);
|
2010-12-08 21:14:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-07-21 22:15:58 +00:00
|
|
|
|
2012-03-11 20:15:45 +00:00
|
|
|
ssize_t __guac_socket_write_length_double(guac_socket* socket, double d) {
|
|
|
|
|
|
|
|
char buffer[128];
|
|
|
|
snprintf(buffer, sizeof(buffer), "%g", d);
|
|
|
|
return __guac_socket_write_length_string(socket, buffer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
/* PNG output formatting */
|
2011-07-21 22:15:58 +00:00
|
|
|
|
2011-11-25 20:17:20 +00:00
|
|
|
typedef struct __guac_socket_write_png_data {
|
2011-09-10 06:59:07 +00:00
|
|
|
|
2011-11-26 00:34:43 +00:00
|
|
|
guac_socket* socket;
|
2011-09-10 06:59:07 +00:00
|
|
|
|
|
|
|
char* buffer;
|
|
|
|
int buffer_size;
|
|
|
|
int data_size;
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
}
|
|
|
|
__guac_socket_write_png_data;
|
2011-09-10 06:59:07 +00:00
|
|
|
|
2011-11-25 20:17:20 +00:00
|
|
|
cairo_status_t __guac_socket_write_png(void* closure, const unsigned char* data, unsigned int length) {
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-11-25 20:17:20 +00:00
|
|
|
__guac_socket_write_png_data* png_data = (__guac_socket_write_png_data*) closure;
|
2011-02-16 02:07:19 +00:00
|
|
|
|
2011-09-10 06:59:07 +00:00
|
|
|
/* Calculate next buffer size */
|
|
|
|
int next_size = png_data->data_size + length;
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-09-10 06:59:07 +00:00
|
|
|
/* If need resizing, double buffer size until big enough */
|
|
|
|
if (next_size > png_data->buffer_size) {
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-09-10 06:59:07 +00:00
|
|
|
char* new_buffer;
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-09-10 06:59:07 +00:00
|
|
|
do {
|
|
|
|
png_data->buffer_size <<= 1;
|
|
|
|
} while (next_size > png_data->buffer_size);
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-09-10 06:59:07 +00:00
|
|
|
/* Resize buffer */
|
|
|
|
new_buffer = realloc(png_data->buffer, png_data->buffer_size);
|
|
|
|
png_data->buffer = new_buffer;
|
2011-03-21 02:34:45 +00:00
|
|
|
|
2011-03-19 23:32:35 +00:00
|
|
|
}
|
|
|
|
|
2011-09-10 06:59:07 +00:00
|
|
|
/* Append data to buffer */
|
|
|
|
memcpy(png_data->buffer + png_data->data_size, data, length);
|
2011-09-10 07:40:22 +00:00
|
|
|
png_data->data_size += length;
|
2011-09-10 06:59:07 +00:00
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
|
2011-11-26 00:34:43 +00:00
|
|
|
int __guac_socket_write_length_png(guac_socket* socket, cairo_surface_t* surface) {
|
2011-09-10 06:59:07 +00:00
|
|
|
|
2011-11-25 20:17:20 +00:00
|
|
|
__guac_socket_write_png_data png_data;
|
2011-09-10 06:59:07 +00:00
|
|
|
int base64_length;
|
|
|
|
|
2011-03-27 23:32:49 +00:00
|
|
|
/* Write surface */
|
|
|
|
|
2011-11-26 00:34:43 +00:00
|
|
|
png_data.socket = socket;
|
2011-09-10 06:59:07 +00:00
|
|
|
png_data.buffer_size = 8192;
|
|
|
|
png_data.buffer = malloc(png_data.buffer_size);
|
|
|
|
png_data.data_size = 0;
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-11-25 20:17:20 +00:00
|
|
|
if (cairo_surface_write_to_png_stream(surface, __guac_socket_write_png, &png_data) != CAIRO_STATUS_SUCCESS) {
|
2011-03-19 23:32:35 +00:00
|
|
|
return -1;
|
2010-12-08 21:14:04 +00:00
|
|
|
}
|
|
|
|
|
2011-09-10 06:59:07 +00:00
|
|
|
base64_length = (png_data.data_size + 2) / 3 * 4;
|
2011-03-27 23:32:49 +00:00
|
|
|
|
2011-09-10 07:40:22 +00:00
|
|
|
/* Write length and data */
|
2011-09-10 06:59:07 +00:00
|
|
|
if (
|
2011-11-26 00:34:43 +00:00
|
|
|
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)) {
|
2011-09-10 07:40:22 +00:00
|
|
|
free(png_data.buffer);
|
2011-09-10 06:59:07 +00:00
|
|
|
return -1;
|
2011-09-10 07:40:22 +00:00
|
|
|
}
|
2011-09-10 06:59:07 +00:00
|
|
|
|
|
|
|
free(png_data.buffer);
|
|
|
|
return 0;
|
2010-12-08 21:14:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
/* Instruction I/O */
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-11-26 00:34:43 +00:00
|
|
|
int __guac_fill_instructionbuf(guac_socket* socket) {
|
2010-12-08 21:14:04 +00:00
|
|
|
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
/* Attempt to fill buffer */
|
|
|
|
retval = recv(
|
2012-03-15 18:30:52 +00:00
|
|
|
socket->fd,
|
|
|
|
socket->__instructionbuf + socket->__instructionbuf_used_length,
|
|
|
|
socket->__instructionbuf_size - socket->__instructionbuf_used_length,
|
|
|
|
0
|
2010-12-08 21:14:04 +00:00
|
|
|
);
|
|
|
|
|
2012-03-15 18:30:52 +00:00
|
|
|
/* Set guac_error if recv() unsuccessful */
|
|
|
|
if (retval < 0) {
|
|
|
|
guac_error = GUAC_STATUS_SEE_ERRNO;
|
|
|
|
guac_error_message = "Error filling instruction buffer";
|
2010-12-08 21:14:04 +00:00
|
|
|
return retval;
|
2012-03-15 18:30:52 +00:00
|
|
|
}
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-11-26 00:34:43 +00:00
|
|
|
socket->__instructionbuf_used_length += retval;
|
2010-12-08 21:14:04 +00:00
|
|
|
|
|
|
|
/* Expand buffer if necessary */
|
2012-03-15 18:30:52 +00:00
|
|
|
if (socket->__instructionbuf_used_length >
|
|
|
|
socket->__instructionbuf_size / 2) {
|
|
|
|
|
2011-11-26 00:34:43 +00:00
|
|
|
socket->__instructionbuf_size *= 2;
|
2012-03-15 18:30:52 +00:00
|
|
|
socket->__instructionbuf = realloc(socket->__instructionbuf,
|
|
|
|
socket->__instructionbuf_size);
|
2010-12-08 21:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
|
2010-12-08 21:14:04 +00:00
|
|
|
/* Returns new instruction if one exists, or NULL if no more instructions. */
|
2012-03-15 18:30:52 +00:00
|
|
|
guac_instruction* guac_protocol_read_instruction(guac_socket* socket,
|
|
|
|
int usec_timeout) {
|
2010-12-08 21:14:04 +00:00
|
|
|
|
|
|
|
int retval;
|
2011-11-28 07:38:38 +00:00
|
|
|
|
2010-12-08 21:14:04 +00:00
|
|
|
/* Loop until a instruction is read */
|
|
|
|
for (;;) {
|
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
/* Length of element */
|
|
|
|
int element_length = 0;
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-11-28 07:38:38 +00:00
|
|
|
/* Position within buffer */
|
|
|
|
int i = socket->__instructionbuf_parse_start;
|
|
|
|
|
2011-11-26 07:48:45 +00:00
|
|
|
/* Parse instruction in buffer */
|
2011-11-26 00:34:43 +00:00
|
|
|
while (i < socket->__instructionbuf_used_length) {
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
/* Read character from buffer */
|
2011-11-26 00:34:43 +00:00
|
|
|
char c = socket->__instructionbuf[i++];
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
/* If digit, calculate element length */
|
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
element_length = element_length * 10 + c - '0';
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
/* Otherwise, if end of length */
|
|
|
|
else if (c == '.') {
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
/* Verify element is fully read */
|
2011-11-26 00:34:43 +00:00
|
|
|
if (i + element_length < socket->__instructionbuf_used_length) {
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
/* Get element value */
|
2011-11-26 00:34:43 +00:00
|
|
|
char* elementv = &(socket->__instructionbuf[i]);
|
2011-10-19 08:28:18 +00:00
|
|
|
|
|
|
|
/* Get terminator, set null terminator of elementv */
|
|
|
|
char terminator = elementv[element_length];
|
|
|
|
elementv[element_length] = '\0';
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-11-26 07:48:45 +00:00
|
|
|
/* Move to char after terminator of element */
|
|
|
|
i += element_length+1;
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
/* Reset element length */
|
|
|
|
element_length = 0;
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
/* As element has been read successfully, update
|
|
|
|
* parse start */
|
2011-11-26 00:34:43 +00:00
|
|
|
socket->__instructionbuf_parse_start = i;
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
/* Save element */
|
2011-11-26 00:34:43 +00:00
|
|
|
socket->__instructionbuf_elementv[socket->__instructionbuf_elementc++] = elementv;
|
2011-10-19 08:28:18 +00:00
|
|
|
|
|
|
|
/* Finish parse if terminator is a semicolon */
|
|
|
|
if (terminator == ';') {
|
|
|
|
|
2011-11-25 02:18:03 +00:00
|
|
|
guac_instruction* parsed_instruction;
|
2011-10-19 08:28:18 +00:00
|
|
|
int j;
|
|
|
|
|
2011-11-25 02:18:03 +00:00
|
|
|
/* Allocate instruction */
|
|
|
|
parsed_instruction = malloc(sizeof(guac_instruction));
|
|
|
|
if (parsed_instruction == NULL) {
|
|
|
|
guac_error = GUAC_STATUS_NO_MEMORY;
|
2011-11-27 23:57:43 +00:00
|
|
|
guac_error_message = "Could not allocate memory for parsed instruction";
|
2011-11-25 02:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
/* Init parsed instruction */
|
2011-11-26 00:34:43 +00:00
|
|
|
parsed_instruction->argc = socket->__instructionbuf_elementc - 1;
|
2011-10-19 08:28:18 +00:00
|
|
|
parsed_instruction->argv = malloc(sizeof(char*) * parsed_instruction->argc);
|
|
|
|
|
2011-11-25 02:18:03 +00:00
|
|
|
/* Fail if memory could not be alloc'd for argv */
|
|
|
|
if (parsed_instruction->argv == NULL) {
|
|
|
|
guac_error = GUAC_STATUS_NO_MEMORY;
|
2011-11-27 23:57:43 +00:00
|
|
|
guac_error_message = "Could not allocate memory for arguments of parsed instruction";
|
2011-11-25 02:18:03 +00:00
|
|
|
free(parsed_instruction);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
/* Set opcode */
|
2011-11-26 00:34:43 +00:00
|
|
|
parsed_instruction->opcode = strdup(socket->__instructionbuf_elementv[0]);
|
2011-10-19 08:28:18 +00:00
|
|
|
|
2011-11-25 02:18:03 +00:00
|
|
|
/* Fail if memory could not be alloc'd for opcode */
|
|
|
|
if (parsed_instruction->opcode == NULL) {
|
|
|
|
guac_error = GUAC_STATUS_NO_MEMORY;
|
2011-11-27 23:57:43 +00:00
|
|
|
guac_error_message = "Could not allocate memory for opcode of parsed instruction";
|
2011-11-25 02:18:03 +00:00
|
|
|
free(parsed_instruction->argv);
|
|
|
|
free(parsed_instruction);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
/* Copy element values to parsed instruction */
|
2011-11-25 02:18:03 +00:00
|
|
|
for (j=0; j<parsed_instruction->argc; j++) {
|
2011-11-26 00:34:43 +00:00
|
|
|
parsed_instruction->argv[j] = strdup(socket->__instructionbuf_elementv[j+1]);
|
2011-10-19 08:28:18 +00:00
|
|
|
|
2011-11-25 02:18:03 +00:00
|
|
|
/* Free memory and fail if out of mem */
|
|
|
|
if (parsed_instruction->argv[j] == NULL) {
|
|
|
|
guac_error = GUAC_STATUS_NO_MEMORY;
|
2011-11-27 23:57:43 +00:00
|
|
|
guac_error_message = "Could not allocate memory for single argument of parsed instruction";
|
2011-11-25 02:18:03 +00:00
|
|
|
|
|
|
|
/* Free all alloc'd argv values */
|
|
|
|
while (--j >= 0)
|
|
|
|
free(parsed_instruction->argv[j]);
|
|
|
|
|
|
|
|
free(parsed_instruction->opcode);
|
|
|
|
free(parsed_instruction->argv);
|
|
|
|
free(parsed_instruction);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
/* Reset buffer */
|
2011-11-26 08:28:43 +00:00
|
|
|
memmove(socket->__instructionbuf, socket->__instructionbuf + i, socket->__instructionbuf_used_length - i);
|
|
|
|
socket->__instructionbuf_used_length -= i;
|
2011-11-26 00:34:43 +00:00
|
|
|
socket->__instructionbuf_parse_start = 0;
|
|
|
|
socket->__instructionbuf_elementc = 0;
|
2011-10-19 08:28:18 +00:00
|
|
|
|
|
|
|
/* Done */
|
2011-11-25 02:18:03 +00:00
|
|
|
return parsed_instruction;
|
2011-10-19 08:28:18 +00:00
|
|
|
|
|
|
|
} /* end if terminator */
|
|
|
|
|
2011-11-26 07:48:45 +00:00
|
|
|
/* Error if expected comma is not present */
|
|
|
|
else if (terminator != ',') {
|
|
|
|
guac_error = GUAC_STATUS_BAD_ARGUMENT;
|
2011-11-27 23:57:43 +00:00
|
|
|
guac_error_message = "Element terminator of instructioni was not ';' nor ','";
|
2011-11-26 07:48:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-19 08:28:18 +00:00
|
|
|
} /* end if element fully read */
|
|
|
|
|
|
|
|
/* Otherwise, read more data */
|
|
|
|
else
|
|
|
|
break;
|
2010-12-08 21:14:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-26 07:48:45 +00:00
|
|
|
/* Error if length is non-numeric or does not end in a period */
|
|
|
|
else {
|
|
|
|
guac_error = GUAC_STATUS_BAD_ARGUMENT;
|
2011-11-27 23:57:43 +00:00
|
|
|
guac_error_message = "Non-numeric character in element length";
|
2011-11-26 07:48:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-08 21:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No instruction yet? Get more data ... */
|
2011-11-26 00:34:43 +00:00
|
|
|
retval = guac_socket_select(socket, usec_timeout);
|
2010-12-08 21:14:04 +00:00
|
|
|
if (retval <= 0)
|
2011-11-25 02:18:03 +00:00
|
|
|
return NULL;
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-03-17 07:25:35 +00:00
|
|
|
/* If more data is available, fill into buffer */
|
2011-11-26 00:34:43 +00:00
|
|
|
retval = __guac_fill_instructionbuf(socket);
|
2011-11-25 02:18:03 +00:00
|
|
|
|
|
|
|
/* Error, guac_error already set */
|
|
|
|
if (retval < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* EOF */
|
|
|
|
if (retval == 0) {
|
|
|
|
guac_error = GUAC_STATUS_NO_INPUT;
|
2011-11-27 23:57:43 +00:00
|
|
|
guac_error_message = "End of stream reached while reading instruction";
|
2011-11-25 02:18:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-12-08 21:14:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
|
2011-11-26 00:34:43 +00:00
|
|
|
guac_instruction* guac_protocol_expect_instruction(guac_socket* socket, int usec_timeout,
|
2011-11-25 20:17:20 +00:00
|
|
|
const char* opcode) {
|
|
|
|
|
|
|
|
guac_instruction* instruction;
|
|
|
|
|
|
|
|
/* Wait for data until timeout */
|
2011-11-26 00:34:43 +00:00
|
|
|
if (guac_protocol_instructions_waiting(socket, usec_timeout) <= 0)
|
2011-11-25 20:17:20 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Read available instruction */
|
2011-11-26 00:34:43 +00:00
|
|
|
instruction = guac_protocol_read_instruction(socket, usec_timeout);
|
2011-11-25 20:17:20 +00:00
|
|
|
if (instruction == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Validate instruction */
|
|
|
|
if (strcmp(instruction->opcode, opcode) != 0) {
|
|
|
|
guac_error = GUAC_STATUS_BAD_STATE;
|
2011-11-27 23:57:43 +00:00
|
|
|
guac_error_message = "Instruction read did not have expected opcode";
|
2011-11-25 20:17:20 +00:00
|
|
|
guac_instruction_free(instruction);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return instruction if valid */
|
|
|
|
return instruction;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-27 04:10:52 +00:00
|
|
|
|
|
|
|
void guac_instruction_free(guac_instruction* instruction) {
|
|
|
|
|
2011-12-21 09:35:16 +00:00
|
|
|
int argc = instruction->argc;
|
|
|
|
|
2011-11-27 04:10:52 +00:00
|
|
|
/* Free opcode */
|
2010-12-08 21:14:04 +00:00
|
|
|
free(instruction->opcode);
|
|
|
|
|
2011-11-27 04:10:52 +00:00
|
|
|
/* Free argv if set (may be NULL of argc is 0) */
|
2011-12-21 09:35:16 +00:00
|
|
|
if (instruction->argv) {
|
|
|
|
|
|
|
|
/* All argument values */
|
|
|
|
while (argc > 0)
|
|
|
|
free(instruction->argv[--argc]);
|
|
|
|
|
|
|
|
/* Free actual array */
|
2010-12-08 21:14:04 +00:00
|
|
|
free(instruction->argv);
|
|
|
|
|
2011-12-21 09:35:16 +00:00
|
|
|
}
|
|
|
|
|
2011-11-27 04:10:52 +00:00
|
|
|
/* Free instruction */
|
2010-12-08 21:14:04 +00:00
|
|
|
free(instruction);
|
2011-11-27 04:10:52 +00:00
|
|
|
|
2010-12-08 21:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-26 00:34:43 +00:00
|
|
|
int guac_protocol_instructions_waiting(guac_socket* socket, int usec_timeout) {
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2011-11-26 00:34:43 +00:00
|
|
|
if (socket->__instructionbuf_used_length > 0)
|
2010-12-08 21:14:04 +00:00
|
|
|
return 1;
|
|
|
|
|
2011-11-26 00:34:43 +00:00
|
|
|
return guac_socket_select(socket, usec_timeout);
|
2010-12-08 21:14:04 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
|
2011-11-25 20:17:20 +00:00
|
|
|
guac_timestamp guac_protocol_get_timestamp() {
|
2011-03-18 04:16:29 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CLOCK_GETTIME
|
|
|
|
|
|
|
|
struct timespec current;
|
|
|
|
|
|
|
|
/* Get current time */
|
|
|
|
clock_gettime(CLOCK_REALTIME, ¤t);
|
|
|
|
|
|
|
|
/* Calculate milliseconds */
|
2011-11-16 23:43:28 +00:00
|
|
|
return (guac_timestamp) current.tv_sec * 1000 + current.tv_nsec / 1000000;
|
2011-03-18 04:16:29 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
struct timeval current;
|
|
|
|
|
|
|
|
/* Get current time */
|
|
|
|
gettimeofday(¤t, NULL);
|
|
|
|
|
|
|
|
/* Calculate milliseconds */
|
2011-11-16 23:43:28 +00:00
|
|
|
return (guac_timestamp) current.tv_sec * 1000 + current.tv_usec / 1000;
|
2011-03-18 04:16:29 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
|
|
|
|
/* Protocol functions */
|
|
|
|
|
|
|
|
int guac_protocol_send_args(guac_socket* socket, const char** args) {
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (guac_socket_write_string(socket, "4.args")) return -1;
|
|
|
|
|
|
|
|
for (i=0; args[i] != NULL; i++) {
|
|
|
|
|
|
|
|
if (guac_socket_write_string(socket, ","))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (__guac_socket_write_length_string(socket, args[i]))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-13 00:22:04 +00:00
|
|
|
int guac_protocol_send_arc(guac_socket* socket, const guac_layer* layer,
|
2012-03-14 02:07:24 +00:00
|
|
|
int x, int y, int radius, double startAngle, double endAngle,
|
|
|
|
int negative) {
|
2012-03-13 00:22:04 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "3.arc,")
|
|
|
|
|| __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, radius)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, startAngle)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, endAngle)
|
2012-03-14 02:07:24 +00:00
|
|
|
|| guac_socket_write_string(socket, ",")
|
2012-03-14 02:12:37 +00:00
|
|
|
|| guac_socket_write_string(socket, negative ? "1.1" : "1.0")
|
2012-03-13 00:22:04 +00:00
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 19:57:15 +00:00
|
|
|
int guac_protocol_send_cfill(guac_socket* socket,
|
|
|
|
guac_composite_mode mode, const guac_layer* layer,
|
|
|
|
int r, int g, int b, int a) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "5.cfill,")
|
|
|
|
|| __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, 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, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-13 00:22:04 +00:00
|
|
|
int guac_protocol_send_close(guac_socket* socket, const guac_layer* layer) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "5.close,")
|
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 19:57:15 +00:00
|
|
|
int guac_protocol_send_connect(guac_socket* socket, const char** args) {
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (guac_socket_write_string(socket, "7.connect")) return -1;
|
|
|
|
|
|
|
|
for (i=0; args[i] != NULL; i++) {
|
|
|
|
|
|
|
|
if (guac_socket_write_string(socket, ","))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (__guac_socket_write_length_string(socket, args[i]))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
int guac_protocol_send_clip(guac_socket* socket, const guac_layer* layer) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "4.clip,")
|
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int guac_protocol_send_clipboard(guac_socket* socket, const char* data) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "9.clipboard,")
|
|
|
|
|| __guac_socket_write_length_string(socket, data)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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(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, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 19:57:15 +00:00
|
|
|
int guac_protocol_send_cstroke(guac_socket* socket,
|
|
|
|
guac_composite_mode mode, const guac_layer* layer,
|
|
|
|
guac_line_cap_style cap, guac_line_join_style join, int thickness,
|
|
|
|
int r, int g, int b, int a) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "7.cstroke,")
|
|
|
|
|| __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, cap)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_int(socket, join)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_int(socket, thickness)
|
|
|
|
|| 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, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
int guac_protocol_send_cursor(guac_socket* socket, int x, int y,
|
|
|
|
const guac_layer* srcl, int srcx, int srcy, int w, int h) {
|
|
|
|
return
|
|
|
|
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_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, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-13 00:22:04 +00:00
|
|
|
int guac_protocol_send_curve(guac_socket* socket, const guac_layer* layer,
|
|
|
|
int cp1x, int cp1y, int cp2x, int cp2y, int x, int y) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "5.curve,")
|
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_int(socket, cp1x)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_int(socket, cp1y)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_int(socket, cp2x)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_int(socket, cp2y)
|
|
|
|
|| 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, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 19:57:15 +00:00
|
|
|
int guac_protocol_send_disconnect(guac_socket* socket) {
|
|
|
|
return guac_socket_write_string(socket, "10.disconnect;");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
int guac_protocol_send_dispose(guac_socket* socket, const guac_layer* layer) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "7.dispose,")
|
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 20:15:45 +00:00
|
|
|
int guac_protocol_send_distort(guac_socket* socket, const guac_layer* layer,
|
|
|
|
double a, double b, double c,
|
|
|
|
double d, double e, double f) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "7.distort,")
|
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, a)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, b)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, c)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, d)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, e)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, f)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
int guac_protocol_send_error(guac_socket* socket, const char* error) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "5.error,")
|
|
|
|
|| __guac_socket_write_length_string(socket, error)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-13 00:22:04 +00:00
|
|
|
int guac_protocol_send_identity(guac_socket* socket, const guac_layer* layer) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "8.identity,")
|
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-12 04:05:34 +00:00
|
|
|
int guac_protocol_send_lfill(guac_socket* socket,
|
|
|
|
guac_composite_mode mode, const guac_layer* layer,
|
|
|
|
const guac_layer* srcl) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "5.lfill,")
|
|
|
|
|| __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, srcl->index)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-13 00:22:04 +00:00
|
|
|
int guac_protocol_send_line(guac_socket* socket, const guac_layer* layer,
|
|
|
|
int x, int y) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "4.line,")
|
|
|
|
|| __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, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-12 04:05:34 +00:00
|
|
|
int guac_protocol_send_lstroke(guac_socket* socket,
|
|
|
|
guac_composite_mode mode, const guac_layer* layer,
|
|
|
|
guac_line_cap_style cap, guac_line_join_style join, int thickness,
|
|
|
|
const guac_layer* srcl) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "7.lstroke,")
|
|
|
|
|| __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, cap)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_int(socket, join)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_int(socket, thickness)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_int(socket, srcl->index)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
|
|
|
|
int guac_protocol_send_move(guac_socket* socket, const guac_layer* layer,
|
|
|
|
const guac_layer* parent, int x, int y, int z) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "4.move,")
|
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_int(socket, parent->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, z)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int guac_protocol_send_name(guac_socket* socket, const char* name) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "4.name,")
|
|
|
|
|| __guac_socket_write_length_string(socket, name)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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(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, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 20:15:45 +00:00
|
|
|
int guac_protocol_send_pop(guac_socket* socket, const guac_layer* layer) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "3.pop,")
|
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int guac_protocol_send_push(guac_socket* socket, const guac_layer* layer) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "4.push,")
|
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
int guac_protocol_send_rect(guac_socket* socket,
|
|
|
|
const guac_layer* layer, int x, int y, int width, int height) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "4.rect,")
|
|
|
|
|| __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, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 20:15:45 +00:00
|
|
|
int guac_protocol_send_reset(guac_socket* socket, const guac_layer* layer) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "5.reset,")
|
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-13 19:06:11 +00:00
|
|
|
int guac_protocol_send_set(guac_socket* socket, const guac_layer* layer,
|
|
|
|
const char* name, const char* value) {
|
2012-03-11 19:57:15 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "3.set,")
|
2012-03-13 19:06:11 +00:00
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
2012-03-11 19:57:15 +00:00
|
|
|
|| __guac_socket_write_length_string(socket, name)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_string(socket, value)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int guac_protocol_send_select(guac_socket* socket, const char* protocol) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "6.select,")
|
|
|
|
|| __guac_socket_write_length_string(socket, protocol)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 20:15:45 +00:00
|
|
|
int guac_protocol_send_shade(guac_socket* socket, const guac_layer* layer,
|
|
|
|
int a) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "5.shade,")
|
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_int(socket, a)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
int guac_protocol_send_size(guac_socket* socket, const guac_layer* layer,
|
|
|
|
int w, int h) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "4.size,")
|
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| 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, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-13 00:22:04 +00:00
|
|
|
int guac_protocol_send_start(guac_socket* socket, const guac_layer* layer,
|
|
|
|
int x, int y) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "5.start,")
|
|
|
|
|| __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, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 05:34:42 +00:00
|
|
|
int guac_protocol_send_sync(guac_socket* socket, guac_timestamp timestamp) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "4.sync,")
|
|
|
|
|| __guac_socket_write_length_int(socket, timestamp)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int guac_protocol_send_transfer(guac_socket* socket,
|
|
|
|
const guac_layer* srcl, int srcx, int srcy, int w, int h,
|
|
|
|
guac_transfer_function fn, const guac_layer* dstl, int dstx, int dsty) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "8.transfer,")
|
|
|
|
|| __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, fn)
|
|
|
|
|| 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, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-11 20:15:45 +00:00
|
|
|
int guac_protocol_send_transform(guac_socket* socket, const guac_layer* layer,
|
|
|
|
double a, double b, double c,
|
|
|
|
double d, double e, double f) {
|
|
|
|
|
|
|
|
return
|
|
|
|
guac_socket_write_string(socket, "9.transform,")
|
|
|
|
|| __guac_socket_write_length_int(socket, layer->index)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, a)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, b)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, c)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, d)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, e)
|
|
|
|
|| guac_socket_write_string(socket, ",")
|
|
|
|
|| __guac_socket_write_length_double(socket, f)
|
|
|
|
|| guac_socket_write_string(socket, ";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|