Initial connect instruction support, connection UUIDs

This commit is contained in:
Michael Jumper
2010-09-17 22:05:23 -07:00
parent 0630e69668
commit 60d78e22c7
9 changed files with 98 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
CFLAGS=-O2 -fPIC -pedantic -Wall -Werror -Iinclude
LDFLAGS=-lpng
LDFLAGS=-lpng -luuid
.PHONY: clean doc

View File

@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <uuid/uuid.h>
#include "guacio.h"
#include "protocol.h"
@@ -53,19 +54,57 @@ void guac_free_png_buffer(png_byte** png_buffer, int h) {
}
guac_client* guac_get_client(int client_fd, guac_client_init_handler* client_init, const char* hostname, int port) {
guac_client* __guac_alloc_client(GUACIO* io) {
/* Allocate new client (not handoff) */
guac_client* client = malloc(sizeof(guac_client));
client->io = guac_open(client_fd);
/* Init new client */
client->io = io;
uuid_generate(client->uuid);
return client;
}
guac_client* guac_get_client(int client_fd, guac_client_init_handler* client_init, const char* hostname, int port) {
guac_client* client;
GUACIO* io = guac_open(client_fd);
guac_instruction instruction;
/* Wait for handshaking messages */
for (;;) {
int retval;
retval = guac_read_instruction(io, &instruction); /* 0 if no instructions finished yet, <0 if error or EOF */
if (retval > 0) {
/* connect -> create new client connection */
if (strcmp(instruction.opcode, "connect") == 0) {
client = __guac_alloc_client(io);
guac_send_uuid(io, client->uuid);
break;
}
}
if (retval < 0)
return NULL; /* EOF or error */
/* Otherwise, retval == 0 implies unfinished instruction */
}
/* FIXME: hostname and port should not be required. Should be made available in some sort of client-contained argc/argv, specified after the protocol on the commandline */
client_init(client, hostname, port);
guac_flush(client->io);
return client;
}
void guac_free_client(guac_client* client) {
if (client->free_handler)
client->free_handler(client);

View File

@@ -21,6 +21,7 @@
#define _CLIENT_H
#include <png.h>
#include <uuid/uuid.h>
#include "guacio.h"
@@ -46,6 +47,12 @@ typedef void guac_client_free_handler(void* client);
*/
struct guac_client {
/**
* UUID identifying this client. Useful when identifying a client
* for connection handoff/resume.
*/
uuid_t uuid;
/**
* The GUACIO structure to be used to communicate with the web-client. It is
* expected that the implementor of any Guacamole proxy client will provide

View File

@@ -21,6 +21,7 @@
#define __PROTOCOL_H
#include <png.h>
#include <uuid/uuid.h>
#include "guacio.h"
@@ -40,6 +41,7 @@ char* guac_unescape_string_inplace(char* str);
void guac_send_name(GUACIO* io, const char* name);
void guac_send_error(GUACIO* io, const char* error);
void guac_send_clipboard(GUACIO* io, const char* data);
void guac_send_uuid(GUACIO* io, uuid_t uuid);
void guac_send_size(GUACIO* io, int w, int h);
void guac_send_copy(GUACIO* io, int srcx, int srcy, int w, int h, int dstx, int dsty);
void guac_send_png(GUACIO* io, int x, int y, png_byte** png_rows, int w, int h);

View File

@@ -26,6 +26,8 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <uuid/uuid.h>
#include "guacio.h"
#include "protocol.h"
@@ -154,6 +156,15 @@ void guac_send_size(GUACIO* io, int w, int h) {
guac_write_string(io, ";");
}
void guac_send_uuid(GUACIO* io, uuid_t uuid) {
guac_write_string(io, "uuid:");
guac_write_base64(io, uuid, 16);
guac_flush_base64(io);
guac_write_string(io, ";");
}
void guac_send_clipboard(GUACIO* io, const char* data) {
char* escaped = guac_escape_string(data);