mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
Support for new instruction format, dependency on Apache commons
This commit is contained in:
@@ -43,6 +43,13 @@
|
|||||||
<version>1.6.1</version>
|
<version>1.6.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Apache Commons -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>3.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@@ -21,9 +21,13 @@ package net.sourceforge.guacamole.io;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import net.sourceforge.guacamole.GuacamoleException;
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
import net.sourceforge.guacamole.protocol.GuacamoleInstruction;
|
import net.sourceforge.guacamole.protocol.GuacamoleInstruction;
|
||||||
import net.sourceforge.guacamole.protocol.GuacamoleInstruction.Operation;
|
import net.sourceforge.guacamole.protocol.GuacamoleInstruction.Operation;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A GuacamoleReader which wraps a standard Java Reader, using that Reader as
|
* A GuacamoleReader which wraps a standard Java Reader, using that Reader as
|
||||||
@@ -127,54 +131,59 @@ public class ReaderGuacamoleReader implements GuacamoleReader {
|
|||||||
// If EOF, return EOF
|
// If EOF, return EOF
|
||||||
if (instructionBuffer == null)
|
if (instructionBuffer == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
// Build list of elements
|
||||||
|
LinkedList<String> elements = new LinkedList<String>();
|
||||||
|
while (instructionStart < instructionBuffer.length) {
|
||||||
|
|
||||||
// Locate end-of-opcode and end-of-instruction
|
// Find end of length
|
||||||
int opcodeEnd = -1;
|
int lengthEnd = ArrayUtils.indexOf(instructionBuffer, '.', instructionStart);
|
||||||
int instructionEnd = -1;
|
|
||||||
|
|
||||||
for (int i=instructionStart; i<instructionBuffer.length; i++) {
|
// Parse length
|
||||||
|
int length = Integer.parseInt(new String(
|
||||||
|
instructionBuffer,
|
||||||
|
instructionStart,
|
||||||
|
lengthEnd - instructionStart
|
||||||
|
));
|
||||||
|
|
||||||
char c = instructionBuffer[i];
|
// Parse element from just after period
|
||||||
|
instructionStart = lengthEnd + 1;
|
||||||
|
String element = new String(
|
||||||
|
instructionBuffer,
|
||||||
|
instructionStart,
|
||||||
|
length
|
||||||
|
);
|
||||||
|
|
||||||
if (c == ':')
|
// Append element to list of elements
|
||||||
opcodeEnd = i;
|
elements.addLast(element);
|
||||||
|
|
||||||
|
// Read terminator after element
|
||||||
|
instructionStart += length;
|
||||||
|
char terminator = instructionBuffer[instructionStart];
|
||||||
|
|
||||||
else if (c == ';') {
|
// Continue reading instructions after terminator
|
||||||
instructionEnd = i;
|
instructionStart++;
|
||||||
|
|
||||||
|
// If we've reached the end of the instruction
|
||||||
|
if (terminator == ';')
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no end-of-instruction marker, malformed.
|
// Pull opcode off elements list
|
||||||
if (instructionEnd == -1)
|
String opcode = elements.removeFirst();
|
||||||
throw new GuacamoleException("Malformed instruction.");
|
|
||||||
|
|
||||||
// If no end-of-opcode marker, end is end-of-instruction
|
|
||||||
if (opcodeEnd == -1)
|
|
||||||
opcodeEnd = instructionEnd;
|
|
||||||
|
|
||||||
// Parse opcode
|
|
||||||
String opcode = new String(instructionBuffer, instructionStart, opcodeEnd - instructionStart);
|
|
||||||
|
|
||||||
// Parse args
|
|
||||||
String[] args;
|
|
||||||
if (instructionEnd > opcodeEnd)
|
|
||||||
args = new String(instructionBuffer, opcodeEnd+1, instructionEnd - opcodeEnd - 1).split(",");
|
|
||||||
else
|
|
||||||
args = new String[0];
|
|
||||||
|
|
||||||
// Create instruction
|
// Create instruction
|
||||||
GuacamoleInstruction instruction = new GuacamoleInstruction(
|
GuacamoleInstruction instruction = new GuacamoleInstruction(
|
||||||
Operation.fromOpcode(opcode),
|
Operation.fromOpcode(opcode),
|
||||||
args
|
elements.toArray(new String[elements.size()])
|
||||||
);
|
);
|
||||||
|
|
||||||
// Advance instructionBuffer
|
// Detect end of buffer
|
||||||
instructionStart = instructionEnd + 1;
|
|
||||||
if (instructionStart >= instructionBuffer.length)
|
if (instructionStart >= instructionBuffer.length)
|
||||||
instructionBuffer = null;
|
instructionBuffer = null;
|
||||||
|
|
||||||
|
// Return parsed instruction
|
||||||
return instruction;
|
return instruction;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -221,7 +221,7 @@ public abstract class GuacamoleTunnelServlet extends HttpServlet {
|
|||||||
tunnel.close();
|
tunnel.close();
|
||||||
|
|
||||||
// End-of-instructions marker
|
// End-of-instructions marker
|
||||||
out.write(';');
|
out.write("0.;");
|
||||||
out.flush();
|
out.flush();
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user