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