mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Support for new instruction format.
This commit is contained in:
@@ -227,16 +227,16 @@ Guacamole.Client = function(display, tunnel) {
|
|||||||
var instructionHandlers = {
|
var instructionHandlers = {
|
||||||
|
|
||||||
"error": function(parameters) {
|
"error": function(parameters) {
|
||||||
if (guac_client.onerror) guac_client.onerror(unescapeGuacamoleString(parameters[0]));
|
if (guac_client.onerror) guac_client.onerror(parameters[0]);
|
||||||
disconnect();
|
disconnect();
|
||||||
},
|
},
|
||||||
|
|
||||||
"name": function(parameters) {
|
"name": function(parameters) {
|
||||||
if (guac_client.onname) guac_client.onname(unescapeGuacamoleString(parameters[0]));
|
if (guac_client.onname) guac_client.onname(parameters[0]);
|
||||||
},
|
},
|
||||||
|
|
||||||
"clipboard": function(parameters) {
|
"clipboard": function(parameters) {
|
||||||
if (guac_client.onclipboard) guac_client.onclipboard(unescapeGuacamoleString(parameters[0]));
|
if (guac_client.onclipboard) guac_client.onclipboard(parameters[0]);
|
||||||
},
|
},
|
||||||
|
|
||||||
"size": function(parameters) {
|
"size": function(parameters) {
|
||||||
@@ -454,35 +454,6 @@ Guacamole.Client = function(display, tunnel) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function unescapeGuacamoleString(str) {
|
|
||||||
|
|
||||||
var unescapedString = "";
|
|
||||||
|
|
||||||
for (var i=0; i<str.length; i++) {
|
|
||||||
|
|
||||||
var c = str.charAt(i);
|
|
||||||
if (c == "\\" && i<str.length-1) {
|
|
||||||
|
|
||||||
var escapeChar = str.charAt(++i);
|
|
||||||
if (escapeChar == "c")
|
|
||||||
unescapedString += ",";
|
|
||||||
else if (escapeChar == "s")
|
|
||||||
unescapedString += ";";
|
|
||||||
else if (escapeChar == "\\")
|
|
||||||
unescapedString += "\\";
|
|
||||||
else
|
|
||||||
unescapedString += "\\" + escapeChar;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
unescapedString += c;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return unescapedString;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
guac_client.disconnect = disconnect;
|
guac_client.disconnect = disconnect;
|
||||||
guac_client.connect = function(data) {
|
guac_client.connect = function(data) {
|
||||||
|
|
||||||
@@ -499,7 +470,4 @@ Guacamole.Client = function(display, tunnel) {
|
|||||||
setState(STATE_WAITING);
|
setState(STATE_WAITING);
|
||||||
};
|
};
|
||||||
|
|
||||||
guac_client.escapeGuacamoleString = escapeGuacamoleString;
|
|
||||||
guac_client.unescapeGuacamoleString = unescapeGuacamoleString;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -154,9 +154,16 @@ Guacamole.HTTPTunnel = function(tunnelURL) {
|
|||||||
var nextRequest = null;
|
var nextRequest = null;
|
||||||
|
|
||||||
var dataUpdateEvents = 0;
|
var dataUpdateEvents = 0;
|
||||||
var instructionStart = 0;
|
|
||||||
|
// The location of the last element's terminator
|
||||||
|
var elementEnd = -1;
|
||||||
|
|
||||||
|
// Where to start the next length search or the next element
|
||||||
var startIndex = 0;
|
var startIndex = 0;
|
||||||
|
|
||||||
|
// Parsed elements
|
||||||
|
var elements = new Array();
|
||||||
|
|
||||||
function parseResponse() {
|
function parseResponse() {
|
||||||
|
|
||||||
// Do not handle responses if not connected
|
// Do not handle responses if not connected
|
||||||
@@ -208,51 +215,84 @@ Guacamole.HTTPTunnel = function(tunnelURL) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var current = xmlhttprequest.responseText;
|
var current = xmlhttprequest.responseText;
|
||||||
var instructionEnd;
|
|
||||||
|
|
||||||
while ((instructionEnd = current.indexOf(";", startIndex)) != -1) {
|
// While search is within currently received data
|
||||||
|
while (elementEnd < current.length) {
|
||||||
|
|
||||||
// Start next search at next instruction
|
// If we are waiting for element data
|
||||||
startIndex = instructionEnd+1;
|
if (elementEnd >= startIndex) {
|
||||||
|
|
||||||
var instruction = current.substr(instructionStart,
|
// We now have enough data for the element. Parse.
|
||||||
instructionEnd - instructionStart);
|
var element = current.substring(startIndex, elementEnd);
|
||||||
|
var terminator = current.substring(elementEnd, elementEnd+1);
|
||||||
|
|
||||||
instructionStart = startIndex;
|
// Add element to array
|
||||||
|
elements.push(element);
|
||||||
|
|
||||||
var opcodeEnd = instruction.indexOf(":");
|
// If last element, handle instruction
|
||||||
|
if (terminator == ";") {
|
||||||
|
|
||||||
|
// Get opcode
|
||||||
|
var opcode = elements.shift();
|
||||||
|
|
||||||
|
// Call instruction handler.
|
||||||
|
if (tunnel.oninstruction != null)
|
||||||
|
tunnel.oninstruction(opcode, elements);
|
||||||
|
|
||||||
|
// Clear elements
|
||||||
|
elements.length = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start searching for length at character after
|
||||||
|
// element terminator
|
||||||
|
startIndex = elementEnd + 1;
|
||||||
|
|
||||||
var opcode;
|
|
||||||
var parameters;
|
|
||||||
if (opcodeEnd == -1) {
|
|
||||||
opcode = instruction;
|
|
||||||
parameters = new Array();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Search for end of length
|
||||||
|
var lengthEnd = current.indexOf(".", startIndex);
|
||||||
|
if (lengthEnd != -1) {
|
||||||
|
|
||||||
|
// Parse length
|
||||||
|
var length = parseInt(current.substring(elementEnd+1, lengthEnd));
|
||||||
|
|
||||||
|
// If we're done parsing, handle the next response.
|
||||||
|
if (length == 0) {
|
||||||
|
|
||||||
|
// Clean up interval if polling
|
||||||
|
if (interval != null)
|
||||||
|
clearInterval(interval);
|
||||||
|
|
||||||
|
// Clean up object
|
||||||
|
xmlhttprequest.onreadystatechange = null;
|
||||||
|
xmlhttprequest.abort();
|
||||||
|
|
||||||
|
// Start handling next request
|
||||||
|
if (nextRequest)
|
||||||
|
handleResponse(nextRequest);
|
||||||
|
|
||||||
|
// Done parsing
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate start of element
|
||||||
|
startIndex = lengthEnd + 1;
|
||||||
|
|
||||||
|
// Calculate location of element terminator
|
||||||
|
elementEnd = startIndex + length;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no period yet, continue search when more data
|
||||||
|
// is received
|
||||||
else {
|
else {
|
||||||
opcode = instruction.substr(0, opcodeEnd);
|
startIndex = current.length;
|
||||||
parameters = instruction.substr(opcodeEnd+1).split(",");
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're done parsing, handle the next response.
|
|
||||||
if (opcode.length == 0) {
|
|
||||||
|
|
||||||
delete xmlhttprequest;
|
|
||||||
if (nextRequest)
|
|
||||||
handleResponse(nextRequest);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call instruction handler.
|
} // end parse loop
|
||||||
if (tunnel.oninstruction != null)
|
|
||||||
tunnel.oninstruction(opcode, parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start search at end of string.
|
|
||||||
startIndex = current.length;
|
|
||||||
|
|
||||||
delete instruction;
|
|
||||||
delete parameters;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user