You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mi...@apache.org on 2012/09/08 03:24:27 UTC
[4/6] CLOUDSTACK-61 Console proxy has plenty of files with CRLF line
ending.
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/BufferedImageCanvas.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/BufferedImageCanvas.java b/console-proxy/src/com/cloud/consoleproxy/vnc/BufferedImageCanvas.java
index a92131f..f2fb4bb 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/BufferedImageCanvas.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/BufferedImageCanvas.java
@@ -30,125 +30,121 @@ import com.cloud.consoleproxy.util.ImageHelper;
import com.cloud.consoleproxy.util.TileInfo;
/**
- * A <code>BuffereImageCanvas</code> component represents frame buffer image on the
- * screen. It also notifies its subscribers when screen is repainted.
+ * A <code>BuffereImageCanvas</code> component represents frame buffer image on
+ * the screen. It also notifies its subscribers when screen is repainted.
*/
public class BufferedImageCanvas extends Canvas implements FrameBufferCanvas {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- // Offline screen buffer
- private BufferedImage offlineImage;
-
- // Cached Graphics2D object for offline screen buffer
- private Graphics2D graphics;
+ // Offline screen buffer
+ private BufferedImage offlineImage;
- private PaintNotificationListener listener;
+ // Cached Graphics2D object for offline screen buffer
+ private Graphics2D graphics;
- public BufferedImageCanvas(PaintNotificationListener listener, int width, int height) {
- super();
- this.listener = listener;
+ private PaintNotificationListener listener;
- setBackground(Color.black);
-
- setFocusable(true);
+ public BufferedImageCanvas(PaintNotificationListener listener, int width, int height) {
+ super();
+ this.listener = listener;
- // Don't intercept TAB key
- setFocusTraversalKeysEnabled(false);
+ setBackground(Color.black);
- setCanvasSize(width, height);
- }
+ setFocusable(true);
- public void setCanvasSize(int width, int height) {
- this.offlineImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
- graphics = offlineImage.createGraphics();
+ // Don't intercept TAB key
+ setFocusTraversalKeysEnabled(false);
- setSize(offlineImage.getWidth(), offlineImage.getHeight());
- }
+ setCanvasSize(width, height);
+ }
+
+ public void setCanvasSize(int width, int height) {
+ this.offlineImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+ graphics = offlineImage.createGraphics();
+
+ setSize(offlineImage.getWidth(), offlineImage.getHeight());
+ }
+
+ @Override
+ public void update(Graphics g) {
+ // Call paint() directly, without clearing screen first
+ paint(g);
+ }
+
+ @Override
+ public void paint(Graphics g) {
+ // Only part of image, requested with repaint(Rectangle), will be
+ // painted on screen.
+ synchronized (offlineImage) {
+ g.drawImage(offlineImage, 0, 0, this);
+ }
+ // Notify server that update is painted on screen
+ listener.imagePaintedOnScreen();
+ }
+
+ public BufferedImage getOfflineImage() {
+ return offlineImage;
+ }
+
+ public Graphics2D getOfflineGraphics() {
+ return graphics;
+ }
+
+ public void copyTile(Graphics2D g, int x, int y, Rectangle rc) {
+ synchronized (offlineImage) {
+ g.drawImage(offlineImage, x, y, x + rc.width, y + rc.height, rc.x, rc.y, rc.x + rc.width, rc.y + rc.height, null);
+ }
+ }
+
+ @Override
+ public Image getFrameBufferScaledImage(int width, int height) {
+ if (offlineImage != null)
+ return offlineImage.getScaledInstance(width, height, Image.SCALE_DEFAULT);
+ return null;
+ }
+
+ @Override
+ public byte[] getFrameBufferJpeg() {
+ int width = 800;
+ int height = 600;
+
+ width = offlineImage.getWidth();
+ height = offlineImage.getHeight();
+
+ BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
+ Graphics2D g = bufferedImage.createGraphics();
+ synchronized (offlineImage) {
+ g.drawImage(offlineImage, 0, 0, width, height, 0, 0, width, height, null);
+ }
+
+ byte[] imgBits = null;
+ try {
+ imgBits = ImageHelper.jpegFromImage(bufferedImage);
+ } catch (IOException e) {
+ }
+ return imgBits;
+ }
+
+ @Override
+ public byte[] getTilesMergedJpeg(List<TileInfo> tileList, int tileWidth, int tileHeight) {
+ int width = Math.max(tileWidth, tileWidth * tileList.size());
+ BufferedImage bufferedImage = new BufferedImage(width, tileHeight, BufferedImage.TYPE_3BYTE_BGR);
+ Graphics2D g = bufferedImage.createGraphics();
- @Override
- public void update(Graphics g) {
- // Call paint() directly, without clearing screen first
- paint(g);
- }
+ synchronized (offlineImage) {
+ int i = 0;
+ for (TileInfo tile : tileList) {
+ Rectangle rc = tile.getTileRect();
+ g.drawImage(offlineImage, i * tileWidth, 0, i * tileWidth + rc.width, rc.height, rc.x, rc.y, rc.x + rc.width, rc.y + rc.height, null);
+ i++;
+ }
+ }
- @Override
- public void paint(Graphics g) {
- // Only part of image, requested with repaint(Rectangle), will be
- // painted on screen.
- synchronized(offlineImage) {
- g.drawImage(offlineImage, 0, 0, this);
+ byte[] imgBits = null;
+ try {
+ imgBits = ImageHelper.jpegFromImage(bufferedImage);
+ } catch (IOException e) {
+ }
+ return imgBits;
}
- // Notify server that update is painted on screen
- listener.imagePaintedOnScreen();
- }
-
- public BufferedImage getOfflineImage() {
- return offlineImage;
- }
-
- public Graphics2D getOfflineGraphics() {
- return graphics;
- }
-
- public void copyTile(Graphics2D g, int x, int y, Rectangle rc) {
- synchronized(offlineImage) {
- g.drawImage(offlineImage, x, y, x + rc.width, y + rc.height,
- rc.x, rc.y, rc.x + rc.width, rc.y + rc.height, null);
- }
- }
-
- @Override
- public Image getFrameBufferScaledImage(int width, int height) {
- if(offlineImage != null)
- return offlineImage.getScaledInstance(width, height, Image.SCALE_DEFAULT);
- return null;
- }
-
- @Override
- public byte[] getFrameBufferJpeg() {
- int width = 800;
- int height = 600;
-
- width = offlineImage.getWidth();
- height = offlineImage.getHeight();
-
- BufferedImage bufferedImage = new BufferedImage(width, height,
- BufferedImage.TYPE_3BYTE_BGR);
- Graphics2D g = bufferedImage.createGraphics();
- synchronized(offlineImage) {
- g.drawImage(offlineImage, 0, 0, width, height, 0, 0, width, height, null);
- }
-
- byte[] imgBits = null;
- try {
- imgBits = ImageHelper.jpegFromImage(bufferedImage);
- } catch (IOException e) {
- }
- return imgBits;
- }
-
- @Override
- public byte[] getTilesMergedJpeg(List<TileInfo> tileList, int tileWidth, int tileHeight) {
- int width = Math.max(tileWidth, tileWidth*tileList.size());
- BufferedImage bufferedImage = new BufferedImage(width, tileHeight,
- BufferedImage.TYPE_3BYTE_BGR);
- Graphics2D g = bufferedImage.createGraphics();
-
- synchronized(offlineImage) {
- int i = 0;
- for(TileInfo tile : tileList) {
- Rectangle rc = tile.getTileRect();
- g.drawImage(offlineImage, i*tileWidth, 0, i*tileWidth + rc.width, rc.height,
- rc.x, rc.y, rc.x + rc.width, rc.y + rc.height, null);
- i++;
- }
- }
-
- byte[] imgBits = null;
- try {
- imgBits = ImageHelper.jpegFromImage(bufferedImage);
- } catch (IOException e) {
- }
- return imgBits;
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/FrameBufferCanvas.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/FrameBufferCanvas.java b/console-proxy/src/com/cloud/consoleproxy/vnc/FrameBufferCanvas.java
index 3b72f44..dcf1146 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/FrameBufferCanvas.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/FrameBufferCanvas.java
@@ -14,15 +14,17 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-package com.cloud.consoleproxy.vnc;
-
-import java.awt.Image;
-import java.util.List;
-
-import com.cloud.consoleproxy.util.TileInfo;
-
-public interface FrameBufferCanvas {
- Image getFrameBufferScaledImage(int width, int height);
- public byte[] getFrameBufferJpeg();
- public byte[] getTilesMergedJpeg(List<TileInfo> tileList, int tileWidth, int tileHeight);
-}
+package com.cloud.consoleproxy.vnc;
+
+import java.awt.Image;
+import java.util.List;
+
+import com.cloud.consoleproxy.util.TileInfo;
+
+public interface FrameBufferCanvas {
+ Image getFrameBufferScaledImage(int width, int height);
+
+ public byte[] getFrameBufferJpeg();
+
+ public byte[] getTilesMergedJpeg(List<TileInfo> tileList, int tileWidth, int tileHeight);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/FrameBufferUpdateListener.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/FrameBufferUpdateListener.java b/console-proxy/src/com/cloud/consoleproxy/vnc/FrameBufferUpdateListener.java
index 8dbbe99..b8527c5 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/FrameBufferUpdateListener.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/FrameBufferUpdateListener.java
@@ -18,9 +18,9 @@ package com.cloud.consoleproxy.vnc;
public interface FrameBufferUpdateListener {
- /**
- * Notify listener, that frame buffer update packet is received, so client is
- * permitted (but not obligated) to ask server to send another update.
- */
- void frameBufferPacketReceived();
+ /**
+ * Notify listener, that frame buffer update packet is received, so client
+ * is permitted (but not obligated) to ask server to send another update.
+ */
+ void frameBufferPacketReceived();
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/PaintNotificationListener.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/PaintNotificationListener.java b/console-proxy/src/com/cloud/consoleproxy/vnc/PaintNotificationListener.java
index e3bd4af..aaefacb 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/PaintNotificationListener.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/PaintNotificationListener.java
@@ -18,10 +18,10 @@ package com.cloud.consoleproxy.vnc;
public interface PaintNotificationListener {
- /**
- * Notify subscriber that screen is updated, so client can send another frame
- * buffer update request to server.
- */
- void imagePaintedOnScreen();
+ /**
+ * Notify subscriber that screen is updated, so client can send another
+ * frame buffer update request to server.
+ */
+ void imagePaintedOnScreen();
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/RfbConstants.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/RfbConstants.java b/console-proxy/src/com/cloud/consoleproxy/vnc/RfbConstants.java
index 75499b8..18bf47e 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/RfbConstants.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/RfbConstants.java
@@ -20,62 +20,63 @@ import java.nio.charset.Charset;
public interface RfbConstants {
- public static final String RFB_PROTOCOL_VERSION_MAJOR = "RFB 003.";
-// public static final String VNC_PROTOCOL_VERSION_MINOR = "003";
- public static final String VNC_PROTOCOL_VERSION_MINOR = "003";
- public static final String RFB_PROTOCOL_VERSION = RFB_PROTOCOL_VERSION_MAJOR + VNC_PROTOCOL_VERSION_MINOR;
-
- /**
- * Server message types.
- */
- final static int SERVER_FRAMEBUFFER_UPDATE = 0, SERVER_SET_COLOURMAP_ENTRIES = 1, SERVER_BELL = 2, SERVER_CUT_TEXT = 3;
-
- /**
- * Client message types.
- */
- public static final int CLIENT_SET_PIXEL_FORMAT = 0, CLIENT_FIX_COLOURMAP_ENTRIES = 1, CLIENT_SET_ENCODINGS = 2, CLIENT_FRAMEBUFFER_UPDATE_REQUEST = 3,
- CLIENT_KEYBOARD_EVENT = 4, CLIENT_POINTER_EVENT = 5, CLIENT_CUT_TEXT = 6;
-
- /**
- * Server authorization type
- */
- public final static int CONNECTION_FAILED = 0, NO_AUTH = 1, VNC_AUTH = 2;
-
- /**
- * Server authorization reply.
- */
- public final static int VNC_AUTH_OK = 0, VNC_AUTH_FAILED = 1, VNC_AUTH_TOO_MANY = 2;
-
- /**
- * Encodings.
- */
- public final static int ENCODING_RAW = 0, ENCODING_COPY_RECT = 1, ENCODING_RRE = 2, ENCODING_CO_RRE = 4, ENCODING_HEXTILE = 5, ENCODING_ZRLE = 16;
-
- /**
- * Pseudo-encodings.
- */
- public final static int ENCODING_CURSOR = -239 /*0xFFFFFF11*/, ENCODING_DESKTOP_SIZE = -223 /*0xFFFFFF21*/;
-
- /**
- * Encodings, which we support.
- */
- public final static int[] SUPPORTED_ENCODINGS_ARRAY = { ENCODING_RAW, ENCODING_COPY_RECT, ENCODING_DESKTOP_SIZE };
-
- /**
- * Frame buffer update request type: update of whole screen or partial update.
- */
- public static final int FRAMEBUFFER_FULL_UPDATE_REQUEST = 0, FRAMEBUFFER_INCREMENTAL_UPDATE_REQUEST = 1;
-
- public static final int KEY_UP = 0, KEY_DOWN = 1;
-
- public static final int LITTLE_ENDIAN = 0, BIG_ENDIAN = 1;
-
- public static final int EXCLUSIVE_ACCESS = 0, SHARED_ACCESS = 1;
-
- public static final int PALETTE = 0, TRUE_COLOR = 1;
-
- /**
- * Default charset to use when communicating with server.
- */
- public static final Charset CHARSET = Charset.availableCharsets().get("US-ASCII");
+ public static final String RFB_PROTOCOL_VERSION_MAJOR = "RFB 003.";
+ // public static final String VNC_PROTOCOL_VERSION_MINOR = "003";
+ public static final String VNC_PROTOCOL_VERSION_MINOR = "003";
+ public static final String RFB_PROTOCOL_VERSION = RFB_PROTOCOL_VERSION_MAJOR + VNC_PROTOCOL_VERSION_MINOR;
+
+ /**
+ * Server message types.
+ */
+ final static int SERVER_FRAMEBUFFER_UPDATE = 0, SERVER_SET_COLOURMAP_ENTRIES = 1, SERVER_BELL = 2, SERVER_CUT_TEXT = 3;
+
+ /**
+ * Client message types.
+ */
+ public static final int CLIENT_SET_PIXEL_FORMAT = 0, CLIENT_FIX_COLOURMAP_ENTRIES = 1, CLIENT_SET_ENCODINGS = 2, CLIENT_FRAMEBUFFER_UPDATE_REQUEST = 3, CLIENT_KEYBOARD_EVENT = 4,
+ CLIENT_POINTER_EVENT = 5, CLIENT_CUT_TEXT = 6;
+
+ /**
+ * Server authorization type
+ */
+ public final static int CONNECTION_FAILED = 0, NO_AUTH = 1, VNC_AUTH = 2;
+
+ /**
+ * Server authorization reply.
+ */
+ public final static int VNC_AUTH_OK = 0, VNC_AUTH_FAILED = 1, VNC_AUTH_TOO_MANY = 2;
+
+ /**
+ * Encodings.
+ */
+ public final static int ENCODING_RAW = 0, ENCODING_COPY_RECT = 1, ENCODING_RRE = 2, ENCODING_CO_RRE = 4, ENCODING_HEXTILE = 5, ENCODING_ZRLE = 16;
+
+ /**
+ * Pseudo-encodings.
+ */
+ public final static int ENCODING_CURSOR = -239 /* 0xFFFFFF11 */, ENCODING_DESKTOP_SIZE = -223 /* 0xFFFFFF21 */;
+
+ /**
+ * Encodings, which we support.
+ */
+ public final static int[] SUPPORTED_ENCODINGS_ARRAY = { ENCODING_RAW, ENCODING_COPY_RECT, ENCODING_DESKTOP_SIZE };
+
+ /**
+ * Frame buffer update request type: update of whole screen or partial
+ * update.
+ */
+ public static final int FRAMEBUFFER_FULL_UPDATE_REQUEST = 0, FRAMEBUFFER_INCREMENTAL_UPDATE_REQUEST = 1;
+
+ public static final int KEY_UP = 0, KEY_DOWN = 1;
+
+ public static final int LITTLE_ENDIAN = 0, BIG_ENDIAN = 1;
+
+ public static final int EXCLUSIVE_ACCESS = 0, SHARED_ACCESS = 1;
+
+ public static final int PALETTE = 0, TRUE_COLOR = 1;
+
+ /**
+ * Default charset to use when communicating with server.
+ */
+ public static final Charset CHARSET = Charset.availableCharsets().get("US-ASCII");
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/VncClient.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/VncClient.java b/console-proxy/src/com/cloud/consoleproxy/vnc/VncClient.java
index abc9ffa..194eec1 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/VncClient.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/VncClient.java
@@ -39,414 +39,413 @@ import com.cloud.consoleproxy.vnc.packet.client.KeyboardEventPacket;
import com.cloud.consoleproxy.vnc.packet.client.MouseEventPacket;
public class VncClient {
- private static final Logger s_logger = Logger.getLogger(VncClient.class);
+ private static final Logger s_logger = Logger.getLogger(VncClient.class);
+
+ private Socket socket;
+ private DataInputStream is;
+ private DataOutputStream os;
+
+ private VncScreenDescription screen = new VncScreenDescription();
+
+ private VncClientPacketSender sender;
+ private VncServerPacketReceiver receiver;
+
+ private boolean noUI = false;
+ private ConsoleProxyClientListener clientListener = null;
+
+ public static void main(String args[]) {
+ if (args.length < 3) {
+ printHelpMessage();
+ System.exit(1);
+ }
+
+ String host = args[0];
+ String port = args[1];
+ String password = args[2];
+
+ try {
+ new VncClient(host, Integer.parseInt(port), password, false, null);
+ } catch (NumberFormatException e) {
+ s_logger.error("Incorrect VNC server port number: " + port + ".");
+ System.exit(1);
+ } catch (UnknownHostException e) {
+ s_logger.error("Incorrect VNC server host name: " + host + ".");
+ System.exit(1);
+ } catch (IOException e) {
+ s_logger.error("Cannot communicate with VNC server: " + e.getMessage());
+ System.exit(1);
+ } catch (Throwable e) {
+ s_logger.error("An error happened: " + e.getMessage());
+ System.exit(1);
+ }
+ System.exit(0);
+ }
- private Socket socket;
- private DataInputStream is;
- private DataOutputStream os;
+ private static void printHelpMessage() {
+ /* LOG */s_logger.info("Usage: HOST PORT PASSWORD.");
+ }
- private VncScreenDescription screen = new VncScreenDescription();
+ public VncClient(ConsoleProxyClientListener clientListener) {
+ this.noUI = true;
+ this.clientListener = clientListener;
+ }
- private VncClientPacketSender sender;
- private VncServerPacketReceiver receiver;
-
- private boolean noUI = false;
- private ConsoleProxyClientListener clientListener = null;
+ public VncClient(String host, int port, String password, boolean noUI, ConsoleProxyClientListener clientListener) throws UnknownHostException, IOException {
- public static void main(String args[]) {
- if (args.length < 3) {
- printHelpMessage();
- System.exit(1);
+ this.noUI = noUI;
+ this.clientListener = clientListener;
+ connectTo(host, port, password);
}
- String host = args[0];
- String port = args[1];
- String password = args[2];
-
- try {
- new VncClient(host, Integer.parseInt(port), password, false, null);
- } catch (NumberFormatException e) {
- s_logger.error("Incorrect VNC server port number: " + port + ".");
- System.exit(1);
- } catch (UnknownHostException e) {
- s_logger.error("Incorrect VNC server host name: " + host + ".");
- System.exit(1);
- } catch (IOException e) {
- s_logger.error("Cannot communicate with VNC server: " + e.getMessage());
- System.exit(1);
- } catch (Throwable e) {
- s_logger.error("An error happened: " + e.getMessage());
- System.exit(1);
- }
- System.exit(0);
- }
-
- private static void printHelpMessage() {
- /* LOG */s_logger.info("Usage: HOST PORT PASSWORD.");
- }
-
- public VncClient(ConsoleProxyClientListener clientListener) {
- this.noUI = true;
- this.clientListener = clientListener;
- }
-
- public VncClient(String host, int port, String password, boolean noUI, ConsoleProxyClientListener clientListener)
- throws UnknownHostException, IOException {
-
- this.noUI = noUI;
- this.clientListener = clientListener;
- connectTo(host, port, password);
- }
-
- public void shutdown() {
- if(sender != null)
- sender.closeConnection();
-
- if(receiver != null)
- receiver.closeConnection();
-
- if(is != null) {
- try {
- is.close();
- } catch (Throwable e) {
- }
- }
-
- if(os != null) {
- try {
- os.close();
- } catch (Throwable e) {
- }
- }
-
- if(socket != null) {
- try {
- socket.close();
- } catch (Throwable e) {
- }
- }
- }
-
- public ConsoleProxyClientListener getClientListener() {
- return clientListener;
- }
-
- public void connectTo(String host, int port, String path,
- String session, boolean useSSL, String sid) throws UnknownHostException, IOException {
- if(port < 0) {
- if(useSSL)
- port = 443;
- else
- port = 80;
- }
-
- RawHTTP tunnel = new RawHTTP("CONNECT", host, port, path, session, useSSL);
- this.socket = tunnel.connect();
- doConnect(sid);
- }
-
- public void connectTo(String host, int port, String password) throws UnknownHostException, IOException {
- // Connect to server
- s_logger.info("Connecting to VNC server " + host + ":" + port + "...");
- this.socket = new Socket(host, port);
- doConnect(password);
- }
-
- private void doConnect(String password) throws IOException {
- is = new DataInputStream(socket.getInputStream());
- os = new DataOutputStream(socket.getOutputStream());
-
- // Initialize connection
- handshake();
- authenticate(password);
- initialize();
-
- s_logger.info("Connecting to VNC server succeeded, start session");
-
- // Run client-to-server packet sender
- sender = new VncClientPacketSender(os, screen, this);
-
- // Create buffered image canvas
- BufferedImageCanvas canvas = new BufferedImageCanvas(sender, screen.getFramebufferWidth(), screen.getFramebufferHeight());
-
- // Subscribe packet sender to various events
- canvas.addMouseListener(sender);
- canvas.addMouseMotionListener(sender);
- canvas.addKeyListener(sender);
-
- Frame frame = null;
- if(!noUI)
- frame = createVncClientMainWindow(canvas, screen.getDesktopName());
-
- new Thread(sender).start();
-
- // Run server-to-client packet receiver
- receiver = new VncServerPacketReceiver(is, canvas, screen, this, sender, clientListener);
- try {
- receiver.run();
- } finally {
- if(frame != null) {
- frame.setVisible(false);
- frame.dispose();
- }
- this.shutdown();
- }
- }
-
- private Frame createVncClientMainWindow(BufferedImageCanvas canvas, String title) {
- // Create AWT windows
- final Frame frame = new Frame(title + " - VNCle");
-
- // Use scrolling pane to support screens, which are larger than ours
- ScrollPane scroller = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
- scroller.add(canvas);
- scroller.setSize(screen.getFramebufferWidth(), screen.getFramebufferHeight());
-
- frame.add(scroller);
- frame.pack();
- frame.setVisible(true);
-
- frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent evt) {
- frame.setVisible(false);
- shutdown();
- }
- });
-
- return frame;
- }
-
- /**
- * Handshake with VNC server.
- */
- private void handshake() throws IOException {
-
- // Read protocol version
- byte[] buf = new byte[12];
- is.readFully(buf);
- String rfbProtocol = new String(buf);
-
- // Server should use RFB protocol 3.x
- if (!rfbProtocol.contains(RfbConstants.RFB_PROTOCOL_VERSION_MAJOR)) {
- s_logger.error("Cannot handshake with VNC server. Unsupported protocol version: \"" + rfbProtocol + "\".");
- throw new RuntimeException("Cannot handshake with VNC server. Unsupported protocol version: \"" + rfbProtocol + "\".");
+ public void shutdown() {
+ if (sender != null)
+ sender.closeConnection();
+
+ if (receiver != null)
+ receiver.closeConnection();
+
+ if (is != null) {
+ try {
+ is.close();
+ } catch (Throwable e) {
+ }
+ }
+
+ if (os != null) {
+ try {
+ os.close();
+ } catch (Throwable e) {
+ }
+ }
+
+ if (socket != null) {
+ try {
+ socket.close();
+ } catch (Throwable e) {
+ }
+ }
}
- // Send response: we support RFB 3.3 only
- String ourProtocolString = RfbConstants.RFB_PROTOCOL_VERSION + "\n";
- os.write(ourProtocolString.getBytes());
- os.flush();
- }
-
- /**
- * VNC authentication.
- */
- private void authenticate(String password) throws IOException {
- // Read security type
- int authType = is.readInt();
-
- switch (authType) {
- case RfbConstants.CONNECTION_FAILED: {
- // Server forbids to connect. Read reason and throw exception
-
- int length = is.readInt();
- byte[] buf = new byte[length];
- is.readFully(buf);
- String reason = new String(buf, RfbConstants.CHARSET);
-
- s_logger.error("Authentication to VNC server is failed. Reason: " + reason);
- throw new RuntimeException("Authentication to VNC server is failed. Reason: " + reason);
+ public ConsoleProxyClientListener getClientListener() {
+ return clientListener;
}
- case RfbConstants.NO_AUTH: {
- // Client can connect without authorization. Nothing to do.
- break;
+ public void connectTo(String host, int port, String path, String session, boolean useSSL, String sid) throws UnknownHostException, IOException {
+ if (port < 0) {
+ if (useSSL)
+ port = 443;
+ else
+ port = 80;
+ }
+
+ RawHTTP tunnel = new RawHTTP("CONNECT", host, port, path, session, useSSL);
+ this.socket = tunnel.connect();
+ doConnect(sid);
}
- case RfbConstants.VNC_AUTH: {
- s_logger.info("VNC server requires password authentication");
- doVncAuth(password);
- break;
+ public void connectTo(String host, int port, String password) throws UnknownHostException, IOException {
+ // Connect to server
+ s_logger.info("Connecting to VNC server " + host + ":" + port + "...");
+ this.socket = new Socket(host, port);
+ doConnect(password);
}
- default:
- s_logger.error("Unsupported VNC protocol authorization scheme, scheme code: " + authType + ".");
- throw new RuntimeException("Unsupported VNC protocol authorization scheme, scheme code: " + authType + ".");
- }
- }
-
- /**
- * Encode client password and send it to server.
- */
- private void doVncAuth(String password) throws IOException {
-
- // Read challenge
- byte[] challenge = new byte[16];
- is.readFully(challenge);
-
- // Encode challenge with password
- byte[] response;
- try {
- response = encodePassword(challenge, password);
- } catch (Exception e) {
- s_logger.error("Cannot encrypt client password to send to server: " + e.getMessage());
- throw new RuntimeException("Cannot encrypt client password to send to server: " + e.getMessage());
+ private void doConnect(String password) throws IOException {
+ is = new DataInputStream(socket.getInputStream());
+ os = new DataOutputStream(socket.getOutputStream());
+
+ // Initialize connection
+ handshake();
+ authenticate(password);
+ initialize();
+
+ s_logger.info("Connecting to VNC server succeeded, start session");
+
+ // Run client-to-server packet sender
+ sender = new VncClientPacketSender(os, screen, this);
+
+ // Create buffered image canvas
+ BufferedImageCanvas canvas = new BufferedImageCanvas(sender, screen.getFramebufferWidth(), screen.getFramebufferHeight());
+
+ // Subscribe packet sender to various events
+ canvas.addMouseListener(sender);
+ canvas.addMouseMotionListener(sender);
+ canvas.addKeyListener(sender);
+
+ Frame frame = null;
+ if (!noUI)
+ frame = createVncClientMainWindow(canvas, screen.getDesktopName());
+
+ new Thread(sender).start();
+
+ // Run server-to-client packet receiver
+ receiver = new VncServerPacketReceiver(is, canvas, screen, this, sender, clientListener);
+ try {
+ receiver.run();
+ } finally {
+ if (frame != null) {
+ frame.setVisible(false);
+ frame.dispose();
+ }
+ this.shutdown();
+ }
}
- // Send encoded challenge
- os.write(response);
- os.flush();
+ private Frame createVncClientMainWindow(BufferedImageCanvas canvas, String title) {
+ // Create AWT windows
+ final Frame frame = new Frame(title + " - VNCle");
- // Read security result
- int authResult = is.readInt();
+ // Use scrolling pane to support screens, which are larger than ours
+ ScrollPane scroller = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
+ scroller.add(canvas);
+ scroller.setSize(screen.getFramebufferWidth(), screen.getFramebufferHeight());
- switch (authResult) {
- case RfbConstants.VNC_AUTH_OK: {
- // Nothing to do
- break;
- }
+ frame.add(scroller);
+ frame.pack();
+ frame.setVisible(true);
- case RfbConstants.VNC_AUTH_TOO_MANY:
- s_logger.error("Connection to VNC server failed: too many wrong attempts.");
- throw new RuntimeException("Connection to VNC server failed: too many wrong attempts.");
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent evt) {
+ frame.setVisible(false);
+ shutdown();
+ }
+ });
- case RfbConstants.VNC_AUTH_FAILED:
- s_logger.error("Connection to VNC server failed: wrong password.");
- throw new RuntimeException("Connection to VNC server failed: wrong password.");
+ return frame;
+ }
- default:
- s_logger.error("Connection to VNC server failed, reason code: " + authResult);
- throw new RuntimeException("Connection to VNC server failed, reason code: " + authResult);
+ /**
+ * Handshake with VNC server.
+ */
+ private void handshake() throws IOException {
+
+ // Read protocol version
+ byte[] buf = new byte[12];
+ is.readFully(buf);
+ String rfbProtocol = new String(buf);
+
+ // Server should use RFB protocol 3.x
+ if (!rfbProtocol.contains(RfbConstants.RFB_PROTOCOL_VERSION_MAJOR)) {
+ s_logger.error("Cannot handshake with VNC server. Unsupported protocol version: \"" + rfbProtocol + "\".");
+ throw new RuntimeException("Cannot handshake with VNC server. Unsupported protocol version: \"" + rfbProtocol + "\".");
+ }
+
+ // Send response: we support RFB 3.3 only
+ String ourProtocolString = RfbConstants.RFB_PROTOCOL_VERSION + "\n";
+ os.write(ourProtocolString.getBytes());
+ os.flush();
}
- }
-
- /**
- * Encode password using DES encryption with given challenge.
- *
- * @param challenge
- * a random set of bytes.
- * @param password
- * a password
- * @return DES hash of password and challenge
- */
- public byte[] encodePassword(byte[] challenge, String password) throws Exception {
- // VNC password consist of up to eight ASCII characters.
- byte[] key = { 0, 0, 0, 0, 0, 0, 0, 0 }; // Padding
- byte[] passwordAsciiBytes = password.getBytes(RfbConstants.CHARSET);
- System.arraycopy(passwordAsciiBytes, 0, key, 0, Math.min(password.length(), 8));
-
- // Flip bytes (reverse bits) in key
- for (int i = 0; i < key.length; i++) {
- key[i] = flipByte(key[i]);
+
+ /**
+ * VNC authentication.
+ */
+ private void authenticate(String password) throws IOException {
+ // Read security type
+ int authType = is.readInt();
+
+ switch (authType) {
+ case RfbConstants.CONNECTION_FAILED: {
+ // Server forbids to connect. Read reason and throw exception
+
+ int length = is.readInt();
+ byte[] buf = new byte[length];
+ is.readFully(buf);
+ String reason = new String(buf, RfbConstants.CHARSET);
+
+ s_logger.error("Authentication to VNC server is failed. Reason: " + reason);
+ throw new RuntimeException("Authentication to VNC server is failed. Reason: " + reason);
+ }
+
+ case RfbConstants.NO_AUTH: {
+ // Client can connect without authorization. Nothing to do.
+ break;
+ }
+
+ case RfbConstants.VNC_AUTH: {
+ s_logger.info("VNC server requires password authentication");
+ doVncAuth(password);
+ break;
+ }
+
+ default:
+ s_logger.error("Unsupported VNC protocol authorization scheme, scheme code: " + authType + ".");
+ throw new RuntimeException("Unsupported VNC protocol authorization scheme, scheme code: " + authType + ".");
+ }
}
- KeySpec desKeySpec = new DESKeySpec(key);
- SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("DES");
- SecretKey secretKey = secretKeyFactory.generateSecret(desKeySpec);
- Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
- cipher.init(Cipher.ENCRYPT_MODE, secretKey);
-
- byte[] response = cipher.doFinal(challenge);
- return response;
- }
-
- /**
- * Reverse bits in byte, so least significant bit will be most significant
- * bit. E.g. 01001100 will become 00110010.
- *
- * See also: http://www.vidarholen.net/contents/junk/vnc.html ,
- * http://bytecrafter .blogspot.com/2010/09/des-encryption-as-used-in-vnc.html
- *
- * @param b
- * a byte
- * @return byte in reverse order
- */
- private static byte flipByte(byte b) {
- int b1_8 = (b & 0x1) << 7;
- int b2_7 = (b & 0x2) << 5;
- int b3_6 = (b & 0x4) << 3;
- int b4_5 = (b & 0x8) << 1;
- int b5_4 = (b & 0x10) >>> 1;
- int b6_3 = (b & 0x20) >>> 3;
- int b7_2 = (b & 0x40) >>> 5;
- int b8_1 = (b & 0x80) >>> 7;
- byte c = (byte) (b1_8 | b2_7 | b3_6 | b4_5 | b5_4 | b6_3 | b7_2 | b8_1);
- return c;
- }
-
- private void initialize() throws IOException {
- // Send client initialization message
- {
- // Send shared flag
- os.writeByte(RfbConstants.EXCLUSIVE_ACCESS);
- os.flush();
+ /**
+ * Encode client password and send it to server.
+ */
+ private void doVncAuth(String password) throws IOException {
+
+ // Read challenge
+ byte[] challenge = new byte[16];
+ is.readFully(challenge);
+
+ // Encode challenge with password
+ byte[] response;
+ try {
+ response = encodePassword(challenge, password);
+ } catch (Exception e) {
+ s_logger.error("Cannot encrypt client password to send to server: " + e.getMessage());
+ throw new RuntimeException("Cannot encrypt client password to send to server: " + e.getMessage());
+ }
+
+ // Send encoded challenge
+ os.write(response);
+ os.flush();
+
+ // Read security result
+ int authResult = is.readInt();
+
+ switch (authResult) {
+ case RfbConstants.VNC_AUTH_OK: {
+ // Nothing to do
+ break;
+ }
+
+ case RfbConstants.VNC_AUTH_TOO_MANY:
+ s_logger.error("Connection to VNC server failed: too many wrong attempts.");
+ throw new RuntimeException("Connection to VNC server failed: too many wrong attempts.");
+
+ case RfbConstants.VNC_AUTH_FAILED:
+ s_logger.error("Connection to VNC server failed: wrong password.");
+ throw new RuntimeException("Connection to VNC server failed: wrong password.");
+
+ default:
+ s_logger.error("Connection to VNC server failed, reason code: " + authResult);
+ throw new RuntimeException("Connection to VNC server failed, reason code: " + authResult);
+ }
}
- // Read server initialization message
- {
- // Read frame buffer size
- int framebufferWidth = is.readUnsignedShort();
- int framebufferHeight = is.readUnsignedShort();
- screen.setFramebufferSize(framebufferWidth, framebufferHeight);
- if(clientListener != null)
- clientListener.onFramebufferSizeChange(framebufferWidth, framebufferHeight);
+ /**
+ * Encode password using DES encryption with given challenge.
+ *
+ * @param challenge
+ * a random set of bytes.
+ * @param password
+ * a password
+ * @return DES hash of password and challenge
+ */
+ public byte[] encodePassword(byte[] challenge, String password) throws Exception {
+ // VNC password consist of up to eight ASCII characters.
+ byte[] key = { 0, 0, 0, 0, 0, 0, 0, 0 }; // Padding
+ byte[] passwordAsciiBytes = password.getBytes(RfbConstants.CHARSET);
+ System.arraycopy(passwordAsciiBytes, 0, key, 0, Math.min(password.length(), 8));
+
+ // Flip bytes (reverse bits) in key
+ for (int i = 0; i < key.length; i++) {
+ key[i] = flipByte(key[i]);
+ }
+
+ KeySpec desKeySpec = new DESKeySpec(key);
+ SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("DES");
+ SecretKey secretKey = secretKeyFactory.generateSecret(desKeySpec);
+ Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
+ cipher.init(Cipher.ENCRYPT_MODE, secretKey);
+
+ byte[] response = cipher.doFinal(challenge);
+ return response;
}
- // Read pixel format
- {
- int bitsPerPixel = is.readUnsignedByte();
- int depth = is.readUnsignedByte();
+ /**
+ * Reverse bits in byte, so least significant bit will be most significant
+ * bit. E.g. 01001100 will become 00110010.
+ *
+ * See also: http://www.vidarholen.net/contents/junk/vnc.html ,
+ * http://bytecrafter
+ * .blogspot.com/2010/09/des-encryption-as-used-in-vnc.html
+ *
+ * @param b
+ * a byte
+ * @return byte in reverse order
+ */
+ private static byte flipByte(byte b) {
+ int b1_8 = (b & 0x1) << 7;
+ int b2_7 = (b & 0x2) << 5;
+ int b3_6 = (b & 0x4) << 3;
+ int b4_5 = (b & 0x8) << 1;
+ int b5_4 = (b & 0x10) >>> 1;
+ int b6_3 = (b & 0x20) >>> 3;
+ int b7_2 = (b & 0x40) >>> 5;
+ int b8_1 = (b & 0x80) >>> 7;
+ byte c = (byte) (b1_8 | b2_7 | b3_6 | b4_5 | b5_4 | b6_3 | b7_2 | b8_1);
+ return c;
+ }
- int bigEndianFlag = is.readUnsignedByte();
- int trueColorFlag = is.readUnsignedByte();
+ private void initialize() throws IOException {
+ // Send client initialization message
+ {
+ // Send shared flag
+ os.writeByte(RfbConstants.EXCLUSIVE_ACCESS);
+ os.flush();
+ }
+
+ // Read server initialization message
+ {
+ // Read frame buffer size
+ int framebufferWidth = is.readUnsignedShort();
+ int framebufferHeight = is.readUnsignedShort();
+ screen.setFramebufferSize(framebufferWidth, framebufferHeight);
+ if (clientListener != null)
+ clientListener.onFramebufferSizeChange(framebufferWidth, framebufferHeight);
+ }
+
+ // Read pixel format
+ {
+ int bitsPerPixel = is.readUnsignedByte();
+ int depth = is.readUnsignedByte();
+
+ int bigEndianFlag = is.readUnsignedByte();
+ int trueColorFlag = is.readUnsignedByte();
+
+ int redMax = is.readUnsignedShort();
+ int greenMax = is.readUnsignedShort();
+ int blueMax = is.readUnsignedShort();
+
+ int redShift = is.readUnsignedByte();
+ int greenShift = is.readUnsignedByte();
+ int blueShift = is.readUnsignedByte();
+
+ // Skip padding
+ is.skipBytes(3);
+
+ screen.setPixelFormat(bitsPerPixel, depth, bigEndianFlag, trueColorFlag, redMax, greenMax, blueMax, redShift, greenShift, blueShift);
+ }
+
+ // Read desktop name
+ {
+ int length = is.readInt();
+ byte buf[] = new byte[length];
+ is.readFully(buf);
+ String desktopName = new String(buf, RfbConstants.CHARSET);
+ screen.setDesktopName(desktopName);
+ }
+ }
- int redMax = is.readUnsignedShort();
- int greenMax = is.readUnsignedShort();
- int blueMax = is.readUnsignedShort();
+ public FrameBufferCanvas getFrameBufferCanvas() {
+ if (receiver != null)
+ return receiver.getCanvas();
- int redShift = is.readUnsignedByte();
- int greenShift = is.readUnsignedByte();
- int blueShift = is.readUnsignedByte();
+ return null;
+ }
- // Skip padding
- is.skipBytes(3);
+ public void requestUpdate(boolean fullUpdate) {
+ if (fullUpdate)
+ sender.requestFullScreenUpdate();
+ else
+ sender.imagePaintedOnScreen();
+ }
+
+ public void sendClientKeyboardEvent(int event, int code, int modifiers) {
+ sender.sendClientPacket(new KeyboardEventPacket(event, code));
+ }
- screen.setPixelFormat(bitsPerPixel, depth, bigEndianFlag, trueColorFlag, redMax, greenMax, blueMax, redShift, greenShift, blueShift);
+ public void sendClientMouseEvent(int event, int x, int y, int code, int modifiers) {
+ sender.sendClientPacket(new MouseEventPacket(event, x, y));
}
- // Read desktop name
- {
- int length = is.readInt();
- byte buf[] = new byte[length];
- is.readFully(buf);
- String desktopName = new String(buf, RfbConstants.CHARSET);
- screen.setDesktopName(desktopName);
+ public boolean isHostConnected() {
+ return receiver != null && receiver.isConnectionAlive();
}
- }
-
- public FrameBufferCanvas getFrameBufferCanvas() {
- if(receiver != null)
- return receiver.getCanvas();
-
- return null;
- }
-
- public void requestUpdate(boolean fullUpdate) {
- if(fullUpdate)
- sender.requestFullScreenUpdate();
- else
- sender.imagePaintedOnScreen();
- }
-
- public void sendClientKeyboardEvent(int event, int code, int modifiers) {
- sender.sendClientPacket(new KeyboardEventPacket(event, code));
- }
-
- public void sendClientMouseEvent(int event, int x, int y, int code, int modifiers) {
- sender.sendClientPacket(new MouseEventPacket(event, x, y));
- }
-
- public boolean isHostConnected() {
- return receiver != null && receiver.isConnectionAlive();
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/VncClientPacketSender.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/VncClientPacketSender.java b/console-proxy/src/com/cloud/consoleproxy/vnc/VncClientPacketSender.java
index cf15f88..d27b76d 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/VncClientPacketSender.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/VncClientPacketSender.java
@@ -35,226 +35,224 @@ import com.cloud.consoleproxy.vnc.packet.client.SetEncodingsPacket;
import com.cloud.consoleproxy.vnc.packet.client.SetPixelFormatPacket;
public class VncClientPacketSender implements Runnable, PaintNotificationListener, KeyListener, MouseListener, MouseMotionListener, FrameBufferUpdateListener {
- private static final Logger s_logger = Logger.getLogger(VncClientPacketSender.class);
+ private static final Logger s_logger = Logger.getLogger(VncClientPacketSender.class);
- // Queue for outgoing packets
- private final BlockingQueue<ClientPacket> queue = new ArrayBlockingQueue<ClientPacket>(30);
+ // Queue for outgoing packets
+ private final BlockingQueue<ClientPacket> queue = new ArrayBlockingQueue<ClientPacket>(30);
- private final DataOutputStream os;
- private final VncScreenDescription screen;
- private final VncClient vncConnection;
+ private final DataOutputStream os;
+ private final VncScreenDescription screen;
+ private final VncClient vncConnection;
- private boolean connectionAlive = true;
+ private boolean connectionAlive = true;
- // Don't send update request again until we receive next frame buffer update
- private boolean updateRequestSent = false;
+ // Don't send update request again until we receive next frame buffer update
+ private boolean updateRequestSent = false;
- public VncClientPacketSender(DataOutputStream os, VncScreenDescription screen, VncClient vncConnection) {
- this.os = os;
- this.screen = screen;
- this.vncConnection = vncConnection;
+ public VncClientPacketSender(DataOutputStream os, VncScreenDescription screen, VncClient vncConnection) {
+ this.os = os;
+ this.screen = screen;
+ this.vncConnection = vncConnection;
- sendSetPixelFormat();
- sendSetEncodings();
- requestFullScreenUpdate();
- }
-
- public void sendClientPacket(ClientPacket packet) {
- queue.add(packet);
- }
+ sendSetPixelFormat();
+ sendSetEncodings();
+ requestFullScreenUpdate();
+ }
- @Override
- public void run() {
- try {
- while (connectionAlive) {
- ClientPacket packet = queue.poll(1, TimeUnit.SECONDS);
- if (packet != null) {
- packet.write(os);
- os.flush();
- }
- }
- } catch (Throwable e) {
- s_logger.error("Unexpected exception: ", e);
- if (connectionAlive) {
- closeConnection();
- vncConnection.shutdown();
- }
+ public void sendClientPacket(ClientPacket packet) {
+ queue.add(packet);
}
- }
- private void sendSetEncodings() {
- queue.add(new SetEncodingsPacket(RfbConstants.SUPPORTED_ENCODINGS_ARRAY));
- }
+ @Override
+ public void run() {
+ try {
+ while (connectionAlive) {
+ ClientPacket packet = queue.poll(1, TimeUnit.SECONDS);
+ if (packet != null) {
+ packet.write(os);
+ os.flush();
+ }
+ }
+ } catch (Throwable e) {
+ s_logger.error("Unexpected exception: ", e);
+ if (connectionAlive) {
+ closeConnection();
+ vncConnection.shutdown();
+ }
+ }
+ }
- private void sendSetPixelFormat() {
- if (!screen.isRGB888_32_LE()) {
- queue.add(new SetPixelFormatPacket(screen, 32, 24, RfbConstants.LITTLE_ENDIAN, RfbConstants.TRUE_COLOR, 255, 255, 255, 16, 8, 0));
+ private void sendSetEncodings() {
+ queue.add(new SetEncodingsPacket(RfbConstants.SUPPORTED_ENCODINGS_ARRAY));
}
- }
- public void closeConnection() {
- connectionAlive = false;
- }
+ private void sendSetPixelFormat() {
+ if (!screen.isRGB888_32_LE()) {
+ queue.add(new SetPixelFormatPacket(screen, 32, 24, RfbConstants.LITTLE_ENDIAN, RfbConstants.TRUE_COLOR, 255, 255, 255, 16, 8, 0));
+ }
+ }
- public void requestFullScreenUpdate() {
- queue.add(new FramebufferUpdateRequestPacket(RfbConstants.FRAMEBUFFER_FULL_UPDATE_REQUEST, 0, 0, screen.getFramebufferWidth(), screen
- .getFramebufferHeight()));
- updateRequestSent = true;
- }
+ public void closeConnection() {
+ connectionAlive = false;
+ }
- @Override
- public void imagePaintedOnScreen() {
- if (!updateRequestSent) {
- queue.add(new FramebufferUpdateRequestPacket(RfbConstants.FRAMEBUFFER_INCREMENTAL_UPDATE_REQUEST, 0, 0, screen.getFramebufferWidth(), screen
- .getFramebufferHeight()));
- updateRequestSent = true;
+ public void requestFullScreenUpdate() {
+ queue.add(new FramebufferUpdateRequestPacket(RfbConstants.FRAMEBUFFER_FULL_UPDATE_REQUEST, 0, 0, screen.getFramebufferWidth(), screen.getFramebufferHeight()));
+ updateRequestSent = true;
}
- }
- @Override
- public void frameBufferPacketReceived() {
- updateRequestSent = false;
- }
+ @Override
+ public void imagePaintedOnScreen() {
+ if (!updateRequestSent) {
+ queue.add(new FramebufferUpdateRequestPacket(RfbConstants.FRAMEBUFFER_INCREMENTAL_UPDATE_REQUEST, 0, 0, screen.getFramebufferWidth(), screen.getFramebufferHeight()));
+ updateRequestSent = true;
+ }
+ }
- @Override
- public void mouseDragged(MouseEvent e) {
- queue.add(new MouseEventPacket(mapAwtModifiersToVncButtonMask(e.getModifiersEx()), e.getX(), e.getY()));
- }
+ @Override
+ public void frameBufferPacketReceived() {
+ updateRequestSent = false;
+ }
- @Override
- public void mouseMoved(MouseEvent e) {
- queue.add(new MouseEventPacket(mapAwtModifiersToVncButtonMask(e.getModifiersEx()), e.getX(), e.getY()));
- }
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ queue.add(new MouseEventPacket(mapAwtModifiersToVncButtonMask(e.getModifiersEx()), e.getX(), e.getY()));
+ }
- @Override
- public void mouseClicked(MouseEvent e) {
- // Nothing to do
- }
+ @Override
+ public void mouseMoved(MouseEvent e) {
+ queue.add(new MouseEventPacket(mapAwtModifiersToVncButtonMask(e.getModifiersEx()), e.getX(), e.getY()));
+ }
- @Override
- public void mousePressed(MouseEvent e) {
- queue.add(new MouseEventPacket(mapAwtModifiersToVncButtonMask(e.getModifiersEx()), e.getX(), e.getY()));
- }
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ // Nothing to do
+ }
- @Override
- public void mouseReleased(MouseEvent e) {
- queue.add(new MouseEventPacket(mapAwtModifiersToVncButtonMask(e.getModifiersEx()), e.getX(), e.getY()));
- }
+ @Override
+ public void mousePressed(MouseEvent e) {
+ queue.add(new MouseEventPacket(mapAwtModifiersToVncButtonMask(e.getModifiersEx()), e.getX(), e.getY()));
+ }
- @Override
- public void mouseEntered(MouseEvent e) {
- // Nothing to do
- }
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ queue.add(new MouseEventPacket(mapAwtModifiersToVncButtonMask(e.getModifiersEx()), e.getX(), e.getY()));
+ }
- @Override
- public void mouseExited(MouseEvent e) {
- // Nothing to do
- }
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ // Nothing to do
+ }
- /**
- * Current state of buttons 1 to 8 are represented by bits 0 to 7 of
- * button-mask respectively, 0 meaning up, 1 meaning down (pressed). On a
- * conventional mouse, buttons 1, 2 and 3 correspond to the left, middle and
- * right buttons on the mouse. On a wheel mouse, each step of the wheel
- * upwards is represented by a press and release of button 4, and each step
- * downwards is represented by a press and release of button 5.
- *
- * @param modifiers
- * extended modifiers from AWT mouse event
- * @return VNC mouse button mask
- */
- public static int mapAwtModifiersToVncButtonMask(int modifiers) {
- int mask = (((modifiers & MouseEvent.BUTTON1_DOWN_MASK) != 0) ? 0x1 : 0) | (((modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0) ? 0x2 : 0)
- | (((modifiers & MouseEvent.BUTTON3_DOWN_MASK) != 0) ? 0x4 : 0);
- return mask;
- }
+ @Override
+ public void mouseExited(MouseEvent e) {
+ // Nothing to do
+ }
- @Override
- public void keyTyped(KeyEvent e) {
- // Do nothing
- }
+ /**
+ * Current state of buttons 1 to 8 are represented by bits 0 to 7 of
+ * button-mask respectively, 0 meaning up, 1 meaning down (pressed). On a
+ * conventional mouse, buttons 1, 2 and 3 correspond to the left, middle and
+ * right buttons on the mouse. On a wheel mouse, each step of the wheel
+ * upwards is represented by a press and release of button 4, and each step
+ * downwards is represented by a press and release of button 5.
+ *
+ * @param modifiers
+ * extended modifiers from AWT mouse event
+ * @return VNC mouse button mask
+ */
+ public static int mapAwtModifiersToVncButtonMask(int modifiers) {
+ int mask = (((modifiers & MouseEvent.BUTTON1_DOWN_MASK) != 0) ? 0x1 : 0) | (((modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0) ? 0x2 : 0)
+ | (((modifiers & MouseEvent.BUTTON3_DOWN_MASK) != 0) ? 0x4 : 0);
+ return mask;
+ }
- @Override
- public void keyPressed(KeyEvent e) {
- ClientPacket request = new KeyboardEventPacket(RfbConstants.KEY_DOWN, mapAwtKeyToVncKey(e.getKeyCode()));
- queue.add(request);
- }
+ @Override
+ public void keyTyped(KeyEvent e) {
+ // Do nothing
+ }
- @Override
- public void keyReleased(KeyEvent e) {
- ClientPacket request = new KeyboardEventPacket(RfbConstants.KEY_UP, mapAwtKeyToVncKey(e.getKeyCode()));
- queue.add(request);
- }
+ @Override
+ public void keyPressed(KeyEvent e) {
+ ClientPacket request = new KeyboardEventPacket(RfbConstants.KEY_DOWN, mapAwtKeyToVncKey(e.getKeyCode()));
+ queue.add(request);
+ }
- private int mapAwtKeyToVncKey(int key) {
- switch (key) {
- case KeyEvent.VK_BACK_SPACE:
- return 0xff08;
- case KeyEvent.VK_TAB:
- return 0xff09;
- case KeyEvent.VK_ENTER:
- return 0xff0d;
- case KeyEvent.VK_ESCAPE:
- return 0xff1b;
- case KeyEvent.VK_INSERT:
- return 0xff63;
- case KeyEvent.VK_DELETE:
- return 0xffff;
- case KeyEvent.VK_HOME:
- return 0xff50;
- case KeyEvent.VK_END:
- return 0xff57;
- case KeyEvent.VK_PAGE_UP:
- return 0xff55;
- case KeyEvent.VK_PAGE_DOWN:
- return 0xff56;
- case KeyEvent.VK_LEFT:
- return 0xff51;
- case KeyEvent.VK_UP:
- return 0xff52;
- case KeyEvent.VK_RIGHT:
- return 0xff53;
- case KeyEvent.VK_DOWN:
- return 0xff54;
- case KeyEvent.VK_F1:
- return 0xffbe;
- case KeyEvent.VK_F2:
- return 0xffbf;
- case KeyEvent.VK_F3:
- return 0xffc0;
- case KeyEvent.VK_F4:
- return 0xffc1;
- case KeyEvent.VK_F5:
- return 0xffc2;
- case KeyEvent.VK_F6:
- return 0xffc3;
- case KeyEvent.VK_F7:
- return 0xffc4;
- case KeyEvent.VK_F8:
- return 0xffc5;
- case KeyEvent.VK_F9:
- return 0xffc6;
- case KeyEvent.VK_F10:
- return 0xffc7;
- case KeyEvent.VK_F11:
- return 0xffc8;
- case KeyEvent.VK_F12:
- return 0xffc9;
- case KeyEvent.VK_SHIFT:
- return 0xffe1;
- case KeyEvent.VK_CONTROL:
- return 0xffe3;
- case KeyEvent.VK_META:
- return 0xffe7;
- case KeyEvent.VK_ALT:
- return 0xffe9;
- case KeyEvent.VK_ALT_GRAPH:
- return 0xffea;
- case KeyEvent.VK_BACK_QUOTE:
- return 0x0060;
+ @Override
+ public void keyReleased(KeyEvent e) {
+ ClientPacket request = new KeyboardEventPacket(RfbConstants.KEY_UP, mapAwtKeyToVncKey(e.getKeyCode()));
+ queue.add(request);
}
- return key;
- }
+ private int mapAwtKeyToVncKey(int key) {
+ switch (key) {
+ case KeyEvent.VK_BACK_SPACE:
+ return 0xff08;
+ case KeyEvent.VK_TAB:
+ return 0xff09;
+ case KeyEvent.VK_ENTER:
+ return 0xff0d;
+ case KeyEvent.VK_ESCAPE:
+ return 0xff1b;
+ case KeyEvent.VK_INSERT:
+ return 0xff63;
+ case KeyEvent.VK_DELETE:
+ return 0xffff;
+ case KeyEvent.VK_HOME:
+ return 0xff50;
+ case KeyEvent.VK_END:
+ return 0xff57;
+ case KeyEvent.VK_PAGE_UP:
+ return 0xff55;
+ case KeyEvent.VK_PAGE_DOWN:
+ return 0xff56;
+ case KeyEvent.VK_LEFT:
+ return 0xff51;
+ case KeyEvent.VK_UP:
+ return 0xff52;
+ case KeyEvent.VK_RIGHT:
+ return 0xff53;
+ case KeyEvent.VK_DOWN:
+ return 0xff54;
+ case KeyEvent.VK_F1:
+ return 0xffbe;
+ case KeyEvent.VK_F2:
+ return 0xffbf;
+ case KeyEvent.VK_F3:
+ return 0xffc0;
+ case KeyEvent.VK_F4:
+ return 0xffc1;
+ case KeyEvent.VK_F5:
+ return 0xffc2;
+ case KeyEvent.VK_F6:
+ return 0xffc3;
+ case KeyEvent.VK_F7:
+ return 0xffc4;
+ case KeyEvent.VK_F8:
+ return 0xffc5;
+ case KeyEvent.VK_F9:
+ return 0xffc6;
+ case KeyEvent.VK_F10:
+ return 0xffc7;
+ case KeyEvent.VK_F11:
+ return 0xffc8;
+ case KeyEvent.VK_F12:
+ return 0xffc9;
+ case KeyEvent.VK_SHIFT:
+ return 0xffe1;
+ case KeyEvent.VK_CONTROL:
+ return 0xffe3;
+ case KeyEvent.VK_META:
+ return 0xffe7;
+ case KeyEvent.VK_ALT:
+ return 0xffe9;
+ case KeyEvent.VK_ALT_GRAPH:
+ return 0xffea;
+ case KeyEvent.VK_BACK_QUOTE:
+ return 0x0060;
+ }
+
+ return key;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/VncScreenDescription.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/VncScreenDescription.java b/console-proxy/src/com/cloud/consoleproxy/vnc/VncScreenDescription.java
index c9e135e..44b2a34 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/VncScreenDescription.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/VncScreenDescription.java
@@ -21,70 +21,69 @@ package com.cloud.consoleproxy.vnc;
*/
public class VncScreenDescription {
- // Frame buffer size
- private int framebufferWidth = -1;
- private int framebufferHeight = -1;
-
- // Desktop name
- private String desktopName;
-
- // Bytes per pixel
- private int bytesPerPixel;
-
- // Indicates that screen uses format which we want to use:
- // RGB 24bit packed into 32bit little-endian int.
- private boolean rgb888_32_le = false;
-
- public VncScreenDescription() {
- }
-
- /**
- * Store information about server pixel format.
- */
- public void setPixelFormat(int bitsPerPixel, int depth, int bigEndianFlag, int trueColorFlag, int redMax, int greenMax, int blueMax, int redShift,
- int greenShift, int blueShift) {
-
- bytesPerPixel = (bitsPerPixel + 7) / 8;
-
- rgb888_32_le = (depth == 24 && bitsPerPixel == 32 && redShift == 16 && greenShift == 8 && blueShift == 0 && redMax == 255 && greenMax == 255
- && blueMax == 255 && bigEndianFlag == RfbConstants.LITTLE_ENDIAN && trueColorFlag == RfbConstants.TRUE_COLOR);
- }
-
- /**
- * Store information about server screen size.
- */
- public void setFramebufferSize(int framebufferWidth, int framebufferHeight) {
- this.framebufferWidth = framebufferWidth;
- this.framebufferHeight = framebufferHeight;
- }
-
- /**
- * Store server desktop name.
- */
- public void setDesktopName(String desktopName) {
- this.desktopName = desktopName;
- }
-
- // Getters for variables, as usual
-
- public String getDesktopName() {
- return desktopName;
- }
-
- public int getBytesPerPixel() {
- return bytesPerPixel;
- }
-
- public int getFramebufferHeight() {
- return framebufferHeight;
- }
-
- public int getFramebufferWidth() {
- return framebufferWidth;
- }
-
- public boolean isRGB888_32_LE() {
- return rgb888_32_le;
- }
+ // Frame buffer size
+ private int framebufferWidth = -1;
+ private int framebufferHeight = -1;
+
+ // Desktop name
+ private String desktopName;
+
+ // Bytes per pixel
+ private int bytesPerPixel;
+
+ // Indicates that screen uses format which we want to use:
+ // RGB 24bit packed into 32bit little-endian int.
+ private boolean rgb888_32_le = false;
+
+ public VncScreenDescription() {
+ }
+
+ /**
+ * Store information about server pixel format.
+ */
+ public void setPixelFormat(int bitsPerPixel, int depth, int bigEndianFlag, int trueColorFlag, int redMax, int greenMax, int blueMax, int redShift, int greenShift, int blueShift) {
+
+ bytesPerPixel = (bitsPerPixel + 7) / 8;
+
+ rgb888_32_le = (depth == 24 && bitsPerPixel == 32 && redShift == 16 && greenShift == 8 && blueShift == 0 && redMax == 255 && greenMax == 255 && blueMax == 255
+ && bigEndianFlag == RfbConstants.LITTLE_ENDIAN && trueColorFlag == RfbConstants.TRUE_COLOR);
+ }
+
+ /**
+ * Store information about server screen size.
+ */
+ public void setFramebufferSize(int framebufferWidth, int framebufferHeight) {
+ this.framebufferWidth = framebufferWidth;
+ this.framebufferHeight = framebufferHeight;
+ }
+
+ /**
+ * Store server desktop name.
+ */
+ public void setDesktopName(String desktopName) {
+ this.desktopName = desktopName;
+ }
+
+ // Getters for variables, as usual
+
+ public String getDesktopName() {
+ return desktopName;
+ }
+
+ public int getBytesPerPixel() {
+ return bytesPerPixel;
+ }
+
+ public int getFramebufferHeight() {
+ return framebufferHeight;
+ }
+
+ public int getFramebufferWidth() {
+ return framebufferWidth;
+ }
+
+ public boolean isRGB888_32_LE() {
+ return rgb888_32_le;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/VncServerPacketReceiver.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/VncServerPacketReceiver.java b/console-proxy/src/com/cloud/consoleproxy/vnc/VncServerPacketReceiver.java
index 06a4f03..57c8ff8 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/VncServerPacketReceiver.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/VncServerPacketReceiver.java
@@ -27,97 +27,97 @@ import com.cloud.consoleproxy.vnc.packet.server.FramebufferUpdatePacket;
import com.cloud.consoleproxy.vnc.packet.server.ServerCutText;
public class VncServerPacketReceiver implements Runnable {
- private static final Logger s_logger = Logger.getLogger(VncServerPacketReceiver.class);
-
- private final VncScreenDescription screen;
- private BufferedImageCanvas canvas;
- private DataInputStream is;
-
- private boolean connectionAlive = true;
- private VncClient vncConnection;
- private final FrameBufferUpdateListener fburListener;
- private final ConsoleProxyClientListener clientListener;
-
- public VncServerPacketReceiver(DataInputStream is, BufferedImageCanvas canvas, VncScreenDescription screen, VncClient vncConnection,
- FrameBufferUpdateListener fburListener, ConsoleProxyClientListener clientListener) {
- this.screen = screen;
- this.canvas = canvas;
- this.is = is;
- this.vncConnection = vncConnection;
- this.fburListener = fburListener;
- this.clientListener = clientListener;
- }
-
- public BufferedImageCanvas getCanvas() {
- return canvas;
- }
-
- @Override
- public void run() {
- try {
- while (connectionAlive) {
-
- // Read server message type
- int messageType = is.readUnsignedByte();
-
- // Invoke packet handler by packet type.
- switch (messageType) {
-
- case RfbConstants.SERVER_FRAMEBUFFER_UPDATE: {
- // Notify sender that frame buffer update is received,
- // so it can send another frame buffer update request
- fburListener.frameBufferPacketReceived();
- // Handle frame buffer update
- new FramebufferUpdatePacket(canvas, screen, is, clientListener);
- break;
- }
+ private static final Logger s_logger = Logger.getLogger(VncServerPacketReceiver.class);
+
+ private final VncScreenDescription screen;
+ private BufferedImageCanvas canvas;
+ private DataInputStream is;
+
+ private boolean connectionAlive = true;
+ private VncClient vncConnection;
+ private final FrameBufferUpdateListener fburListener;
+ private final ConsoleProxyClientListener clientListener;
+
+ public VncServerPacketReceiver(DataInputStream is, BufferedImageCanvas canvas, VncScreenDescription screen, VncClient vncConnection, FrameBufferUpdateListener fburListener,
+ ConsoleProxyClientListener clientListener) {
+ this.screen = screen;
+ this.canvas = canvas;
+ this.is = is;
+ this.vncConnection = vncConnection;
+ this.fburListener = fburListener;
+ this.clientListener = clientListener;
+ }
- case RfbConstants.SERVER_BELL: {
- serverBell();
- break;
- }
+ public BufferedImageCanvas getCanvas() {
+ return canvas;
+ }
- case RfbConstants.SERVER_CUT_TEXT: {
- serverCutText(is);
- break;
+ @Override
+ public void run() {
+ try {
+ while (connectionAlive) {
+
+ // Read server message type
+ int messageType = is.readUnsignedByte();
+
+ // Invoke packet handler by packet type.
+ switch (messageType) {
+
+ case RfbConstants.SERVER_FRAMEBUFFER_UPDATE: {
+ // Notify sender that frame buffer update is received,
+ // so it can send another frame buffer update request
+ fburListener.frameBufferPacketReceived();
+ // Handle frame buffer update
+ new FramebufferUpdatePacket(canvas, screen, is, clientListener);
+ break;
+ }
+
+ case RfbConstants.SERVER_BELL: {
+ serverBell();
+ break;
+ }
+
+ case RfbConstants.SERVER_CUT_TEXT: {
+ serverCutText(is);
+ break;
+ }
+
+ default:
+ throw new RuntimeException("Unknown server packet type: " + messageType + ".");
+ }
+ }
+ } catch (Throwable e) {
+ s_logger.error("Unexpected exception: ", e);
+ if (connectionAlive) {
+ closeConnection();
+ vncConnection.shutdown();
+ }
}
+ }
- default:
- throw new RuntimeException("Unknown server packet type: " + messageType + ".");
- }
- }
- } catch (Throwable e) {
- s_logger.error("Unexpected exception: ", e);
- if (connectionAlive) {
- closeConnection();
- vncConnection.shutdown();
- }
+ public void closeConnection() {
+ connectionAlive = false;
+ }
+
+ public boolean isConnectionAlive() {
+ return connectionAlive;
+ }
+
+ /**
+ * Handle server bell packet.
+ */
+ private void serverBell() {
+ Toolkit.getDefaultToolkit().beep();
+ }
+
+ /**
+ * Handle packet with server clip-board.
+ */
+ private void serverCutText(DataInputStream is) throws IOException {
+ ServerCutText clipboardContent = new ServerCutText(is);
+ StringSelection contents = new StringSelection(clipboardContent.getContent());
+ Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, null);
+
+ s_logger.info("Server clipboard buffer: " + clipboardContent.getContent());
}
- }
-
- public void closeConnection() {
- connectionAlive = false;
- }
-
- public boolean isConnectionAlive() {
- return connectionAlive;
- }
-
- /**
- * Handle server bell packet.
- */
- private void serverBell() {
- Toolkit.getDefaultToolkit().beep();
- }
-
- /**
- * Handle packet with server clip-board.
- */
- private void serverCutText(DataInputStream is) throws IOException {
- ServerCutText clipboardContent = new ServerCutText(is);
- StringSelection contents = new StringSelection(clipboardContent.getContent());
- Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, null);
-
- s_logger.info("Server clipboard buffer: "+clipboardContent.getContent());
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/ClientPacket.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/ClientPacket.java b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/ClientPacket.java
index 10e7c02..873b8c0 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/ClientPacket.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/ClientPacket.java
@@ -21,6 +21,6 @@ import java.io.IOException;
public interface ClientPacket {
- void write(DataOutputStream os) throws IOException;
+ void write(DataOutputStream os) throws IOException;
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/FramebufferUpdateRequestPacket.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/FramebufferUpdateRequestPacket.java b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/FramebufferUpdateRequestPacket.java
index b5e87a8..d3a6e40 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/FramebufferUpdateRequestPacket.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/FramebufferUpdateRequestPacket.java
@@ -28,27 +28,26 @@ import com.cloud.consoleproxy.vnc.RfbConstants;
*/
public class FramebufferUpdateRequestPacket implements ClientPacket {
- private final int incremental;
- private final int x, y, width, height;
-
- public FramebufferUpdateRequestPacket(int incremental, int x, int y, int width, int height) {
- this.incremental = incremental;
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
-
-
- @Override
- public void write(DataOutputStream os) throws IOException {
- os.writeByte(RfbConstants.CLIENT_FRAMEBUFFER_UPDATE_REQUEST);
-
- os.writeByte(incremental);
- os.writeShort(x);
- os.writeShort(y);
- os.writeShort(width);
- os.writeShort(height);
- }
+ private final int incremental;
+ private final int x, y, width, height;
+
+ public FramebufferUpdateRequestPacket(int incremental, int x, int y, int width, int height) {
+ this.incremental = incremental;
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+
+ @Override
+ public void write(DataOutputStream os) throws IOException {
+ os.writeByte(RfbConstants.CLIENT_FRAMEBUFFER_UPDATE_REQUEST);
+
+ os.writeByte(incremental);
+ os.writeShort(x);
+ os.writeShort(y);
+ os.writeShort(width);
+ os.writeShort(height);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/KeyboardEventPacket.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/KeyboardEventPacket.java b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/KeyboardEventPacket.java
index 335fee6..8efbab1 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/KeyboardEventPacket.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/KeyboardEventPacket.java
@@ -23,20 +23,20 @@ import com.cloud.consoleproxy.vnc.RfbConstants;
public class KeyboardEventPacket implements ClientPacket {
- private final int downFlag, key;
-
- public KeyboardEventPacket(int downFlag, int key) {
- this.downFlag = downFlag;
- this.key = key;
- }
-
- @Override
- public void write(DataOutputStream os) throws IOException {
- os.writeByte(RfbConstants.CLIENT_KEYBOARD_EVENT);
-
- os.writeByte(downFlag);
- os.writeShort(0); // padding
- os.writeInt(key);
- }
+ private final int downFlag, key;
+
+ public KeyboardEventPacket(int downFlag, int key) {
+ this.downFlag = downFlag;
+ this.key = key;
+ }
+
+ @Override
+ public void write(DataOutputStream os) throws IOException {
+ os.writeByte(RfbConstants.CLIENT_KEYBOARD_EVENT);
+
+ os.writeByte(downFlag);
+ os.writeShort(0); // padding
+ os.writeInt(key);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/MouseEventPacket.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/MouseEventPacket.java b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/MouseEventPacket.java
index 4b799f6..b42191c 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/MouseEventPacket.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/MouseEventPacket.java
@@ -23,21 +23,21 @@ import com.cloud.consoleproxy.vnc.RfbConstants;
public class MouseEventPacket implements ClientPacket {
- private final int buttonMask, x, y;
-
- public MouseEventPacket(int buttonMask, int x, int y) {
- this.buttonMask = buttonMask;
- this.x = x;
- this.y = y;
- }
-
- @Override
- public void write(DataOutputStream os) throws IOException {
- os.writeByte(RfbConstants.CLIENT_POINTER_EVENT);
-
- os.writeByte(buttonMask);
- os.writeShort(x);
- os.writeShort(y);
- }
+ private final int buttonMask, x, y;
+
+ public MouseEventPacket(int buttonMask, int x, int y) {
+ this.buttonMask = buttonMask;
+ this.x = x;
+ this.y = y;
+ }
+
+ @Override
+ public void write(DataOutputStream os) throws IOException {
+ os.writeByte(RfbConstants.CLIENT_POINTER_EVENT);
+
+ os.writeByte(buttonMask);
+ os.writeShort(x);
+ os.writeShort(y);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/SetEncodingsPacket.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/SetEncodingsPacket.java b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/SetEncodingsPacket.java
index f34576f..3d8cfcb 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/SetEncodingsPacket.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/SetEncodingsPacket.java
@@ -23,26 +23,23 @@ import com.cloud.consoleproxy.vnc.RfbConstants;
public class SetEncodingsPacket implements ClientPacket {
- private final int[] encodings;
-
- public SetEncodingsPacket(int[] encodings)
- {
- this.encodings = encodings;
- }
-
- @Override
- public void write(DataOutputStream os) throws IOException
- {
- os.writeByte(RfbConstants.CLIENT_SET_ENCODINGS);
-
- os.writeByte(0);//padding
-
- os.writeShort(encodings.length);
-
- for(int i=0;i<encodings.length;i++)
- {
- os.writeInt(encodings[i]);
+ private final int[] encodings;
+
+ public SetEncodingsPacket(int[] encodings) {
+ this.encodings = encodings;
+ }
+
+ @Override
+ public void write(DataOutputStream os) throws IOException {
+ os.writeByte(RfbConstants.CLIENT_SET_ENCODINGS);
+
+ os.writeByte(0);// padding
+
+ os.writeShort(encodings.length);
+
+ for (int i = 0; i < encodings.length; i++) {
+ os.writeInt(encodings[i]);
+ }
}
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/SetPixelFormatPacket.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/SetPixelFormatPacket.java b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/SetPixelFormatPacket.java
index 5a578a7..7a25bfa 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/SetPixelFormatPacket.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/client/SetPixelFormatPacket.java
@@ -24,52 +24,52 @@ import com.cloud.consoleproxy.vnc.VncScreenDescription;
public class SetPixelFormatPacket implements ClientPacket {
- private final int bitsPerPixel, depth, bigEndianFlag, trueColourFlag, redMax, greenMax, blueMax, redShift, greenShift, blueShift;
-
- private final VncScreenDescription screen;
+ private final int bitsPerPixel, depth, bigEndianFlag, trueColourFlag, redMax, greenMax, blueMax, redShift, greenShift, blueShift;
- public SetPixelFormatPacket(VncScreenDescription screen, int bitsPerPixel, int depth, int bigEndianFlag, int trueColorFlag, int redMax, int greenMax,
- int blueMax, int redShift, int greenShift, int blueShift) {
- this.screen = screen;
- this.bitsPerPixel = bitsPerPixel;
- this.depth = depth;
- this.bigEndianFlag = bigEndianFlag;
- this.trueColourFlag = trueColorFlag;
- this.redMax = redMax;
- this.greenMax = greenMax;
- this.blueMax = blueMax;
- this.redShift = redShift;
- this.greenShift = greenShift;
- this.blueShift = blueShift;
- }
+ private final VncScreenDescription screen;
- @Override
- public void write(DataOutputStream os) throws IOException {
- os.writeByte(RfbConstants.CLIENT_SET_PIXEL_FORMAT);
+ public SetPixelFormatPacket(VncScreenDescription screen, int bitsPerPixel, int depth, int bigEndianFlag, int trueColorFlag, int redMax, int greenMax, int blueMax, int redShift, int greenShift,
+ int blueShift) {
+ this.screen = screen;
+ this.bitsPerPixel = bitsPerPixel;
+ this.depth = depth;
+ this.bigEndianFlag = bigEndianFlag;
+ this.trueColourFlag = trueColorFlag;
+ this.redMax = redMax;
+ this.greenMax = greenMax;
+ this.blueMax = blueMax;
+ this.redShift = redShift;
+ this.greenShift = greenShift;
+ this.blueShift = blueShift;
+ }
- // Padding
- os.writeByte(0);
- os.writeByte(0);
- os.writeByte(0);
+ @Override
+ public void write(DataOutputStream os) throws IOException {
+ os.writeByte(RfbConstants.CLIENT_SET_PIXEL_FORMAT);
- // Send pixel format
- os.writeByte(bitsPerPixel);
- os.writeByte(depth);
- os.writeByte(bigEndianFlag);
- os.writeByte(trueColourFlag);
- os.writeShort(redMax);
- os.writeShort(greenMax);
- os.writeShort(blueMax);
- os.writeByte(redShift);
- os.writeByte(greenShift);
- os.writeByte(blueShift);
+ // Padding
+ os.writeByte(0);
+ os.writeByte(0);
+ os.writeByte(0);
- // Padding
- os.writeByte(0);
- os.writeByte(0);
- os.writeByte(0);
+ // Send pixel format
+ os.writeByte(bitsPerPixel);
+ os.writeByte(depth);
+ os.writeByte(bigEndianFlag);
+ os.writeByte(trueColourFlag);
+ os.writeShort(redMax);
+ os.writeShort(greenMax);
+ os.writeShort(blueMax);
+ os.writeByte(redShift);
+ os.writeByte(greenShift);
+ os.writeByte(blueShift);
- screen.setPixelFormat(bitsPerPixel, depth, bigEndianFlag, trueColourFlag, redMax, greenMax, blueMax, redShift, greenShift, blueShift);
- }
+ // Padding
+ os.writeByte(0);
+ os.writeByte(0);
+ os.writeByte(0);
+
+ screen.setPixelFormat(bitsPerPixel, depth, bigEndianFlag, trueColourFlag, redMax, greenMax, blueMax, redShift, greenShift, blueShift);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/AbstractRect.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/AbstractRect.java b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/AbstractRect.java
index da069de..a380e9c 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/AbstractRect.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/AbstractRect.java
@@ -18,36 +18,36 @@ package com.cloud.consoleproxy.vnc.packet.server;
public abstract class AbstractRect implements Rect {
- protected final int x;
- protected final int y;
- protected final int width;
- protected final int height;
-
- public AbstractRect(int x, int y, int width, int height) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
-
- @Override
- public int getX() {
- return x;
- }
-
- @Override
- public int getY() {
- return y;
- }
-
- @Override
- public int getWidth() {
- return width;
- }
-
- @Override
- public int getHeight() {
- return height;
- }
+ protected final int x;
+ protected final int y;
+ protected final int width;
+ protected final int height;
+
+ public AbstractRect(int x, int y, int width, int height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+
+ @Override
+ public int getX() {
+ return x;
+ }
+
+ @Override
+ public int getY() {
+ return y;
+ }
+
+ @Override
+ public int getWidth() {
+ return width;
+ }
+
+ @Override
+ public int getHeight() {
+ return height;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/CopyRect.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/CopyRect.java b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/CopyRect.java
index a972c81..caaecb5 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/CopyRect.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/CopyRect.java
@@ -23,17 +23,17 @@ import java.io.IOException;
public class CopyRect extends AbstractRect {
- private final int srcX, srcY;
+ private final int srcX, srcY;
- public CopyRect(int x, int y, int width, int height, DataInputStream is) throws IOException {
- super(x, y, width, height);
+ public CopyRect(int x, int y, int width, int height, DataInputStream is) throws IOException {
+ super(x, y, width, height);
- srcX = is.readUnsignedShort();
- srcY = is.readUnsignedShort();
- }
+ srcX = is.readUnsignedShort();
+ srcY = is.readUnsignedShort();
+ }
- @Override
- public void paint(BufferedImage image, Graphics2D graphics) {
- graphics.copyArea(srcX, srcY, width, height, x - srcX, y - srcY);
- }
+ @Override
+ public void paint(BufferedImage image, Graphics2D graphics) {
+ graphics.copyArea(srcX, srcY, width, height, x - srcX, y - srcY);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0bf8c5a1/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/FrameBufferSizeChangeRequest.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/FrameBufferSizeChangeRequest.java b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/FrameBufferSizeChangeRequest.java
index bb4522f..18f6987 100644
--- a/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/FrameBufferSizeChangeRequest.java
+++ b/console-proxy/src/com/cloud/consoleproxy/vnc/packet/server/FrameBufferSizeChangeRequest.java
@@ -22,18 +22,18 @@ import java.awt.image.BufferedImage;
import com.cloud.consoleproxy.vnc.BufferedImageCanvas;
public class FrameBufferSizeChangeRequest extends AbstractRect {
-
- private final BufferedImageCanvas canvas;
- public FrameBufferSizeChangeRequest(BufferedImageCanvas canvas, int width, int height) {
- super(0, 0, width, height);
- this.canvas = canvas;
- canvas.setCanvasSize(width, height);
- }
+ private final BufferedImageCanvas canvas;
- @Override
- public void paint(BufferedImage offlineImage, Graphics2D graphics) {
- canvas.setCanvasSize(width, height);
- }
+ public FrameBufferSizeChangeRequest(BufferedImageCanvas canvas, int width, int height) {
+ super(0, 0, width, height);
+ this.canvas = canvas;
+ canvas.setCanvasSize(width, height);
+ }
+
+ @Override
+ public void paint(BufferedImage offlineImage, Graphics2D graphics) {
+ canvas.setCanvasSize(width, height);
+ }
}