mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
Restored old VNC client as a LegacyClient
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
|
||||
package net.sourceforge.guacamole;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import net.sourceforge.guacamole.instruction.Instruction;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.event.KeyEvent;
|
||||
import net.sourceforge.guacamole.event.PointerEvent;
|
||||
|
||||
public abstract class LegacyClient {
|
||||
|
||||
public abstract void send(KeyEvent event) throws GuacamoleException;
|
||||
public abstract void send(PointerEvent event) throws GuacamoleException;
|
||||
public abstract void setClipboard(String clipboard) throws GuacamoleException;
|
||||
public abstract void disconnect() throws GuacamoleException;
|
||||
public abstract Instruction nextInstruction(boolean blocking) throws GuacamoleException;
|
||||
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
|
||||
package net.sourceforge.guacamole.instruction;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
public class ClipboardInstruction extends Instruction {
|
||||
|
||||
private String data;
|
||||
|
||||
public ClipboardInstruction(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "clipboard:" + escape(getData()) + ";";
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
|
||||
package net.sourceforge.guacamole.instruction;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
public class ErrorInstruction extends Instruction {
|
||||
|
||||
private String error;
|
||||
|
||||
public ErrorInstruction(String error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "error:" + escape(getError()) + ";";
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
|
||||
package net.sourceforge.guacamole.instruction;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
public abstract class Instruction {
|
||||
|
||||
|
||||
// All Instructions must provide a toString() implementation
|
||||
// which returns the properly formatted instruction:
|
||||
// OPCODE:parm1,parm2,...,parmN;
|
||||
|
||||
@Override
|
||||
public abstract String toString();
|
||||
|
||||
public String escape(String str) {
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
for (int i=0; i<str.length(); i++) {
|
||||
|
||||
char c = str.charAt(i);
|
||||
|
||||
switch (c) {
|
||||
case ',':
|
||||
sb.append("\\c");
|
||||
break;
|
||||
|
||||
case ';':
|
||||
sb.append("\\s");
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
sb.append("\\\\");
|
||||
break;
|
||||
|
||||
default:
|
||||
sb.append(c);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
|
||||
package net.sourceforge.guacamole.instruction;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
public class NameInstruction extends Instruction {
|
||||
|
||||
private String name;
|
||||
|
||||
public NameInstruction(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "name:" + escape(getName()) + ";";
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
|
||||
package net.sourceforge.guacamole.instruction;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
public class SizeInstruction extends Instruction {
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public SizeInstruction(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "size:"
|
||||
+ getWidth() + ","
|
||||
+ getHeight() + ";";
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
|
||||
package net.sourceforge.guacamole.instruction.framebuffer;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import net.sourceforge.guacamole.instruction.Instruction;
|
||||
|
||||
public class CopyRectInstruction extends Instruction {
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
private final int srcX;
|
||||
private final int srcY;
|
||||
|
||||
public CopyRectInstruction(int x, int y, int width, int height, int srcX, int srcY) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.srcX = srcX;
|
||||
this.srcY = srcY;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getSrcX() {
|
||||
return srcX;
|
||||
}
|
||||
|
||||
public int getSrcY() {
|
||||
return srcY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "copy:"
|
||||
+ getSrcX() + ","
|
||||
+ getSrcY() + ","
|
||||
+ getWidth() + ","
|
||||
+ getHeight() + ","
|
||||
+ getX() + ","
|
||||
+ getY() + ";";
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
package net.sourceforge.guacamole.instruction.framebuffer;
|
||||
|
||||
import net.sourceforge.guacamole.net.Base64;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import net.sourceforge.guacamole.instruction.Instruction;
|
||||
|
||||
public class CursorInstruction extends Instruction {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private PNGImage image;
|
||||
|
||||
public CursorInstruction(int x, int y, PNGImage image) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public PNGImage getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return getImage().getWidth();
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return getImage().getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "cursor:"
|
||||
+ getX() + ","
|
||||
+ getY() + ","
|
||||
+ Base64.toString(getImage().getData()) + ";";
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
|
||||
package net.sourceforge.guacamole.instruction.framebuffer;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import net.sourceforge.guacamole.instruction.Instruction;
|
||||
|
||||
public class DrawRectInstruction extends Instruction {
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int color;
|
||||
|
||||
public DrawRectInstruction(int x, int y, int width, int height, int color) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
return "rect:"
|
||||
+ getX() + ","
|
||||
+ getY() + ","
|
||||
+ getWidth() + ","
|
||||
+ getHeight() + ","
|
||||
+ String.format("#%06X", getColor()) + ";";
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
package net.sourceforge.guacamole.instruction.framebuffer;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Iterator;
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
|
||||
public class PNGImage {
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
private byte[] data;
|
||||
|
||||
public PNGImage(BufferedImage image) throws GuacamoleException {
|
||||
|
||||
width = image.getWidth();
|
||||
height = image.getHeight();
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
writeImage(image, bos);
|
||||
bos.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new GuacamoleException("I/O Error while creating PNG.", e);
|
||||
}
|
||||
|
||||
data = bos.toByteArray();
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
private static void writeImage(BufferedImage image, OutputStream outputStream) throws GuacamoleException, IOException {
|
||||
|
||||
// Obtain list of image writers
|
||||
// If no such writers exist, fail with error, exit.
|
||||
Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType("image/png");
|
||||
if (!writers.hasNext())
|
||||
throw new GuacamoleException("No useful image writers found.");
|
||||
|
||||
// Obtain JPEG writer
|
||||
ImageWriter imageWriter = writers.next();
|
||||
|
||||
// Setup image parameters (including compression quality)
|
||||
/*ImageWriteParam imageParameters = new JPEGImageWriteParam(Locale.ENGLISH);
|
||||
imageParameters.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
imageParameters.setCompressionQuality(0.6f); // 60% quality, currently...
|
||||
imageParameters.setProgressiveMode(ImageWriteParam.MODE_DEFAULT);*/
|
||||
|
||||
ImageOutputStream out = ImageIO.createImageOutputStream(outputStream);
|
||||
|
||||
// Write image
|
||||
imageWriter.setOutput(out);
|
||||
imageWriter.write(null, new IIOImage(image, null, null), null/*imageParameters*/);
|
||||
imageWriter.dispose();
|
||||
|
||||
out.flush();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
package net.sourceforge.guacamole.instruction.framebuffer;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import net.sourceforge.guacamole.instruction.Instruction;
|
||||
import net.sourceforge.guacamole.net.Base64;
|
||||
|
||||
public class PNGInstruction extends Instruction {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private PNGImage image;
|
||||
|
||||
public PNGInstruction(int x, int y, PNGImage image) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public PNGImage getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return getImage().getWidth();
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return getImage().getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "png:"
|
||||
+ getX() + ","
|
||||
+ getY() + ","
|
||||
+ Base64.toString(getImage().getData()) + ";";
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
|
||||
package net.sourceforge.guacamole.vnc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class InputOutputStream extends InputStream {
|
||||
|
||||
private int pos = 0;
|
||||
private byte[] current = null;
|
||||
private LinkedList<byte[]> buffer = new LinkedList<byte[]>();
|
||||
|
||||
public void write(byte[] data) {
|
||||
|
||||
if (data.length == 0)
|
||||
return;
|
||||
|
||||
if (current == null)
|
||||
current = data;
|
||||
else
|
||||
buffer.addLast(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
|
||||
if (pos >= current.length) {
|
||||
if (buffer.size() == 0)
|
||||
throw new IOException("Buffer underrun.");
|
||||
|
||||
current = buffer.removeFirst();
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
return 0xFF & current[pos++];
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] data) throws IOException {
|
||||
return read(data, 0, data.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] data, int off, int len) throws IOException {
|
||||
|
||||
if (pos >= current.length) {
|
||||
if (buffer.size() == 0)
|
||||
throw new IOException("Buffer underrun.");
|
||||
|
||||
current = buffer.removeFirst();
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
int amountRead = Math.min(current.length - pos, len);
|
||||
System.arraycopy(current, pos, data, off, amountRead);
|
||||
pos += amountRead;
|
||||
|
||||
return amountRead;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,60 @@
|
||||
|
||||
package net.sourceforge.guacamole.vnc;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import net.sourceforge.guacamole.net.Configuration;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
public class VNCConfiguration extends Configuration {
|
||||
|
||||
private String hostname;
|
||||
private int port;
|
||||
private String password;
|
||||
private int bpp;
|
||||
|
||||
public VNCConfiguration(ServletContext context) throws GuacamoleException {
|
||||
|
||||
super(context);
|
||||
|
||||
hostname = readParameter("host", null);
|
||||
port = readIntParameter("port", null);
|
||||
password = context.getInitParameter("password");
|
||||
bpp = readIntParameter("bpp", 24, 8, 16, 24);
|
||||
|
||||
}
|
||||
|
||||
public int getBPP() {
|
||||
return bpp;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
|
||||
package net.sourceforge.guacamole.vnc;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
public class VNCException extends Exception {
|
||||
|
||||
public VNCException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public VNCException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,239 @@
|
||||
package net.sourceforge.guacamole.vnc;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class VNCFullColorImageReader extends VNCImageReader {
|
||||
|
||||
private int bpp;
|
||||
private int depth;
|
||||
|
||||
private int redBits;
|
||||
private int greenBits;
|
||||
private int blueBits;
|
||||
|
||||
private int redMax;
|
||||
private int greenMax;
|
||||
private int blueMax;
|
||||
|
||||
private int redShift;
|
||||
private int greenShift;
|
||||
private int blueShift;
|
||||
|
||||
private boolean readAsIndexed;
|
||||
private boolean bigEndian;
|
||||
|
||||
private boolean swapRedAndBlue;
|
||||
|
||||
public boolean isBigEndian() {
|
||||
return bigEndian;
|
||||
}
|
||||
|
||||
public int getBitsPerPixel() {
|
||||
return bpp;
|
||||
}
|
||||
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
public int getRedMax() {
|
||||
return redMax;
|
||||
}
|
||||
|
||||
public int getGreenMax() {
|
||||
return greenMax;
|
||||
}
|
||||
|
||||
public int getBlueMax() {
|
||||
return blueMax;
|
||||
}
|
||||
|
||||
public int getRedShift() {
|
||||
return redShift;
|
||||
}
|
||||
|
||||
public int getGreenShift() {
|
||||
return greenShift;
|
||||
}
|
||||
|
||||
public int getBlueShift() {
|
||||
return blueShift;
|
||||
}
|
||||
|
||||
// Set up BGR reader
|
||||
public VNCFullColorImageReader(boolean bigEndian, int redBits, int greenBits, int blueBits, int outputBPP, boolean swapRedAndBlue) throws VNCException {
|
||||
|
||||
this.swapRedAndBlue = swapRedAndBlue;
|
||||
|
||||
depth = redBits + greenBits + blueBits;
|
||||
|
||||
if (depth > 0 && depth <= 8)
|
||||
bpp = 8;
|
||||
else if (depth <= 16)
|
||||
bpp = 16;
|
||||
else if (depth <= 32)
|
||||
bpp = 32;
|
||||
else
|
||||
throw new VNCException("Illegal bit depth for VNC images: " + bpp);
|
||||
|
||||
this.redBits = redBits;
|
||||
this.greenBits = greenBits;
|
||||
this.blueBits = blueBits;
|
||||
|
||||
blueMax = (1 << blueBits) - 1;
|
||||
greenMax = (1 << greenBits) - 1;
|
||||
redMax = (1 << redBits) - 1;
|
||||
|
||||
redShift = greenBits + blueBits;
|
||||
greenShift = blueBits;
|
||||
blueShift = 0;
|
||||
|
||||
if (outputBPP == 8)
|
||||
this.readAsIndexed = true;
|
||||
else if (outputBPP == 24)
|
||||
this.readAsIndexed = false;
|
||||
else
|
||||
throw new VNCException("Only 8-bit or 24-bit output is supported.");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readCPixel(DataInputStream input) throws IOException {
|
||||
|
||||
if (redBits != 8 || greenBits != 8 || blueBits != 8)
|
||||
return readPixel(input);
|
||||
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
|
||||
if (bigEndian) {
|
||||
red = input.read();
|
||||
green = input.read();
|
||||
blue = input.read();
|
||||
}
|
||||
else {
|
||||
blue = input.read();
|
||||
green = input.read();
|
||||
red = input.read();
|
||||
}
|
||||
|
||||
if (swapRedAndBlue)
|
||||
return (blue << 16) | (green << 8) | red;
|
||||
else
|
||||
return (red << 16) | (green << 8) | blue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readPixel(DataInputStream input) throws IOException {
|
||||
int value;
|
||||
switch (bpp) {
|
||||
case 8:
|
||||
value = input.read();
|
||||
break;
|
||||
case 16:
|
||||
|
||||
short inputShort = input.readShort();
|
||||
if (!bigEndian) inputShort = Short.reverseBytes(inputShort);
|
||||
|
||||
value = inputShort;
|
||||
break;
|
||||
case 32:
|
||||
|
||||
int inputInt = input.readInt();
|
||||
if (!bigEndian) inputInt = Integer.reverseBytes(inputInt);
|
||||
|
||||
value = inputInt;
|
||||
break;
|
||||
default:
|
||||
throw new IOException("Invalid BPP.");
|
||||
}
|
||||
|
||||
int red = (value >> redShift) & redMax;
|
||||
int green = (value >> greenShift) & greenMax;
|
||||
int blue = (value >> blueShift) & blueMax;
|
||||
|
||||
red <<= 8 - redBits;
|
||||
green <<= 8 - greenBits;
|
||||
blue <<= 8 - blueBits;
|
||||
|
||||
if (swapRedAndBlue)
|
||||
return (blue << 16) | (green << 8) | red;
|
||||
else
|
||||
return (red << 16) | (green << 8) | blue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage generateBlankImage(int width, int height) {
|
||||
if (readAsIndexed)
|
||||
return new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, COLOR_MODEL);
|
||||
return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
|
||||
// Load color model
|
||||
public static final IndexColorModel COLOR_MODEL;
|
||||
static {
|
||||
// Construct color model
|
||||
byte[] colorShade = {0, (byte) 51, (byte) 104, (byte) 153, (byte) 204, (byte) 255};
|
||||
byte[] greyShade = new byte[39];
|
||||
for (int i=1; i<40; i++)
|
||||
greyShade[i-1] = (byte) (6*i);
|
||||
|
||||
byte[] red = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
|
||||
byte[] green = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
|
||||
byte[] blue = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
|
||||
byte[] alpha = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
|
||||
|
||||
int color = 0;
|
||||
for (int r=0; r<colorShade.length; r++) {
|
||||
for (int g=0; g<colorShade.length; g++) {
|
||||
for (int b=0; b<colorShade.length; b++) {
|
||||
red[color] = colorShade[r];
|
||||
green[color] = colorShade[g];
|
||||
blue[color] = colorShade[b];
|
||||
alpha[color] = (byte) 255;
|
||||
color++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int grey=0; grey<greyShade.length; grey++) {
|
||||
red[color] = greyShade[grey];
|
||||
green[color] = greyShade[grey];
|
||||
blue[color] = greyShade[grey];
|
||||
alpha[color] = (byte) 255;
|
||||
color++;
|
||||
}
|
||||
|
||||
red[color] = 0;
|
||||
green[color] = 0;
|
||||
blue[color] = 0;
|
||||
alpha[color] = (byte) 0;
|
||||
|
||||
COLOR_MODEL = new IndexColorModel(8, 256, red, green, blue, alpha);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,64 @@
|
||||
package net.sourceforge.guacamole.vnc;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class VNCImageReader {
|
||||
|
||||
public BufferedImage readCImage(DataInputStream input, int width, int height) throws IOException {
|
||||
|
||||
BufferedImage image = generateBlankImage(width, height);
|
||||
// Read image
|
||||
|
||||
for (int pixelY=0; pixelY<height; pixelY++) {
|
||||
for (int pixelX=0; pixelX<width; pixelX++) {
|
||||
int color = 0xFF000000 | readCPixel(input);
|
||||
image.setRGB(pixelX, pixelY, color);
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
public BufferedImage readImage(DataInputStream input, int width, int height) throws IOException {
|
||||
|
||||
BufferedImage image = generateBlankImage(width, height);
|
||||
// Read image
|
||||
|
||||
for (int pixelY=0; pixelY<height; pixelY++) {
|
||||
for (int pixelX=0; pixelX<width; pixelX++) {
|
||||
int color = 0xFF000000 | readPixel(input);
|
||||
image.setRGB(pixelX, pixelY, color);
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
public abstract BufferedImage generateBlankImage(int width, int height);
|
||||
public abstract int readPixel(DataInputStream input) throws IOException;
|
||||
public int readCPixel(DataInputStream input) throws IOException {
|
||||
return readPixel(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,104 @@
|
||||
package net.sourceforge.guacamole.vnc;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class VNCIndexedImageReader extends VNCImageReader {
|
||||
|
||||
private IndexColorModel palette;
|
||||
private byte[] red;
|
||||
private byte[] green;
|
||||
private byte[] blue;
|
||||
|
||||
// Set up BGR reader
|
||||
public VNCIndexedImageReader(byte[] red, byte[] green, byte[] blue) throws VNCException {
|
||||
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
|
||||
palette = new IndexColorModel(8, 256, red, green, blue);
|
||||
if (palette.getMapSize() != 256)
|
||||
throw new VNCException("Currently, only 256-color maps are supported.");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readPixel(DataInputStream input) throws IOException {
|
||||
int value = input.read();
|
||||
int color = (red[value] << 16) | (green[value] << 8) | blue[value];
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage generateBlankImage(int width, int height) {
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, palette);
|
||||
return image;
|
||||
}
|
||||
|
||||
// Load color model
|
||||
public static final IndexColorModel COLOR_MODEL;
|
||||
static {
|
||||
// Construct color model
|
||||
byte[] colorShade = {0, (byte) 51, (byte) 104, (byte) 153, (byte) 204, (byte) 255};
|
||||
byte[] greyShade = new byte[39];
|
||||
for (int i=1; i<40; i++)
|
||||
greyShade[i-1] = (byte) (6*i);
|
||||
|
||||
byte[] red = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
|
||||
byte[] green = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
|
||||
byte[] blue = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
|
||||
byte[] alpha = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
|
||||
|
||||
int color = 0;
|
||||
for (int r=0; r<colorShade.length; r++) {
|
||||
for (int g=0; g<colorShade.length; g++) {
|
||||
for (int b=0; b<colorShade.length; b++) {
|
||||
red[color] = colorShade[r];
|
||||
green[color] = colorShade[g];
|
||||
blue[color] = colorShade[b];
|
||||
alpha[color] = (byte) 255;
|
||||
color++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int grey=0; grey<greyShade.length; grey++) {
|
||||
red[color] = greyShade[grey];
|
||||
green[color] = greyShade[grey];
|
||||
blue[color] = greyShade[grey];
|
||||
alpha[color] = (byte) 255;
|
||||
color++;
|
||||
}
|
||||
|
||||
red[color] = 0;
|
||||
green[color] = 0;
|
||||
blue[color] = 0;
|
||||
alpha[color] = (byte) 0;
|
||||
|
||||
COLOR_MODEL = new IndexColorModel(8, 256, red, green, blue, alpha);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user