blob: e09d3bb00ac45095b8dd9ecc878eacda542e0274 [file] [log] [blame]
DRCc5dc0382011-05-13 21:42:14 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Brian Hinzb213da62012-04-11 22:00:55 +00002 * Copyright 2009-2011 Pierre Ossman for Cendio AB
3 * Copyright (C) 2011 Brian P. Hinz
Brian Hinzc0a36092013-05-12 15:46:09 +00004 *
DRCc5dc0382011-05-13 21:42:14 +00005 * 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 Hinzc0a36092013-05-12 15:46:09 +00009 *
DRCc5dc0382011-05-13 21:42:14 +000010 * 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 Hinzc0a36092013-05-12 15:46:09 +000014 *
DRCc5dc0382011-05-13 21:42:14 +000015 * 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 Hinzb213da62012-04-11 22:00:55 +000017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
DRCc5dc0382011-05-13 21:42:14 +000018 * USA.
19 */
20
21package com.tigervnc.rfb;
22
23import com.tigervnc.rdr.*;
24
25public class CMsgReaderV3 extends CMsgReader {
26
Brian Hinzc0a36092013-05-12 15:46:09 +000027 public CMsgReaderV3(CMsgHandler handler_, InStream is_)
DRCc5dc0382011-05-13 21:42:14 +000028 {
29 super(handler_, is_);
30 nUpdateRectsLeft = 0;
31 }
32
Brian Hinzc0a36092013-05-12 15:46:09 +000033 public void readServerInit()
DRCc5dc0382011-05-13 21:42:14 +000034 {
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 Hinzc0a36092013-05-12 15:46:09 +000046 public void readMsg()
DRCc5dc0382011-05-13 21:42:14 +000047 {
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 Hinzaf15db22012-02-12 20:44:29 +000056 case MsgTypes.msgTypeServerFence: readFence(); break;
57 case MsgTypes.msgTypeEndOfContinuousUpdates: readEndOfContinuousUpdates(); break;
DRCc5dc0382011-05-13 21:42:14 +000058 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 Hinze7681412011-05-17 21:00:34 +000069 int encoding = is.readS32();
DRCc5dc0382011-05-13 21:42:14 +000070
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 Hinzf7ed1f62011-06-10 00:44:05 +000087 case Encodings.pseudoEncodingClientRedirect:
88 readClientRedirect(x, y, w, h);
89 break;
DRCc5dc0382011-05-13 21:42:14 +000090 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 Hinzc0a36092013-05-12 15:46:09 +0000100 void readFramebufferUpdate()
DRCc5dc0382011-05-13 21:42:14 +0000101 {
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 Hinzc0a36092013-05-12 15:46:09 +0000110
DRCc5dc0382011-05-13 21:42:14 +0000111 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 Hinzc0a36092013-05-12 15:46:09 +0000116
DRCc5dc0382011-05-13 21:42:14 +0000117 }
Brian Hinzc0a36092013-05-12 15:46:09 +0000118
DRCc5dc0382011-05-13 21:42:14 +0000119 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 Hinzc0a36092013-05-12 15:46:09 +0000125
DRCc5dc0382011-05-13 21:42:14 +0000126 screens = is.readU8();
127 is.skip(3);
Brian Hinzc0a36092013-05-12 15:46:09 +0000128
DRCc5dc0382011-05-13 21:42:14 +0000129 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 Hinzc0a36092013-05-12 15:46:09 +0000136
DRCc5dc0382011-05-13 21:42:14 +0000137 layout.add_screen(new Screen(id, sx, sy, sw, sh, flags));
138 }
Brian Hinzc0a36092013-05-12 15:46:09 +0000139
DRCc5dc0382011-05-13 21:42:14 +0000140 handler.setExtendedDesktopSize(x, y, w, h, layout);
141 }
142
Brian Hinzaf15db22012-02-12 20:44:29 +0000143 void readFence()
144 {
145 int flags;
146 int len;
147 byte[] data = new byte[64];
Brian Hinzc0a36092013-05-12 15:46:09 +0000148
Brian Hinzaf15db22012-02-12 20:44:29 +0000149 is.skip(3);
Brian Hinzc0a36092013-05-12 15:46:09 +0000150
Brian Hinzaf15db22012-02-12 20:44:29 +0000151 flags = is.readU32();
Brian Hinzc0a36092013-05-12 15:46:09 +0000152
Brian Hinzaf15db22012-02-12 20:44:29 +0000153 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 Hinzc0a36092013-05-12 15:46:09 +0000159
Brian Hinzaf15db22012-02-12 20:44:29 +0000160 is.readBytes(data, 0, len);
Brian Hinzc0a36092013-05-12 15:46:09 +0000161
Brian Hinzaf15db22012-02-12 20:44:29 +0000162 handler.fence(flags, len, data);
163 }
Brian Hinzc0a36092013-05-12 15:46:09 +0000164
Brian Hinzaf15db22012-02-12 20:44:29 +0000165 void readEndOfContinuousUpdates()
166 {
167 handler.endOfContinuousUpdates();
168 }
169
Brian Hinzc0a36092013-05-12 15:46:09 +0000170 void readClientRedirect(int x, int y, int w, int h)
Brian Hinzf7ed1f62011-06-10 00:44:05 +0000171 {
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
DRCc5dc0382011-05-13 21:42:14 +0000183 int nUpdateRectsLeft;
184
185 static LogWriter vlog = new LogWriter("CMsgReaderV3");
186}