blob: f59d2378863cbe6f87e0dd94da234fa2db39fcb2 [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
DRCc5dc0382011-05-13 21:42:14 +00004 *
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.
9 *
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.
14 *
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 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
27 public CMsgReaderV3(CMsgHandler handler_, InStream is_)
28 {
29 super(handler_, is_);
30 nUpdateRectsLeft = 0;
31 }
32
33 public void readServerInit()
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
46 public void readMsg()
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 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
100 void readFramebufferUpdate()
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();
110
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 }
116
117 }
118
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();
125
126 screens = is.readU8();
127 is.skip(3);
128
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();
136
137 layout.add_screen(new Screen(id, sx, sy, sw, sh, flags));
138 }
139
140 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];
148
149 is.skip(3);
150
151 flags = is.readU32();
152
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 }
159
160 is.readBytes(data, 0, len);
161
162 handler.fence(flags, len, data);
163 }
164
165 void readEndOfContinuousUpdates()
166 {
167 handler.endOfContinuousUpdates();
168 }
169
Brian Hinzf7ed1f62011-06-10 00:44:05 +0000170 void readClientRedirect(int x, int y, int w, int h)
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
DRCc5dc0382011-05-13 21:42:14 +0000183 int nUpdateRectsLeft;
184
185 static LogWriter vlog = new LogWriter("CMsgReaderV3");
186}