DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Brian Hinz | b213da6 | 2012-04-11 22:00:55 +0000 | [diff] [blame] | 2 | * Copyright 2009-2011 Pierre Ossman for Cendio AB |
| 3 | * Copyright (C) 2011 Brian P. Hinz |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 4 | * |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 5 | * This is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 9 | * |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 10 | * This software is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 14 | * |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this software; if not, write to the Free Software |
Brian Hinz | b213da6 | 2012-04-11 22:00:55 +0000 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 18 | * USA. |
| 19 | */ |
| 20 | |
| 21 | package com.tigervnc.rfb; |
| 22 | |
| 23 | import com.tigervnc.rdr.*; |
| 24 | |
| 25 | public class CMsgReaderV3 extends CMsgReader { |
| 26 | |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 27 | public CMsgReaderV3(CMsgHandler handler_, InStream is_) |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 28 | { |
| 29 | super(handler_, is_); |
| 30 | nUpdateRectsLeft = 0; |
| 31 | } |
| 32 | |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 33 | public void readServerInit() |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 34 | { |
| 35 | int width = is.readU16(); |
| 36 | int height = is.readU16(); |
| 37 | handler.setDesktopSize(width, height); |
| 38 | PixelFormat pf = new PixelFormat(); |
| 39 | pf.read(is); |
| 40 | handler.setPixelFormat(pf); |
| 41 | String name = is.readString(); |
| 42 | handler.setName(name); |
| 43 | handler.serverInit(); |
| 44 | } |
| 45 | |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 46 | public void readMsg() |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 47 | { |
| 48 | if (nUpdateRectsLeft == 0) { |
| 49 | |
| 50 | int type = is.readU8(); |
| 51 | switch (type) { |
| 52 | case MsgTypes.msgTypeFramebufferUpdate: readFramebufferUpdate(); break; |
| 53 | case MsgTypes.msgTypeSetColourMapEntries: readSetColourMapEntries(); break; |
| 54 | case MsgTypes.msgTypeBell: readBell(); break; |
| 55 | case MsgTypes.msgTypeServerCutText: readServerCutText(); break; |
Brian Hinz | af15db2 | 2012-02-12 20:44:29 +0000 | [diff] [blame] | 56 | case MsgTypes.msgTypeServerFence: readFence(); break; |
| 57 | case MsgTypes.msgTypeEndOfContinuousUpdates: readEndOfContinuousUpdates(); break; |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 58 | default: |
| 59 | vlog.error("unknown message type "+type); |
| 60 | throw new Exception("unknown message type"); |
| 61 | } |
| 62 | |
| 63 | } else { |
| 64 | |
| 65 | int x = is.readU16(); |
| 66 | int y = is.readU16(); |
| 67 | int w = is.readU16(); |
| 68 | int h = is.readU16(); |
Brian Hinz | e768141 | 2011-05-17 21:00:34 +0000 | [diff] [blame] | 69 | int encoding = is.readS32(); |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 70 | |
| 71 | switch (encoding) { |
| 72 | case Encodings.pseudoEncodingDesktopSize: |
| 73 | handler.setDesktopSize(w, h); |
| 74 | break; |
| 75 | case Encodings.pseudoEncodingExtendedDesktopSize: |
| 76 | readExtendedDesktopSize(x, y, w, h); |
| 77 | break; |
| 78 | case Encodings.pseudoEncodingDesktopName: |
| 79 | readSetDesktopName(x, y, w, h); |
| 80 | break; |
| 81 | case Encodings.pseudoEncodingCursor: |
| 82 | readSetCursor(w, h, new Point(x,y)); |
| 83 | break; |
| 84 | case Encodings.pseudoEncodingLastRect: |
| 85 | nUpdateRectsLeft = 1; // this rectangle is the last one |
| 86 | break; |
Brian Hinz | f7ed1f6 | 2011-06-10 00:44:05 +0000 | [diff] [blame] | 87 | case Encodings.pseudoEncodingClientRedirect: |
| 88 | readClientRedirect(x, y, w, h); |
| 89 | break; |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 90 | default: |
| 91 | readRect(new Rect(x, y, x+w, y+h), encoding); |
| 92 | break; |
| 93 | } |
| 94 | |
| 95 | nUpdateRectsLeft--; |
| 96 | if (nUpdateRectsLeft == 0) handler.framebufferUpdateEnd(); |
| 97 | } |
| 98 | } |
| 99 | |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 100 | void readFramebufferUpdate() |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 101 | { |
| 102 | is.skip(1); |
| 103 | nUpdateRectsLeft = is.readU16(); |
| 104 | handler.framebufferUpdateStart(); |
| 105 | } |
| 106 | |
| 107 | void readSetDesktopName(int x, int y, int w, int h) |
| 108 | { |
| 109 | String name = is.readString(); |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 110 | |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 111 | if (x != 0 || y != 0 || w != 0 || h != 0) { |
| 112 | vlog.error("Ignoring DesktopName rect with non-zero position/size"); |
| 113 | } else { |
| 114 | handler.setName(name); |
| 115 | } |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 116 | |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 117 | } |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 118 | |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 119 | void readExtendedDesktopSize(int x, int y, int w, int h) |
| 120 | { |
| 121 | int screens, i; |
| 122 | int id, flags; |
| 123 | int sx, sy, sw, sh; |
| 124 | ScreenSet layout = new ScreenSet(); |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 125 | |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 126 | screens = is.readU8(); |
| 127 | is.skip(3); |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 128 | |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 129 | for (i = 0;i < screens;i++) { |
| 130 | id = is.readU32(); |
| 131 | sx = is.readU16(); |
| 132 | sy = is.readU16(); |
| 133 | sw = is.readU16(); |
| 134 | sh = is.readU16(); |
| 135 | flags = is.readU32(); |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 136 | |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 137 | layout.add_screen(new Screen(id, sx, sy, sw, sh, flags)); |
| 138 | } |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 139 | |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 140 | handler.setExtendedDesktopSize(x, y, w, h, layout); |
| 141 | } |
| 142 | |
Brian Hinz | af15db2 | 2012-02-12 20:44:29 +0000 | [diff] [blame] | 143 | void readFence() |
| 144 | { |
| 145 | int flags; |
| 146 | int len; |
| 147 | byte[] data = new byte[64]; |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 148 | |
Brian Hinz | af15db2 | 2012-02-12 20:44:29 +0000 | [diff] [blame] | 149 | is.skip(3); |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 150 | |
Brian Hinz | af15db2 | 2012-02-12 20:44:29 +0000 | [diff] [blame] | 151 | flags = is.readU32(); |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 152 | |
Brian Hinz | af15db2 | 2012-02-12 20:44:29 +0000 | [diff] [blame] | 153 | len = is.readU8(); |
| 154 | if (len > data.length) { |
| 155 | System.out.println("Ignoring fence with too large payload\n"); |
| 156 | is.skip(len); |
| 157 | return; |
| 158 | } |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 159 | |
Brian Hinz | af15db2 | 2012-02-12 20:44:29 +0000 | [diff] [blame] | 160 | is.readBytes(data, 0, len); |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 161 | |
Brian Hinz | af15db2 | 2012-02-12 20:44:29 +0000 | [diff] [blame] | 162 | handler.fence(flags, len, data); |
| 163 | } |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 164 | |
Brian Hinz | af15db2 | 2012-02-12 20:44:29 +0000 | [diff] [blame] | 165 | void readEndOfContinuousUpdates() |
| 166 | { |
| 167 | handler.endOfContinuousUpdates(); |
| 168 | } |
| 169 | |
Brian Hinz | c0a3609 | 2013-05-12 15:46:09 +0000 | [diff] [blame] | 170 | void readClientRedirect(int x, int y, int w, int h) |
Brian Hinz | f7ed1f6 | 2011-06-10 00:44:05 +0000 | [diff] [blame] | 171 | { |
| 172 | int port = is.readU16(); |
| 173 | String host = is.readString(); |
| 174 | String x509subject = is.readString(); |
| 175 | |
| 176 | if (x != 0 || y != 0 || w != 0 || h != 0) { |
| 177 | vlog.error("Ignoring ClientRedirect rect with non-zero position/size"); |
| 178 | } else { |
| 179 | handler.clientRedirect(port, host, x509subject); |
| 180 | } |
| 181 | } |
| 182 | |
DRC | c5dc038 | 2011-05-13 21:42:14 +0000 | [diff] [blame] | 183 | int nUpdateRectsLeft; |
| 184 | |
| 185 | static LogWriter vlog = new LogWriter("CMsgReaderV3"); |
| 186 | } |