mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-09 14:41:21 +00:00
Remove central guac-dev repo reference. Refactor net.sourceforge.guacamole to org.glyptodon.guacamole. Extensions are remaining with their classes in net.sourceforge.guacamole for compatibility's sake until we have a better system for extensions.
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
|
||||
package org.glyptodon.guacamole.io;
|
||||
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is guacamole-common.
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleInstruction;
|
||||
|
||||
/**
|
||||
* Provides abstract and raw character read access to a stream of Guacamole
|
||||
* instructions.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public interface GuacamoleReader {
|
||||
|
||||
/**
|
||||
* Returns whether instruction data is available for reading. Note that
|
||||
* this does not guarantee an entire instruction is available. If a full
|
||||
* instruction is not available, this function can return true, and a call
|
||||
* to read() will still block.
|
||||
*
|
||||
* @return true if instruction data is available for reading, false
|
||||
* otherwise.
|
||||
* @throws GuacamoleException If an error occurs while checking for
|
||||
* available data.
|
||||
*/
|
||||
public boolean available() throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Reads at least one complete Guacamole instruction, returning a buffer
|
||||
* containing one or more complete Guacamole instructions and no
|
||||
* incomplete Guacamole instructions. This function will block until at
|
||||
* least one complete instruction is available.
|
||||
*
|
||||
* @return A buffer containing at least one complete Guacamole instruction,
|
||||
* or null if no more instructions are available for reading.
|
||||
* @throws GuacamoleException If an error occurs while reading from the
|
||||
* stream.
|
||||
*/
|
||||
public char[] read() throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Reads exactly one complete Guacamole instruction and returns the fully
|
||||
* parsed instruction.
|
||||
*
|
||||
* @return The next complete instruction from the stream, fully parsed, or
|
||||
* null if no more instructions are available for reading.
|
||||
* @throws GuacamoleException If an error occurs while reading from the
|
||||
* stream, or if the instruction cannot be
|
||||
* parsed.
|
||||
*/
|
||||
public GuacamoleInstruction readInstruction() throws GuacamoleException;
|
||||
|
||||
}
|
@@ -0,0 +1,85 @@
|
||||
|
||||
package org.glyptodon.guacamole.io;
|
||||
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is guacamole-common.
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleInstruction;
|
||||
|
||||
/**
|
||||
* Provides abstract and raw character write access to a stream of Guacamole
|
||||
* instructions.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public interface GuacamoleWriter {
|
||||
|
||||
/**
|
||||
* Writes a portion of the given array of characters to the Guacamole
|
||||
* instruction stream. The portion must contain only complete Guacamole
|
||||
* instructions.
|
||||
*
|
||||
* @param chunk An array of characters containing Guacamole instructions.
|
||||
* @param off The start offset of the portion of the array to write.
|
||||
* @param len The length of the portion of the array to write.
|
||||
* @throws GuacamoleException If an error occurred while writing the
|
||||
* portion of the array specified.
|
||||
*/
|
||||
public void write(char[] chunk, int off, int len) throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Writes the entire given array of characters to the Guacamole instruction
|
||||
* stream. The array must consist only of complete Guacamole instructions.
|
||||
*
|
||||
* @param chunk An array of characters consisting only of complete
|
||||
* Guacamole instructions.
|
||||
* @throws GuacamoleException If an error occurred while writing the
|
||||
* the specified array.
|
||||
*/
|
||||
public void write(char[] chunk) throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Writes the given fully parsed instruction to the Guacamole instruction
|
||||
* stream.
|
||||
*
|
||||
* @param instruction The Guacamole instruction to write.
|
||||
* @throws GuacamoleException If an error occurred while writing the
|
||||
* instruction.
|
||||
*/
|
||||
public void writeInstruction(GuacamoleInstruction instruction) throws GuacamoleException;
|
||||
|
||||
}
|
@@ -0,0 +1,276 @@
|
||||
|
||||
package org.glyptodon.guacamole.io;
|
||||
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is guacamole-common.
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleServerException;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleInstruction;
|
||||
|
||||
/**
|
||||
* A GuacamoleReader which wraps a standard Java Reader, using that Reader as
|
||||
* the Guacamole instruction stream.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class ReaderGuacamoleReader implements GuacamoleReader {
|
||||
|
||||
/**
|
||||
* Wrapped Reader to be used for all input.
|
||||
*/
|
||||
private Reader input;
|
||||
|
||||
/**
|
||||
* Creates a new ReaderGuacamoleReader which will use the given Reader as
|
||||
* the Guacamole instruction stream.
|
||||
*
|
||||
* @param input The Reader to use as the Guacamole instruction stream.
|
||||
*/
|
||||
public ReaderGuacamoleReader(Reader input) {
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
/**
|
||||
* The location within the received data buffer that parsing should begin
|
||||
* when more data is read.
|
||||
*/
|
||||
private int parseStart;
|
||||
|
||||
/**
|
||||
* The buffer holding all received, unparsed data.
|
||||
*/
|
||||
private char[] buffer = new char[20480];
|
||||
|
||||
/**
|
||||
* The number of characters currently used within the data buffer. All
|
||||
* other characters within the buffer are free space available for
|
||||
* future reads.
|
||||
*/
|
||||
private int usedLength = 0;
|
||||
|
||||
@Override
|
||||
public boolean available() throws GuacamoleException {
|
||||
try {
|
||||
return input.ready() || usedLength != 0;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new GuacamoleServerException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] read() throws GuacamoleException {
|
||||
|
||||
try {
|
||||
|
||||
// While we're blocking, or input is available
|
||||
for (;;) {
|
||||
|
||||
// Length of element
|
||||
int elementLength = 0;
|
||||
|
||||
// Resume where we left off
|
||||
int i = parseStart;
|
||||
|
||||
// Parse instruction in buffer
|
||||
while (i < usedLength) {
|
||||
|
||||
// Read character
|
||||
char readChar = buffer[i++];
|
||||
|
||||
// If digit, update length
|
||||
if (readChar >= '0' && readChar <= '9')
|
||||
elementLength = elementLength * 10 + readChar - '0';
|
||||
|
||||
// If not digit, check for end-of-length character
|
||||
else if (readChar == '.') {
|
||||
|
||||
// Check if element present in buffer
|
||||
if (i + elementLength < usedLength) {
|
||||
|
||||
// Get terminator
|
||||
char terminator = buffer[i + elementLength];
|
||||
|
||||
// Move to character after terminator
|
||||
i += elementLength + 1;
|
||||
|
||||
// Reset length
|
||||
elementLength = 0;
|
||||
|
||||
// Continue here if necessary
|
||||
parseStart = i;
|
||||
|
||||
// If terminator is semicolon, we have a full
|
||||
// instruction.
|
||||
if (terminator == ';') {
|
||||
|
||||
// Copy instruction data
|
||||
char[] instruction = new char[i];
|
||||
System.arraycopy(buffer, 0, instruction, 0, i);
|
||||
|
||||
// Update buffer
|
||||
usedLength -= i;
|
||||
parseStart = 0;
|
||||
System.arraycopy(buffer, i, buffer, 0, usedLength);
|
||||
|
||||
return instruction;
|
||||
|
||||
}
|
||||
|
||||
// Handle invalid terminator characters
|
||||
else if (terminator != ',')
|
||||
throw new GuacamoleServerException("Element terminator of instruction was not ';' nor ','");
|
||||
|
||||
}
|
||||
|
||||
// Otherwise, read more data
|
||||
else
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// Otherwise, parse error
|
||||
else
|
||||
throw new GuacamoleServerException("Non-numeric character in element length.");
|
||||
|
||||
}
|
||||
|
||||
// If past threshold, resize buffer before reading
|
||||
if (usedLength > buffer.length/2) {
|
||||
char[] biggerBuffer = new char[buffer.length*2];
|
||||
System.arraycopy(buffer, 0, biggerBuffer, 0, usedLength);
|
||||
buffer = biggerBuffer;
|
||||
}
|
||||
|
||||
// Attempt to fill buffer
|
||||
int numRead = input.read(buffer, usedLength, buffer.length - usedLength);
|
||||
if (numRead == -1)
|
||||
return null;
|
||||
|
||||
// Update used length
|
||||
usedLength += numRead;
|
||||
|
||||
} // End read loop
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new GuacamoleServerException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuacamoleInstruction readInstruction() throws GuacamoleException {
|
||||
|
||||
// Get instruction
|
||||
char[] instructionBuffer = read();
|
||||
|
||||
// If EOF, return EOF
|
||||
if (instructionBuffer == null)
|
||||
return null;
|
||||
|
||||
// Start of element
|
||||
int elementStart = 0;
|
||||
|
||||
// Build list of elements
|
||||
Deque<String> elements = new LinkedList<String>();
|
||||
while (elementStart < instructionBuffer.length) {
|
||||
|
||||
// Find end of length
|
||||
int lengthEnd = -1;
|
||||
for (int i=elementStart; i<instructionBuffer.length; i++) {
|
||||
if (instructionBuffer[i] == '.') {
|
||||
lengthEnd = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// read() is required to return a complete instruction. If it does
|
||||
// not, this is a severe internal error.
|
||||
if (lengthEnd == -1)
|
||||
throw new GuacamoleServerException("Read returned incomplete instruction.");
|
||||
|
||||
// Parse length
|
||||
int length = Integer.parseInt(new String(
|
||||
instructionBuffer,
|
||||
elementStart,
|
||||
lengthEnd - elementStart
|
||||
));
|
||||
|
||||
// Parse element from just after period
|
||||
elementStart = lengthEnd + 1;
|
||||
String element = new String(
|
||||
instructionBuffer,
|
||||
elementStart,
|
||||
length
|
||||
);
|
||||
|
||||
// Append element to list of elements
|
||||
elements.addLast(element);
|
||||
|
||||
// Read terminator after element
|
||||
elementStart += length;
|
||||
char terminator = instructionBuffer[elementStart];
|
||||
|
||||
// Continue reading instructions after terminator
|
||||
elementStart++;
|
||||
|
||||
// If we've reached the end of the instruction
|
||||
if (terminator == ';')
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// Pull opcode off elements list
|
||||
String opcode = elements.removeFirst();
|
||||
|
||||
// Create instruction
|
||||
GuacamoleInstruction instruction = new GuacamoleInstruction(
|
||||
opcode,
|
||||
elements.toArray(new String[elements.size()])
|
||||
);
|
||||
|
||||
// Return parsed instruction
|
||||
return instruction;
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
|
||||
package org.glyptodon.guacamole.io;
|
||||
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is guacamole-common.
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleServerException;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleInstruction;
|
||||
|
||||
/**
|
||||
* A GuacamoleWriter which wraps a standard Java Writer, using that Writer as
|
||||
* the Guacamole instruction stream.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class WriterGuacamoleWriter implements GuacamoleWriter {
|
||||
|
||||
/**
|
||||
* Wrapped Writer to be used for all output.
|
||||
*/
|
||||
private Writer output;
|
||||
|
||||
/**
|
||||
* Creates a new WriterGuacamoleWriter which will use the given Writer as
|
||||
* the Guacamole instruction stream.
|
||||
*
|
||||
* @param output The Writer to use as the Guacamole instruction stream.
|
||||
*/
|
||||
public WriterGuacamoleWriter(Writer output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(char[] chunk, int off, int len) throws GuacamoleException {
|
||||
try {
|
||||
output.write(chunk, off, len);
|
||||
output.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new GuacamoleServerException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(char[] chunk) throws GuacamoleException {
|
||||
write(chunk, 0, chunk.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeInstruction(GuacamoleInstruction instruction) throws GuacamoleException {
|
||||
write(instruction.toString().toCharArray());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
|
||||
/**
|
||||
* All classes relating directly to data input or output.
|
||||
*/
|
||||
package org.glyptodon.guacamole.io;
|
||||
|
Reference in New Issue
Block a user