mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Initial connect instruction support, connection UUIDs
This commit is contained in:
@@ -111,6 +111,12 @@ public class GuacamoleSession {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
synchronized (session) {
|
||||
return client != null;
|
||||
}
|
||||
}
|
||||
|
||||
public GuacamoleConfiguration getConfiguration() {
|
||||
return config;
|
||||
}
|
||||
@@ -126,8 +132,12 @@ public class GuacamoleSession {
|
||||
}
|
||||
|
||||
public void disconnect() throws GuacamoleException {
|
||||
if (client != null)
|
||||
if (client != null) {
|
||||
client.disconnect();
|
||||
|
||||
session.removeAttribute("CLIENT");
|
||||
client = null;
|
||||
}
|
||||
}
|
||||
|
||||
public ReentrantLock getInstructionStreamLock() {
|
||||
|
@@ -30,10 +30,16 @@ import net.sourceforge.guacamole.net.XMLGuacamoleServlet;
|
||||
|
||||
public class Inbound extends XMLGuacamoleServlet {
|
||||
|
||||
protected boolean shouldCreateSession() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleRequest(GuacamoleSession session, ServletRequest request, Element root) throws GuacamoleException {
|
||||
|
||||
if (!session.isConnected())
|
||||
session.connect();
|
||||
|
||||
// Send data
|
||||
try {
|
||||
|
||||
|
@@ -32,9 +32,16 @@ import net.sourceforge.guacamole.net.GuacamoleSession;
|
||||
|
||||
public class InstructionStream extends GuacamoleServlet {
|
||||
|
||||
protected boolean shouldCreateSession() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleRequest(GuacamoleSession session, HttpServletRequest request, HttpServletResponse response) throws GuacamoleException {
|
||||
|
||||
if (!session.isConnected())
|
||||
session.connect();
|
||||
|
||||
ReentrantLock instructionStreamLock = session.getInstructionStreamLock();
|
||||
instructionStreamLock.lock();
|
||||
|
||||
|
@@ -115,6 +115,10 @@ function VNCClient(display) {
|
||||
this.enableKeyboard();
|
||||
|
||||
function sendKeyEvent(pressed, keysym) {
|
||||
// Do not send requests if not connected
|
||||
if (!isConnected())
|
||||
return;
|
||||
|
||||
sendMessage("key:" + keysym + "," + pressed + ";");
|
||||
}
|
||||
|
||||
@@ -159,6 +163,10 @@ function VNCClient(display) {
|
||||
|
||||
function sendMouseState(mouseState) {
|
||||
|
||||
// Do not send requests if not connected
|
||||
if (!isConnected())
|
||||
return;
|
||||
|
||||
// Build mask
|
||||
var buttonMask = 0;
|
||||
if (mouseState.getLeft()) buttonMask |= 1;
|
||||
@@ -176,10 +184,6 @@ function VNCClient(display) {
|
||||
|
||||
function sendMessage(message) {
|
||||
|
||||
// Do not send requests if not connected
|
||||
if (!isConnected())
|
||||
return;
|
||||
|
||||
// Add event to queue, restart send loop if finished.
|
||||
outputMessageBuffer += message;
|
||||
if (sendingMessages == 0)
|
||||
@@ -189,10 +193,6 @@ function VNCClient(display) {
|
||||
|
||||
function sendPendingMessages() {
|
||||
|
||||
// Do not send requests if not connected
|
||||
if (!isConnected())
|
||||
return;
|
||||
|
||||
if (outputMessageBuffer.length > 0) {
|
||||
|
||||
sendingMessages = 1;
|
||||
@@ -560,20 +560,11 @@ function VNCClient(display) {
|
||||
this.connect = function() {
|
||||
|
||||
// Attempt connection
|
||||
var connect_xmlhttprequest = new XMLHttpRequest();
|
||||
connect_xmlhttprequest.open("GET", "connect", false);
|
||||
|
||||
setState(STATE_CONNECTING);
|
||||
connect_xmlhttprequest.send(null);
|
||||
sendMessage("connect;"); // Start new guacamole session
|
||||
|
||||
// Handle result (and check for errors)
|
||||
var message = new GuacamoleMessage(connect_xmlhttprequest.responseXML);
|
||||
if (!message.hasErrors()) {
|
||||
setState(STATE_WAITING);
|
||||
handleResponse(makeRequest());
|
||||
}
|
||||
else
|
||||
handleErrors(message);
|
||||
|
||||
};
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
|
||||
CFLAGS=-O2 -fPIC -pedantic -Wall -Werror -Iinclude
|
||||
LDFLAGS=-lpng
|
||||
LDFLAGS=-lpng -luuid
|
||||
|
||||
.PHONY: clean doc
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user